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, Aryeh Gregor,
61 Aaron Schulz and others.
63 MediaWiki is free software; you can redistribute it and/or modify
64 it under the terms of the GNU General Public License as published by
65 the Free Software Foundation; either version 2 of the License, or
66 (at your option) any later version.
68 MediaWiki is distributed in the hope that it will be useful,
69 but WITHOUT ANY WARRANTY; without even the implied warranty of
70 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
71 GNU General Public License for more details.
73 You should have received [{{SERVER}}{{SCRIPTPATH}}/COPYING a copy of the GNU General Public License]
74 along with this program; if not, write to the Free Software
75 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
76 or [http://www.gnu.org/licenses/old-licenses/gpl-2.0.html read it online].
79 return str_replace( "\t\t", '', $ret ) . "\n";
83 * @return wiki text showing the third party software versions (apache, php, mysql).
85 static function softwareInformation() {
86 $dbr = wfGetDB( DB_SLAVE
);
88 return Xml
::element( 'h2', array( 'id' => 'mw-version-software' ), wfMsg( 'version-software' ) ) .
89 Xml
::openElement( 'table', array( 'id' => 'sv-software' ) ) .
91 <th>" . wfMsg( 'version-software-product' ) . "</th>
92 <th>" . wfMsg( 'version-software-version' ) . "</th>
95 <td>[http://www.mediawiki.org/ MediaWiki]</td>
96 <td>" . self
::getVersionLinked() . "</td>
99 <td>[http://www.php.net/ PHP]</td>
100 <td>" . phpversion() . " (" . php_sapi_name() . ")</td>
103 <td>" . $dbr->getSoftwareLink() . "</td>
104 <td>" . $dbr->getServerVersion() . "</td>
106 Xml
::closeElement( 'table' );
110 * Return a string of the MediaWiki version with SVN revision if available
114 public static function getVersion() {
115 global $wgVersion, $IP;
116 wfProfileIn( __METHOD__
);
117 $svn = self
::getSvnRevision( $IP );
118 $version = $svn ?
"$wgVersion (r$svn)" : $wgVersion;
119 wfProfileOut( __METHOD__
);
124 * Return a string of the MediaWiki version with a link to SVN revision if
129 public static function getVersionLinked() {
130 global $wgVersion, $IP;
131 wfProfileIn( __METHOD__
);
132 $svn = self
::getSvnRevision( $IP );
133 $viewvc = 'http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/?pathrev=';
134 $version = $svn ?
"$wgVersion ([{$viewvc}{$svn} r$svn])" : $wgVersion;
135 wfProfileOut( __METHOD__
);
139 /** Generate wikitext showing extensions name, URL, author and description */
140 function extensionCredits() {
141 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunctions;
143 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunctions ) )
146 $extensionTypes = array(
147 'specialpage' => wfMsg( 'version-specialpages' ),
148 'parserhook' => wfMsg( 'version-parserhooks' ),
149 'variable' => wfMsg( 'version-variables' ),
150 'media' => wfMsg( 'version-mediahandlers' ),
151 'other' => wfMsg( 'version-other' ),
153 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
155 $out = Xml
::element( 'h2', array( 'id' => 'mw-version-ext' ), wfMsg( 'version-extensions' ) ) .
156 Xml
::openElement( 'table', array( 'id' => 'sv-ext' ) );
158 foreach ( $extensionTypes as $type => $text ) {
159 if ( isset ( $wgExtensionCredits[$type] ) && count ( $wgExtensionCredits[$type] ) ) {
160 $out .= $this->openExtType( $text );
162 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
164 foreach ( $wgExtensionCredits[$type] as $extension ) {
165 if ( isset( $extension['version'] ) ) {
166 $version = $extension['version'];
167 } elseif ( isset( $extension['svn-revision'] ) &&
168 preg_match( '/\$(?:Rev|LastChangedRevision|Revision): *(\d+)/',
169 $extension['svn-revision'], $m ) )
171 $version = 'r' . $m[1];
176 $out .= $this->formatCredits(
177 isset ( $extension['name'] ) ?
$extension['name'] : '',
179 isset ( $extension['author'] ) ?
$extension['author'] : '',
180 isset ( $extension['url'] ) ?
$extension['url'] : null,
181 isset ( $extension['description'] ) ?
$extension['description'] : '',
182 isset ( $extension['descriptionmsg'] ) ?
$extension['descriptionmsg'] : ''
188 if ( count( $wgExtensionFunctions ) ) {
189 $out .= $this->openExtType( wfMsg( 'version-extension-functions' ) );
190 $out .= '<tr><td colspan="3">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
193 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
194 for ( $i = 0; $i < $cnt; ++
$i )
195 $tags[$i] = "<{$tags[$i]}>";
196 $out .= $this->openExtType( wfMsg( 'version-parser-extensiontags' ) );
197 $out .= '<tr><td colspan="3">' . $this->listToText( $tags ). "</td></tr>\n";
200 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
201 $out .= $this->openExtType( wfMsg( 'version-parser-function-hooks' ) );
202 $out .= '<tr><td colspan="3">' . $this->listToText( $fhooks ) . "</td></tr>\n";
205 if ( count( $wgSkinExtensionFunctions ) ) {
206 $out .= $this->openExtType( wfMsg( 'version-skin-extension-functions' ) );
207 $out .= '<tr><td colspan="3">' . $this->listToText( $wgSkinExtensionFunctions ) . "</td></tr>\n";
209 $out .= Xml
::closeElement( 'table' );
213 /** Callback to sort extensions by type */
214 function compare( $a, $b ) {
216 if( $a['name'] === $b['name'] ) {
219 return $wgLang->lc( $a['name'] ) > $wgLang->lc( $b['name'] )
225 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null, $descriptionMsg = null ) {
226 $extension = isset( $url ) ?
"[$url $name]" : $name;
227 $version = isset( $version ) ?
"(" . wfMsg( 'version-version' ) . " $version)" : '';
229 # Look for a localized description
230 if( isset( $descriptionMsg ) ) {
231 $msg = wfMsg( $descriptionMsg );
232 if ( !wfEmptyMsg( $descriptionMsg, $msg ) && $msg != '' ) {
238 <td><em>$extension $version</em></td>
239 <td>$description</td>
240 <td>" . $this->listToText( (array)$author ) . "</td>
250 if ( count( $wgHooks ) ) {
251 $myWgHooks = $wgHooks;
254 $ret = Xml
::element( 'h2', array( 'id' => 'mw-version-hooks' ), wfMsg( 'version-hooks' ) ) .
255 Xml
::openElement( 'table', array( 'id' => 'sv-hooks' ) ) .
257 <th>" . wfMsg( 'version-hook-name' ) . "</th>
258 <th>" . wfMsg( 'version-hook-subscribedby' ) . "</th>
261 foreach ( $myWgHooks as $hook => $hooks )
264 <td>" . $this->listToText( $hooks ) . "</td>
267 $ret .= Xml
::closeElement( 'table' );
273 private function openExtType($text, $name = null) {
274 $opt = array( 'colspan' => 3 );
277 if(!$this->firstExtOpened
) {
278 // Insert a spacing line
279 $out .= '<tr class="sv-space">' . Xml
::element( 'td', $opt ) . "</tr>\n";
281 $this->firstExtOpened
= false;
283 if($name) { $opt['id'] = "sv-$name"; }
285 $out .= "<tr>" . Xml
::element( 'th', $opt, $text) . "</tr>\n";
295 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
296 return "<!-- visited from $ip -->\n" .
297 "<span style='display:none'>visited from $ip</span>";
304 function listToText( $list ) {
305 $cnt = count( $list );
308 // Enforce always returning a string
309 return (string)$this->arrayToString( $list[0] );
310 } elseif ( $cnt == 0 ) {
314 $t = array_slice( $list, 0, $cnt - 1 );
315 $one = array_map( array( &$this, 'arrayToString' ), $t );
316 $two = $this->arrayToString( $list[$cnt - 1] );
317 $and = wfMsg( 'and' );
319 return implode( ', ', $one ) . " $and $two";
326 * @param mixed $list Will convert an array to string if given and return
327 * the paramater unaltered otherwise
330 function arrayToString( $list ) {
331 if( is_object( $list ) ) {
332 $class = get_class( $list );
334 } elseif ( ! is_array( $list ) ) {
337 $class = get_class( $list[0] );
338 return "($class, {$list[1]})";
343 * Retrieve the revision number of a Subversion working directory.
346 * @return mixed revision number as int, or false if not a SVN checkout
348 public static function getSvnRevision( $dir ) {
349 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
350 $entries = $dir . '/.svn/entries';
352 if( !file_exists( $entries ) ) {
356 $content = file( $entries );
358 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
359 if( preg_match( '/^<\?xml/', $content[0] ) ) {
360 // subversion is release <= 1.3
361 if( !function_exists( 'simplexml_load_file' ) ) {
362 // We could fall back to expat... YUCK
366 // SimpleXml whines about the xmlns...
367 wfSuppressWarnings();
368 $xml = simplexml_load_file( $entries );
372 foreach( $xml->entry
as $entry ) {
373 if( $xml->entry
[0]['name'] == '' ) {
374 // The directory entry should always have a revision marker.
375 if( $entry['revision'] ) {
376 return intval( $entry['revision'] );
383 // subversion is release 1.4
384 return intval( $content[3] );