Revert namespacebanner feature:
[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 function MediaWikiCredits() {
48 global $wgVersion;
49
50 $dbr =& wfGetDB( DB_SLAVE );
51
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
71 or [http://www.gnu.org/copyleft/gpl.html read it online]
72
73 * [http://www.mediawiki.org/ MediaWiki]: $wgVersion
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 extensionCredits() {
81 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunction;
82
83 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunction ) )
84 return '';
85
86 $extensionTypes = array(
87 'specialpage' => 'Special pages',
88 'parserhook' => 'Parser hooks',
89 'variable' => 'Variables',
90 'other' => 'Other',
91 );
92 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
93
94 $out = "\n* Extensions:\n";
95 foreach ( $extensionTypes as $type => $text ) {
96 if ( count( @$wgExtensionCredits[$type] ) ) {
97 $out .= "** $text:\n";
98
99 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
100
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']
109 );
110 wfRestoreWarnings();
111 }
112 }
113 }
114
115 if ( count( $wgExtensionFunctions ) ) {
116 $out .= "** Extension functions:\n";
117 $out .= '***' . $this->listToText( $wgExtensionFunctions ) . "\n";
118 }
119
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";
125 }
126
127 if ( count( $wgSkinExtensionFunction ) ) {
128 $out .= "** Skin extension functions:\n";
129 $out .= '***' . $this->listToText( $wgSkinExtensionFunction ) . "\n";
130 }
131
132 return $out;
133 }
134
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;
140 }
141
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 );
158
159 return "$ret\n";
160 }
161
162 /**
163 * @return string
164 */
165 function wgHooks() {
166 global $wgHooks;
167
168 $myWgHooks = $wgHooks;
169 ksort( $myWgHooks );
170
171 $ret = "* Hooks:\n";
172 foreach ($myWgHooks as $hook => $hooks)
173 $ret .= "** $hook: " . $this->listToText( $hooks ) . "\n";
174
175 return $ret;
176 }
177
178 /**
179 * @static
180 *
181 * @return string
182 */
183 function IPInfo() {
184 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
185 return "<!-- visited from $ip -->\n";
186 }
187
188 /**
189 * @param array $list
190 * @return string
191 */
192 function listToText( $list ) {
193 $cnt = count( $list );
194
195 if ( $cnt == 1 )
196 // Enforce always returning a string
197 return (string)$this->arrayToString( $list[0] );
198 else {
199 $t = array_slice( $list, 0, $cnt - 1 );
200 $one = array_map( array( &$this, 'arrayToString' ), $t );
201 $two = $this->arrayToString( $list[$cnt - 1] );
202
203 return implode( ', ', $one ) . " and $two";
204 }
205 }
206
207 /**
208 * @static
209 *
210 * @param mixed $list Will convert an array to string if given and return
211 * the paramater unaltered otherwise
212 * @return mixed
213 */
214 function arrayToString( $list ) {
215 if ( ! is_array( $list ) )
216 return $list;
217 else {
218 $class = get_class( $list[0] );
219 return "($class, {$list[1]})";
220 }
221 }
222
223 /**#@-*/
224 }
225
226 /**#@-*/
227 ?>