Various Userrights-related fixes:
[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 * @addtogroup SpecialPage
6 *
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
10 */
11
12 /**
13 * constructor
14 */
15 function wfSpecialVersion() {
16 $version = new SpecialVersion;
17 $version->execute();
18 }
19
20 class SpecialVersion {
21 private $firstExtOpened = true;
22
23 /**
24 * main()
25 */
26 function execute() {
27 global $wgOut;
28
29 $wgOut->addHTML( '<div dir="ltr">' );
30 $wgOut->addWikiText(
31 $this->MediaWikiCredits() .
32 $this->extensionCredits() .
33 $this->wgHooks()
34 );
35 $wgOut->addHTML( $this->IPInfo() );
36 $wgOut->addHTML( '</div>' );
37 }
38
39 /**#@+
40 * @private
41 */
42
43 /**
44 * Return wiki text showing the licence information and third party
45 * software versions (apache, php, mysql).
46 * @static
47 */
48 function MediaWikiCredits() {
49 $version = self::getVersion();
50 $dbr = wfGetDB( DB_SLAVE );
51
52 $ret =
53 "__NOTOC__
54 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
55 copyright (C) 2001-2008 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
56 Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
57 Niklas Laxström, Domas Mituzas, Rob Church and others.
58
59 MediaWiki is free software; you can redistribute it and/or modify
60 it under the terms of the GNU General Public License as published by
61 the Free Software Foundation; either version 2 of the License, or
62 (at your option) any later version.
63
64 MediaWiki is distributed in the hope that it will be useful,
65 but WITHOUT ANY WARRANTY; without even the implied warranty of
66 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67 GNU General Public License for more details.
68
69 You should have received [{{SERVER}}{{SCRIPTPATH}}/COPYING a copy of the GNU General Public License]
70 along with this program; if not, write to the Free Software
71 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
72 or [http://www.gnu.org/copyleft/gpl.html read it online]
73
74 * [http://www.mediawiki.org/ MediaWiki]: $version
75 * [http://www.php.net/ PHP]: " . phpversion() . " (" . php_sapi_name() . ")
76 * " . $dbr->getSoftwareLink() . ": " . $dbr->getServerVersion();
77
78 return str_replace( "\t\t", '', $ret ) . "\n";
79 }
80
81 /** Return a string of the MediaWiki version with SVN revision if available */
82 public static function getVersion() {
83 global $wgVersion, $IP;
84 $svn = self::getSvnRevision( $IP );
85 return $svn ? "$wgVersion (r$svn)" : $wgVersion;
86 }
87
88 /** Generate wikitext showing extensions name, URL, author and description */
89 function extensionCredits() {
90 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunction;
91
92 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunction ) )
93 return '';
94
95 $extensionTypes = array(
96 'specialpage' => 'Special pages',
97 'parserhook' => 'Parser hooks',
98 'variable' => 'Variables',
99 'media' => 'Media handlers',
100 'other' => 'Other',
101 );
102 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
103
104 $out = "<h2>Extensions</h2>\n";
105 $out .= wfOpenElement('table', array('id' => 'sv-ext') );
106
107 foreach ( $extensionTypes as $type => $text ) {
108 if ( isset ( $wgExtensionCredits[$type] ) && count ( $wgExtensionCredits[$type] ) ) {
109 $out .= $this->openExtType( $text );
110
111 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
112
113 foreach ( $wgExtensionCredits[$type] as $extension ) {
114 $out .= $this->formatCredits(
115 isset ( $extension['name'] ) ? $extension['name'] : '',
116 isset ( $extension['version'] ) ? $extension['version'] : null,
117 isset ( $extension['author'] ) ? $extension['author'] : '',
118 isset ( $extension['url'] ) ? $extension['url'] : null,
119 isset ( $extension['description'] ) ? $extension['description'] : ''
120 );
121 }
122 }
123 }
124
125 if ( count( $wgExtensionFunctions ) ) {
126 $out .= $this->openExtType('Extension functions');
127 $out .= '<tr><td colspan="3">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
128 }
129
130 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
131 for ( $i = 0; $i < $cnt; ++$i )
132 $tags[$i] = "&lt;{$tags[$i]}&gt;";
133 $out .= $this->openExtType('Parser extension tags');
134 $out .= '<tr><td colspan="3">' . $this->listToText( $tags ). "</td></tr>\n";
135 }
136
137 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
138 $out .= $this->openExtType('Parser function hooks');
139 $out .= '<tr><td colspan="3">' . $this->listToText( $fhooks ) . "</td></tr>\n";
140 }
141
142 if ( count( $wgSkinExtensionFunction ) ) {
143 $out .= $this->openExtType('Skin extension functions');
144 $out .= '<tr><td colspan="3">' . $this->listToText( $wgSkinExtensionFunction ) . "</td></tr>\n";
145 }
146 $out .= wfCloseElement( 'table' );
147 return $out;
148 }
149
150 /** Callback to sort extensions by type */
151 function compare( $a, $b ) {
152 global $wgLang;
153 if( $a['name'] === $b['name'] ) {
154 return 0;
155 } else {
156 return $wgLang->lc( $a['name'] ) > $wgLang->lc( $b['name'] )
157 ? 1
158 : -1;
159 }
160 }
161
162 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null) {
163 $ret = '<tr><td>';
164 if ( isset( $url ) )
165 $ret .= "[$url ";
166 $ret .= "''$name";
167 if ( isset( $version ) )
168 $ret .= " (version $version)";
169 $ret .= "''";
170 if ( isset( $url ) )
171 $ret .= ']';
172 $ret .= '</td>';
173 $ret .= "<td>$description</td>";
174 $ret .= "<td>" . $this->listToText( (array)$author ) . "</td>";
175 $ret .= '</tr>';
176 return "$ret\n";
177 }
178
179 /**
180 * @return string
181 */
182 function wgHooks() {
183 global $wgHooks;
184
185 if ( count( $wgHooks ) ) {
186 $myWgHooks = $wgHooks;
187 ksort( $myWgHooks );
188
189 $ret = "<h2>Hooks</h2>\n"
190 . wfOpenElement('table', array('id' => 'sv-hooks') )
191 . "<tr><th>Hook name</th><th>Subscribed by</th></tr>\n";
192
193 foreach ($myWgHooks as $hook => $hooks)
194 $ret .= "<tr><td>$hook</td><td>" . $this->listToText( $hooks ) . "</td></tr>\n";
195
196 $ret .= '</table>';
197 return $ret;
198 } else
199 return '';
200 }
201
202 private function openExtType($text, $name = null) {
203 $opt = array( 'colspan' => 3 );
204 $out = '';
205
206 if(!$this->firstExtOpened) {
207 // Insert a spacing line
208 $out .= '<tr class="sv-space">' . wfElement( 'td', $opt ) . "</tr>\n";
209 }
210 $this->firstExtOpened = false;
211
212 if($name) { $opt['id'] = "sv-$name"; }
213
214 $out .= "<tr>" . wfElement( 'th', $opt, $text) . "</tr>\n";
215 return $out;
216 }
217
218 /**
219 * @static
220 *
221 * @return string
222 */
223 function IPInfo() {
224 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
225 return "<!-- visited from $ip -->\n" .
226 "<span style='display:none'>visited from $ip</span>";
227 }
228
229 /**
230 * @param array $list
231 * @return string
232 */
233 function listToText( $list ) {
234 $cnt = count( $list );
235
236 if ( $cnt == 1 ) {
237 // Enforce always returning a string
238 return (string)$this->arrayToString( $list[0] );
239 } elseif ( $cnt == 0 ) {
240 return '';
241 } else {
242 $t = array_slice( $list, 0, $cnt - 1 );
243 $one = array_map( array( &$this, 'arrayToString' ), $t );
244 $two = $this->arrayToString( $list[$cnt - 1] );
245
246 return implode( ', ', $one ) . " and $two";
247 }
248 }
249
250 /**
251 * @static
252 *
253 * @param mixed $list Will convert an array to string if given and return
254 * the paramater unaltered otherwise
255 * @return mixed
256 */
257 function arrayToString( $list ) {
258 if( is_object( $list ) ) {
259 $class = get_class( $list );
260 return "($class)";
261 } elseif ( ! is_array( $list ) ) {
262 return $list;
263 } else {
264 $class = get_class( $list[0] );
265 return "($class, {$list[1]})";
266 }
267 }
268
269 /**
270 * Retrieve the revision number of a Subversion working directory.
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 // SimpleXml whines about the xmlns...
294 wfSuppressWarnings();
295 $xml = simplexml_load_file( $entries );
296 wfRestoreWarnings();
297
298 if( $xml ) {
299 foreach( $xml->entry as $entry ) {
300 if( $xml->entry[0]['name'] == '' ) {
301 // The directory entry should always have a revision marker.
302 if( $entry['revision'] ) {
303 return intval( $entry['revision'] );
304 }
305 }
306 }
307 }
308 return false;
309 } else {
310 // subversion is release 1.4
311 return intval( $content[3] );
312 }
313 }
314
315 /**#@-*/
316 }
317
318 /**#@-*/
319