Index: trunk/extensions/ExtensionDistributor/ExtensionDistributor_body.php |
— | — | @@ -2,7 +2,7 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Special page that allows users to download extensions as tar archives. |
6 | | - * |
| 6 | + * |
7 | 7 | * @author Tim Starling |
8 | 8 | */ |
9 | 9 | class ExtensionDistributorPage extends SpecialPage { |
— | — | @@ -24,17 +24,17 @@ |
25 | 25 | |
26 | 26 | if ( $subpage ) { |
27 | 27 | $parts = explode( '/', $subpage, 2 ); |
28 | | - |
| 28 | + |
29 | 29 | if ( count( $parts ) == 1 ) { |
30 | 30 | $parts[] = false; |
31 | 31 | } |
32 | | - |
| 32 | + |
33 | 33 | list( $extension, $version ) = $parts; |
34 | 34 | } else { |
35 | 35 | $extension = $wgRequest->getVal( 'extdist_extension' ); |
36 | 36 | $version = $wgRequest->getVal( 'extdist_version' ); |
37 | 37 | } |
38 | | - |
| 38 | + |
39 | 39 | if ( !$extension ) { |
40 | 40 | $this->showExtensionSelector(); |
41 | 41 | return; |
— | — | @@ -68,46 +68,46 @@ |
69 | 69 | } |
70 | 70 | |
71 | 71 | $this->extensionList = array(); |
72 | | - |
| 72 | + |
73 | 73 | foreach ( $wgExtDistBranches as $branchPath => $branch ) { |
74 | 74 | $wc = "$wgExtDistWorkingCopy/$branchPath/extensions"; |
75 | 75 | $dir = opendir( $wc ); |
76 | | - |
| 76 | + |
77 | 77 | if ( !$dir ) { |
78 | 78 | return false; |
79 | 79 | } |
80 | 80 | |
81 | 81 | $this->extensionList[$branchPath] = array(); |
82 | | - |
| 82 | + |
83 | 83 | while ( false !== ( $file = readdir( $dir ) ) ) { |
84 | 84 | if ( substr( $file, 0, 1 ) == '.' ) { |
85 | 85 | continue; |
86 | 86 | } |
87 | | - |
| 87 | + |
88 | 88 | if ( !is_dir( "$wc/$file" ) ) { |
89 | 89 | continue; |
90 | 90 | } |
91 | | - |
| 91 | + |
92 | 92 | if ( file_exists( "$wc/$file/NO-DIST" ) ) { |
93 | 93 | continue; |
94 | 94 | } |
95 | | - |
| 95 | + |
96 | 96 | $this->extensionList[$branchPath][] = $file; |
97 | 97 | } |
98 | | - |
| 98 | + |
99 | 99 | natcasesort( $this->extensionList[$branchPath] ); |
100 | 100 | } |
101 | | - |
| 101 | + |
102 | 102 | return $this->extensionList; |
103 | 103 | } |
104 | 104 | |
105 | 105 | protected function getBranchName( $path ) { |
106 | 106 | global $wgExtDistBranches; |
107 | | - |
| 107 | + |
108 | 108 | if ( !isset( $wgExtDistBranches[$path] ) ) { |
109 | 109 | return false; |
110 | 110 | } |
111 | | - |
| 111 | + |
112 | 112 | if ( isset( $wgExtDistBranches[$path]['msgName'] ) ) { |
113 | 113 | return wfMsg( $wgExtDistBranches[$path]['msgName'] ); |
114 | 114 | } else { |
— | — | @@ -119,12 +119,12 @@ |
120 | 120 | global $wgOut; |
121 | 121 | |
122 | 122 | $extensions = $this->getExtensionList(); |
123 | | - |
| 123 | + |
124 | 124 | if ( $extensions === false ) { |
125 | 125 | $wgOut->addWikiMsg( 'extdist-wc-missing' ); |
126 | 126 | return; |
127 | 127 | } |
128 | | - |
| 128 | + |
129 | 129 | if ( !$extensions['trunk'] ) { |
130 | 130 | $wgOut->addWikiMsg( 'extdist-wc-empty' ); |
131 | 131 | return; |
— | — | @@ -152,11 +152,11 @@ |
153 | 153 | |
154 | 154 | protected function showVersionSelector( $extensionName ) { |
155 | 155 | global $wgOut, $wgExtDistBranches; |
156 | | - |
| 156 | + |
157 | 157 | $extensions = $this->getExtensionList(); |
158 | 158 | |
159 | 159 | $versions = array(); |
160 | | - |
| 160 | + |
161 | 161 | foreach ( $wgExtDistBranches as $branchPath => $branch ) { |
162 | 162 | if ( !in_array( $extensionName, $extensions[$branchPath] ) ) { |
163 | 163 | continue; |
— | — | @@ -167,7 +167,7 @@ |
168 | 168 | } else { |
169 | 169 | $branchName = $branch['name']; |
170 | 170 | } |
171 | | - |
| 171 | + |
172 | 172 | $versions[$branchPath] = $branchName; |
173 | 173 | } |
174 | 174 | |
— | — | @@ -185,15 +185,15 @@ |
186 | 186 | Xml::element( 'input' , array( 'type' => 'hidden', |
187 | 187 | 'name' => 'extdist_extension', 'value' => $extensionName ) ) . |
188 | 188 | "<select name=\"extdist_version\">\n" ); |
189 | | - |
| 189 | + |
190 | 190 | $selected = 0; |
191 | | - |
| 191 | + |
192 | 192 | foreach ( $versions as $branchPath => $branchName ) { |
193 | 193 | $wgOut->addHTML( Xml::option( $branchName, $branchPath, ($selected == 1) ) ); |
194 | | - |
| 194 | + |
195 | 195 | $selected++; |
196 | 196 | } |
197 | | - |
| 197 | + |
198 | 198 | $wgOut->addHTML( |
199 | 199 | Xml::closeElement( 'select' ) . ' ' . |
200 | 200 | Xml::submitButton( wfMsg( 'extdist-submit-version' ), array( 'name' => 'extdist_submit' ) ) . |
— | — | @@ -210,7 +210,7 @@ |
211 | 211 | } else { |
212 | 212 | $rev = $this->updateAndGetRevisionLocal( $extension, $version ); |
213 | 213 | } |
214 | | - |
| 214 | + |
215 | 215 | if ( $rev === false ) { |
216 | 216 | // Error already displayed |
217 | 217 | return; |
— | — | @@ -241,10 +241,10 @@ |
242 | 242 | ' ' . wfEscapeShellArg( $extension ) . |
243 | 243 | ( $needEF ? ' ExtensionFunctions.php' : '' ) . |
244 | 244 | ' 2>&1'; |
245 | | - |
| 245 | + |
246 | 246 | $retval = - 1; |
247 | 247 | $result = wfShellExec( $cmd, $retval ); |
248 | | - |
| 248 | + |
249 | 249 | if ( $retval ) { |
250 | 250 | $wgOut->addWikiMsg( 'extdist-tar-error', $retval ); |
251 | 251 | $wgOut->addHTML( '<pre>' . htmlspecialchars( $result ) . '</pre>' ); |
— | — | @@ -267,15 +267,15 @@ |
268 | 268 | |
269 | 269 | protected function updateAndGetRevisionLocal( $extension, $version ) { |
270 | 270 | global $wgExtDistWorkingCopy, $wgOut; |
271 | | - |
| 271 | + |
272 | 272 | // svn up |
273 | 273 | $dir = "$wgExtDistWorkingCopy/$version/extensions/$extension"; |
274 | | - |
| 274 | + |
275 | 275 | $cmd = "svn up --non-interactive " . wfEscapeShellArg( $dir ) . " 2>&1"; |
276 | 276 | $retval = - 1; |
277 | | - |
| 277 | + |
278 | 278 | $result = wfShellExec( $cmd, $retval ); |
279 | | - |
| 279 | + |
280 | 280 | if ( $retval ) { |
281 | 281 | $wgOut->addWikiMsg( 'extdist-svn-error', $result ); |
282 | 282 | return false; |
— | — | @@ -285,7 +285,7 @@ |
286 | 286 | $cmd = "svn info --non-interactive --xml " . wfEscapeShellArg( $dir ); |
287 | 287 | $retval = - 1; |
288 | 288 | $result = wfShellExec( $cmd, $retval ); |
289 | | - |
| 289 | + |
290 | 290 | if ( $retval ) { |
291 | 291 | $wgOut->addWikiMsg( 'extdist-svn-error', $result ); |
292 | 292 | return false; |
— | — | @@ -293,7 +293,7 @@ |
294 | 294 | |
295 | 295 | $sx = new SimpleXMLElement( $result ); |
296 | 296 | $rev = $sx->entry->commit['revision']; |
297 | | - |
| 297 | + |
298 | 298 | if ( !$rev || strpos( $rev, '/' ) !== false || strpos( $rev, "\000" ) !== false ) { |
299 | 299 | $wgOut->addWikiMsg( 'extdist-svn-parse-error', $result ); |
300 | 300 | return false; |
— | — | @@ -304,14 +304,14 @@ |
305 | 305 | |
306 | 306 | protected function updateAndGetRevisionRemote( $extension, $version ) { |
307 | 307 | global $wgExtDistRemoteClient, $wgOut; |
308 | | - |
| 308 | + |
309 | 309 | $cmd = json_encode( array( 'extension' => $extension, 'version' => $version ) ); |
310 | 310 | $cmd = str_replace( "\000", '', $cmd ); |
311 | | - |
| 311 | + |
312 | 312 | list( $host, $port ) = explode( ':', $wgExtDistRemoteClient, 2 ); |
313 | | - |
| 313 | + |
314 | 314 | $sock = fsockopen( $host, $port ); |
315 | | - |
| 315 | + |
316 | 316 | if ( !$sock ) { |
317 | 317 | $wgOut->addWikiMsg( 'extdist-no-remote' ); |
318 | 318 | return false; |
— | — | @@ -324,21 +324,21 @@ |
325 | 325 | $encResponse .= fread( $sock, 8192 ); |
326 | 326 | } |
327 | 327 | fclose( $sock ); |
328 | | - |
| 328 | + |
329 | 329 | $response = json_decode( $encResponse ); |
330 | | - |
| 330 | + |
331 | 331 | if ( isset( $response->error ) ) { |
332 | 332 | $info = isset( $response->errorInfo ) ? $response->errorInfo : ''; |
333 | 333 | $wgOut->addWikiMsg( $response->error, $info ); |
334 | 334 | return false; |
335 | 335 | } |
336 | | - |
| 336 | + |
337 | 337 | if ( !isset( $response->revision ) ) { |
338 | 338 | $wgOut->addWikiMsg( 'extdist-remote-invalid-response' ); |
339 | 339 | return false; |
340 | 340 | } |
341 | | - |
| 341 | + |
342 | 342 | return $response->revision; |
343 | 343 | } |
344 | | - |
| 344 | + |
345 | 345 | } |
\ No newline at end of file |