r70313 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70312‎ | r70313 | r70314 >
Date:03:44, 2 August 2010
Author:jeroendedauw
Status:ok
Tags:
Comment:
Documentation and style improvements
Modified paths:
  • /trunk/phase3/includes/specials/SpecialVersion.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialVersion.php
@@ -1,6 +1,6 @@
22 <?php
 3+
34 /**
4 - *
55 * This program is free software; you can redistribute it and/or modify
66 * it under the terms of the GNU General Public License as published by
77 * the Free Software Foundation; either version 2 of the License, or
@@ -45,6 +45,7 @@
4646 */
4747 function execute( $par ) {
4848 global $wgOut, $wgMessageCache, $wgSpecialVersionShowHooks, $wgContLang;
 49+
4950 $wgMessageCache->loadAllMessages();
5051
5152 $this->setHeaders();
@@ -53,25 +54,24 @@
5455 $wgOut->addHTML( Xml::openElement( 'div',
5556 array( 'dir' => $wgContLang->getDir() ) ) );
5657 $text =
57 - $this->MediaWikiCredits() .
 58+ $this->getMediaWikiCredits() .
5859 $this->softwareInformation() .
5960 $this->extensionCredits();
6061 if ( $wgSpecialVersionShowHooks ) {
61 - $text .= $this->wgHooks();
 62+ $text .= $this->getWgHooks();
6263 }
 64+
6365 $wgOut->addWikiText( $text );
6466 $wgOut->addHTML( $this->IPInfo() );
6567 $wgOut->addHTML( '</div>' );
6668 }
6769
68 - /**#@+
69 - * @private
70 - */
71 -
7270 /**
73 - * @return wiki text showing the license information
 71+ * Returns wiki text showing the license information.
 72+ *
 73+ * @return string
7474 */
75 - static function MediaWikiCredits() {
 75+ private static function getMediaWikiCredits() {
7676 $ret = Xml::element( 'h2', array( 'id' => 'mw-version-license' ), wfMsg( 'version-license' ) );
7777
7878 // This text is always left-to-right.
@@ -105,20 +105,22 @@
106106 }
107107
108108 /**
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
110112 */
111113 static function softwareInformation() {
112114 $dbr = wfGetDB( DB_SLAVE );
113115
114116 // Put the software in an array of form 'name' => 'version'. All messages should
115117 // be loaded here, so feel free to use wfMsg*() in the 'name'. Raw HTML or wikimarkup
116 - // can be used
 118+ // can be used.
117119 $software = array();
118120 $software['[http://www.mediawiki.org/ MediaWiki]'] = self::getVersionLinked();
119121 $software['[http://www.php.net/ PHP]'] = phpversion() . " (" . php_sapi_name() . ")";
120122 $software[$dbr->getSoftwareLink()] = $dbr->getServerVersion();
121123
122 - // Allow a hook to add/remove items
 124+ // Allow a hook to add/remove items.
123125 wfRunHooks( 'SoftwareInfo', array( &$software ) );
124126
125127 $out = Xml::element( 'h2', array( 'id' => 'mw-version-software' ), wfMsg( 'version-software' ) ) .
@@ -127,17 +129,19 @@
128130 <th>" . wfMsg( 'version-software-product' ) . "</th>
129131 <th>" . wfMsg( 'version-software-version' ) . "</th>
130132 </tr>\n";
 133+
131134 foreach( $software as $name => $version ) {
132135 $out .= "<tr>
133136 <td>" . $name . "</td>
134137 <td>" . $version . "</td>
135138 </tr>\n";
136 - }
 139+ }
 140+
137141 return $out . Xml::closeElement( 'table' );
138142 }
139143
140144 /**
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.
142146 *
143147 * @return mixed
144148 */
@@ -165,20 +169,23 @@
166170
167171 /**
168172 * 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.
170174 *
171175 * @return mixed
172176 */
173177 public static function getVersionLinked() {
174178 global $wgVersion, $IP;
175179 wfProfileIn( __METHOD__ );
 180+
176181 $info = self::getSvnInfo( $IP );
 182+
177183 if ( isset( $info['checkout-rev'] ) ) {
178184 $linkText = wfMsg(
179185 'version-svn-revision',
180186 isset( $info['directory-rev'] ) ? $info['directory-rev'] : '',
181187 $info['checkout-rev']
182188 );
 189+
183190 if ( isset( $info['viewvc-url'] ) ) {
184191 $version = "$wgVersion [{$info['viewvc-url']} $linkText]";
185192 } else {
@@ -187,12 +194,13 @@
188195 } else {
189196 $version = $wgVersion;
190197 }
 198+
191199 wfProfileOut( __METHOD__ );
192200 return $version;
193201 }
194202
195203 /**
196 - * Generate wikitext showing extensions name, URL, author and description
 204+ * Generate wikitext showing extensions name, URL, author and description.
197205 *
198206 * @return String: Wikitext
199207 */
@@ -247,11 +255,15 @@
248256 $out .= $this->openExtType( wfMsg( 'version-skin-extension-functions' ), 'skin-extension-functions' );
249257 $out .= '<tr><td colspan="4">' . $this->listToText( $wgSkinExtensionFunctions ) . "</td></tr>\n";
250258 }
 259+
251260 $out .= Xml::closeElement( 'table' );
 261+
252262 return $out;
253263 }
254264
255 - /** Callback to sort extensions by type */
 265+ /**
 266+ * Callback to sort extensions by type.
 267+ */
