- whitespaces
[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 /**
25 * main()
26 */
27 function execute() {
28 global $wgOut;
29
30 $wgOut->addHTML( '<div dir="ltr">' );
31 $wgOut->addWikiText(
32 $this->MediaWikiCredits() .
33 $this->extensionCredits() .
34 $this->wgHooks()
35 );
36 $wgOut->addHTML( $this->IPInfo() );
37 $wgOut->addHTML( '</div>' );
38 }
39
40 /**#@+
41 * @private
42 */
43
44 /**
45 * Return wiki text showing the licence information and third party
46 * software versions (apache, php, mysql).
47 * @static
48 */
49 function MediaWikiCredits() {
50 $version = self::getVersion();
51 $dbr =& wfGetDB( DB_SLAVE );
52
53 global $wgLanguageNames, $wgLanguageCode;
54 $mwlang = $wgLanguageNames[$wgLanguageCode];
55
56 $ret =
57 "__NOTOC__
58 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
59 copyright (C) 2001-2007 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
60 Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
61 Niklas Laxström, Domas Mituzas, Rob Church 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/copyleft/gpl.html read it online]
77
78 * [http://www.mediawiki.org/ MediaWiki]: $version ($wgLanguageCode $mwlang)
79 * [http://www.php.net/ PHP]: " . phpversion() . " (" . php_sapi_name() . ")
80 * " . $dbr->getSoftwareLink() . ": " . $dbr->getServerVersion();
81
82 return str_replace( "\t\t", '', $ret );
83 }
84
85 /** Return a string of the MediaWiki version with SVN revision if available */
86 public static function getVersion() {
87 global $wgVersion, $IP;
88 $svn = self::getSvnRevision( $IP );
89 return $svn ? "$wgVersion (r$svn)" : $wgVersion;
90 }
91
92 /** Generate wikitext showing extensions name, URL, author and description */
93 function extensionCredits() {
94 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunction;
95
96 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunction ) )
97 return '';
98
99 $extensionTypes = array(
100 'specialpage' => 'Special pages',
101 'parserhook' => 'Parser hooks',
102 'variable' => 'Variables',
103 'other' => 'Other',
104 );
105 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
106
107 $out = "\n* Extensions:\n";
108 foreach ( $extensionTypes as $type => $text ) {
109 if ( count( @$wgExtensionCredits[$type] ) ) {
110 $out .= "** $text:\n";
111
112 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
113
114 foreach ( $wgExtensionCredits[$type] as $extension ) {
115 wfSuppressWarnings();
116 $out .= $this->formatCredits(
117 $extension['name'],
118 $extension['version'],
119 $extension['author'],
120 $extension['url'],
121 $extension['description']
122 );
123 wfRestoreWarnings();
124 }
125 }
126 }
127
128 if ( count( $wgExtensionFunctions ) ) {
129 $out .= "** Extension functions:\n";
130 $out .= '***' . $this->listToText( $wgExtensionFunctions ) . "\n";
131 }
132
133 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
134 for ( $i = 0; $i < $cnt; ++$i )
135 $tags[$i] = "&lt;{$tags[$i]}&gt;";
136 $out .= "** Parser extension tags:\n";
137 $out .= '***' . $this->listToText( $tags ). "\n";
138 }
139
140 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
141 $out .= "** Parser function hooks:\n";
142 $out .= '***' . $this->listToText( $fhooks ) . "\n";
143 }
144
145 if ( count( $wgSkinExtensionFunction ) ) {
146 $out .= "** Skin extension functions:\n";
147 $out .= '***' . $this->listToText( $wgSkinExtensionFunction ) . "\n";
148 }
149
150 return $out;
151 }
152
153 /** Callback to sort extensions by type */
154 function compare( $a, $b ) {
155 if ( $a['name'] === $b['name'] )
156 return 0;
157 else
158 return Language::lc( $a['name'] ) > Language::lc( $b['name'] ) ? 1 : -1;
159 }
160
161 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null) {
162 $ret = '*** ';
163 if ( isset( $url ) )
164 $ret .= "[$url ";
165 $ret .= "''$name";
166 if ( isset( $version ) )
167 $ret .= " (version $version)";
168 $ret .= "''";
169 if ( isset( $url ) )
170 $ret .= ']';
171 if ( isset( $description ) )
172 $ret .= ', ' . $description;
173 if ( isset( $description ) && isset( $author ) )
174 $ret .= ', ';
175 if ( isset( $author ) )
176 $ret .= ' by ' . $this->listToText( (array)$author );
177
178 return "$ret\n";
179 }
180
181 /**
182 * @return string
183 */
184 function wgHooks() {
185 global $wgHooks;
186
187 if ( count( $wgHooks ) ) {
188 $myWgHooks = $wgHooks;
189 ksort( $myWgHooks );
190
191 $ret = "* Hooks:\n";
192 foreach ($myWgHooks as $hook => $hooks)
193 $ret .= "** $hook: " . $this->listToText( $hooks ) . "\n";
194
195 return $ret;
196 } else
197 return '';
198 }
199
200 /**
201 * @static
202 *
203 * @return string
204 */
205 function IPInfo() {
206 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
207 return "<!-- visited from $ip -->\n" .
208 "<span style='display:none'>visited from $ip</span>";
209 }
210
211 /**
212 * @param array $list
213 * @return string
214 */
215 function listToText( $list ) {
216 $cnt = count( $list );
217
218 if ( $cnt == 1 )
219 // Enforce always returning a string
220 return (string)$this->arrayToString( $list[0] );
221 else {
222 $t = array_slice( $list, 0, $cnt - 1 );
223 $one = array_map( array( &$this, 'arrayToString' ), $t );
224 $two = $this->arrayToString( $list[$cnt - 1] );
225
226 return implode( ', ', $one ) . " and $two";
227 }
228 }
229
230 /**
231 * @static
232 *
233 * @param mixed $list Will convert an array to string if given and return
234 * the paramater unaltered otherwise
235 * @return mixed
236 */
237 function arrayToString( $list ) {
238 if ( ! is_array( $list ) )
239 return $list;
240 else {
241 $class = get_class( $list[0] );
242 return "($class, {$list[1]})";
243 }
244 }
245
246 /**
247 * Retrieve the revision number of a Subversion working directory.
248 *
249 * @bug 7335
250 *
251 * @param string $dir
252 * @return mixed revision number as int, or false if not a SVN checkout
253 */
254 public static function getSvnRevision( $dir ) {
255 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
256 $entries = $dir . '/.svn/entries';
257
258 if( !file_exists( $entries ) ) {
259 return false;
260 }
261
262 $content = file( $entries );
263
264 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
265 if( preg_match( '/^<\?xml/', $content[0] ) ) {
266 // subversion is release <= 1.3
267 if( !function_exists( 'simplexml_load_file' ) ) {
268 // We could fall back to expat... YUCK
269 return false;
270 }
271
272 // SimpleXml whines about the xmlns...
273 wfSuppressWarnings();
274 $xml = simplexml_load_file( $entries );
275 wfRestoreWarnings();
276
277 if( $xml ) {
278 foreach( $xml->entry as $entry ) {
279 if( $xml->entry[0]['name'] == '' ) {
280 // The directory entry should always have a revision marker.
281 if( $entry['revision'] ) {
282 return intval( $entry['revision'] );
283 }
284 }
285 }
286 }
287 return false;
288 } else {
289 // subversion is release 1.4
290 return intval( $content[3] );
291 }
292 }
293
294 /**#@-*/
295 }
296
297 /**#@-*/
298 ?>