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