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();
226 public static function getSoftwareInformation() {
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 '[https://www.mediawiki.org/ MediaWiki]' => self
::getVersionLinked()
237 $software['[https://hhvm.com/ HHVM]'] = HHVM_VERSION
. " (" . PHP_SAPI
. ")";
239 $software['[https://php.net/ PHP]'] = PHP_VERSION
. " (" . PHP_SAPI
. ")";
242 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
244 if ( defined( 'INTL_ICU_VERSION' ) ) {
245 $software['[http://site.icu-project.org/ ICU]'] = INTL_ICU_VERSION
;
248 // Allow a hook to add/remove items.
249 Hooks
::run( 'SoftwareInfo', [ &$software ] );
255 * Returns HTML showing the third party software versions (apache, php, mysql).
257 * @return string HTML table
259 public static function softwareInformation() {
262 [ 'id' => 'mw-version-software' ],
263 wfMessage( 'version-software' )->text()
265 Xml
::openElement( 'table', [ 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ] ) .
267 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
268 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
271 foreach ( self
::getSoftwareInformation() as $name => $version ) {
273 <td>" . $name . "</td>
274 <td dir=\"ltr\">" . $version . "</td>
278 return $out . Xml
::closeElement( 'table' );
282 * Return a string of the MediaWiki version with Git revision if available.
284 * @param string $flags
285 * @param Language|string|null $lang
288 public static function getVersion( $flags = '', $lang = null ) {
289 global $wgVersion, $IP;
291 $gitInfo = self
::getGitHeadSha1( $IP );
293 $version = $wgVersion;
294 } elseif ( $flags === 'nodb' ) {
295 $shortSha1 = substr( $gitInfo, 0, 7 );
296 $version = "$wgVersion ($shortSha1)";
298 $shortSha1 = substr( $gitInfo, 0, 7 );
299 $msg = wfMessage( 'parentheses' );
300 if ( $lang !== null ) {
301 $msg->inLanguage( $lang );
303 $shortSha1 = $msg->params( $shortSha1 )->escaped();
304 $version = "$wgVersion $shortSha1";
311 * Return a wikitext-formatted string of the MediaWiki version with a link to
312 * the Git SHA1 of head if available.
313 * The fallback is just $wgVersion
317 public static function getVersionLinked() {
320 $gitVersion = self
::getVersionLinkedGit();
324 $v = $wgVersion; // fallback
333 private static function getwgVersionLinked() {
336 if ( Hooks
::run( 'SpecialVersionVersionUrl', [ $wgVersion, &$versionUrl ] ) ) {
338 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
339 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
342 return "[$versionUrl $wgVersion]";
346 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
347 * @return bool|string Global wgVersion + HEAD sha1 stripped to the first 7 chars
348 * with link and date, or false on failure
350 private static function getVersionLinkedGit() {
353 $gitInfo = new GitInfo( $IP );
354 $headSHA1 = $gitInfo->getHeadSHA1();
359 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
361 $gitHeadUrl = $gitInfo->getHeadViewUrl();
362 if ( $gitHeadUrl !== false ) {
363 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
366 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
367 if ( $gitHeadCommitDate ) {
368 $shortSHA1 .= Html
::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true );
371 return self
::getwgVersionLinked() . " $shortSHA1";
375 * Returns an array with the base extension types.
376 * Type is stored as array key, the message as array value.
378 * TODO: ideally this would return all extension types.
384 public static function getExtensionTypes() {
385 if ( self
::$extensionTypes === false ) {
386 self
::$extensionTypes = [
387 'specialpage' => wfMessage( 'version-specialpages' )->text(),
388 'editor' => wfMessage( 'version-editors' )->text(),
389 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
390 'variable' => wfMessage( 'version-variables' )->text(),
391 'media' => wfMessage( 'version-mediahandlers' )->text(),
392 'antispam' => wfMessage( 'version-antispam' )->text(),
393 'skin' => wfMessage( 'version-skins' )->text(),
394 'api' => wfMessage( 'version-api' )->text(),
395 'other' => wfMessage( 'version-other' )->text(),
398 Hooks
::run( 'ExtensionTypes', [ &self
::$extensionTypes ] );
401 return self
::$extensionTypes;
405 * Returns the internationalized name for an extension type.
409 * @param string $type
413 public static function getExtensionTypeName( $type ) {
414 $types = self
::getExtensionTypes();
416 return $types[$type] ??
$types['other'];
420 * Generate wikitext showing the name, URL, author and description of each extension.
422 * @return string Wikitext
424 public function getExtensionCredits() {
425 $config = $this->getConfig();
426 $extensionCredits = $config->get( 'ExtensionCredits' );
429 count( $extensionCredits ) === 0 ||
430 // Skins are displayed separately, see getSkinCredits()
431 ( count( $extensionCredits ) === 1 && isset( $extensionCredits['skin'] ) )
436 $extensionTypes = self
::getExtensionTypes();
440 [ 'id' => 'mw-version-ext' ],
441 $this->msg( 'version-extensions' )->text()
443 Xml
::openElement( 'table', [ 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ] );
445 // Make sure the 'other' type is set to an array.
446 if ( !array_key_exists( 'other', $extensionCredits ) ) {
447 $extensionCredits['other'] = [];
450 // Find all extensions that do not have a valid type and give them the type 'other'.
451 foreach ( $extensionCredits as $type => $extensions ) {
452 if ( !array_key_exists( $type, $extensionTypes ) ) {
453 $extensionCredits['other'] = array_merge( $extensionCredits['other'], $extensions );
457 $this->firstExtOpened
= false;
458 // Loop through the extension categories to display their extensions in the list.
459 foreach ( $extensionTypes as $type => $message ) {
460 // Skins have a separate section
461 if ( $type !== 'other' && $type !== 'skin' ) {
462 $out .= $this->getExtensionCategory( $type, $message );
466 // We want the 'other' type to be last in the list.
467 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
469 $out .= Xml
::closeElement( 'table' );
475 * Generate wikitext showing the name, URL, author and description of each skin.
477 * @return string Wikitext
479 public function getSkinCredits() {
480 global $wgExtensionCredits;
481 if ( !isset( $wgExtensionCredits['skin'] ) ||
count( $wgExtensionCredits['skin'] ) === 0 ) {
487 [ 'id' => 'mw-version-skin' ],
488 $this->msg( 'version-skins' )->text()
490 Xml
::openElement( 'table', [ 'class' => 'wikitable plainlinks', 'id' => 'sv-skin' ] );
492 $this->firstExtOpened
= false;
493 $out .= $this->getExtensionCategory( 'skin', null );
495 $out .= Xml
::closeElement( 'table' );
501 * Generate an HTML table for external libraries that are installed
505 protected function getExternalLibraries() {
507 $path = "$IP/vendor/composer/installed.json";
508 if ( !file_exists( $path ) ) {
512 $installed = new ComposerInstalled( $path );
513 $out = Html
::element(
515 [ 'id' => 'mw-version-libraries' ],
516 $this->msg( 'version-libraries' )->text()
518 $out .= Html
::openElement(
520 [ 'class' => 'wikitable plainlinks', 'id' => 'sv-libraries' ]
522 $out .= Html
::openElement( 'tr' )
523 . Html
::element( 'th', [], $this->msg( 'version-libraries-library' )->text() )
524 . Html
::element( 'th', [], $this->msg( 'version-libraries-version' )->text() )
525 . Html
::element( 'th', [], $this->msg( 'version-libraries-license' )->text() )
526 . Html
::element( 'th', [], $this->msg( 'version-libraries-description' )->text() )
527 . Html
::element( 'th', [], $this->msg( 'version-libraries-authors' )->text() )
528 . Html
::closeElement( 'tr' );
530 foreach ( $installed->getInstalledDependencies() as $name => $info ) {
531 if ( strpos( $info['type'], 'mediawiki-' ) === 0 ) {
532 // Skip any extensions or skins since they'll be listed
533 // in their proper section
536 $authors = array_map( function ( $arr ) {
537 // If a homepage is set, link to it
538 if ( isset( $arr['homepage'] ) ) {
539 return "[{$arr['homepage']} {$arr['name']}]";
542 }, $info['authors'] );
543 $authors = $this->listAuthors( $authors, false, "$IP/vendor/$name" );
545 // We can safely assume that the libraries' names and descriptions
546 // are written in English and aren't going to be translated,
547 // so set appropriate lang and dir attributes
548 $out .= Html
::openElement( 'tr' )
552 Linker
::makeExternalLink(
553 "https://packagist.org/packages/$name", $name,
555 [ 'class' => 'mw-version-library-name' ]
558 . Html
::element( 'td', [ 'dir' => 'auto' ], $info['version'] )
559 . Html
::element( 'td', [ 'dir' => 'auto' ], $this->listToText( $info['licenses'] ) )
560 . Html
::element( 'td', [ 'lang' => 'en', 'dir' => 'ltr' ], $info['description'] )
561 . Html
::rawElement( 'td', [], $authors )
562 . Html
::closeElement( 'tr' );
564 $out .= Html
::closeElement( 'table' );
570 * Obtains a list of installed parser tags and the associated H2 header
572 * @return string HTML output
574 protected function getParserTags() {
575 $tags = MediaWikiServices
::getInstance()->getParser()->getTags();
577 if ( count( $tags ) ) {
578 $out = Html
::rawElement(
581 'class' => 'mw-headline plainlinks',
582 'id' => 'mw-version-parser-extensiontags',
584 Linker
::makeExternalLink(
585 'https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions',
586 $this->msg( 'version-parser-extensiontags' )->parse(),
587 false /* msg()->parse() already escapes */
591 array_walk( $tags, function ( &$value ) {
592 // Bidirectional isolation improves readability in RTL wikis
593 $value = Html
::element(
595 // Prevent < and > from slipping to another line
597 'style' => 'white-space: nowrap;',
603 $out .= $this->listToText( $tags );
612 * Obtains a list of installed parser function hooks and the associated H2 header
614 * @return string HTML output
616 protected function getParserFunctionHooks() {
617 $fhooks = MediaWikiServices
::getInstance()->getParser()->getFunctionHooks();
618 if ( count( $fhooks ) ) {
619 $out = Html
::rawElement(
622 'class' => 'mw-headline plainlinks',
623 'id' => 'mw-version-parser-function-hooks',
625 Linker
::makeExternalLink(
626 'https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions',
627 $this->msg( 'version-parser-function-hooks' )->parse(),
628 false /* msg()->parse() already escapes */
632 $out .= $this->listToText( $fhooks );
641 * Creates and returns the HTML for a single extension category.
645 * @param string $type
646 * @param string $message
650 protected function getExtensionCategory( $type, $message ) {
651 $config = $this->getConfig();
652 $extensionCredits = $config->get( 'ExtensionCredits' );
656 if ( array_key_exists( $type, $extensionCredits ) && count( $extensionCredits[$type] ) > 0 ) {
657 $out .= $this->openExtType( $message, 'credits-' . $type );
659 usort( $extensionCredits[$type], [ $this, 'compare' ] );
661 foreach ( $extensionCredits[$type] as $extension ) {
662 $out .= $this->getCreditsForExtension( $type, $extension );
670 * Callback to sort extensions by type.
675 public function compare( $a, $b ) {
676 return $this->getLanguage()->lc( $a['name'] ) <=> $this->getLanguage()->lc( $b['name'] );
680 * Creates and formats a version line for a single extension.
682 * Information for five columns will be created. Parameters required in the
683 * $extension array for part rendering are indicated in ()
684 * - The name of (name), and URL link to (url), the extension
685 * - Official version number (version) and if available version control system
686 * revision (path), link, and date
687 * - If available the short name of the license (license-name) and a link
688 * to ((LICENSE)|(COPYING))(\.txt)? if it exists.
689 * - Description of extension (descriptionmsg or description)
690 * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
692 * @param string $type Category name of the extension
693 * @param array $extension
695 * @return string Raw HTML
697 public function getCreditsForExtension( $type, array $extension ) {
698 $out = $this->getOutput();
700 // We must obtain the information for all the bits and pieces!
701 // ... such as extension names and links
702 if ( isset( $extension['namemsg'] ) ) {
703 // Localized name of extension
704 $extensionName = $this->msg( $extension['namemsg'] )->text();
705 } elseif ( isset( $extension['name'] ) ) {
706 // Non localized version
707 $extensionName = $extension['name'];
709 $extensionName = $this->msg( 'version-no-ext-name' )->text();
712 if ( isset( $extension['url'] ) ) {
713 $extensionNameLink = Linker
::makeExternalLink(
718 [ 'class' => 'mw-version-ext-name' ]
721 $extensionNameLink = htmlspecialchars( $extensionName );
724 // ... and the version information
725 // If the extension path is set we will check that directory for GIT
726 // metadata in an attempt to extract date and vcs commit metadata.
727 $canonicalVersion = '–';
728 $extensionPath = null;
733 if ( isset( $extension['version'] ) ) {
734 $canonicalVersion = $out->parseInlineAsInterface( $extension['version'] );
737 if ( isset( $extension['path'] ) ) {
739 $extensionPath = dirname( $extension['path'] );
740 if ( $this->coreId
== '' ) {
741 wfDebug( 'Looking up core head id' );
742 $coreHeadSHA1 = self
::getGitHeadSha1( $IP );
743 if ( $coreHeadSHA1 ) {
744 $this->coreId
= $coreHeadSHA1;
747 $cache = wfGetCache( CACHE_ANYTHING
);
748 $memcKey = $cache->makeKey(
749 'specialversion-ext-version-text', $extension['path'], $this->coreId
751 list( $vcsVersion, $vcsLink, $vcsDate ) = $cache->get( $memcKey );
753 if ( !$vcsVersion ) {
754 wfDebug( "Getting VCS info for extension {$extension['name']}" );
755 $gitInfo = new GitInfo( $extensionPath );
756 $vcsVersion = $gitInfo->getHeadSHA1();
757 if ( $vcsVersion !== false ) {
758 $vcsVersion = substr( $vcsVersion, 0, 7 );
759 $vcsLink = $gitInfo->getHeadViewUrl();
760 $vcsDate = $gitInfo->getHeadCommitDate();
762 $cache->set( $memcKey, [ $vcsVersion, $vcsLink, $vcsDate ], 60 * 60 * 24 );
764 wfDebug( "Pulled VCS info for extension {$extension['name']} from cache" );
768 $versionString = Html
::rawElement(
770 [ 'class' => 'mw-version-ext-version' ],
776 $vcsVerString = Linker
::makeExternalLink(
778 $this->msg( 'version-version', $vcsVersion ),
781 [ 'class' => 'mw-version-ext-vcs-version' ]
784 $vcsVerString = Html
::element( 'span',
785 [ 'class' => 'mw-version-ext-vcs-version' ],
789 $versionString .= " {$vcsVerString}";
792 $vcsTimeString = Html
::element( 'span',
793 [ 'class' => 'mw-version-ext-vcs-timestamp' ],
794 $this->getLanguage()->timeanddate( $vcsDate, true )
796 $versionString .= " {$vcsTimeString}";
798 $versionString = Html
::rawElement( 'span',
799 [ 'class' => 'mw-version-ext-meta-version' ],
804 // ... and license information; if a license file exists we
807 if ( isset( $extension['name'] ) ) {
809 if ( isset( $extension['license-name'] ) ) {
810 $licenseName = new HtmlArmor( $out->parseInlineAsInterface( $extension['license-name'] ) );
811 } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
812 $licenseName = $this->msg( 'version-ext-license' )->text();
814 if ( $licenseName !== null ) {
815 $licenseLink = $this->getLinkRenderer()->makeLink(
816 $this->getPageTitle( 'License/' . $extension['name'] ),
819 'class' => 'mw-version-ext-license',
826 // ... and generate the description; which can be a parameterized l10n message
827 // in the form [ <msgname>, <parameter>, <parameter>... ] or just a straight
829 if ( isset( $extension['descriptionmsg'] ) ) {
830 // Localized description of extension
831 $descriptionMsg = $extension['descriptionmsg'];
833 if ( is_array( $descriptionMsg ) ) {
834 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
835 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
836 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
837 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
839 $description = $this->msg( $descriptionMsg )->text();
841 } elseif ( isset( $extension['description'] ) ) {
842 // Non localized version
843 $description = $extension['description'];
847 $description = $out->parseInlineAsInterface( $description );
849 // ... now get the authors for this extension
850 $authors = $extension['author'] ??
[];
851 $authors = $this->listAuthors( $authors, $extension['name'], $extensionPath );
853 // Finally! Create the table
854 $html = Html
::openElement( 'tr', [
855 'class' => 'mw-version-ext',
856 'id' => Sanitizer
::escapeIdForAttribute( 'mw-version-ext-' . $type . '-' . $extension['name'] )
860 $html .= Html
::rawElement( 'td', [], $extensionNameLink );
861 $html .= Html
::rawElement( 'td', [], $versionString );
862 $html .= Html
::rawElement( 'td', [], $licenseLink );
863 $html .= Html
::rawElement( 'td', [ 'class' => 'mw-version-ext-description' ], $description );
864 $html .= Html
::rawElement( 'td', [ 'class' => 'mw-version-ext-authors' ], $authors );
866 $html .= Html
::closeElement( 'tr' );
872 * Generate wikitext showing hooks in $wgHooks.
874 * @return string Wikitext
876 private function getWgHooks() {
877 global $wgSpecialVersionShowHooks, $wgHooks;
879 if ( $wgSpecialVersionShowHooks && count( $wgHooks ) ) {
880 $myWgHooks = $wgHooks;
884 $ret[] = '== {{int:version-hooks}} ==';
885 $ret[] = Html
::openElement( 'table', [ 'class' => 'wikitable', 'id' => 'sv-hooks' ] );
886 $ret[] = Html
::openElement( 'tr' );
887 $ret[] = Html
::element( 'th', [], $this->msg( 'version-hook-name' )->text() );
888 $ret[] = Html
::element( 'th', [], $this->msg( 'version-hook-subscribedby' )->text() );
889 $ret[] = Html
::closeElement( 'tr' );
891 foreach ( $myWgHooks as $hook => $hooks ) {
892 $ret[] = Html
::openElement( 'tr' );
893 $ret[] = Html
::element( 'td', [], $hook );
894 $ret[] = Html
::element( 'td', [], $this->listToText( $hooks ) );
895 $ret[] = Html
::closeElement( 'tr' );
898 $ret[] = Html
::closeElement( 'table' );
900 return implode( "\n", $ret );
906 private function openExtType( $text = null, $name = null ) {
909 $opt = [ 'colspan' => 5 ];
910 if ( $this->firstExtOpened
) {
911 // Insert a spacing line
912 $out .= Html
::rawElement( 'tr', [ 'class' => 'sv-space' ],
913 Html
::element( 'td', $opt )
916 $this->firstExtOpened
= true;
919 $opt['id'] = "sv-$name";
922 if ( $text !== null ) {
923 $out .= Html
::rawElement( 'tr', [],
924 Html
::element( 'th', $opt, $text )
928 $firstHeadingMsg = ( $name === 'credits-skin' )
929 ?
'version-skin-colheader-name'
930 : 'version-ext-colheader-name';
931 $out .= Html
::openElement( 'tr' );
932 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
933 $this->msg( $firstHeadingMsg )->text() );
934 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
935 $this->msg( 'version-ext-colheader-version' )->text() );
936 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
937 $this->msg( 'version-ext-colheader-license' )->text() );
938 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
939 $this->msg( 'version-ext-colheader-description' )->text() );
940 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
941 $this->msg( 'version-ext-colheader-credits' )->text() );
942 $out .= Html
::closeElement( 'tr' );
948 * Get information about client's IP address.
950 * @return string HTML fragment
952 private function IPInfo() {
953 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
955 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
959 * Return a formatted unsorted list of authors
962 * If an item in the $authors array is '...' it is assumed to indicate an
963 * 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
964 * file if it exists in $dir.
966 * Similarly an entry ending with ' ...]' is assumed to be a link to an
969 * If no '...' string variant is found, but an authors file is found an
970 * 'and others' will be added to the end of the credits.
972 * @param string|array $authors
973 * @param string|bool $extName Name of the extension for link creation,
974 * false if no links should be created
975 * @param string $extDir Path to the extension root directory
977 * @return string HTML fragment
979 public function listAuthors( $authors, $extName, $extDir ) {
981 $linkRenderer = $this->getLinkRenderer();
984 foreach ( (array)$authors as $item ) {
985 if ( $item == '...' ) {
988 if ( $extName && $this->getExtAuthorsFileName( $extDir ) ) {
989 $text = $linkRenderer->makeLink(
990 $this->getPageTitle( "Credits/$extName" ),
991 $this->msg( 'version-poweredby-others' )->text()
994 $text = $this->msg( 'version-poweredby-others' )->escaped();
997 } elseif ( substr( $item, -5 ) == ' ...]' ) {
999 $list[] = $this->getOutput()->parseInlineAsInterface(
1000 substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
1003 $list[] = $this->getOutput()->parseInlineAsInterface( $item );
1007 if ( $extName && !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
1008 $list[] = $text = $linkRenderer->makeLink(
1009 $this->getPageTitle( "Credits/$extName" ),
1010 $this->msg( 'version-poweredby-others' )->text()
1014 return $this->listToText( $list, false );
1018 * Obtains the full path of an extensions authors or credits file if
1021 * @param string $extDir Path to the extensions root directory
1025 * @return bool|string False if no such file exists, otherwise returns
1028 public static function getExtAuthorsFileName( $extDir ) {
1033 foreach ( scandir( $extDir ) as $file ) {
1034 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
1035 if ( preg_match( '/^((AUTHORS)|(CREDITS))(\.txt|\.wiki|\.mediawiki)?$/', $file ) &&
1036 is_readable( $fullPath ) &&
1037 is_file( $fullPath )
1047 * Obtains the full path of an extensions copying or license file if
1050 * @param string $extDir Path to the extensions root directory
1054 * @return bool|string False if no such file exists, otherwise returns
1057 public static function getExtLicenseFileName( $extDir ) {
1062 foreach ( scandir( $extDir ) as $file ) {
1063 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
1064 if ( preg_match( '/^((COPYING)|(LICENSE))(\.txt)?$/', $file ) &&
1065 is_readable( $fullPath ) &&
1066 is_file( $fullPath )
1076 * Convert an array of items into a list for display.
1078 * @param array $list List of elements to display
1079 * @param bool $sort Whether to sort the items in $list
1083 public function listToText( $list, $sort = true ) {
1084 if ( !count( $list ) ) {
1091 return $this->getLanguage()
1092 ->listToText( array_map( [ __CLASS__
, 'arrayToString' ], $list ) );
1096 * Convert an array or object to a string for display.
1098 * @param mixed $list Will convert an array to string if given and return
1099 * the parameter unaltered otherwise
1103 public static function arrayToString( $list ) {
1104 if ( is_array( $list ) && count( $list ) == 1 ) {
1107 if ( $list instanceof Closure
) {
1108 // Don't output stuff like "Closure$;1028376090#8$48499d94fe0147f7c633b365be39952b$"
1110 } elseif ( is_object( $list ) ) {
1111 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
1114 } elseif ( !is_array( $list ) ) {
1117 if ( is_object( $list[0] ) ) {
1118 $class = get_class( $list[0] );
1123 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
1128 * @param string $dir Directory of the git checkout
1129 * @return bool|string Sha1 of commit HEAD points to
1131 public static function getGitHeadSha1( $dir ) {
1132 $repo = new GitInfo( $dir );
1134 return $repo->getHeadSHA1();
1138 * @param string $dir Directory of the git checkout
1139 * @return bool|string Branch currently checked out
1141 public static function getGitCurrentBranch( $dir ) {
1142 $repo = new GitInfo( $dir );
1143 return $repo->getCurrentBranch();
1147 * Get the list of entry points and their URLs
1148 * @return string Wikitext
1150 public function getEntryPointInfo() {
1151 $config = $this->getConfig();
1152 $scriptPath = $config->get( 'ScriptPath' ) ?
: '/';
1155 'version-entrypoints-articlepath' => $config->get( 'ArticlePath' ),
1156 'version-entrypoints-scriptpath' => $scriptPath,
1157 'version-entrypoints-index-php' => wfScript( 'index' ),
1158 'version-entrypoints-api-php' => wfScript( 'api' ),
1159 'version-entrypoints-load-php' => wfScript( 'load' ),
1162 $language = $this->getLanguage();
1164 'dir' => $language->getDir(),
1165 'lang' => $language->getHtmlCode()
1167 $out = Html
::element(
1169 [ 'id' => 'mw-version-entrypoints' ],
1170 $this->msg( 'version-entrypoints' )->text()
1172 Html
::openElement( 'table',
1174 'class' => 'wikitable plainlinks',
1175 'id' => 'mw-version-entrypoints-table',
1180 Html
::openElement( 'tr' ) .
1184 $this->msg( 'version-entrypoints-header-entrypoint' )->text()
1189 $this->msg( 'version-entrypoints-header-url' )->text()
1191 Html
::closeElement( 'tr' );
1193 foreach ( $entryPoints as $message => $value ) {
1194 $url = wfExpandUrl( $value, PROTO_RELATIVE
);
1195 $out .= Html
::openElement( 'tr' ) .
1196 // ->plain() looks like it should be ->parse(), but this function
1197 // returns wikitext, not HTML, boo
1198 Html
::rawElement( 'td', [], $this->msg( $message )->plain() ) .
1199 Html
::rawElement( 'td', [], Html
::rawElement( 'code', [], "[$url $value]" ) ) .
1200 Html
::closeElement( 'tr' );
1203 $out .= Html
::closeElement( 'table' );
1208 protected function getGroupName() {