e477181f0497e27eae84e97f4bff6c12abc8739c
3 * Give information about the version of MediaWiki, PHP, the DB and extensions
6 * @subpackage SpecialPage
10 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
11 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
12 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
18 function wfSpecialVersion() {
19 $version = new SpecialVersion
;
23 class SpecialVersion
{
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
);
53 global $wgLanguageNames, $wgLanguageCode;
54 $mwlang = $wgLanguageNames[$wgLanguageCode];
58 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
59 copyright (C) 2001-2007 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
60 Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
61 Niklas Laxström, Domas Mituzas, Rob Church 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/copyleft/gpl.html read it online]
78 * [http://www.mediawiki.org/ MediaWiki]: $version ($wgLanguageCode $mwlang)
79 * [http://www.php.net/ PHP]: " . phpversion() . " (" . php_sapi_name() . ")
80 * " . $dbr->getSoftwareLink() . ": " . $dbr->getServerVersion();
82 return str_replace( "\t\t", '', $ret );
85 /** Return a string of the MediaWiki version with SVN revision if available */
86 public static function getVersion() {
87 global $wgVersion, $IP;
88 $svn = self
::getSvnRevision( $IP );
89 return $svn ?
"$wgVersion (r$svn)" : $wgVersion;
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' => 'Special pages',
101 'parserhook' => 'Parser hooks',
102 'variable' => 'Variables',
105 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
107 $out = "\n* Extensions:\n";
108 foreach ( $extensionTypes as $type => $text ) {
109 if ( count( @$wgExtensionCredits[$type] ) ) {
110 $out .= "** $text:\n";
112 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
114 foreach ( $wgExtensionCredits[$type] as $extension ) {
115 wfSuppressWarnings();
116 $out .= $this->formatCredits(
118 $extension['version'],
119 $extension['author'],
121 $extension['description']
128 if ( count( $wgExtensionFunctions ) ) {
129 $out .= "** Extension functions:\n";
130 $out .= '***' . $this->listToText( $wgExtensionFunctions ) . "\n";
133 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
134 for ( $i = 0; $i < $cnt; ++
$i )
135 $tags[$i] = "<{$tags[$i]}>";
136 $out .= "** Parser extension tags:\n";
137 $out .= '***' . $this->listToText( $tags ). "\n";
140 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
141 $out .= "** Parser function hooks:\n";
142 $out .= '***' . $this->listToText( $fhooks ) . "\n";
145 if ( count( $wgSkinExtensionFunction ) ) {
146 $out .= "** Skin extension functions:\n";
147 $out .= '***' . $this->listToText( $wgSkinExtensionFunction ) . "\n";
153 /** Callback to sort extensions by type */
154 function compare( $a, $b ) {
155 if ( $a['name'] === $b['name'] )
158 return Language
::lc( $a['name'] ) > Language
::lc( $b['name'] ) ?
1 : -1;
161 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null) {
166 if ( isset( $version ) )
167 $ret .= " (version $version)";
171 if ( isset( $description ) )
172 $ret .= ', ' . $description;
173 if ( isset( $description ) && isset( $author ) )
175 if ( isset( $author ) )
176 $ret .= ' by ' . $this->listToText( (array)$author );
187 if ( count( $wgHooks ) ) {
188 $myWgHooks = $wgHooks;
192 foreach ($myWgHooks as $hook => $hooks)
193 $ret .= "** $hook: " . $this->listToText( $hooks ) . "\n";
206 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
207 return "<!-- visited from $ip -->\n" .
208 "<span style='display:none'>visited from $ip</span>";
215 function listToText( $list ) {
216 $cnt = count( $list );
219 // Enforce always returning a string
220 return (string)$this->arrayToString( $list[0] );
222 $t = array_slice( $list, 0, $cnt - 1 );
223 $one = array_map( array( &$this, 'arrayToString' ), $t );
224 $two = $this->arrayToString( $list[$cnt - 1] );
226 return implode( ', ', $one ) . " and $two";
233 * @param mixed $list Will convert an array to string if given and return
234 * the paramater unaltered otherwise
237 function arrayToString( $list ) {
238 if ( ! is_array( $list ) )
241 $class = get_class( $list[0] );
242 return "($class, {$list[1]})";
247 * Retrieve the revision number of a Subversion working directory.
252 * @return mixed revision number as int, or false if not a SVN checkout
254 public static function getSvnRevision( $dir ) {
255 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
256 $entries = $dir . '/.svn/entries';
258 if( !file_exists( $entries ) ) {
262 $content = file( $entries );
264 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
265 if( preg_match( '/^<\?xml/', $content[0] ) ) {
266 // subversion is release <= 1.3
267 if( !function_exists( 'simplexml_load_file' ) ) {
268 // We could fall back to expat... YUCK
272 // SimpleXml whines about the xmlns...
273 wfSuppressWarnings();
274 $xml = simplexml_load_file( $entries );
278 foreach( $xml->entry
as $entry ) {
279 if( $xml->entry
[0]['name'] == '' ) {
280 // The directory entry should always have a revision marker.
281 if( $entry['revision'] ) {
282 return intval( $entry['revision'] );
289 // subversion is release 1.4
290 return intval( $content[3] );