Wiki源代码GitHubConfigSheet

xu yang 于 2021/11/30 11:14 最后修改

Show last authors
1 {{velocity}}
2 #if ("$!request.action" == "compare")
3 = $msg.get('github.configsheet.compare.title'): $request.page =
4 #else
5 = $msg.get("github.configsheet.title"): $doc.name =
6 #end
7
8 #if(!$xwiki.hasProgrammingRights())
9 #warning("This application cannot work without programming rights on the current page. Resave this page as an admin and retry.")
10 #else
11
12 #if(!$request.action)
13 #set($class = $doc.getObject('GitHubCode.GitHubConfigClass').xWikiClass)
14 #set($authobj = $doc.getObject("GitHubCode.GitHubAuthClass", "contextuser", $context.user))
15 #if(!$authobj)
16 #set($authobj = $doc.newObject("GitHubCode.GitHubAuthClass"))
17 #if($context.action=="inline")
18 #set($ok = $doc.use($authobj))
19 #set($ok = $doc.set("contextuser", $context.user))
20 #set($ok = $doc.use("GitHubCode.GitHubConfigClass"))
21 #set($ok = $doc.save())
22 #end
23 #end
24 #foreach($prop in $class.properties)
25 #if($prop.name=="username")
26 #set($ok = $doc.use($authobj))
27 **$doc.displayPrettyName("username")**
28 $doc.display("username")
29 **$doc.displayPrettyName("email")**
30 $doc.display("email")
31 #if($context.action=="inline")
32 **$doc.displayPrettyName("password")**
33 $doc.display("password")
34 #set($ok = $doc.set("contextuser", $context.user))
35 $doc.display("contextuser", "hidden")
36 #end
37 #set($ok = $doc.use("GitHubCode.GitHubConfigClass"))
38 #elseif($prop.name!="username"&&$prop.name!="password"&&$prop.name!="email")
39 #set($tooltip = $prop.propertyClass.getTooltip($context.context))
40 **$doc.displayPrettyName($prop.name)** #if($tooltip!="GitHubCode.GitHubConfigClass_${prop.name}_tooltip")//(${tooltip})//#end
41
42 #if($context.action=="inline"&&$prop.name=="savedlist")
43 #set($path = $xwiki.getURL("GitHubCode.SavedListSuggest", "view"))
44 #set($script = $path + "?xpage=plain&outputSyntax=plain&")
45 {{html clean=false}}
46 <input type="text" id="GitHubCode.GitHubConfigClass_0_savedlist" name="GitHubCode.GitHubConfigClass_0_savedlist" onfocus="tsuggest(this);" value="$!doc.getValue("savedlist")" />
47 <script type="text/javascript">
48 // <![CDATA[
49 function tsuggest(field) {
50 if (!field.suggest) {
51 field.suggest = new ajaxSuggest(field, {script:'$script', varname: 'input', seps:'', offsety: 13,
52 callback: function(obj) { field.value=obj.info;} });
53 field.suggest.options.timeout = 5000;
54 }
55 }
56 // ]]>
57 </script>
58 {{/html}}
59 #else
60 $doc.display($prop.getName())
61 #end
62 #end
63 #end
64 #end
65 #set($configLoaded = "")
66 #if($request.action)
67 #set($githubgroovy = $xwiki.parseGroovyFromPage("GitHubCode.GitHubGroovy","GitHubCode.GitHubGroovy"))
68 #set($ok = $githubgroovy.setXWiki($xwiki, $context))
69 #if(!$githubgroovy.hasProgrammingRights())
70 #warning("This application cannot work without programming rights on [[GitHubCode.GitHubGroovy]]. Resave this page as an admin and retry.")
71 #end
72 #set($configLoaded = $githubgroovy.setGitHubConfig($doc.fullName))
73 #if($request.spaces)
74 #set($spaces = $request.spaces)
75 #set($savedlist = "")
76 #else
77 #set($savedlist = $githubgroovy.getSavedList())
78 #set($spaces = $githubgroovy.getDefaultSpace())
79 #end
80 #end
81 #if($configLoaded!="")
82 ## it was not possible to connect to github
83 $configLoaded
84 #else
85 ## CUSTOM action
86 #if($request.action=="custom")
87 {{html wiki=true clean=false}}
88 <form action="" method="get">
89 <input type="hidden" name="action" value="list" />
90 $msg.get("github.configsheet.custom.spacelist"): <input type="text" name="spaces" value="" /><input type="submit" value="$msg.get("github.configsheet.listpages")" />
91 </form>
92 <form action="" method="get">
93 <input type="hidden" name="action" value="list" />
94 $msg.get("github.configsheet.custom.space"): <select name="spaces">
95 #foreach($space in $xwiki.spaces)
96 <option value="$space">$space</option>
97 #end
98 </select>
99 <input type="submit" value="$msg.get("github.configsheet.listpages")" />
100 </form>
101 {{/html}}
102 ## LIST ACTION
103 #elseif($request.action=="list")
104 {{html wiki=true}}
105 <form action="$doc.name" method="post">
106 <input type="hidden" name="action" value="commit" />
107 <input type="hidden" name="spaces" value="$!{spaces}" />
108 <ul>
109 #set($cmap = $!githubgroovy.getChangedPages($spaces, $savedlist))
110 #foreach($page in $cmap.keySet())
111 #set($status = $cmap.get($page))
112 ## encode the language of the document after the document name, after a dot. Will be processed on commit
113 <li>$status.status <input type="checkbox" name="page" value="${status.fullname}.$!{status.language}" /> ${page}
114 <input type="hidden" name="${status.fullname}.$!{status.language}_sha" value="${status.githubsha}" />
115 #if($status.status!="N")
116 [[$msg.get("github.configsheet.viewdiff")>>${doc.fullName}?action=compare&page=${status.fullname}&githublanguage=${status.language}&spaces=$!{spaces}&githubsha=${status.githubsha}||target=_blank]]
117 -
118 [[$msg.get("github.configsheet.viewdiffunformatted")>>${doc.fullName}?action=compare&page=${status.fullname}&githublanguage=${status.language}&spaces=$!{spaces}&githubsha=${status.githubsha}&unformatted=1||target=_blank]]
119 -
120 [[$msg.get("github.configsheet.viewdoc")>>${status.fullname}?language=${status.language}||target=_blank]]
121 #end
122 #end
123 </ul>
124 <input type="submit" name="commit" value="$msg.get("github.configsheet.commitall")" /> <input type="submit" name="update" value="$msg.get("github.configsheet.updateall")" /> <input type="submit" name="export" value="$msg.get("github.configsheet.exportall")" />
125 </form>
126 {{/html}}
127 #elseif($request.export)
128 #set($pagelist = $xwiki.arrayList)
129 #foreach($page in $request.getParameterValues("page"))
130 #set($ok = $pagelist.add($page))
131 #end
132 $githubgroovy.exportPages($doc.name, $pagelist)
133 #set($ok = $context.setFinished(true))
134 #elseif($request.update)
135 #set($pagelist = $xwiki.arrayList)
136 #foreach($page in $request.getParameterValues("page"))
137 #set($ok = $pagelist.add({ "page" : $page, "sha" : $request.get("${page}_sha")}))
138 #end
139 #set($list = $githubgroovy.updatePages($pagelist,$spaces))
140
141 $msg.get("github.configsheet.pagesupdated")
142
143 #foreach($page in $list.keySet())
144 * $page
145 #end
146
147 [[$msg.get("github.configsheet.backtolist")>>${doc.fullName}?action=list]] - [[$msg.get("github.configsheet.backtocustom")>>${doc.fullName}?action=custom]]
148
149 ## COMMIT ACTION with confirm
150 #elseif($request.action=="commit" && $request.confirm=="1")
151 $msg.get("github.configsheet.committingpages"):
152
153 #set($pagelist = $xwiki.arrayList)
154 #foreach($page in $request.getParameterValues("page"))
155 * $page
156 #set($ok = $pagelist.add($page))
157 #end
158
159 $githubgroovy.commitFiles($pagelist, $request.message, $!request.pom)
160
161 $msg.get("github.configsheet.committsuccessfull")
162
163
164 [[$msg.get("github.configsheet.backtolist")>>${doc.fullName}?action=list]] - [[$msg.get("github.configsheet.backtocustom")>>${doc.fullName}?action=custom]]
165
166 ## COMMIT ACTION before confirm
167 #elseif($request.action=="commit")
168 ## confirm commit
169 $msg.get("github.configsheet.confirmcommittingpage")
170
171 {{html wiki=true}}
172 <form action="$doc.name" method="post">
173 <input type="hidden" name="action" value="commit" />
174 <input type="hidden" name="confirm" value="1" />
175 <input type="hidden" name="spaces" value="$!{spaces}" />
176 ## just pass the pages to commit further
177 #foreach($page in $request.getParameterValues("page"))
178 * $page
179 <input type="hidden" name="page" value="$!{page}" />
180 #end
181
182 $msg.get("github.configsheet.commitmessage"):
183 <br />
184 <textarea name="message" rows="5" cols="80">
185 </textarea>
186 <br />
187 <input type="checkbox" name="pom" value="1" /> $msg.get("github.configsheet.commitpom")
188 <br />
189 <input type="submit" value="Commit" />
190 </form>
191 {{/html}}
192 ## VIEW STATUS ACTION
193 #elseif($request.action=="status")
194
195 $githubgroovy.getCommitStatus("|", "|", false)
196
197 ## VIEW STATUS ACTION
198 #elseif($request.action=="compare")
199 {{html clean=false}}
200 <style type="text/css">
201 .diffremoveword {
202 background-color: #FFAAAA;
203 }
204 .diffaddword {
205 background-color: #AAFFAA;
206 }
207 </style>
208 #set($pagedoc = $xwiki.getDocument($request.page))
209 #if($request.githublanguage)
210 #set($pagedoc = $pagedoc.getTranslatedDocument($request.githublanguage))
211 #end
212 #if("1"=="$!{request.unformatted}")
213 $githubgroovy.showXMLDiff($pagedoc, $request.githubsha, false)
214 #else
215 $githubgroovy.showXMLDiff($pagedoc, $request.githubsha, true)
216 #end
217 {{/html}}
218
219 ## OTHER ACTION
220 #else
221
222 [[$msg.get("github.configsheet.listpages")>>${doc.fullName}?action=list]] - [[$msg.get("github.configsheet.customlist")>>${doc.fullName}?action=custom]]
223 #end
224
225 #end ## end set config failed
226
227 #if($request.action)
228 $msg.get("github.configsheet.debug"):
229
230 $githubgroovy.getDebug()
231 #end
232 #end
233 {{/velocity}}