* (bug 14604) Update LanguageConverter for T (Title) conversion
[mediawiki.git] / includes / specials / SpecialVersion.php
blob8c8e386d110c3ba94ea2db24e3663b1d5cd6fe98
1 <?php
2 /**#@+
3 * Give information about the version of MediaWiki, PHP, the DB and extensions
5 * @file
6 * @ingroup SpecialPage
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
13 /**
14 * constructor
16 function wfSpecialVersion() {
17 $version = new SpecialVersion;
18 $version->execute();
21 /**
22 * @ingroup SpecialPage
24 class SpecialVersion {
25 private $firstExtOpened = true;
27 /**
28 * main()
30 function execute() {
31 global $wgOut, $wgMessageCache, $wgSpecialVersionShowHooks;
32 $wgMessageCache->loadAllMessages();
34 $wgOut->addHTML( '<div dir="ltr">' );
35 $text =
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>' );
47 /**#@+
48 * @private
51 /**
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' ) ) .
56 "__NOTOC__
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";
82 /**
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' ) ) .
90 "<tr>
91 <th>" . wfMsg( 'version-software-product' ) . "</th>
92 <th>" . wfMsg( 'version-software-version' ) . "</th>
93 </tr>\n
94 <tr>
95 <td>[http://www.mediawiki.org/ MediaWiki]</td>
96 <td>" . self::getVersionLinked() . "</td>
97 </tr>\n
98 <tr>
99 <td>[http://www.php.net/ PHP]</td>
100 <td>" . phpversion() . " (" . php_sapi_name() . ")</td>
101 </tr>\n
102 <tr>
103 <td>" . $dbr->getSoftwareLink() . "</td>
104 <td>" . $dbr->getServerVersion() . "</td>
105 </tr>\n" .
106 Xml::closeElement( 'table' );
110 * Return a string of the MediaWiki version with SVN revision if available
112 * @return mixed
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__ );
120 return $version;
124 * Return a string of the MediaWiki version with a link to SVN revision if
125 * available
127 * @return mixed
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__ );
136 return $version;
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 ) )
144 return '';
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];
172 } else {
173 $version = null;
176 $out .= $this->formatCredits(
177 isset ( $extension['name'] ) ? $extension['name'] : '',
178 $version,
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] = "&lt;{$tags[$i]}&gt;";
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' );
210 return $out;
213 /** Callback to sort extensions by type */
214 function compare( $a, $b ) {
215 global $wgLang;
216 if( $a['name'] === $b['name'] ) {
217 return 0;
218 } else {
219 return $wgLang->lc( $a['name'] ) > $wgLang->lc( $b['name'] )
221 : -1;
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 != '' ) {
233 $description = $msg;
237 return "<tr>
238 <td><em>$extension $version</em></td>
239 <td>$description</td>
240 <td>" . $this->listToText( (array)$author ) . "</td>
241 </tr>\n";
245 * @return string
247 function wgHooks() {
248 global $wgHooks;
250 if ( count( $wgHooks ) ) {
251 $myWgHooks = $wgHooks;
252 ksort( $myWgHooks );
254 $ret = Xml::element( 'h2', array( 'id' => 'mw-version-hooks' ), wfMsg( 'version-hooks' ) ) .
255 Xml::openElement( 'table', array( 'id' => 'sv-hooks' ) ) .
256 "<tr>
257 <th>" . wfMsg( 'version-hook-name' ) . "</th>
258 <th>" . wfMsg( 'version-hook-subscribedby' ) . "</th>
259 </tr>\n";
261 foreach ( $myWgHooks as $hook => $hooks )
262 $ret .= "<tr>
263 <td>$hook</td>
264 <td>" . $this->listToText( $hooks ) . "</td>
265 </tr>\n";
267 $ret .= Xml::closeElement( 'table' );
268 return $ret;
269 } else
270 return '';
273 private function openExtType($text, $name = null) {
274 $opt = array( 'colspan' => 3 );
275 $out = '';
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";
286 return $out;
290 * @static
292 * @return string
294 function IPInfo() {
295 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
296 return "<!-- visited from $ip -->\n" .
297 "<span style='display:none'>visited from $ip</span>";
301 * @param array $list
302 * @return string
304 function listToText( $list ) {
305 $cnt = count( $list );
307 if ( $cnt == 1 ) {
308 // Enforce always returning a string
309 return (string)$this->arrayToString( $list[0] );
310 } elseif ( $cnt == 0 ) {
311 return '';
312 } else {
313 sort( $list );
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";
324 * @static
326 * @param mixed $list Will convert an array to string if given and return
327 * the paramater unaltered otherwise
328 * @return mixed
330 function arrayToString( $list ) {
331 if( is_object( $list ) ) {
332 $class = get_class( $list );
333 return "($class)";
334 } elseif ( ! is_array( $list ) ) {
335 return $list;
336 } else {
337 $class = get_class( $list[0] );
338 return "($class, {$list[1]})";
343 * Retrieve the revision number of a Subversion working directory.
345 * @param string $dir
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 ) ) {
353 return false;
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
363 return false;
366 // SimpleXml whines about the xmlns...
367 wfSuppressWarnings();
368 $xml = simplexml_load_file( $entries );
369 wfRestoreWarnings();
371 if( $xml ) {
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'] );
381 return false;
382 } else {
383 // subversion is release 1.4
384 return intval( $content[3] );
388 /**#@-*/
391 /**#@-*/