4 * Give information about the version of MediaWiki, PHP, the DB and extensions
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' );
29 function execute( $par ) {
30 global $wgOut, $wgMessageCache, $wgSpecialVersionShowHooks, $wgContLang;
31 $wgMessageCache->loadAllMessages();
34 $this->outputHeader();
35 $wgOut->allowClickjacking();
37 $wgOut->addHTML( Xml::openElement( 'div',
38 array( 'dir' => $wgContLang->getDir() ) ) );
40 $this->MediaWikiCredits() .
41 $this->softwareInformation() .
42 $this->extensionCredits();
43 if ( $wgSpecialVersionShowHooks ) {
44 $text .= $this->wgHooks();
46 $wgOut->addWikiText( $text );
47 $wgOut->addHTML( $this->IPInfo() );
48 $wgOut->addHTML( '</div>' );
56 * @return wiki text showing the license information
58 static function MediaWikiCredits() {
61 $ret = Xml::element( 'h2', array( 'id' => 'mw-version-license' ), wfMsg( 'version-license' ) );
63 // This text is always left-to-right.
64 $ret .= '<div dir="ltr">';
66 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
67 copyright © 2001-2010 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
68 Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
69 Niklas Laxström, Domas Mituzas, Rob Church, Yuri Astrakhan, Aryeh Gregor,
70 Aaron Schulz, Andrew Garrett, Raimond Spekking, Alexandre Emsenhuber,
71 Siebrand Mazeland, Chad Horohoe and others.
73 MediaWiki is free software; you can redistribute it and/or modify
74 it under the terms of the GNU General Public License as published by
75 the Free Software Foundation; either version 2 of the License, or
76 (at your option) any later version.
78 MediaWiki is distributed in the hope that it will be useful,
79 but WITHOUT ANY WARRANTY; without even the implied warranty of
80 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
81 GNU General Public License for more details.
83 You should have received [{{SERVER}}{{SCRIPTPATH}}/COPYING a copy of the GNU General Public License]
84 along with this program; if not, write to the Free Software
85 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
86 or [http://www.gnu.org/licenses/old-licenses/gpl-2.0.html read it online].
90 return str_replace( "\t\t", '', $ret ) . "\n";
94 * @return wiki text showing the third party software versions (apache, php, mysql).
96 static function softwareInformation() {
97 $dbr = wfGetDB( DB_SLAVE );
99 // Put the software in an array of form 'name' => 'version'. All messages should
100 // be loaded here, so feel free to use wfMsg*() in the 'name'. Raw HTML or wikimarkup
103 $software['[http://www.mediawiki.org/ MediaWiki]'] = self::getVersionLinked();
104 $software['[http://www.php.net/ PHP]'] = phpversion() . " (" . php_sapi_name() . ")";
105 $software[$dbr->getSoftwareLink()] = $dbr->getServerVersion();
107 // Allow a hook to add/remove items
108 wfRunHooks( 'SoftwareInfo', array( &$software ) );
110 $out = Xml::element( 'h2', array( 'id' => 'mw-version-software' ), wfMsg( 'version-software' ) ) .
111 Xml::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-software' ) ) .
113 <th>" . wfMsg( 'version-software-product' ) . "</th>
114 <th>" . wfMsg( 'version-software-version' ) . "</th>
116 foreach( $software as $name => $version ) {
118 <td>" . $name . "</td>
119 <td>" . $version . "</td>
122 return $out . Xml::closeElement( 'table' );
126 * Return a string of the MediaWiki version with SVN revision if available
130 public static function getVersion( $flags = '' ) {
131 global $wgVersion, $IP;
132 wfProfileIn( __METHOD__ );
134 $info = self::getSvnInfo( $IP );
136 $version = $wgVersion;
137 } elseif( $flags === 'nodb' ) {
138 $version = "$wgVersion (r{$info['checkout-rev']})";
140 $version = $wgVersion . ' ' .
142 'version-svn-revision',
143 isset( $info['directory-rev'] ) ? $info['directory-rev'] : '',
144 $info['checkout-rev']
148 wfProfileOut( __METHOD__ );
153 * Return a wikitext-formatted string of the MediaWiki version with a link to
154 * the SVN revision if available
158 public static function getVersionLinked() {
159 global $wgVersion, $IP;
160 wfProfileIn( __METHOD__ );
161 $info = self::getSvnInfo( $IP );
162 if ( isset( $info['checkout-rev'] ) ) {
164 'version-svn-revision',
165 isset( $info['directory-rev'] ) ? $info['directory-rev'] : '',
166 $info['checkout-rev']
168 if ( isset( $info['viewvc-url'] ) ) {
169 $version = "$wgVersion [{$info['viewvc-url']} $linkText]";
171 $version = "$wgVersion $linkText";
174 $version = $wgVersion;
176 wfProfileOut( __METHOD__ );
180 /** Generate wikitext showing extensions name, URL, author and description */
181 function extensionCredits() {
182 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunctions;
184 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunctions ) )
187 $extensionTypes = array(
188 'specialpage' => wfMsg( 'version-specialpages' ),
189 'parserhook' => wfMsg( 'version-parserhooks' ),
190 'variable' => wfMsg( 'version-variables' ),
191 'media' => wfMsg( 'version-mediahandlers' ),
192 'other' => wfMsg( 'version-other' ),
194 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
196 $out = Xml::element( 'h2', array( 'id' => 'mw-version-ext' ), wfMsg( 'version-extensions' ) ) .
197 Xml::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-ext' ) );
199 foreach ( $extensionTypes as $type => $text ) {
200 if ( isset ( $wgExtensionCredits[$type] ) && count ( $wgExtensionCredits[$type] ) ) {
201 $out .= $this->openExtType( $text, 'credits-' . $type );
203 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
205 foreach ( $wgExtensionCredits[$type] as $extension ) {
206 $out .= $this->formatCredits( $extension );
211 if ( count( $wgExtensionFunctions ) ) {
212 $out .= $this->openExtType( wfMsg( 'version-extension-functions' ), 'extension-functions' );
213 $out .= '<tr><td colspan="4">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
216 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
217 for ( $i = 0; $i < $cnt; ++$i )
218 $tags[$i] = "<{$tags[$i]}>";
219 $out .= $this->openExtType( wfMsg( 'version-parser-extensiontags' ), 'parser-tags' );
220 $out .= '<tr><td colspan="4">' . $this->listToText( $tags ). "</td></tr>\n";
223 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
224 $out .= $this->openExtType( wfMsg( 'version-parser-function-hooks' ), 'parser-function-hooks' );
225 $out .= '<tr><td colspan="4">' . $this->listToText( $fhooks ) . "</td></tr>\n";
228 if ( count( $wgSkinExtensionFunctions ) ) {
229 $out .= $this->openExtType( wfMsg( 'version-skin-extension-functions' ), 'skin-extension-functions' );
230 $out .= '<tr><td colspan="4">' . $this->listToText( $wgSkinExtensionFunctions ) . "</td></tr>\n";
232 $out .= Xml::closeElement( 'table' );
236 /** Callback to sort extensions by type */
237 function compare( $a, $b ) {
239 if( $a['name'] === $b['name'] ) {
242 return $wgLang->lc( $a['name'] ) > $wgLang->lc( $b['name'] )
248 function formatCredits( $extension ) {
249 $name = isset( $extension['name'] ) ? $extension['name'] : '[no name]';
250 if ( isset( $extension['path'] ) ) {
251 $svnInfo = self::getSvnInfo( dirname($extension['path']) );
252 $directoryRev = isset( $svnInfo['directory-rev'] ) ? $svnInfo['directory-rev'] : null;
253 $checkoutRev = isset( $svnInfo['checkout-rev'] ) ? $svnInfo['checkout-rev'] : null;
254 $viewvcUrl = isset( $svnInfo['viewvc-url'] ) ? $svnInfo['viewvc-url'] : null;
256 $directoryRev = null;
261 # Make main link (or just the name if there is no URL)
262 if ( isset( $extension['url'] ) ) {
263 $mainLink = "[{$extension['url']} $name]";
267 if ( isset( $extension['version'] ) ) {
268 $versionText = '<span class="mw-version-ext-version">' .
269 wfMsg( 'version-version', $extension['version'] ) .
275 # Make subversion text/link
276 if ( $checkoutRev ) {
277 $svnText = wfMsg( 'version-svn-revision', $directoryRev, $checkoutRev );
278 $svnText = isset( $viewvcUrl ) ? "[$viewvcUrl $svnText]" : $svnText;
283 # Make description text
284 $description = isset ( $extension['description'] ) ? $extension['description'] : '';
285 if( isset ( $extension['descriptionmsg'] ) ) {
286 # Look for a localized description
287 $descriptionMsg = $extension['descriptionmsg'];
288 if( is_array( $descriptionMsg ) ) {
289 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
290 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
291 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
292 $msg = wfMsg( $descriptionMsgKey, $descriptionMsg );
294 $msg = wfMsg( $descriptionMsg );
296 if ( !wfEmptyMsg( $descriptionMsg, $msg ) && $msg != '' ) {
301 if ( $svnText !== false ) {
303 <td><em>$mainLink $versionText</em></td>
304 <td><em>$svnText</em></td>";
307 <td colspan=\"2\"><em>$mainLink $versionText</em></td>";
309 $author = isset ( $extension['author'] ) ? $extension['author'] : array();
310 $extDescAuthor = "<td>$description</td>
311 <td>" . $this->listToText( (array)$author, false ) . "</td>
313 return $extNameVer . $extDescAuthor;
322 if ( count( $wgHooks ) ) {
323 $myWgHooks = $wgHooks;
326 $ret = Xml::element( 'h2', array( 'id' => 'mw-version-hooks' ), wfMsg( 'version-hooks' ) ) .
327 Xml::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) ) .
329 <th>" . wfMsg( 'version-hook-name' ) . "</th>
330 <th>" . wfMsg( 'version-hook-subscribedby' ) . "</th>
333 foreach ( $myWgHooks as $hook => $hooks )
336 <td>" . $this->listToText( $hooks ) . "</td>
339 $ret .= Xml::closeElement( 'table' );
345 private function openExtType( $text, $name = null ) {
346 $opt = array( 'colspan' => 4 );
349 if( !$this->firstExtOpened ) {
350 // Insert a spacing line
351 $out .= '<tr class="sv-space">' . Xml::element( 'td', $opt ) . "</tr>\n";
353 $this->firstExtOpened = false;
356 $opt['id'] = "sv-$name";
358 $out .= "<tr>" . Xml::element( 'th', $opt, $text ) . "</tr>\n";
366 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
367 return "<!-- visited from $ip -->\n" .
368 "<span style='display:none'>visited from $ip</span>";
376 function listToText( $list, $sort = true ) {
377 $cnt = count( $list );
380 // Enforce always returning a string
381 return (string)self::arrayToString( $list[0] );
382 } elseif ( $cnt == 0 ) {
389 return $wgLang->listToText( array_map( array( __CLASS__, 'arrayToString' ), $list ) );
394 * @param mixed $list Will convert an array to string if given and return
395 * the paramater unaltered otherwise
398 static function arrayToString( $list ) {
399 if( is_array( $list ) && count( $list ) == 1 )
401 if( is_object( $list ) ) {
402 $class = get_class( $list );
404 } elseif ( !is_array( $list ) ) {
407 if( is_object( $list[0] ) )
408 $class = get_class( $list[0] );
411 return "($class, {$list[1]})";
416 * Get an associative array of information about a given path, from its .svn
417 * subdirectory. Returns false on error, such as if the directory was not
418 * checked out with subversion.
422 * checkout-rev The revision which was checked out
424 * directory-rev The revision when the directory was last modified
425 * url The subversion URL of the directory
426 * repo-url The base URL of the repository
427 * viewvc-url A ViewVC URL pointing to the checked-out revision
429 public static function getSvnInfo( $dir ) {
430 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
431 $entries = $dir . '/.svn/entries';
433 if( !file_exists( $entries ) ) {
437 $lines = file( $entries );
438 if ( !count( $lines ) ) {
442 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
443 if( preg_match( '/^<\?xml/', $lines[0] ) ) {
444 // subversion is release <= 1.3
445 if( !function_exists( 'simplexml_load_file' ) ) {
446 // We could fall back to expat... YUCK
450 // SimpleXml whines about the xmlns...
451 wfSuppressWarnings();
452 $xml = simplexml_load_file( $entries );
456 foreach( $xml->entry as $entry ) {
457 if( $xml->entry[0]['name'] == '' ) {
458 // The directory entry should always have a revision marker.
459 if( $entry['revision'] ) {
460 return array( 'checkout-rev' => intval( $entry['revision'] ) );
468 // subversion is release 1.4 or above
469 if ( count( $lines ) < 11 ) {
473 'checkout-rev' => intval( trim( $lines[3] ) ),
474 'url' => trim( $lines[4] ),
475 'repo-url' => trim( $lines[5] ),
476 'directory-rev' => intval( trim( $lines[10] ) )
478 if ( isset( self::$viewvcUrls[$info['repo-url']] ) ) {
479 $viewvc = str_replace(
481 self::$viewvcUrls[$info['repo-url']],
484 $pathRelativeToRepo = substr( $info['url'], strlen( $info['repo-url'] ) );
485 $viewvc .= '/?pathrev=';
486 $viewvc .= urlencode( $info['checkout-rev'] );
487 $info['viewvc-url'] = $viewvc;
493 * Retrieve the revision number of a Subversion working directory.
495 * @param String $dir Directory of the svn checkout
496 * @return int revision number as int
498 public static function getSvnRevision( $dir ) {
499 $info = self::getSvnInfo( $dir );
500 if ( $info === false ) {
502 } elseif ( isset( $info['checkout-rev'] ) ) {
503 return $info['checkout-rev'];