* Fix explicit s-maxage=0 on raw pages; should help with proxy issues in
[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 if ( count( $wgHooks ) ) {
169 $myWgHooks = $wgHooks;
170 ksort( $myWgHooks );
171
172 $ret = "* Hooks:\n";
173 foreach ($myWgHooks as $hook => $hooks)
174 $ret .= "** $hook: " . $this->listToText( $hooks ) . "\n";
175
176 return $ret;
177 } else
178 return '';
179 }
180
181 /**
182 * @static
183 *
184 * @return string
185 */
186 function IPInfo() {
187 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
188 return "<!-- visited from $ip -->\n";
189 }
190
191 /**
192 * @param array $list
193 * @return string
194 */
195 function listToText( $list ) {
196 $cnt = count( $list );
197
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] );
205
206 return implode( ', ', $one ) . " and $two";
207 }
208 }
209
210 /**
211 * @static
212 *
213 * @param mixed $list Will convert an array to string if given and return
214 * the paramater unaltered otherwise
215 * @return mixed
216 */
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]})";
223 }
224 }
225
226 /**#@-*/
227 }
228
229 /**#@-*/
230 ?>