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 function __construct(){
16 parent
::__construct( 'Version' );
22 function execute( $par ) {
23 global $wgOut, $wgMessageCache, $wgSpecialVersionShowHooks, $wgContLang;
24 $wgMessageCache->loadAllMessages();
27 $this->outputHeader();
29 if( $wgContLang->isRTL() ) {
30 $wgOut->addHTML( '<div dir="rtl">' );
32 $wgOut->addHTML( '<div dir="ltr">' );
35 $this->MediaWikiCredits() .
36 $this->softwareInformation() .
37 $this->extensionCredits();
38 if ( $wgSpecialVersionShowHooks ) {
39 $text .= $this->wgHooks();
41 $wgOut->addWikiText( $text );
42 $wgOut->addHTML( $this->IPInfo() );
43 $wgOut->addHTML( '</div>' );
47 * execuate command for output
48 * @param string command
49 * @return string output
51 static function execOutput( $cmd ) {
53 exec( $cmd.' 2>&1', $out );
55 return implode("\n", $out );
63 * @return wiki text showing the license information
65 static function MediaWikiCredits() {
68 $ret = Xml
::element( 'h2', array( 'id' => 'mw-version-license' ), wfMsg( 'version-license' ) );
70 // This text is always left-to-right.
71 $ret .= '<div dir="ltr">';
73 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
74 copyright © 2001-2009 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
75 Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
76 Niklas Laxström, Domas Mituzas, Rob Church, Yuri Astrakhan, Aryeh Gregor,
77 Aaron Schulz and others.
79 MediaWiki is free software; you can redistribute it and/or modify
80 it under the terms of the GNU General Public License as published by
81 the Free Software Foundation; either version 2 of the License, or
82 (at your option) any later version.
84 MediaWiki is distributed in the hope that it will be useful,
85 but WITHOUT ANY WARRANTY; without even the implied warranty of
86 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
87 GNU General Public License for more details.
89 You should have received [{{SERVER}}{{SCRIPTPATH}}/COPYING a copy of the GNU General Public License]
90 along with this program; if not, write to the Free Software
91 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
92 or [http://www.gnu.org/licenses/old-licenses/gpl-2.0.html read it online].
96 return str_replace( "\t\t", '', $ret ) . "\n";
100 * @return wiki text showing the third party software versions (apache, php, mysql).
102 static function softwareInformation() {
103 global $wgUseImageMagick, $wgImageMagickConvertCommand, $wgDiff3, $wgDiff;
104 global $wgAllowTitlesInSVG, $wgSVGConverter, $wgSVGConverters, $wgSVGConverterPath;
105 $dbr = wfGetDB( DB_SLAVE
);
107 // Put the software in an array of form 'name' => 'version'. All messages should
108 // be loaded here, so feel free to use wfMsg*() in the 'name'. Raw HTML or wikimarkup
111 $software['[http://www.mediawiki.org/ MediaWiki]'] = self
::getVersionLinked();
112 $software['[http://www.php.net/ PHP]'] = phpversion() . " (" . php_sapi_name() . ")";
113 $software[$dbr->getSoftwareLink()] = $dbr->getServerVersion();
115 // Version information for diff3
116 if ( file_exists( trim( $wgDiff3, '"' ) ) ) {
117 $swDiff3Info = self
::execOutput( $wgDiff3 . ' -v' );
118 $swDiff3Line = explode("\n",$swDiff3Info ,2);
119 $swDiff3Ver = $swDiff3Line[0];
120 $swDiff3Ver = str_replace( 'diff3 (GNU diffutils) ', '' , $swDiff3Ver);
121 $software['[http://www.gnu.org/software/diffutils/diffutils.html diff3]'] = $swDiff3Ver;
124 // Version information for diff
125 if ( file_exists( trim( $wgDiff, '"' ) ) ) {
126 $swDiffInfo = self
::execOutput( $wgDiff . ' -v' );
127 $swDiffLine = explode("\n",$swDiffInfo ,2);
128 $swDiffVer = $swDiffLine[0];
129 $swDiffVer = str_replace( 'diff (GNU diffutils) ', '' , $swDiffVer);
130 $software['[http://www.gnu.org/software/diffutils/diffutils.html diff]'] = $swDiffVer;
133 // Look for ImageMagick's version, if did not found, try to find the GD library version
134 if ( $wgUseImageMagick ) {
135 if ( file_exists( trim( $wgImageMagickConvertCommand, '"' ) ) ) {
136 $swImageMagickInfo = self
::execOutput( $wgImageMagickConvertCommand . ' -version' );
137 list( $head, $tail ) = explode( 'ImageMagick', $swImageMagickInfo );
138 list( $swImageMagickVer ) = explode('http://www.imagemagick.org', $tail );
139 $software['[http://www.imagemagick.org/ ImageMagick]'] = $swImageMagickVer;
142 if( function_exists( 'gd_info' ) ) {
144 if ( strstr( $gdInfo['GD Version'], 'bundled' ) != false ) {
145 $gd_URL = 'http://www.php.net/gd';
148 $gd_URL = 'http://www.libgd.org';
150 $software['[' . $gd_URL . ' GD library]'] = $gdInfo['GD Version'];
154 // Look for SVG converter and print the version info
155 if ( $wgAllowTitlesInSVG ) {
156 $swSVGConvName = $wgSVGConverter;
157 $haveSVGConvVer = false;
159 $binPath = '/usr/bin/';
160 $execPath = strtok(strstr($wgSVGConverters[$wgSVGConverter],$pathVar), ' ');
161 $execPath = substr_replace($execPath, '', 0, strlen($pathVar));
162 $execFullPath = trim($wgSVGConverterPath,'"') . $execPath;
163 $execBinPath = $binPath . $execPath;
164 if (strstr($execFullPath, ' ') != false) {
165 $execFullPath = '"' . $execFullPath . '"';
167 if ( !strcmp( $wgSVGConverter, 'ImageMagick') ) {
168 // Get version info for ImageMagick
169 if ( ( file_exists( $execBinPath ) ) ||
file_exists( trim( $execFullPath, '"' ) ) ||
( file_exists( trim( $execFullPath, '"' ) . '.exe' ) ) )
170 $swSVGConvInfo = self
::execOutput( $execFullPath . ' -version' );
171 list( $head, $tail ) = explode( 'ImageMagick', $swSVGConvInfo );
172 list( $swSVGConvVer ) = explode('http://www.imagemagick.org', $tail );
173 $swSVGConvURL = 'http://www.imagemagick.org/';
174 $haveSVGConvVer = true;
175 } else if ( strstr ($execFullPath, 'rsvg') != false ) {
176 // Get version info for rsvg
177 if ( ( file_exists( $execBinPath ) ) ||
file_exists( trim( $execFullPath, '"' ) ) ||
( file_exists( trim( $execFullPath, '"' ) . '.exe' ) ) )
178 $swSVGConvInfo = self
::execOutput( $execFullPath . ' -v' );
179 $swSVGConvLine = explode("\n",$swSVGConvInfo ,2);
180 $swSVGConvVer = $swSVGConvLine[0];
181 $swSVGConvURL = 'http://librsvg.sourceforge.net/';
182 $haveSVGConvVer = true;
183 } else if ( strstr ($execFullPath, 'inkscape') != false ) {
184 // Get version info for Inkscape
185 if ( ( file_exists( $execBinPath ) ) ||
file_exists( trim( $execFullPath, '"' ) ) ||
( file_exists( trim( $execFullPath, '"' ) . '.exe' ) ) )
186 $swSVGConvInfo = self
::execOutput( $execFullPath . ' -z -V' );
187 $swSVGConvLine = explode("\n",$swSVGConvInfo ,2);
188 $swSVGConvVer = ltrim( $swSVGConvLine[0], 'Inkscape ' );
189 $swSVGConvURL = 'http://www.inkscape.org/';
190 $swSVGConvName = ucfirst( $wgSVGConverter );
191 $haveSVGConvVer = true;
193 if ( $haveSVGConvVer )
194 $software["[$swSVGConvURL $swSVGConvName]"] = $swSVGConvVer;
197 // Allow a hook to add/remove items
198 wfRunHooks( 'SoftwareInfo', array( &$software ) );
200 $out = Xml
::element( 'h2', array( 'id' => 'mw-version-software' ), wfMsg( 'version-software' ) ) .
201 Xml
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-software' ) ) .
203 <th>" . wfMsg( 'version-software-product' ) . "</th>
204 <th>" . wfMsg( 'version-software-version' ) . "</th>
206 foreach( $software as $name => $version ) {
208 <td>" . $name . "</td>
209 <td>" . $version . "</td>
212 return $out . Xml
::closeElement( 'table' );
216 * Return a string of the MediaWiki version with SVN revision if available
220 public static function getVersion( $flags = '' ) {
221 global $wgVersion, $IP;
222 wfProfileIn( __METHOD__
);
223 $svn = self
::getSvnRevision( $IP, false, false , false );
224 $svnCo = self
::getSvnRevision( $IP, true, false , false );
226 $version = $wgVersion;
227 } elseif( $flags === 'nodb' ) {
228 $version = "$wgVersion (r$svnCo)";
230 $version = $wgVersion . wfMsg( 'version-svn-revision', $svn, $svnCo );
232 wfProfileOut( __METHOD__
);
237 * Return a string of the MediaWiki version with a link to SVN revision if
242 public static function getVersionLinked() {
243 global $wgVersion, $IP;
244 wfProfileIn( __METHOD__
);
245 $svn = self
::getSvnRevision( $IP, false, false, false );
246 $svnCo = self
::getSvnRevision( $IP, true, false, false );
247 $svnDir = self
::getSvnRevision( $IP, true, false, true );
248 $viewvcStart = 'http://svn.wikimedia.org/viewvc/mediawiki/';
249 $viewvcEnd = '/?pathrev=';
250 $viewvc = $viewvcStart . $svnDir . $viewvcEnd;
251 $version = $svn ?
$wgVersion . " [{$viewvc}{$svnCo} " . wfMsg( 'version-svn-revision', $svn, $svnCo ) . ']' : $wgVersion;
252 wfProfileOut( __METHOD__
);
256 /** Generate wikitext showing extensions name, URL, author and description */
257 function extensionCredits() {
258 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunctions;
260 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunctions ) )
263 $extensionTypes = array(
264 'specialpage' => wfMsg( 'version-specialpages' ),
265 'parserhook' => wfMsg( 'version-parserhooks' ),
266 'variable' => wfMsg( 'version-variables' ),
267 'media' => wfMsg( 'version-mediahandlers' ),
268 'other' => wfMsg( 'version-other' ),
270 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
272 $out = Xml
::element( 'h2', array( 'id' => 'mw-version-ext' ), wfMsg( 'version-extensions' ) ) .
273 Xml
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-ext' ) );
275 foreach ( $extensionTypes as $type => $text ) {
276 if ( isset ( $wgExtensionCredits[$type] ) && count ( $wgExtensionCredits[$type] ) ) {
277 $out .= $this->openExtType( $text );
279 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
281 foreach ( $wgExtensionCredits[$type] as $extension ) {
284 $subVersionCo = null;
286 if ( isset( $extension['path'] ) ) {
287 $subVersion = self
::getSvnRevision(dirname($extension['path']), false, true, false);
288 $subVersionCo = self
::getSvnRevision(dirname($extension['path']), true, true, false);
289 $subVersionDir = self
::getSvnRevision(dirname($extension['path']), false, true, true);
291 $viewvc = $subVersionDir . $subVersionCo;
293 if ( isset( $extension['version'] ) ) {
294 $version = $extension['version'];
297 $out .= $this->formatCredits(
298 isset ( $extension['name'] ) ?
$extension['name'] : '',
303 isset ( $extension['author'] ) ?
$extension['author'] : '',
304 isset ( $extension['url'] ) ?
$extension['url'] : null,
305 isset ( $extension['description'] ) ?
$extension['description'] : '',
306 isset ( $extension['descriptionmsg'] ) ?
$extension['descriptionmsg'] : ''
312 if ( count( $wgExtensionFunctions ) ) {
313 $out .= $this->openExtType( wfMsg( 'version-extension-functions' ) );
314 $out .= '<tr><td colspan="4">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
317 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
318 for ( $i = 0; $i < $cnt; ++
$i )
319 $tags[$i] = "<{$tags[$i]}>";
320 $out .= $this->openExtType( wfMsg( 'version-parser-extensiontags' ) );
321 $out .= '<tr><td colspan="4">' . $this->listToText( $tags ). "</td></tr>\n";
324 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
325 $out .= $this->openExtType( wfMsg( 'version-parser-function-hooks' ) );
326 $out .= '<tr><td colspan="4">' . $this->listToText( $fhooks ) . "</td></tr>\n";
329 if ( count( $wgSkinExtensionFunctions ) ) {
330 $out .= $this->openExtType( wfMsg( 'version-skin-extension-functions' ) );
331 $out .= '<tr><td colspan="4">' . $this->listToText( $wgSkinExtensionFunctions ) . "</td></tr>\n";
333 $out .= Xml
::closeElement( 'table' );
337 /** Callback to sort extensions by type */
338 function compare( $a, $b ) {
340 if( $a['name'] === $b['name'] ) {
343 return $wgLang->lc( $a['name'] ) > $wgLang->lc( $b['name'] )
349 function formatCredits( $name, $version = null, $subVersion = null, $subVersionCo = null, $subVersionURL = null, $author = null, $url = null, $description = null, $descriptionMsg = null ) {
350 $haveSubversion = $subVersion;
351 $extension = isset( $url ) ?
"[$url $name]" : $name;
352 $version = isset( $version ) ?
wfMsg( 'version-version', $version ) : '';
353 $subVersion = isset( $subVersion ) ?
wfMsg( 'version-svn-revision', $subVersion, $subVersionCo ) : '';
354 $subVersion = isset( $subVersionURL ) ?
"[$subVersionURL $subVersion]" : $subVersion;
356 # Look for a localized description
357 if( isset( $descriptionMsg ) ) {
358 $msg = wfMsg( $descriptionMsg );
359 if ( !wfEmptyMsg( $descriptionMsg, $msg ) && $msg != '' ) {
364 if ( $haveSubversion ) {
366 <td><em>$extension $version</em></td>
367 <td><em>$subVersion</em></td>";
370 <td colspan=\"2\"><em>$extension $version</em></td>";
372 $extDescAuthor = "<td>$description</td>
373 <td>" . $this->listToText( (array)$author ) . "</td>
375 return $ret = $extNameVer . $extDescAuthor;
385 if ( count( $wgHooks ) ) {
386 $myWgHooks = $wgHooks;
389 $ret = Xml
::element( 'h2', array( 'id' => 'mw-version-hooks' ), wfMsg( 'version-hooks' ) ) .
390 Xml
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) ) .
392 <th>" . wfMsg( 'version-hook-name' ) . "</th>
393 <th>" . wfMsg( 'version-hook-subscribedby' ) . "</th>
396 foreach ( $myWgHooks as $hook => $hooks )
399 <td>" . $this->listToText( $hooks ) . "</td>
402 $ret .= Xml
::closeElement( 'table' );
408 private function openExtType($text, $name = null) {
409 $opt = array( 'colspan' => 4 );
412 if(!$this->firstExtOpened
) {
413 // Insert a spacing line
414 $out .= '<tr class="sv-space">' . Xml
::element( 'td', $opt ) . "</tr>\n";
416 $this->firstExtOpened
= false;
418 if($name) { $opt['id'] = "sv-$name"; }
420 $out .= "<tr>" . Xml
::element( 'th', $opt, $text) . "</tr>\n";
428 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
429 return "<!-- visited from $ip -->\n" .
430 "<span style='display:none'>visited from $ip</span>";
437 function listToText( $list ) {
438 $cnt = count( $list );
441 // Enforce always returning a string
442 return (string)self
::arrayToString( $list[0] );
443 } elseif ( $cnt == 0 ) {
448 return $wgLang->listToText( array_map( array( __CLASS__
, 'arrayToString' ), $list ) );
453 * @param mixed $list Will convert an array to string if given and return
454 * the paramater unaltered otherwise
457 static function arrayToString( $list ) {
458 if( is_array( $list ) && count( $list ) == 1 )
460 if( is_object( $list ) ) {
461 $class = get_class( $list );
463 } elseif ( !is_array( $list ) ) {
466 if( is_object( $list[0] ) )
467 $class = get_class( $list[0] );
470 return "($class, {$list[1]})";
475 * Retrieve the revision number of a Subversion working directory.
477 * @param String $dir Directory of the svn checkout
478 * @param Boolean $coRev optional to return value whether is Last Modified
479 * or Checkout revision number
480 * @param Boolean $extension optional to check the path whether is from
481 * Wikimedia SVN server or not
482 * @param Boolean $relPath optional to get the end part of the checkout path
483 * @return mixed revision number as int, end part of the checkout path,
484 * or false if not a SVN checkout
486 public static function getSvnRevision( $dir, $coRev = false, $extension = false, $relPath = false) {
487 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
488 $entries = $dir . '/.svn/entries';
490 if( !file_exists( $entries ) ) {
494 $content = file( $entries );
496 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
497 if( preg_match( '/^<\?xml/', $content[0] ) ) {
498 // subversion is release <= 1.3
499 if( !function_exists( 'simplexml_load_file' ) ) {
500 // We could fall back to expat... YUCK
504 // SimpleXml whines about the xmlns...
505 wfSuppressWarnings();
506 $xml = simplexml_load_file( $entries );
510 foreach( $xml->entry
as $entry ) {
511 if( $xml->entry
[0]['name'] == '' ) {
512 // The directory entry should always have a revision marker.
513 if( $entry['revision'] ) {
514 return intval( $entry['revision'] );
521 // subversion is release 1.4 or above
523 $endPath = strstr( $content[4], 'tags' );
525 $endPath = strstr( $content[4], 'branches' );
527 $endPath = strstr( $content[4], 'trunk' );
532 $endPath = trim ( $endPath );
534 $wmSvnPath = 'svn.wikimedia.org/svnroot/mediawiki';
535 $isWMSvn = strstr($content[5],$wmSvnPath);
536 if (!strcmp($isWMSvn,null)) {
539 $viewvcStart = 'http://svn.wikimedia.org/viewvc/mediawiki/';
540 if (strstr( $content[4], 'trunk' ))
541 $viewvcEnd = '/?pathrev=';
543 // Avoids 404 error using pathrev when it does not found
544 $viewvcEnd = '/?revision=';
545 $viewvc = $viewvcStart . $endPath . $viewvcEnd;
552 // get the directory checkout revsion number
553 return intval( $content[3]) ;
555 // get the directory last modified revision number
556 return intval( $content[10] );