begin cleanup on magnus' url upload thingy
[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 = $this->getVersion();
49 $dbr =& wfGetDB( DB_SLAVE );
50
51 $ret =
52 "__NOTOC__
53 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
54 copyright (C) 2001-2006 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
55 Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
56 Niklas Laxström, Domas Mituzas, Rob Church and others.
57
58 MediaWiki is free software; you can redistribute it and/or modify
59 it under the terms of the GNU General Public License as published by
60 the Free Software Foundation; either version 2 of the License, or
61 (at your option) any later version.
62
63 MediaWiki is distributed in the hope that it will be useful,
64 but WITHOUT ANY WARRANTY; without even the implied warranty of
65 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66 GNU General Public License for more details.
67
68 You should have received [{{SERVER}}{{SCRIPTPATH}}/COPYING a copy of the GNU General Public License]
69 along with this program; if not, write to the Free Software
70 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
71 or [http://www.gnu.org/copyleft/gpl.html read it online]
72
73 * [http://www.mediawiki.org/ MediaWiki]: $version
74 * [http://www.php.net/ PHP]: " . phpversion() . " (" . php_sapi_name() . ")
75 * " . $dbr->getSoftwareLink() . ": " . $dbr->getServerVersion();
76
77 return str_replace( "\t\t", '', $ret );
78 }
79
80 function getVersion() {
81 global $wgVersion, $IP;
82 $svn = $this->getSvnRevision( $IP );
83 return $svn ? "$wgVersion (r$svn)" : $wgVersion;
84 }
85
86 function extensionCredits() {
87 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunction;
88
89 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunction ) )
90 return '';
91
92 $extensionTypes = array(
93 'specialpage' => 'Special pages',
94 'parserhook' => 'Parser hooks',
95 'variable' => 'Variables',
96 'other' => 'Other',
97 );
98 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
99
100 $out = "\n* Extensions:\n";
101 foreach ( $extensionTypes as $type => $text ) {
102 if ( count( @$wgExtensionCredits[$type] ) ) {
103 $out .= "** $text:\n";
104
105 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
106
107 foreach ( $wgExtensionCredits[$type] as $extension ) {
108 wfSuppressWarnings();
109 $out .= $this->formatCredits(
110 $extension['name'],
111 $extension['version'],
112 $extension['author'],
113 $extension['url'],
114 $extension['description']
115 );
116 wfRestoreWarnings();
117 }
118 }
119 }
120
121 if ( count( $wgExtensionFunctions ) ) {
122 $out .= "** Extension functions:\n";
123 $out .= '***' . $this->listToText( $wgExtensionFunctions ) . "\n";
124 }
125
126 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
127 for ( $i = 0; $i < $cnt; ++$i )
128 $tags[$i] = "&lt;{$tags[$i]}&gt;";
129 $out .= "** Parser extension tags:\n";
130 $out .= '***' . $this->listToText( $tags ). "\n";
131 }
132
133 if ( count( $wgSkinExtensionFunction ) ) {
134 $out .= "** Skin extension functions:\n";
135 $out .= '***' . $this->listToText( $wgSkinExtensionFunction ) . "\n";
136 }
137
138 return $out;
139 }
140
141 function compare( $a, $b ) {
142 if ( $a['name'] === $b['name'] )
143 return 0;
144 else
145 return Language::lc( $a['name'] ) > Language::lc( $b['name'] ) ? 1 : -1;
146 }
147
148 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null) {
149 $ret = '*** ';
150 if ( isset( $url ) )
151 $ret .= "[$url ";
152 $ret .= "''$name";
153 if ( isset( $version ) )
154 $ret .= " (version $version)";
155 $ret .= "''";
156 if ( isset( $url ) )
157 $ret .= ']';
158 if ( isset( $description ) )
159 $ret .= ', ' . $description;
160 if ( isset( $description ) && isset( $author ) )
161 $ret .= ', ';
162 if ( isset( $author ) )
163 $ret .= ' by ' . $this->listToText( (array)$author );
164
165 return "$ret\n";
166 }
167
168 /**
169 * @return string
170 */
171 function wgHooks() {
172 global $wgHooks;
173
174 if ( count( $wgHooks ) ) {
175 $myWgHooks = $wgHooks;
176 ksort( $myWgHooks );
177
178 $ret = "* Hooks:\n";
179 foreach ($myWgHooks as $hook => $hooks)
180 $ret .= "** $hook: " . $this->listToText( $hooks ) . "\n";
181
182 return $ret;
183 } else
184 return '';
185 }
186
187 /**
188 * @static
189 *
190 * @return string
191 */
192 function IPInfo() {
193 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
194 return "<!-- visited from $ip -->\n" .
195 "<span style='display:none'>visited from $ip</span>";
196 }
197
198 /**
199 * @param array $list
200 * @return string
201 */
202 function listToText( $list ) {
203 $cnt = count( $list );
204
205 if ( $cnt == 1 )
206 // Enforce always returning a string
207 return (string)$this->arrayToString( $list[0] );
208 else {
209 $t = array_slice( $list, 0, $cnt - 1 );
210 $one = array_map( array( &$this, 'arrayToString' ), $t );
211 $two = $this->arrayToString( $list[$cnt - 1] );
212
213 return implode( ', ', $one ) . " and $two";
214 }
215 }
216
217 /**
218 * @static
219 *
220 * @param mixed $list Will convert an array to string if given and return
221 * the paramater unaltered otherwise
222 * @return mixed
223 */
224 function arrayToString( $list ) {
225 if ( ! is_array( $list ) )
226 return $list;
227 else {
228 $class = get_class( $list[0] );
229 return "($class, {$list[1]})";
230 }
231 }
232
233 /**
234 * Retrieve the revision number of a Subversion working directory.
235 *
236 * @param string $dir
237 * @return mixed revision number as int, or false if not a SVN checkout
238 */
239 function getSvnRevision( $dir ) {
240 if( !function_exists( 'simplexml_load_file' ) ) {
241 // We could fall back to expat... YUCK
242 return false;
243 }
244
245 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
246 $entries = $dir . '/.svn/entries';
247
248 // SimpleXml whines about the xmlns...
249 wfSuppressWarnings();
250 $xml = simplexml_load_file( $entries );
251 wfRestoreWarnings();
252
253 if( $xml ) {
254 foreach( $xml->entry as $entry ) {
255 if( $xml->entry[0]['name'] == '' ) {
256 // The directory entry should always have a revision marker.
257 if( $entry['revision'] ) {
258 return intval( $entry['revision'] );
259 }
260 }
261 }
262 }
263 return false;
264 }
265
266 /**#@-*/
267 }
268
269 /**#@-*/
270 ?>