]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/SpecialVersion.php
MediaWiki 1.11.0-scripts
[autoinstallsdev/mediawiki.git] / includes / SpecialVersion.php
1 <?php
2 /**#@+
3  * Give information about the version of MediaWiki, PHP, the DB and extensions
4  *
5  * @addtogroup SpecialPage
6  *
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
10  */
11
12 /**
13  * constructor
14  */
15 function wfSpecialVersion() {
16         $version = new SpecialVersion;
17         $version->execute();
18 }
19
20 class SpecialVersion {
21         private $firstExtOpened = true;
22
23         /**
24          * main()
25          */
26         function execute() {
27                 global $wgOut;
28
29                 $wgOut->addHTML( '<div dir="ltr">' );
30                 $wgOut->addWikiText(
31                         $this->MediaWikiCredits() .
32                         $this->extensionCredits() .
33                         $this->wgHooks()
34                 );
35                 $wgOut->addHTML( $this->IPInfo() );
36                 $wgOut->addHTML( '</div>' );
37         }
38
39         /**#@+
40          * @private
41          */
42
43         /**
44          * Return wiki text showing the licence information and third party
45          * software versions (apache, php, mysql).
46          * @static
47          */
48         function MediaWikiCredits() {
49                 $version = self::getVersion();
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-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.
58
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.
63
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.
68
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]
73
74                 * [http://www.mediawiki.org/ MediaWiki]: $version
75                 * [http://www.php.net/ PHP]: " . phpversion() . " (" . php_sapi_name() . ")
76                 * " . $dbr->getSoftwareLink() . ": " . $dbr->getServerVersion();
77
78                 return str_replace( "\t\t", '', $ret ) . "\n";
79         }
80
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;
86         }
87
88         /** Generate wikitext showing extensions name, URL, author and description */
89         function extensionCredits() {
90                 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunction;
91
92                 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunction ) )
93                         return '';
94
95                 $extensionTypes = array(
96                         'specialpage' => 'Special pages',
97                         'parserhook' => 'Parser hooks',
98                         'variable' => 'Variables',
99                         'other' => 'Other',
100                 );
101                 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
102
103                 $out = "<h2>Extensions</h2>\n";
104                 $out .= wfOpenElement('table', array('id' => 'sv-ext') );
105
106                 foreach ( $extensionTypes as $type => $text ) {
107                         if ( isset ( $wgExtensionCredits[$type] ) && count ( $wgExtensionCredits[$type] ) ) {
108                                 $out .= $this->openExtType( $text );
109
110                                 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
111
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'] : ''
119                                         );
120                                 }
121                         }
122                 }
123
124                 if ( count( $wgExtensionFunctions ) ) {
125                         $out .= $this->openExtType('Extension functions');
126                         $out .= '<tr><td colspan="3">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
127                 }
128
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";
134                 }
135
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";
139                 }
140
141                 if ( count( $wgSkinExtensionFunction ) ) {
142                         $out .= $this->openExtType('Skin extension functions');
143                         $out .= '<tr><td colspan="3">' . $this->listToText( $wgSkinExtensionFunction ) . "</td></tr>\n";
144                 }
145                 $out .= wfCloseElement( 'table' );
146                 return $out;
147         }
148
149         /** Callback to sort extensions by type */
150         function compare( $a, $b ) {
151                 global $wgLang;
152                 if( $a['name'] === $b['name'] ) {
153                         return 0;
154                 } else {
155                         return $wgLang->lc( $a['name'] ) > $wgLang->lc( $b['name'] )
156                                 ? 1
157                                 : -1;
158                 }
159         }
160
161         function formatCredits( $name, $version = null, $author = null, $url = null, $description = null) {
162                 $ret = '<tr><td>';
163                 if ( isset( $url ) )
164                         $ret .= "[$url ";
165                 $ret .= "''$name";
166                 if ( isset( $version ) )
167                         $ret .= " (version $version)";
168                 $ret .= "''";
169                 if ( isset( $url ) )
170                         $ret .= ']';
171                 $ret .= '</td>';
172                 $ret .= "<td>$description</td>";
173                 $ret .= "<td>" . $this->listToText( (array)$author ) . "</td>";
174                 $ret .= '</tr>';
175                 return "$ret\n";
176         }
177
178         /**
179          * @return string
180          */
181         function wgHooks() {
182                 global $wgHooks;
183
184                 if ( count( $wgHooks ) ) {
185                         $myWgHooks = $wgHooks;
186                         ksort( $myWgHooks );
187
188                         $ret = "<h2>Hooks</h2>\n"
189                                 . wfOpenElement('table', array('id' => 'sv-hooks') )
190                                 . "<tr><th>Hook name</th><th>Subscribed by</th></tr>\n";
191
192                         foreach ($myWgHooks as $hook => $hooks)
193                                 $ret .= "<tr><td>$hook</td><td>" . $this->listToText( $hooks ) . "</td></tr>\n";
194
195                         $ret .= '</table>';
196                         return $ret;
197                 } else
198                         return '';
199         }
200
201         private function openExtType($text, $name = null) {
202                 $opt = array( 'colspan' => 3 );
203                 $out = '';
204
205                 if(!$this->firstExtOpened) {
206                         // Insert a spacing line
207                         $out .= '<tr class="sv-space">' . wfElement( 'td', $opt ) . "</tr>\n";
208                 }
209                 $this->firstExtOpened = false;
210
211                 if($name) { $opt['id'] = "sv-$name"; }
212
213                 $out .= "<tr>" . wfElement( 'th', $opt, $text) . "</tr>\n";
214                 return $out;
215         }
216
217         /**
218          * @static
219          *
220          * @return string
221          */
222         function IPInfo() {
223                 $ip =  str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
224                 return "<!-- visited from $ip -->\n" .
225                         "<span style='display:none'>visited from $ip</span>";
226         }
227
228         /**
229          * @param array $list
230          * @return string
231          */
232         function listToText( $list ) {
233                 $cnt = count( $list );
234
235             if ( $cnt == 1 ) {
236                         // Enforce always returning a string
237                         return (string)$this->arrayToString( $list[0] );
238             } elseif ( $cnt == 0 ) {
239                         return '';
240                 } else {
241                         $t = array_slice( $list, 0, $cnt - 1 );
242                         $one = array_map( array( &$this, 'arrayToString' ), $t );
243                         $two = $this->arrayToString( $list[$cnt - 1] );
244
245                         return implode( ', ', $one ) . " and $two";
246             }
247         }
248
249         /**
250          * @static
251          *
252          * @param mixed $list Will convert an array to string if given and return
253          *                    the paramater unaltered otherwise
254          * @return mixed
255          */
256         function arrayToString( $list ) {
257                 if( is_object( $list ) ) {
258                         $class = get_class( $list );
259                         return "($class)";
260                 } elseif ( ! is_array( $list ) ) {
261                         return $list;
262                 } else {
263                         $class = get_class( $list[0] );
264                         return "($class, {$list[1]})";
265                 }
266         }
267
268         /**
269          * Retrieve the revision number of a Subversion working directory.
270          *
271          * @param string $dir
272          * @return mixed revision number as int, or false if not a SVN checkout
273          */
274         public static function getSvnRevision( $dir ) {
275                 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
276                 $entries = $dir . '/.svn/entries';
277
278                 if( !file_exists( $entries ) ) {
279                         return false;
280                 }
281
282                 $content = file( $entries );
283
284                 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
285                 if( preg_match( '/^<\?xml/', $content[0] ) ) {
286                         // subversion is release <= 1.3
287                         if( !function_exists( 'simplexml_load_file' ) ) {
288                                 // We could fall back to expat... YUCK
289                                 return false;
290                         }
291
292                         // SimpleXml whines about the xmlns...
293                         wfSuppressWarnings();
294                         $xml = simplexml_load_file( $entries );
295                         wfRestoreWarnings();
296
297                         if( $xml ) {
298                                 foreach( $xml->entry as $entry ) {
299                                         if( $xml->entry[0]['name'] == '' ) {
300                                                 // The directory entry should always have a revision marker.
301                                                 if( $entry['revision'] ) {
302                                                         return intval( $entry['revision'] );
303                                                 }
304                                         }
305                                 }
306                         }
307                         return false;
308                 } else {
309                         // subversion is release 1.4
310                         return intval( $content[3] );
311                 }
312         }
313
314         /**#@-*/
315 }
316
317 /**#@-*/
318