Updated contact data in credits
[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 * @access private
42 */
43
44 /**
45 * @static
46 */
47 <?php
48 /**
49 * Copyright (C) 2004 Gabriel Wicke <wicke@wikidev.net>
50 * http://wikidev.net/
51 * Based on PageHistory and SpecialExport
52 *
53 * License: GPL (http://www.gnu.org/copyleft/gpl.html)
54 *
55 * @author Gabriel Wicke <wicke@wikidev.net>
56 * @package MediaWiki
57 */
58
59 /** */
60 require_once( 'Revision.php' );
61
62 /**
63 * @todo document
64 * @package MediaWiki
65 */
66 class RawPage {
67 var $mArticle, $mTitle, $mRequest;
68 var $mOldId, $mGen, $mCharset;
69 var $mSmaxage, $mMaxage;
70 var $mContentType, $mExpandTemplates;
71
72 function RawPage( &$article, $request = false ) {
73 global $wgRequest, $wgInputEncoding, $wgSquidMaxage, $wgJsMimeType;
74
75 $allowedCTypes = array('text/x-wiki', $wgJsMimeType, 'text/css', 'application/x-zope-edit');
76 $this->mArticle =& $article;
77 $this->mTitle =& $article->mTitle;
78
79 if ( $request === false ) {
80 $this->mRequest =& $wgRequest;
81 } else {
82 $this->mRequest = $request;
83 }
84
85 $ctype = $this->mRequest->getVal( 'ctype' );
86 $smaxage = $this->mRequest->getIntOrNull( 'smaxage', $wgSquidMaxage );
87 $maxage = $this->mRequest->getInt( 'maxage', $wgSquidMaxage );
88 $this->mExpandTemplates = $this->mRequest->getVal( 'templates' ) === 'expand';
89
90 $oldid = $this->mRequest->getInt( 'oldid' );
91 switch ( $wgRequest->getText( 'direction' ) ) {
92 case 'next':
93 # output next revision, or nothing if there isn't one
94 if ( $oldid ) {
95 $oldid = $this->mTitle->getNextRevisionId( $oldid );
96 }
97 $oldid = $oldid ? $oldid : -1;
98 break;
99 case 'prev':
100 # output previous revision, or nothing if there isn't one
101 if ( ! $oldid ) {
102 # get the current revision so we can get the penultimate one
103 $this->mArticle->getTouched();
104 $oldid = $this->mArticle->mLatest;
105 }
106 $prev = $this->mTitle->getPreviousRevisionId( $oldid );
107 $oldid = $prev ? $prev : -1 ;
108 break;
109 case 'cur':
110 $oldid = 0;
111 break;
112 }
113 $this->mOldId = $oldid;
114
115 # special case for 'generated' raw things: user css/js
116 $gen = $this->mRequest->getVal( 'gen' );
117
118 if($gen == 'css') {
119 $this->mGen = $gen;
120 if( is_null( $smaxage ) ) $smaxage = $wgSquidMaxage;
121 if($ctype == '') $ctype = 'text/css';
122 } elseif ($gen == 'js') {
123 $this->mGen = $gen;
124 if( is_null( $smaxage ) ) $smaxage = $wgSquidMaxage;
125 if($ctype == '') $ctype = $wgJsMimeType;
126 } else {
127 $this->mGen = false;
128 }
129 $this->mCharset = $wgInputEncoding;
130 $this->mSmaxage = intval( $smaxage );
131 $this->mMaxage = $maxage;
132 if ( $ctype == '' or ! in_array( $ctype, $allowedCTypes ) ) {
133 $this->mContentType = 'text/x-wiki';
134 } else {
135 $this->mContentType = $ctype;
136 }
137 }
138
139 function view() {
140 global $wgOut, $wgScript;
141
142 if( isset( $_SERVER['SCRIPT_URL'] ) ) {
143 # Normally we use PHP_SELF to get the URL to the script
144 # as it was called, minus the query string.
145 #
146 # Some sites use Apache rewrite rules to handle subdomains,
147 # and have PHP set up in a weird way that causes PHP_SELF
148 # to contain the rewritten URL instead of the one that the
149 # outside world sees.
150 #
151 # If in this mode, use SCRIPT_URL instead, which mod_rewrite
152 # provides containing the "before" URL.
153 $url = $_SERVER['SCRIPT_URL'];
154 } else {
155 $url = $_SERVER['PHP_SELF'];
156 }
157
158 $ua = @$_SERVER['HTTP_USER_AGENT'];
159 if( strcmp( $wgScript, $url ) && strpos( $ua, 'MSIE' ) !== false ) {
160 # Internet Explorer will ignore the Content-Type header if it
161 # thinks it sees a file extension it recognizes. Make sure that
162 # all raw requests are done through the script node, which will
163 # have eg '.php' and should remain safe.
164 #
165 # We used to redirect to a canonical-form URL as a general
166 # backwards-compatibility / good-citizen nice thing. However
167 # a lot of servers are set up in buggy ways, resulting in
168 # redirect loops which hang the browser until the CSS load
169 # times out.
170 #
171 # Just return a 403 Forbidden and get it over with.
172 wfHttpError( 403, 'Forbidden',
173 'Raw pages must be accessed through the primary script entry point.' );
174 return;
175 }
176
177 header( "Content-type: ".$this->mContentType.'; charset='.$this->mCharset );
178 # allow the client to cache this for 24 hours
179 header( 'Cache-Control: s-maxage='.$this->mSmaxage.', max-age='.$this->mMaxage );
180 echo $this->getRawText();
181 $wgOut->disable();
182 }
183
184 function getRawText() {
185 global $wgUser, $wgOut;
186 if($this->mGen) {
187 $sk = $wgUser->getSkin();
188 $sk->initPage($wgOut);
189 if($this->mGen == 'css') {
190 return $sk->getUserStylesheet();
191 } else if($this->mGen == 'js') {
192 return $sk->getUserJs();
193 }
194 } else {
195 return $this->getArticleText();
196 }
197 }
198
199 function getArticleText() {
200 if( $this->mTitle ) {
201 $text = '';
202
203 // If it's a MediaWiki message we can just hit the message cache
204 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
205 $text = wfMsgForContentNoTrans( $this->mTitle->getDbkey() );
206 } else {
207 // Get it from the DB
208 $rev = Revision::newFromTitle( $this->mTitle, $this->mOldId );
209 if ( $rev ) {
210 $lastmod = wfTimestamp( TS_RFC2822, $rev->getTimestamp() );
211 header( "Last-modified: $lastmod" );
212 $text = $rev->getText();
213 } else
214 $text = '';
215 }
216
217 return $this->parseArticleText( $text );
218 }
219
220 # Bad title or page does not exist
221 if( $this->mContentType == 'text/x-wiki' ) {
222 # Don't return a 404 response for CSS or JavaScript;
223 # 404s aren't generally cached and it would create
224 # extra hits when user CSS/JS are on and the user doesn't
225 # have the pages.
226 header( "HTTP/1.0 404 Not Found" );
227 }
228 return '';
229 }
230
231 function parseArticleText( $text ) {
232 if ( $text === '' )
233 return '';
234 else
235 if ( $this->mExpandTemplates ) {
236 global $wgTitle;
237
238 $parser = new Parser();
239 $parser->Options( new ParserOptions() ); // We don't want this to be user-specific
240 $parser->Title( $wgTitle );
241 $parser->OutputType( OT_HTML );
242
243 return $parser->replaceVariables( $text );
244 } else
245 return $text;
246 }
247 }
248 ?>
249 function MediaWikiCredits() {
250 global $wgVersion;
251
252 $dbr =& wfGetDB( DB_SLAVE );
253
254 $ret =
255 "__NOTOC__
256 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
257 copyright (C) 2001-2006 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
258 Tim Starling, Erik Möller, Gabriel Wicke and others.
259
260 MediaWiki is free software; you can redistribute it and/or modify
261 it under the terms of the GNU General Public License as published by
262 the Free Software Foundation; either version 2 of the License, or
263 (at your option) any later version.
264
265 MediaWiki is distributed in the hope that it will be useful,
266 but WITHOUT ANY WARRANTY; without even the implied warranty of
267 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
268 GNU General Public License for more details.
269
270 You should have received [{{SERVER}}{{SCRIPTPATH}}/COPYING a copy of the GNU General Public License]
271 along with this program; if not, write to the Free Software
272 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
273 or [http://www.gnu.org/copyleft/gpl.html read it online]
274
275 * [http://www.mediawiki.org/ MediaWiki]: $wgVersion
276 * [http://www.php.net/ PHP]: " . phpversion() . " (" . php_sapi_name() . ")
277 * " . $dbr->getSoftwareLink() . ": " . $dbr->getServerVersion();
278
279 return str_replace( "\t\t", '', $ret );
280 }
281
282 function extensionCredits() {
283 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunction;
284
285 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunction ) )
286 return '';
287
288 $extensionTypes = array(
289 'specialpage' => 'Special pages',
290 'parserhook' => 'Parser hooks',
291 'variable' => 'Variables',
292 'other' => 'Other',
293 );
294 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
295
296 $out = "\n* Extensions:\n";
297 foreach ( $extensionTypes as $type => $text ) {
298 if ( count( @$wgExtensionCredits[$type] ) ) {
299 $out .= "** $text:\n";
300
301 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
302
303 foreach ( $wgExtensionCredits[$type] as $extension ) {
304 wfSuppressWarnings();
305 $out .= $this->formatCredits(
306 $extension['name'],
307 $extension['version'],
308 $extension['author'],
309 $extension['url'],
310 $extension['description']
311 );
312 wfRestoreWarnings();
313 }
314 }
315 }
316
317 if ( count( $wgExtensionFunctions ) ) {
318 $out .= "** Extension functions:\n";
319 $out .= '***' . $this->listToText( $wgExtensionFunctions ) . "\n";
320 }
321
322 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
323 for ( $i = 0; $i < $cnt; ++$i )
324 $tags[$i] = "&lt;{$tags[$i]}&gt;";
325 $out .= "** Parser extension tags:\n";
326 $out .= '***' . $this->listToText( $tags ). "\n";
327 }
328
329 if ( count( $wgSkinExtensionFunction ) ) {
330 $out .= "** Skin extension functions:\n";
331 $out .= '***' . $this->listToText( $wgSkinExtensionFunction ) . "\n";
332 }
333
334 return $out;
335 }
336
337 function compare( $a, $b ) {
338 if ( $a['name'] === $b['name'] )
339 return 0;
340 else
341 return LanguageUtf8::lc( $a['name'] ) > LanguageUtf8::lc( $b['name'] ) ? 1 : -1;
342 }
343
344 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null) {
345 $ret = '*** ';
346 if ( isset( $url ) )
347 $ret .= "[$url ";
348 $ret .= "''$name";
349 if ( isset( $version ) )
350 $ret .= " (version $version)";
351 $ret .= "''";
352 if ( isset( $url ) )
353 $ret .= ']';
354 if ( isset( $description ) )
355 $ret .= ', ' . $description;
356 if ( isset( $description ) && isset( $author ) )
357 $ret .= ', ';
358 if ( isset( $author ) )
359 $ret .= ' by ' . $this->listToText( (array)$author );
360
361 return "$ret\n";
362 }
363
364 /**
365 * @return string
366 */
367 function wgHooks() {
368 global $wgHooks;
369
370 if ( count( $wgHooks ) ) {
371 $myWgHooks = $wgHooks;
372 ksort( $myWgHooks );
373
374 $ret = "* Hooks:\n";
375 foreach ($myWgHooks as $hook => $hooks)
376 $ret .= "** $hook: " . $this->listToText( $hooks ) . "\n";
377
378 return $ret;
379 } else
380 return '';
381 }
382
383 /**
384 * @static
385 *
386 * @return string
387 */
388 function IPInfo() {
389 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
390 return "<!-- visited from $ip -->\n";
391 }
392
393 /**
394 * @param array $list
395 * @return string
396 */
397 function listToText( $list ) {
398 $cnt = count( $list );
399
400 if ( $cnt == 1 )
401 // Enforce always returning a string
402 return (string)$this->arrayToString( $list[0] );
403 else {
404 $t = array_slice( $list, 0, $cnt - 1 );
405 $one = array_map( array( &$this, 'arrayToString' ), $t );
406 $two = $this->arrayToString( $list[$cnt - 1] );
407
408 return implode( ', ', $one ) . " and $two";
409 }
410 }
411
412 /**
413 * @static
414 *
415 * @param mixed $list Will convert an array to string if given and return
416 * the paramater unaltered otherwise
417 * @return mixed
418 */
419 function arrayToString( $list ) {
420 if ( ! is_array( $list ) )
421 return $list;
422 else {
423 $class = get_class( $list[0] );
424 return "($class, {$list[1]})";
425 }
426 }
427
428 /**#@-*/
429 }
430
431 /**#@-*/
432 ?>