Fix regression in even sizing of diff columns; forgot to restore a couple bits I...
[mediawiki.git] / includes / SpecialVersion.php
blob6de2da11909136a38f3765809f0ff2749a33316e
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 'other' => 'Other',
101 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
103 $out = "<h2>Extensions</h2>\n";
104 $out .= wfOpenElement('table', array('id' => 'sv-ext') );
106 foreach ( $extensionTypes as $type => $text ) {
107 if ( isset ( $wgExtensionCredits[$type] ) && count ( $wgExtensionCredits[$type] ) ) {
108 $out .= $this->openExtType( $text );
110 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
112 foreach ( $wgExtensionCredits[$type] as $extension ) {
113 $out .= $this->formatCredits(
114 isset ( $extension['name'] ) ? $extension['name'] : '',
115 isset ( $extension['version'] ) ? $extension['version'] : null,
116 isset ( $extension['author'] ) ? $extension['author'] : '',
117 isset ( $extension['url'] ) ? $extension['url'] : null,
118 isset ( $extension['description'] ) ? $extension['description'] : ''
124 if ( count( $wgExtensionFunctions ) ) {
125 $out .= $this->openExtType('Extension functions');
126 $out .= '<tr><td colspan="3">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
129 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
130 for ( $i = 0; $i < $cnt; ++$i )
131 $tags[$i] = "&lt;{$tags[$i]}&gt;";
132 $out .= $this->openExtType('Parser extension tags');
133 $out .= '<tr><td colspan="3">' . $this->listToText( $tags ). "</td></tr>\n";
136 if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
137 $out .= $this->openExtType('Parser function hooks');
138 $out .= '<tr><td colspan="3">' . $this->listToText( $fhooks ) . "</td></tr>\n";
141 if ( count( $wgSkinExtensionFunction ) ) {
142 $out .= $this->openExtType('Skin extension functions');
143 $out .= '<tr><td colspan="3">' . $this->listToText( $wgSkinExtensionFunction ) . "</td></tr>\n";
145 $out .= wfCloseElement( 'table' );
146 return $out;
149 /** Callback to sort extensions by type */
150 function compare( $a, $b ) {
151 if ( $a['name'] === $b['name'] )
152 return 0;
153 else
154 return Language::lc( $a['name'] ) > Language::lc( $b['name'] ) ? 1 : -1;
157 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null) {
158 $ret = '<tr><td>';
159 if ( isset( $url ) )
160 $ret .= "[$url ";
161 $ret .= "''$name";
162 if ( isset( $version ) )
163 $ret .= " (version $version)";
164 $ret .= "''";
165 if ( isset( $url ) )
166 $ret .= ']';
167 $ret .= '</td>';
168 $ret .= "<td>$description</td>";
169 $ret .= "<td>" . $this->listToText( (array)$author ) . "</td>";
170 $ret .= '</tr>';
171 return "$ret\n";
175 * @return string
177 function wgHooks() {
178 global $wgHooks;
180 if ( count( $wgHooks ) ) {
181 $myWgHooks = $wgHooks;
182 ksort( $myWgHooks );
184 $ret = "<h2>Hooks</h2>\n"
185 . wfOpenElement('table', array('id' => 'sv-hooks') )
186 . "<tr><th>Hook name</th><th>Subscribed by</th></tr>\n";
188 foreach ($myWgHooks as $hook => $hooks)
189 $ret .= "<tr><td>$hook</td><td>" . $this->listToText( $hooks ) . "</td></tr>\n";
191 $ret .= '</table>';
192 return $ret;
193 } else
194 return '';
197 private function openExtType($text, $name = null) {
198 $opt = array( 'colspan' => 3 );
199 $out = '';
201 if(!$this->firstExtOpened) {
202 // Insert a spacing line
203 $out .= '<tr class="sv-space">' . wfElement( 'td', $opt ) . "</tr>\n";
205 $this->firstExtOpened = false;
207 if($name) { $opt['id'] = "sv-$name"; }
209 $out .= "<tr>" . wfElement( 'th', $opt, $text) . "</tr>\n";
210 return $out;
214 * @static
216 * @return string
218 function IPInfo() {
219 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
220 return "<!-- visited from $ip -->\n" .
221 "<span style='display:none'>visited from $ip</span>";
225 * @param array $list
226 * @return string
228 function listToText( $list ) {
229 $cnt = count( $list );
231 if ( $cnt == 1 ) {
232 // Enforce always returning a string
233 return (string)$this->arrayToString( $list[0] );
234 } elseif ( $cnt == 0 ) {
235 return '';
236 } else {
237 $t = array_slice( $list, 0, $cnt - 1 );
238 $one = array_map( array( &$this, 'arrayToString' ), $t );
239 $two = $this->arrayToString( $list[$cnt - 1] );
241 return implode( ', ', $one ) . " and $two";
246 * @static
248 * @param mixed $list Will convert an array to string if given and return
249 * the paramater unaltered otherwise
250 * @return mixed
252 function arrayToString( $list ) {
253 if ( ! is_array( $list ) ) {
254 return $list;
255 } else {
256 $class = get_class( $list[0] );
257 return "($class, {$list[1]})";
262 * Retrieve the revision number of a Subversion working directory.
264 * @param string $dir
265 * @return mixed revision number as int, or false if not a SVN checkout
267 public static function getSvnRevision( $dir ) {
268 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
269 $entries = $dir . '/.svn/entries';
271 if( !file_exists( $entries ) ) {
272 return false;
275 $content = file( $entries );
277 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
278 if( preg_match( '/^<\?xml/', $content[0] ) ) {
279 // subversion is release <= 1.3
280 if( !function_exists( 'simplexml_load_file' ) ) {
281 // We could fall back to expat... YUCK
282 return false;
285 // SimpleXml whines about the xmlns...
286 wfSuppressWarnings();
287 $xml = simplexml_load_file( $entries );
288 wfRestoreWarnings();
290 if( $xml ) {
291 foreach( $xml->entry as $entry ) {
292 if( $xml->entry[0]['name'] == '' ) {
293 // The directory entry should always have a revision marker.
294 if( $entry['revision'] ) {
295 return intval( $entry['revision'] );
300 return false;
301 } else {
302 // subversion is release 1.4
303 return intval( $content[3] );
307 /**#@-*/
310 /**#@-*/