3 * Give information about the version of MediaWiki, PHP, the DB and extensions
6 * @subpackage SpecialPage
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
18 function wfSpecialVersion() {
19 $version = new SpecialVersion
;
23 class SpecialVersion
{
30 $wgOut->addHTML( '<div dir="ltr">' );
32 $this->MediaWikiCredits() .
33 $this->extensionCredits() .
36 $wgOut->addHTML( $this->IPInfo() );
37 $wgOut->addHTML( '</div>' );
49 * Copyright (C) 2004 Gabriel Wicke <wicke@wikidev.net>
51 * Based on PageHistory and SpecialExport
53 * License: GPL (http://www.gnu.org/copyleft/gpl.html)
55 * @author Gabriel Wicke <wicke@wikidev.net>
60 require_once( 'Revision.php' );
67 var $mArticle, $mTitle, $mRequest;
68 var $mOldId, $mGen, $mCharset;
69 var $mSmaxage, $mMaxage;
70 var $mContentType, $mExpandTemplates;
72 function RawPage( &$article, $request = false ) {
73 global $wgRequest, $wgInputEncoding, $wgSquidMaxage, $wgJsMimeType;
75 $allowedCTypes = array('text/x-wiki', $wgJsMimeType, 'text/css', 'application/x-zope-edit');
76 $this->mArticle
=& $article;
77 $this->mTitle
=& $article->mTitle
;
79 if ( $request === false ) {
80 $this->mRequest
=& $wgRequest;
82 $this->mRequest
= $request;
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';
90 $oldid = $this->mRequest
->getInt( 'oldid' );
91 switch ( $wgRequest->getText( 'direction' ) ) {
93 # output next revision, or nothing if there isn't one
95 $oldid = $this->mTitle
->getNextRevisionId( $oldid );
97 $oldid = $oldid ?
$oldid : -1;
100 # output previous revision, or nothing if there isn't one
102 # get the current revision so we can get the penultimate one
103 $this->mArticle
->getTouched();
104 $oldid = $this->mArticle
->mLatest
;
106 $prev = $this->mTitle
->getPreviousRevisionId( $oldid );
107 $oldid = $prev ?
$prev : -1 ;
113 $this->mOldId
= $oldid;
115 # special case for 'generated' raw things: user css/js
116 $gen = $this->mRequest
->getVal( 'gen' );
120 if( is_null( $smaxage ) ) $smaxage = $wgSquidMaxage;
121 if($ctype == '') $ctype = 'text/css';
122 } elseif ($gen == 'js') {
124 if( is_null( $smaxage ) ) $smaxage = $wgSquidMaxage;
125 if($ctype == '') $ctype = $wgJsMimeType;
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';
135 $this->mContentType
= $ctype;
140 global $wgOut, $wgScript;
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.
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.
151 # If in this mode, use SCRIPT_URL instead, which mod_rewrite
152 # provides containing the "before" URL.
153 $url = $_SERVER['SCRIPT_URL'];
155 $url = $_SERVER['PHP_SELF'];
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.
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
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.' );
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();
184 function getRawText() {
185 global $wgUser, $wgOut;
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();
195 return $this->getArticleText();
199 function getArticleText() {
200 if( $this->mTitle
) {
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() );
207 // Get it from the DB
208 $rev = Revision
::newFromTitle( $this->mTitle
, $this->mOldId
);
210 $lastmod = wfTimestamp( TS_RFC2822
, $rev->getTimestamp() );
211 header( "Last-modified: $lastmod" );
212 $text = $rev->getText();
217 return $this->parseArticleText( $text );
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
226 header( "HTTP/1.0 404 Not Found" );
231 function parseArticleText( $text ) {
235 if ( $this->mExpandTemplates
) {
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
);
243 return $parser->replaceVariables( $text );
249 function MediaWikiCredits() {
252 $dbr =& wfGetDB( DB_SLAVE
);
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.
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.
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.
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]
275 * [http://www.mediawiki.org/ MediaWiki]: $wgVersion
276 * [http://www.php.net/ PHP]: " . phpversion() . " (" . php_sapi_name() . ")
277 * " . $dbr->getSoftwareLink() . ": " . $dbr->getServerVersion();
279 return str_replace( "\t\t", '', $ret );
282 function extensionCredits() {
283 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunction;
285 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunction ) )
288 $extensionTypes = array(
289 'specialpage' => 'Special pages',
290 'parserhook' => 'Parser hooks',
291 'variable' => 'Variables',
294 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
296 $out = "\n* Extensions:\n";
297 foreach ( $extensionTypes as $type => $text ) {
298 if ( count( @$wgExtensionCredits[$type] ) ) {
299 $out .= "** $text:\n";
301 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
303 foreach ( $wgExtensionCredits[$type] as $extension ) {
304 wfSuppressWarnings();
305 $out .= $this->formatCredits(
307 $extension['version'],
308 $extension['author'],
310 $extension['description']
317 if ( count( $wgExtensionFunctions ) ) {
318 $out .= "** Extension functions:\n";
319 $out .= '***' . $this->listToText( $wgExtensionFunctions ) . "\n";
322 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
323 for ( $i = 0; $i < $cnt; ++
$i )
324 $tags[$i] = "<{$tags[$i]}>";
325 $out .= "** Parser extension tags:\n";
326 $out .= '***' . $this->listToText( $tags ). "\n";
329 if ( count( $wgSkinExtensionFunction ) ) {
330 $out .= "** Skin extension functions:\n";
331 $out .= '***' . $this->listToText( $wgSkinExtensionFunction ) . "\n";
337 function compare( $a, $b ) {
338 if ( $a['name'] === $b['name'] )
341 return LanguageUtf8
::lc( $a['name'] ) > LanguageUtf8
::lc( $b['name'] ) ?
1 : -1;
344 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null) {
349 if ( isset( $version ) )
350 $ret .= " (version $version)";
354 if ( isset( $description ) )
355 $ret .= ', ' . $description;
356 if ( isset( $description ) && isset( $author ) )
358 if ( isset( $author ) )
359 $ret .= ' by ' . $this->listToText( (array)$author );
370 if ( count( $wgHooks ) ) {
371 $myWgHooks = $wgHooks;
375 foreach ($myWgHooks as $hook => $hooks)
376 $ret .= "** $hook: " . $this->listToText( $hooks ) . "\n";
389 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
390 return "<!-- visited from $ip -->\n";
397 function listToText( $list ) {
398 $cnt = count( $list );
401 // Enforce always returning a string
402 return (string)$this->arrayToString( $list[0] );
404 $t = array_slice( $list, 0, $cnt - 1 );
405 $one = array_map( array( &$this, 'arrayToString' ), $t );
406 $two = $this->arrayToString( $list[$cnt - 1] );
408 return implode( ', ', $one ) . " and $two";
415 * @param mixed $list Will convert an array to string if given and return
416 * the paramater unaltered otherwise
419 function arrayToString( $list ) {
420 if ( ! is_array( $list ) )
423 $class = get_class( $list[0] );
424 return "($class, {$list[1]})";