API * Optimized backlinking query (still needs an index change)
[mediawiki.git] / includes / SpecialVersion.php
blob8744597adf15e5367166cd84c872934bd490bc72
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 * @private
44 /**
45 * @static
47 function MediaWikiCredits() {
48 $version = self::getVersion();
49 $dbr =& wfGetDB( DB_SLAVE );
51 $ret =
52 "__NOTOC__
53 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
54 copyright (C) 2001-2006 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
55 Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
56 Niklas Laxström, Domas Mituzas, Rob Church 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
71 or [http://www.gnu.org/copyleft/gpl.html read it online]
73 * [http://www.mediawiki.org/ MediaWiki]: $version
74 * [http://www.php.net/ PHP]: " . phpversion() . " (" . php_sapi_name() . ")
75 * " . $dbr->getSoftwareLink() . ": " . $dbr->getServerVersion();
77 return str_replace( "\t\t", '', $ret );
80 public static function getVersion() {
81 global $wgVersion, $IP;
82 $svn = self::getSvnRevision( $IP );
83 return $svn ? "$wgVersion (r$svn)" : $wgVersion;
86 function extensionCredits() {
87 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunction;
89 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunction ) )
90 return '';
92 $extensionTypes = array(
93 'specialpage' => 'Special pages',
94 'parserhook' => 'Parser hooks',
95 'variable' => 'Variables',
96 'other' => 'Other',
98 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
100 $out = "\n* Extensions:\n";
101 foreach ( $extensionTypes as $type => $text ) {
102 if ( count( @$wgExtensionCredits[$type] ) ) {
103 $out .= "** $text:\n";
105 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
107 foreach ( $wgExtensionCredits[$type] as $extension ) {
108 wfSuppressWarnings();
109 $out .= $this->formatCredits(
110 $extension['name'],
111 $extension['version'],
112 $extension['author'],
113 $extension['url'],
114 $extension['description']
116 wfRestoreWarnings();
121 if ( count( $wgExtensionFunctions ) ) {
122 $out .= "** Extension functions:\n";
123 $out .= '***' . $this->listToText( $wgExtensionFunctions ) . "\n";
126 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
127 for ( $i = 0; $i < $cnt; ++$i )
128 $tags[$i] = "&lt;{$tags[$i]}&gt;";
129 $out .= "** Parser extension tags:\n";
130 $out .= '***' . $this->listToText( $tags ). "\n";
133 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
134 $out .= "** Parser function hooks:\n";
135 $out .= '***' . $this->listToText( $fhooks ) . "\n";
138 if ( count( $wgSkinExtensionFunction ) ) {
139 $out .= "** Skin extension functions:\n";
140 $out .= '***' . $this->listToText( $wgSkinExtensionFunction ) . "\n";
143 return $out;
146 function compare( $a, $b ) {
147 if ( $a['name'] === $b['name'] )
148 return 0;
149 else
150 return Language::lc( $a['name'] ) > Language::lc( $b['name'] ) ? 1 : -1;
153 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null) {
154 $ret = '*** ';
155 if ( isset( $url ) )
156 $ret .= "[$url ";
157 $ret .= "''$name";
158 if ( isset( $version ) )
159 $ret .= " (version $version)";
160 $ret .= "''";
161 if ( isset( $url ) )
162 $ret .= ']';
163 if ( isset( $description ) )
164 $ret .= ', ' . $description;
165 if ( isset( $description ) && isset( $author ) )
166 $ret .= ', ';
167 if ( isset( $author ) )
168 $ret .= ' by ' . $this->listToText( (array)$author );
170 return "$ret\n";
174 * @return string
176 function wgHooks() {
177 global $wgHooks;
179 if ( count( $wgHooks ) ) {
180 $myWgHooks = $wgHooks;
181 ksort( $myWgHooks );
183 $ret = "* Hooks:\n";
184 foreach ($myWgHooks as $hook => $hooks)
185 $ret .= "** $hook: " . $this->listToText( $hooks ) . "\n";
187 return $ret;
188 } else
189 return '';
193 * @static
195 * @return string
197 function IPInfo() {
198 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
199 return "<!-- visited from $ip -->\n" .
200 "<span style='display:none'>visited from $ip</span>";
204 * @param array $list
205 * @return string
207 function listToText( $list ) {
208 $cnt = count( $list );
210 if ( $cnt == 1 )
211 // Enforce always returning a string
212 return (string)$this->arrayToString( $list[0] );
213 else {
214 $t = array_slice( $list, 0, $cnt - 1 );
215 $one = array_map( array( &$this, 'arrayToString' ), $t );
216 $two = $this->arrayToString( $list[$cnt - 1] );
218 return implode( ', ', $one ) . " and $two";
223 * @static
225 * @param mixed $list Will convert an array to string if given and return
226 * the paramater unaltered otherwise
227 * @return mixed
229 function arrayToString( $list ) {
230 if ( ! is_array( $list ) )
231 return $list;
232 else {
233 $class = get_class( $list[0] );
234 return "($class, {$list[1]})";
239 * Retrieve the revision number of a Subversion working directory.
241 * @bug 7335
243 * @param string $dir
244 * @return mixed revision number as int, or false if not a SVN checkout
246 public static function getSvnRevision( $dir ) {
247 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
248 $entries = $dir . '/.svn/entries';
250 if( !file_exists( $entries ) ) {
251 return false;
254 $content = file( $entries );
256 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
257 if( preg_match( '/^<\?xml/', $content[0] ) ) {
258 // subversion is release <= 1.3
259 if( !function_exists( 'simplexml_load_file' ) ) {
260 // We could fall back to expat... YUCK
261 return false;
264 // SimpleXml whines about the xmlns...
265 wfSuppressWarnings();
266 $xml = simplexml_load_file( $entries );
267 wfRestoreWarnings();
269 if( $xml ) {
270 foreach( $xml->entry as $entry ) {
271 if( $xml->entry[0]['name'] == '' ) {
272 // The directory entry should always have a revision marker.
273 if( $entry['revision'] ) {
274 return intval( $entry['revision'] );
279 return false;
280 } else {
281 // subversion is release 1.4
282 return intval( $content[3] );
285 return false;
288 /**#@-*/
291 /**#@-*/