3 * 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
16 function wfSpecialVersion() {
17 $version = new SpecialVersion
;
22 * @ingroup SpecialPage
24 class SpecialVersion
{
25 private $firstExtOpened = true;
31 global $wgOut, $wgMessageCache, $wgSpecialVersionShowHooks;
32 $wgMessageCache->loadAllMessages();
34 $wgOut->addHTML( '<div dir="ltr">' );
36 $this->MediaWikiCredits() .
37 $this->softwareInformation() .
38 $this->extensionCredits();
39 if ( $wgSpecialVersionShowHooks ) {
40 $text .= $this->wgHooks();
42 $wgOut->addWikiText( $text );
43 $wgOut->addHTML( $this->IPInfo() );
44 $wgOut->addHTML( '</div>' );
52 * @return wiki text showing the license information
54 static function MediaWikiCredits() {
55 $ret = Xml
::element( 'h2', array( 'id' => 'mw-version-license' ), wfMsg( 'version-license' ) ) .
57 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
58 copyright (C) 2001-2008 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
59 Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
60 Niklas Laxström, Domas Mituzas, Rob Church, Yuri Astrakhan and others.
62 MediaWiki is free software; you can redistribute it and/or modify
63 it under the terms of the GNU General Public License as published by
64 the Free Software Foundation; either version 2 of the License, or
65 (at your option) any later version.
67 MediaWiki is distributed in the hope that it will be useful,
68 but WITHOUT ANY WARRANTY; without even the implied warranty of
69 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70 GNU General Public License for more details.
72 You should have received [{{SERVER}}{{SCRIPTPATH}}/COPYING a copy of the GNU General Public License]
73 along with this program; if not, write to the Free Software
74 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
75 or [http://www.gnu.org/licenses/old-licenses/gpl-2.0.html read it online].
78 return str_replace( "\t\t", '', $ret ) . "\n";
82 * @return wiki text showing the third party software versions (apache, php, mysql).
84 static function softwareInformation() {
85 $dbr = wfGetDB( DB_SLAVE
);
87 return Xml
::element( 'h2', array( 'id' => 'mw-version-software' ), wfMsg( 'version-software' ) ) .
88 Xml
::openElement( 'table', array( 'id' => 'sv-software' ) ) .
90 <th>" . wfMsg( 'version-software-product' ) . "</th>
91 <th>" . wfMsg( 'version-software-version' ) . "</th>
94 <td>[http://www.mediawiki.org/ MediaWiki]</td>
95 <td>" . self
::getVersionLinked() . "</td>
98 <td>[http://www.php.net/ PHP]</td>
99 <td>" . phpversion() . " (" . php_sapi_name() . ")</td>
102 <td>" . $dbr->getSoftwareLink() . "</td>
103 <td>" . $dbr->getServerVersion() . "</td>
105 Xml
::closeElement( 'table' );
109 * Return a string of the MediaWiki version with SVN revision if available
113 public static function getVersion() {
114 global $wgVersion, $IP;
115 wfProfileIn( __METHOD__
);
116 $svn = self
::getSvnRevision( $IP );
117 $version = $svn ?
"$wgVersion (r$svn)" : $wgVersion;
118 wfProfileOut( __METHOD__
);
123 * Return a string of the MediaWiki version with a link to SVN revision if
128 public static function getVersionLinked() {
129 global $wgVersion, $IP;
130 wfProfileIn( __METHOD__
);
131 $svn = self
::getSvnRevision( $IP );
132 $viewvc = 'http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/?pathrev=';
133 $version = $svn ?
"$wgVersion ([{$viewvc}{$svn} r$svn])" : $wgVersion;
134 wfProfileOut( __METHOD__
);
138 /** Generate wikitext showing extensions name, URL, author and description */
139 function extensionCredits() {
140 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunctions;
142 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunctions ) )
145 $extensionTypes = array(
146 'specialpage' => wfMsg( 'version-specialpages' ),
147 'parserhook' => wfMsg( 'version-parserhooks' ),
148 'variable' => wfMsg( 'version-variables' ),
149 'media' => wfMsg( 'version-mediahandlers' ),
150 'other' => wfMsg( 'version-other' ),
152 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
154 $out = Xml
::element( 'h2', array( 'id' => 'mw-version-ext' ), wfMsg( 'version-extensions' ) ) .
155 Xml
::openElement( 'table', array( 'id' => 'sv-ext' ) );
157 foreach ( $extensionTypes as $type => $text ) {
158 if ( isset ( $wgExtensionCredits[$type] ) && count ( $wgExtensionCredits[$type] ) ) {
159 $out .= $this->openExtType( $text );
161 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
163 foreach ( $wgExtensionCredits[$type] as $extension ) {
164 if ( isset( $extension['version'] ) ) {
165 $version = $extension['version'];
166 } elseif ( isset( $extension['svn-revision'] ) &&
167 preg_match( '/\$(?:Rev|LastChangedRevision|Revision): *(\d+)/',
168 $extension['svn-revision'], $m ) )
170 $version = 'r' . $m[1];
175 $out .= $this->formatCredits(
176 isset ( $extension['name'] ) ?
$extension['name'] : '',
178 isset ( $extension['author'] ) ?
$extension['author'] : '',
179 isset ( $extension['url'] ) ?
$extension['url'] : null,
180 isset ( $extension['description'] ) ?
$extension['description'] : '',
181 isset ( $extension['descriptionmsg'] ) ?
$extension['descriptionmsg'] : ''
187 if ( count( $wgExtensionFunctions ) ) {
188 $out .= $this->openExtType( wfMsg( 'version-extension-functions' ) );
189 $out .= '<tr><td colspan="3">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
192 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
193 for ( $i = 0; $i < $cnt; ++
$i )
194 $tags[$i] = "<{$tags[$i]}>";
195 $out .= $this->openExtType( wfMsg( 'version-parser-extensiontags' ) );
196 $out .= '<tr><td colspan="3">' . $this->listToText( $tags ). "</td></tr>\n";
199 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
200 $out .= $this->openExtType( wfMsg( 'version-parser-function-hooks' ) );
201 $out .= '<tr><td colspan="3">' . $this->listToText( $fhooks ) . "</td></tr>\n";
204 if ( count( $wgSkinExtensionFunctions ) ) {
205 $out .= $this->openExtType( wfMsg( 'version-skin-extension-functions' ) );
206 $out .= '<tr><td colspan="3">' . $this->listToText( $wgSkinExtensionFunctions ) . "</td></tr>\n";
208 $out .= Xml
::closeElement( 'table' );
212 /** Callback to sort extensions by type */
213 function compare( $a, $b ) {
215 if( $a['name'] === $b['name'] ) {
218 return $wgLang->lc( $a['name'] ) > $wgLang->lc( $b['name'] )
224 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null, $descriptionMsg = null ) {
225 $extension = isset( $url ) ?
"[$url $name]" : $name;
226 $version = isset( $version ) ?
"(" . wfMsg( 'version-version' ) . " $version)" : '';
228 # Look for a localized description
229 if( isset( $descriptionMsg ) ) {
230 $msg = wfMsg( $descriptionMsg );
231 if ( !wfEmptyMsg( $descriptionMsg, $msg ) && $msg != '' ) {
237 <td><em>$extension $version</em></td>
238 <td>$description</td>
239 <td>" . $this->listToText( (array)$author ) . "</td>
249 if ( count( $wgHooks ) ) {
250 $myWgHooks = $wgHooks;
253 $ret = Xml
::element( 'h2', array( 'id' => 'mw-version-hooks' ), wfMsg( 'version-hooks' ) ) .
254 Xml
::openElement( 'table', array( 'id' => 'sv-hooks' ) ) .
256 <th>" . wfMsg( 'version-hook-name' ) . "</th>
257 <th>" . wfMsg( 'version-hook-subscribedby' ) . "</th>
260 foreach ( $myWgHooks as $hook => $hooks )
263 <td>" . $this->listToText( $hooks ) . "</td>
266 $ret .= Xml
::closeElement( 'table' );
272 private function openExtType($text, $name = null) {
273 $opt = array( 'colspan' => 3 );
276 if(!$this->firstExtOpened
) {
277 // Insert a spacing line
278 $out .= '<tr class="sv-space">' . Xml
::element( 'td', $opt ) . "</tr>\n";
280 $this->firstExtOpened
= false;
282 if($name) { $opt['id'] = "sv-$name"; }
284 $out .= "<tr>" . Xml
::element( 'th', $opt, $text) . "</tr>\n";
294 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
295 return "<!-- visited from $ip -->\n" .
296 "<span style='display:none'>visited from $ip</span>";
303 function listToText( $list ) {
304 $cnt = count( $list );
307 // Enforce always returning a string
308 return (string)$this->arrayToString( $list[0] );
309 } elseif ( $cnt == 0 ) {
313 $t = array_slice( $list, 0, $cnt - 1 );
314 $one = array_map( array( &$this, 'arrayToString' ), $t );
315 $two = $this->arrayToString( $list[$cnt - 1] );
316 $and = wfMsg( 'and' );
318 return implode( ', ', $one ) . " $and $two";
325 * @param mixed $list Will convert an array to string if given and return
326 * the paramater unaltered otherwise
329 function arrayToString( $list ) {
330 if( is_object( $list ) ) {
331 $class = get_class( $list );
333 } elseif ( ! is_array( $list ) ) {
336 $class = get_class( $list[0] );
337 return "($class, {$list[1]})";
342 * Retrieve the revision number of a Subversion working directory.
345 * @return mixed revision number as int, or false if not a SVN checkout
347 public static function getSvnRevision( $dir ) {
348 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
349 $entries = $dir . '/.svn/entries';
351 if( !file_exists( $entries ) ) {
355 $content = file( $entries );
357 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
358 if( preg_match( '/^<\?xml/', $content[0] ) ) {
359 // subversion is release <= 1.3
360 if( !function_exists( 'simplexml_load_file' ) ) {
361 // We could fall back to expat... YUCK
365 // SimpleXml whines about the xmlns...
366 wfSuppressWarnings();
367 $xml = simplexml_load_file( $entries );
371 foreach( $xml->entry
as $entry ) {
372 if( $xml->entry
[0]['name'] == '' ) {
373 // The directory entry should always have a revision marker.
374 if( $entry['revision'] ) {
375 return intval( $entry['revision'] );
382 // subversion is release 1.4
383 return intval( $content[3] );