Documentation
[mediawiki.git] / includes / SpecialVersion.php
blob6341dd30a87a0a2341fbfe99a18dc6b31d6a83cb
1 <?php
2 /**#@+
3 * Give information about the version of MediaWiki, PHP, the DB and extensions
5 * @package MediaWiki
6 * @subpackage SpecialPage
8 * @bug 2019, 4531
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
15 /**
16 * constructor
18 function wfSpecialVersion() {
19 $version = new SpecialVersion;
20 $version->execute();
23 class SpecialVersion {
24 /**
25 * main()
27 function execute() {
28 global $wgOut;
30 $wgOut->addHTML( '<div dir="ltr">' );
31 $wgOut->addWikiText(
32 $this->MediaWikiCredits() .
33 $this->extensionCredits() .
34 $this->wgHooks()
36 $wgOut->addHTML( $this->IPInfo() );
37 $wgOut->addHTML( '</div>' );
40 /**#@+
41 * @access private
44 /**
45 * @static
47 function MediaWikiCredits() {
48 global $wgVersion;
50 $dbr =& wfGetDB( DB_SLAVE );
52 $ret =
53 "__NOTOC__
54 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
55 copyright (C) 2001-2006 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
56 Tim Starling, Erik Möller, and others.
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
71 or [http://www.gnu.org/copyleft/gpl.html read it online]
73 * [http://www.mediawiki.org/ MediaWiki]: $wgVersion
74 * [http://www.php.net/ PHP]: " . phpversion() . " (" . php_sapi_name() . ")
75 * " . $dbr->getSoftwareLink() . ": " . $dbr->getServerVersion();
77 return str_replace( "\t\t", '', $ret );
80 function extensionCredits() {
81 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunction;
83 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunction ) )
84 return '';
86 $extensionTypes = array(
87 'specialpage' => 'Special pages',
88 'parserhook' => 'Parser hooks',
89 'variable' => 'Variables',
90 'other' => 'Other',
92 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
94 $out = "\n* Extensions:\n";
95 foreach ( $extensionTypes as $type => $text ) {
96 if ( count( @$wgExtensionCredits[$type] ) ) {
97 $out .= "** $text:\n";
99 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
101 foreach ( $wgExtensionCredits[$type] as $extension ) {
102 wfSuppressWarnings();
103 $out .= $this->formatCredits(
104 $extension['name'],
105 $extension['version'],
106 $extension['author'],
107 $extension['url'],
108 $extension['description']
110 wfRestoreWarnings();
115 if ( count( $wgExtensionFunctions ) ) {
116 $out .= "** Extension functions:\n";
117 $out .= '***' . $this->listToText( $wgExtensionFunctions ) . "\n";
120 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
121 for ( $i = 0; $i < $cnt; ++$i )
122 $tags[$i] = "&lt;{$tags[$i]}&gt;";
123 $out .= "** Parser extension tags:\n";
124 $out .= '***' . $this->listToText( $tags ). "\n";
127 if ( count( $wgSkinExtensionFunction ) ) {
128 $out .= "** Skin extension functions:\n";
129 $out .= '***' . $this->listToText( $wgSkinExtensionFunction ) . "\n";
132 return $out;
135 function compare( $a, $b ) {
136 if ( $a['name'] === $b['name'] )
137 return 0;
138 else
139 return LanguageUtf8::lc( $a['name'] ) > LanguageUtf8::lc( $b['name'] ) ? 1 : -1;
142 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null) {
143 $ret = '*** ';
144 if ( isset( $url ) )
145 $ret .= "[$url ";
146 $ret .= "''$name";
147 if ( isset( $version ) )
148 $ret .= " (version $version)";
149 $ret .= "''";
150 if ( isset( $url ) )
151 $ret .= ']';
152 if ( isset( $description ) )
153 $ret .= ', ' . $description;
154 if ( isset( $description ) && isset( $author ) )
155 $ret .= ', ';
156 if ( isset( $author ) )
157 $ret .= ' by ' . $this->listToText( (array)$author );
159 return "$ret\n";
163 * @return string
165 function wgHooks() {
166 global $wgHooks;
168 if ( count( $wgHooks ) ) {
169 $myWgHooks = $wgHooks;
170 ksort( $myWgHooks );
172 $ret = "* Hooks:\n";
173 foreach ($myWgHooks as $hook => $hooks)
174 $ret .= "** $hook: " . $this->listToText( $hooks ) . "\n";
176 return $ret;
177 } else
178 return '';
182 * @static
184 * @return string
186 function IPInfo() {
187 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
188 return "<!-- visited from $ip -->\n";
192 * @param array $list
193 * @return string
195 function listToText( $list ) {
196 $cnt = count( $list );
198 if ( $cnt == 1 )
199 // Enforce always returning a string
200 return (string)$this->arrayToString( $list[0] );
201 else {
202 $t = array_slice( $list, 0, $cnt - 1 );
203 $one = array_map( array( &$this, 'arrayToString' ), $t );
204 $two = $this->arrayToString( $list[$cnt - 1] );
206 return implode( ', ', $one ) . " and $two";
211 * @static
213 * @param mixed $list Will convert an array to string if given and return
214 * the paramater unaltered otherwise
215 * @return mixed
217 function arrayToString( $list ) {
218 if ( ! is_array( $list ) )
219 return $list;
220 else {
221 $class = get_class( $list[0] );
222 return "($class, {$list[1]})";
226 /**#@-*/
229 /**#@-*/