Revert previous commit, breaks cache.
[lhc/web/wiklou.git] / includes / specials / SpecialVersion.php
1 <?php
2 /**#@+
3 * Give information about the version of MediaWiki, PHP, the DB and extensions
4 *
5 * @file
6 * @ingroup SpecialPage
7 *
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
11 */
12
13 /**
14 * constructor
15 */
16 function wfSpecialVersion() {
17 $version = new SpecialVersion;
18 $version->execute();
19 }
20
21 /**
22 * @ingroup SpecialPage
23 */
24 class SpecialVersion {
25 private $firstExtOpened = true;
26
27 /**
28 * main()
29 */
30 function execute() {
31 global $wgOut, $wgMessageCache, $wgSpecialVersionShowHooks;
32 $wgMessageCache->loadAllMessages();
33
34 $wgOut->addHTML( '<div dir="ltr">' );
35 $text =
36 $this->MediaWikiCredits() .
37 $this->softwareInformation() .
38 $this->extensionCredits();
39 if ( $wgSpecialVersionShowHooks ) {
40 $text .= $this->wgHooks();
41 }
42 $wgOut->addWikiText( $text );
43 $wgOut->addHTML( $this->IPInfo() );
44 $wgOut->addHTML( '</div>' );
45 }
46
47 /**#@+
48 * @private
49 */
50
51 /**
52 * @return wiki text showing the license information
53 */
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.
62
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.
67
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.
72
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].
77 ";
78
79 return str_replace( "\t\t", '', $ret ) . "\n";
80 }
81
82 /**
83 * @return wiki text showing the third party software versions (apache, php, mysql).
84 */
85 static function softwareInformation() {
86 $dbr = wfGetDB( DB_SLAVE );
87
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' );
107 }
108
109 /**
110 * Return a string of the MediaWiki version with SVN revision if available
111 *
112 * @return mixed
113 */
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;
121 }
122
123 /**
124 * Return a string of the MediaWiki version with a link to SVN revision if
125 * available
126 *
127 * @return mixed
128 */
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;
137 }
138
139 /** Generate wikitext showing extensions name, URL, author and description */
140 function extensionCredits() {
141 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunctions;
142
143 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunctions ) )
144 return '';
145
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' ),
152 );
153 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
154
155 $out = Xml::element( 'h2', array( 'id' => 'mw-version-ext' ), wfMsg( 'version-extensions' ) ) .
156 Xml::openElement( 'table', array( 'id' => 'sv-ext' ) );
157
158 foreach ( $extensionTypes as $type => $text ) {
159 if ( isset ( $wgExtensionCredits[$type] ) && count ( $wgExtensionCredits[$type] ) ) {
160 $out .= $this->openExtType( $text );
161
162 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
163
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 ) )
170 {
171 $version = 'r' . $m[1];
172 } else {
173 $version = null;
174 }
175
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'] : ''
183 );
184 }
185 }
186 }
187
188 if ( count( $wgExtensionFunctions ) ) {
189 $out .= $this->openExtType( wfMsg( 'version-extension-functions' ) );
190 $out .= '<tr><td colspan="3">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
191 }
192
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";
198 }
199
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";
203 }
204
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";
208 }
209 $out .= Xml::closeElement( 'table' );
210 return $out;
211 }
212
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'] )
220 ? 1
221 : -1;
222 }
223 }
224
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)" : '';
228
229 # Look for a localized description
230 if( isset( $descriptionMsg ) ) {
231 $msg = wfMsg( $descriptionMsg );
232 if ( !wfEmptyMsg( $descriptionMsg, $msg ) && $msg != '' ) {
233 $description = $msg;
234 }
235 }
236
237 return "<tr>
238 <td><em>$extension $version</em></td>
239 <td>$description</td>
240 <td>" . $this->listToText( (array)$author ) . "</td>
241 </tr>\n";
242 }
243
244 /**
245 * @return string
246 */
247 function wgHooks() {
248 global $wgHooks;
249
250 if ( count( $wgHooks ) ) {
251 $myWgHooks = $wgHooks;
252 ksort( $myWgHooks );
253
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";
260
261 foreach ( $myWgHooks as $hook => $hooks )
262 $ret .= "<tr>
263 <td>$hook</td>
264 <td>" . $this->listToText( $hooks ) . "</td>
265 </tr>\n";
266
267 $ret .= Xml::closeElement( 'table' );
268 return $ret;
269 } else
270 return '';
271 }
272
273 private function openExtType($text, $name = null) {
274 $opt = array( 'colspan' => 3 );
275 $out = '';
276
277 if(!$this->firstExtOpened) {
278 // Insert a spacing line
279 $out .= '<tr class="sv-space">' . Xml::element( 'td', $opt ) . "</tr>\n";
280 }
281 $this->firstExtOpened = false;
282
283 if($name) { $opt['id'] = "sv-$name"; }
284
285 $out .= "<tr>" . Xml::element( 'th', $opt, $text) . "</tr>\n";
286 return $out;
287 }
288
289 /**
290 * @static
291 *
292 * @return string
293 */
294 function IPInfo() {
295 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
296 return "<!-- visited from $ip -->\n" .
297 "<span style='display:none'>visited from $ip</span>";
298 }
299
300 /**
301 * @param array $list
302 * @return string
303 */
304 function listToText( $list ) {
305 $cnt = count( $list );
306
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' );
318
319 return implode( ', ', $one ) . " $and $two";
320 }
321 }
322
323 /**
324 * @static
325 *
326 * @param mixed $list Will convert an array to string if given and return
327 * the paramater unaltered otherwise
328 * @return mixed
329 */
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]})";
339 }
340 }
341
342 /**
343 * Retrieve the revision number of a Subversion working directory.
344 *
345 * @param string $dir
346 * @return mixed revision number as int, or false if not a SVN checkout
347 */
348 public static function getSvnRevision( $dir ) {
349 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
350 $entries = $dir . '/.svn/entries';
351
352 if( !file_exists( $entries ) ) {
353 return false;
354 }
355
356 $content = file( $entries );
357
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;
364 }
365
366 // SimpleXml whines about the xmlns...
367 wfSuppressWarnings();
368 $xml = simplexml_load_file( $entries );
369 wfRestoreWarnings();
370
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'] );
377 }
378 }
379 }
380 }
381 return false;
382 } else {
383 // subversion is release 1.4
384 return intval( $content[3] );
385 }
386 }
387
388 /**#@-*/
389 }
390
391 /**#@-*/