256268 function compare( $a, $b ) {
257269 global $wgLang;
258270 if( $a['name'] === $b['name'] ) {
@@ -265,6 +277,7 @@
266278
267279 function formatCredits( $extension ) {
268280 $name = isset( $extension['name'] ) ? $extension['name'] : '[no name]';
 281+
269282 if ( isset( $extension['path'] ) ) {
270283 $svnInfo = self::getSvnInfo( dirname($extension['path']) );
271284 $directoryRev = isset( $svnInfo['directory-rev'] ) ? $svnInfo['directory-rev'] : null;
@@ -276,12 +289,13 @@
277290 $viewvcUrl = null;
278291 }
279292
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).
281294 if ( isset( $extension['url'] ) ) {
282295 $mainLink = "[{$extension['url']} $name]";
283296 } else {
284297 $mainLink = $name;
285298 }
 299+
286300 if ( isset( $extension['version'] ) ) {
287301 $versionText = '<span class="mw-version-ext-version">' .
288302 wfMsg( 'version-version', $extension['version'] ) .
@@ -290,7 +304,7 @@
291305 $versionText = '';
292306 }
293307
294 - # Make subversion text/link
 308+ # Make subversion text/link.
295309 if ( $checkoutRev ) {
296310 $svnText = wfMsg( 'version-svn-revision', $directoryRev, $checkoutRev );
297311 $svnText = isset( $viewvcUrl ) ? "[$viewvcUrl $svnText]" : $svnText;
@@ -298,11 +312,13 @@
299313 $svnText = false;
300314 }
301315
302 - # Make description text
 316+ # Make description text.
303317 $description = isset ( $extension['description'] ) ? $extension['description'] : '';
 318+
304319 if( isset ( $extension['descriptionmsg'] ) ) {
305 - # Look for a localized description
 320+ # Look for a localized description.
306321 $descriptionMsg = $extension['descriptionmsg'];
 322+
307323 if( is_array( $descriptionMsg ) ) {
308324 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
309325 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
@@ -324,19 +340,21 @@
325341 $extNameVer = "<tr>
326342 <td colspan=\"2\"><em>$mainLink $versionText</em></td>";
327343 }
 344+
328345 $author = isset ( $extension['author'] ) ? $extension['author'] : array();
329346 $extDescAuthor = "<td>$description</td>
330347 <td>" . $this->listToText( (array)$author, false ) . "</td>
331348 </tr>\n";
 349+
332350 return $extNameVer . $extDescAuthor;
333351 }
334352
335353 /**
336 - * Generate wikitext showing hooks in $wgHooks
 354+ * Generate wikitext showing hooks in $wgHooks.
337355 *
338356 * @return String: wikitext
339357 */
340 - function wgHooks() {
 358+ private function getWgHooks() {
341359 global $wgHooks;
342360
343361 if ( count( $wgHooks ) ) {
@@ -380,21 +398,22 @@
381399 }
382400
383401 /**
384 - * Get information about client's IP address
 402+ * Get information about client's IP address.
385403 *
386404 * @return String: HTML fragment
387405 */
388 - function IPInfo() {
 406+ private function IPInfo() {
389407 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
390408 return "<!-- visited from $ip -->\n" .
391409 "<span style='display:none'>visited from $ip</span>";
392410 }
393411
394412 /**
395 - * Convert an array of items into a list for display
 413+ * Convert an array of items into a list for display.
396414 *
397415 * @param $list Array of elements to display
398416 * @param $sort Boolean: whether to sort the items in $list
 417+ *
399418 * @return String
400419 */
401420 function listToText( $list, $sort = true ) {
@@ -415,10 +434,11 @@
416435 }
417436
418437 /**
419 - * Convert an array or object to a string for display
 438+ * Convert an array or object to a string for display.
420439 *
421440 * @param $list Mixed: will convert an array to string if given and return
422441 * the paramater unaltered otherwise
 442+ *
423443 * @return Mixed
424444 */
425445 static function arrayToString( $list ) {
@@ -488,30 +508,35 @@
489509 }
490510 }
491511 }
 512+
492513 return false;
493514 }
494515
495 - // subversion is release 1.4 or above
 516+ // Subversion is release 1.4 or above.
496517 if ( count( $lines ) < 11 ) {
497518 return false;
498519 }
 520+
499521 $info = array(
500522 'checkout-rev' => intval( trim( $lines[3] ) ),
501523 'url' => trim( $lines[4] ),
502524 'repo-url' => trim( $lines[5] ),
503525 'directory-rev' => intval( trim( $lines[10] ) )
504526 );
 527+
505528 if ( isset( self::$viewvcUrls[$info['repo-url']] ) ) {
506529 $viewvc = str_replace(
507530 $info['repo-url'],
508531 self::$viewvcUrls[$info['repo-url']],
509532 $info['url']
510533 );
 534+
511535 $pathRelativeToRepo = substr( $info['url'], strlen( $info['repo-url'] ) );
512536 $viewvc .= '/?pathrev=';
513537 $viewvc .= urlencode( $info['checkout-rev'] );
514538 $info['viewvc-url'] = $viewvc;
515539 }
 540+
516541 return $info;
517542 }
518543
@@ -519,10 +544,12 @@
520545 * Retrieve the revision number of a Subversion working directory.
521546 *
522547 * @param $dir String: directory of the svn checkout
 548+ *
523549 * @return Integer: revision number as int
524550 */
525551 public static function getSvnRevision( $dir ) {
526552 $info = self::getSvnInfo( $dir );
 553+
527554 if ( $info === false ) {
528555 return false;
529556 } elseif ( isset( $info['checkout-rev'] ) ) {
@@ -532,5 +559,4 @@
533560 }
534561 }
535562
536 - /**#@-*/
537 -}
 563+}
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r70317Follow up to r70313jeroendedauw04:41, 2 August 2010

Status & tagging log