Index: trunk/phase3/includes/specials/SpecialVersion.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | | - * |
5 | 5 | * This program is free software; you can redistribute it and/or modify |
6 | 6 | * it under the terms of the GNU General Public License as published by |
7 | 7 | * the Free Software Foundation; either version 2 of the License, or |
— | — | @@ -45,6 +45,7 @@ |
46 | 46 | */ |
47 | 47 | function execute( $par ) { |
48 | 48 | global $wgOut, $wgMessageCache, $wgSpecialVersionShowHooks, $wgContLang; |
| 49 | + |
49 | 50 | $wgMessageCache->loadAllMessages(); |
50 | 51 | |
51 | 52 | $this->setHeaders(); |
— | — | @@ -53,25 +54,24 @@ |
54 | 55 | $wgOut->addHTML( Xml::openElement( 'div', |
55 | 56 | array( 'dir' => $wgContLang->getDir() ) ) ); |
56 | 57 | $text = |
57 | | - $this->MediaWikiCredits() . |
| 58 | + $this->getMediaWikiCredits() . |
58 | 59 | $this->softwareInformation() . |
59 | 60 | $this->extensionCredits(); |
60 | 61 | if ( $wgSpecialVersionShowHooks ) { |
61 | | - $text .= $this->wgHooks(); |
| 62 | + $text .= $this->getWgHooks(); |
62 | 63 | } |
| 64 | + |
63 | 65 | $wgOut->addWikiText( $text ); |
64 | 66 | $wgOut->addHTML( $this->IPInfo() ); |
65 | 67 | $wgOut->addHTML( '</div>' ); |
66 | 68 | } |
67 | 69 | |
68 | | - /**#@+ |
69 | | - * @private |
70 | | - */ |
71 | | - |
72 | 70 | /** |
73 | | - * @return wiki text showing the license information |
| 71 | + * Returns wiki text showing the license information. |
| 72 | + * |
| 73 | + * @return string |
74 | 74 | */ |
75 | | - static function MediaWikiCredits() { |
| 75 | + private static function getMediaWikiCredits() { |
76 | 76 | $ret = Xml::element( 'h2', array( 'id' => 'mw-version-license' ), wfMsg( 'version-license' ) ); |
77 | 77 | |
78 | 78 | // This text is always left-to-right. |
— | — | @@ -105,20 +105,22 @@ |
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
109 | | - * @return wiki text showing the third party software versions (apache, php, mysql). |
| 109 | + * Returns wiki text showing the third party software versions (apache, php, mysql). |
| 110 | + * |
| 111 | + * @return string |
110 | 112 | */ |
111 | 113 | static function softwareInformation() { |
112 | 114 | $dbr = wfGetDB( DB_SLAVE ); |
113 | 115 | |
114 | 116 | // Put the software in an array of form 'name' => 'version'. All messages should |
115 | 117 | // be loaded here, so feel free to use wfMsg*() in the 'name'. Raw HTML or wikimarkup |
116 | | - // can be used |
| 118 | + // can be used. |
117 | 119 | $software = array(); |
118 | 120 | $software['[http://www.mediawiki.org/ MediaWiki]'] = self::getVersionLinked(); |
119 | 121 | $software['[http://www.php.net/ PHP]'] = phpversion() . " (" . php_sapi_name() . ")"; |
120 | 122 | $software[$dbr->getSoftwareLink()] = $dbr->getServerVersion(); |
121 | 123 | |
122 | | - // Allow a hook to add/remove items |
| 124 | + // Allow a hook to add/remove items. |
123 | 125 | wfRunHooks( 'SoftwareInfo', array( &$software ) ); |
124 | 126 | |
125 | 127 | $out = Xml::element( 'h2', array( 'id' => 'mw-version-software' ), wfMsg( 'version-software' ) ) . |
— | — | @@ -127,17 +129,19 @@ |
128 | 130 | <th>" . wfMsg( 'version-software-product' ) . "</th> |
129 | 131 | <th>" . wfMsg( 'version-software-version' ) . "</th> |
130 | 132 | </tr>\n"; |
| 133 | + |
131 | 134 | foreach( $software as $name => $version ) { |
132 | 135 | $out .= "<tr> |
133 | 136 | <td>" . $name . "</td> |
134 | 137 | <td>" . $version . "</td> |
135 | 138 | </tr>\n"; |
136 | | - } |
| 139 | + } |
| 140 | + |
137 | 141 | return $out . Xml::closeElement( 'table' ); |
138 | 142 | } |
139 | 143 | |
140 | 144 | /** |
141 | | - * Return a string of the MediaWiki version with SVN revision if available |
| 145 | + * Return a string of the MediaWiki version with SVN revision if available. |
142 | 146 | * |
143 | 147 | * @return mixed |
144 | 148 | */ |
— | — | @@ -165,20 +169,23 @@ |
166 | 170 | |
167 | 171 | /** |
168 | 172 | * Return a wikitext-formatted string of the MediaWiki version with a link to |
169 | | - * the SVN revision if available |
| 173 | + * the SVN revision if available. |
170 | 174 | * |
171 | 175 | * @return mixed |
172 | 176 | */ |
173 | 177 | public static function getVersionLinked() { |
174 | 178 | global $wgVersion, $IP; |
175 | 179 | wfProfileIn( __METHOD__ ); |
| 180 | + |
176 | 181 | $info = self::getSvnInfo( $IP ); |
| 182 | + |
177 | 183 | if ( isset( $info['checkout-rev'] ) ) { |
178 | 184 | $linkText = wfMsg( |
179 | 185 | 'version-svn-revision', |
180 | 186 | isset( $info['directory-rev'] ) ? $info['directory-rev'] : '', |
181 | 187 | $info['checkout-rev'] |
182 | 188 | ); |
| 189 | + |
183 | 190 | if ( isset( $info['viewvc-url'] ) ) { |
184 | 191 | $version = "$wgVersion [{$info['viewvc-url']} $linkText]"; |
185 | 192 | } else { |
— | — | @@ -187,12 +194,13 @@ |
188 | 195 | } else { |
189 | 196 | $version = $wgVersion; |
190 | 197 | } |
| 198 | + |
191 | 199 | wfProfileOut( __METHOD__ ); |
192 | 200 | return $version; |
193 | 201 | } |
194 | 202 | |
195 | 203 | /** |
196 | | - * Generate wikitext showing extensions name, URL, author and description |
| 204 | + * Generate wikitext showing extensions name, URL, author and description. |
197 | 205 | * |
198 | 206 | * @return String: Wikitext |
199 | 207 | */ |
— | — | @@ -247,11 +255,15 @@ |
248 | 256 | $out .= $this->openExtType( wfMsg( 'version-skin-extension-functions' ), 'skin-extension-functions' ); |
249 | 257 | $out .= '<tr><td colspan="4">' . $this->listToText( $wgSkinExtensionFunctions ) . "</td></tr>\n"; |
250 | 258 | } |
| 259 | + |
251 | 260 | $out .= Xml::closeElement( 'table' ); |
| 261 | + |
252 | 262 | return $out; |
253 | 263 | } |
254 | 264 | |
255 | | - /** Callback to sort extensions by type */ |
| 265 | + /** |
| 266 | + * Callback to sort extensions by type. |
| 267 | + */ |
256 | 268 | function compare( $a, $b ) { |
257 | 269 | global $wgLang; |
258 | 270 | if( $a['name'] === $b['name'] ) { |
— | — | @@ -265,6 +277,7 @@ |
266 | 278 | |
267 | 279 | function formatCredits( $extension ) { |
268 | 280 | $name = isset( $extension['name'] ) ? $extension['name'] : '[no name]'; |
| 281 | + |
269 | 282 | if ( isset( $extension['path'] ) ) { |
270 | 283 | $svnInfo = self::getSvnInfo( dirname($extension['path']) ); |
271 | 284 | $directoryRev = isset( $svnInfo['directory-rev'] ) ? $svnInfo['directory-rev'] : null; |
— | — | @@ -276,12 +289,13 @@ |
277 | 290 | $viewvcUrl = null; |
278 | 291 | } |
279 | 292 | |
280 | | - # Make main link (or just the name if there is no URL) |
| 293 | + # Make main link (or just the name if there is no URL). |
281 | 294 | if ( isset( $extension['url'] ) ) { |
282 | 295 | $mainLink = "[{$extension['url']} $name]"; |
283 | 296 | } else { |
284 | 297 | $mainLink = $name; |
285 | 298 | } |
| 299 | + |
286 | 300 | if ( isset( $extension['version'] ) ) { |
287 | 301 | $versionText = '<span class="mw-version-ext-version">' . |
288 | 302 | wfMsg( 'version-version', $extension['version'] ) . |
— | — | @@ -290,7 +304,7 @@ |
291 | 305 | $versionText = ''; |
292 | 306 | } |
293 | 307 | |
294 | | - # Make subversion text/link |
| 308 | + # Make subversion text/link. |
295 | 309 | if ( $checkoutRev ) { |
296 | 310 | $svnText = wfMsg( 'version-svn-revision', $directoryRev, $checkoutRev ); |
297 | 311 | $svnText = isset( $viewvcUrl ) ? "[$viewvcUrl $svnText]" : $svnText; |
— | — | @@ -298,11 +312,13 @@ |
299 | 313 | $svnText = false; |
300 | 314 | } |
301 | 315 | |
302 | | - # Make description text |
| 316 | + # Make description text. |
303 | 317 | $description = isset ( $extension['description'] ) ? $extension['description'] : ''; |
| 318 | + |
304 | 319 | if( isset ( $extension['descriptionmsg'] ) ) { |
305 | | - # Look for a localized description |
| 320 | + # Look for a localized description. |
306 | 321 | $descriptionMsg = $extension['descriptionmsg']; |
| 322 | + |
307 | 323 | if( is_array( $descriptionMsg ) ) { |
308 | 324 | $descriptionMsgKey = $descriptionMsg[0]; // Get the message key |
309 | 325 | array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only |
— | — | @@ -324,19 +340,21 @@ |
325 | 341 | $extNameVer = "<tr> |
326 | 342 | <td colspan=\"2\"><em>$mainLink $versionText</em></td>"; |
327 | 343 | } |
| 344 | + |
328 | 345 | $author = isset ( $extension['author'] ) ? $extension['author'] : array(); |
329 | 346 | $extDescAuthor = "<td>$description</td> |
330 | 347 | <td>" . $this->listToText( (array)$author, false ) . "</td> |
331 | 348 | </tr>\n"; |
| 349 | + |
332 | 350 | return $extNameVer . $extDescAuthor; |
333 | 351 | } |
334 | 352 | |
335 | 353 | /** |
336 | | - * Generate wikitext showing hooks in $wgHooks |
| 354 | + * Generate wikitext showing hooks in $wgHooks. |
337 | 355 | * |
338 | 356 | * @return String: wikitext |
339 | 357 | */ |
340 | | - function wgHooks() { |
| 358 | + private function getWgHooks() { |
341 | 359 | global $wgHooks; |
342 | 360 | |
343 | 361 | if ( count( $wgHooks ) ) { |
— | — | @@ -380,21 +398,22 @@ |
381 | 399 | } |
382 | 400 | |
383 | 401 | /** |
384 | | - * Get information about client's IP address |
| 402 | + * Get information about client's IP address. |
385 | 403 | * |
386 | 404 | * @return String: HTML fragment |
387 | 405 | */ |
388 | | - function IPInfo() { |
| 406 | + private function IPInfo() { |
389 | 407 | $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) ); |
390 | 408 | return "<!-- visited from $ip -->\n" . |
391 | 409 | "<span style='display:none'>visited from $ip</span>"; |
392 | 410 | } |
393 | 411 | |
394 | 412 | /** |
395 | | - * Convert an array of items into a list for display |
| 413 | + * Convert an array of items into a list for display. |
396 | 414 | * |
397 | 415 | * @param $list Array of elements to display |
398 | 416 | * @param $sort Boolean: whether to sort the items in $list |
| 417 | + * |
399 | 418 | * @return String |
400 | 419 | */ |
401 | 420 | function listToText( $list, $sort = true ) { |
— | — | @@ -415,10 +434,11 @@ |
416 | 435 | } |
417 | 436 | |
418 | 437 | /** |
419 | | - * Convert an array or object to a string for display |
| 438 | + * Convert an array or object to a string for display. |
420 | 439 | * |
421 | 440 | * @param $list Mixed: will convert an array to string if given and return |
422 | 441 | * the paramater unaltered otherwise |
| 442 | + * |
423 | 443 | * @return Mixed |
424 | 444 | */ |
425 | 445 | static function arrayToString( $list ) { |
— | — | @@ -488,30 +508,35 @@ |
489 | 509 | } |
490 | 510 | } |
491 | 511 | } |
| 512 | + |
492 | 513 | return false; |
493 | 514 | } |
494 | 515 | |
495 | | - // subversion is release 1.4 or above |
| 516 | + // Subversion is release 1.4 or above. |
496 | 517 | if ( count( $lines ) < 11 ) { |
497 | 518 | return false; |
498 | 519 | } |
| 520 | + |
499 | 521 | $info = array( |
500 | 522 | 'checkout-rev' => intval( trim( $lines[3] ) ), |
501 | 523 | 'url' => trim( $lines[4] ), |
502 | 524 | 'repo-url' => trim( $lines[5] ), |
503 | 525 | 'directory-rev' => intval( trim( $lines[10] ) ) |
504 | 526 | ); |
| 527 | + |
505 | 528 | if ( isset( self::$viewvcUrls[$info['repo-url']] ) ) { |
506 | 529 | $viewvc = str_replace( |
507 | 530 | $info['repo-url'], |
508 | 531 | self::$viewvcUrls[$info['repo-url']], |
509 | 532 | $info['url'] |
510 | 533 | ); |
| 534 | + |
511 | 535 | $pathRelativeToRepo = substr( $info['url'], strlen( $info['repo-url'] ) ); |
512 | 536 | $viewvc .= '/?pathrev='; |
513 | 537 | $viewvc .= urlencode( $info['checkout-rev'] ); |
514 | 538 | $info['viewvc-url'] = $viewvc; |
515 | 539 | } |
| 540 | + |
516 | 541 | return $info; |
517 | 542 | } |
518 | 543 | |
— | — | @@ -519,10 +544,12 @@ |
520 | 545 | * Retrieve the revision number of a Subversion working directory. |
521 | 546 | * |
522 | 547 | * @param $dir String: directory of the svn checkout |
| 548 | + * |
523 | 549 | * @return Integer: revision number as int |
524 | 550 | */ |
525 | 551 | public static function getSvnRevision( $dir ) { |
526 | 552 | $info = self::getSvnInfo( $dir ); |
| 553 | + |
527 | 554 | if ( $info === false ) { |
528 | 555 | return false; |
529 | 556 | } elseif ( isset( $info['checkout-rev'] ) ) { |
— | — | @@ -532,5 +559,4 @@ |
533 | 560 | } |
534 | 561 | } |
535 | 562 | |
536 | | - /**#@-*/ |
537 | | -} |
| 563 | +} |
\ No newline at end of file |