4a9fad00f9bcc45001ae363a18ee40127ac1ca95
3 * Give information about the version of MediaWiki, PHP, the DB and extensions
5 * @addtogroup SpecialPage
7 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
8 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
9 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
15 function wfSpecialVersion() {
16 $version = new SpecialVersion
;
20 class SpecialVersion
{
21 private $firstExtOpened = true;
27 global $wgOut, $wgMessageCache;
28 $wgMessageCache->loadAllMessages();
30 $wgOut->addHTML( '<div dir="ltr">' );
32 $this->MediaWikiCredits() .
33 $this->extensionCredits() .
36 $wgOut->addHTML( $this->IPInfo() );
37 $wgOut->addHTML( '</div>' );
45 * Return wiki text showing the licence information and third party
46 * software versions (apache, php, mysql).
49 function MediaWikiCredits() {
50 $version = self
::getVersion();
51 $dbr = wfGetDB( DB_SLAVE
);
55 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
56 copyright (C) 2001-2008 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
57 Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
58 Niklas Laxström, Domas Mituzas, Rob Church and others.
60 MediaWiki is free software; you can redistribute it and/or modify
61 it under the terms of the GNU General Public License as published by
62 the Free Software Foundation; either version 2 of the License, or
63 (at your option) any later version.
65 MediaWiki is distributed in the hope that it will be useful,
66 but WITHOUT ANY WARRANTY; without even the implied warranty of
67 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68 GNU General Public License for more details.
70 You should have received [{{SERVER}}{{SCRIPTPATH}}/COPYING a copy of the GNU General Public License]
71 along with this program; if not, write to the Free Software
72 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
73 or [http://www.gnu.org/copyleft/gpl.html read it online]
75 * [http://www.mediawiki.org/ MediaWiki]: $version
76 * [http://www.php.net/ PHP]: " . phpversion() . " (" . php_sapi_name() . ")
77 * " . $dbr->getSoftwareLink() . ": " . $dbr->getServerVersion();
79 return str_replace( "\t\t", '', $ret ) . "\n";
82 /** Return a string of the MediaWiki version with SVN revision if available */
83 public static function getVersion() {
84 global $wgVersion, $IP;
85 wfProfileIn( __METHOD__
);
86 $svn = self
::getSvnRevision( $IP );
87 $version = $svn ?
"$wgVersion (r$svn)" : $wgVersion;
88 wfProfileOut( __METHOD__
);
92 /** Generate wikitext showing extensions name, URL, author and description */
93 function extensionCredits() {
94 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunction;
96 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunction ) )
99 $extensionTypes = array(
100 'specialpage' => wfMsg( 'version-specialpages' ),
101 'parserhook' => wfMsg( 'version-parserhooks' ),
102 'variable' => wfMsg( 'version-variables' ),
103 'media' => wfMsg( 'version-mediahandlers' ),
104 'other' => wfMsg( 'version-other' ),
106 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
108 $out = Xml
::element( 'h2', array( 'id' => 'mw-version-ext' ), wfMsg( 'version-extensions' ) ) .
109 Xml
::openElement( 'table', array( 'id' => 'sv-ext' ) );
111 foreach ( $extensionTypes as $type => $text ) {
112 if ( isset ( $wgExtensionCredits[$type] ) && count ( $wgExtensionCredits[$type] ) ) {
113 $out .= $this->openExtType( $text );
115 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
117 foreach ( $wgExtensionCredits[$type] as $extension ) {
118 $out .= $this->formatCredits(
119 isset ( $extension['name'] ) ?
$extension['name'] : '',
120 isset ( $extension['version'] ) ?
$extension['version'] : null,
121 isset ( $extension['author'] ) ?
$extension['author'] : '',
122 isset ( $extension['url'] ) ?
$extension['url'] : null,
123 isset ( $extension['description'] ) ?
$extension['description'] : '',
124 isset ( $extension['descriptionmsg'] ) ?
$extension['descriptionmsg'] : ''
130 if ( count( $wgExtensionFunctions ) ) {
131 $out .= $this->openExtType( wfMsg( 'version-extension-functions' ) );
132 $out .= '<tr><td colspan="3">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
135 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
136 for ( $i = 0; $i < $cnt; ++
$i )
137 $tags[$i] = "<{$tags[$i]}>";
138 $out .= $this->openExtType( wfMsg( 'version-parser-extensiontags' ) );
139 $out .= '<tr><td colspan="3">' . $this->listToText( $tags ). "</td></tr>\n";
142 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
143 $out .= $this->openExtType( wfMsg( 'version-parser-function-hooks' ) );
144 $out .= '<tr><td colspan="3">' . $this->listToText( $fhooks ) . "</td></tr>\n";
147 if ( count( $wgSkinExtensionFunction ) ) {
148 $out .= $this->openExtType( wfMsg( 'version-skin-extension-functions' ) );
149 $out .= '<tr><td colspan="3">' . $this->listToText( $wgSkinExtensionFunction ) . "</td></tr>\n";
151 $out .= Xml
::closeElement( 'table' );
155 /** Callback to sort extensions by type */
156 function compare( $a, $b ) {
158 if( $a['name'] === $b['name'] ) {
161 return $wgLang->lc( $a['name'] ) > $wgLang->lc( $b['name'] )
167 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null, $descriptionMsg = null ) {
168 $extension = isset( $url ) ?
"[$url $name]" : $name;
169 $version = isset( $version ) ?
"(" . wfMsg( 'version-version' ) . " $version)" : '';
171 # Look for a localized description
172 if( isset( $descriptionMsg ) ) {
173 $msg = wfMsg( $descriptionMsg );
174 if ( !wfEmptyMsg( $descriptionMsg, $msg ) && $msg != '' ) {
180 <td><em>$extension $version</em></td>
181 <td>$description</td>
182 <td>" . $this->listToText( (array)$author ) . "</td>
192 if ( count( $wgHooks ) ) {
193 $myWgHooks = $wgHooks;
196 $ret = Xml
::element( 'h2', array( 'id' => 'mw-version-hooks' ), wfMsg( 'version-hooks' ) ) .
197 Xml
::openElement( 'table', array( 'id' => 'sv-hooks' ) ) .
199 <th>" . wfMsg( 'version-hook-name' ) . "</th>
200 <th>" . wfMsg( 'version-hook-subscribedby' ) . "</th>
203 foreach ( $myWgHooks as $hook => $hooks )
206 <td>" . $this->listToText( $hooks ) . "</td>
209 $ret .= Xml
::closeElement( 'table' );
215 private function openExtType($text, $name = null) {
216 $opt = array( 'colspan' => 3 );
219 if(!$this->firstExtOpened
) {
220 // Insert a spacing line
221 $out .= '<tr class="sv-space">' . Xml
::element( 'td', $opt ) . "</tr>\n";
223 $this->firstExtOpened
= false;
225 if($name) { $opt['id'] = "sv-$name"; }
227 $out .= "<tr>" . Xml
::element( 'th', $opt, $text) . "</tr>\n";
237 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
238 return "<!-- visited from $ip -->\n" .
239 "<span style='display:none'>visited from $ip</span>";
246 function listToText( $list ) {
247 $cnt = count( $list );
250 // Enforce always returning a string
251 return (string)$this->arrayToString( $list[0] );
252 } elseif ( $cnt == 0 ) {
256 $t = array_slice( $list, 0, $cnt - 1 );
257 $one = array_map( array( &$this, 'arrayToString' ), $t );
258 $two = $this->arrayToString( $list[$cnt - 1] );
259 $and = wfMsg( 'and' );
261 return implode( ', ', $one ) . " $and $two";
268 * @param mixed $list Will convert an array to string if given and return
269 * the paramater unaltered otherwise
272 function arrayToString( $list ) {
273 if( is_object( $list ) ) {
274 $class = get_class( $list );
276 } elseif ( ! is_array( $list ) ) {
279 $class = get_class( $list[0] );
280 return "($class, {$list[1]})";
285 * Retrieve the revision number of a Subversion working directory.
288 * @return mixed revision number as int, or false if not a SVN checkout
290 public static function getSvnRevision( $dir ) {
291 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
292 $entries = $dir . '/.svn/entries';
294 if( !file_exists( $entries ) ) {
298 $content = file( $entries );
300 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
301 if( preg_match( '/^<\?xml/', $content[0] ) ) {
302 // subversion is release <= 1.3
303 if( !function_exists( 'simplexml_load_file' ) ) {
304 // We could fall back to expat... YUCK
308 // SimpleXml whines about the xmlns...
309 wfSuppressWarnings();
310 $xml = simplexml_load_file( $entries );
314 foreach( $xml->entry
as $entry ) {
315 if( $xml->entry
[0]['name'] == '' ) {
316 // The directory entry should always have a revision marker.
317 if( $entry['revision'] ) {
318 return intval( $entry['revision'] );
325 // subversion is release 1.4
326 return intval( $content[3] );