*Tweak rev_deleted message
[mediawiki.git] / includes / SpecialVersion.php
blobde0a25002d12590fe1454b6c037f109afa621f11
1 <?php
2 /**#@+
3 * Give information about the version of MediaWiki, PHP, the DB and extensions
5 * @addtogroup SpecialPage
7 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
8 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
9 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
12 /**
13 * constructor
15 function wfSpecialVersion() {
16 $version = new SpecialVersion;
17 $version->execute();
20 class SpecialVersion {
21 private $firstExtOpened = true;
23 /**
24 * main()
26 function execute() {
27 global $wgOut;
29 $wgOut->addHTML( '<div dir="ltr">' );
30 $wgOut->addWikiText(
31 $this->MediaWikiCredits() .
32 $this->extensionCredits() .
33 $this->wgHooks()
35 $wgOut->addHTML( $this->IPInfo() );
36 $wgOut->addHTML( '</div>' );
39 /**#@+
40 * @private
43 /**
44 * Return wiki text showing the licence information and third party
45 * software versions (apache, php, mysql).
46 * @static
48 function MediaWikiCredits() {
49 $version = self::getVersion();
50 $dbr = wfGetDB( DB_SLAVE );
52 $ret =
53 "__NOTOC__
54 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
55 copyright (C) 2001-2007 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
56 Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
57 Niklas Laxström, Domas Mituzas, Rob Church and others.
59 MediaWiki is free software; you can redistribute it and/or modify
60 it under the terms of the GNU General Public License as published by
61 the Free Software Foundation; either version 2 of the License, or
62 (at your option) any later version.
64 MediaWiki is distributed in the hope that it will be useful,
65 but WITHOUT ANY WARRANTY; without even the implied warranty of
66 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67 GNU General Public License for more details.
69 You should have received [{{SERVER}}{{SCRIPTPATH}}/COPYING a copy of the GNU General Public License]
70 along with this program; if not, write to the Free Software
71 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
72 or [http://www.gnu.org/copyleft/gpl.html read it online]
74 * [http://www.mediawiki.org/ MediaWiki]: $version
75 * [http://www.php.net/ PHP]: " . phpversion() . " (" . php_sapi_name() . ")
76 * " . $dbr->getSoftwareLink() . ": " . $dbr->getServerVersion();
78 return str_replace( "\t\t", '', $ret ) . "\n";
81 /** Return a string of the MediaWiki version with SVN revision if available */
82 public static function getVersion() {
83 global $wgVersion, $IP;
84 $svn = self::getSvnRevision( $IP );
85 return $svn ? "$wgVersion (r$svn)" : $wgVersion;
88 /** Generate wikitext showing extensions name, URL, author and description */
89 function extensionCredits() {
90 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunction;
92 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunction ) )
93 return '';
95 $extensionTypes = array(
96 'specialpage' => 'Special pages',
97 'parserhook' => 'Parser hooks',
98 'variable' => 'Variables',
99 'media' => 'Media handlers',
100 'other' => 'Other',
102 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
104 $out = "<h2>Extensions</h2>\n";
105 $out .= wfOpenElement('table', array('id' => 'sv-ext') );
107 foreach ( $extensionTypes as $type => $text ) {
108 if ( isset ( $wgExtensionCredits[$type] ) && count ( $wgExtensionCredits[$type] ) ) {
109 $out .= $this->openExtType( $text );
111 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
113 foreach ( $wgExtensionCredits[$type] as $extension ) {
114 $out .= $this->formatCredits(
115 isset ( $extension['name'] ) ? $extension['name'] : '',
116 isset ( $extension['version'] ) ? $extension['version'] : null,
117 isset ( $extension['author'] ) ? $extension['author'] : '',
118 isset ( $extension['url'] ) ? $extension['url'] : null,
119 isset ( $extension['description'] ) ? $extension['description'] : ''
125 if ( count( $wgExtensionFunctions ) ) {
126 $out .= $this->openExtType('Extension functions');
127 $out .= '<tr><td colspan="3">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
130 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
131 for ( $i = 0; $i < $cnt; ++$i )
132 $tags[$i] = "&lt;{$tags[$i]}&gt;";
133 $out .= $this->openExtType('Parser extension tags');
134 $out .= '<tr><td colspan="3">' . $this->listToText( $tags ). "</td></tr>\n";
137 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
138 $out .= $this->openExtType('Parser function hooks');
139 $out .= '<tr><td colspan="3">' . $this->listToText( $fhooks ) . "</td></tr>\n";
142 if ( count( $wgSkinExtensionFunction ) ) {
143 $out .= $this->openExtType('Skin extension functions');
144 $out .= '<tr><td colspan="3">' . $this->listToText( $wgSkinExtensionFunction ) . "</td></tr>\n";
146 $out .= wfCloseElement( 'table' );
147 return $out;
150 /** Callback to sort extensions by type */
151 function compare( $a, $b ) {
152 global $wgLang;
153 if( $a['name'] === $b['name'] ) {
154 return 0;
155 } else {
156 return $wgLang->lc( $a['name'] ) > $wgLang->lc( $b['name'] )
158 : -1;
162 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null) {
163 $ret = '<tr><td>';
164 if ( isset( $url ) )
165 $ret .= "[$url ";
166 $ret .= "''$name";
167 if ( isset( $version ) )
168 $ret .= " (version $version)";
169 $ret .= "''";
170 if ( isset( $url ) )
171 $ret .= ']';
172 $ret .= '</td>';
173 $ret .= "<td>$description</td>";
174 $ret .= "<td>" . $this->listToText( (array)$author ) . "</td>";
175 $ret .= '</tr>';
176 return "$ret\n";
180 * @return string
182 function wgHooks() {
183 global $wgHooks;
185 if ( count( $wgHooks ) ) {
186 $myWgHooks = $wgHooks;
187 ksort( $myWgHooks );
189 $ret = "<h2>Hooks</h2>\n"
190 . wfOpenElement('table', array('id' => 'sv-hooks') )
191 . "<tr><th>Hook name</th><th>Subscribed by</th></tr>\n";
193 foreach ($myWgHooks as $hook => $hooks)
194 $ret .= "<tr><td>$hook</td><td>" . $this->listToText( $hooks ) . "</td></tr>\n";
196 $ret .= '</table>';
197 return $ret;
198 } else
199 return '';
202 private function openExtType($text, $name = null) {
203 $opt = array( 'colspan' => 3 );
204 $out = '';
206 if(!$this->firstExtOpened) {
207 // Insert a spacing line
208 $out .= '<tr class="sv-space">' . wfElement( 'td', $opt ) . "</tr>\n";
210 $this->firstExtOpened = false;
212 if($name) { $opt['id'] = "sv-$name"; }
214 $out .= "<tr>" . wfElement( 'th', $opt, $text) . "</tr>\n";
215 return $out;
219 * @static
221 * @return string
223 function IPInfo() {
224 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
225 return "<!-- visited from $ip -->\n" .
226 "<span style='display:none'>visited from $ip</span>";
230 * @param array $list
231 * @return string
233 function listToText( $list ) {
234 $cnt = count( $list );
236 if ( $cnt == 1 ) {
237 // Enforce always returning a string
238 return (string)$this->arrayToString( $list[0] );
239 } elseif ( $cnt == 0 ) {
240 return '';
241 } else {
242 $t = array_slice( $list, 0, $cnt - 1 );
243 $one = array_map( array( &$this, 'arrayToString' ), $t );
244 $two = $this->arrayToString( $list[$cnt - 1] );
246 return implode( ', ', $one ) . " and $two";
251 * @static
253 * @param mixed $list Will convert an array to string if given and return
254 * the paramater unaltered otherwise
255 * @return mixed
257 function arrayToString( $list ) {
258 if( is_object( $list ) ) {
259 $class = get_class( $list );
260 return "($class)";
261 } elseif ( ! is_array( $list ) ) {
262 return $list;
263 } else {
264 $class = get_class( $list[0] );
265 return "($class, {$list[1]})";
270 * Retrieve the revision number of a Subversion working directory.
272 * @param string $dir
273 * @return mixed revision number as int, or false if not a SVN checkout
275 public static function getSvnRevision( $dir ) {
276 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
277 $entries = $dir . '/.svn/entries';
279 if( !file_exists( $entries ) ) {
280 return false;
283 $content = file( $entries );
285 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
286 if( preg_match( '/^<\?xml/', $content[0] ) ) {
287 // subversion is release <= 1.3
288 if( !function_exists( 'simplexml_load_file' ) ) {
289 // We could fall back to expat... YUCK
290 return false;
293 // SimpleXml whines about the xmlns...
294 wfSuppressWarnings();
295 $xml = simplexml_load_file( $entries );
296 wfRestoreWarnings();
298 if( $xml ) {
299 foreach( $xml->entry as $entry ) {
300 if( $xml->entry[0]['name'] == '' ) {
301 // The directory entry should always have a revision marker.
302 if( $entry['revision'] ) {
303 return intval( $entry['revision'] );
308 return false;
309 } else {
310 // subversion is release 1.4
311 return intval( $content[3] );
315 /**#@-*/
318 /**#@-*/