SpecialVersion.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <?php
  2. /**
  3. * Give information about the version of MediaWiki, PHP, the DB and extensions
  4. *
  5. * @ingroup 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. class SpecialVersion extends SpecialPage {
  12. private $firstExtOpened = true;
  13. function __construct(){
  14. parent::__construct( 'Version' );
  15. }
  16. /**
  17. * main()
  18. */
  19. function execute( $par ) {
  20. global $wgOut, $wgMessageCache, $wgSpecialVersionShowHooks;
  21. $wgMessageCache->loadAllMessages();
  22. $this->setHeaders();
  23. $this->outputHeader();
  24. $wgOut->addHTML( '<div dir="ltr">' );
  25. $text =
  26. $this->MediaWikiCredits() .
  27. $this->softwareInformation() .
  28. $this->extensionCredits();
  29. if ( $wgSpecialVersionShowHooks ) {
  30. $text .= $this->wgHooks();
  31. }
  32. $wgOut->addWikiText( $text );
  33. $wgOut->addHTML( $this->IPInfo() );
  34. $wgOut->addHTML( '</div>' );
  35. }
  36. /**#@+
  37. * @private
  38. */
  39. /**
  40. * @return wiki text showing the license information
  41. */
  42. static function MediaWikiCredits() {
  43. $ret = Xml::element( 'h2', array( 'id' => 'mw-version-license' ), wfMsg( 'version-license' ) ) .
  44. "__NOTOC__
  45. This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
  46. copyright (C) 2001-2009 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
  47. Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
  48. Niklas Laxström, Domas Mituzas, Rob Church, Yuri Astrakhan, Aryeh Gregor,
  49. Aaron Schulz and others.
  50. MediaWiki is free software; you can redistribute it and/or modify
  51. it under the terms of the GNU General Public License as published by
  52. the Free Software Foundation; either version 2 of the License, or
  53. (at your option) any later version.
  54. MediaWiki is distributed in the hope that it will be useful,
  55. but WITHOUT ANY WARRANTY; without even the implied warranty of
  56. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  57. GNU General Public License for more details.
  58. You should have received [{{SERVER}}{{SCRIPTPATH}}/COPYING a copy of the GNU General Public License]
  59. along with this program; if not, write to the Free Software
  60. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  61. or [http://www.gnu.org/licenses/old-licenses/gpl-2.0.html read it online].
  62. ";
  63. return str_replace( "\t\t", '', $ret ) . "\n";
  64. }
  65. /**
  66. * @return wiki text showing the third party software versions (apache, php, mysql).
  67. */
  68. static function softwareInformation() {
  69. $dbr = wfGetDB( DB_SLAVE );
  70. return Xml::element( 'h2', array( 'id' => 'mw-version-software' ), wfMsg( 'version-software' ) ) .
  71. Xml::openElement( 'table', array( 'id' => 'sv-software' ) ) .
  72. "<tr>
  73. <th>" . wfMsg( 'version-software-product' ) . "</th>
  74. <th>" . wfMsg( 'version-software-version' ) . "</th>
  75. </tr>\n
  76. <tr>
  77. <td>[http://www.mediawiki.org/ MediaWiki]</td>
  78. <td>" . self::getVersionLinked() . "</td>
  79. </tr>\n
  80. <tr>
  81. <td>[http://www.php.net/ PHP]</td>
  82. <td>" . phpversion() . " (" . php_sapi_name() . ")</td>
  83. </tr>\n
  84. <tr>
  85. <td>" . $dbr->getSoftwareLink() . "</td>
  86. <td>" . $dbr->getServerVersion() . "</td>
  87. </tr>\n" .
  88. Xml::closeElement( 'table' );
  89. }
  90. /**
  91. * Return a string of the MediaWiki version with SVN revision if available
  92. *
  93. * @return mixed
  94. */
  95. public static function getVersion() {
  96. global $wgVersion, $IP;
  97. wfProfileIn( __METHOD__ );
  98. $svn = self::getSvnRevision( $IP );
  99. $version = $svn ? "$wgVersion (r$svn)" : $wgVersion;
  100. wfProfileOut( __METHOD__ );
  101. return $version;
  102. }
  103. /**
  104. * Return a string of the MediaWiki version with a link to SVN revision if
  105. * available
  106. *
  107. * @return mixed
  108. */
  109. public static function getVersionLinked() {
  110. global $wgVersion, $IP;
  111. wfProfileIn( __METHOD__ );
  112. $svn = self::getSvnRevision( $IP );
  113. $viewvc = 'http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/?pathrev=';
  114. $version = $svn ? "$wgVersion ([{$viewvc}{$svn} r$svn])" : $wgVersion;
  115. wfProfileOut( __METHOD__ );
  116. return $version;
  117. }
  118. /** Generate wikitext showing extensions name, URL, author and description */
  119. function extensionCredits() {
  120. global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunctions;
  121. if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunctions ) )
  122. return '';
  123. $extensionTypes = array(
  124. 'specialpage' => wfMsg( 'version-specialpages' ),
  125. 'parserhook' => wfMsg( 'version-parserhooks' ),
  126. 'variable' => wfMsg( 'version-variables' ),
  127. 'media' => wfMsg( 'version-mediahandlers' ),
  128. 'other' => wfMsg( 'version-other' ),
  129. );
  130. wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
  131. $out = Xml::element( 'h2', array( 'id' => 'mw-version-ext' ), wfMsg( 'version-extensions' ) ) .
  132. Xml::openElement( 'table', array( 'id' => 'sv-ext' ) );
  133. foreach ( $extensionTypes as $type => $text ) {
  134. if ( isset ( $wgExtensionCredits[$type] ) && count ( $wgExtensionCredits[$type] ) ) {
  135. $out .= $this->openExtType( $text );
  136. usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
  137. foreach ( $wgExtensionCredits[$type] as $extension ) {
  138. $version = null;
  139. $subVersion = '';
  140. if ( isset( $extension['version'] ) ) {
  141. $version = $extension['version'];
  142. }
  143. if ( isset( $extension['svn-revision'] ) &&
  144. preg_match( '/\$(?:Rev|LastChangedRevision|Revision): *(\d+)/',
  145. $extension['svn-revision'], $m ) ) {
  146. $subVersion = 'r' . $m[1];
  147. }
  148. if( $version && $subVersion ) {
  149. $version = $version . ' [' . $subVersion . ']';
  150. } elseif ( !$version && $subVersion ) {
  151. $version = $subVersion;
  152. }
  153. $out .= $this->formatCredits(
  154. isset ( $extension['name'] ) ? $extension['name'] : '',
  155. $version,
  156. isset ( $extension['author'] ) ? $extension['author'] : '',
  157. isset ( $extension['url'] ) ? $extension['url'] : null,
  158. isset ( $extension['description'] ) ? $extension['description'] : '',
  159. isset ( $extension['descriptionmsg'] ) ? $extension['descriptionmsg'] : ''
  160. );
  161. }
  162. }
  163. }
  164. if ( count( $wgExtensionFunctions ) ) {
  165. $out .= $this->openExtType( wfMsg( 'version-extension-functions' ) );
  166. $out .= '<tr><td colspan="3">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
  167. }
  168. if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
  169. for ( $i = 0; $i < $cnt; ++$i )
  170. $tags[$i] = "&lt;{$tags[$i]}&gt;";
  171. $out .= $this->openExtType( wfMsg( 'version-parser-extensiontags' ) );
  172. $out .= '<tr><td colspan="3">' . $this->listToText( $tags ). "</td></tr>\n";
  173. }
  174. if( $cnt = count( $fhooks = $wgParser->getFunctionHooks() ) ) {
  175. $out .= $this->openExtType( wfMsg( 'version-parser-function-hooks' ) );
  176. $out .= '<tr><td colspan="3">' . $this->listToText( $fhooks ) . "</td></tr>\n";
  177. }
  178. if ( count( $wgSkinExtensionFunctions ) ) {
  179. $out .= $this->openExtType( wfMsg( 'version-skin-extension-functions' ) );
  180. $out .= '<tr><td colspan="3">' . $this->listToText( $wgSkinExtensionFunctions ) . "</td></tr>\n";
  181. }
  182. $out .= Xml::closeElement( 'table' );
  183. return $out;
  184. }
  185. /** Callback to sort extensions by type */
  186. function compare( $a, $b ) {
  187. global $wgLang;
  188. if( $a['name'] === $b['name'] ) {
  189. return 0;
  190. } else {
  191. return $wgLang->lc( $a['name'] ) > $wgLang->lc( $b['name'] )
  192. ? 1
  193. : -1;
  194. }
  195. }
  196. function formatCredits( $name, $version = null, $author = null, $url = null, $description = null, $descriptionMsg = null ) {
  197. $extension = isset( $url ) ? "[$url $name]" : $name;
  198. $version = isset( $version ) ? "(" . wfMsg( 'version-version' ) . " $version)" : '';
  199. # Look for a localized description
  200. if( isset( $descriptionMsg ) ) {
  201. $msg = wfMsg( $descriptionMsg );
  202. if ( !wfEmptyMsg( $descriptionMsg, $msg ) && $msg != '' ) {
  203. $description = $msg;
  204. }
  205. }
  206. return "<tr>
  207. <td><em>$extension $version</em></td>
  208. <td>$description</td>
  209. <td>" . $this->listToText( (array)$author ) . "</td>
  210. </tr>\n";
  211. }
  212. /**
  213. * @return string
  214. */
  215. function wgHooks() {
  216. global $wgHooks;
  217. if ( count( $wgHooks ) ) {
  218. $myWgHooks = $wgHooks;
  219. ksort( $myWgHooks );
  220. $ret = Xml::element( 'h2', array( 'id' => 'mw-version-hooks' ), wfMsg( 'version-hooks' ) ) .
  221. Xml::openElement( 'table', array( 'id' => 'sv-hooks' ) ) .
  222. "<tr>
  223. <th>" . wfMsg( 'version-hook-name' ) . "</th>
  224. <th>" . wfMsg( 'version-hook-subscribedby' ) . "</th>
  225. </tr>\n";
  226. foreach ( $myWgHooks as $hook => $hooks )
  227. $ret .= "<tr>
  228. <td>$hook</td>
  229. <td>" . $this->listToText( $hooks ) . "</td>
  230. </tr>\n";
  231. $ret .= Xml::closeElement( 'table' );
  232. return $ret;
  233. } else
  234. return '';
  235. }
  236. private function openExtType($text, $name = null) {
  237. $opt = array( 'colspan' => 3 );
  238. $out = '';
  239. if(!$this->firstExtOpened) {
  240. // Insert a spacing line
  241. $out .= '<tr class="sv-space">' . Xml::element( 'td', $opt ) . "</tr>\n";
  242. }
  243. $this->firstExtOpened = false;
  244. if($name) { $opt['id'] = "sv-$name"; }
  245. $out .= "<tr>" . Xml::element( 'th', $opt, $text) . "</tr>\n";
  246. return $out;
  247. }
  248. /**
  249. * @return string
  250. */
  251. function IPInfo() {
  252. $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
  253. return "<!-- visited from $ip -->\n" .
  254. "<span style='display:none'>visited from $ip</span>";
  255. }
  256. /**
  257. * @param array $list
  258. * @return string
  259. */
  260. function listToText( $list ) {
  261. $cnt = count( $list );
  262. if ( $cnt == 1 ) {
  263. // Enforce always returning a string
  264. return (string)self::arrayToString( $list[0] );
  265. } elseif ( $cnt == 0 ) {
  266. return '';
  267. } else {
  268. global $wgLang;
  269. sort( $list );
  270. return $wgLang->listToText( array_map( array( __CLASS__, 'arrayToString' ), $list ) );
  271. }
  272. }
  273. /**
  274. * @param mixed $list Will convert an array to string if given and return
  275. * the paramater unaltered otherwise
  276. * @return mixed
  277. */
  278. static function arrayToString( $list ) {
  279. if( is_array( $list ) && count( $list ) == 1 )
  280. $list = $list[0];
  281. if( is_object( $list ) ) {
  282. $class = get_class( $list );
  283. return "($class)";
  284. } elseif ( !is_array( $list ) ) {
  285. return $list;
  286. } else {
  287. if( is_object( $list[0] ) )
  288. $class = get_class( $list[0] );
  289. else
  290. $class = $list[0];
  291. return "($class, {$list[1]})";
  292. }
  293. }
  294. /**
  295. * Retrieve the revision number of a Subversion working directory.
  296. *
  297. * @param string $dir
  298. * @return mixed revision number as int, or false if not a SVN checkout
  299. */
  300. public static function getSvnRevision( $dir ) {
  301. // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
  302. $entries = $dir . '/.svn/entries';
  303. if( !file_exists( $entries ) ) {
  304. return false;
  305. }
  306. $content = file( $entries );
  307. // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
  308. if( preg_match( '/^<\?xml/', $content[0] ) ) {
  309. // subversion is release <= 1.3
  310. if( !function_exists( 'simplexml_load_file' ) ) {
  311. // We could fall back to expat... YUCK
  312. return false;
  313. }
  314. // SimpleXml whines about the xmlns...
  315. wfSuppressWarnings();
  316. $xml = simplexml_load_file( $entries );
  317. wfRestoreWarnings();
  318. if( $xml ) {
  319. foreach( $xml->entry as $entry ) {
  320. if( $xml->entry[0]['name'] == '' ) {
  321. // The directory entry should always have a revision marker.
  322. if( $entry['revision'] ) {
  323. return intval( $entry['revision'] );
  324. }
  325. }
  326. }
  327. }
  328. return false;
  329. } else {
  330. // subversion is release 1.4
  331. return intval( $content[3] );
  332. }
  333. }
  334. /**#@-*/
  335. }