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
23 * @ingroup SpecialPage
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;
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' );
53 * @param string|null $par
55 public function execute( $par ) {
56 global $IP, $wgExtensionCredits;
59 $this->outputHeader();
60 $out = $this->getOutput();
61 $out->allowClickjacking();
63 // Explode the sub page information into useful bits
64 $parts = explode( '/', (string)$par );
66 if ( isset( $parts[1] ) ) {
67 $extName = str_replace( '_', ' ', $parts[1] );
69 foreach ( $wgExtensionCredits as $group => $extensions ) {
70 foreach ( $extensions as $ext ) {
71 if ( isset( $ext['name'] ) && ( $ext['name'] === $extName ) ) {
78 $out->setStatusCode( 404 );
81 $extName = 'MediaWiki';
84 // Now figure out what to do
85 switch ( strtolower( $parts[0] ) ) {
87 $wikiText = '{{int:version-credits-not-found}}';
88 if ( $extName === 'MediaWiki' ) {
89 $wikiText = file_get_contents( $IP . '/CREDITS' );
90 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
91 $file = $this->getExtAuthorsFileName( dirname( $extNode['path'] ) );
93 $wikiText = file_get_contents( $file );
94 if ( substr( $file, -4 ) === '.txt' ) {
95 $wikiText = Html
::element(
107 $out->setPageTitle( $this->msg( 'version-credits-title', $extName ) );
108 $out->addWikiText( $wikiText );
112 $wikiText = '{{int:version-license-not-found}}';
113 if ( $extName === 'MediaWiki' ) {
114 $wikiText = file_get_contents( $IP . '/COPYING' );
115 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
116 $file = $this->getExtLicenseFileName( dirname( $extNode['path'] ) );
118 $wikiText = file_get_contents( $file );
119 $wikiText = Html
::element(
130 $out->setPageTitle( $this->msg( 'version-license-title', $extName ) );
131 $out->addWikiText( $wikiText );
135 $out->addModules( 'mediawiki.special.version' );
137 $this->getMediaWikiCredits() .
138 $this->softwareInformation() .
139 $this->getEntryPointInfo()
142 $this->getSkinCredits() .
143 $this->getExtensionCredits() .
144 $this->getExternalLibraries() .
145 $this->getParserTags() .
146 $this->getParserFunctionHooks()
148 $out->addWikiText( $this->getWgHooks() );
149 $out->addHTML( $this->IPInfo() );
156 * Returns wiki text showing the license information.
160 private static function getMediaWikiCredits() {
163 array( 'id' => 'mw-version-license' ),
164 wfMessage( 'version-license' )->text()
167 // This text is always left-to-right.
168 $ret .= '<div class="plainlinks">';
170 " . self
::getCopyrightAndAuthorList() . "\n
171 " . wfMessage( 'version-license-info' )->text();
174 return str_replace( "\t\t", '', $ret ) . "\n";
178 * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
182 public static function getCopyrightAndAuthorList() {
185 if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
186 $othersLink = '[//www.mediawiki.org/wiki/Special:Version/Credits ' .
187 wfMessage( 'version-poweredby-others' )->text() . ']';
189 $othersLink = '[[Special:Version/Credits|' .
190 wfMessage( 'version-poweredby-others' )->text() . ']]';
193 $translatorsLink = '[//translatewiki.net/wiki/Translating:MediaWiki/Credits ' .
194 wfMessage( 'version-poweredby-translators' )->text() . ']';
197 'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
198 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
199 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
200 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
201 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
202 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
203 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
204 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', 'Brad Jorsch',
205 $othersLink, $translatorsLink
208 return wfMessage( 'version-poweredby-credits', MWTimestamp
::getLocalInstance()->format( 'Y' ),
209 $wgLang->listToText( $authorList ) )->text();
213 * Returns wiki text showing the third party software versions (apache, php, mysql).
217 public static function softwareInformation() {
218 $dbr = wfGetDB( DB_SLAVE
);
220 // Put the software in an array of form 'name' => 'version'. All messages should
221 // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
222 // wikimarkup can be used.
224 $software['[https://www.mediawiki.org/ MediaWiki]'] = self
::getVersionLinked();
226 $software['[http://hhvm.com/ HHVM]'] = HHVM_VERSION
. " (" . PHP_SAPI
. ")";
228 $software['[https://php.net/ PHP]'] = PHP_VERSION
. " (" . PHP_SAPI
. ")";
230 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
232 if ( IcuCollation
::getICUVersion() ) {
233 $software['[http://site.icu-project.org/ ICU]'] = IcuCollation
::getICUVersion();
236 // Allow a hook to add/remove items.
237 Hooks
::run( 'SoftwareInfo', array( &$software ) );
241 array( 'id' => 'mw-version-software' ),
242 wfMessage( 'version-software' )->text()
244 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ) ) .
246 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
247 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
250 foreach ( $software as $name => $version ) {
252 <td>" . $name . "</td>
253 <td dir=\"ltr\">" . $version . "</td>
257 return $out . Xml
::closeElement( 'table' );
261 * Return a string of the MediaWiki version with SVN revision if available.
263 * @param string $flags
266 public static function getVersion( $flags = '' ) {
267 global $wgVersion, $IP;
269 $gitInfo = self
::getGitHeadSha1( $IP );
270 $svnInfo = self
::getSvnInfo( $IP );
271 if ( !$svnInfo && !$gitInfo ) {
272 $version = $wgVersion;
273 } elseif ( $gitInfo && $flags === 'nodb' ) {
274 $shortSha1 = substr( $gitInfo, 0, 7 );
275 $version = "$wgVersion ($shortSha1)";
276 } elseif ( $gitInfo ) {
277 $shortSha1 = substr( $gitInfo, 0, 7 );
278 $shortSha1 = wfMessage( 'parentheses' )->params( $shortSha1 )->escaped();
279 $version = "$wgVersion $shortSha1";
280 } elseif ( $flags === 'nodb' ) {
281 $version = "$wgVersion (r{$svnInfo['checkout-rev']})";
283 $version = $wgVersion . ' ' .
285 'version-svn-revision',
286 isset( $svnInfo['directory-rev'] ) ?
$svnInfo['directory-rev'] : '',
287 isset( $svnInfo['checkout-rev'] ) ?
$svnInfo['checkout-rev'] : ''
295 * Return a wikitext-formatted string of the MediaWiki version with a link to
296 * the SVN revision or the git SHA1 of head if available.
297 * Git is prefered over Svn
298 * The fallback is just $wgVersion
302 public static function getVersionLinked() {
305 $gitVersion = self
::getVersionLinkedGit();
309 $svnVersion = self
::getVersionLinkedSvn();
313 $v = $wgVersion; // fallback
321 * @return string Global wgVersion + a link to subversion revision of svn BASE
323 private static function getVersionLinkedSvn() {
326 $info = self
::getSvnInfo( $IP );
327 if ( !isset( $info['checkout-rev'] ) ) {
331 $linkText = wfMessage(
332 'version-svn-revision',
333 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
334 $info['checkout-rev']
337 if ( isset( $info['viewvc-url'] ) ) {
338 $version = "[{$info['viewvc-url']} $linkText]";
340 $version = $linkText;
343 return self
::getwgVersionLinked() . " $version";
349 private static function getwgVersionLinked() {
352 if ( Hooks
::run( 'SpecialVersionVersionUrl', array( $wgVersion, &$versionUrl ) ) ) {
353 $versionParts = array();
354 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
355 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
358 return "[$versionUrl $wgVersion]";
362 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
363 * @return bool|string Global wgVersion + HEAD sha1 stripped to the first 7 chars
364 * with link and date, or false on failure
366 private static function getVersionLinkedGit() {
369 $gitInfo = new GitInfo( $IP );
370 $headSHA1 = $gitInfo->getHeadSHA1();
375 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
377 $gitHeadUrl = $gitInfo->getHeadViewUrl();
378 if ( $gitHeadUrl !== false ) {
379 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
382 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
383 if ( $gitHeadCommitDate ) {
384 $shortSHA1 .= Html
::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true );
387 return self
::getwgVersionLinked() . " $shortSHA1";
391 * Returns an array with the base extension types.
392 * Type is stored as array key, the message as array value.
394 * TODO: ideally this would return all extension types.
400 public static function getExtensionTypes() {
401 if ( self
::$extensionTypes === false ) {
402 self
::$extensionTypes = array(
403 'specialpage' => wfMessage( 'version-specialpages' )->text(),
404 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
405 'variable' => wfMessage( 'version-variables' )->text(),
406 'media' => wfMessage( 'version-mediahandlers' )->text(),
407 'antispam' => wfMessage( 'version-antispam' )->text(),
408 'skin' => wfMessage( 'version-skins' )->text(),
409 'api' => wfMessage( 'version-api' )->text(),
410 'other' => wfMessage( 'version-other' )->text(),
413 Hooks
::run( 'ExtensionTypes', array( &self
::$extensionTypes ) );
416 return self
::$extensionTypes;
420 * Returns the internationalized name for an extension type.
424 * @param string $type
428 public static function getExtensionTypeName( $type ) {
429 $types = self
::getExtensionTypes();
431 return isset( $types[$type] ) ?
$types[$type] : $types['other'];
435 * Generate wikitext showing the name, URL, author and description of each extension.
437 * @return string Wikitext
439 public function getExtensionCredits() {
440 global $wgExtensionCredits;
443 count( $wgExtensionCredits ) === 0 ||
444 // Skins are displayed separately, see getSkinCredits()
445 ( count( $wgExtensionCredits ) === 1 && isset( $wgExtensionCredits['skin'] ) )
450 $extensionTypes = self
::getExtensionTypes();
454 array( 'id' => 'mw-version-ext' ),
455 $this->msg( 'version-extensions' )->text()
457 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ) );
459 // Make sure the 'other' type is set to an array.
460 if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
461 $wgExtensionCredits['other'] = array();
464 // Find all extensions that do not have a valid type and give them the type 'other'.
465 foreach ( $wgExtensionCredits as $type => $extensions ) {
466 if ( !array_key_exists( $type, $extensionTypes ) ) {
467 $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
471 $this->firstExtOpened
= false;
472 // Loop through the extension categories to display their extensions in the list.
473 foreach ( $extensionTypes as $type => $message ) {
474 // Skins have a separate section
475 if ( $type !== 'other' && $type !== 'skin' ) {
476 $out .= $this->getExtensionCategory( $type, $message );
480 // We want the 'other' type to be last in the list.
481 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
483 $out .= Xml
::closeElement( 'table' );
489 * Generate wikitext showing the name, URL, author and description of each skin.
491 * @return string Wikitext
493 public function getSkinCredits() {
494 global $wgExtensionCredits;
495 if ( !isset( $wgExtensionCredits['skin'] ) ||
count( $wgExtensionCredits['skin'] ) === 0 ) {
501 array( 'id' => 'mw-version-skin' ),
502 $this->msg( 'version-skins' )->text()
504 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-skin' ) );
506 $this->firstExtOpened
= false;
507 $out .= $this->getExtensionCategory( 'skin', null );
509 $out .= Xml
::closeElement( 'table' );
515 * Generate an HTML table for external libraries that are installed
519 protected function getExternalLibraries() {
521 $path = "$IP/composer.lock";
522 if ( !file_exists( $path ) ) {
523 // Maybe they're using mediawiki/vendor?
524 $path = "$IP/vendor/composer.lock";
525 if ( !file_exists( $path ) ) {
530 $lock = new ComposerLock( $path );
531 $out = Html
::element(
533 array( 'id' => 'mw-version-libraries' ),
534 $this->msg( 'version-libraries' )->text()
536 $out .= Html
::openElement(
538 array( 'class' => 'wikitable plainlinks', 'id' => 'sv-libraries' )
540 $out .= Html
::openElement( 'tr' )
541 . Html
::element( 'th', array(), $this->msg( 'version-libraries-library' )->text() )
542 . Html
::element( 'th', array(), $this->msg( 'version-libraries-version' )->text() )
543 . Html
::element( 'th', array(), $this->msg( 'version-libraries-license' )->text() )
544 . Html
::element( 'th', array(), $this->msg( 'version-libraries-description' )->text() )
545 . Html
::element( 'th', array(), $this->msg( 'version-libraries-authors' )->text() )
546 . Html
::closeElement( 'tr' );
548 foreach ( $lock->getInstalledDependencies() as $name => $info ) {
549 if ( strpos( $info['type'], 'mediawiki-' ) === 0 ) {
550 // Skip any extensions or skins since they'll be listed
551 // in their proper section
554 $authors = array_map( function( $arr ) {
555 // If a homepage is set, link to it
556 if ( isset( $arr['homepage'] ) ) {
557 return "[{$arr['homepage']} {$arr['name']}]";
560 }, $info['authors'] );
561 $authors = $this->listAuthors( $authors, false, "$IP/vendor/$name" );
563 // We can safely assume that the libraries' names and descriptions
564 // are written in English and aren't going to be translated,
565 // so set appropriate lang and dir attributes
566 $out .= Html
::openElement( 'tr' )
570 Linker
::makeExternalLink(
571 "https://packagist.org/packages/$name", $name,
573 array( 'class' => 'mw-version-library-name' )
576 . Html
::element( 'td', array( 'dir' => 'auto' ), $info['version'] )
577 . Html
::element( 'td', array( 'dir' => 'auto' ), $this->listToText( $info['licenses'] ) )
578 . Html
::element( 'td', array( 'lang' => 'en', 'dir' => 'ltr' ), $info['description'] )
579 . Html
::rawElement( 'td', array(), $authors )
580 . Html
::closeElement( 'tr' );
582 $out .= Html
::closeElement( 'table' );
588 * Obtains a list of installed parser tags and the associated H2 header
590 * @return string HTML output
592 protected function getParserTags() {
595 $tags = $wgParser->getTags();
597 if ( count( $tags ) ) {
598 $out = Html
::rawElement(
601 'class' => 'mw-headline plainlinks',
602 'id' => 'mw-version-parser-extensiontags',
604 Linker
::makeExternalLink(
605 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions',
606 $this->msg( 'version-parser-extensiontags' )->parse(),
607 false /* msg()->parse() already escapes */
611 array_walk( $tags, function ( &$value ) {
612 // Bidirectional isolation improves readability in RTL wikis
613 $value = Html
::element(
615 // Prevent < and > from slipping to another line
617 'style' => 'white-space: nowrap;',
623 $out .= $this->listToText( $tags );
632 * Obtains a list of installed parser function hooks and the associated H2 header
634 * @return string HTML output
636 protected function getParserFunctionHooks() {
639 $fhooks = $wgParser->getFunctionHooks();
640 if ( count( $fhooks ) ) {
641 $out = Html
::rawElement(
644 'class' => 'mw-headline plainlinks',
645 'id' => 'mw-version-parser-function-hooks',
647 Linker
::makeExternalLink(
648 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions',
649 $this->msg( 'version-parser-function-hooks' )->parse(),
650 false /* msg()->parse() already escapes */
654 $out .= $this->listToText( $fhooks );
663 * Creates and returns the HTML for a single extension category.
667 * @param string $type
668 * @param string $message
672 protected function getExtensionCategory( $type, $message ) {
673 global $wgExtensionCredits;
677 if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
678 $out .= $this->openExtType( $message, 'credits-' . $type );
680 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
682 foreach ( $wgExtensionCredits[$type] as $extension ) {
683 $out .= $this->getCreditsForExtension( $extension );
691 * Callback to sort extensions by type.
696 public function compare( $a, $b ) {
697 if ( $a['name'] === $b['name'] ) {
700 return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
707 * Creates and formats a version line for a single extension.
709 * Information for five columns will be created. Parameters required in the
710 * $extension array for part rendering are indicated in ()
711 * - The name of (name), and URL link to (url), the extension
712 * - Official version number (version) and if available version control system
713 * revision (path), link, and date
714 * - If available the short name of the license (license-name) and a linke
715 * to ((LICENSE)|(COPYING))(\.txt)? if it exists.
716 * - Description of extension (descriptionmsg or description)
717 * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
719 * @param array $extension
721 * @return string Raw HTML
723 public function getCreditsForExtension( array $extension ) {
724 $out = $this->getOutput();
726 // We must obtain the information for all the bits and pieces!
727 // ... such as extension names and links
728 if ( isset( $extension['namemsg'] ) ) {
729 // Localized name of extension
730 $extensionName = $this->msg( $extension['namemsg'] )->text();
731 } elseif ( isset( $extension['name'] ) ) {
732 // Non localized version
733 $extensionName = $extension['name'];
735 $extensionName = $this->msg( 'version-no-ext-name' )->text();
738 if ( isset( $extension['url'] ) ) {
739 $extensionNameLink = Linker
::makeExternalLink(
744 array( 'class' => 'mw-version-ext-name' )
747 $extensionNameLink = $extensionName;
750 // ... and the version information
751 // If the extension path is set we will check that directory for GIT and SVN
752 // metadata in an attempt to extract date and vcs commit metadata.
753 $canonicalVersion = '–';
754 $extensionPath = null;
759 if ( isset( $extension['version'] ) ) {
760 $canonicalVersion = $out->parseInline( $extension['version'] );
763 if ( isset( $extension['path'] ) ) {
765 $extensionPath = dirname( $extension['path'] );
766 if ( $this->coreId
== '' ) {
767 wfDebug( 'Looking up core head id' );
768 $coreHeadSHA1 = self
::getGitHeadSha1( $IP );
769 if ( $coreHeadSHA1 ) {
770 $this->coreId
= $coreHeadSHA1;
772 $svnInfo = self
::getSvnInfo( $IP );
773 if ( $svnInfo !== false ) {
774 $this->coreId
= $svnInfo['checkout-rev'];
778 $cache = wfGetCache( CACHE_ANYTHING
);
779 $memcKey = wfMemcKey( 'specialversion-ext-version-text', $extension['path'], $this->coreId
);
780 list( $vcsVersion, $vcsLink, $vcsDate ) = $cache->get( $memcKey );
782 if ( !$vcsVersion ) {
783 wfDebug( "Getting VCS info for extension {$extension['name']}" );
784 $gitInfo = new GitInfo( $extensionPath );
785 $vcsVersion = $gitInfo->getHeadSHA1();
786 if ( $vcsVersion !== false ) {
787 $vcsVersion = substr( $vcsVersion, 0, 7 );
788 $vcsLink = $gitInfo->getHeadViewUrl();
789 $vcsDate = $gitInfo->getHeadCommitDate();
791 $svnInfo = self
::getSvnInfo( $extensionPath );
792 if ( $svnInfo !== false ) {
793 $vcsVersion = $this->msg( 'version-svn-revision', $svnInfo['checkout-rev'] )->text();
794 $vcsLink = isset( $svnInfo['viewvc-url'] ) ?
$svnInfo['viewvc-url'] : '';
797 $cache->set( $memcKey, array( $vcsVersion, $vcsLink, $vcsDate ), 60 * 60 * 24 );
799 wfDebug( "Pulled VCS info for extension {$extension['name']} from cache" );
803 $versionString = Html
::rawElement(
805 array( 'class' => 'mw-version-ext-version' ),
811 $vcsVerString = Linker
::makeExternalLink(
813 $this->msg( 'version-version', $vcsVersion ),
816 array( 'class' => 'mw-version-ext-vcs-version' )
819 $vcsVerString = Html
::element( 'span',
820 array( 'class' => 'mw-version-ext-vcs-version' ),
824 $versionString .= " {$vcsVerString}";
827 $vcsTimeString = Html
::element( 'span',
828 array( 'class' => 'mw-version-ext-vcs-timestamp' ),
829 $this->getLanguage()->timeanddate( $vcsDate, true )
831 $versionString .= " {$vcsTimeString}";
833 $versionString = Html
::rawElement( 'span',
834 array( 'class' => 'mw-version-ext-meta-version' ),
839 // ... and license information; if a license file exists we
842 if ( isset( $extension['name'] ) ) {
844 if ( isset( $extension['license-name'] ) ) {
845 $licenseName = $out->parseInline( $extension['license-name'] );
846 } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
847 $licenseName = $this->msg( 'version-ext-license' );
849 if ( $licenseName !== null ) {
850 $licenseLink = Linker
::link(
851 $this->getPageTitle( 'License/' . $extension['name'] ),
854 'class' => 'mw-version-ext-license',
861 // ... and generate the description; which can be a parameterized l10n message
862 // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
864 if ( isset( $extension['descriptionmsg'] ) ) {
865 // Localized description of extension
866 $descriptionMsg = $extension['descriptionmsg'];
868 if ( is_array( $descriptionMsg ) ) {
869 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
870 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
871 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
872 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
874 $description = $this->msg( $descriptionMsg )->text();
876 } elseif ( isset( $extension['description'] ) ) {
877 // Non localized version
878 $description = $extension['description'];
882 $description = $out->parseInline( $description );
884 // ... now get the authors for this extension
885 $authors = isset( $extension['author'] ) ?
$extension['author'] : array();
886 $authors = $this->listAuthors( $authors, $extension['name'], $extensionPath );
888 // Finally! Create the table
889 $html = Html
::openElement( 'tr', array(
890 'class' => 'mw-version-ext',
891 'id' => Sanitizer
::escapeId( 'mw-version-ext-' . $extension['name'] )
895 $html .= Html
::rawElement( 'td', array(), $extensionNameLink );
896 $html .= Html
::rawElement( 'td', array(), $versionString );
897 $html .= Html
::rawElement( 'td', array(), $licenseLink );
898 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-description' ), $description );
899 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-authors' ), $authors );
901 $html .= Html
::closeElement( 'tr' );
907 * Generate wikitext showing hooks in $wgHooks.
909 * @return string Wikitext
911 private function getWgHooks() {
912 global $wgSpecialVersionShowHooks, $wgHooks;
914 if ( $wgSpecialVersionShowHooks && count( $wgHooks ) ) {
915 $myWgHooks = $wgHooks;
919 $ret[] = '== {{int:version-hooks}} ==';
920 $ret[] = Html
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) );
921 $ret[] = Html
::openElement( 'tr' );
922 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-name' )->text() );
923 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-subscribedby' )->text() );
924 $ret[] = Html
::closeElement( 'tr' );
926 foreach ( $myWgHooks as $hook => $hooks ) {
927 $ret[] = Html
::openElement( 'tr' );
928 $ret[] = Html
::element( 'td', array(), $hook );
929 $ret[] = Html
::element( 'td', array(), $this->listToText( $hooks ) );
930 $ret[] = Html
::closeElement( 'tr' );
933 $ret[] = Html
::closeElement( 'table' );
935 return implode( "\n", $ret );
941 private function openExtType( $text = null, $name = null ) {
944 $opt = array( 'colspan' => 5 );
945 if ( $this->firstExtOpened
) {
946 // Insert a spacing line
947 $out .= Html
::rawElement( 'tr', array( 'class' => 'sv-space' ),
948 Html
::element( 'td', $opt )
951 $this->firstExtOpened
= true;
954 $opt['id'] = "sv-$name";
957 if ( $text !== null ) {
958 $out .= Html
::rawElement( 'tr', array(),
959 Html
::element( 'th', $opt, $text )
963 $firstHeadingMsg = ( $name === 'credits-skin' )
964 ?
'version-skin-colheader-name'
965 : 'version-ext-colheader-name';
966 $out .= Html
::openElement( 'tr' );
967 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
968 $this->msg( $firstHeadingMsg )->text() );
969 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
970 $this->msg( 'version-ext-colheader-version' )->text() );
971 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
972 $this->msg( 'version-ext-colheader-license' )->text() );
973 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
974 $this->msg( 'version-ext-colheader-description' )->text() );
975 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
976 $this->msg( 'version-ext-colheader-credits' )->text() );
977 $out .= Html
::closeElement( 'tr' );
983 * Get information about client's IP address.
985 * @return string HTML fragment
987 private function IPInfo() {
988 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
990 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
994 * Return a formatted unsorted list of authors
997 * If an item in the $authors array is '...' it is assumed to indicate an
998 * 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
999 * file if it exists in $dir.
1001 * Similarly an entry ending with ' ...]' is assumed to be a link to an
1002 * 'and others' page.
1004 * If no '...' string variant is found, but an authors file is found an
1005 * 'and others' will be added to the end of the credits.
1007 * @param string|array $authors
1008 * @param string|bool $extName Name of the extension for link creation,
1009 * false if no links should be created
1010 * @param string $extDir Path to the extension root directory
1012 * @return string HTML fragment
1014 public function listAuthors( $authors, $extName, $extDir ) {
1018 foreach ( (array)$authors as $item ) {
1019 if ( $item == '...' ) {
1022 if ( $extName && $this->getExtAuthorsFileName( $extDir ) ) {
1023 $text = Linker
::link(
1024 $this->getPageTitle( "Credits/$extName" ),
1025 $this->msg( 'version-poweredby-others' )->escaped()
1028 $text = $this->msg( 'version-poweredby-others' )->escaped();
1031 } elseif ( substr( $item, -5 ) == ' ...]' ) {
1033 $list[] = $this->getOutput()->parseInline(
1034 substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
1037 $list[] = $this->getOutput()->parseInline( $item );
1041 if ( $extName && !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
1042 $list[] = $text = Linker
::link(
1043 $this->getPageTitle( "Credits/$extName" ),
1044 $this->msg( 'version-poweredby-others' )->escaped()
1048 return $this->listToText( $list, false );
1052 * Obtains the full path of an extensions authors or credits file if
1055 * @param string $extDir Path to the extensions root directory
1059 * @return bool|string False if no such file exists, otherwise returns
1062 public static function getExtAuthorsFileName( $extDir ) {
1067 foreach ( scandir( $extDir ) as $file ) {
1068 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
1069 if ( preg_match( '/^((AUTHORS)|(CREDITS))(\.txt)?$/', $file ) &&
1070 is_readable( $fullPath ) &&
1071 is_file( $fullPath )
1081 * Obtains the full path of an extensions copying or license file if
1084 * @param string $extDir Path to the extensions root directory
1088 * @return bool|string False if no such file exists, otherwise returns
1091 public static function getExtLicenseFileName( $extDir ) {
1096 foreach ( scandir( $extDir ) as $file ) {
1097 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
1098 if ( preg_match( '/^((COPYING)|(LICENSE))(\.txt)?$/', $file ) &&
1099 is_readable( $fullPath ) &&
1100 is_file( $fullPath )
1110 * Convert an array of items into a list for display.
1112 * @param array $list List of elements to display
1113 * @param bool $sort Whether to sort the items in $list
1117 public function listToText( $list, $sort = true ) {
1118 if ( !count( $list ) ) {
1125 return $this->getLanguage()
1126 ->listToText( array_map( array( __CLASS__
, 'arrayToString' ), $list ) );
1130 * Convert an array or object to a string for display.
1132 * @param mixed $list Will convert an array to string if given and return
1133 * the parameter unaltered otherwise
1137 public static function arrayToString( $list ) {
1138 if ( is_array( $list ) && count( $list ) == 1 ) {
1141 if ( $list instanceof Closure
) {
1142 // Don't output stuff like "Closure$;1028376090#8$48499d94fe0147f7c633b365be39952b$"
1144 } elseif ( is_object( $list ) ) {
1145 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
1148 } elseif ( !is_array( $list ) ) {
1151 if ( is_object( $list[0] ) ) {
1152 $class = get_class( $list[0] );
1157 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
1162 * Get an associative array of information about a given path, from its .svn
1163 * subdirectory. Returns false on error, such as if the directory was not
1164 * checked out with subversion.
1166 * Returned keys are:
1168 * checkout-rev The revision which was checked out
1170 * directory-rev The revision when the directory was last modified
1171 * url The subversion URL of the directory
1172 * repo-url The base URL of the repository
1173 * viewvc-url A ViewVC URL pointing to the checked-out revision
1174 * @param string $dir
1175 * @return array|bool
1177 public static function getSvnInfo( $dir ) {
1178 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
1179 $entries = $dir . '/.svn/entries';
1181 if ( !file_exists( $entries ) ) {
1185 $lines = file( $entries );
1186 if ( !count( $lines ) ) {
1190 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
1191 if ( preg_match( '/^<\?xml/', $lines[0] ) ) {
1192 // subversion is release <= 1.3
1193 if ( !function_exists( 'simplexml_load_file' ) ) {
1194 // We could fall back to expat... YUCK
1198 // SimpleXml whines about the xmlns...
1199 MediaWiki\
suppressWarnings();
1200 $xml = simplexml_load_file( $entries );
1201 MediaWiki\restoreWarnings
();
1204 foreach ( $xml->entry
as $entry ) {
1205 if ( $xml->entry
[0]['name'] == '' ) {
1206 // The directory entry should always have a revision marker.
1207 if ( $entry['revision'] ) {
1208 return array( 'checkout-rev' => intval( $entry['revision'] ) );
1217 // Subversion is release 1.4 or above.
1218 if ( count( $lines ) < 11 ) {
1223 'checkout-rev' => intval( trim( $lines[3] ) ),
1224 'url' => trim( $lines[4] ),
1225 'repo-url' => trim( $lines[5] ),
1226 'directory-rev' => intval( trim( $lines[10] ) )
1229 if ( isset( self
::$viewvcUrls[$info['repo-url']] ) ) {
1230 $viewvc = str_replace(
1232 self
::$viewvcUrls[$info['repo-url']],
1236 $viewvc .= '/?pathrev=';
1237 $viewvc .= urlencode( $info['checkout-rev'] );
1238 $info['viewvc-url'] = $viewvc;
1245 * Retrieve the revision number of a Subversion working directory.
1247 * @param string $dir Directory of the svn checkout
1249 * @return int Revision number
1251 public static function getSvnRevision( $dir ) {
1252 $info = self
::getSvnInfo( $dir );
1254 if ( $info === false ) {
1256 } elseif ( isset( $info['checkout-rev'] ) ) {
1257 return $info['checkout-rev'];
1264 * @param string $dir Directory of the git checkout
1265 * @return bool|string Sha1 of commit HEAD points to
1267 public static function getGitHeadSha1( $dir ) {
1268 $repo = new GitInfo( $dir );
1270 return $repo->getHeadSHA1();
1274 * @param string $dir Directory of the git checkout
1275 * @return bool|string Branch currently checked out
1277 public static function getGitCurrentBranch( $dir ) {
1278 $repo = new GitInfo( $dir );
1279 return $repo->getCurrentBranch();
1283 * Get the list of entry points and their URLs
1284 * @return string Wikitext
1286 public function getEntryPointInfo() {
1287 global $wgArticlePath, $wgScriptPath;
1288 $scriptPath = $wgScriptPath ?
$wgScriptPath : "/";
1289 $entryPoints = array(
1290 'version-entrypoints-articlepath' => $wgArticlePath,
1291 'version-entrypoints-scriptpath' => $scriptPath,
1292 'version-entrypoints-index-php' => wfScript( 'index' ),
1293 'version-entrypoints-api-php' => wfScript( 'api' ),
1294 'version-entrypoints-load-php' => wfScript( 'load' ),
1297 $language = $this->getLanguage();
1298 $thAttribures = array(
1299 'dir' => $language->getDir(),
1300 'lang' => $language->getHtmlCode()
1302 $out = Html
::element(
1304 array( 'id' => 'mw-version-entrypoints' ),
1305 $this->msg( 'version-entrypoints' )->text()
1307 Html
::openElement( 'table',
1309 'class' => 'wikitable plainlinks',
1310 'id' => 'mw-version-entrypoints-table',
1315 Html
::openElement( 'tr' ) .
1319 $this->msg( 'version-entrypoints-header-entrypoint' )->text()
1324 $this->msg( 'version-entrypoints-header-url' )->text()
1326 Html
::closeElement( 'tr' );
1328 foreach ( $entryPoints as $message => $value ) {
1329 $url = wfExpandUrl( $value, PROTO_RELATIVE
);
1330 $out .= Html
::openElement( 'tr' ) .
1331 // ->text() looks like it should be ->parse(), but this function
1332 // returns wikitext, not HTML, boo
1333 Html
::rawElement( 'td', array(), $this->msg( $message )->text() ) .
1334 Html
::rawElement( 'td', array(), Html
::rawElement( 'code', array(), "[$url $value]" ) ) .
1335 Html
::closeElement( 'tr' );
1338 $out .= Html
::closeElement( 'table' );
1343 protected function getGroupName() {