Add RELEASE-NOTES for 33269, fix another one.
[mediawiki.git] / includes / SpecialVersion.php
blobbe10f500c89b466278e4b48ab9e240359a3c1d86
1 <?php
2 /**#@+
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
12 /**
13 * constructor
15 function wfSpecialVersion() {
16 $version = new SpecialVersion;
17 $version->execute();
20 class SpecialVersion {
21 private $firstExtOpened = true;
23 /**
24 * main()
26 function execute() {
27 global $wgOut, $wgMessageCache;
28 $wgMessageCache->loadAllMessages();
30 $wgOut->addHTML( '<div dir="ltr">' );
31 $wgOut->addWikiText(
32 $this->MediaWikiCredits() .
33 $this->softwareInformation() .
34 $this->extensionCredits() .
35 $this->wgHooks()
37 $wgOut->addHTML( $this->IPInfo() );
38 $wgOut->addHTML( '</div>' );
41 /**#@+
42 * @private
45 /**
46 * @return wiki text showing the license information
48 static function MediaWikiCredits() {
49 $ret = Xml::element( 'h2', array( 'id' => 'mw-version-license' ), wfMsg( 'version-license' ) ) .
50 "__NOTOC__
51 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
52 copyright (C) 2001-2008 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
53 Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
54 Niklas Laxström, Domas Mituzas, Rob Church, Yuri Astrakhan and others.
56 MediaWiki is free software; you can redistribute it and/or modify
57 it under the terms of the GNU General Public License as published by
58 the Free Software Foundation; either version 2 of the License, or
59 (at your option) any later version.
61 MediaWiki is distributed in the hope that it will be useful,
62 but WITHOUT ANY WARRANTY; without even the implied warranty of
63 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64 GNU General Public License for more details.
66 You should have received [{{SERVER}}{{SCRIPTPATH}}/COPYING a copy of the GNU General Public License]
67 along with this program; if not, write to the Free Software
68 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
69 or [http://www.gnu.org/copyleft/gpl.html read it online].
72 return str_replace( "\t\t", '', $ret ) . "\n";
75 /**
76 * @return wiki text showing the third party software versions (apache, php, mysql).
78 static function softwareInformation() {
79 $dbr = wfGetDB( DB_SLAVE );
81 return Xml::element( 'h2', array( 'id' => 'mw-version-software' ), wfMsg( 'version-software' ) ) .
82 Xml::openElement( 'table', array( 'id' => 'sv-software' ) ) .
83 "<tr>
84 <th>" . wfMsg( 'version-software-product' ) . "</th>
85 <th>" . wfMsg( 'version-software-version' ) . "</th>
86 </tr>\n
87 <tr>
88 <td>[http://www.mediawiki.org/ MediaWiki]</td>
89 <td>" . self::getVersion() . "</td>
90 </tr>\n
91 <tr>
92 <td>[http://www.php.net/ PHP]</td>
93 <td>" . phpversion() . " (" . php_sapi_name() . ")</td>
94 </tr>\n
95 <tr>
96 <td>" . $dbr->getSoftwareLink() . "</td>
97 <td>" . $dbr->getServerVersion() . "</td>
98 </tr>\n" .
99 Xml::closeElement( 'table' );
102 /** Return a string of the MediaWiki version with SVN revision if available */
103 public static function getVersion() {
104 global $wgVersion, $IP;
105 wfProfileIn( __METHOD__ );
106 $svn = self::getSvnRevision( $IP );
107 $version = $svn ? "$wgVersion (r$svn)" : $wgVersion;
108 wfProfileOut( __METHOD__ );
109 return $version;
112 /** Generate wikitext showing extensions name, URL, author and description */
113 function extensionCredits() {
114 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunctions;
116 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunctions ) )
117 return '';
119 $extensionTypes = array(
120 'specialpage' => wfMsg( 'version-specialpages' ),
121 'parserhook' => wfMsg( 'version-parserhooks' ),
122 'variable' => wfMsg( 'version-variables' ),
123 'media' => wfMsg( 'version-mediahandlers' ),
124 'other' => wfMsg( 'version-other' ),
126 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
128 $out = Xml::element( 'h2', array( 'id' => 'mw-version-ext' ), wfMsg( 'version-extensions' ) ) .
129 Xml::openElement( 'table', array( 'id' => 'sv-ext' ) );
131 foreach ( $extensionTypes as $type => $text ) {
132 if ( isset ( $wgExtensionCredits[$type] ) && count ( $wgExtensionCredits[$type] ) ) {
133 $out .= $this->openExtType( $text );
135 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
137 foreach ( $wgExtensionCredits[$type] as $extension ) {
138 $out .= $this->formatCredits(
139 isset ( $extension['name'] ) ? $extension['name'] : '',
140 isset ( $extension['version'] ) ? $extension['version'] : null,
141 isset ( $extension['author'] ) ? $extension['author'] : '',
142 isset ( $extension['url'] ) ? $extension['url'] : null,
143 isset ( $extension['description'] ) ? $extension['description'] : '',
144 isset ( $extension['descriptionmsg'] ) ? $extension['descriptionmsg'] : ''
150 if ( count( $wgExtensionFunctions ) ) {
151 $out .= $this->openExtType( wfMsg( 'version-extension-functions' ) );
152 $out .= '<tr><td colspan="3">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
155 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
156 for ( $i = 0; $i < $cnt; ++$i )
157 $tags[$i] = "&lt;{$tags[$i]}&gt;";
158 $out .= $this->openExtType( wfMsg( 'version-parser-extensiontags' ) );
159 $out .= '<tr><td colspan="3">' . $this->listToText( $tags ). "</td></tr>\n";
162 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
163 $out .= $this->openExtType( wfMsg( 'version-parser-function-hooks' ) );
164 $out .= '<tr><td colspan="3">' . $this->listToText( $fhooks ) . "</td></tr>\n";
167 if ( count( $wgSkinExtensionFunctions ) ) {
168 $out .= $this->openExtType( wfMsg( 'version-skin-extension-functions' ) );
169 $out .= '<tr><td colspan="3">' . $this->listToText( $wgSkinExtensionFunctions ) . "</td></tr>\n";
171 $out .= Xml::closeElement( 'table' );
172 return $out;
175 /** Callback to sort extensions by type */
176 function compare( $a, $b ) {
177 global $wgLang;
178 if( $a['name'] === $b['name'] ) {
179 return 0;
180 } else {
181 return $wgLang->lc( $a['name'] ) > $wgLang->lc( $b['name'] )
183 : -1;
187 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null, $descriptionMsg = null ) {
188 $extension = isset( $url ) ? "[$url $name]" : $name;
189 $version = isset( $version ) ? "(" . wfMsg( 'version-version' ) . " $version)" : '';
191 # Look for a localized description
192 if( isset( $descriptionMsg ) ) {
193 $msg = wfMsg( $descriptionMsg );
194 if ( !wfEmptyMsg( $descriptionMsg, $msg ) && $msg != '' ) {
195 $description = $msg;
199 return "<tr>
200 <td><em>$extension $version</em></td>
201 <td>$description</td>
202 <td>" . $this->listToText( (array)$author ) . "</td>
203 </tr>\n";
207 * @return string
209 function wgHooks() {
210 global $wgHooks;
212 if ( count( $wgHooks ) ) {
213 $myWgHooks = $wgHooks;
214 ksort( $myWgHooks );
216 $ret = Xml::element( 'h2', array( 'id' => 'mw-version-hooks' ), wfMsg( 'version-hooks' ) ) .
217 Xml::openElement( 'table', array( 'id' => 'sv-hooks' ) ) .
218 "<tr>
219 <th>" . wfMsg( 'version-hook-name' ) . "</th>
220 <th>" . wfMsg( 'version-hook-subscribedby' ) . "</th>
221 </tr>\n";
223 foreach ( $myWgHooks as $hook => $hooks )
224 $ret .= "<tr>
225 <td>$hook</td>
226 <td>" . $this->listToText( $hooks ) . "</td>
227 </tr>\n";
229 $ret .= Xml::closeElement( 'table' );
230 return $ret;
231 } else
232 return '';
235 private function openExtType($text, $name = null) {
236 $opt = array( 'colspan' => 3 );
237 $out = '';
239 if(!$this->firstExtOpened) {
240 // Insert a spacing line
241 $out .= '<tr class="sv-space">' . Xml::element( 'td', $opt ) . "</tr>\n";
243 $this->firstExtOpened = false;
245 if($name) { $opt['id'] = "sv-$name"; }
247 $out .= "<tr>" . Xml::element( 'th', $opt, $text) . "</tr>\n";
248 return $out;
252 * @static
254 * @return string
256 function IPInfo() {
257 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
258 return "<!-- visited from $ip -->\n" .
259 "<span style='display:none'>visited from $ip</span>";
263 * @param array $list
264 * @return string
266 function listToText( $list ) {
267 $cnt = count( $list );
269 if ( $cnt == 1 ) {
270 // Enforce always returning a string
271 return (string)$this->arrayToString( $list[0] );
272 } elseif ( $cnt == 0 ) {
273 return '';
274 } else {
275 sort( $list );
276 $t = array_slice( $list, 0, $cnt - 1 );
277 $one = array_map( array( &$this, 'arrayToString' ), $t );
278 $two = $this->arrayToString( $list[$cnt - 1] );
279 $and = wfMsg( 'and' );
281 return implode( ', ', $one ) . " $and $two";
286 * @static
288 * @param mixed $list Will convert an array to string if given and return
289 * the paramater unaltered otherwise
290 * @return mixed
292 function arrayToString( $list ) {
293 if( is_object( $list ) ) {
294 $class = get_class( $list );
295 return "($class)";
296 } elseif ( ! is_array( $list ) ) {
297 return $list;
298 } else {
299 $class = get_class( $list[0] );
300 return "($class, {$list[1]})";
305 * Retrieve the revision number of a Subversion working directory.
307 * @param string $dir
308 * @return mixed revision number as int, or false if not a SVN checkout
310 public static function getSvnRevision( $dir ) {
311 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
312 $entries = $dir . '/.svn/entries';
314 if( !file_exists( $entries ) ) {
315 return false;
318 $content = file( $entries );
320 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
321 if( preg_match( '/^<\?xml/', $content[0] ) ) {
322 // subversion is release <= 1.3
323 if( !function_exists( 'simplexml_load_file' ) ) {
324 // We could fall back to expat... YUCK
325 return false;
328 // SimpleXml whines about the xmlns...
329 wfSuppressWarnings();
330 $xml = simplexml_load_file( $entries );
331 wfRestoreWarnings();
333 if( $xml ) {
334 foreach( $xml->entry as $entry ) {
335 if( $xml->entry[0]['name'] == '' ) {
336 // The directory entry should always have a revision marker.
337 if( $entry['revision'] ) {
338 return intval( $entry['revision'] );
343 return false;
344 } else {
345 // subversion is release 1.4
346 return intval( $content[3] );
350 /**#@-*/
353 /**#@-*/