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
26 use MediaWiki\MediaWikiServices
;
29 * Give information about the version of MediaWiki, PHP, the DB and extensions
31 * @ingroup SpecialPage
33 class SpecialVersion
extends SpecialPage
{
38 protected $firstExtOpened = false;
41 * @var string The current rev id/SHA hash of MediaWiki core
43 protected $coreId = '';
46 * @var string[]|false Lazy initialized key/value with message content
48 protected static $extensionTypes = false;
50 public function __construct() {
51 parent
::__construct( 'Version' );
56 * @param string|null $par
58 public function execute( $par ) {
60 $config = $this->getConfig();
61 $extensionCredits = $config->get( 'ExtensionCredits' );
64 $this->outputHeader();
65 $out = $this->getOutput();
66 $out->allowClickjacking();
68 // Explode the sub page information into useful bits
69 $parts = explode( '/', (string)$par );
71 if ( isset( $parts[1] ) ) {
72 $extName = str_replace( '_', ' ', $parts[1] );
74 foreach ( $extensionCredits as $group => $extensions ) {
75 foreach ( $extensions as $ext ) {
76 if ( isset( $ext['name'] ) && ( $ext['name'] === $extName ) ) {
83 $out->setStatusCode( 404 );
86 $extName = 'MediaWiki';
89 // Now figure out what to do
90 switch ( strtolower( $parts[0] ) ) {
92 $out->addModuleStyles( 'mediawiki.special.version' );
94 $wikiText = '{{int:version-credits-not-found}}';
95 if ( $extName === 'MediaWiki' ) {
96 $wikiText = file_get_contents( $IP . '/CREDITS' );
97 // Put the contributor list into columns
98 $wikiText = str_replace(
99 [ '<!-- BEGIN CONTRIBUTOR LIST -->', '<!-- END CONTRIBUTOR LIST -->' ],
100 [ '<div class="mw-version-credits">', '</div>' ],
102 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
103 $file = $this->getExtAuthorsFileName( dirname( $extNode['path'] ) );
105 $wikiText = file_get_contents( $file );
106 if ( substr( $file, -4 ) === '.txt' ) {
107 $wikiText = Html
::element(
119 $out->setPageTitle( $this->msg( 'version-credits-title', $extName ) );
120 $out->addWikiTextAsInterface( $wikiText );
124 $wikiText = '{{int:version-license-not-found}}';
125 if ( $extName === 'MediaWiki' ) {
126 $wikiText = file_get_contents( $IP . '/COPYING' );
127 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
128 $file = $this->getExtLicenseFileName( dirname( $extNode['path'] ) );
130 $wikiText = file_get_contents( $file );
131 $wikiText = Html
::element(
142 $out->setPageTitle( $this->msg( 'version-license-title', $extName ) );
143 $out->addWikiTextAsInterface( $wikiText );
147 $out->addModuleStyles( 'mediawiki.special.version' );
148 $out->addWikiTextAsInterface(
149 $this->getMediaWikiCredits() .
150 $this->softwareInformation() .
151 $this->getEntryPointInfo()
154 $this->getSkinCredits() .
155 $this->getExtensionCredits() .
156 $this->getExternalLibraries() .
157 $this->getParserTags() .
158 $this->getParserFunctionHooks()
160 $out->addWikiTextAsInterface( $this->getWgHooks() );
161 $out->addHTML( $this->IPInfo() );
168 * Returns wiki text showing the license information.
172 private static function getMediaWikiCredits() {
175 [ 'id' => 'mw-version-license' ],
176 wfMessage( 'version-license' )->text()
179 // This text is always left-to-right.
180 $ret .= '<div class="plainlinks">';
182 " . self
::getCopyrightAndAuthorList() . "\n
183 " . '<div class="mw-version-license-info">' .
184 wfMessage( 'version-license-info' )->text() .
188 return str_replace( "\t\t", '', $ret ) . "\n";
192 * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
196 public static function getCopyrightAndAuthorList() {
199 if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
200 $othersLink = '[https://www.mediawiki.org/wiki/Special:Version/Credits ' .
201 wfMessage( 'version-poweredby-others' )->text() . ']';
203 $othersLink = '[[Special:Version/Credits|' .
204 wfMessage( 'version-poweredby-others' )->text() . ']]';
207 $translatorsLink = '[https://translatewiki.net/wiki/Translating:MediaWiki/Credits ' .
208 wfMessage( 'version-poweredby-translators' )->text() . ']';
211 'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
212 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
213 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
214 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
215 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
216 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
217 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
218 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', 'Brad Jorsch',
219 'Bartosz Dziewoński', 'Ed Sanders', 'Moriel Schottlender',
220 'Kunal Mehta', 'James D. Forrester', 'Brian Wolff', 'Adam Shorland',
221 $othersLink, $translatorsLink
224 return wfMessage( 'version-poweredby-credits', MWTimestamp
::getLocalInstance()->format( 'Y' ),
225 $wgLang->listToText( $authorList ) )->text();
233 public static function getSoftwareInformation() {
234 $dbr = wfGetDB( DB_REPLICA
);
236 // Put the software in an array of form 'name' => 'version'. All messages should
237 // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
238 // wikimarkup can be used.
240 '[https://www.mediawiki.org/ MediaWiki]' => self
::getVersionLinked()
244 $software['[https://hhvm.com/ HHVM]'] = HHVM_VERSION
. " (" . PHP_SAPI
. ")";
246 $software['[https://php.net/ PHP]'] = PHP_VERSION
. " (" . PHP_SAPI
. ")";
249 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
251 if ( defined( 'INTL_ICU_VERSION' ) ) {
252 $software['[http://site.icu-project.org/ ICU]'] = INTL_ICU_VERSION
;
255 // Allow a hook to add/remove items.
256 Hooks
::run( 'SoftwareInfo', [ &$software ] );
262 * Returns HTML showing the third party software versions (apache, php, mysql).
264 * @return string HTML table
266 public static function softwareInformation() {
269 [ 'id' => 'mw-version-software' ],
270 wfMessage( 'version-software' )->text()
272 Xml
::openElement( 'table', [ 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ] ) .
274 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
275 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
278 foreach ( self
::getSoftwareInformation() as $name => $version ) {
280 <td>" . $name . "</td>
281 <td dir=\"ltr\">" . $version . "</td>
285 return $out . Xml
::closeElement( 'table' );
289 * Return a string of the MediaWiki version with Git revision if available.
291 * @param string $flags
292 * @param Language|string|null $lang
295 public static function getVersion( $flags = '', $lang = null ) {
296 global $wgVersion, $IP;
298 $gitInfo = self
::getGitHeadSha1( $IP );
300 $version = $wgVersion;
301 } elseif ( $flags === 'nodb' ) {
302 $shortSha1 = substr( $gitInfo, 0, 7 );
303 $version = "$wgVersion ($shortSha1)";
305 $shortSha1 = substr( $gitInfo, 0, 7 );
306 $msg = wfMessage( 'parentheses' );
307 if ( $lang !== null ) {
308 $msg->inLanguage( $lang );
310 $shortSha1 = $msg->params( $shortSha1 )->escaped();
311 $version = "$wgVersion $shortSha1";
318 * Return a wikitext-formatted string of the MediaWiki version with a link to
319 * the Git SHA1 of head if available.
320 * The fallback is just $wgVersion
324 public static function getVersionLinked() {
327 $gitVersion = self
::getVersionLinkedGit();
331 $v = $wgVersion; // fallback
340 private static function getwgVersionLinked() {
343 if ( Hooks
::run( 'SpecialVersionVersionUrl', [ $wgVersion, &$versionUrl ] ) ) {
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() {
360 $gitInfo = new GitInfo( $IP );
361 $headSHA1 = $gitInfo->getHeadSHA1();
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.
391 public static function getExtensionTypes() {
392 if ( self
::$extensionTypes === false ) {
393 self
::$extensionTypes = [
394 'specialpage' => wfMessage( 'version-specialpages' )->text(),
395 'editor' => wfMessage( 'version-editors' )->text(),
396 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
397 'variable' => wfMessage( 'version-variables' )->text(),
398 'media' => wfMessage( 'version-mediahandlers' )->text(),
399 'antispam' => wfMessage( 'version-antispam' )->text(),
400 'skin' => wfMessage( 'version-skins' )->text(),
401 'api' => wfMessage( 'version-api' )->text(),
402 'other' => wfMessage( 'version-other' )->text(),
405 Hooks
::run( 'ExtensionTypes', [ &self
::$extensionTypes ] );
408 return self
::$extensionTypes;
412 * Returns the internationalized name for an extension type.
416 * @param string $type
420 public static function getExtensionTypeName( $type ) {
421 $types = self
::getExtensionTypes();
423 return $types[$type] ??
$types['other'];
427 * Generate wikitext showing the name, URL, author and description of each extension.
429 * @return string Wikitext
431 public function getExtensionCredits() {
432 $config = $this->getConfig();
433 $extensionCredits = $config->get( 'ExtensionCredits' );
436 count( $extensionCredits ) === 0 ||
437 // Skins are displayed separately, see getSkinCredits()
438 ( count( $extensionCredits ) === 1 && isset( $extensionCredits['skin'] ) )
443 $extensionTypes = self
::getExtensionTypes();
447 [ 'id' => 'mw-version-ext' ],
448 $this->msg( 'version-extensions' )->text()
450 Xml
::openElement( 'table', [ 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ] );
452 // Make sure the 'other' type is set to an array.
453 if ( !array_key_exists( 'other', $extensionCredits ) ) {
454 $extensionCredits['other'] = [];
457 // Find all extensions that do not have a valid type and give them the type 'other'.
458 foreach ( $extensionCredits as $type => $extensions ) {
459 if ( !array_key_exists( $type, $extensionTypes ) ) {
460 $extensionCredits['other'] = array_merge( $extensionCredits['other'], $extensions );
464 $this->firstExtOpened
= false;
465 // Loop through the extension categories to display their extensions in the list.
466 foreach ( $extensionTypes as $type => $message ) {
467 // Skins have a separate section
468 if ( $type !== 'other' && $type !== 'skin' ) {
469 $out .= $this->getExtensionCategory( $type, $message );
473 // We want the 'other' type to be last in the list.
474 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
476 $out .= Xml
::closeElement( 'table' );
482 * Generate wikitext showing the name, URL, author and description of each skin.
484 * @return string Wikitext
486 public function getSkinCredits() {
487 global $wgExtensionCredits;
488 if ( !isset( $wgExtensionCredits['skin'] ) ||
count( $wgExtensionCredits['skin'] ) === 0 ) {
494 [ 'id' => 'mw-version-skin' ],
495 $this->msg( 'version-skins' )->text()
497 Xml
::openElement( 'table', [ 'class' => 'wikitable plainlinks', 'id' => 'sv-skin' ] );
499 $this->firstExtOpened
= false;
500 $out .= $this->getExtensionCategory( 'skin', null );
502 $out .= Xml
::closeElement( 'table' );
508 * Generate an HTML table for external libraries that are installed
512 protected function getExternalLibraries() {
514 $path = "$IP/vendor/composer/installed.json";
515 if ( !file_exists( $path ) ) {
519 $installed = new ComposerInstalled( $path );
520 $out = Html
::element(
522 [ 'id' => 'mw-version-libraries' ],
523 $this->msg( 'version-libraries' )->text()
525 $out .= Html
::openElement(
527 [ 'class' => 'wikitable plainlinks', 'id' => 'sv-libraries' ]
529 $out .= Html
::openElement( 'tr' )
530 . Html
::element( 'th', [], $this->msg( 'version-libraries-library' )->text() )
531 . Html
::element( 'th', [], $this->msg( 'version-libraries-version' )->text() )
532 . Html
::element( 'th', [], $this->msg( 'version-libraries-license' )->text() )
533 . Html
::element( 'th', [], $this->msg( 'version-libraries-description' )->text() )
534 . Html
::element( 'th', [], $this->msg( 'version-libraries-authors' )->text() )
535 . Html
::closeElement( 'tr' );
537 foreach ( $installed->getInstalledDependencies() as $name => $info ) {
538 if ( strpos( $info['type'], 'mediawiki-' ) === 0 ) {
539 // Skip any extensions or skins since they'll be listed
540 // in their proper section
543 $authors = array_map( function ( $arr ) {
544 // If a homepage is set, link to it
545 if ( isset( $arr['homepage'] ) ) {
546 return "[{$arr['homepage']} {$arr['name']}]";
549 }, $info['authors'] );
550 $authors = $this->listAuthors( $authors, false, "$IP/vendor/$name" );
552 // We can safely assume that the libraries' names and descriptions
553 // are written in English and aren't going to be translated,
554 // so set appropriate lang and dir attributes
555 $out .= Html
::openElement( 'tr' )
559 Linker
::makeExternalLink(
560 "https://packagist.org/packages/$name", $name,
562 [ 'class' => 'mw-version-library-name' ]
565 . Html
::element( 'td', [ 'dir' => 'auto' ], $info['version'] )
566 . Html
::element( 'td', [ 'dir' => 'auto' ], $this->listToText( $info['licenses'] ) )
567 . Html
::element( 'td', [ 'lang' => 'en', 'dir' => 'ltr' ], $info['description'] )
568 . Html
::rawElement( 'td', [], $authors )
569 . Html
::closeElement( 'tr' );
571 $out .= Html
::closeElement( 'table' );
577 * Obtains a list of installed parser tags and the associated H2 header
579 * @return string HTML output
581 protected function getParserTags() {
582 $tags = MediaWikiServices
::getInstance()->getParser()->getTags();
584 if ( count( $tags ) ) {
585 $out = Html
::rawElement(
588 'class' => 'mw-headline plainlinks',
589 'id' => 'mw-version-parser-extensiontags',
591 Linker
::makeExternalLink(
592 'https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions',
593 $this->msg( 'version-parser-extensiontags' )->parse(),
594 false /* msg()->parse() already escapes */
598 array_walk( $tags, function ( &$value ) {
599 // Bidirectional isolation improves readability in RTL wikis
600 $value = Html
::element(
602 // Prevent < and > from slipping to another line
604 'style' => 'white-space: nowrap;',
610 $out .= $this->listToText( $tags );
619 * Obtains a list of installed parser function hooks and the associated H2 header
621 * @return string HTML output
623 protected function getParserFunctionHooks() {
624 $fhooks = MediaWikiServices
::getInstance()->getParser()->getFunctionHooks();
625 if ( count( $fhooks ) ) {
626 $out = Html
::rawElement(
629 'class' => 'mw-headline plainlinks',
630 'id' => 'mw-version-parser-function-hooks',
632 Linker
::makeExternalLink(
633 'https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions',
634 $this->msg( 'version-parser-function-hooks' )->parse(),
635 false /* msg()->parse() already escapes */
639 $out .= $this->listToText( $fhooks );
648 * Creates and returns the HTML for a single extension category.
652 * @param string $type
653 * @param string $message
657 protected function getExtensionCategory( $type, $message ) {
658 $config = $this->getConfig();
659 $extensionCredits = $config->get( 'ExtensionCredits' );
663 if ( array_key_exists( $type, $extensionCredits ) && count( $extensionCredits[$type] ) > 0 ) {
664 $out .= $this->openExtType( $message, 'credits-' . $type );
666 usort( $extensionCredits[$type], [ $this, 'compare' ] );
668 foreach ( $extensionCredits[$type] as $extension ) {
669 $out .= $this->getCreditsForExtension( $type, $extension );
677 * Callback to sort extensions by type.
682 public function compare( $a, $b ) {
683 return $this->getLanguage()->lc( $a['name'] ) <=> $this->getLanguage()->lc( $b['name'] );
687 * Creates and formats a version line for a single extension.
689 * Information for five columns will be created. Parameters required in the
690 * $extension array for part rendering are indicated in ()
691 * - The name of (name), and URL link to (url), the extension
692 * - Official version number (version) and if available version control system
693 * revision (path), link, and date
694 * - If available the short name of the license (license-name) and a link
695 * to ((LICENSE)|(COPYING))(\.txt)? if it exists.
696 * - Description of extension (descriptionmsg or description)
697 * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
699 * @param string $type Category name of the extension
700 * @param array $extension
702 * @return string Raw HTML
704 public function getCreditsForExtension( $type, array $extension ) {
705 $out = $this->getOutput();
707 // We must obtain the information for all the bits and pieces!
708 // ... such as extension names and links
709 if ( isset( $extension['namemsg'] ) ) {
710 // Localized name of extension
711 $extensionName = $this->msg( $extension['namemsg'] )->text();
712 } elseif ( isset( $extension['name'] ) ) {
713 // Non localized version
714 $extensionName = $extension['name'];
716 $extensionName = $this->msg( 'version-no-ext-name' )->text();
719 if ( isset( $extension['url'] ) ) {
720 $extensionNameLink = Linker
::makeExternalLink(
725 [ 'class' => 'mw-version-ext-name' ]
728 $extensionNameLink = htmlspecialchars( $extensionName );
731 // ... and the version information
732 // If the extension path is set we will check that directory for GIT
733 // metadata in an attempt to extract date and vcs commit metadata.
734 $canonicalVersion = '–';
735 $extensionPath = null;
740 if ( isset( $extension['version'] ) ) {
741 $canonicalVersion = $out->parseInlineAsInterface( $extension['version'] );
744 if ( isset( $extension['path'] ) ) {
746 $extensionPath = dirname( $extension['path'] );
747 if ( $this->coreId
== '' ) {
748 wfDebug( 'Looking up core head id' );
749 $coreHeadSHA1 = self
::getGitHeadSha1( $IP );
750 if ( $coreHeadSHA1 ) {
751 $this->coreId
= $coreHeadSHA1;
754 $cache = wfGetCache( CACHE_ANYTHING
);
755 $memcKey = $cache->makeKey(
756 'specialversion-ext-version-text', $extension['path'], $this->coreId
758 list( $vcsVersion, $vcsLink, $vcsDate ) = $cache->get( $memcKey );
760 if ( !$vcsVersion ) {
761 wfDebug( "Getting VCS info for extension {$extension['name']}" );
762 $gitInfo = new GitInfo( $extensionPath );
763 $vcsVersion = $gitInfo->getHeadSHA1();
764 if ( $vcsVersion !== false ) {
765 $vcsVersion = substr( $vcsVersion, 0, 7 );
766 $vcsLink = $gitInfo->getHeadViewUrl();
767 $vcsDate = $gitInfo->getHeadCommitDate();
769 $cache->set( $memcKey, [ $vcsVersion, $vcsLink, $vcsDate ], 60 * 60 * 24 );
771 wfDebug( "Pulled VCS info for extension {$extension['name']} from cache" );
775 $versionString = Html
::rawElement(
777 [ 'class' => 'mw-version-ext-version' ],
783 $vcsVerString = Linker
::makeExternalLink(
785 $this->msg( 'version-version', $vcsVersion ),
788 [ 'class' => 'mw-version-ext-vcs-version' ]
791 $vcsVerString = Html
::element( 'span',
792 [ 'class' => 'mw-version-ext-vcs-version' ],
796 $versionString .= " {$vcsVerString}";
799 $vcsTimeString = Html
::element( 'span',
800 [ 'class' => 'mw-version-ext-vcs-timestamp' ],
801 $this->getLanguage()->timeanddate( $vcsDate, true )
803 $versionString .= " {$vcsTimeString}";
805 $versionString = Html
::rawElement( 'span',
806 [ 'class' => 'mw-version-ext-meta-version' ],
811 // ... and license information; if a license file exists we
814 if ( isset( $extension['name'] ) ) {
816 if ( isset( $extension['license-name'] ) ) {
817 $licenseName = new HtmlArmor( $out->parseInlineAsInterface( $extension['license-name'] ) );
818 } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
819 $licenseName = $this->msg( 'version-ext-license' )->text();
821 if ( $licenseName !== null ) {
822 $licenseLink = $this->getLinkRenderer()->makeLink(
823 $this->getPageTitle( 'License/' . $extension['name'] ),
826 'class' => 'mw-version-ext-license',
833 // ... and generate the description; which can be a parameterized l10n message
834 // in the form [ <msgname>, <parameter>, <parameter>... ] or just a straight
836 if ( isset( $extension['descriptionmsg'] ) ) {
837 // Localized description of extension
838 $descriptionMsg = $extension['descriptionmsg'];
840 if ( is_array( $descriptionMsg ) ) {
841 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
842 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
843 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
844 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
846 $description = $this->msg( $descriptionMsg )->text();
848 } elseif ( isset( $extension['description'] ) ) {
849 // Non localized version
850 $description = $extension['description'];
854 $description = $out->parseInlineAsInterface( $description );
856 // ... now get the authors for this extension
857 $authors = $extension['author'] ??
[];
858 $authors = $this->listAuthors( $authors, $extension['name'], $extensionPath );
860 // Finally! Create the table
861 $html = Html
::openElement( 'tr', [
862 'class' => 'mw-version-ext',
863 'id' => Sanitizer
::escapeIdForAttribute( 'mw-version-ext-' . $type . '-' . $extension['name'] )
867 $html .= Html
::rawElement( 'td', [], $extensionNameLink );
868 $html .= Html
::rawElement( 'td', [], $versionString );
869 $html .= Html
::rawElement( 'td', [], $licenseLink );
870 $html .= Html
::rawElement( 'td', [ 'class' => 'mw-version-ext-description' ], $description );
871 $html .= Html
::rawElement( 'td', [ 'class' => 'mw-version-ext-authors' ], $authors );
873 $html .= Html
::closeElement( 'tr' );
879 * Generate wikitext showing hooks in $wgHooks.
881 * @return string Wikitext
883 private function getWgHooks() {
884 global $wgSpecialVersionShowHooks, $wgHooks;
886 if ( $wgSpecialVersionShowHooks && count( $wgHooks ) ) {
887 $myWgHooks = $wgHooks;
891 $ret[] = '== {{int:version-hooks}} ==';
892 $ret[] = Html
::openElement( 'table', [ 'class' => 'wikitable', 'id' => 'sv-hooks' ] );
893 $ret[] = Html
::openElement( 'tr' );
894 $ret[] = Html
::element( 'th', [], $this->msg( 'version-hook-name' )->text() );
895 $ret[] = Html
::element( 'th', [], $this->msg( 'version-hook-subscribedby' )->text() );
896 $ret[] = Html
::closeElement( 'tr' );
898 foreach ( $myWgHooks as $hook => $hooks ) {
899 $ret[] = Html
::openElement( 'tr' );
900 $ret[] = Html
::element( 'td', [], $hook );
901 $ret[] = Html
::element( 'td', [], $this->listToText( $hooks ) );
902 $ret[] = Html
::closeElement( 'tr' );
905 $ret[] = Html
::closeElement( 'table' );
907 return implode( "\n", $ret );
913 private function openExtType( $text = null, $name = null ) {
916 $opt = [ 'colspan' => 5 ];
917 if ( $this->firstExtOpened
) {
918 // Insert a spacing line
919 $out .= Html
::rawElement( 'tr', [ 'class' => 'sv-space' ],
920 Html
::element( 'td', $opt )
923 $this->firstExtOpened
= true;
926 $opt['id'] = "sv-$name";
929 if ( $text !== null ) {
930 $out .= Html
::rawElement( 'tr', [],
931 Html
::element( 'th', $opt, $text )
935 $firstHeadingMsg = ( $name === 'credits-skin' )
936 ?
'version-skin-colheader-name'
937 : 'version-ext-colheader-name';
938 $out .= Html
::openElement( 'tr' );
939 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
940 $this->msg( $firstHeadingMsg )->text() );
941 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
942 $this->msg( 'version-ext-colheader-version' )->text() );
943 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
944 $this->msg( 'version-ext-colheader-license' )->text() );
945 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
946 $this->msg( 'version-ext-colheader-description' )->text() );
947 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
948 $this->msg( 'version-ext-colheader-credits' )->text() );
949 $out .= Html
::closeElement( 'tr' );
955 * Get information about client's IP address.
957 * @return string HTML fragment
959 private function IPInfo() {
960 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
962 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
966 * Return a formatted unsorted list of authors
969 * If an item in the $authors array is '...' it is assumed to indicate an
970 * 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
971 * file if it exists in $dir.
973 * Similarly an entry ending with ' ...]' is assumed to be a link to an
976 * If no '...' string variant is found, but an authors file is found an
977 * 'and others' will be added to the end of the credits.
979 * @param string|array $authors
980 * @param string|bool $extName Name of the extension for link creation,
981 * false if no links should be created
982 * @param string $extDir Path to the extension root directory
984 * @return string HTML fragment
986 public function listAuthors( $authors, $extName, $extDir ) {
988 $linkRenderer = $this->getLinkRenderer();
991 foreach ( (array)$authors as $item ) {
992 if ( $item == '...' ) {
995 if ( $extName && $this->getExtAuthorsFileName( $extDir ) ) {
996 $text = $linkRenderer->makeLink(
997 $this->getPageTitle( "Credits/$extName" ),
998 $this->msg( 'version-poweredby-others' )->text()
1001 $text = $this->msg( 'version-poweredby-others' )->escaped();
1004 } elseif ( substr( $item, -5 ) == ' ...]' ) {
1006 $list[] = $this->getOutput()->parseInlineAsInterface(
1007 substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
1010 $list[] = $this->getOutput()->parseInlineAsInterface( $item );
1014 if ( $extName && !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
1015 $list[] = $text = $linkRenderer->makeLink(
1016 $this->getPageTitle( "Credits/$extName" ),
1017 $this->msg( 'version-poweredby-others' )->text()
1021 return $this->listToText( $list, false );
1025 * Obtains the full path of an extensions authors or credits file if
1028 * @param string $extDir Path to the extensions root directory
1032 * @return bool|string False if no such file exists, otherwise returns
1035 public static function getExtAuthorsFileName( $extDir ) {
1040 foreach ( scandir( $extDir ) as $file ) {
1041 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
1042 if ( preg_match( '/^((AUTHORS)|(CREDITS))(\.txt|\.wiki|\.mediawiki)?$/', $file ) &&
1043 is_readable( $fullPath ) &&
1044 is_file( $fullPath )
1054 * Obtains the full path of an extensions copying or license file if
1057 * @param string $extDir Path to the extensions root directory
1061 * @return bool|string False if no such file exists, otherwise returns
1064 public static function getExtLicenseFileName( $extDir ) {
1069 foreach ( scandir( $extDir ) as $file ) {
1070 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
1071 if ( preg_match( '/^((COPYING)|(LICENSE))(\.txt)?$/', $file ) &&
1072 is_readable( $fullPath ) &&
1073 is_file( $fullPath )
1083 * Convert an array of items into a list for display.
1085 * @param array $list List of elements to display
1086 * @param bool $sort Whether to sort the items in $list
1090 public function listToText( $list, $sort = true ) {
1091 if ( !count( $list ) ) {
1098 return $this->getLanguage()
1099 ->listToText( array_map( [ __CLASS__
, 'arrayToString' ], $list ) );
1103 * Convert an array or object to a string for display.
1105 * @param mixed $list Will convert an array to string if given and return
1106 * the parameter unaltered otherwise
1110 public static function arrayToString( $list ) {
1111 if ( is_array( $list ) && count( $list ) == 1 ) {
1114 if ( $list instanceof Closure
) {
1115 // Don't output stuff like "Closure$;1028376090#8$48499d94fe0147f7c633b365be39952b$"
1117 } elseif ( is_object( $list ) ) {
1118 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
1121 } elseif ( !is_array( $list ) ) {
1124 if ( is_object( $list[0] ) ) {
1125 $class = get_class( $list[0] );
1130 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
1135 * @param string $dir Directory of the git checkout
1136 * @return bool|string Sha1 of commit HEAD points to
1138 public static function getGitHeadSha1( $dir ) {
1139 $repo = new GitInfo( $dir );
1141 return $repo->getHeadSHA1();
1145 * @param string $dir Directory of the git checkout
1146 * @return bool|string Branch currently checked out
1148 public static function getGitCurrentBranch( $dir ) {
1149 $repo = new GitInfo( $dir );
1150 return $repo->getCurrentBranch();
1154 * Get the list of entry points and their URLs
1155 * @return string Wikitext
1157 public function getEntryPointInfo() {
1158 $config = $this->getConfig();
1159 $scriptPath = $config->get( 'ScriptPath' ) ?
: '/';
1162 'version-entrypoints-articlepath' => $config->get( 'ArticlePath' ),
1163 'version-entrypoints-scriptpath' => $scriptPath,
1164 'version-entrypoints-index-php' => wfScript( 'index' ),
1165 'version-entrypoints-api-php' => wfScript( 'api' ),
1166 'version-entrypoints-load-php' => wfScript( 'load' ),
1169 $language = $this->getLanguage();
1171 'dir' => $language->getDir(),
1172 'lang' => $language->getHtmlCode()
1174 $out = Html
::element(
1176 [ 'id' => 'mw-version-entrypoints' ],
1177 $this->msg( 'version-entrypoints' )->text()
1179 Html
::openElement( 'table',
1181 'class' => 'wikitable plainlinks',
1182 'id' => 'mw-version-entrypoints-table',
1187 Html
::openElement( 'tr' ) .
1191 $this->msg( 'version-entrypoints-header-entrypoint' )->text()
1196 $this->msg( 'version-entrypoints-header-url' )->text()
1198 Html
::closeElement( 'tr' );
1200 foreach ( $entryPoints as $message => $value ) {
1201 $url = wfExpandUrl( $value, PROTO_RELATIVE
);
1202 $out .= Html
::openElement( 'tr' ) .
1203 // ->plain() looks like it should be ->parse(), but this function
1204 // returns wikitext, not HTML, boo
1205 Html
::rawElement( 'td', [], $this->msg( $message )->plain() ) .
1206 Html
::rawElement( 'td', [], Html
::rawElement( 'code', [], "[$url $value]" ) ) .
1207 Html
::closeElement( 'tr' );
1210 $out .= Html
::closeElement( 'table' );
1215 protected function getGroupName() {