3 * Give information about the version of MediaWiki, PHP, the DB and extensions
5 * @addtogroup SpecialPage
9 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
10 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
11 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
17 function wfSpecialVersion() {
18 $version = new SpecialVersion
;
22 class SpecialVersion
{
23 private $firstExtOpened = true;
31 $wgOut->addHTML( '<div dir="ltr">' );
33 $this->MediaWikiCredits() .
34 $this->extensionCredits() .
37 $wgOut->addHTML( $this->IPInfo() );
38 $wgOut->addHTML( '</div>' );
46 * Return wiki text showing the licence information and third party
47 * software versions (apache, php, mysql).
50 function MediaWikiCredits() {
51 $version = self
::getVersion();
52 $dbr = wfGetDB( DB_SLAVE
);
56 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
57 copyright (C) 2001-2007 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
58 Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
59 Niklas Laxström, Domas Mituzas, Rob Church and others.
61 MediaWiki is free software; you can redistribute it and/or modify
62 it under the terms of the GNU General Public License as published by
63 the Free Software Foundation; either version 2 of the License, or
64 (at your option) any later version.
66 MediaWiki is distributed in the hope that it will be useful,
67 but WITHOUT ANY WARRANTY; without even the implied warranty of
68 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69 GNU General Public License for more details.
71 You should have received [{{SERVER}}{{SCRIPTPATH}}/COPYING a copy of the GNU General Public License]
72 along with this program; if not, write to the Free Software
73 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
74 or [http://www.gnu.org/copyleft/gpl.html read it online]
76 * [http://www.mediawiki.org/ MediaWiki]: $version
77 * [http://www.php.net/ PHP]: " . phpversion() . " (" . php_sapi_name() . ")
78 * " . $dbr->getSoftwareLink() . ": " . $dbr->getServerVersion();
80 return str_replace( "\t\t", '', $ret ) . "\n";
83 /** Return a string of the MediaWiki version with SVN revision if available */
84 public static function getVersion() {
85 global $wgVersion, $IP;
86 $svn = self
::getSvnRevision( $IP );
87 return $svn ?
"$wgVersion (r$svn)" : $wgVersion;
90 /** Generate wikitext showing extensions name, URL, author and description */
91 function extensionCredits() {
92 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunction;
94 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunction ) )
97 $extensionTypes = array(
98 'specialpage' => 'Special pages',
99 'parserhook' => 'Parser hooks',
100 'variable' => 'Variables',
103 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
105 $out = "<h2>Extensions</h2>\n";
106 $out .= wfOpenElement('table', array('id' => 'sv-ext') );
108 foreach ( $extensionTypes as $type => $text ) {
109 if ( isset ( $wgExtensionCredits[$type] ) && count ( $wgExtensionCredits[$type] ) ) {
110 $out .= $this->openExtType( $text );
112 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
114 foreach ( $wgExtensionCredits[$type] as $extension ) {
115 $out .= $this->formatCredits(
116 isset ( $extension['name'] ) ?
$extension['name'] : '',
117 isset ( $extension['version'] ) ?
$extension['version'] : null,
118 isset ( $extension['author'] ) ?
$extension['author'] : '',
119 isset ( $extension['url'] ) ?
$extension['url'] : null,
120 isset ( $extension['description'] ) ?
$extension['description'] : ''
126 if ( count( $wgExtensionFunctions ) ) {
127 $out .= $this->openExtType('Extension functions');
128 $out .= '<tr><td colspan="3">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
131 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
132 for ( $i = 0; $i < $cnt; ++
$i )
133 $tags[$i] = "<{$tags[$i]}>";
134 $out .= $this->openExtType('Parser extension tags');
135 $out .= '<tr><td colspan="3">' . $this->listToText( $tags ). "</td></tr>\n";
138 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
139 $out .= $this->openExtType('Parser function hooks');
140 $out .= '<tr><td colspan="3">' . $this->listToText( $fhooks ) . "</td></tr>\n";
143 if ( count( $wgSkinExtensionFunction ) ) {
144 $out .= $this->openExtType('Skin extension functions');
145 $out .= '<tr><td colspan="3">' . $this->listToText( $wgSkinExtensionFunction ) . "</td></tr>\n";
147 $out .= wfCloseElement( 'table' );
151 /** Callback to sort extensions by type */
152 function compare( $a, $b ) {
153 if ( $a['name'] === $b['name'] )
156 return Language
::lc( $a['name'] ) > Language
::lc( $b['name'] ) ?
1 : -1;
159 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null) {
164 if ( isset( $version ) )
165 $ret .= " (version $version)";
170 $ret .= "<td>$description</td>";
171 $ret .= "<td>" . $this->listToText( (array)$author ) . "</td>";
182 if ( count( $wgHooks ) ) {
183 $myWgHooks = $wgHooks;
186 $ret = "<h2>Hooks</h2>\n"
187 . wfOpenElement('table', array('id' => 'sv-hooks') )
188 . "<tr><th>Hook name</th><th>Subscribed by</th></tr>\n";
190 foreach ($myWgHooks as $hook => $hooks)
191 $ret .= "<tr><td>$hook</td><td>" . $this->listToText( $hooks ) . "</td></tr>\n";
199 private function openExtType($text, $name = null) {
200 $opt = array( 'colspan' => 3 );
203 if(!$this->firstExtOpened
) {
204 // Insert a spacing line
205 $out .= '<tr class="sv-space">' . wfElement( 'td', $opt ) . "</tr>\n";
207 $this->firstExtOpened
= false;
209 if($name) { $opt['id'] = "sv-$name"; }
211 $out .= "<tr>" . wfElement( 'th', $opt, $text) . "</tr>\n";
221 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
222 return "<!-- visited from $ip -->\n" .
223 "<span style='display:none'>visited from $ip</span>";
230 function listToText( $list ) {
231 $cnt = count( $list );
234 // Enforce always returning a string
235 return (string)$this->arrayToString( $list[0] );
236 } elseif ( $cnt == 0 ) {
239 $t = array_slice( $list, 0, $cnt - 1 );
240 $one = array_map( array( &$this, 'arrayToString' ), $t );
241 $two = $this->arrayToString( $list[$cnt - 1] );
243 return implode( ', ', $one ) . " and $two";
250 * @param mixed $list Will convert an array to string if given and return
251 * the paramater unaltered otherwise
254 function arrayToString( $list ) {
255 if ( ! is_array( $list ) ) {
258 $class = get_class( $list[0] );
259 return "($class, {$list[1]})";
264 * Retrieve the revision number of a Subversion working directory.
269 * @return mixed revision number as int, or false if not a SVN checkout
271 public static function getSvnRevision( $dir ) {
272 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
273 $entries = $dir . '/.svn/entries';
275 if( !file_exists( $entries ) ) {
279 $content = file( $entries );
281 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
282 if( preg_match( '/^<\?xml/', $content[0] ) ) {
283 // subversion is release <= 1.3
284 if( !function_exists( 'simplexml_load_file' ) ) {
285 // We could fall back to expat... YUCK
289 $xml = simplexml_load_file( $entries, "SimpleXMLElement", LIBXML_NOWARNING
);
292 foreach( $xml->entry
as $entry ) {
293 if( $xml->entry
[0]['name'] == '' ) {
294 // The directory entry should always have a revision marker.
295 if( $entry['revision'] ) {
296 return intval( $entry['revision'] );
303 // subversion is release 1.4
304 return intval( $content[3] );