cd57dd92ea18c1812a06a11646a6b7284e58e05a
[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 * @static
46 */
47 function MediaWikiCredits() {
48 $version = self::getVersion();
49 $dbr =& wfGetDB( DB_SLAVE );
50
51 global $wgLanguageNames, $wgLanguageCode;
52 $mwlang = $wgLanguageNames[$wgLanguageCode];
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 ($wgLanguageCode $mwlang)
77 * [http://www.php.net/ PHP]: " . phpversion() . " (" . php_sapi_name() . ")
78 * " . $dbr->getSoftwareLink() . ": " . $dbr->getServerVersion();
79
80 return str_replace( "\t\t", '', $ret );
81 }
82
83 public static function getVersion() {
84 global $wgVersion, $IP;
85 $svn = self::getSvnRevision( $IP );
86 return $svn ? "$wgVersion (r$svn)" : $wgVersion;
87 }
88
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 'other' => 'Other',
100 );
101 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
102
103 $out = "\n* Extensions:\n";
104 foreach ( $extensionTypes as $type => $text ) {
105 if ( count( @$wgExtensionCredits[$type] ) ) {
106 $out .= "** $text:\n";
107
108 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
109
110 foreach ( $wgExtensionCredits[$type] as $extension ) {
111 wfSuppressWarnings();
112 $out .= $this->formatCredits(
113 $extension['name'],
114 $extension['version'],
115 $extension['author'],
116 $extension['url'],
117 $extension['description']
118 );
119 wfRestoreWarnings();
120 }
121 }
122 }
123
124 if ( count( $wgExtensionFunctions ) ) {
125 $out .= "** Extension functions:\n";
126 $out .= '***' . $this->listToText( $wgExtensionFunctions ) . "\n";
127 }
128
129 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
130 for ( $i = 0; $i < $cnt; ++$i )
131 $tags[$i] = "&lt;{$tags[$i]}&gt;";
132 $out .= "** Parser extension tags:\n";
133 $out .= '***' . $this->listToText( $tags ). "\n";
134 }
135
136 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
137 $out .= "** Parser function hooks:\n";
138 $out .= '***' . $this->listToText( $fhooks ) . "\n";
139 }
140
141 if ( count( $wgSkinExtensionFunction ) ) {
142 $out .= "** Skin extension functions:\n";
143 $out .= '***' . $this->listToText( $wgSkinExtensionFunction ) . "\n";
144 }
145
146 return $out;
147 }
148
149 function compare( $a, $b ) {
150 if ( $a['name'] === $b['name'] )
151 return 0;
152 else
153 return Language::lc( $a['name'] ) > Language::lc( $b['name'] ) ? 1 : -1;
154 }
155
156 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null) {
157 $ret = '*** ';
158 if ( isset( $url ) )
159 $ret .= "[$url ";
160 $ret .= "''$name";
161 if ( isset( $version ) )
162 $ret .= " (version $version)";
163 $ret .= "''";
164 if ( isset( $url ) )
165 $ret .= ']';
166 if ( isset( $description ) )
167 $ret .= ', ' . $description;
168 if ( isset( $description ) && isset( $author ) )
169 $ret .= ', ';
170 if ( isset( $author ) )
171 $ret .= ' by ' . $this->listToText( (array)$author );
172
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 = "* Hooks:\n";
187 foreach ($myWgHooks as $hook => $hooks)
188 $ret .= "** $hook: " . $this->listToText( $hooks ) . "\n";
189
190 return $ret;
191 } else
192 return '';
193 }
194
195 /**
196 * @static
197 *
198 * @return string
199 */
200 function IPInfo() {
201 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
202 return "<!-- visited from $ip -->\n" .
203 "<span style='display:none'>visited from $ip</span>";
204 }
205
206 /**
207 * @param array $list
208 * @return string
209 */
210 function listToText( $list ) {
211 $cnt = count( $list );
212
213 if ( $cnt == 1 )
214 // Enforce always returning a string
215 return (string)$this->arrayToString( $list[0] );
216 else {
217 $t = array_slice( $list, 0, $cnt - 1 );
218 $one = array_map( array( &$this, 'arrayToString' ), $t );
219 $two = $this->arrayToString( $list[$cnt - 1] );
220
221 return implode( ', ', $one ) . " and $two";
222 }
223 }
224
225 /**
226 * @static
227 *
228 * @param mixed $list Will convert an array to string if given and return
229 * the paramater unaltered otherwise
230 * @return mixed
231 */
232 function arrayToString( $list ) {
233 if ( ! is_array( $list ) )
234 return $list;
235 else {
236 $class = get_class( $list[0] );
237 return "($class, {$list[1]})";
238 }
239 }
240
241 /**
242 * Retrieve the revision number of a Subversion working directory.
243 *
244 * @bug 7335
245 *
246 * @param string $dir
247 * @return mixed revision number as int, or false if not a SVN checkout
248 */
249 public static function getSvnRevision( $dir ) {
250 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
251 $entries = $dir . '/.svn/entries';
252
253 if( !file_exists( $entries ) ) {
254 return false;
255 }
256
257 $content = file( $entries );
258
259 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
260 if( preg_match( '/^<\?xml/', $content[0] ) ) {
261 // subversion is release <= 1.3
262 if( !function_exists( 'simplexml_load_file' ) ) {
263 // We could fall back to expat... YUCK
264 return false;
265 }
266
267 // SimpleXml whines about the xmlns...
268 wfSuppressWarnings();
269 $xml = simplexml_load_file( $entries );
270 wfRestoreWarnings();
271
272 if( $xml ) {
273 foreach( $xml->entry as $entry ) {
274 if( $xml->entry[0]['name'] == '' ) {
275 // The directory entry should always have a revision marker.
276 if( $entry['revision'] ) {
277 return intval( $entry['revision'] );
278 }
279 }
280 }
281 }
282 return false;
283 } else {
284 // subversion is release 1.4
285 return intval( $content[3] );
286 }
287 }
288
289 /**#@-*/
290 }
291
292 /**#@-*/
293 ?>