Indicate the actual version of HHVM in use
[mediawiki.git] / includes / specials / SpecialVersion.php
blob10cc5820f7533837a2a2f7c7e7ef5610fee7e00e
1 <?php
2 /**
3 * Implements Special:Version
5 * Copyright © 2005 Ævar Arnfjörð Bjarmason
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
22 * @file
23 * @ingroup SpecialPage
26 /**
27 * Give information about the version of MediaWiki, PHP, the DB and extensions
29 * @ingroup SpecialPage
31 class SpecialVersion extends SpecialPage {
32 protected $firstExtOpened = false;
34 /**
35 * Stores the current rev id/SHA hash of MediaWiki core
37 protected $coreId = '';
39 protected static $extensionTypes = false;
41 protected static $viewvcUrls = array(
42 'svn+ssh://svn.wikimedia.org/svnroot/mediawiki' => 'http://svn.wikimedia.org/viewvc/mediawiki',
43 'http://svn.wikimedia.org/svnroot/mediawiki' => 'http://svn.wikimedia.org/viewvc/mediawiki',
44 'https://svn.wikimedia.org/svnroot/mediawiki' => 'https://svn.wikimedia.org/viewvc/mediawiki',
47 public function __construct() {
48 parent::__construct( 'Version' );
51 /**
52 * main()
54 public function execute( $par ) {
55 global $IP, $wgExtensionCredits;
57 $this->setHeaders();
58 $this->outputHeader();
59 $out = $this->getOutput();
60 $out->allowClickjacking();
62 // Explode the sub page information into useful bits
63 $parts = explode( '/', (string)$par );
64 $extNode = null;
65 if ( isset( $parts[1] ) ) {
66 $extName = str_replace( '_', ' ', $parts[1] );
67 // Find it!
68 foreach ( $wgExtensionCredits as $group => $extensions ) {
69 foreach ( $extensions as $ext ) {
70 if ( isset( $ext['name'] ) && ( $ext['name'] === $extName ) ) {
71 $extNode = &$ext;
72 break 2;
76 if ( !$extNode ) {
77 $out->setStatusCode( 404 );
79 } else {
80 $extName = 'MediaWiki';
83 // Now figure out what to do
84 switch ( strtolower( $parts[0] ) ) {
85 case 'credits':
86 $wikiText = '{{int:version-credits-not-found}}';
87 if ( $extName === 'MediaWiki' ) {
88 $wikiText = file_get_contents( $IP . '/CREDITS' );
89 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
90 $file = $this->getExtAuthorsFileName( dirname( $extNode['path'] ) );
91 if ( $file ) {
92 $wikiText = file_get_contents( $file );
93 if ( substr( $file, -4 ) === '.txt' ) {
94 $wikiText = Html::element( 'pre', array(), $wikiText );
99 $out->setPageTitle( $this->msg( 'version-credits-title', $extName ) );
100 $out->addWikiText( $wikiText );
101 break;
103 case 'license':
104 $wikiText = '{{int:version-license-not-found}}';
105 if ( $extName === 'MediaWiki' ) {
106 $wikiText = file_get_contents( $IP . '/COPYING' );
107 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
108 $file = $this->getExtLicenseFileName( dirname( $extNode['path'] ) );
109 if ( $file ) {
110 $wikiText = file_get_contents( $file );
111 if ( !isset( $extNode['license-name'] ) ) {
112 // If the developer did not explicitly set license-name they probably
113 // are unaware that we're now sucking this file in and thus it's probably
114 // not wikitext friendly.
115 $wikiText = "<pre>$wikiText</pre>";
120 $out->setPageTitle( $this->msg( 'version-license-title', $extName ) );
121 $out->addWikiText( $wikiText );
122 break;
124 default:
125 $out->addModules( 'mediawiki.special.version' );
126 $out->addWikiText(
127 $this->getMediaWikiCredits() .
128 $this->softwareInformation() .
129 $this->getEntryPointInfo()
131 $out->addHtml(
132 $this->getSkinCredits() .
133 $this->getExtensionCredits() .
134 $this->getParserTags() .
135 $this->getParserFunctionHooks()
137 $out->addWikiText( $this->getWgHooks() );
138 $out->addHTML( $this->IPInfo() );
140 break;
145 * Returns wiki text showing the license information.
147 * @return string
149 private static function getMediaWikiCredits() {
150 $ret = Xml::element(
151 'h2',
152 array( 'id' => 'mw-version-license' ),
153 wfMessage( 'version-license' )->text()
156 // This text is always left-to-right.
157 $ret .= '<div class="plainlinks">';
158 $ret .= "__NOTOC__
159 " . self::getCopyrightAndAuthorList() . "\n
160 " . wfMessage( 'version-license-info' )->text();
161 $ret .= '</div>';
163 return str_replace( "\t\t", '', $ret ) . "\n";
167 * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
169 * @return string
171 public static function getCopyrightAndAuthorList() {
172 global $wgLang;
174 if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
175 $othersLink = '[//www.mediawiki.org/wiki/Special:Version/Credits ' .
176 wfMessage( 'version-poweredby-others' )->text() . ']';
177 } else {
178 $othersLink = '[[Special:Version/Credits|' .
179 wfMessage( 'version-poweredby-others' )->text() . ']]';
182 $translatorsLink = '[//translatewiki.net/wiki/Translating:MediaWiki/Credits ' .
183 wfMessage( 'version-poweredby-translators' )->text() . ']';
185 $authorList = array(
186 'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
187 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
188 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
189 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
190 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
191 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
192 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
193 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', $othersLink,
194 $translatorsLink
197 return wfMessage( 'version-poweredby-credits', MWTimestamp::getLocalInstance()->format( 'Y' ),
198 $wgLang->listToText( $authorList ) )->text();
202 * Returns wiki text showing the third party software versions (apache, php, mysql).
204 * @return string
206 static function softwareInformation() {
207 $dbr = wfGetDB( DB_SLAVE );
209 // Put the software in an array of form 'name' => 'version'. All messages should
210 // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
211 // wikimarkup can be used.
212 $software = array();
213 $software['[https://www.mediawiki.org/ MediaWiki]'] = self::getVersionLinked();
214 if ( wfIsHHVM() ) {
215 $software['[http://hhvm.com/ HHVM]'] = HHVM_VERSION . " (" . PHP_SAPI . ")";
216 } else {
217 $software['[https://php.net/ PHP]'] = PHP_VERSION . " (" . PHP_SAPI . ")";
219 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
221 // Allow a hook to add/remove items.
222 wfRunHooks( 'SoftwareInfo', array( &$software ) );
224 $out = Xml::element(
225 'h2',
226 array( 'id' => 'mw-version-software' ),
227 wfMessage( 'version-software' )->text()
229 Xml::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ) ) .
230 "<tr>
231 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
232 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
233 </tr>\n";
235 foreach ( $software as $name => $version ) {
236 $out .= "<tr>
237 <td>" . $name . "</td>
238 <td dir=\"ltr\">" . $version . "</td>
239 </tr>\n";
242 return $out . Xml::closeElement( 'table' );
246 * Return a string of the MediaWiki version with SVN revision if available.
248 * @param string $flags
249 * @return mixed
251 public static function getVersion( $flags = '' ) {
252 global $wgVersion, $IP;
253 wfProfileIn( __METHOD__ );
255 $gitInfo = self::getGitHeadSha1( $IP );
256 $svnInfo = self::getSvnInfo( $IP );
257 if ( !$svnInfo && !$gitInfo ) {
258 $version = $wgVersion;
259 } elseif ( $gitInfo && $flags === 'nodb' ) {
260 $shortSha1 = substr( $gitInfo, 0, 7 );
261 $version = "$wgVersion ($shortSha1)";
262 } elseif ( $gitInfo ) {
263 $shortSha1 = substr( $gitInfo, 0, 7 );
264 $shortSha1 = wfMessage( 'parentheses' )->params( $shortSha1 )->escaped();
265 $version = "$wgVersion $shortSha1";
266 } elseif ( $flags === 'nodb' ) {
267 $version = "$wgVersion (r{$svnInfo['checkout-rev']})";
268 } else {
269 $version = $wgVersion . ' ' .
270 wfMessage(
271 'version-svn-revision',
272 isset( $info['directory-rev'] ) ? $info['directory-rev'] : '',
273 $info['checkout-rev']
274 )->text();
277 wfProfileOut( __METHOD__ );
279 return $version;
283 * Return a wikitext-formatted string of the MediaWiki version with a link to
284 * the SVN revision or the git SHA1 of head if available.
285 * Git is prefered over Svn
286 * The fallback is just $wgVersion
288 * @return mixed
290 public static function getVersionLinked() {
291 global $wgVersion;
292 wfProfileIn( __METHOD__ );
294 $gitVersion = self::getVersionLinkedGit();
295 if ( $gitVersion ) {
296 $v = $gitVersion;
297 } else {
298 $svnVersion = self::getVersionLinkedSvn();
299 if ( $svnVersion ) {
300 $v = $svnVersion;
301 } else {
302 $v = $wgVersion; // fallback
306 wfProfileOut( __METHOD__ );
308 return $v;
312 * @return string Global wgVersion + a link to subversion revision of svn BASE
314 private static function getVersionLinkedSvn() {
315 global $IP;
317 $info = self::getSvnInfo( $IP );
318 if ( !isset( $info['checkout-rev'] ) ) {
319 return false;
322 $linkText = wfMessage(
323 'version-svn-revision',
324 isset( $info['directory-rev'] ) ? $info['directory-rev'] : '',
325 $info['checkout-rev']
326 )->text();
328 if ( isset( $info['viewvc-url'] ) ) {
329 $version = "[{$info['viewvc-url']} $linkText]";
330 } else {
331 $version = $linkText;
334 return self::getwgVersionLinked() . " $version";
338 * @return string
340 private static function getwgVersionLinked() {
341 global $wgVersion;
342 $versionUrl = "";
343 if ( wfRunHooks( 'SpecialVersionVersionUrl', array( $wgVersion, &$versionUrl ) ) ) {
344 $versionParts = array();
345 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
346 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
349 return "[$versionUrl $wgVersion]";
353 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
354 * @return bool|string Global wgVersion + HEAD sha1 stripped to the first 7 chars
355 * with link and date, or false on failure
357 private static function getVersionLinkedGit() {
358 global $IP, $wgLang;
360 $gitInfo = new GitInfo( $IP );
361 $headSHA1 = $gitInfo->getHeadSHA1();
362 if ( !$headSHA1 ) {
363 return false;
366 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
368 $gitHeadUrl = $gitInfo->getHeadViewUrl();
369 if ( $gitHeadUrl !== false ) {
370 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
373 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
374 if ( $gitHeadCommitDate ) {
375 $shortSHA1 .= Html::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true );
378 return self::getwgVersionLinked() . " $shortSHA1";
382 * Returns an array with the base extension types.
383 * Type is stored as array key, the message as array value.
385 * TODO: ideally this would return all extension types.
387 * @since 1.17
389 * @return array
391 public static function getExtensionTypes() {
392 if ( self::$extensionTypes === false ) {
393 self::$extensionTypes = array(
394 'specialpage' => wfMessage( 'version-specialpages' )->text(),
395 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
396 'variable' => wfMessage( 'version-variables' )->text(),
397 'media' => wfMessage( 'version-mediahandlers' )->text(),
398 'antispam' => wfMessage( 'version-antispam' )->text(),
399 'skin' => wfMessage( 'version-skins' )->text(),
400 'api' => wfMessage( 'version-api' )->text(),
401 'other' => wfMessage( 'version-other' )->text(),
404 wfRunHooks( 'ExtensionTypes', array( &self::$extensionTypes ) );
407 return self::$extensionTypes;
411 * Returns the internationalized name for an extension type.
413 * @since 1.17
415 * @param string $type
417 * @return string
419 public static function getExtensionTypeName( $type ) {
420 $types = self::getExtensionTypes();
422 return isset( $types[$type] ) ? $types[$type] : $types['other'];
426 * Generate wikitext showing the name, URL, author and description of each extension.
428 * @return string Wikitext
430 function getExtensionCredits() {
431 global $wgExtensionCredits;
433 if ( !count( $wgExtensionCredits ) ) {
434 return '';
437 $extensionTypes = self::getExtensionTypes();
439 $out = Xml::element(
440 'h2',
441 array( 'id' => 'mw-version-ext' ),
442 $this->msg( 'version-extensions' )->text()
444 Xml::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ) );
446 // Make sure the 'other' type is set to an array.
447 if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
448 $wgExtensionCredits['other'] = array();
451 // Find all extensions that do not have a valid type and give them the type 'other'.
452 foreach ( $wgExtensionCredits as $type => $extensions ) {
453 if ( !array_key_exists( $type, $extensionTypes ) ) {
454 $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
458 $this->firstExtOpened = false;
459 // Loop through the extension categories to display their extensions in the list.
460 foreach ( $extensionTypes as $type => $message ) {
461 // Skins have a separate section
462 if ( $type !== 'other' && $type !== 'skin' ) {
463 $out .= $this->getExtensionCategory( $type, $message );
467 // We want the 'other' type to be last in the list.
468 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
470 $out .= Xml::closeElement( 'table' );
472 return $out;
476 * Generate wikitext showing the name, URL, author and description of each skin.
478 * @return string Wikitext
480 function getSkinCredits() {
481 $out = Xml::element(
482 'h2',
483 array( 'id' => 'mw-version-skin' ),
484 $this->msg( 'version-skins' )->text()
486 Xml::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-skin' ) );
488 $this->firstExtOpened = false;
489 $out .= $this->getExtensionCategory( 'skin', null );
491 $out .= Xml::closeElement( 'table' );
493 return $out;
497 * Obtains a list of installed parser tags and the associated H2 header
499 * @return string HTML output
501 protected function getParserTags() {
502 global $wgParser;
504 $tags = $wgParser->getTags();
506 if ( count( $tags ) ) {
507 $out = Html::rawElement(
508 'h2',
509 array( 'class' => 'mw-headline' ),
510 Linker::makeExternalLink(
511 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions',
512 $this->msg( 'version-parser-extensiontags' )->parse(),
513 false /* msg()->parse() already escapes */
517 array_walk( $tags, function ( &$value ) {
518 $value = '&lt;' . htmlspecialchars( $value ) . '&gt;';
519 } );
520 $out .= $this->listToText( $tags );
521 } else {
522 $out = '';
525 return $out;
529 * Obtains a list of installed parser function hooks and the associated H2 header
531 * @return string HTML output
533 protected function getParserFunctionHooks() {
534 global $wgParser;
536 $fhooks = $wgParser->getFunctionHooks();
537 if ( count( $fhooks ) ) {
538 $out = Html::rawElement( 'h2', array( 'class' => 'mw-headline' ), Linker::makeExternalLink(
539 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions',
540 $this->msg( 'version-parser-function-hooks' )->parse(),
541 false /* msg()->parse() already escapes */
542 ) );
544 $out .= $this->listToText( $fhooks );
545 } else {
546 $out = '';
549 return $out;
553 * Creates and returns the HTML for a single extension category.
555 * @since 1.17
557 * @param string $type
558 * @param string $message
560 * @return string
562 protected function getExtensionCategory( $type, $message ) {
563 global $wgExtensionCredits;
565 $out = '';
567 if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
568 $out .= $this->openExtType( $message, 'credits-' . $type );
570 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
572 foreach ( $wgExtensionCredits[$type] as $extension ) {
573 $out .= $this->getCreditsForExtension( $extension );
577 return $out;
581 * Callback to sort extensions by type.
582 * @param array $a
583 * @param array $b
584 * @return int
586 function compare( $a, $b ) {
587 if ( $a['name'] === $b['name'] ) {
588 return 0;
589 } else {
590 return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
592 : -1;
597 * Creates and formats a version line for a single extension.
599 * Information for five columns will be created. Parameters required in the
600 * $extension array for part rendering are indicated in ()
601 * - The name of (name), and URL link to (url), the extension
602 * - Official version number (version) and if available version control system
603 * revision (path), link, and date
604 * - If available the short name of the license (license-name) and a linke
605 * to ((LICENSE)|(COPYING))(\.txt)? if it exists.
606 * - Description of extension (descriptionmsg or description)
607 * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
609 * @param array $extension
611 * @return string Raw HTML
613 function getCreditsForExtension( array $extension ) {
614 $out = $this->getOutput();
616 // We must obtain the information for all the bits and pieces!
617 // ... such as extension names and links
618 if ( isset( $extension['namemsg'] ) ) {
619 // Localized name of extension
620 $extensionName = $this->msg( $extension['namemsg'] )->text();
621 } elseif ( isset( $extension['name'] ) ) {
622 // Non localized version
623 $extensionName = $extension['name'];
624 } else {
625 $extensionName = $this->msg( 'version-no-ext-name' )->text();
628 if ( isset( $extension['url'] ) ) {
629 $extensionNameLink = Linker::makeExternalLink(
630 $extension['url'],
631 $extensionName,
632 true,
634 array( 'class' => 'mw-version-ext-name' )
636 } else {
637 $extensionNameLink = $extensionName;
640 // ... and the version information
641 // If the extension path is set we will check that directory for GIT and SVN
642 // metadata in an attempt to extract date and vcs commit metadata.
643 $canonicalVersion = '&ndash;';
644 $extensionPath = null;
645 $vcsVersion = null;
646 $vcsLink = null;
647 $vcsDate = null;
649 if ( isset( $extension['version'] ) ) {
650 $canonicalVersion = $out->parseInline( $extension['version'] );
653 if ( isset( $extension['path'] ) ) {
654 global $IP;
655 $extensionPath = dirname( $extension['path'] );
656 if ( $this->coreId == '' ) {
657 wfDebug( 'Looking up core head id' );
658 $coreHeadSHA1 = self::getGitHeadSha1( $IP );
659 if ( $coreHeadSHA1 ) {
660 $this->coreId = $coreHeadSHA1;
661 } else {
662 $svnInfo = self::getSvnInfo( $IP );
663 if ( $svnInfo !== false ) {
664 $this->coreId = $svnInfo['checkout-rev'];
668 $cache = wfGetCache( CACHE_ANYTHING );
669 $memcKey = wfMemcKey( 'specialversion-ext-version-text', $extension['path'], $this->coreId );
670 list( $vcsVersion, $vcsLink, $vcsDate ) = $cache->get( $memcKey );
672 if ( !$vcsVersion ) {
673 wfDebug( "Getting VCS info for extension $extensionName" );
674 $gitInfo = new GitInfo( $extensionPath );
675 $vcsVersion = $gitInfo->getHeadSHA1();
676 if ( $vcsVersion !== false ) {
677 $vcsVersion = substr( $vcsVersion, 0, 7 );
678 $vcsLink = $gitInfo->getHeadViewUrl();
679 $vcsDate = $gitInfo->getHeadCommitDate();
680 } else {
681 $svnInfo = self::getSvnInfo( $extensionPath );
682 if ( $svnInfo !== false ) {
683 $vcsVersion = $this->msg( 'version-svn-revision', $svnInfo['checkout-rev'] )->text();
684 $vcsLink = isset( $svnInfo['viewvc-url'] ) ? $svnInfo['viewvc-url'] : '';
687 $cache->set( $memcKey, array( $vcsVersion, $vcsLink, $vcsDate ), 60 * 60 * 24 );
688 } else {
689 wfDebug( "Pulled VCS info for extension $extensionName from cache" );
693 $versionString = Html::rawElement(
694 'span',
695 array( 'class' => 'mw-version-ext-version' ),
696 $canonicalVersion
699 if ( $vcsVersion ) {
700 if ( $vcsLink ) {
701 $vcsVerString = Linker::makeExternalLink(
702 $vcsLink,
703 $this->msg( 'version-version', $vcsVersion ),
704 true,
706 array( 'class' => 'mw-version-ext-vcs-version' )
708 } else {
709 $vcsVerString = Html::element( 'span',
710 array( 'class' => 'mw-version-ext-vcs-version' ),
711 "({$vcsVersion})"
714 $versionString .= " {$vcsVerString}";
716 if ( $vcsDate ) {
717 $vcsTimeString = Html::element( 'span',
718 array( 'class' => 'mw-version-ext-vcs-timestamp' ),
719 $this->getLanguage()->timeanddate( $vcsDate )
721 $versionString .= " {$vcsTimeString}";
723 $versionString = Html::rawElement( 'span',
724 array( 'class' => 'mw-version-ext-meta-version' ),
725 $versionString
729 // ... and license information; if a license file exists we
730 // will link to it
731 $licenseLink = '';
732 if ( isset( $extension['license-name'] ) ) {
733 $licenseLink = Linker::link(
734 $this->getPageTitle( 'License/' . $extensionName ),
735 $out->parseInline( $extension['license-name'] ),
736 array( 'class' => 'mw-version-ext-license' )
738 } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
739 $licenseLink = Linker::link(
740 $this->getPageTitle( 'License/' . $extensionName ),
741 $this->msg( 'version-ext-license' ),
742 array( 'class' => 'mw-version-ext-license' )
746 // ... and generate the description; which can be a parameterized l10n message
747 // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
748 // up string
749 if ( isset( $extension['descriptionmsg'] ) ) {
750 // Localized description of extension
751 $descriptionMsg = $extension['descriptionmsg'];
753 if ( is_array( $descriptionMsg ) ) {
754 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
755 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
756 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
757 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
758 } else {
759 $description = $this->msg( $descriptionMsg )->text();
761 } elseif ( isset( $extension['description'] ) ) {
762 // Non localized version
763 $description = $extension['description'];
764 } else {
765 $description = '';
767 $description = $out->parseInline( $description );
769 // ... now get the authors for this extension
770 $authors = isset( $extension['author'] ) ? $extension['author'] : array();
771 $authors = $this->listAuthors( $authors, $extensionName, $extensionPath );
773 // Finally! Create the table
774 $html = Html::openElement( 'tr', array(
775 'class' => 'mw-version-ext',
776 'id' => "mw-version-ext-{$extensionName}"
780 $html .= Html::rawElement( 'td', array(), $extensionNameLink );
781 $html .= Html::rawElement( 'td', array(), $versionString );
782 $html .= Html::rawElement( 'td', array(), $licenseLink );
783 $html .= Html::rawElement( 'td', array( 'class' => 'mw-version-ext-description' ), $description );
784 $html .= Html::rawElement( 'td', array( 'class' => 'mw-version-ext-authors' ), $authors );
786 $html .= Html::closeElement( 'td' );
788 return $html;
792 * Generate wikitext showing hooks in $wgHooks.
794 * @return string Wikitext
796 private function getWgHooks() {
797 global $wgSpecialVersionShowHooks, $wgHooks;
799 if ( $wgSpecialVersionShowHooks && count( $wgHooks ) ) {
800 $myWgHooks = $wgHooks;
801 ksort( $myWgHooks );
803 $ret = array();
804 $ret[] = '== {{int:version-hooks}} ==';
805 $ret[] = Html::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) );
806 $ret[] = Html::openElement( 'tr' );
807 $ret[] = Html::element( 'th', array(), $this->msg( 'version-hook-name' )->text() );
808 $ret[] = Html::element( 'th', array(), $this->msg( 'version-hook-subscribedby' )->text() );
809 $ret[] = Html::closeElement( 'tr' );
811 foreach ( $myWgHooks as $hook => $hooks ) {
812 $ret[] = Html::openElement( 'tr' );
813 $ret[] = Html::element( 'td', array(), $hook );
814 $ret[] = Html::element( 'td', array(), $this->listToText( $hooks ) );
815 $ret[] = Html::closeElement( 'tr' );
818 $ret[] = Html::closeElement( 'table' );
820 return implode( "\n", $ret );
821 } else {
822 return '';
826 private function openExtType( $text = null, $name = null ) {
827 $out = '';
829 $opt = array( 'colspan' => 5 );
830 if ( $this->firstExtOpened ) {
831 // Insert a spacing line
832 $out .= Html::rawElement( 'tr', array( 'class' => 'sv-space' ),
833 Html::element( 'td', $opt )
836 $this->firstExtOpened = true;
838 if ( $name ) {
839 $opt['id'] = "sv-$name";
842 if ( $text !== null ) {
843 $out .= Html::rawElement( 'tr', array(),
844 Html::element( 'th', $opt, $text )
848 $firstHeadingMsg = ( $name === 'credits-skin' )
849 ? 'version-skin-colheader-name'
850 : 'version-ext-colheader-name';
851 $out .= Html::openElement( 'tr' );
852 $out .= Html::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
853 $this->msg( $firstHeadingMsg )->text() );
854 $out .= Html::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
855 $this->msg( 'version-ext-colheader-version' )->text() );
856 $out .= Html::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
857 $this->msg( 'version-ext-colheader-license' )->text() );
858 $out .= Html::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
859 $this->msg( 'version-ext-colheader-description' )->text() );
860 $out .= Html::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
861 $this->msg( 'version-ext-colheader-credits' )->text() );
862 $out .= Html::closeElement( 'tr' );
864 return $out;
868 * Get information about client's IP address.
870 * @return string HTML fragment
872 private function IPInfo() {
873 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
875 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
879 * Return a formatted unsorted list of authors
881 * 'And Others'
882 * If an item in the $authors array is '...' it is assumed to indicate an
883 * 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
884 * file if it exists in $dir.
886 * Similarly an entry ending with ' ...]' is assumed to be a link to an
887 * 'and others' page.
889 * If no '...' string variant is found, but an authors file is found an
890 * 'and others' will be added to the end of the credits.
892 * @param string|array $authors
893 * @param string $extName Name of the extension for link creation
894 * @param string $extDir Path to the extension root directory
896 * @return string HTML fragment
898 function listAuthors( $authors, $extName, $extDir ) {
899 $hasOthers = false;
901 $list = array();
902 foreach ( (array)$authors as $item ) {
903 if ( $item == '...' ) {
904 $hasOthers = true;
906 if ( $this->getExtAuthorsFileName( $extDir ) ) {
907 $text = Linker::link(
908 $this->getPageTitle( "Credits/$extName" ),
909 $this->msg( 'version-poweredby-others' )->text()
911 } else {
912 $text = $this->msg( 'version-poweredby-others' )->text();
914 $list[] = $text;
915 } elseif ( substr( $item, -5 ) == ' ...]' ) {
916 $hasOthers = true;
917 $list[] = $this->getOutput()->parseInline(
918 substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
920 } else {
921 $list[] = $this->getOutput()->parseInline( $item );
925 if ( !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
926 $list[] = $text = Linker::link(
927 $this->getPageTitle( "Credits/$extName" ),
928 $this->msg( 'version-poweredby-others' )->text()
932 return $this->listToText( $list, false );
936 * Obtains the full path of an extensions authors or credits file if
937 * one exists.
939 * @param string $extDir Path to the extensions root directory
941 * @since 1.23
943 * @return bool|string False if no such file exists, otherwise returns
944 * a path to it.
946 public static function getExtAuthorsFileName( $extDir ) {
947 if ( !$extDir ) {
948 return false;
951 foreach ( scandir( $extDir ) as $file ) {
952 $fullPath = $extDir . DIRECTORY_SEPARATOR . $file;
953 if ( preg_match( '/^((AUTHORS)|(CREDITS))(\.txt)?$/', $file ) &&
954 is_readable( $fullPath ) &&
955 is_file( $fullPath )
957 return $fullPath;
961 return false;
965 * Obtains the full path of an extensions copying or license file if
966 * one exists.
968 * @param string $extDir Path to the extensions root directory
970 * @since 1.23
972 * @return bool|string False if no such file exists, otherwise returns
973 * a path to it.
975 public static function getExtLicenseFileName( $extDir ) {
976 if ( !$extDir ) {
977 return false;
980 foreach ( scandir( $extDir ) as $file ) {
981 $fullPath = $extDir . DIRECTORY_SEPARATOR . $file;
982 if ( preg_match( '/^((COPYING)|(LICENSE))(\.txt)?$/', $file ) &&
983 is_readable( $fullPath ) &&
984 is_file( $fullPath )
986 return $fullPath;
990 return false;
994 * Convert an array of items into a list for display.
996 * @param array $list List of elements to display
997 * @param bool $sort Whether to sort the items in $list
999 * @return string
1001 function listToText( $list, $sort = true ) {
1002 if ( !count( $list ) ) {
1003 return '';
1005 if ( $sort ) {
1006 sort( $list );
1009 return $this->getLanguage()
1010 ->listToText( array_map( array( __CLASS__, 'arrayToString' ), $list ) );
1014 * Convert an array or object to a string for display.
1016 * @param mixed $list Will convert an array to string if given and return
1017 * the paramater unaltered otherwise
1019 * @return mixed
1021 public static function arrayToString( $list ) {
1022 if ( is_array( $list ) && count( $list ) == 1 ) {
1023 $list = $list[0];
1025 if ( is_object( $list ) ) {
1026 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
1028 return $class;
1029 } elseif ( !is_array( $list ) ) {
1030 return $list;
1031 } else {
1032 if ( is_object( $list[0] ) ) {
1033 $class = get_class( $list[0] );
1034 } else {
1035 $class = $list[0];
1038 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
1043 * Get an associative array of information about a given path, from its .svn
1044 * subdirectory. Returns false on error, such as if the directory was not
1045 * checked out with subversion.
1047 * Returned keys are:
1048 * Required:
1049 * checkout-rev The revision which was checked out
1050 * Optional:
1051 * directory-rev The revision when the directory was last modified
1052 * url The subversion URL of the directory
1053 * repo-url The base URL of the repository
1054 * viewvc-url A ViewVC URL pointing to the checked-out revision
1055 * @param string $dir
1056 * @return array|bool
1058 public static function getSvnInfo( $dir ) {
1059 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
1060 $entries = $dir . '/.svn/entries';
1062 if ( !file_exists( $entries ) ) {
1063 return false;
1066 $lines = file( $entries );
1067 if ( !count( $lines ) ) {
1068 return false;
1071 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
1072 if ( preg_match( '/^<\?xml/', $lines[0] ) ) {
1073 // subversion is release <= 1.3
1074 if ( !function_exists( 'simplexml_load_file' ) ) {
1075 // We could fall back to expat... YUCK
1076 return false;
1079 // SimpleXml whines about the xmlns...
1080 wfSuppressWarnings();
1081 $xml = simplexml_load_file( $entries );
1082 wfRestoreWarnings();
1084 if ( $xml ) {
1085 foreach ( $xml->entry as $entry ) {
1086 if ( $xml->entry[0]['name'] == '' ) {
1087 // The directory entry should always have a revision marker.
1088 if ( $entry['revision'] ) {
1089 return array( 'checkout-rev' => intval( $entry['revision'] ) );
1095 return false;
1098 // Subversion is release 1.4 or above.
1099 if ( count( $lines ) < 11 ) {
1100 return false;
1103 $info = array(
1104 'checkout-rev' => intval( trim( $lines[3] ) ),
1105 'url' => trim( $lines[4] ),
1106 'repo-url' => trim( $lines[5] ),
1107 'directory-rev' => intval( trim( $lines[10] ) )
1110 if ( isset( self::$viewvcUrls[$info['repo-url']] ) ) {
1111 $viewvc = str_replace(
1112 $info['repo-url'],
1113 self::$viewvcUrls[$info['repo-url']],
1114 $info['url']
1117 $viewvc .= '/?pathrev=';
1118 $viewvc .= urlencode( $info['checkout-rev'] );
1119 $info['viewvc-url'] = $viewvc;
1122 return $info;
1126 * Retrieve the revision number of a Subversion working directory.
1128 * @param string $dir Directory of the svn checkout
1130 * @return int Revision number
1132 public static function getSvnRevision( $dir ) {
1133 $info = self::getSvnInfo( $dir );
1135 if ( $info === false ) {
1136 return false;
1137 } elseif ( isset( $info['checkout-rev'] ) ) {
1138 return $info['checkout-rev'];
1139 } else {
1140 return false;
1145 * @param string $dir Directory of the git checkout
1146 * @return bool|string Sha1 of commit HEAD points to
1148 public static function getGitHeadSha1( $dir ) {
1149 $repo = new GitInfo( $dir );
1151 return $repo->getHeadSHA1();
1155 * @param string $dir Directory of the git checkout
1156 * @return bool|string Branch currently checked out
1158 public static function getGitCurrentBranch( $dir ) {
1159 $repo = new GitInfo( $dir );
1160 return $repo->getCurrentBranch();
1164 * Get the list of entry points and their URLs
1165 * @return string Wikitext
1167 public function getEntryPointInfo() {
1168 global $wgArticlePath, $wgScriptPath;
1169 $scriptPath = $wgScriptPath ? $wgScriptPath : "/";
1170 $entryPoints = array(
1171 'version-entrypoints-articlepath' => $wgArticlePath,
1172 'version-entrypoints-scriptpath' => $scriptPath,
1173 'version-entrypoints-index-php' => wfScript( 'index' ),
1174 'version-entrypoints-api-php' => wfScript( 'api' ),
1175 'version-entrypoints-load-php' => wfScript( 'load' ),
1178 $language = $this->getLanguage();
1179 $thAttribures = array(
1180 'dir' => $language->getDir(),
1181 'lang' => $language->getCode()
1183 $out = Html::element(
1184 'h2',
1185 array( 'id' => 'mw-version-entrypoints' ),
1186 $this->msg( 'version-entrypoints' )->text()
1188 Html::openElement( 'table',
1189 array(
1190 'class' => 'wikitable plainlinks',
1191 'id' => 'mw-version-entrypoints-table',
1192 'dir' => 'ltr',
1193 'lang' => 'en'
1196 Html::openElement( 'tr' ) .
1197 Html::element(
1198 'th',
1199 $thAttribures,
1200 $this->msg( 'version-entrypoints-header-entrypoint' )->text()
1202 Html::element(
1203 'th',
1204 $thAttribures,
1205 $this->msg( 'version-entrypoints-header-url' )->text()
1207 Html::closeElement( 'tr' );
1209 foreach ( $entryPoints as $message => $value ) {
1210 $url = wfExpandUrl( $value, PROTO_RELATIVE );
1211 $out .= Html::openElement( 'tr' ) .
1212 // ->text() looks like it should be ->parse(), but this function
1213 // returns wikitext, not HTML, boo
1214 Html::rawElement( 'td', array(), $this->msg( $message )->text() ) .
1215 Html::rawElement( 'td', array(), Html::rawElement( 'code', array(), "[$url $value]" ) ) .
1216 Html::closeElement( 'tr' );
1219 $out .= Html::closeElement( 'table' );
1221 return $out;
1224 protected function getGroupName() {
1225 return 'wiki';