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, $wgUseTeX;
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 ) )
170 $swSVGConvInfo = self
::execOutput( $execBinPath . ' -version' );
171 else if ( file_exists( trim( $execFullPath, '"' ) ) ||
( file_exists( trim( $execFullPath, '"' ) . '.exe' ) ) )
172 $swSVGConvInfo = self
::execOutput( $execFullPath . ' -version' );
173 list( $head, $tail ) = explode( 'ImageMagick', $swSVGConvInfo );
174 list( $swSVGConvVer ) = explode('http://www.imagemagick.org', $tail );
175 $swSVGConvURL = 'http://www.imagemagick.org/';
176 $haveSVGConvVer = true;
177 } else if ( strstr ($execFullPath, 'rsvg') != false ) {
178 // Get version info for rsvg
179 if ( file_exists( $execBinPath ) )
180 $swSVGConvInfo = self
::execOutput( $execBinPath . ' -v' );
181 else if ( file_exists( trim( $execFullPath, '"' ) ) ||
( file_exists( trim( $execFullPath, '"' ) . '.exe' ) ) )
182 $swSVGConvInfo = self
::execOutput( $execFullPath . ' -v' );
183 $swSVGConvLine = explode("\n",$swSVGConvInfo ,2);
184 $swSVGConvVer = $swSVGConvLine[0];
185 $swSVGConvURL = 'http://librsvg.sourceforge.net/';
186 $haveSVGConvVer = true;
187 } else if ( strstr ($execFullPath, 'inkscape') != false ) {
188 // Get version info for Inkscape
189 if ( file_exists( $execBinPath ) )
190 $swSVGConvInfo = self
::execOutput( $execBinPath . ' -z -V' );
191 else if ( file_exists( trim( $execFullPath, '"' ) ) ||
( file_exists( trim( $execFullPath, '"' ) . '.exe' ) ) )
192 $swSVGConvInfo = self
::execOutput( $execFullPath . ' -z -V' );
193 $swSVGConvLine = explode("\n",$swSVGConvInfo ,2);
194 $swSVGConvVer = ltrim( $swSVGConvLine[0], 'Inkscape ' );
195 $swSVGConvURL = 'http://www.inkscape.org/';
196 $swSVGConvName = ucfirst( $wgSVGConverter );
197 $haveSVGConvVer = true;
199 if ( $haveSVGConvVer )
200 $software["[$swSVGConvURL $swSVGConvName]"] = $swSVGConvVer;
203 // Look for TeX support and print the software version info
205 $binPath = '/usr/bin/';
206 $binPathLocal = '/usr/local/bin/';
209 'gs' => 'Ghostscript',
212 'imagemagick' => 'ImageMagick',
215 'ocaml' => 'http://caml.inria.fr/',
216 'gs' => 'http://www.ghostscript.com/',
217 'dvips' => 'http://www.radicaleye.com/dvips.html',
218 'latex' => 'http://www.latex-project.org/',
219 'imagemagick' => 'http://www.imagemagick.org/',
226 'imagemagick' => 'convert',
228 $swMathParam = Array(
229 'ocaml' => '-version',
233 'imagemagick' => '-version',
235 foreach ( $swMathExec as $swMath => $swMathCmd ) {
236 if ( file_exists( $binPath . $swMathCmd ) ||
file_exists( $binPathLocal . $swMathCmd ) ) {
237 $swMathInfo = self
::execOutput( $swMathCmd . ' ' . $swMathParam[$swMath] );
238 $swMathLine = explode( "\n", $swMathInfo, 2);
239 $swMathVerInfo = $swMathLine[0];
240 if ( !strcmp( $swMath, 'gs' ) )
241 $swMathVerInfo = str_replace( 'GPL Ghostscript ', '', $swMathVerInfo );
242 else if ( !strcmp( $swMath, 'dvips' ) ) {
243 $swMathVerParts = explode( ' ' , $swMathVerInfo );
244 $swMathVerInfo = $swMathVerParts[3];
245 } else if ( !strcmp( $swMath, 'imagemagick' ) ) {
246 list( $head, $tail ) = explode( 'ImageMagick', $swMathVerInfo );
247 list( $swMathVerInfo ) = explode('http://www.imagemagick.org', $tail );
249 $swMathVer[$swMath] = $swMathVerInfo;
250 $software["[$swMathURL[$swMath] $swMathName[$swMath]]"] = trim ( $swMathVer[$swMath] );
255 // Allow a hook to add/remove items
256 wfRunHooks( 'SoftwareInfo', array( &$software ) );
258 $out = Xml
::element( 'h2', array( 'id' => 'mw-version-software' ), wfMsg( 'version-software' ) ) .
259 Xml
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-software' ) ) .
261 <th>" . wfMsg( 'version-software-product' ) . "</th>
262 <th>" . wfMsg( 'version-software-version' ) . "</th>
264 foreach( $software as $name => $version ) {
266 <td>" . $name . "</td>
267 <td>" . $version . "</td>
270 return $out . Xml
::closeElement( 'table' );
274 * Return a string of the MediaWiki version with SVN revision if available
278 public static function getVersion( $flags = '' ) {
279 global $wgVersion, $IP;
280 wfProfileIn( __METHOD__
);
281 $svn = self
::getSvnRevision( $IP, false, false , false );
282 $svnCo = self
::getSvnRevision( $IP, true, false , false );
284 $version = $wgVersion;
285 } elseif( $flags === 'nodb' ) {
286 $version = "$wgVersion (r$svnCo)";
288 $version = $wgVersion . wfMsg( 'version-svn-revision', $svn, $svnCo );
290 wfProfileOut( __METHOD__
);
295 * Return a string of the MediaWiki version with a link to SVN revision if
300 public static function getVersionLinked() {
301 global $wgVersion, $IP;
302 wfProfileIn( __METHOD__
);
303 $svn = self
::getSvnRevision( $IP, false, false, false );
304 $svnCo = self
::getSvnRevision( $IP, true, false, false );
305 $svnDir = self
::getSvnRevision( $IP, true, false, true );
306 $viewvcStart = 'http://svn.wikimedia.org/viewvc/mediawiki/';
307 $viewvcEnd = '/?pathrev=';
308 $viewvc = $viewvcStart . $svnDir . $viewvcEnd;
309 $version = $svn ?
$wgVersion . " [{$viewvc}{$svnCo} " . wfMsg( 'version-svn-revision', $svn, $svnCo ) . ']' : $wgVersion;
310 wfProfileOut( __METHOD__
);
314 /** Generate wikitext showing extensions name, URL, author and description */
315 function extensionCredits() {
316 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunctions;
318 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunctions ) )
321 $extensionTypes = array(
322 'specialpage' => wfMsg( 'version-specialpages' ),
323 'parserhook' => wfMsg( 'version-parserhooks' ),
324 'variable' => wfMsg( 'version-variables' ),
325 'media' => wfMsg( 'version-mediahandlers' ),
326 'other' => wfMsg( 'version-other' ),
328 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
330 $out = Xml
::element( 'h2', array( 'id' => 'mw-version-ext' ), wfMsg( 'version-extensions' ) ) .
331 Xml
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-ext' ) );
333 foreach ( $extensionTypes as $type => $text ) {
334 if ( isset ( $wgExtensionCredits[$type] ) && count ( $wgExtensionCredits[$type] ) ) {
335 $out .= $this->openExtType( $text );
337 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
339 foreach ( $wgExtensionCredits[$type] as $extension ) {
342 $subVersionCo = null;
344 if ( isset( $extension['path'] ) ) {
345 $subVersion = self
::getSvnRevision(dirname($extension['path']), false, true, false);
346 $subVersionCo = self
::getSvnRevision(dirname($extension['path']), true, true, false);
347 $subVersionDir = self
::getSvnRevision(dirname($extension['path']), false, true, true);
349 $viewvc = $subVersionDir . $subVersionCo;
351 if ( isset( $extension['version'] ) ) {
352 $version = $extension['version'];
355 $out .= $this->formatCredits(
356 isset ( $extension['name'] ) ?
$extension['name'] : '',
361 isset ( $extension['author'] ) ?
$extension['author'] : '',
362 isset ( $extension['url'] ) ?
$extension['url'] : null,
363 isset ( $extension['description'] ) ?
$extension['description'] : '',
364 isset ( $extension['descriptionmsg'] ) ?
$extension['descriptionmsg'] : null
370 if ( count( $wgExtensionFunctions ) ) {
371 $out .= $this->openExtType( wfMsg( 'version-extension-functions' ) );
372 $out .= '<tr><td colspan="4">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
375 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
376 for ( $i = 0; $i < $cnt; ++
$i )
377 $tags[$i] = "<{$tags[$i]}>";
378 $out .= $this->openExtType( wfMsg( 'version-parser-extensiontags' ) );
379 $out .= '<tr><td colspan="4">' . $this->listToText( $tags ). "</td></tr>\n";
382 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
383 $out .= $this->openExtType( wfMsg( 'version-parser-function-hooks' ) );
384 $out .= '<tr><td colspan="4">' . $this->listToText( $fhooks ) . "</td></tr>\n";
387 if ( count( $wgSkinExtensionFunctions ) ) {
388 $out .= $this->openExtType( wfMsg( 'version-skin-extension-functions' ) );
389 $out .= '<tr><td colspan="4">' . $this->listToText( $wgSkinExtensionFunctions ) . "</td></tr>\n";
391 $out .= Xml
::closeElement( 'table' );
395 /** Callback to sort extensions by type */
396 function compare( $a, $b ) {
398 if( $a['name'] === $b['name'] ) {
401 return $wgLang->lc( $a['name'] ) > $wgLang->lc( $b['name'] )
407 function formatCredits( $name, $version = null, $subVersion = null, $subVersionCo = null, $subVersionURL = null, $author = null, $url = null, $description = null, $descriptionMsg = null ) {
408 $haveSubversion = $subVersion;
409 $extension = isset( $url ) ?
"[$url $name]" : $name;
410 $version = isset( $version ) ?
wfMsg( 'version-version', $version ) : '';
411 $subVersion = isset( $subVersion ) ?
wfMsg( 'version-svn-revision', $subVersion, $subVersionCo ) : '';
412 $subVersion = isset( $subVersionURL ) ?
"[$subVersionURL $subVersion]" : $subVersion;
414 # Look for a localized description
415 if( isset( $descriptionMsg ) ) {
416 $msg = wfMsg( $descriptionMsg );
417 if ( !wfEmptyMsg( $descriptionMsg, $msg ) && $msg != '' ) {
422 if ( $haveSubversion ) {
424 <td><em>$extension $version</em></td>
425 <td><em>$subVersion</em></td>";
428 <td colspan=\"2\"><em>$extension $version</em></td>";
430 $extDescAuthor = "<td>$description</td>
431 <td>" . $this->listToText( (array)$author ) . "</td>
433 return $ret = $extNameVer . $extDescAuthor;
443 if ( count( $wgHooks ) ) {
444 $myWgHooks = $wgHooks;
447 $ret = Xml
::element( 'h2', array( 'id' => 'mw-version-hooks' ), wfMsg( 'version-hooks' ) ) .
448 Xml
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) ) .
450 <th>" . wfMsg( 'version-hook-name' ) . "</th>
451 <th>" . wfMsg( 'version-hook-subscribedby' ) . "</th>
454 foreach ( $myWgHooks as $hook => $hooks )
457 <td>" . $this->listToText( $hooks ) . "</td>
460 $ret .= Xml
::closeElement( 'table' );
466 private function openExtType($text, $name = null) {
467 $opt = array( 'colspan' => 4 );
470 if(!$this->firstExtOpened
) {
471 // Insert a spacing line
472 $out .= '<tr class="sv-space">' . Xml
::element( 'td', $opt ) . "</tr>\n";
474 $this->firstExtOpened
= false;
476 if($name) { $opt['id'] = "sv-$name"; }
478 $out .= "<tr>" . Xml
::element( 'th', $opt, $text) . "</tr>\n";
486 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
487 return "<!-- visited from $ip -->\n" .
488 "<span style='display:none'>visited from $ip</span>";
495 function listToText( $list ) {
496 $cnt = count( $list );
499 // Enforce always returning a string
500 return (string)self
::arrayToString( $list[0] );
501 } elseif ( $cnt == 0 ) {
506 return $wgLang->listToText( array_map( array( __CLASS__
, 'arrayToString' ), $list ) );
511 * @param mixed $list Will convert an array to string if given and return
512 * the paramater unaltered otherwise
515 static function arrayToString( $list ) {
516 if( is_array( $list ) && count( $list ) == 1 )
518 if( is_object( $list ) ) {
519 $class = get_class( $list );
521 } elseif ( !is_array( $list ) ) {
524 if( is_object( $list[0] ) )
525 $class = get_class( $list[0] );
528 return "($class, {$list[1]})";
533 * Retrieve the revision number of a Subversion working directory.
535 * @param String $dir Directory of the svn checkout
536 * @param Boolean $coRev optional to return value whether is Last Modified
537 * or Checkout revision number
538 * @param Boolean $extension optional to check the path whether is from
539 * Wikimedia SVN server or not
540 * @param Boolean $relPath optional to get the end part of the checkout path
541 * @return mixed revision number as int, end part of the checkout path,
542 * or false if not a SVN checkout
544 public static function getSvnRevision( $dir, $coRev = false, $extension = false, $relPath = false) {
545 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
546 $entries = $dir . '/.svn/entries';
548 if( !file_exists( $entries ) ) {
552 $content = file( $entries );
554 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
555 if( preg_match( '/^<\?xml/', $content[0] ) ) {
556 // subversion is release <= 1.3
557 if( !function_exists( 'simplexml_load_file' ) ) {
558 // We could fall back to expat... YUCK
562 // SimpleXml whines about the xmlns...
563 wfSuppressWarnings();
564 $xml = simplexml_load_file( $entries );
568 foreach( $xml->entry
as $entry ) {
569 if( $xml->entry
[0]['name'] == '' ) {
570 // The directory entry should always have a revision marker.
571 if( $entry['revision'] ) {
572 return intval( $entry['revision'] );
579 // subversion is release 1.4 or above
581 $endPath = strstr( $content[4], 'tags' );
583 $endPath = strstr( $content[4], 'branches' );
585 $endPath = strstr( $content[4], 'trunk' );
590 $endPath = trim ( $endPath );
592 $wmSvnPath = 'svn.wikimedia.org/svnroot/mediawiki';
593 $isWMSvn = strstr($content[5],$wmSvnPath);
594 if (!strcmp($isWMSvn,null)) {
597 $viewvcStart = 'http://svn.wikimedia.org/viewvc/mediawiki/';
598 if (strstr( $content[4], 'trunk' ))
599 $viewvcEnd = '/?pathrev=';
601 // Avoids 404 error using pathrev when it does not found
602 $viewvcEnd = '/?revision=';
603 $viewvc = $viewvcStart . $endPath . $viewvcEnd;
610 // get the directory checkout revsion number
611 return intval( $content[3]) ;
613 // get the directory last modified revision number
614 return intval( $content[10] );