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();
36 $wgOut->addHTML( Xml
::openElement( 'div',
37 array( 'dir' => $wgContLang->getDir() ) ) );
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>' );
55 * @return wiki text showing the license information
57 static function MediaWikiCredits() {
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">';
65 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
66 copyright © 2001-2010 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].
89 return str_replace( "\t\t", '', $ret ) . "\n";
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
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' ) ) .
112 <th>" . wfMsg( 'version-software-product' ) . "</th>
113 <th>" . wfMsg( 'version-software-version' ) . "</th>
115 foreach( $software as $name => $version ) {
117 <td>" . $name . "</td>
118 <td>" . $version . "</td>
121 return $out . Xml
::closeElement( 'table' );
125 * Return a string of the MediaWiki version with SVN revision if available
129 public static function getVersion( $flags = '' ) {
130 global $wgVersion, $IP;
131 wfProfileIn( __METHOD__
);
133 $info = self
::getSvnInfo( $IP );
135 $version = $wgVersion;
136 } elseif( $flags === 'nodb' ) {
137 $version = "$wgVersion (r{$info['checkout-rev']})";
139 $version = $wgVersion . ' ' .
141 'version-svn-revision',
142 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
143 $info['checkout-rev']
147 wfProfileOut( __METHOD__
);
152 * Return a wikitext-formatted string of the MediaWiki version with a link to
153 * the SVN revision if available
157 public static function getVersionLinked() {
158 global $wgVersion, $IP;
159 wfProfileIn( __METHOD__
);
160 $info = self
::getSvnInfo( $IP );
161 if ( isset( $info['checkout-rev'] ) ) {
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]";
170 $version = "$wgVersion $linkText";
173 $version = $wgVersion;
175 wfProfileOut( __METHOD__
);
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 ) )
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, 'credits-' . $type );
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' ), '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] = "<{$tags[$i]}>";
218 $out .= $this->openExtType( wfMsg( 'version-parser-extensiontags' ), 'parser-tags' );
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' ), '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' ), 'skin-extension-functions' );
229 $out .= '<tr><td colspan="4">' . $this->listToText( $wgSkinExtensionFunctions ) . "</td></tr>\n";
231 $out .= Xml
::closeElement( 'table' );
235 /** Callback to sort extensions by type */
236 function compare( $a, $b ) {
238 if( $a['name'] === $b['name'] ) {
241 return $wgLang->lc( $a['name'] ) > $wgLang->lc( $b['name'] )
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;
255 $directoryRev = null;
260 # Make main link (or just the name if there is no URL)
261 if ( isset( $extension['url'] ) ) {
262 $mainLink = "[{$extension['url']} $name]";
266 if ( isset( $extension['version'] ) ) {
267 $versionText = '<span class="mw-version-ext-version">' .
268 wfMsg( 'version-version', $extension['version'] ) .
274 # Make subversion text/link
275 if ( $checkoutRev ) {
276 $svnText = wfMsg( 'version-svn-revision', $directoryRev, $checkoutRev );
277 $svnText = isset( $viewvcUrl ) ?
"[$viewvcUrl $svnText]" : $svnText;
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 );
293 $msg = wfMsg( $descriptionMsg );
295 if ( !wfEmptyMsg( $descriptionMsg, $msg ) && $msg != '' ) {
300 if ( $svnText !== false ) {
302 <td><em>$mainLink $versionText</em></td>
303 <td><em>$svnText</em></td>";
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>
312 return $extNameVer . $extDescAuthor;
321 if ( count( $wgHooks ) ) {
322 $myWgHooks = $wgHooks;
325 $ret = Xml
::element( 'h2', array( 'id' => 'mw-version-hooks' ), wfMsg( 'version-hooks' ) ) .
326 Xml
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) ) .
328 <th>" . wfMsg( 'version-hook-name' ) . "</th>
329 <th>" . wfMsg( 'version-hook-subscribedby' ) . "</th>
332 foreach ( $myWgHooks as $hook => $hooks )
335 <td>" . $this->listToText( $hooks ) . "</td>
338 $ret .= Xml
::closeElement( 'table' );
344 private function openExtType( $text, $name = null ) {
345 $opt = array( 'colspan' => 4 );
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;
355 $opt['id'] = "sv-$name";
357 $out .= "<tr>" . Xml
::element( 'th', $opt, $text ) . "</tr>\n";
365 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
366 return "<!-- visited from $ip -->\n" .
367 "<span style='display:none'>visited from $ip</span>";
374 function listToText( $list ) {
375 $cnt = count( $list );
378 // Enforce always returning a string
379 return (string)self
::arrayToString( $list[0] );
380 } elseif ( $cnt == 0 ) {
385 return $wgLang->listToText( array_map( array( __CLASS__
, 'arrayToString' ), $list ) );
390 * @param mixed $list Will convert an array to string if given and return
391 * the paramater unaltered otherwise
394 static function arrayToString( $list ) {
395 if( is_array( $list ) && count( $list ) == 1 )
397 if( is_object( $list ) ) {
398 $class = get_class( $list );
400 } elseif ( !is_array( $list ) ) {
403 if( is_object( $list[0] ) )
404 $class = get_class( $list[0] );
407 return "($class, {$list[1]})";
412 * Get an associative array of information about a given path, from its .svn
413 * subdirectory. Returns false on error, such as if the directory was not
414 * checked out with subversion.
418 * checkout-rev The revision which was checked out
420 * directory-rev The revision when the directory was last modified
421 * url The subversion URL of the directory
422 * repo-url The base URL of the repository
423 * viewvc-url A ViewVC URL pointing to the checked-out revision
425 public static function getSvnInfo( $dir ) {
426 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
427 $entries = $dir . '/.svn/entries';
429 if( !file_exists( $entries ) ) {
433 $lines = file( $entries );
434 if ( !count( $lines ) ) {
438 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
439 if( preg_match( '/^<\?xml/', $lines[0] ) ) {
440 // subversion is release <= 1.3
441 if( !function_exists( 'simplexml_load_file' ) ) {
442 // We could fall back to expat... YUCK
446 // SimpleXml whines about the xmlns...
447 wfSuppressWarnings();
448 $xml = simplexml_load_file( $entries );
452 foreach( $xml->entry
as $entry ) {
453 if( $xml->entry
[0]['name'] == '' ) {
454 // The directory entry should always have a revision marker.
455 if( $entry['revision'] ) {
456 return array( 'checkout-rev' => intval( $entry['revision'] ) );
464 // subversion is release 1.4 or above
465 if ( count( $lines ) < 11 ) {
469 'checkout-rev' => intval( trim( $lines[3] ) ),
470 'url' => trim( $lines[4] ),
471 'repo-url' => trim( $lines[5] ),
472 'directory-rev' => intval( trim( $lines[10] ) )
474 if ( isset( self
::$viewvcUrls[$info['repo-url']] ) ) {
475 $viewvc = str_replace(
477 self
::$viewvcUrls[$info['repo-url']],
480 $pathRelativeToRepo = substr( $info['url'], strlen( $info['repo-url'] ) );
481 $viewvc .= '/?pathrev=';
482 $viewvc .= urlencode( $info['checkout-rev'] );
483 $info['viewvc-url'] = $viewvc;
489 * Retrieve the revision number of a Subversion working directory.
491 * @param String $dir Directory of the svn checkout
492 * @return int revision number as int
494 public static function getSvnRevision( $dir ) {
495 $info = self
::getSvnInfo( $dir );
496 if ( $info === false ) {
498 } elseif ( isset( $info['checkout-rev'] ) ) {
499 return $info['checkout-rev'];