66c621dc7ae6487a33dcf4b9e9e12f0225aa896f
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 if( $wgContLang->isRTL() ) {
37 $wgOut->addHTML( '<div dir="rtl">' );
39 $wgOut->addHTML( '<div dir="ltr">' );
42 $this->MediaWikiCredits() .
43 $this->softwareInformation() .
44 $this->extensionCredits();
45 if ( $wgSpecialVersionShowHooks ) {
46 $text .= $this->wgHooks();
48 $wgOut->addWikiText( $text );
49 $wgOut->addHTML( $this->IPInfo() );
50 $wgOut->addHTML( '</div>' );
58 * @return wiki text showing the license information
60 static function MediaWikiCredits() {
63 $ret = Xml
::element( 'h2', array( 'id' => 'mw-version-license' ), wfMsg( 'version-license' ) );
65 // This text is always left-to-right.
66 $ret .= '<div dir="ltr">';
68 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
69 copyright © 2001-2009 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
70 Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
71 Niklas Laxström, Domas Mituzas, Rob Church, Yuri Astrakhan, Aryeh Gregor,
72 Aaron Schulz, Andrew Garrett, Raimond Spekking, Alexandre Emsenhuber,
73 Siebrand Mazeland, Chad Horohoe and others.
75 MediaWiki is free software; you can redistribute it and/or modify
76 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
78 (at your option) any later version.
80 MediaWiki is distributed in the hope that it will be useful,
81 but WITHOUT ANY WARRANTY; without even the implied warranty of
82 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83 GNU General Public License for more details.
85 You should have received [{{SERVER}}{{SCRIPTPATH}}/COPYING a copy of the GNU General Public License]
86 along with this program; if not, write to the Free Software
87 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
88 or [http://www.gnu.org/licenses/old-licenses/gpl-2.0.html read it online].
92 return str_replace( "\t\t", '', $ret ) . "\n";
96 * @return wiki text showing the third party software versions (apache, php, mysql).
98 static function softwareInformation() {
99 $dbr = wfGetDB( DB_SLAVE
);
101 // Put the software in an array of form 'name' => 'version'. All messages should
102 // be loaded here, so feel free to use wfMsg*() in the 'name'. Raw HTML or wikimarkup
105 $software['[http://www.mediawiki.org/ MediaWiki]'] = self
::getVersionLinked();
106 $software['[http://www.php.net/ PHP]'] = phpversion() . " (" . php_sapi_name() . ")";
107 $software[$dbr->getSoftwareLink()] = $dbr->getServerVersion();
109 // Allow a hook to add/remove items
110 wfRunHooks( 'SoftwareInfo', array( &$software ) );
112 $out = Xml
::element( 'h2', array( 'id' => 'mw-version-software' ), wfMsg( 'version-software' ) ) .
113 Xml
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-software' ) ) .
115 <th>" . wfMsg( 'version-software-product' ) . "</th>
116 <th>" . wfMsg( 'version-software-version' ) . "</th>
118 foreach( $software as $name => $version ) {
120 <td>" . $name . "</td>
121 <td>" . $version . "</td>
124 return $out . Xml
::closeElement( 'table' );
128 * Return a string of the MediaWiki version with SVN revision if available
132 public static function getVersion( $flags = '' ) {
133 global $wgVersion, $IP;
134 wfProfileIn( __METHOD__
);
136 $info = self
::getSvnInfo( $IP );
138 $version = $wgVersion;
139 } elseif( $flags === 'nodb' ) {
140 $version = "$wgVersion (r{$info['checkout-rev']})";
142 $version = $wgVersion .
144 'version-svn-revision',
145 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
146 $info['checkout-rev']
150 wfProfileOut( __METHOD__
);
155 * Return a wikitext-formatted string of the MediaWiki version with a link to
156 * the SVN revision if available
160 public static function getVersionLinked() {
161 global $wgVersion, $IP;
162 wfProfileIn( __METHOD__
);
163 $info = self
::getSvnInfo( $IP );
164 if ( isset( $info['checkout-rev'] ) ) {
166 'version-svn-revision',
167 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
168 $info['checkout-rev']
170 if ( isset( $info['viewvc-url'] ) ) {
171 $version = "$wgVersion [{$info['viewvc-url']} $linkText]";
173 $version = "$wgVersion $linkText";
176 $version = $wgVersion;
178 wfProfileOut( __METHOD__
);
182 /** Generate wikitext showing extensions name, URL, author and description */
183 function extensionCredits() {
184 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunctions;
186 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunctions ) )
189 $extensionTypes = array(
190 'specialpage' => wfMsg( 'version-specialpages' ),
191 'parserhook' => wfMsg( 'version-parserhooks' ),
192 'variable' => wfMsg( 'version-variables' ),
193 'media' => wfMsg( 'version-mediahandlers' ),
194 'other' => wfMsg( 'version-other' ),
196 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
198 $out = Xml
::element( 'h2', array( 'id' => 'mw-version-ext' ), wfMsg( 'version-extensions' ) ) .
199 Xml
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-ext' ) );
201 foreach ( $extensionTypes as $type => $text ) {
202 if ( isset ( $wgExtensionCredits[$type] ) && count ( $wgExtensionCredits[$type] ) ) {
203 $out .= $this->openExtType( $text );
205 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
207 foreach ( $wgExtensionCredits[$type] as $extension ) {
208 $out .= $this->formatCredits( $extension );
213 if ( count( $wgExtensionFunctions ) ) {
214 $out .= $this->openExtType( wfMsg( 'version-extension-functions' ) );
215 $out .= '<tr><td colspan="4">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
218 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
219 for ( $i = 0; $i < $cnt; ++
$i )
220 $tags[$i] = "<{$tags[$i]}>";
221 $out .= $this->openExtType( wfMsg( 'version-parser-extensiontags' ) );
222 $out .= '<tr><td colspan="4">' . $this->listToText( $tags ). "</td></tr>\n";
225 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
226 $out .= $this->openExtType( wfMsg( 'version-parser-function-hooks' ) );
227 $out .= '<tr><td colspan="4">' . $this->listToText( $fhooks ) . "</td></tr>\n";
230 if ( count( $wgSkinExtensionFunctions ) ) {
231 $out .= $this->openExtType( wfMsg( 'version-skin-extension-functions' ) );
232 $out .= '<tr><td colspan="4">' . $this->listToText( $wgSkinExtensionFunctions ) . "</td></tr>\n";
234 $out .= Xml
::closeElement( 'table' );
238 /** Callback to sort extensions by type */
239 function compare( $a, $b ) {
241 if( $a['name'] === $b['name'] ) {
244 return $wgLang->lc( $a['name'] ) > $wgLang->lc( $b['name'] )
250 function formatCredits( $extension ) {
251 $name = isset( $extension['name'] ) ?
$extension['name'] : '[no name]';
252 if ( isset( $extension['path'] ) ) {
253 $svnInfo = self
::getSvnInfo( dirname($extension['path']) );
254 $directoryRev = isset( $svnInfo['directory-rev'] ) ?
$svnInfo['directory-rev'] : null;
255 $checkoutRev = isset( $svnInfo['checkout-rev'] ) ?
$svnInfo['checkout-rev'] : null;
256 $viewvcUrl = isset( $svnInfo['viewvc-url'] ) ?
$svnInfo['viewvc-url'] : null;
258 $directoryRev = null;
263 # Make main link (or just the name if there is no URL)
264 if ( isset( $extension['url'] ) ) {
265 $mainLink = "[{$extension['url']} $name]";
269 if ( isset( $extension['version'] ) ) {
270 $versionText = '<span class="mw-version-ext-version">' .
271 wfMsg( 'version-version', $extension['version'] ) .
277 # Make subversion text/link
278 if ( $checkoutRev ) {
279 $svnText = wfMsg( 'version-svn-revision', $directoryRev, $checkoutRev );
280 $svnText = isset( $viewvcUrl ) ?
"[$viewvcUrl $svnText]" : $svnText;
285 # Make description text
286 $description = isset ( $extension['description'] ) ?
$extension['description'] : '';
287 if( isset ( $extension['descriptionmsg'] ) ) {
288 # Look for a localized description
289 $descriptionMsg = $extension['descriptionmsg'];
290 if( is_array( $descriptionMsg ) ) {
291 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
292 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
293 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
294 $msg = wfMsg( $descriptionMsgKey, $descriptionMsg );
296 $msg = wfMsg( $descriptionMsg );
298 if ( !wfEmptyMsg( $descriptionMsg, $msg ) && $msg != '' ) {
303 if ( $svnText !== false ) {
305 <td><em>$mainLink $versionText</em></td>
306 <td><em>$svnText</em></td>";
309 <td colspan=\"2\"><em>$mainLink $versionText</em></td>";
311 $author = isset ( $extension['author'] ) ?
$extension['author'] : array();
312 $extDescAuthor = "<td>$description</td>
313 <td>" . $this->listToText( (array)$author ) . "</td>
315 return $extNameVer . $extDescAuthor;
324 if ( count( $wgHooks ) ) {
325 $myWgHooks = $wgHooks;
328 $ret = Xml
::element( 'h2', array( 'id' => 'mw-version-hooks' ), wfMsg( 'version-hooks' ) ) .
329 Xml
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) ) .
331 <th>" . wfMsg( 'version-hook-name' ) . "</th>
332 <th>" . wfMsg( 'version-hook-subscribedby' ) . "</th>
335 foreach ( $myWgHooks as $hook => $hooks )
338 <td>" . $this->listToText( $hooks ) . "</td>
341 $ret .= Xml
::closeElement( 'table' );
347 private function openExtType($text, $name = null) {
348 $opt = array( 'colspan' => 4 );
351 if(!$this->firstExtOpened
) {
352 // Insert a spacing line
353 $out .= '<tr class="sv-space">' . Xml
::element( 'td', $opt ) . "</tr>\n";
355 $this->firstExtOpened
= false;
357 if($name) { $opt['id'] = "sv-$name"; }
359 $out .= "<tr>" . Xml
::element( 'th', $opt, $text) . "</tr>\n";
367 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
368 return "<!-- visited from $ip -->\n" .
369 "<span style='display:none'>visited from $ip</span>";
376 function listToText( $list ) {
377 $cnt = count( $list );
380 // Enforce always returning a string
381 return (string)self
::arrayToString( $list[0] );
382 } elseif ( $cnt == 0 ) {
387 return $wgLang->listToText( array_map( array( __CLASS__
, 'arrayToString' ), $list ) );
392 * @param mixed $list Will convert an array to string if given and return
393 * the paramater unaltered otherwise
396 static function arrayToString( $list ) {
397 if( is_array( $list ) && count( $list ) == 1 )
399 if( is_object( $list ) ) {
400 $class = get_class( $list );
402 } elseif ( !is_array( $list ) ) {
405 if( is_object( $list[0] ) )
406 $class = get_class( $list[0] );
409 return "($class, {$list[1]})";
414 * Get an associative array of information about a given path, from its .svn
415 * subdirectory. Returns false on error, such as if the directory was not
416 * checked out with subversion.
420 * checkout-rev The revision which was checked out
422 * directory-rev The revision when the directory was last modified
423 * url The subversion URL of the directory
424 * repo-url The base URL of the repository
425 * viewvc-url A ViewVC URL pointing to the checked-out revision
427 public static function getSvnInfo( $dir ) {
428 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
429 $entries = $dir . '/.svn/entries';
431 if( !file_exists( $entries ) ) {
435 $lines = file( $entries );
436 if ( !count( $lines ) ) {
440 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
441 if( preg_match( '/^<\?xml/', $lines[0] ) ) {
442 // subversion is release <= 1.3
443 if( !function_exists( 'simplexml_load_file' ) ) {
444 // We could fall back to expat... YUCK
448 // SimpleXml whines about the xmlns...
449 wfSuppressWarnings();
450 $xml = simplexml_load_file( $entries );
454 foreach( $xml->entry
as $entry ) {
455 if( $xml->entry
[0]['name'] == '' ) {
456 // The directory entry should always have a revision marker.
457 if( $entry['revision'] ) {
458 return array( 'checkout-rev' => intval( $entry['revision'] ) );
466 // subversion is release 1.4 or above
467 if ( count( $lines ) < 11 ) {
471 'checkout-rev' => intval( trim( $lines[3] ) ),
472 'url' => trim( $lines[4] ),
473 'repo-url' => trim( $lines[5] ),
474 'directory-rev' => intval( trim( $lines[10] ) )
476 if ( isset( self
::$viewvcUrls[$info['repo-url']] ) ) {
477 $viewvc = str_replace(
479 self
::$viewvcUrls[$info['repo-url']],
482 $pathRelativeToRepo = substr( $info['url'], strlen( $info['repo-url'] ) );
483 if ( substr( $pathRelativeToRepo, 0, 6 ) == '/trunk' ) {
484 $viewvc .= '/?pathrev=';
486 // Avoids 404 error using pathrev when it does not found
487 $viewvc .= '/?revision=';
489 $viewvc .= urlencode( $info['checkout-rev'] );
490 $info['viewvc-url'] = $viewvc;
496 * Retrieve the revision number of a Subversion working directory.
498 * @param String $dir Directory of the svn checkout
499 * @return int revision number as int
501 public static function getSvnRevision( $dir ) {
502 $info = self
::getSvnInfo( $dir );
503 if ( $info === false ) {
505 } elseif ( isset( $info['checkout-rev'] ) ) {
506 return $info['checkout-rev'];