Localisation updates for core and extension messages from translatewiki.net (2009...
[mediawiki.git] / includes / specials / SpecialVersion.php
blobc9fd892a4b4604a86f1ffe6547b1d2b546df6c1e
1 <?php
3 /**
4 * Give information about the version of MediaWiki, PHP, the DB and extensions
6 * @ingroup SpecialPage
8 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
9 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
10 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
12 class SpecialVersion extends SpecialPage {
13 private $firstExtOpened = true;
15 static $viewvcUrls = array(
16 'svn+ssh://svn.wikimedia.org/svnroot/mediawiki' => 'http://svn.wikimedia.org/viewvc/mediawiki',
17 'http://svn.wikimedia.org/svnroot/mediawiki' => 'http://svn.wikimedia.org/viewvc/mediawiki',
18 # Doesn't work at the time of writing but maybe some day:
19 'https://svn.wikimedia.org/viewvc/mediawiki' => 'http://svn.wikimedia.org/viewvc/mediawiki',
22 function __construct(){
23 parent::__construct( 'Version' );
26 /**
27 * main()
29 function execute( $par ) {
30 global $wgOut, $wgMessageCache, $wgSpecialVersionShowHooks, $wgContLang;
31 $wgMessageCache->loadAllMessages();
33 $this->setHeaders();
34 $this->outputHeader();
36 $wgOut->addHTML( Xml::openElement( 'div',
37 array( 'dir' => $wgContLang->getDir() ) ) );
38 $text =
39 $this->MediaWikiCredits() .
40 $this->softwareInformation() .
41 $this->extensionCredits();
42 if ( $wgSpecialVersionShowHooks ) {
43 $text .= $this->wgHooks();
45 $wgOut->addWikiText( $text );
46 $wgOut->addHTML( $this->IPInfo() );
47 $wgOut->addHTML( '</div>' );
50 /**#@+
51 * @private
54 /**
55 * @return wiki text showing the license information
57 static function MediaWikiCredits() {
58 global $wgContLang;
60 $ret = Xml::element( 'h2', array( 'id' => 'mw-version-license' ), wfMsg( 'version-license' ) );
62 // This text is always left-to-right.
63 $ret .= '<div dir="ltr">';
64 $ret .= "__NOTOC__
65 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
66 copyright © 2001-2009 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
67 Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
68 Niklas Laxström, Domas Mituzas, Rob Church, Yuri Astrakhan, Aryeh Gregor,
69 Aaron Schulz, Andrew Garrett, Raimond Spekking, Alexandre Emsenhuber,
70 Siebrand Mazeland, Chad Horohoe and others.
72 MediaWiki is free software; you can redistribute it and/or modify
73 it under the terms of the GNU General Public License as published by
74 the Free Software Foundation; either version 2 of the License, or
75 (at your option) any later version.
77 MediaWiki is distributed in the hope that it will be useful,
78 but WITHOUT ANY WARRANTY; without even the implied warranty of
79 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
80 GNU General Public License for more details.
82 You should have received [{{SERVER}}{{SCRIPTPATH}}/COPYING a copy of the GNU General Public License]
83 along with this program; if not, write to the Free Software
84 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
85 or [http://www.gnu.org/licenses/old-licenses/gpl-2.0.html read it online].
87 $ret .= '</div>';
89 return str_replace( "\t\t", '', $ret ) . "\n";
92 /**
93 * @return wiki text showing the third party software versions (apache, php, mysql).
95 static function softwareInformation() {
96 $dbr = wfGetDB( DB_SLAVE );
98 // Put the software in an array of form 'name' => 'version'. All messages should
99 // be loaded here, so feel free to use wfMsg*() in the 'name'. Raw HTML or wikimarkup
100 // can be used
101 $software = array();
102 $software['[http://www.mediawiki.org/ MediaWiki]'] = self::getVersionLinked();
103 $software['[http://www.php.net/ PHP]'] = phpversion() . " (" . php_sapi_name() . ")";
104 $software[$dbr->getSoftwareLink()] = $dbr->getServerVersion();
106 // Allow a hook to add/remove items
107 wfRunHooks( 'SoftwareInfo', array( &$software ) );
109 $out = Xml::element( 'h2', array( 'id' => 'mw-version-software' ), wfMsg( 'version-software' ) ) .
110 Xml::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-software' ) ) .
111 "<tr>
112 <th>" . wfMsg( 'version-software-product' ) . "</th>
113 <th>" . wfMsg( 'version-software-version' ) . "</th>
114 </tr>\n";
115 foreach( $software as $name => $version ) {
116 $out .= "<tr>
117 <td>" . $name . "</td>
118 <td>" . $version . "</td>
119 </tr>\n";
121 return $out . Xml::closeElement( 'table' );
125 * Return a string of the MediaWiki version with SVN revision if available
127 * @return mixed
129 public static function getVersion( $flags = '' ) {
130 global $wgVersion, $IP;
131 wfProfileIn( __METHOD__ );
133 $info = self::getSvnInfo( $IP );
134 if ( !$info ) {
135 $version = $wgVersion;
136 } elseif( $flags === 'nodb' ) {
137 $version = "$wgVersion (r{$info['checkout-rev']})";
138 } else {
139 $version = $wgVersion .
140 wfMsg(
141 'version-svn-revision',
142 isset( $info['directory-rev'] ) ? $info['directory-rev'] : '',
143 $info['checkout-rev']
147 wfProfileOut( __METHOD__ );
148 return $version;
152 * Return a wikitext-formatted string of the MediaWiki version with a link to
153 * the SVN revision if available
155 * @return mixed
157 public static function getVersionLinked() {
158 global $wgVersion, $IP;
159 wfProfileIn( __METHOD__ );
160 $info = self::getSvnInfo( $IP );
161 if ( isset( $info['checkout-rev'] ) ) {
162 $linkText = wfMsg(
163 'version-svn-revision',
164 isset( $info['directory-rev'] ) ? $info['directory-rev'] : '',
165 $info['checkout-rev']
167 if ( isset( $info['viewvc-url'] ) ) {
168 $version = "$wgVersion [{$info['viewvc-url']} $linkText]";
169 } else {
170 $version = "$wgVersion $linkText";
172 } else {
173 $version = $wgVersion;
175 wfProfileOut( __METHOD__ );
176 return $version;
179 /** Generate wikitext showing extensions name, URL, author and description */
180 function extensionCredits() {
181 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunctions;
183 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunctions ) )
184 return '';
186 $extensionTypes = array(
187 'specialpage' => wfMsg( 'version-specialpages' ),
188 'parserhook' => wfMsg( 'version-parserhooks' ),
189 'variable' => wfMsg( 'version-variables' ),
190 'media' => wfMsg( 'version-mediahandlers' ),
191 'other' => wfMsg( 'version-other' ),
193 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
195 $out = Xml::element( 'h2', array( 'id' => 'mw-version-ext' ), wfMsg( 'version-extensions' ) ) .
196 Xml::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-ext' ) );
198 foreach ( $extensionTypes as $type => $text ) {
199 if ( isset ( $wgExtensionCredits[$type] ) && count ( $wgExtensionCredits[$type] ) ) {
200 $out .= $this->openExtType( $text );
202 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
204 foreach ( $wgExtensionCredits[$type] as $extension ) {
205 $out .= $this->formatCredits( $extension );
210 if ( count( $wgExtensionFunctions ) ) {
211 $out .= $this->openExtType( wfMsg( 'version-extension-functions' ) );
212 $out .= '<tr><td colspan="4">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
215 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
216 for ( $i = 0; $i < $cnt; ++$i )
217 $tags[$i] = "&lt;{$tags[$i]}&gt;";
218 $out .= $this->openExtType( wfMsg( 'version-parser-extensiontags' ) );
219 $out .= '<tr><td colspan="4">' . $this->listToText( $tags ). "</td></tr>\n";
222 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
223 $out .= $this->openExtType( wfMsg( 'version-parser-function-hooks' ) );
224 $out .= '<tr><td colspan="4">' . $this->listToText( $fhooks ) . "</td></tr>\n";
227 if ( count( $wgSkinExtensionFunctions ) ) {
228 $out .= $this->openExtType( wfMsg( 'version-skin-extension-functions' ) );
229 $out .= '<tr><td colspan="4">' . $this->listToText( $wgSkinExtensionFunctions ) . "</td></tr>\n";
231 $out .= Xml::closeElement( 'table' );
232 return $out;
235 /** Callback to sort extensions by type */
236 function compare( $a, $b ) {
237 global $wgLang;
238 if( $a['name'] === $b['name'] ) {
239 return 0;
240 } else {
241 return $wgLang->lc( $a['name'] ) > $wgLang->lc( $b['name'] )
243 : -1;
247 function formatCredits( $extension ) {
248 $name = isset( $extension['name'] ) ? $extension['name'] : '[no name]';
249 if ( isset( $extension['path'] ) ) {
250 $svnInfo = self::getSvnInfo( dirname($extension['path']) );
251 $directoryRev = isset( $svnInfo['directory-rev'] ) ? $svnInfo['directory-rev'] : null;
252 $checkoutRev = isset( $svnInfo['checkout-rev'] ) ? $svnInfo['checkout-rev'] : null;
253 $viewvcUrl = isset( $svnInfo['viewvc-url'] ) ? $svnInfo['viewvc-url'] : null;
254 } else {
255 $directoryRev = null;
256 $checkoutRev = null;
257 $viewvcUrl = null;
260 # Make main link (or just the name if there is no URL)
261 if ( isset( $extension['url'] ) ) {
262 $mainLink = "[{$extension['url']} $name]";
263 } else {
264 $mainLink = $name;
266 if ( isset( $extension['version'] ) ) {
267 $versionText = '<span class="mw-version-ext-version">' .
268 wfMsg( 'version-version', $extension['version'] ) .
269 '</span>';
270 } else {
271 $versionText = '';
274 # Make subversion text/link
275 if ( $checkoutRev ) {
276 $svnText = wfMsg( 'version-svn-revision', $directoryRev, $checkoutRev );
277 $svnText = isset( $viewvcUrl ) ? "[$viewvcUrl $svnText]" : $svnText;
278 } else {
279 $svnText = false;
282 # Make description text
283 $description = isset ( $extension['description'] ) ? $extension['description'] : '';
284 if( isset ( $extension['descriptionmsg'] ) ) {
285 # Look for a localized description
286 $descriptionMsg = $extension['descriptionmsg'];
287 if( is_array( $descriptionMsg ) ) {
288 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
289 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
290 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
291 $msg = wfMsg( $descriptionMsgKey, $descriptionMsg );
292 } else {
293 $msg = wfMsg( $descriptionMsg );
295 if ( !wfEmptyMsg( $descriptionMsg, $msg ) && $msg != '' ) {
296 $description = $msg;
300 if ( $svnText !== false ) {
301 $extNameVer = "<tr>
302 <td><em>$mainLink $versionText</em></td>
303 <td><em>$svnText</em></td>";
304 } else {
305 $extNameVer = "<tr>
306 <td colspan=\"2\"><em>$mainLink $versionText</em></td>";
308 $author = isset ( $extension['author'] ) ? $extension['author'] : array();
309 $extDescAuthor = "<td>$description</td>
310 <td>" . $this->listToText( (array)$author ) . "</td>
311 </tr>\n";
312 return $extNameVer . $extDescAuthor;
316 * @return string
318 function wgHooks() {
319 global $wgHooks;
321 if ( count( $wgHooks ) ) {
322 $myWgHooks = $wgHooks;
323 ksort( $myWgHooks );
325 $ret = Xml::element( 'h2', array( 'id' => 'mw-version-hooks' ), wfMsg( 'version-hooks' ) ) .
326 Xml::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) ) .
327 "<tr>
328 <th>" . wfMsg( 'version-hook-name' ) . "</th>
329 <th>" . wfMsg( 'version-hook-subscribedby' ) . "</th>
330 </tr>\n";
332 foreach ( $myWgHooks as $hook => $hooks )
333 $ret .= "<tr>
334 <td>$hook</td>
335 <td>" . $this->listToText( $hooks ) . "</td>
336 </tr>\n";
338 $ret .= Xml::closeElement( 'table' );
339 return $ret;
340 } else
341 return '';
344 private function openExtType($text, $name = null) {
345 $opt = array( 'colspan' => 4 );
346 $out = '';
348 if(!$this->firstExtOpened) {
349 // Insert a spacing line
350 $out .= '<tr class="sv-space">' . Xml::element( 'td', $opt ) . "</tr>\n";
352 $this->firstExtOpened = false;
354 if($name) { $opt['id'] = "sv-$name"; }
356 $out .= "<tr>" . Xml::element( 'th', $opt, $text) . "</tr>\n";
357 return $out;
361 * @return string
363 function IPInfo() {
364 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
365 return "<!-- visited from $ip -->\n" .
366 "<span style='display:none'>visited from $ip</span>";
370 * @param array $list
371 * @return string
373 function listToText( $list ) {
374 $cnt = count( $list );
376 if ( $cnt == 1 ) {
377 // Enforce always returning a string
378 return (string)self::arrayToString( $list[0] );
379 } elseif ( $cnt == 0 ) {
380 return '';
381 } else {
382 global $wgLang;
383 sort( $list );
384 return $wgLang->listToText( array_map( array( __CLASS__, 'arrayToString' ), $list ) );
389 * @param mixed $list Will convert an array to string if given and return
390 * the paramater unaltered otherwise
391 * @return mixed
393 static function arrayToString( $list ) {
394 if( is_array( $list ) && count( $list ) == 1 )
395 $list = $list[0];
396 if( is_object( $list ) ) {
397 $class = get_class( $list );
398 return "($class)";
399 } elseif ( !is_array( $list ) ) {
400 return $list;
401 } else {
402 if( is_object( $list[0] ) )
403 $class = get_class( $list[0] );
404 else
405 $class = $list[0];
406 return "($class, {$list[1]})";
411 * Get an associative array of information about a given path, from its .svn
412 * subdirectory. Returns false on error, such as if the directory was not
413 * checked out with subversion.
415 * Returned keys are:
416 * Required:
417 * checkout-rev The revision which was checked out
418 * Optional:
419 * directory-rev The revision when the directory was last modified
420 * url The subversion URL of the directory
421 * repo-url The base URL of the repository
422 * viewvc-url A ViewVC URL pointing to the checked-out revision
424 public static function getSvnInfo( $dir ) {
425 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
426 $entries = $dir . '/.svn/entries';
428 if( !file_exists( $entries ) ) {
429 return false;
432 $lines = file( $entries );
433 if ( !count( $lines ) ) {
434 return false;
437 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
438 if( preg_match( '/^<\?xml/', $lines[0] ) ) {
439 // subversion is release <= 1.3
440 if( !function_exists( 'simplexml_load_file' ) ) {
441 // We could fall back to expat... YUCK
442 return false;
445 // SimpleXml whines about the xmlns...
446 wfSuppressWarnings();
447 $xml = simplexml_load_file( $entries );
448 wfRestoreWarnings();
450 if( $xml ) {
451 foreach( $xml->entry as $entry ) {
452 if( $xml->entry[0]['name'] == '' ) {
453 // The directory entry should always have a revision marker.
454 if( $entry['revision'] ) {
455 return array( 'checkout-rev' => intval( $entry['revision'] ) );
460 return false;
463 // subversion is release 1.4 or above
464 if ( count( $lines ) < 11 ) {
465 return false;
467 $info = array(
468 'checkout-rev' => intval( trim( $lines[3] ) ),
469 'url' => trim( $lines[4] ),
470 'repo-url' => trim( $lines[5] ),
471 'directory-rev' => intval( trim( $lines[10] ) )
473 if ( isset( self::$viewvcUrls[$info['repo-url']] ) ) {
474 $viewvc = str_replace(
475 $info['repo-url'],
476 self::$viewvcUrls[$info['repo-url']],
477 $info['url']
479 $pathRelativeToRepo = substr( $info['url'], strlen( $info['repo-url'] ) );
480 $viewvc .= '/?pathrev=';
481 $viewvc .= urlencode( $info['checkout-rev'] );
482 $info['viewvc-url'] = $viewvc;
484 return $info;
488 * Retrieve the revision number of a Subversion working directory.
490 * @param String $dir Directory of the svn checkout
491 * @return int revision number as int
493 public static function getSvnRevision( $dir ) {
494 $info = self::getSvnInfo( $dir );
495 if ( $info === false ) {
496 return false;
497 } elseif ( isset( $info['checkout-rev'] ) ) {
498 return $info['checkout-rev'];
499 } else {
500 return false;
504 /**#@-*/