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;
29 $wgOut->addHTML( '<div dir="ltr">' );
31 $this->MediaWikiCredits() .
32 $this->extensionCredits() .
35 $wgOut->addHTML( $this->IPInfo() );
36 $wgOut->addHTML( '</div>' );
44 * Return wiki text showing the licence information and third party
45 * software versions (apache, php, mysql).
48 function MediaWikiCredits() {
49 $version = self
::getVersion();
50 $dbr = wfGetDB( DB_SLAVE
);
54 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
55 copyright (C) 2001-2008 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
56 Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
57 Niklas Laxström, Domas Mituzas, Rob Church and others.
59 MediaWiki is free software; you can redistribute it and/or modify
60 it under the terms of the GNU General Public License as published by
61 the Free Software Foundation; either version 2 of the License, or
62 (at your option) any later version.
64 MediaWiki is distributed in the hope that it will be useful,
65 but WITHOUT ANY WARRANTY; without even the implied warranty of
66 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67 GNU General Public License for more details.
69 You should have received [{{SERVER}}{{SCRIPTPATH}}/COPYING a copy of the GNU General Public License]
70 along with this program; if not, write to the Free Software
71 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
72 or [http://www.gnu.org/copyleft/gpl.html read it online]
74 * [http://www.mediawiki.org/ MediaWiki]: $version
75 * [http://www.php.net/ PHP]: " . phpversion() . " (" . php_sapi_name() . ")
76 * " . $dbr->getSoftwareLink() . ": " . $dbr->getServerVersion();
78 return str_replace( "\t\t", '', $ret ) . "\n";
81 /** Return a string of the MediaWiki version with SVN revision if available */
82 public static function getVersion() {
83 global $wgVersion, $IP;
84 $svn = self
::getSvnRevision( $IP );
85 return $svn ?
"$wgVersion (r$svn)" : $wgVersion;
88 /** Generate wikitext showing extensions name, URL, author and description */
89 function extensionCredits() {
90 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunction;
92 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunction ) )
95 $extensionTypes = array(
96 'specialpage' => 'Special pages',
97 'parserhook' => 'Parser hooks',
98 'variable' => 'Variables',
99 'media' => 'Media handlers',
102 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
104 $out = "<h2>Extensions</h2>\n";
105 $out .= wfOpenElement('table', array('id' => 'sv-ext') );
107 foreach ( $extensionTypes as $type => $text ) {
108 if ( isset ( $wgExtensionCredits[$type] ) && count ( $wgExtensionCredits[$type] ) ) {
109 $out .= $this->openExtType( $text );
111 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
113 foreach ( $wgExtensionCredits[$type] as $extension ) {
114 $out .= $this->formatCredits(
115 isset ( $extension['name'] ) ?
$extension['name'] : '',
116 isset ( $extension['version'] ) ?
$extension['version'] : null,
117 isset ( $extension['author'] ) ?
$extension['author'] : '',
118 isset ( $extension['url'] ) ?
$extension['url'] : null,
119 isset ( $extension['description'] ) ?
$extension['description'] : ''
125 if ( count( $wgExtensionFunctions ) ) {
126 $out .= $this->openExtType('Extension functions');
127 $out .= '<tr><td colspan="3">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
130 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
131 for ( $i = 0; $i < $cnt; ++
$i )
132 $tags[$i] = "<{$tags[$i]}>";
133 $out .= $this->openExtType('Parser extension tags');
134 $out .= '<tr><td colspan="3">' . $this->listToText( $tags ). "</td></tr>\n";
137 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
138 $out .= $this->openExtType('Parser function hooks');
139 $out .= '<tr><td colspan="3">' . $this->listToText( $fhooks ) . "</td></tr>\n";
142 if ( count( $wgSkinExtensionFunction ) ) {
143 $out .= $this->openExtType('Skin extension functions');
144 $out .= '<tr><td colspan="3">' . $this->listToText( $wgSkinExtensionFunction ) . "</td></tr>\n";
146 $out .= wfCloseElement( 'table' );
150 /** Callback to sort extensions by type */
151 function compare( $a, $b ) {
153 if( $a['name'] === $b['name'] ) {
156 return $wgLang->lc( $a['name'] ) > $wgLang->lc( $b['name'] )
162 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null) {
167 if ( isset( $version ) )
168 $ret .= " (version $version)";
173 $ret .= "<td>$description</td>";
174 $ret .= "<td>" . $this->listToText( (array)$author ) . "</td>";
185 if ( count( $wgHooks ) ) {
186 $myWgHooks = $wgHooks;
189 $ret = "<h2>Hooks</h2>\n"
190 . wfOpenElement('table', array('id' => 'sv-hooks') )
191 . "<tr><th>Hook name</th><th>Subscribed by</th></tr>\n";
193 foreach ($myWgHooks as $hook => $hooks)
194 $ret .= "<tr><td>$hook</td><td>" . $this->listToText( $hooks ) . "</td></tr>\n";
202 private function openExtType($text, $name = null) {
203 $opt = array( 'colspan' => 3 );
206 if(!$this->firstExtOpened
) {
207 // Insert a spacing line
208 $out .= '<tr class="sv-space">' . wfElement( 'td', $opt ) . "</tr>\n";
210 $this->firstExtOpened
= false;
212 if($name) { $opt['id'] = "sv-$name"; }
214 $out .= "<tr>" . wfElement( 'th', $opt, $text) . "</tr>\n";
224 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
225 return "<!-- visited from $ip -->\n" .
226 "<span style='display:none'>visited from $ip</span>";
233 function listToText( $list ) {
234 $cnt = count( $list );
237 // Enforce always returning a string
238 return (string)$this->arrayToString( $list[0] );
239 } elseif ( $cnt == 0 ) {
242 $t = array_slice( $list, 0, $cnt - 1 );
243 $one = array_map( array( &$this, 'arrayToString' ), $t );
244 $two = $this->arrayToString( $list[$cnt - 1] );
246 return implode( ', ', $one ) . " and $two";
253 * @param mixed $list Will convert an array to string if given and return
254 * the paramater unaltered otherwise
257 function arrayToString( $list ) {
258 if( is_object( $list ) ) {
259 $class = get_class( $list );
261 } elseif ( ! is_array( $list ) ) {
264 $class = get_class( $list[0] );
265 return "($class, {$list[1]})";
270 * Retrieve the revision number of a Subversion working directory.
273 * @return mixed revision number as int, or false if not a SVN checkout
275 public static function getSvnRevision( $dir ) {
276 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
277 $entries = $dir . '/.svn/entries';
279 if( !file_exists( $entries ) ) {
283 $content = file( $entries );
285 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
286 if( preg_match( '/^<\?xml/', $content[0] ) ) {
287 // subversion is release <= 1.3
288 if( !function_exists( 'simplexml_load_file' ) ) {
289 // We could fall back to expat... YUCK
293 // SimpleXml whines about the xmlns...
294 wfSuppressWarnings();
295 $xml = simplexml_load_file( $entries );
299 foreach( $xml->entry
as $entry ) {
300 if( $xml->entry
[0]['name'] == '' ) {
301 // The directory entry should always have a revision marker.
302 if( $entry['revision'] ) {
303 return intval( $entry['revision'] );
310 // subversion is release 1.4
311 return intval( $content[3] );