| 1 |
<?php |
| 2 |
|
| 3 |
ason |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
namespace MediaWiki\Specials; |
| 24 |
|
| 25 |
use Closure; |
| 26 |
use HtmlArmor; |
| 27 |
use MediaWiki\Config\Config; |
| 28 |
use MediaWiki\HookContainer\HookRunner; |
| 29 |
use MediaWiki\Html\Html; |
| 30 |
use MediaWiki\Language\Language; |
| 31 |
use MediaWiki\Language\RawMessage; |
| 32 |
use MediaWiki\MainConfigNames; |
| 33 |
use MediaWiki\MediaWikiServices; |
| 34 |
use MediaWiki\Message\Message; |
| 35 |
use MediaWiki\Parser\Parser; |
| 36 |
use MediaWiki\Parser\ParserFactory; |
| 37 |
use MediaWiki\Parser\ParserOutput; |
| 38 |
use MediaWiki\Parser\ParserOutputFlags; |
| 39 |
use MediaWiki\Parser\Sanitizer; |
| 40 |
use MediaWiki\Registration\ExtensionRegistry; |
| 41 |
use MediaWiki\SpecialPage\SpecialPage; |
| 42 |
use MediaWiki\Utils\ExtensionInfo; |
| 43 |
use MediaWiki\Utils\GitInfo; |
| 44 |
use MediaWiki\Utils\MWTimestamp; |
| 45 |
use MediaWiki\Utils\UrlUtils; |
| 46 |
use Symfony\Component\Yaml\Yaml; |
| 47 |
use Wikimedia\Composer\ComposerInstalled; |
| 48 |
use Wikimedia\Parsoid\Core\SectionMetadata; |
| 49 |
use Wikimedia\Parsoid\Core\TOCData; |
| 50 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
class SpecialVersion extends SpecialPage { |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
protected $coreId = ''; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
protected static $extensionTypes = false; |
| 68 |
|
| 69 |
|
| 70 |
protected $tocData; |
| 71 |
|
| 72 |
|
| 73 |
protected $tocIndex; |
| 74 |
|
| 75 |
|
| 76 |
protected $tocSection; |
| 77 |
|
| 78 |
|
| 79 |
protected $tocSubSection; |
| 80 |
|
| 81 |
private ParserFactory $parserFactory; |
| 82 |
private UrlUtils $urlUtils; |
| 83 |
private IConnectionProvider $dbProvider; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public function __construct( |
| 91 |
ParserFactory $parserFactory, |
| 92 |
UrlUtils $urlUtils, |
| 93 |
IConnectionProvider $dbProvider |
| 94 |
) { |
| 95 |
parent::__construct( 'Version' ); |
| 96 |
$this->parserFactory = $parserFactory; |
| 97 |
$this->urlUtils = $urlUtils; |
| 98 |
$this->dbProvider = $dbProvider; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public static function getCredits( ExtensionRegistry $reg, Config $conf ): array { |
| 109 |
$credits = $conf->get( MainConfigNames::ExtensionCredits ); |
| 110 |
foreach ( $reg->getAllThings() as $credit ) { |
| 111 |
$credits[$credit['type']][] = $credit; |
| 112 |
} |
| 113 |
return $credits; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
public function execute( $par ) { |
| 120 |
$config = $this->getConfig(); |
| 121 |
$credits = self::getCredits( ExtensionRegistry::getInstance(), $config ); |
| 122 |
|
| 123 |
$this->setHeaders(); |
| 124 |
$this->outputHeader(); |
| 125 |
$out = $this->getOutput(); |
| 126 |
$out->getMetadata()->setPreventClickjacking( false ); |
| 127 |
|
| 128 |
|
| 129 |
$parts = explode( '/', (string)$par ); |
| 130 |
$extNode = null; |
| 131 |
if ( isset( $parts[1] ) ) { |
| 132 |
$extName = str_replace( '_', ' ', $parts[1] ); |
| 133 |
|
| 134 |
foreach ( $credits as $extensions ) { |
| 135 |
foreach ( $extensions as $ext ) { |
| 136 |
if ( isset( $ext['name'] ) && ( $ext['name'] === $extName ) ) { |
| 137 |
$extNode = &$ext; |
| 138 |
break 2; |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
if ( !$extNode ) { |
| 143 |
$out->setStatusCode( 404 ); |
| 144 |
} |
| 145 |
} else { |
| 146 |
$extName = 'MediaWiki'; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
switch ( strtolower( $parts[0] ) ) { |
| 151 |
case 'credits': |
| 152 |
$out->addModuleStyles( 'mediawiki.special' ); |
| 153 |
|
| 154 |
$wikiText = '{{int:version-credits-not-found}}'; |
| 155 |
if ( $extName === 'MediaWiki' ) { |
| 156 |
$wikiText = file_get_contents( MW_INSTALL_PATH . '/CREDITS' ); |
| 157 |
|
| 158 |
$wikiText = str_replace( |
| 159 |
[ '<!-- BEGIN CONTRIBUTOR LIST -->', '<!-- END CONTRIBUTOR LIST -->' ], |
| 160 |
[ '<div class="mw-version-credits">', '</div>' ], |
| 161 |
$wikiText |
| 162 |
); |
| 163 |
} elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) { |
| 164 |
$file = ExtensionInfo::getAuthorsFileName( dirname( $extNode['path'] ) ); |
| 165 |
if ( $file ) { |
| 166 |
$wikiText = file_get_contents( $file ); |
| 167 |
if ( str_ends_with( $file, '.txt' ) ) { |
| 168 |
$wikiText = Html::element( |
| 169 |
'pre', |
| 170 |
[ |
| 171 |
'lang' => 'en', |
| 172 |
'dir' => 'ltr', |
| 173 |
], |
| 174 |
$wikiText |
| 175 |
); |
| 176 |
} |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
$out->setPageTitleMsg( $this->msg( 'version-credits-title' )->plaintextParams( $extName ) ); |
| 181 |
$out->addWikiTextAsInterface( $wikiText ); |
| 182 |
break; |
| 183 |
|
| 184 |
case 'license': |
| 185 |
$out->setPageTitleMsg( $this->msg( 'version-license-title' )->plaintextParams( $extName ) ); |
| 186 |
|
| 187 |
$licenseFound = false; |
| 188 |
|
| 189 |
if ( $extName === 'MediaWiki' ) { |
| 190 |
$out->addWikiTextAsInterface( |
| 191 |
file_get_contents( MW_INSTALL_PATH . '/COPYING' ) |
| 192 |
); |
| 193 |
$licenseFound = true; |
| 194 |
} elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) { |
| 195 |
$files = ExtensionInfo::getLicenseFileNames( dirname( $extNode['path'] ) ); |
| 196 |
if ( $files ) { |
| 197 |
$licenseFound = true; |
| 198 |
foreach ( $files as $file ) { |
| 199 |
$out->addWikiTextAsInterface( |
| 200 |
Html::element( |
| 201 |
'pre', |
| 202 |
[ |
| 203 |
'lang' => 'en', |
| 204 |
'dir' => 'ltr', |
| 205 |
], |
| 206 |
file_get_contents( $file ) |
| 207 |
) |
| 208 |
); |
| 209 |
} |
| 210 |
} |
| 211 |
} |
| 212 |
if ( !$licenseFound ) { |
| 213 |
$out->addWikiTextAsInterface( '{{int:version-license-not-found}}' ); |
| 214 |
} |
| 215 |
break; |
| 216 |
|
| 217 |
default: |
| 218 |
$out->addModuleStyles( 'mediawiki.special' ); |
| 219 |
|
| 220 |
$out->addHTML( $this->getMediaWikiCredits() ); |
| 221 |
|
| 222 |
$this->tocData = new TOCData(); |
| 223 |
$this->tocIndex = 0; |
| 224 |
$this->tocSection = 0; |
| 225 |
$this->tocSubSection = 0; |
| 226 |
|
| 227 |
|
| 228 |
$sections = [ |
| 229 |
$this->softwareInformation(), |
| 230 |
$this->getEntryPointInfo(), |
| 231 |
$this->getSkinCredits( $credits ), |
| 232 |
$this->getExtensionCredits( $credits ), |
| 233 |
$this->getLibraries( $credits ), |
| 234 |
$this->getParserTags(), |
| 235 |
$this->getParserFunctionHooks(), |
| 236 |
$this->getHooks(), |
| 237 |
$this->IPInfo(), |
| 238 |
]; |
| 239 |
|
| 240 |
|
| 241 |
$pout = new ParserOutput; |
| 242 |
$pout->setTOCData( $this->tocData ); |
| 243 |
$pout->setOutputFlag( ParserOutputFlags::SHOW_TOC ); |
| 244 |
$pout->setRawText( Parser::TOC_PLACEHOLDER ); |
| 245 |
$out->addParserOutput( $pout ); |
| 246 |
|
| 247 |
|
| 248 |
foreach ( $sections as $content ) { |
| 249 |
$out->addHTML( $content ); |
| 250 |
} |
| 251 |
|
| 252 |
break; |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
private function addTocSection( $labelMsg, $id ) { |
| 264 |
$this->tocIndex++; |
| 265 |
$this->tocSection++; |
| 266 |
$this->tocSubSection = 0; |
| 267 |
$this->tocData->addSection( new SectionMetadata( |
| 268 |
1, |
| 269 |
2, |
| 270 |
$this->msg( $labelMsg )->escaped(), |
| 271 |
$this->getLanguage()->formatNum( $this->tocSection ), |
| 272 |
(string)$this->tocIndex, |
| 273 |
null, |
| 274 |
null, |
| 275 |
$id, |
| 276 |
$id |
| 277 |
) ); |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
private function addTocSubSection( $label, $id ) { |
| 288 |
$this->tocIndex++; |
| 289 |
$this->tocSubSection++; |
| 290 |
$this->tocData->addSection( new SectionMetadata( |
| 291 |
2, |
| 292 |
3, |
| 293 |
htmlspecialchars( $label ), |
| 294 |
|
| 295 |
$this->getLanguage()->formatNum( $this->tocSection ) . '.' . |
| 296 |
$this->getLanguage()->formatNum( $this->tocSubSection ), |
| 297 |
(string)$this->tocIndex, |
| 298 |
null, |
| 299 |
null, |
| 300 |
$id, |
| 301 |
$id |
| 302 |
) ); |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
private function getMediaWikiCredits() { |
| 311 |
|
| 312 |
|
| 313 |
$ret = Html::element( |
| 314 |
'h2', |
| 315 |
[ 'id' => 'mw-version-license' ], |
| 316 |
$this->msg( 'version-license' )->text() |
| 317 |
); |
| 318 |
|
| 319 |
$ret .= Html::rawElement( 'div', [ 'class' => 'plainlinks' ], |
| 320 |
$this->msg( new RawMessage( self::getCopyrightAndAuthorList() ) )->parseAsBlock() . |
| 321 |
Html::rawElement( 'div', [ 'class' => 'mw-version-license-info' ], |
| 322 |
$this->msg( 'version-license-info' )->parseAsBlock() |
| 323 |
) |
| 324 |
); |
| 325 |
|
| 326 |
return $ret; |
| 327 |
} |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
public static function getCopyrightAndAuthorList() { |
| 336 |
if ( defined( 'MEDIAWIKI_INSTALL' ) ) { |
| 337 |
$othersLink = '[https://www.mediawiki.org/wiki/Special:Version/Credits ' . |
| 338 |
wfMessage( 'version-poweredby-others' )->plain() . ']'; |
| 339 |
} else { |
| 340 |
$othersLink = '[[Special:Version/Credits|' . |
| 341 |
wfMessage( 'version-poweredby-others' )->plain() . ']]'; |
| 342 |
} |
| 343 |
|
| 344 |
$translatorsLink = '[https://translatewiki.net/wiki/Translating:MediaWiki/Credits ' . |
| 345 |
wfMessage( 'version-poweredby-translators' )->plain() . ']'; |
| 346 |
|
| 347 |
$authorList = [ |
| 348 |
'Magnus Manske', 'Brooke Vibber', 'Lee Daniel Crocker', |
| 349 |
'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason', |
| 350 |
'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan', |
| 351 |
'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking', |
| 352 |
'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe', |
| 353 |
'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed', |
| 354 |
'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso', |
| 355 |
'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', 'Brad Jorsch', |
| 356 |
'Bartosz Dziewoński', 'Ed Sanders', 'Moriel Schottlender', |
| 357 |
'Kunal Mehta', 'James D. Forrester', 'Brian Wolff', 'Adam Shorland', |
| 358 |
'DannyS712', 'Ori Livneh', 'Max Semenik', 'Amir Sarabadani', |
| 359 |
'Derk-Jan Hartman', 'Petr Pchelko', |
| 360 |
$othersLink, $translatorsLink |
| 361 |
]; |
| 362 |
|
| 363 |
return wfMessage( 'version-poweredby-credits', MWTimestamp::getLocalInstance()->format( 'Y' ), |
| 364 |
Message::listParam( $authorList ) )->plain(); |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
private function getSoftwareInformation() { |
| 373 |
$dbr = $this->dbProvider->getReplicaDatabase(); |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
$software = [ |
| 379 |
'[https://www.mediawiki.org/ MediaWiki]' => self::getVersionLinked(), |
| 380 |
'[https://php.net/ PHP]' => PHP_VERSION . " (" . PHP_SAPI . ")", |
| 381 |
'[https://icu.unicode.org/ ICU]' => INTL_ICU_VERSION, |
| 382 |
$dbr->getSoftwareLink() => $dbr->getServerInfo(), |
| 383 |
]; |
| 384 |
|
| 385 |
|
| 386 |
if ( phpversion( "wikidiff2" ) ) { |
| 387 |
$software[ '[https://www.mediawiki.org/wiki/Wikidiff2 wikidiff2]' ] = phpversion( "wikidiff2" ); |
| 388 |
} |
| 389 |
|
| 390 |
|
| 391 |
$this->getHookRunner()->onSoftwareInfo( $software ); |
| 392 |
|
| 393 |
return $software; |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
private function softwareInformation() { |
| 402 |
$this->addTocSection( 'version-software', 'mw-version-software' ); |
| 403 |
|
| 404 |
$out = Html::element( |
| 405 |
'h2', |
| 406 |
[ 'id' => 'mw-version-software' ], |
| 407 |
$this->msg( 'version-software' )->text() |
| 408 |
); |
| 409 |
|
| 410 |
$out .= Html::openElement( 'table', [ 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ] ); |
| 411 |
|
| 412 |
$out .= $this->getTableHeaderHtml( [ |
| 413 |
$this->msg( 'version-software-product' )->text(), |
| 414 |
$this->msg( 'version-software-version' )->text() |
| 415 |
] ); |
| 416 |
|
| 417 |
foreach ( $this->getSoftwareInformation() as $name => $version ) { |
| 418 |
$out .= Html::rawElement( |
| 419 |
'tr', |
| 420 |
[], |
| 421 |
Html::rawElement( 'td', [], $this->msg( new RawMessage( $name ) )->parse() ) . |
| 422 |
Html::rawElement( 'td', [ 'dir' => 'ltr' ], $this->msg( new RawMessage( $version ) )->parse() ) |
| 423 |
); |
| 424 |
} |
| 425 |
|
| 426 |
$out .= Html::closeElement( 'table' ); |
| 427 |
|
| 428 |
return $out; |
| 429 |
} |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
public static function getVersion( $flags = '', $lang = null ) { |
| 441 |
$gitInfo = GitInfo::repo()->getHeadSHA1(); |
| 442 |
if ( !$gitInfo ) { |
| 443 |
$version = MW_VERSION; |
| 444 |
} elseif ( $flags === 'nodb' ) { |
| 445 |
$shortSha1 = substr( $gitInfo, 0, 7 ); |
| 446 |
$version = MW_VERSION . " ($shortSha1)"; |
| 447 |
} else { |
| 448 |
$shortSha1 = substr( $gitInfo, 0, 7 ); |
| 449 |
$msg = wfMessage( 'parentheses' ); |
| 450 |
if ( $lang !== null ) { |
| 451 |
$msg->inLanguage( $lang ); |
| 452 |
} |
| 453 |
$shortSha1 = $msg->params( $shortSha1 )->text(); |
| 454 |
$version = MW_VERSION . ' ' . $shortSha1; |
| 455 |
} |
| 456 |
|
| 457 |
return $version; |
| 458 |
} |
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
public static function getVersionLinked() { |
| 468 |
return self::getVersionLinkedGit() ?: MW_VERSION; |
| 469 |
} |
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
private static function getMWVersionLinked() { |
| 475 |
$versionUrl = ""; |
| 476 |
$hookRunner = new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ); |
| 477 |
if ( $hookRunner->onSpecialVersionVersionUrl( MW_VERSION, $versionUrl ) ) { |
| 478 |
$versionParts = []; |
| 479 |
preg_match( "/^(\d+\.\d+)/", MW_VERSION, $versionParts ); |
| 480 |
$versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}"; |
| 481 |
} |
| 482 |
|
| 483 |
return '[' . $versionUrl . ' ' . MW_VERSION . ']'; |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
private static function getVersionLinkedGit() { |
| 492 |
global $wgLang; |
| 493 |
|
| 494 |
$gitInfo = new GitInfo( MW_INSTALL_PATH ); |
| 495 |
$headSHA1 = $gitInfo->getHeadSHA1(); |
| 496 |
if ( !$headSHA1 ) { |
| 497 |
return false; |
| 498 |
} |
| 499 |
|
| 500 |
$shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')'; |
| 501 |
|
| 502 |
$gitHeadUrl = $gitInfo->getHeadViewUrl(); |
| 503 |
if ( $gitHeadUrl !== false ) { |
| 504 |
$shortSHA1 = "[$gitHeadUrl $shortSHA1]"; |
| 505 |
} |
| 506 |
|
| 507 |
$gitHeadCommitDate = $gitInfo->getHeadCommitDate(); |
| 508 |
if ( $gitHeadCommitDate ) { |
| 509 |
$shortSHA1 .= Html::element( 'br' ) . $wgLang->timeanddate( (string)$gitHeadCommitDate, true ); |
| 510 |
} |
| 511 |
|
| 512 |
return self::getMWVersionLinked() . " $shortSHA1"; |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
public static function getExtensionTypes(): array { |
| 525 |
if ( self::$extensionTypes === false ) { |
| 526 |
self::$extensionTypes = [ |
| 527 |
'specialpage' => wfMessage( 'version-specialpages' )->text(), |
| 528 |
'editor' => wfMessage( 'version-editors' )->text(), |
| 529 |
'parserhook' => wfMessage( 'version-parserhooks' )->text(), |
| 530 |
'variable' => wfMessage( 'version-variables' )->text(), |
| 531 |
'media' => wfMessage( 'version-mediahandlers' )->text(), |
| 532 |
'antispam' => wfMessage( 'version-antispam' )->text(), |
| 533 |
'skin' => wfMessage( 'version-skins' )->text(), |
| 534 |
'api' => wfMessage( 'version-api' )->text(), |
| 535 |
'other' => wfMessage( 'version-other' )->text(), |
| 536 |
]; |
| 537 |
|
| 538 |
( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) ) |
| 539 |
->onExtensionTypes( self::$extensionTypes ); |
| 540 |
} |
| 541 |
|
| 542 |
return self::$extensionTypes; |
| 543 |
} |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
public static function getExtensionTypeName( $type ) { |
| 555 |
$types = self::getExtensionTypes(); |
| 556 |
|
| 557 |
return $types[$type] ?? $types['other']; |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
private function getExtensionCredits( array $credits ) { |
| 567 |
$extensionTypes = self::getExtensionTypes(); |
| 568 |
|
| 569 |
$this->addTocSection( 'version-extensions', 'mw-version-ext' ); |
| 570 |
|
| 571 |
$out = Html::element( |
| 572 |
'h2', |
| 573 |
[ 'id' => 'mw-version-ext' ], |
| 574 |
$this->msg( 'version-extensions' )->text() |
| 575 |
); |
| 576 |
|
| 577 |
if ( |
| 578 |
!$credits || |
| 579 |
|
| 580 |
( count( $credits ) === 1 && isset( $credits['skin'] ) ) |
| 581 |
) { |
| 582 |
$out .= Html::element( |
| 583 |
'p', |
| 584 |
[], |
| 585 |
$this->msg( 'version-extensions-no-ext' )->text() |
| 586 |
); |
| 587 |
|
| 588 |
return $out; |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
$credits['other'] ??= []; |
| 593 |
foreach ( $credits as $type => $extensions ) { |
| 594 |
if ( !array_key_exists( $type, $extensionTypes ) ) { |
| 595 |
$credits['other'] = array_merge( $credits['other'], $extensions ); |
| 596 |
} |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
foreach ( $extensionTypes as $type => $text ) { |
| 601 |
|
| 602 |
if ( $type !== 'other' && $type !== 'skin' ) { |
| 603 |
$out .= $this->getExtensionCategory( $type, $text, $credits[$type] ?? [] ); |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
|
| 608 |
$out .= $this->getExtensionCategory( 'other', $extensionTypes['other'], $credits['other'] ); |
| 609 |
|
| 610 |
return $out; |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
private function getSkinCredits( array $credits ) { |
| 620 |
$this->addTocSection( 'version-skins', 'mw-version-skin' ); |
| 621 |
|
| 622 |
$out = Html::element( |
| 623 |
'h2', |
| 624 |
[ 'id' => 'mw-version-skin' ], |
| 625 |
$this->msg( 'version-skins' )->text() |
| 626 |
); |
| 627 |
|
| 628 |
if ( !isset( $credits['skin'] ) || !$credits['skin'] ) { |
| 629 |
$out .= Html::element( |
| 630 |
'p', |
| 631 |
[], |
| 632 |
$this->msg( 'version-skins-no-skin' )->text() |
| 633 |
); |
| 634 |
|
| 635 |
return $out; |
| 636 |
} |
| 637 |
$out .= $this->getExtensionCategory( 'skin', null, $credits['skin'] ); |
| 638 |
|
| 639 |
return $out; |
| 640 |
} |
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
protected function getLibraries( array $credits ) { |
| 649 |
$this->addTocSection( 'version-libraries', 'mw-version-libraries' ); |
| 650 |
|
| 651 |
$out = Html::element( |
| 652 |
'h2', |
| 653 |
[ 'id' => 'mw-version-libraries' ], |
| 654 |
$this->msg( 'version-libraries' )->text() |
| 655 |
); |
| 656 |
|
| 657 |
return $out |
| 658 |
. $this->getExternalLibraries( $credits ) |
| 659 |
. $this->getClientSideLibraries(); |
| 660 |
} |
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
protected function getExternalLibraries( array $credits ) { |
| 669 |
$paths = [ |
| 670 |
MW_INSTALL_PATH . '/vendor/composer/installed.json' |
| 671 |
]; |
| 672 |
|
| 673 |
$extensionTypes = self::getExtensionTypes(); |
| 674 |
foreach ( $extensionTypes as $type => $message ) { |
| 675 |
if ( !isset( $credits[$type] ) || $credits[$type] === [] ) { |
| 676 |
continue; |
| 677 |
} |
| 678 |
foreach ( $credits[$type] as $extension ) { |
| 679 |
if ( !isset( $extension['path'] ) ) { |
| 680 |
continue; |
| 681 |
} |
| 682 |
$paths[] = dirname( $extension['path'] ) . '/vendor/composer/installed.json'; |
| 683 |
} |
| 684 |
} |
| 685 |
|
| 686 |
$dependencies = []; |
| 687 |
|
| 688 |
foreach ( $paths as $path ) { |
| 689 |
if ( !file_exists( $path ) ) { |
| 690 |
continue; |
| 691 |
} |
| 692 |
|
| 693 |
$installed = new ComposerInstalled( $path ); |
| 694 |
|
| 695 |
$dependencies += $installed->getInstalledDependencies(); |
| 696 |
} |
| 697 |
|
| 698 |
if ( $dependencies === [] ) { |
| 699 |
return ''; |
| 700 |
} |
| 701 |
|
| 702 |
ksort( $dependencies ); |
| 703 |
|
| 704 |
$this->addTocSubSection( $this->msg( 'version-libraries-server' )->text(), 'mw-version-libraries-server' ); |
| 705 |
|
| 706 |
$out = Html::element( |
| 707 |
'h3', |
| 708 |
[ 'id' => 'mw-version-libraries-server' ], |
| 709 |
$this->msg( 'version-libraries-server' )->text() |
| 710 |
); |
| 711 |
$out .= Html::openElement( |
| 712 |
'table', |
| 713 |
[ 'class' => 'wikitable plainlinks mw-installed-software', 'id' => 'sv-libraries' ] |
| 714 |
); |
| 715 |
|
| 716 |
$out .= $this->getTableHeaderHtml( [ |
| 717 |
$this->msg( 'version-libraries-library' )->text(), |
| 718 |
$this->msg( 'version-libraries-version' )->text(), |
| 719 |
$this->msg( 'version-libraries-license' )->text(), |
| 720 |
$this->msg( 'version-libraries-description' )->text(), |
| 721 |
$this->msg( 'version-libraries-authors' )->text(), |
| 722 |
] ); |
| 723 |
|
| 724 |
foreach ( $dependencies as $name => $info ) { |
| 725 |
if ( !is_array( $info ) || str_starts_with( $info['type'], 'mediawiki-' ) ) { |
| 726 |
|
| 727 |
|
| 728 |
continue; |
| 729 |
} |
| 730 |
$authors = array_map( static function ( $arr ) { |
| 731 |
return new HtmlArmor( isset( $arr['homepage'] ) ? |
| 732 |
Html::element( 'a', [ 'href' => $arr['homepage'] ], $arr['name'] ) : |
| 733 |
htmlspecialchars( $arr['name'] ) |
| 734 |
); |
| 735 |
}, $info['authors'] ); |
| 736 |
$authors = $this->listAuthors( $authors, false, MW_INSTALL_PATH . "/vendor/$name" ); |
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
$out .= Html::openElement( 'tr', [ |
| 742 |
|
| 743 |
|
| 744 |
'id' => Sanitizer::escapeIdForAttribute( |
| 745 |
"mw-version-library-$name" |
| 746 |
) ] ) |
| 747 |
. Html::rawElement( |
| 748 |
'td', |
| 749 |
[], |
| 750 |
$this->getLinkRenderer()->makeExternalLink( |
| 751 |
"https://packagist.org/packages/$name", |
| 752 |
$name, |
| 753 |
$this->getFullTitle(), |
| 754 |
'', |
| 755 |
[ 'class' => 'mw-version-library-name' ] |
| 756 |
) |
| 757 |
) |
| 758 |
. Html::element( 'td', [ 'dir' => 'auto' ], $info['version'] ) |
| 759 |
|
| 760 |
. Html::element( 'td', [ 'dir' => 'auto' ], $this->listToText( $info['licenses'] ) ) |
| 761 |
. Html::element( 'td', [ 'lang' => 'en', 'dir' => 'ltr' ], $info['description'] ) |
| 762 |
. Html::rawElement( 'td', [], $authors ) |
| 763 |
. Html::closeElement( 'tr' ); |
| 764 |
} |
| 765 |
$out .= Html::closeElement( 'table' ); |
| 766 |
|
| 767 |
return $out; |
| 768 |
} |
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
public static function parseForeignResources() { |
| 776 |
$registryDirs = [ 'MediaWiki' => MW_INSTALL_PATH . '/resources/lib' ] |
| 777 |
+ ExtensionRegistry::getInstance()->getAttribute( 'ForeignResourcesDir' ); |
| 778 |
|
| 779 |
$modules = []; |
| 780 |
foreach ( $registryDirs as $source => $registryDir ) { |
| 781 |
$foreignResources = Yaml::parseFile( "$registryDir/foreign-resources.yaml" ); |
| 782 |
foreach ( $foreignResources as $name => $module ) { |
| 783 |
$key = $name . $module['version']; |
| 784 |
if ( isset( $modules[$key] ) ) { |
| 785 |
$modules[$key]['source'][] = $source; |
| 786 |
continue; |
| 787 |
} |
| 788 |
$modules[$key] = $module + [ 'name' => $name, 'source' => [ $source ] ]; |
| 789 |
} |
| 790 |
} |
| 791 |
ksort( $modules ); |
| 792 |
return $modules; |
| 793 |
} |
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
private function getClientSideLibraries() { |
| 801 |
$this->addTocSubSection( $this->msg( 'version-libraries-client' )->text(), 'mw-version-libraries-client' ); |
| 802 |
|
| 803 |
$out = Html::element( |
| 804 |
'h3', |
| 805 |
[ 'id' => 'mw-version-libraries-client' ], |
| 806 |
$this->msg( 'version-libraries-client' )->text() |
| 807 |
); |
| 808 |
$out .= Html::openElement( |
| 809 |
'table', |
| 810 |
[ 'class' => 'wikitable plainlinks mw-installed-software', 'id' => 'sv-libraries-client' ] |
| 811 |
); |
| 812 |
|
| 813 |
$out .= $this->getTableHeaderHtml( [ |
| 814 |
$this->msg( 'version-libraries-library' )->text(), |
| 815 |
$this->msg( 'version-libraries-version' )->text(), |
| 816 |
$this->msg( 'version-libraries-license' )->text(), |
| 817 |
$this->msg( 'version-libraries-authors' )->text(), |
| 818 |
$this->msg( 'version-libraries-source' )->text() |
| 819 |
] ); |
| 820 |
|
| 821 |
foreach ( self::parseForeignResources() as $name => $info ) { |
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
$out .= Html::openElement( 'tr', [ |
| 826 |
|
| 827 |
|
| 828 |
'id' => Sanitizer::escapeIdForAttribute( |
| 829 |
"mw-version-library-$name" |
| 830 |
) ] ) |
| 831 |
. Html::rawElement( |
| 832 |
'td', |
| 833 |
[], |
| 834 |
$this->getLinkRenderer()->makeExternalLink( |
| 835 |
$info['homepage'], |
| 836 |
$info['name'], |
| 837 |
$this->getFullTitle(), |
| 838 |
'', |
| 839 |
[ 'class' => 'mw-version-library-name' ] |
| 840 |
) |
| 841 |
) |
| 842 |
. Html::element( 'td', [ 'dir' => 'auto' ], $info['version'] ) |
| 843 |
. Html::element( 'td', [ 'dir' => 'auto' ], $info['license'] ) |
| 844 |
. Html::element( 'td', [ 'dir' => 'auto' ], $info['authors'] ?? '—' ) |
| 845 |
|
| 846 |
. Html::element( 'td', [ 'dir' => 'auto' ], $this->listToText( $info['source'] ) ) |
| 847 |
. Html::closeElement( 'tr' ); |
| 848 |
} |
| 849 |
$out .= Html::closeElement( 'table' ); |
| 850 |
|
| 851 |
return $out; |
| 852 |
} |
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
protected function getParserTags() { |
| 860 |
$tags = $this->parserFactory->getMainInstance()->getTags(); |
| 861 |
if ( !$tags ) { |
| 862 |
return ''; |
| 863 |
} |
| 864 |
|
| 865 |
$this->addTocSection( 'version-parser-extensiontags', 'mw-version-parser-extensiontags' ); |
| 866 |
|
| 867 |
$out = Html::rawElement( |
| 868 |
'h2', |
| 869 |
[ 'id' => 'mw-version-parser-extensiontags' ], |
| 870 |
Html::rawElement( |
| 871 |
'span', |
| 872 |
[ 'class' => 'plainlinks' ], |
| 873 |
$this->getLinkRenderer()->makeExternalLink( |
| 874 |
'https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions', |
| 875 |
$this->msg( 'version-parser-extensiontags' ), |
| 876 |
$this->getFullTitle() |
| 877 |
) |
| 878 |
) |
| 879 |
); |
| 880 |
|
| 881 |
array_walk( $tags, static function ( &$value ) { |
| 882 |
|
| 883 |
$value = Html::rawElement( |
| 884 |
'bdi', |
| 885 |
|
| 886 |
[ |
| 887 |
'style' => 'white-space: nowrap;', |
| 888 |
], |
| 889 |
Html::element( 'code', [], "<$value>" ) |
| 890 |
); |
| 891 |
} ); |
| 892 |
|
| 893 |
$out .= $this->listToText( $tags ); |
| 894 |
|
| 895 |
return $out; |
| 896 |
} |
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
protected function getParserFunctionHooks() { |
| 904 |
$funcHooks = $this->parserFactory->getMainInstance()->getFunctionHooks(); |
| 905 |
if ( !$funcHooks ) { |
| 906 |
return ''; |
| 907 |
} |
| 908 |
|
| 909 |
$this->addTocSection( 'version-parser-function-hooks', 'mw-version-parser-function-hooks' ); |
| 910 |
|
| 911 |
$out = Html::rawElement( |
| 912 |
'h2', |
| 913 |
[ 'id' => 'mw-version-parser-function-hooks' ], |
| 914 |
Html::rawElement( |
| 915 |
'span', |
| 916 |
[ 'class' => 'plainlinks' ], |
| 917 |
$this->getLinkRenderer()->makeExternalLink( |
| 918 |
'https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions', |
| 919 |
$this->msg( 'version-parser-function-hooks' ), |
| 920 |
$this->getFullTitle() |
| 921 |
) |
| 922 |
) |
| 923 |
); |
| 924 |
|
| 925 |
$funcSynonyms = $this->parserFactory->getMainInstance()->getFunctionSynonyms(); |
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
$preferredSynonyms = array_flip( array_reverse( $funcSynonyms[1] + $funcSynonyms[0] ) ); |
| 933 |
array_walk( $funcHooks, static function ( &$value ) use ( $preferredSynonyms ) { |
| 934 |
$value = $preferredSynonyms[$value]; |
| 935 |
} ); |
| 936 |
|
| 937 |
|
| 938 |
usort( $funcHooks, static function ( $a, $b ) { |
| 939 |
return strcasecmp( ltrim( $a, '#' ), ltrim( $b, '#' ) ); |
| 940 |
} ); |
| 941 |
|
| 942 |
array_walk( $funcHooks, static function ( &$value ) { |
| 943 |
|
| 944 |
$value = Html::rawElement( |
| 945 |
'bdi', |
| 946 |
[], |
| 947 |
Html::element( 'code', [], '{{' . $value . '}}' ) |
| 948 |
); |
| 949 |
} ); |
| 950 |
|
| 951 |
$out .= $this->getLanguage()->listToText( $funcHooks ); |
| 952 |
|
| 953 |
return $out; |
| 954 |
} |
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
protected function getExtensionCategory( $type, ?string $text, array $creditsGroup ) { |
| 966 |
$out = ''; |
| 967 |
|
| 968 |
if ( $creditsGroup ) { |
| 969 |
$out .= $this->openExtType( $text, 'credits-' . $type ); |
| 970 |
|
| 971 |
usort( $creditsGroup, [ $this, 'compare' ] ); |
| 972 |
|
| 973 |
foreach ( $creditsGroup as $extension ) { |
| 974 |
$out .= $this->getCreditsForExtension( $type, $extension ); |
| 975 |
} |
| 976 |
|
| 977 |
$out .= Html::closeElement( 'table' ); |
| 978 |
} |
| 979 |
|
| 980 |
return $out; |
| 981 |
} |
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
public function compare( $a, $b ) { |
| 990 |
return $this->getLanguage()->lc( $a['name'] ) <=> $this->getLanguage()->lc( $b['name'] ); |
| 991 |
} |
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
public function getCreditsForExtension( $type, array $extension ) { |
| 1012 |
$out = $this->getOutput(); |
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
if ( isset( $extension['namemsg'] ) ) { |
| 1017 |
|
| 1018 |
$extensionName = $this->msg( $extension['namemsg'] ); |
| 1019 |
} elseif ( isset( $extension['name'] ) ) { |
| 1020 |
|
| 1021 |
$extensionName = $extension['name']; |
| 1022 |
} else { |
| 1023 |
$extensionName = $this->msg( 'version-no-ext-name' ); |
| 1024 |
} |
| 1025 |
|
| 1026 |
if ( isset( $extension['url'] ) ) { |
| 1027 |
$extensionNameLink = $this->getLinkRenderer()->makeExternalLink( |
| 1028 |
$extension['url'], |
| 1029 |
$extensionName, |
| 1030 |
$this->getFullTitle(), |
| 1031 |
'', |
| 1032 |
[ 'class' => 'mw-version-ext-name' ] |
| 1033 |
); |
| 1034 |
} else { |
| 1035 |
$extensionNameLink = htmlspecialchars( $extensionName ); |
| 1036 |
} |
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
$canonicalVersion = '–'; |
| 1042 |
$extensionPath = null; |
| 1043 |
$vcsVersion = null; |
| 1044 |
$vcsLink = null; |
| 1045 |
$vcsDate = null; |
| 1046 |
|
| 1047 |
if ( isset( $extension['version'] ) ) { |
| 1048 |
$canonicalVersion = $out->parseInlineAsInterface( $extension['version'] ); |
| 1049 |
} |
| 1050 |
|
| 1051 |
if ( isset( $extension['path'] ) ) { |
| 1052 |
$extensionPath = dirname( $extension['path'] ); |
| 1053 |
if ( $this->coreId == '' ) { |
| 1054 |
wfDebug( 'Looking up core head id' ); |
| 1055 |
$coreHeadSHA1 = GitInfo::repo()->getHeadSHA1(); |
| 1056 |
if ( $coreHeadSHA1 ) { |
| 1057 |
$this->coreId = $coreHeadSHA1; |
| 1058 |
} |
| 1059 |
} |
| 1060 |
$cache = MediaWikiServices::getInstance()->getObjectCacheFactory()->getInstance( CACHE_ANYTHING ); |
| 1061 |
$memcKey = $cache->makeKey( |
| 1062 |
'specialversion-ext-version-text', $extension['path'], $this->coreId |
| 1063 |
); |
| 1064 |
$res = $cache->get( $memcKey ); |
| 1065 |
|
| 1066 |
if ( $res === false ) { |
| 1067 |
wfDebug( "Getting VCS info for extension {$extension['name']}" ); |
| 1068 |
$gitInfo = new GitInfo( $extensionPath ); |
| 1069 |
$vcsVersion = $gitInfo->getHeadSHA1(); |
| 1070 |
if ( $vcsVersion !== false ) { |
| 1071 |
$vcsVersion = substr( $vcsVersion, 0, 7 ); |
| 1072 |
$vcsLink = $gitInfo->getHeadViewUrl(); |
| 1073 |
$vcsDate = $gitInfo->getHeadCommitDate(); |
| 1074 |
} |
| 1075 |
$cache->set( $memcKey, [ $vcsVersion, $vcsLink, $vcsDate ], 60 * 60 * 24 ); |
| 1076 |
} else { |
| 1077 |
wfDebug( "Pulled VCS info for extension {$extension['name']} from cache" ); |
| 1078 |
[ $vcsVersion, $vcsLink, $vcsDate ] = $res; |
| 1079 |
} |
| 1080 |
} |
| 1081 |
|
| 1082 |
$versionString = Html::rawElement( |
| 1083 |
'span', |
| 1084 |
[ 'class' => 'mw-version-ext-version' ], |
| 1085 |
$canonicalVersion |
| 1086 |
); |
| 1087 |
|
| 1088 |
if ( $vcsVersion ) { |
| 1089 |
if ( $vcsLink ) { |
| 1090 |
$vcsVerString = $this->getLinkRenderer()->makeExternalLink( |
| 1091 |
$vcsLink, |
| 1092 |
$this->msg( 'version-version', $vcsVersion ), |
| 1093 |
$this->getFullTitle(), |
| 1094 |
'', |
| 1095 |
[ 'class' => 'mw-version-ext-vcs-version' ] |
| 1096 |
); |
| 1097 |
} else { |
| 1098 |
$vcsVerString = Html::element( 'span', |
| 1099 |
[ 'class' => 'mw-version-ext-vcs-version' ], |
| 1100 |
"({$vcsVersion})" |
| 1101 |
); |
| 1102 |
} |
| 1103 |
$versionString .= " {$vcsVerString}"; |
| 1104 |
|
| 1105 |
if ( $vcsDate ) { |
| 1106 |
$versionString .= ' ' . Html::element( 'span', [ |
| 1107 |
'class' => 'mw-version-ext-vcs-timestamp', |
| 1108 |
'dir' => $this->getLanguage()->getDir(), |
| 1109 |
], $this->getLanguage()->timeanddate( $vcsDate, true ) ); |
| 1110 |
} |
| 1111 |
$versionString = Html::rawElement( 'span', |
| 1112 |
[ 'class' => 'mw-version-ext-meta-version' ], |
| 1113 |
$versionString |
| 1114 |
); |
| 1115 |
} |
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
$licenseLink = ''; |
| 1120 |
if ( isset( $extension['name'] ) ) { |
| 1121 |
$licenseName = null; |
| 1122 |
if ( isset( $extension['license-name'] ) ) { |
| 1123 |
$licenseName = new HtmlArmor( $out->parseInlineAsInterface( $extension['license-name'] ) ); |
| 1124 |
} elseif ( $extensionPath !== null && ExtensionInfo::getLicenseFileNames( $extensionPath ) ) { |
| 1125 |
$licenseName = $this->msg( 'version-ext-license' )->text(); |
| 1126 |
} |
| 1127 |
if ( $licenseName !== null ) { |
| 1128 |
$licenseLink = $this->getLinkRenderer()->makeLink( |
| 1129 |
$this->getPageTitle( 'License/' . $extension['name'] ), |
| 1130 |
$licenseName, |
| 1131 |
[ |
| 1132 |
'class' => 'mw-version-ext-license', |
| 1133 |
'dir' => 'auto', |
| 1134 |
] |
| 1135 |
); |
| 1136 |
} |
| 1137 |
} |
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
if ( isset( $extension['descriptionmsg'] ) ) { |
| 1143 |
|
| 1144 |
$descriptionMsg = $extension['descriptionmsg']; |
| 1145 |
|
| 1146 |
if ( is_array( $descriptionMsg ) ) { |
| 1147 |
$descriptionMsgKey = array_shift( $descriptionMsg ); |
| 1148 |
$descriptionMsg = array_map( 'htmlspecialchars', $descriptionMsg ); |
| 1149 |
$description = $this->msg( $descriptionMsgKey, ...$descriptionMsg )->text(); |
| 1150 |
} else { |
| 1151 |
$description = $this->msg( $descriptionMsg )->text(); |
| 1152 |
} |
| 1153 |
} elseif ( isset( $extension['description'] ) ) { |
| 1154 |
|
| 1155 |
$description = $extension['description']; |
| 1156 |
} else { |
| 1157 |
$description = ''; |
| 1158 |
} |
| 1159 |
$description = $out->parseInlineAsInterface( $description ); |
| 1160 |
|
| 1161 |
|
| 1162 |
$authors = $extension['author'] ?? []; |
| 1163 |
|
| 1164 |
$authors = $this->listAuthors( $authors, $extension['name'], $extensionPath ); |
| 1165 |
|
| 1166 |
|
| 1167 |
$html = Html::openElement( 'tr', [ |
| 1168 |
'class' => 'mw-version-ext', |
| 1169 |
'id' => Sanitizer::escapeIdForAttribute( 'mw-version-ext-' . $type . '-' . $extension['name'] ) |
| 1170 |
] |
| 1171 |
); |
| 1172 |
|
| 1173 |
$html .= Html::rawElement( 'td', [], $extensionNameLink ); |
| 1174 |
$html .= Html::rawElement( 'td', [], $versionString ); |
| 1175 |
$html .= Html::rawElement( 'td', [], $licenseLink ); |
| 1176 |
$html .= Html::rawElement( 'td', [ 'class' => 'mw-version-ext-description' ], $description ); |
| 1177 |
$html .= Html::rawElement( 'td', [ 'class' => 'mw-version-ext-authors' ], $authors ); |
| 1178 |
|
| 1179 |
$html .= Html::closeElement( 'tr' ); |
| 1180 |
|
| 1181 |
return $html; |
| 1182 |
} |
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
private function getHooks() { |
| 1190 |
if ( !$this->getConfig()->get( MainConfigNames::SpecialVersionShowHooks ) ) { |
| 1191 |
return ''; |
| 1192 |
} |
| 1193 |
|
| 1194 |
$hookContainer = MediaWikiServices::getInstance()->getHookContainer(); |
| 1195 |
$hookNames = $hookContainer->getHookNames(); |
| 1196 |
|
| 1197 |
if ( !$hookNames ) { |
| 1198 |
return ''; |
| 1199 |
} |
| 1200 |
|
| 1201 |
sort( $hookNames ); |
| 1202 |
|
| 1203 |
$ret = []; |
| 1204 |
$this->addTocSection( 'version-hooks', 'mw-version-hooks' ); |
| 1205 |
$ret[] = Html::element( |
| 1206 |
'h2', |
| 1207 |
[ 'id' => 'mw-version-hooks' ], |
| 1208 |
$this->msg( 'version-hooks' )->text() |
| 1209 |
); |
| 1210 |
$ret[] = Html::openElement( 'table', [ 'class' => 'wikitable', 'id' => 'sv-hooks' ] ); |
| 1211 |
$ret[] = Html::openElement( 'tr' ); |
| 1212 |
$ret[] = Html::element( 'th', [], $this->msg( 'version-hook-name' )->text() ); |
| 1213 |
$ret[] = Html::element( 'th', [], $this->msg( 'version-hook-subscribedby' )->text() ); |
| 1214 |
$ret[] = Html::closeElement( 'tr' ); |
| 1215 |
|
| 1216 |
foreach ( $hookNames as $name ) { |
| 1217 |
$handlers = $hookContainer->getHandlerDescriptions( $name ); |
| 1218 |
|
| 1219 |
$ret[] = Html::openElement( 'tr' ); |
| 1220 |
$ret[] = Html::element( 'td', [], $name ); |
| 1221 |
|
| 1222 |
$ret[] = Html::element( 'td', [], $this->listToText( $handlers ) ); |
| 1223 |
$ret[] = Html::closeElement( 'tr' ); |
| 1224 |
} |
| 1225 |
|
| 1226 |
$ret[] = Html::closeElement( 'table' ); |
| 1227 |
|
| 1228 |
return implode( "\n", $ret ); |
| 1229 |
} |
| 1230 |
|
| 1231 |
private function openExtType( ?string $text = null, ?string $name = null ) { |
| 1232 |
$out = ''; |
| 1233 |
|
| 1234 |
$opt = [ 'class' => 'wikitable plainlinks mw-installed-software' ]; |
| 1235 |
|
| 1236 |
if ( $name ) { |
| 1237 |
$opt['id'] = "sv-$name"; |
| 1238 |
} |
| 1239 |
|
| 1240 |
$out .= Html::openElement( 'table', $opt ); |
| 1241 |
|
| 1242 |
if ( $text !== null ) { |
| 1243 |
$out .= Html::element( 'caption', [], $text ); |
| 1244 |
} |
| 1245 |
|
| 1246 |
if ( $name && $text !== null ) { |
| 1247 |
$this->addTocSubSection( $text, "sv-$name" ); |
| 1248 |
} |
| 1249 |
|
| 1250 |
$firstHeadingMsg = ( $name === 'credits-skin' ) |
| 1251 |
? 'version-skin-colheader-name' |
| 1252 |
: 'version-ext-colheader-name'; |
| 1253 |
|
| 1254 |
$out .= $this->getTableHeaderHtml( [ |
| 1255 |
$this->msg( $firstHeadingMsg )->text(), |
| 1256 |
$this->msg( 'version-ext-colheader-version' )->text(), |
| 1257 |
$this->msg( 'version-ext-colheader-license' )->text(), |
| 1258 |
$this->msg( 'version-ext-colheader-description' )->text(), |
| 1259 |
$this->msg( 'version-ext-colheader-credits' )->text() |
| 1260 |
] ); |
| 1261 |
|
| 1262 |
return $out; |
| 1263 |
} |
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
private function getTableHeaderHtml( $headers ): string { |
| 1274 |
$out = ''; |
| 1275 |
$out .= Html::openElement( 'thead' ); |
| 1276 |
$out .= Html::openElement( 'tr' ); |
| 1277 |
foreach ( $headers as $header ) { |
| 1278 |
$out .= Html::element( 'th', [ 'scope' => 'col' ], $header ); |
| 1279 |
} |
| 1280 |
$out .= Html::closeElement( 'tr' ); |
| 1281 |
$out .= Html::closeElement( 'thead' ); |
| 1282 |
return $out; |
| 1283 |
} |
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
private function IPInfo() { |
| 1291 |
$ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) ); |
| 1292 |
|
| 1293 |
return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>"; |
| 1294 |
} |
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
public function listAuthors( $authors, $extName, $extDir ): string { |
| 1317 |
$hasOthers = false; |
| 1318 |
$linkRenderer = $this->getLinkRenderer(); |
| 1319 |
|
| 1320 |
$list = []; |
| 1321 |
$authors = (array)$authors; |
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
if ( count( $authors ) === 1 && $authors[0] === '...' ) { |
| 1327 |
|
| 1328 |
|
| 1329 |
if ( $extName && ExtensionInfo::getAuthorsFileName( $extDir ) ) { |
| 1330 |
return $linkRenderer->makeLink( |
| 1331 |
$this->getPageTitle( "Credits/$extName" ), |
| 1332 |
$this->msg( 'version-poweredby-various' )->text() |
| 1333 |
); |
| 1334 |
} else { |
| 1335 |
return $this->msg( 'version-poweredby-various' )->escaped(); |
| 1336 |
} |
| 1337 |
} |
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
foreach ( $authors as $item ) { |
| 1342 |
if ( $item instanceof HtmlArmor ) { |
| 1343 |
$list[] = HtmlArmor::getHtml( $item ); |
| 1344 |
} elseif ( $item === '...' ) { |
| 1345 |
$hasOthers = true; |
| 1346 |
|
| 1347 |
if ( $extName && ExtensionInfo::getAuthorsFileName( $extDir ) ) { |
| 1348 |
$text = $linkRenderer->makeLink( |
| 1349 |
$this->getPageTitle( "Credits/$extName" ), |
| 1350 |
$this->msg( 'version-poweredby-others' )->text() |
| 1351 |
); |
| 1352 |
} else { |
| 1353 |
$text = $this->msg( 'version-poweredby-others' )->escaped(); |
| 1354 |
} |
| 1355 |
$list[] = $text; |
| 1356 |
} elseif ( str_ends_with( $item, ' ...]' ) ) { |
| 1357 |
$hasOthers = true; |
| 1358 |
$list[] = $this->getOutput()->parseInlineAsInterface( |
| 1359 |
substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]" |
| 1360 |
); |
| 1361 |
} else { |
| 1362 |
$list[] = $this->getOutput()->parseInlineAsInterface( $item ); |
| 1363 |
} |
| 1364 |
} |
| 1365 |
|
| 1366 |
if ( $extName && !$hasOthers && ExtensionInfo::getAuthorsFileName( $extDir ) ) { |
| 1367 |
$list[] = $linkRenderer->makeLink( |
| 1368 |
$this->getPageTitle( "Credits/$extName" ), |
| 1369 |
$this->msg( 'version-poweredby-others' )->text() |
| 1370 |
); |
| 1371 |
} |
| 1372 |
|
| 1373 |
return $this->listToText( $list, false ); |
| 1374 |
} |
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
private function listToText( array $list, bool $sort = true ): string { |
| 1386 |
if ( !$list ) { |
| 1387 |
return ''; |
| 1388 |
} |
| 1389 |
if ( $sort ) { |
| 1390 |
sort( $list ); |
| 1391 |
} |
| 1392 |
|
| 1393 |
return $this->getLanguage() |
| 1394 |
->listToText( array_map( [ __CLASS__, 'arrayToString' ], $list ) ); |
| 1395 |
} |
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
public static function arrayToString( $list ) { |
| 1407 |
if ( is_array( $list ) && count( $list ) == 1 ) { |
| 1408 |
$list = $list[0]; |
| 1409 |
} |
| 1410 |
if ( $list instanceof Closure ) { |
| 1411 |
|
| 1412 |
return 'Closure'; |
| 1413 |
} elseif ( is_object( $list ) ) { |
| 1414 |
return wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped(); |
| 1415 |
} elseif ( !is_array( $list ) ) { |
| 1416 |
return $list; |
| 1417 |
} else { |
| 1418 |
if ( is_object( $list[0] ) ) { |
| 1419 |
$class = get_class( $list[0] ); |
| 1420 |
} else { |
| 1421 |
$class = $list[0]; |
| 1422 |
} |
| 1423 |
|
| 1424 |
return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped(); |
| 1425 |
} |
| 1426 |
} |
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
public static function getGitHeadSha1( $dir ) { |
| 1434 |
wfDeprecated( __METHOD__, '1.41' ); |
| 1435 |
return ( new GitInfo( $dir ) )->getHeadSHA1(); |
| 1436 |
} |
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
public function getEntryPointInfo() { |
| 1443 |
$config = $this->getConfig(); |
| 1444 |
$scriptPath = $config->get( MainConfigNames::ScriptPath ) ?: '/'; |
| 1445 |
|
| 1446 |
$entryPoints = [ |
| 1447 |
'version-entrypoints-articlepath' => $config->get( MainConfigNames::ArticlePath ), |
| 1448 |
'version-entrypoints-scriptpath' => $scriptPath, |
| 1449 |
'version-entrypoints-index-php' => wfScript( 'index' ), |
| 1450 |
'version-entrypoints-api-php' => wfScript( 'api' ), |
| 1451 |
'version-entrypoints-rest-php' => wfScript( 'rest' ), |
| 1452 |
]; |
| 1453 |
|
| 1454 |
$language = $this->getLanguage(); |
| 1455 |
$thAttributes = [ |
| 1456 |
'dir' => $language->getDir(), |
| 1457 |
'lang' => $language->getHtmlCode(), |
| 1458 |
'scope' => 'col' |
| 1459 |
]; |
| 1460 |
|
| 1461 |
$this->addTocSection( 'version-entrypoints', 'mw-version-entrypoints' ); |
| 1462 |
|
| 1463 |
$out = Html::element( |
| 1464 |
'h2', |
| 1465 |
[ 'id' => 'mw-version-entrypoints' ], |
| 1466 |
$this->msg( 'version-entrypoints' )->text() |
| 1467 |
) . |
| 1468 |
Html::openElement( 'table', |
| 1469 |
[ |
| 1470 |
'class' => 'wikitable plainlinks', |
| 1471 |
'id' => 'mw-version-entrypoints-table', |
| 1472 |
'dir' => 'ltr', |
| 1473 |
'lang' => 'en' |
| 1474 |
] |
| 1475 |
) . |
| 1476 |
Html::openElement( 'thead' ) . |
| 1477 |
Html::openElement( 'tr' ) . |
| 1478 |
Html::element( |
| 1479 |
'th', |
| 1480 |
$thAttributes, |
| 1481 |
$this->msg( 'version-entrypoints-header-entrypoint' )->text() |
| 1482 |
) . |
| 1483 |
Html::element( |
| 1484 |
'th', |
| 1485 |
$thAttributes, |
| 1486 |
$this->msg( 'version-entrypoints-header-url' )->text() |
| 1487 |
) . |
| 1488 |
Html::closeElement( 'tr' ) . |
| 1489 |
Html::closeElement( 'thead' ); |
| 1490 |
|
| 1491 |
foreach ( $entryPoints as $message => $value ) { |
| 1492 |
$url = $this->urlUtils->expand( $value, PROTO_RELATIVE ); |
| 1493 |
$out .= Html::openElement( 'tr' ) . |
| 1494 |
Html::rawElement( 'td', [], $this->msg( $message )->parse() ) . |
| 1495 |
Html::rawElement( 'td', [], |
| 1496 |
Html::rawElement( |
| 1497 |
'code', |
| 1498 |
[], |
| 1499 |
$this->msg( new RawMessage( "[$url $value]" ) )->parse() |
| 1500 |
) |
| 1501 |
) . |
| 1502 |
Html::closeElement( 'tr' ); |
| 1503 |
} |
| 1504 |
|
| 1505 |
$out .= Html::closeElement( 'table' ); |
| 1506 |
|
| 1507 |
return $out; |
| 1508 |
} |
| 1509 |
|
| 1510 |
protected function getGroupName() { |
| 1511 |
return 'wiki'; |
| 1512 |
} |
| 1513 |
} |
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
class_alias( SpecialVersion::class, 'SpecialVersion' ); |