* Reset the release notes
[mediawiki.git] / includes / SpecialVersion.php
blobdba694c058185b2049bfbd63760fac8db256124f
1 <?php
2 /**#@+
3 * Give information about the version of MediaWiki, PHP, the DB and extensions
5 * @package MediaWiki
6 * @subpackage SpecialPage
8 * @bug 2019, 4531
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
15 /**
16 * constructor
18 function wfSpecialVersion() {
19 $version = new SpecialVersion;
20 $version->execute();
23 class SpecialVersion {
24 private $firstExtOpened = true;
26 /**
27 * main()
29 function execute() {
30 global $wgOut;
32 $wgOut->addHTML( '<div dir="ltr">' );
33 $wgOut->addWikiText(
34 $this->MediaWikiCredits() .
35 $this->extensionCredits() .
36 $this->wgHooks()
38 $wgOut->addHTML( $this->IPInfo() );
39 $wgOut->addHTML( '</div>' );
42 /**#@+
43 * @private
46 /**
47 * Return wiki text showing the licence information and third party
48 * software versions (apache, php, mysql).
49 * @static
51 function MediaWikiCredits() {
52 $version = self::getVersion();
53 $dbr =& wfGetDB( DB_SLAVE );
55 global $wgLanguageNames, $wgLanguageCode;
56 $mwlang = $wgLanguageNames[$wgLanguageCode];
58 $ret =
59 "__NOTOC__
60 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
61 copyright (C) 2001-2007 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
62 Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
63 Niklas Laxström, Domas Mituzas, Rob Church and others.
65 MediaWiki is free software; you can redistribute it and/or modify
66 it under the terms of the GNU General Public License as published by
67 the Free Software Foundation; either version 2 of the License, or
68 (at your option) any later version.
70 MediaWiki is distributed in the hope that it will be useful,
71 but WITHOUT ANY WARRANTY; without even the implied warranty of
72 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
73 GNU General Public License for more details.
75 You should have received [{{SERVER}}{{SCRIPTPATH}}/COPYING a copy of the GNU General Public License]
76 along with this program; if not, write to the Free Software
77 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
78 or [http://www.gnu.org/copyleft/gpl.html read it online]
80 * [http://www.mediawiki.org/ MediaWiki]: $version
81 * [http://www.php.net/ PHP]: " . phpversion() . " (" . php_sapi_name() . ")
82 * " . $dbr->getSoftwareLink() . ": " . $dbr->getServerVersion();
84 return str_replace( "\t\t", '', $ret ) . "\n";
87 /** Return a string of the MediaWiki version with SVN revision if available */
88 public static function getVersion() {
89 global $wgVersion, $IP;
90 $svn = self::getSvnRevision( $IP );
91 return $svn ? "$wgVersion (r$svn)" : $wgVersion;
94 /** Generate wikitext showing extensions name, URL, author and description */
95 function extensionCredits() {
96 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunction;
98 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunction ) )
99 return '';
101 $extensionTypes = array(
102 'specialpage' => 'Special pages',
103 'parserhook' => 'Parser hooks',
104 'variable' => 'Variables',
105 'other' => 'Other',
107 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
109 $out = "<h2>Extensions</h2>\n";
110 $out .= wfOpenElement('table', array('id' => 'sv-ext') );
112 foreach ( $extensionTypes as $type => $text ) {
113 if ( count( @$wgExtensionCredits[$type] ) ) {
114 $out .= $this->openExtType( $text );
116 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
118 foreach ( $wgExtensionCredits[$type] as $extension ) {
119 wfSuppressWarnings();
120 $out .= $this->formatCredits(
121 $extension['name'],
122 $extension['version'],
123 $extension['author'],
124 $extension['url'],
125 $extension['description']
127 wfRestoreWarnings();
132 if ( count( $wgExtensionFunctions ) ) {
133 $out .= $this->openExtType('Extension functions');
134 $out .= '<tr><td colspan="3">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
137 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
138 for ( $i = 0; $i < $cnt; ++$i )
139 $tags[$i] = "&lt;{$tags[$i]}&gt;";
140 $out .= $this->openExtType('Parser extension tags');
141 $out .= '<tr><td colspan="3">' . $this->listToText( $tags ). "</td></tr>\n";
144 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
145 $out .= $this->openExtType('Parser function hooks');
146 $out .= '<tr><td colspan="3">' . $this->listToText( $fhooks ) . "</td></tr>\n";
149 if ( count( $wgSkinExtensionFunction ) ) {
150 $out .= $this->openExtType('Skin extension functions');
151 $out .= '<tr><td colspan="3">' . $this->listToText( $wgSkinExtensionFunction ) . "</td></tr>\n";
153 $out .= wfCloseElement( 'table' );
154 return $out;
157 /** Callback to sort extensions by type */
158 function compare( $a, $b ) {
159 if ( $a['name'] === $b['name'] )
160 return 0;
161 else
162 return Language::lc( $a['name'] ) > Language::lc( $b['name'] ) ? 1 : -1;
165 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null) {
166 $ret = '<tr><td>';
167 if ( isset( $url ) )
168 $ret .= "[$url ";
169 $ret .= "''$name";
170 if ( isset( $version ) )
171 $ret .= " (version $version)";
172 $ret .= "''";
173 if ( isset( $url ) )
174 $ret .= ']';
175 $ret .= '</td>';
176 $ret .= "<td>$description</td>";
177 $ret .= "<td>" . $this->listToText( (array)$author ) . "</td>";
178 $ret .= '</tr>';
179 return "$ret\n";
183 * @return string
185 function wgHooks() {
186 global $wgHooks;
188 if ( count( $wgHooks ) ) {
189 $myWgHooks = $wgHooks;
190 ksort( $myWgHooks );
192 $ret = "<h2>Hooks</h2>\n"
193 . wfOpenElement('table', array('id' => 'sv-hooks') )
194 . "<tr><th>Hook name</th><th>Subscribed by</th></tr>\n";
196 foreach ($myWgHooks as $hook => $hooks)
197 $ret .= "<tr><td>$hook</td><td>" . $this->listToText( $hooks ) . "</td></tr>\n";
199 $ret .= '</table>';
200 return $ret;
201 } else
202 return '';
205 private function openExtType($text, $name = null) {
206 $opt = array( 'colspan' => 3 );
207 $out = '';
209 if(!$this->firstExtOpened) {
210 // Insert a spacing line
211 $out .= '<tr class="sv-space">' . wfElement( 'td', $opt ) . "</tr>\n";
213 $this->firstExtOpened = false;
215 if($name) { $opt['id'] = "sv-$name"; }
217 $out .= "<tr>" . wfElement( 'th', $opt, $text) . "</tr>\n";
218 return $out;
222 * @static
224 * @return string
226 function IPInfo() {
227 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
228 return "<!-- visited from $ip -->\n" .
229 "<span style='display:none'>visited from $ip</span>";
233 * @param array $list
234 * @return string
236 function listToText( $list ) {
237 $cnt = count( $list );
239 if ( $cnt == 1 ) {
240 // Enforce always returning a string
241 return (string)$this->arrayToString( $list[0] );
242 } elseif ( $cnt == 0 ) {
243 return '';
244 } else {
245 $t = array_slice( $list, 0, $cnt - 1 );
246 $one = array_map( array( &$this, 'arrayToString' ), $t );
247 $two = $this->arrayToString( $list[$cnt - 1] );
249 return implode( ', ', $one ) . " and $two";
254 * @static
256 * @param mixed $list Will convert an array to string if given and return
257 * the paramater unaltered otherwise
258 * @return mixed
260 function arrayToString( $list ) {
261 if ( ! is_array( $list ) ) {
262 return $list;
263 } else {
264 $class = get_class( $list[0] );
265 return "($class, {$list[1]})";
270 * Retrieve the revision number of a Subversion working directory.
272 * @bug 7335
274 * @param string $dir
275 * @return mixed revision number as int, or false if not a SVN checkout
277 public static function getSvnRevision( $dir ) {
278 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
279 $entries = $dir . '/.svn/entries';
281 if( !file_exists( $entries ) ) {
282 return false;
285 $content = file( $entries );
287 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
288 if( preg_match( '/^<\?xml/', $content[0] ) ) {
289 // subversion is release <= 1.3
290 if( !function_exists( 'simplexml_load_file' ) ) {
291 // We could fall back to expat... YUCK
292 return false;
295 // SimpleXml whines about the xmlns...
296 wfSuppressWarnings();
297 $xml = simplexml_load_file( $entries );
298 wfRestoreWarnings();
300 if( $xml ) {
301 foreach( $xml->entry as $entry ) {
302 if( $xml->entry[0]['name'] == '' ) {
303 // The directory entry should always have a revision marker.
304 if( $entry['revision'] ) {
305 return intval( $entry['revision'] );
310 return false;
311 } else {
312 // subversion is release 1.4
313 return intval( $content[3] );
317 /**#@-*/
320 /**#@-*/