Tweaks to stop following warnings with PHP's E_STRICT error_reporting mode enabled:
[lhc/web/wiklou.git] / includes / SpecialVersion.php
1 <?php
2 /**#@+
3 * Give information about the version of MediaWiki, PHP, the DB and extensions
4 *
5 * @package MediaWiki
6 * @subpackage SpecialPage
7 *
8 * @bug 2019, 4531
9 *
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
13 */
14
15 /**
16 * constructor
17 */
18 function wfSpecialVersion() {
19 $version = new SpecialVersion;
20 $version->execute();
21 }
22
23 class SpecialVersion {
24 private $firstExtOpened = true;
25
26 /**
27 * main()
28 */
29 function execute() {
30 global $wgOut;
31
32 $wgOut->addHTML( '<div dir="ltr">' );
33 $wgOut->addWikiText(
34 $this->MediaWikiCredits() .
35 $this->extensionCredits() .
36 $this->wgHooks()
37 );
38 $wgOut->addHTML( $this->IPInfo() );
39 $wgOut->addHTML( '</div>' );
40 }
41
42 /**#@+
43 * @private
44 */
45
46 /**
47 * Return wiki text showing the licence information and third party
48 * software versions (apache, php, mysql).
49 * @static
50 */
51 function MediaWikiCredits() {
52 $version = self::getVersion();
53 $dbr =& wfGetDB( DB_SLAVE );
54
55 global $wgLanguageNames, $wgLanguageCode;
56 $mwlang = $wgLanguageNames[$wgLanguageCode];
57
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.
64
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.
69
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.
74
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]
79
80 * [http://www.mediawiki.org/ MediaWiki]: $version
81 * [http://www.php.net/ PHP]: " . phpversion() . " (" . php_sapi_name() . ")
82 * " . $dbr->getSoftwareLink() . ": " . $dbr->getServerVersion();
83
84 return str_replace( "\t\t", '', $ret ) . "\n";
85 }
86
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;
92 }
93
94 /** Generate wikitext showing extensions name, URL, author and description */
95 function extensionCredits() {
96 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunction;
97
98 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunction ) )
99 return '';
100
101 $extensionTypes = array(
102 'specialpage' => 'Special pages',
103 'parserhook' => 'Parser hooks',
104 'variable' => 'Variables',
105 'other' => 'Other',
106 );
107 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
108
109 $out = "<h2>Extensions</h2>\n";
110 $out .= wfOpenElement('table', array('id' => 'sv-ext') );
111
112 foreach ( $extensionTypes as $type => $text ) {
113 if ( isset ( $wgExtensionCredits[$type] ) && count ( $wgExtensionCredits[$type] ) ) {
114 $out .= $this->openExtType( $text );
115
116 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
117
118 foreach ( $wgExtensionCredits[$type] as $extension ) {
119 $out .= $this->formatCredits(
120 isset ( $extension['name'] ) ? $extension['name'] : '',
121 isset ( $extension['version'] ) ? $extension['version'] : '',
122 isset ( $extension['author'] ) ? $extension['author'] : '',
123 isset ( $extension['url'] ) ? $extension['url'] : '',
124 isset ( $extension['description'] ) ? $extension['description'] : ''
125 );
126 }
127 }
128 }
129
130 if ( count( $wgExtensionFunctions ) ) {
131 $out .= $this->openExtType('Extension functions');
132 $out .= '<tr><td colspan="3">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
133 }
134
135 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
136 for ( $i = 0; $i < $cnt; ++$i )
137 $tags[$i] = "&lt;{$tags[$i]}&gt;";
138 $out .= $this->openExtType('Parser extension tags');
139 $out .= '<tr><td colspan="3">' . $this->listToText( $tags ). "</td></tr>\n";
140 }
141
142 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
143 $out .= $this->openExtType('Parser function hooks');
144 $out .= '<tr><td colspan="3">' . $this->listToText( $fhooks ) . "</td></tr>\n";
145 }
146
147 if ( count( $wgSkinExtensionFunction ) ) {
148 $out .= $this->openExtType('Skin extension functions');
149 $out .= '<tr><td colspan="3">' . $this->listToText( $wgSkinExtensionFunction ) . "</td></tr>\n";
150 }
151 $out .= wfCloseElement( 'table' );
152 return $out;
153 }
154
155 /** Callback to sort extensions by type */
156 function compare( $a, $b ) {
157 if ( $a['name'] === $b['name'] )
158 return 0;
159 else
160 return Language::lc( $a['name'] ) > Language::lc( $b['name'] ) ? 1 : -1;
161 }
162
163 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null) {
164 $ret = '<tr><td>';
165 if ( isset( $url ) )
166 $ret .= "[$url ";
167 $ret .= "''$name";
168 if ( isset( $version ) )
169 $ret .= " (version $version)";
170 $ret .= "''";
171 if ( isset( $url ) )
172 $ret .= ']';
173 $ret .= '</td>';
174 $ret .= "<td>$description</td>";
175 $ret .= "<td>" . $this->listToText( (array)$author ) . "</td>";
176 $ret .= '</tr>';
177 return "$ret\n";
178 }
179
180 /**
181 * @return string
182 */
183 function wgHooks() {
184 global $wgHooks;
185
186 if ( count( $wgHooks ) ) {
187 $myWgHooks = $wgHooks;
188 ksort( $myWgHooks );
189
190 $ret = "<h2>Hooks</h2>\n"
191 . wfOpenElement('table', array('id' => 'sv-hooks') )
192 . "<tr><th>Hook name</th><th>Subscribed by</th></tr>\n";
193
194 foreach ($myWgHooks as $hook => $hooks)
195 $ret .= "<tr><td>$hook</td><td>" . $this->listToText( $hooks ) . "</td></tr>\n";
196
197 $ret .= '</table>';
198 return $ret;
199 } else
200 return '';
201 }
202
203 private function openExtType($text, $name = null) {
204 $opt = array( 'colspan' => 3 );
205 $out = '';
206
207 if(!$this->firstExtOpened) {
208 // Insert a spacing line
209 $out .= '<tr class="sv-space">' . wfElement( 'td', $opt ) . "</tr>\n";
210 }
211 $this->firstExtOpened = false;
212
213 if($name) { $opt['id'] = "sv-$name"; }
214
215 $out .= "<tr>" . wfElement( 'th', $opt, $text) . "</tr>\n";
216 return $out;
217 }
218
219 /**
220 * @static
221 *
222 * @return string
223 */
224 function IPInfo() {
225 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
226 return "<!-- visited from $ip -->\n" .
227 "<span style='display:none'>visited from $ip</span>";
228 }
229
230 /**
231 * @param array $list
232 * @return string
233 */
234 function listToText( $list ) {
235 $cnt = count( $list );
236
237 if ( $cnt == 1 ) {
238 // Enforce always returning a string
239 return (string)$this->arrayToString( $list[0] );
240 } elseif ( $cnt == 0 ) {
241 return '';
242 } else {
243 $t = array_slice( $list, 0, $cnt - 1 );
244 $one = array_map( array( &$this, 'arrayToString' ), $t );
245 $two = $this->arrayToString( $list[$cnt - 1] );
246
247 return implode( ', ', $one ) . " and $two";
248 }
249 }
250
251 /**
252 * @static
253 *
254 * @param mixed $list Will convert an array to string if given and return
255 * the paramater unaltered otherwise
256 * @return mixed
257 */
258 function arrayToString( $list ) {
259 if ( ! is_array( $list ) ) {
260 return $list;
261 } else {
262 $class = get_class( $list[0] );
263 return "($class, {$list[1]})";
264 }
265 }
266
267 /**
268 * Retrieve the revision number of a Subversion working directory.
269 *
270 * @bug 7335
271 *
272 * @param string $dir
273 * @return mixed revision number as int, or false if not a SVN checkout
274 */
275 public static function getSvnRevision( $dir ) {
276 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
277 $entries = $dir . '/.svn/entries';
278
279 if( !file_exists( $entries ) ) {
280 return false;
281 }
282
283 $content = file( $entries );
284
285 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
286 if( preg_match( '/^<\?xml/', $content[0] ) ) {
287 // subversion is release <= 1.3
288 if( !function_exists( 'simplexml_load_file' ) ) {
289 // We could fall back to expat... YUCK
290 return false;
291 }
292
293 $xml = simplexml_load_file( $entries, "SimpleXMLElement", LIBXML_NOWARNING );
294
295 if( $xml ) {
296 foreach( $xml->entry as $entry ) {
297 if( $xml->entry[0]['name'] == '' ) {
298 // The directory entry should always have a revision marker.
299 if( $entry['revision'] ) {
300 return intval( $entry['revision'] );
301 }
302 }
303 }
304 }
305 return false;
306 } else {
307 // subversion is release 1.4
308 return intval( $content[3] );
309 }
310 }
311
312 /**#@-*/
313 }
314
315 /**#@-*/
316 ?>