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
{
34 protected $firstExtOpened = false;
37 * Stores the current rev id/SHA hash of MediaWiki core
39 protected $coreId = '';
41 protected static $extensionTypes = false;
43 public function __construct() {
44 parent
::__construct( 'Version' );
49 * @param string|null $par
51 public function execute( $par ) {
53 $config = $this->getConfig();
54 $extensionCredits = $config->get( 'ExtensionCredits' );
57 $this->outputHeader();
58 $out = $this->getOutput();
59 $out->allowClickjacking();
61 // Explode the sub page information into useful bits
62 $parts = explode( '/', (string)$par );
64 if ( isset( $parts[1] ) ) {
65 $extName = str_replace( '_', ' ', $parts[1] );
67 foreach ( $extensionCredits as $group => $extensions ) {
68 foreach ( $extensions as $ext ) {
69 if ( isset( $ext['name'] ) && ( $ext['name'] === $extName ) ) {
76 $out->setStatusCode( 404 );
79 $extName = 'MediaWiki';
82 // Now figure out what to do
83 switch ( strtolower( $parts[0] ) ) {
85 $out->addModuleStyles( 'mediawiki.special.version' );
87 $wikiText = '{{int:version-credits-not-found}}';
88 if ( $extName === 'MediaWiki' ) {
89 $wikiText = file_get_contents( $IP . '/CREDITS' );
90 // Put the contributor list into columns
91 $wikiText = str_replace(
92 [ '<!-- BEGIN CONTRIBUTOR LIST -->', '<!-- END CONTRIBUTOR LIST -->' ],
93 [ '<div class="mw-version-credits">', '</div>' ],
95 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
96 $file = $this->getExtAuthorsFileName( dirname( $extNode['path'] ) );
98 $wikiText = file_get_contents( $file );
99 if ( substr( $file, -4 ) === '.txt' ) {
100 $wikiText = Html
::element(
112 $out->setPageTitle( $this->msg( 'version-credits-title', $extName ) );
113 $out->addWikiTextAsInterface( $wikiText );
117 $wikiText = '{{int:version-license-not-found}}';
118 if ( $extName === 'MediaWiki' ) {
119 $wikiText = file_get_contents( $IP . '/COPYING' );
120 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
121 $file = $this->getExtLicenseFileName( dirname( $extNode['path'] ) );
123 $wikiText = file_get_contents( $file );
124 $wikiText = Html
::element(
135 $out->setPageTitle( $this->msg( 'version-license-title', $extName ) );
136 $out->addWikiTextAsInterface( $wikiText );
140 $out->addModuleStyles( 'mediawiki.special.version' );
141 $out->addWikiTextAsInterface(
142 $this->getMediaWikiCredits() .
143 $this->softwareInformation() .
144 $this->getEntryPointInfo()
147 $this->getSkinCredits() .
148 $this->getExtensionCredits() .
149 $this->getExternalLibraries() .
150 $this->getParserTags() .
151 $this->getParserFunctionHooks()
153 $out->addWikiTextAsInterface( $this->getWgHooks() );
154 $out->addHTML( $this->IPInfo() );
161 * Returns wiki text showing the license information.
165 private static function getMediaWikiCredits() {
168 [ 'id' => 'mw-version-license' ],
169 wfMessage( 'version-license' )->text()
172 // This text is always left-to-right.
173 $ret .= '<div class="plainlinks">';
175 " . self
::getCopyrightAndAuthorList() . "\n
176 " . '<div class="mw-version-license-info">' .
177 wfMessage( 'version-license-info' )->text() .
181 return str_replace( "\t\t", '', $ret ) . "\n";
185 * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
189 public static function getCopyrightAndAuthorList() {
192 if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
193 $othersLink = '[https://www.mediawiki.org/wiki/Special:Version/Credits ' .
194 wfMessage( 'version-poweredby-others' )->text() . ']';
196 $othersLink = '[[Special:Version/Credits|' .
197 wfMessage( 'version-poweredby-others' )->text() . ']]';
200 $translatorsLink = '[https://translatewiki.net/wiki/Translating:MediaWiki/Credits ' .
201 wfMessage( 'version-poweredby-translators' )->text() . ']';
204 'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
205 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
206 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
207 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
208 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
209 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
210 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
211 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', 'Brad Jorsch',
212 'Bartosz Dziewoński', 'Ed Sanders', 'Moriel Schottlender',
213 'Kunal Mehta', 'James D. Forrester', 'Brian Wolff', 'Adam Shorland',
214 $othersLink, $translatorsLink
217 return wfMessage( 'version-poweredby-credits', MWTimestamp
::getLocalInstance()->format( 'Y' ),
218 $wgLang->listToText( $authorList ) )->text();
222 * Returns wiki text showing the third party software versions (apache, php, mysql).
226 public static function softwareInformation() {
227 $dbr = wfGetDB( DB_REPLICA
);
229 // Put the software in an array of form 'name' => 'version'. All messages should
230 // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
231 // wikimarkup can be used.
233 $software['[https://www.mediawiki.org/ MediaWiki]'] = self
::getVersionLinked();
235 $software['[https://hhvm.com/ HHVM]'] = HHVM_VERSION
. " (" . PHP_SAPI
. ")";
237 $software['[https://php.net/ PHP]'] = PHP_VERSION
. " (" . PHP_SAPI
. ")";
239 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
241 if ( defined( 'INTL_ICU_VERSION' ) ) {
242 $software['[http://site.icu-project.org/ ICU]'] = INTL_ICU_VERSION
;
245 // Allow a hook to add/remove items.
246 Hooks
::run( 'SoftwareInfo', [ &$software ] );
250 [ 'id' => 'mw-version-software' ],
251 wfMessage( 'version-software' )->text()
253 Xml
::openElement( 'table', [ 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ] ) .
255 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
256 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
259 foreach ( $software as $name => $version ) {
261 <td>" . $name . "</td>
262 <td dir=\"ltr\">" . $version . "</td>
266 return $out . Xml
::closeElement( 'table' );
270 * Return a string of the MediaWiki version with Git revision if available.
272 * @param string $flags
273 * @param Language|string|null $lang
276 public static function getVersion( $flags = '', $lang = null ) {
277 global $wgVersion, $IP;
279 $gitInfo = self
::getGitHeadSha1( $IP );
281 $version = $wgVersion;
282 } elseif ( $flags === 'nodb' ) {
283 $shortSha1 = substr( $gitInfo, 0, 7 );
284 $version = "$wgVersion ($shortSha1)";
286 $shortSha1 = substr( $gitInfo, 0, 7 );
287 $msg = wfMessage( 'parentheses' );
288 if ( $lang !== null ) {
289 $msg->inLanguage( $lang );
291 $shortSha1 = $msg->params( $shortSha1 )->escaped();
292 $version = "$wgVersion $shortSha1";
299 * Return a wikitext-formatted string of the MediaWiki version with a link to
300 * the Git SHA1 of head if available.
301 * The fallback is just $wgVersion
305 public static function getVersionLinked() {
308 $gitVersion = self
::getVersionLinkedGit();
312 $v = $wgVersion; // fallback
321 private static function getwgVersionLinked() {
324 if ( Hooks
::run( 'SpecialVersionVersionUrl', [ $wgVersion, &$versionUrl ] ) ) {
326 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
327 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
330 return "[$versionUrl $wgVersion]";
334 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
335 * @return bool|string Global wgVersion + HEAD sha1 stripped to the first 7 chars
336 * with link and date, or false on failure
338 private static function getVersionLinkedGit() {
341 $gitInfo = new GitInfo( $IP );
342 $headSHA1 = $gitInfo->getHeadSHA1();
347 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
349 $gitHeadUrl = $gitInfo->getHeadViewUrl();
350 if ( $gitHeadUrl !== false ) {
351 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
354 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
355 if ( $gitHeadCommitDate ) {
356 $shortSHA1 .= Html
::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true );
359 return self
::getwgVersionLinked() . " $shortSHA1";
363 * Returns an array with the base extension types.
364 * Type is stored as array key, the message as array value.
366 * TODO: ideally this would return all extension types.
372 public static function getExtensionTypes() {
373 if ( self
::$extensionTypes === false ) {
374 self
::$extensionTypes = [
375 'specialpage' => wfMessage( 'version-specialpages' )->text(),
376 'editor' => wfMessage( 'version-editors' )->text(),
377 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
378 'variable' => wfMessage( 'version-variables' )->text(),
379 'media' => wfMessage( 'version-mediahandlers' )->text(),
380 'antispam' => wfMessage( 'version-antispam' )->text(),
381 'skin' => wfMessage( 'version-skins' )->text(),
382 'api' => wfMessage( 'version-api' )->text(),
383 'other' => wfMessage( 'version-other' )->text(),
386 Hooks
::run( 'ExtensionTypes', [ &self
::$extensionTypes ] );
389 return self
::$extensionTypes;
393 * Returns the internationalized name for an extension type.
397 * @param string $type
401 public static function getExtensionTypeName( $type ) {
402 $types = self
::getExtensionTypes();
404 return $types[$type] ??
$types['other'];
408 * Generate wikitext showing the name, URL, author and description of each extension.
410 * @return string Wikitext
412 public function getExtensionCredits() {
413 $config = $this->getConfig();
414 $extensionCredits = $config->get( 'ExtensionCredits' );
417 count( $extensionCredits ) === 0 ||
418 // Skins are displayed separately, see getSkinCredits()
419 ( count( $extensionCredits ) === 1 && isset( $extensionCredits['skin'] ) )
424 $extensionTypes = self
::getExtensionTypes();
428 [ 'id' => 'mw-version-ext' ],
429 $this->msg( 'version-extensions' )->text()
431 Xml
::openElement( 'table', [ 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ] );
433 // Make sure the 'other' type is set to an array.
434 if ( !array_key_exists( 'other', $extensionCredits ) ) {
435 $extensionCredits['other'] = [];
438 // Find all extensions that do not have a valid type and give them the type 'other'.
439 foreach ( $extensionCredits as $type => $extensions ) {
440 if ( !array_key_exists( $type, $extensionTypes ) ) {
441 $extensionCredits['other'] = array_merge( $extensionCredits['other'], $extensions );
445 $this->firstExtOpened
= false;
446 // Loop through the extension categories to display their extensions in the list.
447 foreach ( $extensionTypes as $type => $message ) {
448 // Skins have a separate section
449 if ( $type !== 'other' && $type !== 'skin' ) {
450 $out .= $this->getExtensionCategory( $type, $message );
454 // We want the 'other' type to be last in the list.
455 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
457 $out .= Xml
::closeElement( 'table' );
463 * Generate wikitext showing the name, URL, author and description of each skin.
465 * @return string Wikitext
467 public function getSkinCredits() {
468 global $wgExtensionCredits;
469 if ( !isset( $wgExtensionCredits['skin'] ) ||
count( $wgExtensionCredits['skin'] ) === 0 ) {
475 [ 'id' => 'mw-version-skin' ],
476 $this->msg( 'version-skins' )->text()
478 Xml
::openElement( 'table', [ 'class' => 'wikitable plainlinks', 'id' => 'sv-skin' ] );
480 $this->firstExtOpened
= false;
481 $out .= $this->getExtensionCategory( 'skin', null );
483 $out .= Xml
::closeElement( 'table' );
489 * Generate an HTML table for external libraries that are installed
493 protected function getExternalLibraries() {
495 $path = "$IP/vendor/composer/installed.json";
496 if ( !file_exists( $path ) ) {
500 $installed = new ComposerInstalled( $path );
501 $out = Html
::element(
503 [ 'id' => 'mw-version-libraries' ],
504 $this->msg( 'version-libraries' )->text()
506 $out .= Html
::openElement(
508 [ 'class' => 'wikitable plainlinks', 'id' => 'sv-libraries' ]
510 $out .= Html
::openElement( 'tr' )
511 . Html
::element( 'th', [], $this->msg( 'version-libraries-library' )->text() )
512 . Html
::element( 'th', [], $this->msg( 'version-libraries-version' )->text() )
513 . Html
::element( 'th', [], $this->msg( 'version-libraries-license' )->text() )
514 . Html
::element( 'th', [], $this->msg( 'version-libraries-description' )->text() )
515 . Html
::element( 'th', [], $this->msg( 'version-libraries-authors' )->text() )
516 . Html
::closeElement( 'tr' );
518 foreach ( $installed->getInstalledDependencies() as $name => $info ) {
519 if ( strpos( $info['type'], 'mediawiki-' ) === 0 ) {
520 // Skip any extensions or skins since they'll be listed
521 // in their proper section
524 $authors = array_map( function ( $arr ) {
525 // If a homepage is set, link to it
526 if ( isset( $arr['homepage'] ) ) {
527 return "[{$arr['homepage']} {$arr['name']}]";
530 }, $info['authors'] );
531 $authors = $this->listAuthors( $authors, false, "$IP/vendor/$name" );
533 // We can safely assume that the libraries' names and descriptions
534 // are written in English and aren't going to be translated,
535 // so set appropriate lang and dir attributes
536 $out .= Html
::openElement( 'tr' )
540 Linker
::makeExternalLink(
541 "https://packagist.org/packages/$name", $name,
543 [ 'class' => 'mw-version-library-name' ]
546 . Html
::element( 'td', [ 'dir' => 'auto' ], $info['version'] )
547 . Html
::element( 'td', [ 'dir' => 'auto' ], $this->listToText( $info['licenses'] ) )
548 . Html
::element( 'td', [ 'lang' => 'en', 'dir' => 'ltr' ], $info['description'] )
549 . Html
::rawElement( 'td', [], $authors )
550 . Html
::closeElement( 'tr' );
552 $out .= Html
::closeElement( 'table' );
558 * Obtains a list of installed parser tags and the associated H2 header
560 * @return string HTML output
562 protected function getParserTags() {
563 $tags = MediaWikiServices
::getInstance()->getParser()->getTags();
565 if ( count( $tags ) ) {
566 $out = Html
::rawElement(
569 'class' => 'mw-headline plainlinks',
570 'id' => 'mw-version-parser-extensiontags',
572 Linker
::makeExternalLink(
573 'https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions',
574 $this->msg( 'version-parser-extensiontags' )->parse(),
575 false /* msg()->parse() already escapes */
579 array_walk( $tags, function ( &$value ) {
580 // Bidirectional isolation improves readability in RTL wikis
581 $value = Html
::element(
583 // Prevent < and > from slipping to another line
585 'style' => 'white-space: nowrap;',
591 $out .= $this->listToText( $tags );
600 * Obtains a list of installed parser function hooks and the associated H2 header
602 * @return string HTML output
604 protected function getParserFunctionHooks() {
605 $fhooks = MediaWikiServices
::getInstance()->getParser()->getFunctionHooks();
606 if ( count( $fhooks ) ) {
607 $out = Html
::rawElement(
610 'class' => 'mw-headline plainlinks',
611 'id' => 'mw-version-parser-function-hooks',
613 Linker
::makeExternalLink(
614 'https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions',
615 $this->msg( 'version-parser-function-hooks' )->parse(),
616 false /* msg()->parse() already escapes */
620 $out .= $this->listToText( $fhooks );
629 * Creates and returns the HTML for a single extension category.
633 * @param string $type
634 * @param string $message
638 protected function getExtensionCategory( $type, $message ) {
639 $config = $this->getConfig();
640 $extensionCredits = $config->get( 'ExtensionCredits' );
644 if ( array_key_exists( $type, $extensionCredits ) && count( $extensionCredits[$type] ) > 0 ) {
645 $out .= $this->openExtType( $message, 'credits-' . $type );
647 usort( $extensionCredits[$type], [ $this, 'compare' ] );
649 foreach ( $extensionCredits[$type] as $extension ) {
650 $out .= $this->getCreditsForExtension( $type, $extension );
658 * Callback to sort extensions by type.
663 public function compare( $a, $b ) {
664 return $this->getLanguage()->lc( $a['name'] ) <=> $this->getLanguage()->lc( $b['name'] );
668 * Creates and formats a version line for a single extension.
670 * Information for five columns will be created. Parameters required in the
671 * $extension array for part rendering are indicated in ()
672 * - The name of (name), and URL link to (url), the extension
673 * - Official version number (version) and if available version control system
674 * revision (path), link, and date
675 * - If available the short name of the license (license-name) and a link
676 * to ((LICENSE)|(COPYING))(\.txt)? if it exists.
677 * - Description of extension (descriptionmsg or description)
678 * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
680 * @param string $type Category name of the extension
681 * @param array $extension
683 * @return string Raw HTML
685 public function getCreditsForExtension( $type, array $extension ) {
686 $out = $this->getOutput();
688 // We must obtain the information for all the bits and pieces!
689 // ... such as extension names and links
690 if ( isset( $extension['namemsg'] ) ) {
691 // Localized name of extension
692 $extensionName = $this->msg( $extension['namemsg'] )->text();
693 } elseif ( isset( $extension['name'] ) ) {
694 // Non localized version
695 $extensionName = $extension['name'];
697 $extensionName = $this->msg( 'version-no-ext-name' )->text();
700 if ( isset( $extension['url'] ) ) {
701 $extensionNameLink = Linker
::makeExternalLink(
706 [ 'class' => 'mw-version-ext-name' ]
709 $extensionNameLink = htmlspecialchars( $extensionName );
712 // ... and the version information
713 // If the extension path is set we will check that directory for GIT
714 // metadata in an attempt to extract date and vcs commit metadata.
715 $canonicalVersion = '–';
716 $extensionPath = null;
721 if ( isset( $extension['version'] ) ) {
722 $canonicalVersion = $out->parseInlineAsInterface( $extension['version'] );
725 if ( isset( $extension['path'] ) ) {
727 $extensionPath = dirname( $extension['path'] );
728 if ( $this->coreId
== '' ) {
729 wfDebug( 'Looking up core head id' );
730 $coreHeadSHA1 = self
::getGitHeadSha1( $IP );
731 if ( $coreHeadSHA1 ) {
732 $this->coreId
= $coreHeadSHA1;
735 $cache = wfGetCache( CACHE_ANYTHING
);
736 $memcKey = $cache->makeKey(
737 'specialversion-ext-version-text', $extension['path'], $this->coreId
739 list( $vcsVersion, $vcsLink, $vcsDate ) = $cache->get( $memcKey );
741 if ( !$vcsVersion ) {
742 wfDebug( "Getting VCS info for extension {$extension['name']}" );
743 $gitInfo = new GitInfo( $extensionPath );
744 $vcsVersion = $gitInfo->getHeadSHA1();
745 if ( $vcsVersion !== false ) {
746 $vcsVersion = substr( $vcsVersion, 0, 7 );
747 $vcsLink = $gitInfo->getHeadViewUrl();
748 $vcsDate = $gitInfo->getHeadCommitDate();
750 $cache->set( $memcKey, [ $vcsVersion, $vcsLink, $vcsDate ], 60 * 60 * 24 );
752 wfDebug( "Pulled VCS info for extension {$extension['name']} from cache" );
756 $versionString = Html
::rawElement(
758 [ 'class' => 'mw-version-ext-version' ],
764 $vcsVerString = Linker
::makeExternalLink(
766 $this->msg( 'version-version', $vcsVersion ),
769 [ 'class' => 'mw-version-ext-vcs-version' ]
772 $vcsVerString = Html
::element( 'span',
773 [ 'class' => 'mw-version-ext-vcs-version' ],
777 $versionString .= " {$vcsVerString}";
780 $vcsTimeString = Html
::element( 'span',
781 [ 'class' => 'mw-version-ext-vcs-timestamp' ],
782 $this->getLanguage()->timeanddate( $vcsDate, true )
784 $versionString .= " {$vcsTimeString}";
786 $versionString = Html
::rawElement( 'span',
787 [ 'class' => 'mw-version-ext-meta-version' ],
792 // ... and license information; if a license file exists we
795 if ( isset( $extension['name'] ) ) {
797 if ( isset( $extension['license-name'] ) ) {
798 $licenseName = new HtmlArmor( $out->parseInlineAsInterface( $extension['license-name'] ) );
799 } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
800 $licenseName = $this->msg( 'version-ext-license' )->text();
802 if ( $licenseName !== null ) {
803 $licenseLink = $this->getLinkRenderer()->makeLink(
804 $this->getPageTitle( 'License/' . $extension['name'] ),
807 'class' => 'mw-version-ext-license',
814 // ... and generate the description; which can be a parameterized l10n message
815 // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
817 if ( isset( $extension['descriptionmsg'] ) ) {
818 // Localized description of extension
819 $descriptionMsg = $extension['descriptionmsg'];
821 if ( is_array( $descriptionMsg ) ) {
822 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
823 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
824 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
825 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
827 $description = $this->msg( $descriptionMsg )->text();
829 } elseif ( isset( $extension['description'] ) ) {
830 // Non localized version
831 $description = $extension['description'];
835 $description = $out->parseInlineAsInterface( $description );
837 // ... now get the authors for this extension
838 $authors = $extension['author'] ??
[];
839 $authors = $this->listAuthors( $authors, $extension['name'], $extensionPath );
841 // Finally! Create the table
842 $html = Html
::openElement( 'tr', [
843 'class' => 'mw-version-ext',
844 'id' => Sanitizer
::escapeIdForAttribute( 'mw-version-ext-' . $type . '-' . $extension['name'] )
848 $html .= Html
::rawElement( 'td', [], $extensionNameLink );
849 $html .= Html
::rawElement( 'td', [], $versionString );
850 $html .= Html
::rawElement( 'td', [], $licenseLink );
851 $html .= Html
::rawElement( 'td', [ 'class' => 'mw-version-ext-description' ], $description );
852 $html .= Html
::rawElement( 'td', [ 'class' => 'mw-version-ext-authors' ], $authors );
854 $html .= Html
::closeElement( 'tr' );
860 * Generate wikitext showing hooks in $wgHooks.
862 * @return string Wikitext
864 private function getWgHooks() {
865 global $wgSpecialVersionShowHooks, $wgHooks;
867 if ( $wgSpecialVersionShowHooks && count( $wgHooks ) ) {
868 $myWgHooks = $wgHooks;
872 $ret[] = '== {{int:version-hooks}} ==';
873 $ret[] = Html
::openElement( 'table', [ 'class' => 'wikitable', 'id' => 'sv-hooks' ] );
874 $ret[] = Html
::openElement( 'tr' );
875 $ret[] = Html
::element( 'th', [], $this->msg( 'version-hook-name' )->text() );
876 $ret[] = Html
::element( 'th', [], $this->msg( 'version-hook-subscribedby' )->text() );
877 $ret[] = Html
::closeElement( 'tr' );
879 foreach ( $myWgHooks as $hook => $hooks ) {
880 $ret[] = Html
::openElement( 'tr' );
881 $ret[] = Html
::element( 'td', [], $hook );
882 $ret[] = Html
::element( 'td', [], $this->listToText( $hooks ) );
883 $ret[] = Html
::closeElement( 'tr' );
886 $ret[] = Html
::closeElement( 'table' );
888 return implode( "\n", $ret );
894 private function openExtType( $text = null, $name = null ) {
897 $opt = [ 'colspan' => 5 ];
898 if ( $this->firstExtOpened
) {
899 // Insert a spacing line
900 $out .= Html
::rawElement( 'tr', [ 'class' => 'sv-space' ],
901 Html
::element( 'td', $opt )
904 $this->firstExtOpened
= true;
907 $opt['id'] = "sv-$name";
910 if ( $text !== null ) {
911 $out .= Html
::rawElement( 'tr', [],
912 Html
::element( 'th', $opt, $text )
916 $firstHeadingMsg = ( $name === 'credits-skin' )
917 ?
'version-skin-colheader-name'
918 : 'version-ext-colheader-name';
919 $out .= Html
::openElement( 'tr' );
920 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
921 $this->msg( $firstHeadingMsg )->text() );
922 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
923 $this->msg( 'version-ext-colheader-version' )->text() );
924 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
925 $this->msg( 'version-ext-colheader-license' )->text() );
926 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
927 $this->msg( 'version-ext-colheader-description' )->text() );
928 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
929 $this->msg( 'version-ext-colheader-credits' )->text() );
930 $out .= Html
::closeElement( 'tr' );
936 * Get information about client's IP address.
938 * @return string HTML fragment
940 private function IPInfo() {
941 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
943 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
947 * Return a formatted unsorted list of authors
950 * If an item in the $authors array is '...' it is assumed to indicate an
951 * 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
952 * file if it exists in $dir.
954 * Similarly an entry ending with ' ...]' is assumed to be a link to an
957 * If no '...' string variant is found, but an authors file is found an
958 * 'and others' will be added to the end of the credits.
960 * @param string|array $authors
961 * @param string|bool $extName Name of the extension for link creation,
962 * false if no links should be created
963 * @param string $extDir Path to the extension root directory
965 * @return string HTML fragment
967 public function listAuthors( $authors, $extName, $extDir ) {
969 $linkRenderer = $this->getLinkRenderer();
972 foreach ( (array)$authors as $item ) {
973 if ( $item == '...' ) {
976 if ( $extName && $this->getExtAuthorsFileName( $extDir ) ) {
977 $text = $linkRenderer->makeLink(
978 $this->getPageTitle( "Credits/$extName" ),
979 $this->msg( 'version-poweredby-others' )->text()
982 $text = $this->msg( 'version-poweredby-others' )->escaped();
985 } elseif ( substr( $item, -5 ) == ' ...]' ) {
987 $list[] = $this->getOutput()->parseInlineAsInterface(
988 substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
991 $list[] = $this->getOutput()->parseInlineAsInterface( $item );
995 if ( $extName && !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
996 $list[] = $text = $linkRenderer->makeLink(
997 $this->getPageTitle( "Credits/$extName" ),
998 $this->msg( 'version-poweredby-others' )->text()
1002 return $this->listToText( $list, false );
1006 * Obtains the full path of an extensions authors or credits file if
1009 * @param string $extDir Path to the extensions root directory
1013 * @return bool|string False if no such file exists, otherwise returns
1016 public static function getExtAuthorsFileName( $extDir ) {
1021 foreach ( scandir( $extDir ) as $file ) {
1022 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
1023 if ( preg_match( '/^((AUTHORS)|(CREDITS))(\.txt|\.wiki|\.mediawiki)?$/', $file ) &&
1024 is_readable( $fullPath ) &&
1025 is_file( $fullPath )
1035 * Obtains the full path of an extensions copying or license file if
1038 * @param string $extDir Path to the extensions root directory
1042 * @return bool|string False if no such file exists, otherwise returns
1045 public static function getExtLicenseFileName( $extDir ) {
1050 foreach ( scandir( $extDir ) as $file ) {
1051 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
1052 if ( preg_match( '/^((COPYING)|(LICENSE))(\.txt)?$/', $file ) &&
1053 is_readable( $fullPath ) &&
1054 is_file( $fullPath )
1064 * Convert an array of items into a list for display.
1066 * @param array $list List of elements to display
1067 * @param bool $sort Whether to sort the items in $list
1071 public function listToText( $list, $sort = true ) {
1072 if ( !count( $list ) ) {
1079 return $this->getLanguage()
1080 ->listToText( array_map( [ __CLASS__
, 'arrayToString' ], $list ) );
1084 * Convert an array or object to a string for display.
1086 * @param mixed $list Will convert an array to string if given and return
1087 * the parameter unaltered otherwise
1091 public static function arrayToString( $list ) {
1092 if ( is_array( $list ) && count( $list ) == 1 ) {
1095 if ( $list instanceof Closure
) {
1096 // Don't output stuff like "Closure$;1028376090#8$48499d94fe0147f7c633b365be39952b$"
1098 } elseif ( is_object( $list ) ) {
1099 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
1102 } elseif ( !is_array( $list ) ) {
1105 if ( is_object( $list[0] ) ) {
1106 $class = get_class( $list[0] );
1111 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
1116 * @param string $dir Directory of the git checkout
1117 * @return bool|string Sha1 of commit HEAD points to
1119 public static function getGitHeadSha1( $dir ) {
1120 $repo = new GitInfo( $dir );
1122 return $repo->getHeadSHA1();
1126 * @param string $dir Directory of the git checkout
1127 * @return bool|string Branch currently checked out
1129 public static function getGitCurrentBranch( $dir ) {
1130 $repo = new GitInfo( $dir );
1131 return $repo->getCurrentBranch();
1135 * Get the list of entry points and their URLs
1136 * @return string Wikitext
1138 public function getEntryPointInfo() {
1139 $config = $this->getConfig();
1140 $scriptPath = $config->get( 'ScriptPath' ) ?
: '/';
1143 'version-entrypoints-articlepath' => $config->get( 'ArticlePath' ),
1144 'version-entrypoints-scriptpath' => $scriptPath,
1145 'version-entrypoints-index-php' => wfScript( 'index' ),
1146 'version-entrypoints-api-php' => wfScript( 'api' ),
1147 'version-entrypoints-load-php' => wfScript( 'load' ),
1150 $language = $this->getLanguage();
1152 'dir' => $language->getDir(),
1153 'lang' => $language->getHtmlCode()
1155 $out = Html
::element(
1157 [ 'id' => 'mw-version-entrypoints' ],
1158 $this->msg( 'version-entrypoints' )->text()
1160 Html
::openElement( 'table',
1162 'class' => 'wikitable plainlinks',
1163 'id' => 'mw-version-entrypoints-table',
1168 Html
::openElement( 'tr' ) .
1172 $this->msg( 'version-entrypoints-header-entrypoint' )->text()
1177 $this->msg( 'version-entrypoints-header-url' )->text()
1179 Html
::closeElement( 'tr' );
1181 foreach ( $entryPoints as $message => $value ) {
1182 $url = wfExpandUrl( $value, PROTO_RELATIVE
);
1183 $out .= Html
::openElement( 'tr' ) .
1184 // ->plain() looks like it should be ->parse(), but this function
1185 // returns wikitext, not HTML, boo
1186 Html
::rawElement( 'td', [], $this->msg( $message )->plain() ) .
1187 Html
::rawElement( 'td', [], Html
::rawElement( 'code', [], "[$url $value]" ) ) .
1188 Html
::closeElement( 'tr' );
1191 $out .= Html
::closeElement( 'table' );
1196 protected function getGroupName() {