3 * Implements Special:Version
5 * Copyright © 2005 Ævar Arnfjörð Bjarmason
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
23 * @ingroup SpecialPage
27 * Give information about the version of MediaWiki, PHP, the DB and extensions
29 * @ingroup SpecialPage
31 class SpecialVersion
extends SpecialPage
{
32 protected $firstExtOpened = false;
35 * Stores the current rev id/SHA hash of MediaWiki core
37 protected $coreId = '';
39 protected static $extensionTypes = false;
41 public function __construct() {
42 parent
::__construct( 'Version' );
47 * @param string|null $par
49 public function execute( $par ) {
50 global $IP, $wgExtensionCredits;
53 $this->outputHeader();
54 $out = $this->getOutput();
55 $out->allowClickjacking();
57 // Explode the sub page information into useful bits
58 $parts = explode( '/', (string)$par );
60 if ( isset( $parts[1] ) ) {
61 $extName = str_replace( '_', ' ', $parts[1] );
63 foreach ( $wgExtensionCredits as $group => $extensions ) {
64 foreach ( $extensions as $ext ) {
65 if ( isset( $ext['name'] ) && ( $ext['name'] === $extName ) ) {
72 $out->setStatusCode( 404 );
75 $extName = 'MediaWiki';
78 // Now figure out what to do
79 switch ( strtolower( $parts[0] ) ) {
81 $out->addModuleStyles( 'mediawiki.special.version' );
83 $wikiText = '{{int:version-credits-not-found}}';
84 if ( $extName === 'MediaWiki' ) {
85 $wikiText = file_get_contents( $IP . '/CREDITS' );
86 // Put the contributor list into columns
87 $wikiText = str_replace(
88 [ '<!-- BEGIN CONTRIBUTOR LIST -->', '<!-- END CONTRIBUTOR LIST -->' ],
89 [ '<div class="mw-version-credits">', '</div>' ],
91 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
92 $file = $this->getExtAuthorsFileName( dirname( $extNode['path'] ) );
94 $wikiText = file_get_contents( $file );
95 if ( substr( $file, -4 ) === '.txt' ) {
96 $wikiText = Html
::element(
108 $out->setPageTitle( $this->msg( 'version-credits-title', $extName ) );
109 $out->addWikiText( $wikiText );
113 $wikiText = '{{int:version-license-not-found}}';
114 if ( $extName === 'MediaWiki' ) {
115 $wikiText = file_get_contents( $IP . '/COPYING' );
116 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
117 $file = $this->getExtLicenseFileName( dirname( $extNode['path'] ) );
119 $wikiText = file_get_contents( $file );
120 $wikiText = Html
::element(
131 $out->setPageTitle( $this->msg( 'version-license-title', $extName ) );
132 $out->addWikiText( $wikiText );
136 $out->addModuleStyles( 'mediawiki.special.version' );
138 $this->getMediaWikiCredits() .
139 $this->softwareInformation() .
140 $this->getEntryPointInfo()
143 $this->getSkinCredits() .
144 $this->getExtensionCredits() .
145 $this->getExternalLibraries() .
146 $this->getParserTags() .
147 $this->getParserFunctionHooks()
149 $out->addWikiText( $this->getWgHooks() );
150 $out->addHTML( $this->IPInfo() );
157 * Returns wiki text showing the license information.
161 private static function getMediaWikiCredits() {
164 [ 'id' => 'mw-version-license' ],
165 wfMessage( 'version-license' )->text()
168 // This text is always left-to-right.
169 $ret .= '<div class="plainlinks">';
171 " . self
::getCopyrightAndAuthorList() . "\n
172 " . '<div class="mw-version-license-info">' .
173 wfMessage( 'version-license-info' )->text() .
177 return str_replace( "\t\t", '', $ret ) . "\n";
181 * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
185 public static function getCopyrightAndAuthorList() {
188 if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
189 $othersLink = '[https://www.mediawiki.org/wiki/Special:Version/Credits ' .
190 wfMessage( 'version-poweredby-others' )->text() . ']';
192 $othersLink = '[[Special:Version/Credits|' .
193 wfMessage( 'version-poweredby-others' )->text() . ']]';
196 $translatorsLink = '[https://translatewiki.net/wiki/Translating:MediaWiki/Credits ' .
197 wfMessage( 'version-poweredby-translators' )->text() . ']';
200 'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
201 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
202 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
203 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
204 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
205 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
206 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
207 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', 'Brad Jorsch',
208 'Bartosz Dziewoński', 'Ed Sanders', 'Moriel Schottlender',
209 $othersLink, $translatorsLink
212 return wfMessage( 'version-poweredby-credits', MWTimestamp
::getLocalInstance()->format( 'Y' ),
213 $wgLang->listToText( $authorList ) )->text();
217 * Returns wiki text showing the third party software versions (apache, php, mysql).
221 public static function softwareInformation() {
222 $dbr = wfGetDB( DB_REPLICA
);
224 // Put the software in an array of form 'name' => 'version'. All messages should
225 // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
226 // wikimarkup can be used.
228 $software['[https://www.mediawiki.org/ MediaWiki]'] = self
::getVersionLinked();
230 $software['[https://hhvm.com/ HHVM]'] = HHVM_VERSION
. " (" . PHP_SAPI
. ")";
232 $software['[https://php.net/ PHP]'] = PHP_VERSION
. " (" . PHP_SAPI
. ")";
234 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
236 if ( IcuCollation
::getICUVersion() ) {
237 $software['[http://site.icu-project.org/ ICU]'] = IcuCollation
::getICUVersion();
240 // Allow a hook to add/remove items.
241 Hooks
::run( 'SoftwareInfo', [ &$software ] );
245 [ 'id' => 'mw-version-software' ],
246 wfMessage( 'version-software' )->text()
248 Xml
::openElement( 'table', [ 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ] ) .
250 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
251 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
254 foreach ( $software as $name => $version ) {
256 <td>" . $name . "</td>
257 <td dir=\"ltr\">" . $version . "</td>
261 return $out . Xml
::closeElement( 'table' );
265 * Return a string of the MediaWiki version with Git revision if available.
267 * @param string $flags
268 * @param Language|string|null $lang
271 public static function getVersion( $flags = '', $lang = null ) {
272 global $wgVersion, $IP;
274 $gitInfo = self
::getGitHeadSha1( $IP );
276 $version = $wgVersion;
277 } elseif ( $flags === 'nodb' ) {
278 $shortSha1 = substr( $gitInfo, 0, 7 );
279 $version = "$wgVersion ($shortSha1)";
281 $shortSha1 = substr( $gitInfo, 0, 7 );
282 $msg = wfMessage( 'parentheses' );
283 if ( $lang !== null ) {
284 $msg->inLanguage( $lang );
286 $shortSha1 = $msg->params( $shortSha1 )->escaped();
287 $version = "$wgVersion $shortSha1";
294 * Return a wikitext-formatted string of the MediaWiki version with a link to
295 * the Git SHA1 of head if available.
296 * The fallback is just $wgVersion
300 public static function getVersionLinked() {
303 $gitVersion = self
::getVersionLinkedGit();
307 $v = $wgVersion; // fallback
316 private static function getwgVersionLinked() {
319 if ( Hooks
::run( 'SpecialVersionVersionUrl', [ $wgVersion, &$versionUrl ] ) ) {
321 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
322 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
325 return "[$versionUrl $wgVersion]";
329 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
330 * @return bool|string Global wgVersion + HEAD sha1 stripped to the first 7 chars
331 * with link and date, or false on failure
333 private static function getVersionLinkedGit() {
336 $gitInfo = new GitInfo( $IP );
337 $headSHA1 = $gitInfo->getHeadSHA1();
342 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
344 $gitHeadUrl = $gitInfo->getHeadViewUrl();
345 if ( $gitHeadUrl !== false ) {
346 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
349 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
350 if ( $gitHeadCommitDate ) {
351 $shortSHA1 .= Html
::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true );
354 return self
::getwgVersionLinked() . " $shortSHA1";
358 * Returns an array with the base extension types.
359 * Type is stored as array key, the message as array value.
361 * TODO: ideally this would return all extension types.
367 public static function getExtensionTypes() {
368 if ( self
::$extensionTypes === false ) {
369 self
::$extensionTypes = [
370 'specialpage' => wfMessage( 'version-specialpages' )->text(),
371 'editor' => wfMessage( 'version-editors' )->text(),
372 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
373 'variable' => wfMessage( 'version-variables' )->text(),
374 'media' => wfMessage( 'version-mediahandlers' )->text(),
375 'antispam' => wfMessage( 'version-antispam' )->text(),
376 'skin' => wfMessage( 'version-skins' )->text(),
377 'api' => wfMessage( 'version-api' )->text(),
378 'other' => wfMessage( 'version-other' )->text(),
381 Hooks
::run( 'ExtensionTypes', [ &self
::$extensionTypes ] );
384 return self
::$extensionTypes;
388 * Returns the internationalized name for an extension type.
392 * @param string $type
396 public static function getExtensionTypeName( $type ) {
397 $types = self
::getExtensionTypes();
399 return isset( $types[$type] ) ?
$types[$type] : $types['other'];
403 * Generate wikitext showing the name, URL, author and description of each extension.
405 * @return string Wikitext
407 public function getExtensionCredits() {
408 global $wgExtensionCredits;
411 count( $wgExtensionCredits ) === 0 ||
412 // Skins are displayed separately, see getSkinCredits()
413 ( count( $wgExtensionCredits ) === 1 && isset( $wgExtensionCredits['skin'] ) )
418 $extensionTypes = self
::getExtensionTypes();
422 [ 'id' => 'mw-version-ext' ],
423 $this->msg( 'version-extensions' )->text()
425 Xml
::openElement( 'table', [ 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ] );
427 // Make sure the 'other' type is set to an array.
428 if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
429 $wgExtensionCredits['other'] = [];
432 // Find all extensions that do not have a valid type and give them the type 'other'.
433 foreach ( $wgExtensionCredits as $type => $extensions ) {
434 if ( !array_key_exists( $type, $extensionTypes ) ) {
435 $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
439 $this->firstExtOpened
= false;
440 // Loop through the extension categories to display their extensions in the list.
441 foreach ( $extensionTypes as $type => $message ) {
442 // Skins have a separate section
443 if ( $type !== 'other' && $type !== 'skin' ) {
444 $out .= $this->getExtensionCategory( $type, $message );
448 // We want the 'other' type to be last in the list.
449 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
451 $out .= Xml
::closeElement( 'table' );
457 * Generate wikitext showing the name, URL, author and description of each skin.
459 * @return string Wikitext
461 public function getSkinCredits() {
462 global $wgExtensionCredits;
463 if ( !isset( $wgExtensionCredits['skin'] ) ||
count( $wgExtensionCredits['skin'] ) === 0 ) {
469 [ 'id' => 'mw-version-skin' ],
470 $this->msg( 'version-skins' )->text()
472 Xml
::openElement( 'table', [ 'class' => 'wikitable plainlinks', 'id' => 'sv-skin' ] );
474 $this->firstExtOpened
= false;
475 $out .= $this->getExtensionCategory( 'skin', null );
477 $out .= Xml
::closeElement( 'table' );
483 * Generate an HTML table for external libraries that are installed
487 protected function getExternalLibraries() {
489 $path = "$IP/vendor/composer/installed.json";
490 if ( !file_exists( $path ) ) {
494 $installed = new ComposerInstalled( $path );
495 $out = Html
::element(
497 [ 'id' => 'mw-version-libraries' ],
498 $this->msg( 'version-libraries' )->text()
500 $out .= Html
::openElement(
502 [ 'class' => 'wikitable plainlinks', 'id' => 'sv-libraries' ]
504 $out .= Html
::openElement( 'tr' )
505 . Html
::element( 'th', [], $this->msg( 'version-libraries-library' )->text() )
506 . Html
::element( 'th', [], $this->msg( 'version-libraries-version' )->text() )
507 . Html
::element( 'th', [], $this->msg( 'version-libraries-license' )->text() )
508 . Html
::element( 'th', [], $this->msg( 'version-libraries-description' )->text() )
509 . Html
::element( 'th', [], $this->msg( 'version-libraries-authors' )->text() )
510 . Html
::closeElement( 'tr' );
512 foreach ( $installed->getInstalledDependencies() as $name => $info ) {
513 if ( strpos( $info['type'], 'mediawiki-' ) === 0 ) {
514 // Skip any extensions or skins since they'll be listed
515 // in their proper section
518 $authors = array_map( function ( $arr ) {
519 // If a homepage is set, link to it
520 if ( isset( $arr['homepage'] ) ) {
521 return "[{$arr['homepage']} {$arr['name']}]";
524 }, $info['authors'] );
525 $authors = $this->listAuthors( $authors, false, "$IP/vendor/$name" );
527 // We can safely assume that the libraries' names and descriptions
528 // are written in English and aren't going to be translated,
529 // so set appropriate lang and dir attributes
530 $out .= Html
::openElement( 'tr' )
534 Linker
::makeExternalLink(
535 "https://packagist.org/packages/$name", $name,
537 [ 'class' => 'mw-version-library-name' ]
540 . Html
::element( 'td', [ 'dir' => 'auto' ], $info['version'] )
541 . Html
::element( 'td', [ 'dir' => 'auto' ], $this->listToText( $info['licenses'] ) )
542 . Html
::element( 'td', [ 'lang' => 'en', 'dir' => 'ltr' ], $info['description'] )
543 . Html
::rawElement( 'td', [], $authors )
544 . Html
::closeElement( 'tr' );
546 $out .= Html
::closeElement( 'table' );
552 * Obtains a list of installed parser tags and the associated H2 header
554 * @return string HTML output
556 protected function getParserTags() {
559 $tags = $wgParser->getTags();
561 if ( count( $tags ) ) {
562 $out = Html
::rawElement(
565 'class' => 'mw-headline plainlinks',
566 'id' => 'mw-version-parser-extensiontags',
568 Linker
::makeExternalLink(
569 'https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions',
570 $this->msg( 'version-parser-extensiontags' )->parse(),
571 false /* msg()->parse() already escapes */
575 array_walk( $tags, function ( &$value ) {
576 // Bidirectional isolation improves readability in RTL wikis
577 $value = Html
::element(
579 // Prevent < and > from slipping to another line
581 'style' => 'white-space: nowrap;',
587 $out .= $this->listToText( $tags );
596 * Obtains a list of installed parser function hooks and the associated H2 header
598 * @return string HTML output
600 protected function getParserFunctionHooks() {
603 $fhooks = $wgParser->getFunctionHooks();
604 if ( count( $fhooks ) ) {
605 $out = Html
::rawElement(
608 'class' => 'mw-headline plainlinks',
609 'id' => 'mw-version-parser-function-hooks',
611 Linker
::makeExternalLink(
612 'https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions',
613 $this->msg( 'version-parser-function-hooks' )->parse(),
614 false /* msg()->parse() already escapes */
618 $out .= $this->listToText( $fhooks );
627 * Creates and returns the HTML for a single extension category.
631 * @param string $type
632 * @param string $message
636 protected function getExtensionCategory( $type, $message ) {
637 global $wgExtensionCredits;
641 if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
642 $out .= $this->openExtType( $message, 'credits-' . $type );
644 usort( $wgExtensionCredits[$type], [ $this, 'compare' ] );
646 foreach ( $wgExtensionCredits[$type] as $extension ) {
647 $out .= $this->getCreditsForExtension( $type, $extension );
655 * Callback to sort extensions by type.
660 public function compare( $a, $b ) {
661 if ( $a['name'] === $b['name'] ) {
664 return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
671 * Creates and formats a version line for a single extension.
673 * Information for five columns will be created. Parameters required in the
674 * $extension array for part rendering are indicated in ()
675 * - The name of (name), and URL link to (url), the extension
676 * - Official version number (version) and if available version control system
677 * revision (path), link, and date
678 * - If available the short name of the license (license-name) and a link
679 * to ((LICENSE)|(COPYING))(\.txt)? if it exists.
680 * - Description of extension (descriptionmsg or description)
681 * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
683 * @param string $type Category name of the extension
684 * @param array $extension
686 * @return string Raw HTML
688 public function getCreditsForExtension( $type, array $extension ) {
689 $out = $this->getOutput();
691 // We must obtain the information for all the bits and pieces!
692 // ... such as extension names and links
693 if ( isset( $extension['namemsg'] ) ) {
694 // Localized name of extension
695 $extensionName = $this->msg( $extension['namemsg'] )->text();
696 } elseif ( isset( $extension['name'] ) ) {
697 // Non localized version
698 $extensionName = $extension['name'];
700 $extensionName = $this->msg( 'version-no-ext-name' )->text();
703 if ( isset( $extension['url'] ) ) {
704 $extensionNameLink = Linker
::makeExternalLink(
709 [ 'class' => 'mw-version-ext-name' ]
712 $extensionNameLink = $extensionName;
715 // ... and the version information
716 // If the extension path is set we will check that directory for GIT
717 // metadata in an attempt to extract date and vcs commit metadata.
718 $canonicalVersion = '–';
719 $extensionPath = null;
724 if ( isset( $extension['version'] ) ) {
725 $canonicalVersion = $out->parseInline( $extension['version'] );
728 if ( isset( $extension['path'] ) ) {
730 $extensionPath = dirname( $extension['path'] );
731 if ( $this->coreId
== '' ) {
732 wfDebug( 'Looking up core head id' );
733 $coreHeadSHA1 = self
::getGitHeadSha1( $IP );
734 if ( $coreHeadSHA1 ) {
735 $this->coreId
= $coreHeadSHA1;
738 $cache = wfGetCache( CACHE_ANYTHING
);
739 $memcKey = $cache->makeKey(
740 'specialversion-ext-version-text', $extension['path'], $this->coreId
742 list( $vcsVersion, $vcsLink, $vcsDate ) = $cache->get( $memcKey );
744 if ( !$vcsVersion ) {
745 wfDebug( "Getting VCS info for extension {$extension['name']}" );
746 $gitInfo = new GitInfo( $extensionPath );
747 $vcsVersion = $gitInfo->getHeadSHA1();
748 if ( $vcsVersion !== false ) {
749 $vcsVersion = substr( $vcsVersion, 0, 7 );
750 $vcsLink = $gitInfo->getHeadViewUrl();
751 $vcsDate = $gitInfo->getHeadCommitDate();
753 $cache->set( $memcKey, [ $vcsVersion, $vcsLink, $vcsDate ], 60 * 60 * 24 );
755 wfDebug( "Pulled VCS info for extension {$extension['name']} from cache" );
759 $versionString = Html
::rawElement(
761 [ 'class' => 'mw-version-ext-version' ],
767 $vcsVerString = Linker
::makeExternalLink(
769 $this->msg( 'version-version', $vcsVersion ),
772 [ 'class' => 'mw-version-ext-vcs-version' ]
775 $vcsVerString = Html
::element( 'span',
776 [ 'class' => 'mw-version-ext-vcs-version' ],
780 $versionString .= " {$vcsVerString}";
783 $vcsTimeString = Html
::element( 'span',
784 [ 'class' => 'mw-version-ext-vcs-timestamp' ],
785 $this->getLanguage()->timeanddate( $vcsDate, true )
787 $versionString .= " {$vcsTimeString}";
789 $versionString = Html
::rawElement( 'span',
790 [ 'class' => 'mw-version-ext-meta-version' ],
795 // ... and license information; if a license file exists we
798 if ( isset( $extension['name'] ) ) {
800 if ( isset( $extension['license-name'] ) ) {
801 $licenseName = new HtmlArmor( $out->parseInline( $extension['license-name'] ) );
802 } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
803 $licenseName = $this->msg( 'version-ext-license' )->text();
805 if ( $licenseName !== null ) {
806 $licenseLink = $this->getLinkRenderer()->makeLink(
807 $this->getPageTitle( 'License/' . $extension['name'] ),
810 'class' => 'mw-version-ext-license',
817 // ... and generate the description; which can be a parameterized l10n message
818 // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
820 if ( isset( $extension['descriptionmsg'] ) ) {
821 // Localized description of extension
822 $descriptionMsg = $extension['descriptionmsg'];
824 if ( is_array( $descriptionMsg ) ) {
825 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
826 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
827 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
828 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
830 $description = $this->msg( $descriptionMsg )->text();
832 } elseif ( isset( $extension['description'] ) ) {
833 // Non localized version
834 $description = $extension['description'];
838 $description = $out->parseInline( $description );
840 // ... now get the authors for this extension
841 $authors = isset( $extension['author'] ) ?
$extension['author'] : [];
842 $authors = $this->listAuthors( $authors, $extension['name'], $extensionPath );
844 // Finally! Create the table
845 $html = Html
::openElement( 'tr', [
846 'class' => 'mw-version-ext',
847 'id' => Sanitizer
::escapeIdForAttribute( 'mw-version-ext-' . $type . '-' . $extension['name'] )
851 $html .= Html
::rawElement( 'td', [], $extensionNameLink );
852 $html .= Html
::rawElement( 'td', [], $versionString );
853 $html .= Html
::rawElement( 'td', [], $licenseLink );
854 $html .= Html
::rawElement( 'td', [ 'class' => 'mw-version-ext-description' ], $description );
855 $html .= Html
::rawElement( 'td', [ 'class' => 'mw-version-ext-authors' ], $authors );
857 $html .= Html
::closeElement( 'tr' );
863 * Generate wikitext showing hooks in $wgHooks.
865 * @return string Wikitext
867 private function getWgHooks() {
868 global $wgSpecialVersionShowHooks, $wgHooks;
870 if ( $wgSpecialVersionShowHooks && count( $wgHooks ) ) {
871 $myWgHooks = $wgHooks;
875 $ret[] = '== {{int:version-hooks}} ==';
876 $ret[] = Html
::openElement( 'table', [ 'class' => 'wikitable', 'id' => 'sv-hooks' ] );
877 $ret[] = Html
::openElement( 'tr' );
878 $ret[] = Html
::element( 'th', [], $this->msg( 'version-hook-name' )->text() );
879 $ret[] = Html
::element( 'th', [], $this->msg( 'version-hook-subscribedby' )->text() );
880 $ret[] = Html
::closeElement( 'tr' );
882 foreach ( $myWgHooks as $hook => $hooks ) {
883 $ret[] = Html
::openElement( 'tr' );
884 $ret[] = Html
::element( 'td', [], $hook );
885 $ret[] = Html
::element( 'td', [], $this->listToText( $hooks ) );
886 $ret[] = Html
::closeElement( 'tr' );
889 $ret[] = Html
::closeElement( 'table' );
891 return implode( "\n", $ret );
897 private function openExtType( $text = null, $name = null ) {
900 $opt = [ 'colspan' => 5 ];
901 if ( $this->firstExtOpened
) {
902 // Insert a spacing line
903 $out .= Html
::rawElement( 'tr', [ 'class' => 'sv-space' ],
904 Html
::element( 'td', $opt )
907 $this->firstExtOpened
= true;
910 $opt['id'] = "sv-$name";
913 if ( $text !== null ) {
914 $out .= Html
::rawElement( 'tr', [],
915 Html
::element( 'th', $opt, $text )
919 $firstHeadingMsg = ( $name === 'credits-skin' )
920 ?
'version-skin-colheader-name'
921 : 'version-ext-colheader-name';
922 $out .= Html
::openElement( 'tr' );
923 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
924 $this->msg( $firstHeadingMsg )->text() );
925 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
926 $this->msg( 'version-ext-colheader-version' )->text() );
927 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
928 $this->msg( 'version-ext-colheader-license' )->text() );
929 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
930 $this->msg( 'version-ext-colheader-description' )->text() );
931 $out .= Html
::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
932 $this->msg( 'version-ext-colheader-credits' )->text() );
933 $out .= Html
::closeElement( 'tr' );
939 * Get information about client's IP address.
941 * @return string HTML fragment
943 private function IPInfo() {
944 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
946 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
950 * Return a formatted unsorted list of authors
953 * If an item in the $authors array is '...' it is assumed to indicate an
954 * 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
955 * file if it exists in $dir.
957 * Similarly an entry ending with ' ...]' is assumed to be a link to an
960 * If no '...' string variant is found, but an authors file is found an
961 * 'and others' will be added to the end of the credits.
963 * @param string|array $authors
964 * @param string|bool $extName Name of the extension for link creation,
965 * false if no links should be created
966 * @param string $extDir Path to the extension root directory
968 * @return string HTML fragment
970 public function listAuthors( $authors, $extName, $extDir ) {
972 $linkRenderer = $this->getLinkRenderer();
975 foreach ( (array)$authors as $item ) {
976 if ( $item == '...' ) {
979 if ( $extName && $this->getExtAuthorsFileName( $extDir ) ) {
980 $text = $linkRenderer->makeLink(
981 $this->getPageTitle( "Credits/$extName" ),
982 $this->msg( 'version-poweredby-others' )->text()
985 $text = $this->msg( 'version-poweredby-others' )->escaped();
988 } elseif ( substr( $item, -5 ) == ' ...]' ) {
990 $list[] = $this->getOutput()->parseInline(
991 substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
994 $list[] = $this->getOutput()->parseInline( $item );
998 if ( $extName && !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
999 $list[] = $text = $linkRenderer->makeLink(
1000 $this->getPageTitle( "Credits/$extName" ),
1001 $this->msg( 'version-poweredby-others' )->text()
1005 return $this->listToText( $list, false );
1009 * Obtains the full path of an extensions authors or credits file if
1012 * @param string $extDir Path to the extensions root directory
1016 * @return bool|string False if no such file exists, otherwise returns
1019 public static function getExtAuthorsFileName( $extDir ) {
1024 foreach ( scandir( $extDir ) as $file ) {
1025 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
1026 if ( preg_match( '/^((AUTHORS)|(CREDITS))(\.txt|\.wiki|\.mediawiki)?$/', $file ) &&
1027 is_readable( $fullPath ) &&
1028 is_file( $fullPath )
1038 * Obtains the full path of an extensions copying or license file if
1041 * @param string $extDir Path to the extensions root directory
1045 * @return bool|string False if no such file exists, otherwise returns
1048 public static function getExtLicenseFileName( $extDir ) {
1053 foreach ( scandir( $extDir ) as $file ) {
1054 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
1055 if ( preg_match( '/^((COPYING)|(LICENSE))(\.txt)?$/', $file ) &&
1056 is_readable( $fullPath ) &&
1057 is_file( $fullPath )
1067 * Convert an array of items into a list for display.
1069 * @param array $list List of elements to display
1070 * @param bool $sort Whether to sort the items in $list
1074 public function listToText( $list, $sort = true ) {
1075 if ( !count( $list ) ) {
1082 return $this->getLanguage()
1083 ->listToText( array_map( [ __CLASS__
, 'arrayToString' ], $list ) );
1087 * Convert an array or object to a string for display.
1089 * @param mixed $list Will convert an array to string if given and return
1090 * the parameter unaltered otherwise
1094 public static function arrayToString( $list ) {
1095 if ( is_array( $list ) && count( $list ) == 1 ) {
1098 if ( $list instanceof Closure
) {
1099 // Don't output stuff like "Closure$;1028376090#8$48499d94fe0147f7c633b365be39952b$"
1101 } elseif ( is_object( $list ) ) {
1102 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
1105 } elseif ( !is_array( $list ) ) {
1108 if ( is_object( $list[0] ) ) {
1109 $class = get_class( $list[0] );
1114 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
1119 * @param string $dir Directory of the git checkout
1120 * @return bool|string Sha1 of commit HEAD points to
1122 public static function getGitHeadSha1( $dir ) {
1123 $repo = new GitInfo( $dir );
1125 return $repo->getHeadSHA1();
1129 * @param string $dir Directory of the git checkout
1130 * @return bool|string Branch currently checked out
1132 public static function getGitCurrentBranch( $dir ) {
1133 $repo = new GitInfo( $dir );
1134 return $repo->getCurrentBranch();
1138 * Get the list of entry points and their URLs
1139 * @return string Wikitext
1141 public function getEntryPointInfo() {
1142 global $wgArticlePath, $wgScriptPath;
1143 $scriptPath = $wgScriptPath ?
$wgScriptPath : "/";
1145 'version-entrypoints-articlepath' => $wgArticlePath,
1146 'version-entrypoints-scriptpath' => $scriptPath,
1147 'version-entrypoints-index-php' => wfScript( 'index' ),
1148 'version-entrypoints-api-php' => wfScript( 'api' ),
1149 'version-entrypoints-load-php' => wfScript( 'load' ),
1152 $language = $this->getLanguage();
1154 'dir' => $language->getDir(),
1155 'lang' => $language->getHtmlCode()
1157 $out = Html
::element(
1159 [ 'id' => 'mw-version-entrypoints' ],
1160 $this->msg( 'version-entrypoints' )->text()
1162 Html
::openElement( 'table',
1164 'class' => 'wikitable plainlinks',
1165 'id' => 'mw-version-entrypoints-table',
1170 Html
::openElement( 'tr' ) .
1174 $this->msg( 'version-entrypoints-header-entrypoint' )->text()
1179 $this->msg( 'version-entrypoints-header-url' )->text()
1181 Html
::closeElement( 'tr' );
1183 foreach ( $entryPoints as $message => $value ) {
1184 $url = wfExpandUrl( $value, PROTO_RELATIVE
);
1185 $out .= Html
::openElement( 'tr' ) .
1186 // ->text() looks like it should be ->parse(), but this function
1187 // returns wikitext, not HTML, boo
1188 Html
::rawElement( 'td', [], $this->msg( $message )->text() ) .
1189 Html
::rawElement( 'td', [], Html
::rawElement( 'code', [], "[$url $value]" ) ) .
1190 Html
::closeElement( 'tr' );
1193 $out .= Html
::closeElement( 'table' );
1198 protected function getGroupName() {