| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
r |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
use MediaWiki\Cache\LinkBatchFactory; |
| 26 |
use MediaWiki\Category\Category; |
| 27 |
use MediaWiki\Content\ContentHandler; |
| 28 |
use MediaWiki\Context\IContextSource; |
| 29 |
use MediaWiki\EditPage\TemplatesOnThisPageFormatter; |
| 30 |
use MediaWiki\Html\Html; |
| 31 |
use MediaWiki\Language\Language; |
| 32 |
use MediaWiki\Languages\LanguageNameUtils; |
| 33 |
use MediaWiki\Linker\Linker; |
| 34 |
use MediaWiki\Linker\LinkRenderer; |
| 35 |
use MediaWiki\Linker\LinksMigration; |
| 36 |
use MediaWiki\MainConfigNames; |
| 37 |
use MediaWiki\MediaWikiServices; |
| 38 |
use MediaWiki\Message\Message; |
| 39 |
use MediaWiki\Page\PageIdentity; |
| 40 |
use MediaWiki\Page\PageProps; |
| 41 |
use MediaWiki\Page\RedirectLookup; |
| 42 |
use MediaWiki\Parser\MagicWordFactory; |
| 43 |
use MediaWiki\Parser\ParserOutput; |
| 44 |
use MediaWiki\Parser\Sanitizer; |
| 45 |
use MediaWiki\Permissions\RestrictionStore; |
| 46 |
use MediaWiki\Revision\RevisionLookup; |
| 47 |
use MediaWiki\Revision\RevisionRecord; |
| 48 |
use MediaWiki\SpecialPage\SpecialPage; |
| 49 |
use MediaWiki\Title\NamespaceInfo; |
| 50 |
use MediaWiki\Title\Title; |
| 51 |
use MediaWiki\User\UserFactory; |
| 52 |
use MediaWiki\Watchlist\WatchedItemStoreInterface; |
| 53 |
use Wikimedia\ObjectCache\WANObjectCache; |
| 54 |
use Wikimedia\Rdbms\Database; |
| 55 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 56 |
use Wikimedia\Rdbms\IDBAccessObject; |
| 57 |
use Wikimedia\Rdbms\IExpression; |
| 58 |
use Wikimedia\Rdbms\LikeValue; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
class InfoAction extends FormlessAction { |
| 66 |
private const VERSION = 1; |
| 67 |
|
| 68 |
private Language $contentLanguage; |
| 69 |
private LanguageNameUtils $languageNameUtils; |
| 70 |
private LinkBatchFactory $linkBatchFactory; |
| 71 |
private LinkRenderer $linkRenderer; |
| 72 |
private IConnectionProvider $dbProvider; |
| 73 |
private MagicWordFactory $magicWordFactory; |
| 74 |
private NamespaceInfo $namespaceInfo; |
| 75 |
private PageProps $pageProps; |
| 76 |
private RepoGroup $repoGroup; |
| 77 |
private RevisionLookup $revisionLookup; |
| 78 |
private WANObjectCache $wanObjectCache; |
| 79 |
private WatchedItemStoreInterface $watchedItemStore; |
| 80 |
private RedirectLookup $redirectLookup; |
| 81 |
private RestrictionStore $restrictionStore; |
| 82 |
private LinksMigration $linksMigration; |
| 83 |
private UserFactory $userFactory; |
| 84 |
|
| 85 |
public function __construct( |
| 86 |
Article $article, |
| 87 |
IContextSource $context, |
| 88 |
Language $contentLanguage, |
| 89 |
LanguageNameUtils $languageNameUtils, |
| 90 |
LinkBatchFactory $linkBatchFactory, |
| 91 |
LinkRenderer $linkRenderer, |
| 92 |
IConnectionProvider $dbProvider, |
| 93 |
MagicWordFactory $magicWordFactory, |
| 94 |
NamespaceInfo $namespaceInfo, |
| 95 |
PageProps $pageProps, |
| 96 |
RepoGroup $repoGroup, |
| 97 |
RevisionLookup $revisionLookup, |
| 98 |
WANObjectCache $wanObjectCache, |
| 99 |
WatchedItemStoreInterface $watchedItemStore, |
| 100 |
RedirectLookup $redirectLookup, |
| 101 |
RestrictionStore $restrictionStore, |
| 102 |
LinksMigration $linksMigration, |
| 103 |
UserFactory $userFactory |
| 104 |
) { |
| 105 |
parent::__construct( $article, $context ); |
| 106 |
$this->contentLanguage = $contentLanguage; |
| 107 |
$this->languageNameUtils = $languageNameUtils; |
| 108 |
$this->linkBatchFactory = $linkBatchFactory; |
| 109 |
$this->linkRenderer = $linkRenderer; |
| 110 |
$this->dbProvider = $dbProvider; |
| 111 |
$this->magicWordFactory = $magicWordFactory; |
| 112 |
$this->namespaceInfo = $namespaceInfo; |
| 113 |
$this->pageProps = $pageProps; |
| 114 |
$this->repoGroup = $repoGroup; |
| 115 |
$this->revisionLookup = $revisionLookup; |
| 116 |
$this->wanObjectCache = $wanObjectCache; |
| 117 |
$this->watchedItemStore = $watchedItemStore; |
| 118 |
$this->redirectLookup = $redirectLookup; |
| 119 |
$this->restrictionStore = $restrictionStore; |
| 120 |
$this->linksMigration = $linksMigration; |
| 121 |
$this->userFactory = $userFactory; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
public function getName() { |
| 126 |
return 'info'; |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
public function requiresUnblock() { |
| 131 |
return false; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
public function requiresWrite() { |
| 136 |
return false; |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
public static function invalidateCache( PageIdentity $page, $revid = null ) { |
| 147 |
$services = MediaWikiServices::getInstance(); |
| 148 |
if ( $revid === null ) { |
| 149 |
$revision = $services->getRevisionLookup() |
| 150 |
->getRevisionByTitle( $page, 0, IDBAccessObject::READ_LATEST ); |
| 151 |
$revid = $revision ? $revision->getId() : 0; |
| 152 |
} |
| 153 |
$cache = $services->getMainWANObjectCache(); |
| 154 |
$key = self::getCacheKey( $cache, $page, $revid ?? 0 ); |
| 155 |
$cache->delete( $key ); |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
public function onView() { |
| 164 |
$this->getOutput()->addModuleStyles( [ |
| 165 |
'mediawiki.interface.helpers.styles', |
| 166 |
'mediawiki.action.styles', |
| 167 |
] ); |
| 168 |
|
| 169 |
|
| 170 |
$this->addHelpLink( 'Page information' ); |
| 171 |
|
| 172 |
|
| 173 |
$oldid = $this->getArticle()->getOldID(); |
| 174 |
if ( $oldid ) { |
| 175 |
$revRecord = $this->getArticle()->fetchRevisionRecord(); |
| 176 |
|
| 177 |
if ( !$revRecord ) { |
| 178 |
return $this->msg( 'missing-revision', $oldid )->parse(); |
| 179 |
} elseif ( !$revRecord->isCurrent() ) { |
| 180 |
return $this->msg( 'pageinfo-not-current' )->plain(); |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
$msg = $this->msg( 'pageinfo-header' ); |
| 186 |
$content = $msg->isDisabled() ? '' : $msg->parse(); |
| 187 |
|
| 188 |
|
| 189 |
$pageInfo = $this->pageInfo(); |
| 190 |
|
| 191 |
|
| 192 |
$this->getHookRunner()->onInfoAction( $this->getContext(), $pageInfo ); |
| 193 |
|
| 194 |
|
| 195 |
foreach ( $pageInfo as $header => $infoTable ) { |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
$content .= $this->makeHeader( |
| 200 |
$this->msg( "pageinfo-$header" )->text(), |
| 201 |
"mw-pageinfo-$header" |
| 202 |
) . "\n"; |
| 203 |
$rows = ''; |
| 204 |
$below = ""; |
| 205 |
foreach ( $infoTable as $infoRow ) { |
| 206 |
if ( $infoRow[0] == "below" ) { |
| 207 |
$below = $infoRow[1] . "\n"; |
| 208 |
continue; |
| 209 |
} |
| 210 |
$name = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->escaped() : $infoRow[0]; |
| 211 |
$value = ( $infoRow[1] instanceof Message ) ? $infoRow[1]->escaped() : $infoRow[1]; |
| 212 |
$id = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->getKey() : null; |
| 213 |
$rows .= $this->getRow( $name, $value, $id ) . "\n"; |
| 214 |
} |
| 215 |
if ( $rows !== '' ) { |
| 216 |
$content .= Html::rawElement( 'table', [ 'class' => 'wikitable mw-page-info' ], |
| 217 |
"\n" . $rows ); |
| 218 |
} |
| 219 |
$content .= "\n" . $below; |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
if ( !$this->msg( 'pageinfo-footer' )->isDisabled() ) { |
| 224 |
$content .= $this->msg( 'pageinfo-footer' )->parse(); |
| 225 |
} |
| 226 |
|
| 227 |
return $content; |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
private function makeHeader( $header, $canonicalId ) { |
| 238 |
return Html::rawElement( |
| 239 |
'h2', |
| 240 |
[ 'id' => Sanitizer::escapeIdForAttribute( $header ) ], |
| 241 |
Html::element( |
| 242 |
'span', |
| 243 |
[ 'id' => Sanitizer::escapeIdForAttribute( $canonicalId ) ], |
| 244 |
'' |
| 245 |
) . |
| 246 |
htmlspecialchars( $header ) |
| 247 |
); |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
private function getRow( $name, $value, $id ) { |
| 258 |
return Html::rawElement( |
| 259 |
'tr', |
| 260 |
[ |
| 261 |
'id' => $id === null ? null : 'mw-' . $id, |
| 262 |
'style' => 'vertical-align: top;', |
| 263 |
], |
| 264 |
Html::rawElement( 'td', [], $name ) . |
| 265 |
Html::rawElement( 'td', [], $value ) |
| 266 |
); |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
private function pageInfo() { |
| 283 |
$user = $this->getUser(); |
| 284 |
$lang = $this->getLanguage(); |
| 285 |
$title = $this->getTitle(); |
| 286 |
$id = $title->getArticleID(); |
| 287 |
$config = $this->context->getConfig(); |
| 288 |
$linkRenderer = $this->linkRenderer; |
| 289 |
|
| 290 |
$pageCounts = $this->pageCounts(); |
| 291 |
|
| 292 |
$pageProperties = $this->pageProps->getAllProperties( $title )[$id] ?? []; |
| 293 |
|
| 294 |
|
| 295 |
$pageInfo = []; |
| 296 |
$pageInfo['header-basic'] = []; |
| 297 |
|
| 298 |
|
| 299 |
$displayTitle = $pageProperties['displaytitle'] ?? |
| 300 |
htmlspecialchars( $title->getPrefixedText(), ENT_NOQUOTES ); |
| 301 |
|
| 302 |
$pageInfo['header-basic'][] = [ |
| 303 |
$this->msg( 'pageinfo-display-title' ), |
| 304 |
$displayTitle |
| 305 |
]; |
| 306 |
|
| 307 |
|
| 308 |
$redirectTarget = $this->redirectLookup->getRedirectTarget( $this->getWikiPage() ); |
| 309 |
if ( $redirectTarget !== null ) { |
| 310 |
$pageInfo['header-basic'][] = [ |
| 311 |
$this->msg( 'pageinfo-redirectsto' ), |
| 312 |
$linkRenderer->makeLink( $redirectTarget ) . |
| 313 |
$this->msg( 'word-separator' )->escaped() . |
| 314 |
$this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink( |
| 315 |
$redirectTarget, |
| 316 |
$this->msg( 'pageinfo-redirectsto-info' )->text(), |
| 317 |
[], |
| 318 |
[ 'action' => 'info' ] |
| 319 |
) )->escaped() |
| 320 |
]; |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
$sortKey = $pageProperties['defaultsort'] ?? $title->getCategorySortkey(); |
| 325 |
$pageInfo['header-basic'][] = [ |
| 326 |
$this->msg( 'pageinfo-default-sort' ), |
| 327 |
htmlspecialchars( $sortKey ) |
| 328 |
]; |
| 329 |
|
| 330 |
|
| 331 |
$pageInfo['header-basic'][] = [ |
| 332 |
$this->msg( 'pageinfo-length' ), |
| 333 |
$lang->formatNum( $title->getLength() ) |
| 334 |
]; |
| 335 |
|
| 336 |
|
| 337 |
$pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-namespace-id' ), $title->getNamespace() ]; |
| 338 |
$pageNamespace = $title->getNsText(); |
| 339 |
if ( $pageNamespace ) { |
| 340 |
$pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-namespace' ), $pageNamespace ]; |
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
$pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-article-id' ), $id ]; |
| 345 |
|
| 346 |
|
| 347 |
$pageLang = $title->getPageLanguage()->getCode(); |
| 348 |
|
| 349 |
$pageLangHtml = $pageLang . ' - ' . |
| 350 |
$this->languageNameUtils->getLanguageName( $pageLang, $lang->getCode() ); |
| 351 |
|
| 352 |
if ( $config->get( MainConfigNames::PageLanguageUseDB ) |
| 353 |
&& $this->getAuthority()->probablyCan( 'pagelang', $title ) |
| 354 |
) { |
| 355 |
$pageLangHtml .= $this->msg( 'word-separator' )->escaped(); |
| 356 |
$pageLangHtml .= $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink( |
| 357 |
SpecialPage::getTitleValueFor( 'PageLanguage', $title->getPrefixedText() ), |
| 358 |
$this->msg( 'pageinfo-language-change' )->text() |
| 359 |
) )->escaped(); |
| 360 |
} |
| 361 |
|
| 362 |
$pageInfo['header-basic'][] = [ |
| 363 |
$this->msg( 'pageinfo-language' )->escaped(), |
| 364 |
$pageLangHtml |
| 365 |
]; |
| 366 |
|
| 367 |
|
| 368 |
$modelHtml = htmlspecialchars( ContentHandler::getLocalizedName( $title->getContentModel() ) ); |
| 369 |
|
| 370 |
if ( $this->getAuthority()->probablyCan( 'editcontentmodel', $title ) ) { |
| 371 |
$modelHtml .= $this->msg( 'word-separator' )->escaped(); |
| 372 |
$modelHtml .= $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink( |
| 373 |
SpecialPage::getTitleValueFor( 'ChangeContentModel', $title->getPrefixedText() ), |
| 374 |
$this->msg( 'pageinfo-content-model-change' )->text() |
| 375 |
) )->escaped(); |
| 376 |
} |
| 377 |
|
| 378 |
$pageInfo['header-basic'][] = [ |
| 379 |
$this->msg( 'pageinfo-content-model' ), |
| 380 |
$modelHtml |
| 381 |
]; |
| 382 |
|
| 383 |
if ( $title->inNamespace( NS_USER ) ) { |
| 384 |
$pageUser = $this->userFactory->newFromName( $title->getRootText() ); |
| 385 |
if ( $pageUser && $pageUser->getId() && !$pageUser->isHidden() ) { |
| 386 |
$pageInfo['header-basic'][] = [ |
| 387 |
$this->msg( 'pageinfo-user-id' ), |
| 388 |
$pageUser->getId() |
| 389 |
]; |
| 390 |
} |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
$parserOutput = new ParserOutput(); |
| 395 |
if ( isset( $pageProperties['noindex'] ) ) { |
| 396 |
$parserOutput->setIndexPolicy( 'noindex' ); |
| 397 |
} |
| 398 |
if ( isset( $pageProperties['index'] ) ) { |
| 399 |
$parserOutput->setIndexPolicy( 'index' ); |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
$policy = $this->getArticle()->getRobotPolicy( 'view', $parserOutput ); |
| 404 |
$pageInfo['header-basic'][] = [ |
| 405 |
|
| 406 |
$this->msg( 'pageinfo-robot-policy' ), |
| 407 |
$this->msg( "pageinfo-robot-{$policy['index']}" ) |
| 408 |
]; |
| 409 |
|
| 410 |
$unwatchedPageThreshold = $config->get( MainConfigNames::UnwatchedPageThreshold ); |
| 411 |
if ( $this->getAuthority()->isAllowed( 'unwatchedpages' ) || |
| 412 |
( $unwatchedPageThreshold !== false && |
| 413 |
$pageCounts['watchers'] >= $unwatchedPageThreshold ) |
| 414 |
) { |
| 415 |
|
| 416 |
$pageInfo['header-basic'][] = [ |
| 417 |
$this->msg( 'pageinfo-watchers' ), |
| 418 |
$lang->formatNum( $pageCounts['watchers'] ) |
| 419 |
]; |
| 420 |
|
| 421 |
$visiting = $pageCounts['visitingWatchers'] ?? null; |
| 422 |
if ( $visiting !== null && $config->get( MainConfigNames::ShowUpdatedMarker ) ) { |
| 423 |
if ( $visiting > $config->get( MainConfigNames::UnwatchedPageSecret ) || |
| 424 |
$this->getAuthority()->isAllowed( 'unwatchedpages' ) |
| 425 |
) { |
| 426 |
$value = $lang->formatNum( $visiting ); |
| 427 |
} else { |
| 428 |
$value = $this->msg( 'pageinfo-few-visiting-watchers' ); |
| 429 |
} |
| 430 |
$pageInfo['header-basic'][] = [ |
| 431 |
$this->msg( 'pageinfo-visiting-watchers' ) |
| 432 |
->numParams( ceil( $config->get( MainConfigNames::WatchersMaxAge ) / 86400 ) ), |
| 433 |
$value |
| 434 |
]; |
| 435 |
} |
| 436 |
} elseif ( $unwatchedPageThreshold !== false ) { |
| 437 |
$pageInfo['header-basic'][] = [ |
| 438 |
$this->msg( 'pageinfo-watchers' ), |
| 439 |
$this->msg( 'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold ) |
| 440 |
]; |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
$whatLinksHere = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() ); |
| 445 |
$pageInfo['header-basic'][] = [ |
| 446 |
$linkRenderer->makeLink( |
| 447 |
$whatLinksHere, |
| 448 |
$this->msg( 'pageinfo-redirects-name' )->text(), |
| 449 |
[], |
| 450 |
[ |
| 451 |
'hidelinks' => 1, |
| 452 |
'hidetrans' => 1, |
| 453 |
'hideimages' => $title->getNamespace() === NS_FILE |
| 454 |
] |
| 455 |
), |
| 456 |
$this->msg( 'pageinfo-redirects-value' ) |
| 457 |
->numParams( count( $title->getRedirectsHere() ) ) |
| 458 |
]; |
| 459 |
|
| 460 |
|
| 461 |
if ( $this->getWikiPage()->isCountable() ) { |
| 462 |
$pageInfo['header-basic'][] = [ |
| 463 |
$this->msg( 'pageinfo-contentpage' ), |
| 464 |
$this->msg( 'pageinfo-contentpage-yes' ) |
| 465 |
]; |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
if ( $this->namespaceInfo->hasSubpages( $title->getNamespace() ) ) { |
| 470 |
$prefixIndex = SpecialPage::getTitleFor( |
| 471 |
'Prefixindex', |
| 472 |
$title->getPrefixedText() . '/' |
| 473 |
); |
| 474 |
$pageInfo['header-basic'][] = [ |
| 475 |
$linkRenderer->makeLink( |
| 476 |
$prefixIndex, |
| 477 |
$this->msg( 'pageinfo-subpages-name' )->text() |
| 478 |
), |
| 479 |
|
| 480 |
isset( $pageCounts['subpages'] ) |
| 481 |
? $this->msg( 'pageinfo-subpages-value' )->numParams( |
| 482 |
$pageCounts['subpages']['total'], |
| 483 |
$pageCounts['subpages']['redirects'], |
| 484 |
$pageCounts['subpages']['nonredirects'] |
| 485 |
) : $this->msg( 'pageinfo-subpages-value-unknown' )->rawParams( |
| 486 |
$linkRenderer->makeKnownLink( |
| 487 |
$title, $this->msg( 'purge' )->text(), [], [ 'action' => 'purge' ] ) |
| 488 |
) |
| 489 |
]; |
| 490 |
} |
| 491 |
|
| 492 |
if ( $title->inNamespace( NS_CATEGORY ) ) { |
| 493 |
$category = Category::newFromTitle( $title ); |
| 494 |
|
| 495 |
$allCount = $category->getMemberCount(); |
| 496 |
$subcatCount = $category->getSubcatCount(); |
| 497 |
$fileCount = $category->getFileCount(); |
| 498 |
$pageCount = $category->getPageCount( Category::COUNT_CONTENT_PAGES ); |
| 499 |
|
| 500 |
$pageInfo['category-info'] = [ |
| 501 |
[ |
| 502 |
$this->msg( 'pageinfo-category-total' ), |
| 503 |
$lang->formatNum( $allCount ) |
| 504 |
], |
| 505 |
[ |
| 506 |
$this->msg( 'pageinfo-category-pages' ), |
| 507 |
$lang->formatNum( $pageCount ) |
| 508 |
], |
| 509 |
[ |
| 510 |
$this->msg( 'pageinfo-category-subcats' ), |
| 511 |
$lang->formatNum( $subcatCount ) |
| 512 |
], |
| 513 |
[ |
| 514 |
$this->msg( 'pageinfo-category-files' ), |
| 515 |
$lang->formatNum( $fileCount ) |
| 516 |
] |
| 517 |
]; |
| 518 |
} |
| 519 |
|
| 520 |
|
| 521 |
if ( $title->inNamespace( NS_FILE ) ) { |
| 522 |
$fileObj = $this->repoGroup->findFile( $title ); |
| 523 |
if ( $fileObj !== false ) { |
| 524 |
|
| 525 |
$output = Wikimedia\base_convert( $fileObj->getSha1(), 36, 16, 40 ); |
| 526 |
$pageInfo['header-basic'][] = [ |
| 527 |
$this->msg( 'pageinfo-file-hash' ), |
| 528 |
$output |
| 529 |
]; |
| 530 |
} |
| 531 |
} |
| 532 |
|
| 533 |
|
| 534 |
$pageInfo['header-restrictions'] = []; |
| 535 |
|
| 536 |
|
| 537 |
if ( $this->restrictionStore->isCascadeProtected( $title ) ) { |
| 538 |
$cascadingFrom = ''; |
| 539 |
$sources = $this->restrictionStore->getCascadeProtectionSources( $title )[0]; |
| 540 |
|
| 541 |
foreach ( $sources as $sourcePageIdentity ) { |
| 542 |
$cascadingFrom .= Html::rawElement( |
| 543 |
'li', |
| 544 |
[], |
| 545 |
$linkRenderer->makeKnownLink( $sourcePageIdentity ) |
| 546 |
); |
| 547 |
} |
| 548 |
|
| 549 |
$cascadingFrom = Html::rawElement( 'ul', [], $cascadingFrom ); |
| 550 |
$pageInfo['header-restrictions'][] = [ |
| 551 |
$this->msg( 'pageinfo-protect-cascading-from' ), |
| 552 |
$cascadingFrom |
| 553 |
]; |
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
if ( $this->restrictionStore->areRestrictionsCascading( $title ) ) { |
| 558 |
$pageInfo['header-restrictions'][] = [ |
| 559 |
$this->msg( 'pageinfo-protect-cascading' ), |
| 560 |
$this->msg( 'pageinfo-protect-cascading-yes' ) |
| 561 |
]; |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
foreach ( $this->restrictionStore->listApplicableRestrictionTypes( $title ) as $restrictionType ) { |
| 566 |
$protections = $this->restrictionStore->getRestrictions( $title, $restrictionType ); |
| 567 |
|
| 568 |
switch ( count( $protections ) ) { |
| 569 |
case 0: |
| 570 |
$message = $this->getNamespaceProtectionMessage( $title ) ?? |
| 571 |
|
| 572 |
$this->msg( 'protect-default' )->escaped(); |
| 573 |
break; |
| 574 |
|
| 575 |
case 1: |
| 576 |
|
| 577 |
$message = $this->msg( 'protect-level-' . $protections[0] ); |
| 578 |
if ( !$message->isDisabled() ) { |
| 579 |
$message = $message->escaped(); |
| 580 |
break; |
| 581 |
} |
| 582 |
|
| 583 |
|
| 584 |
default: |
| 585 |
|
| 586 |
$message = $this->msg( "protect-fallback", $lang->commaList( $protections ) )->parse(); |
| 587 |
break; |
| 588 |
} |
| 589 |
$expiry = $this->restrictionStore->getRestrictionExpiry( $title, $restrictionType ); |
| 590 |
$formattedexpiry = $expiry === null ? '' : $this->msg( |
| 591 |
'parentheses', |
| 592 |
$lang->formatExpiry( $expiry, true, 'infinity', $user ) |
| 593 |
)->escaped(); |
| 594 |
$message .= $this->msg( 'word-separator' )->escaped() . $formattedexpiry; |
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
$pageInfo['header-restrictions'][] = [ |
| 599 |
$this->msg( "restriction-$restrictionType" ), $message |
| 600 |
]; |
| 601 |
} |
| 602 |
$protectLog = SpecialPage::getTitleFor( 'Log' ); |
| 603 |
$pageInfo['header-restrictions'][] = [ |
| 604 |
'below', |
| 605 |
$linkRenderer->makeKnownLink( |
| 606 |
$protectLog, |
| 607 |
$this->msg( 'pageinfo-view-protect-log' )->text(), |
| 608 |
[], |
| 609 |
[ 'type' => 'protect', 'page' => $title->getPrefixedText() ] |
| 610 |
), |
| 611 |
]; |
| 612 |
|
| 613 |
if ( !$this->getWikiPage()->exists() ) { |
| 614 |
return $pageInfo; |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
$pageInfo['header-edits'] = []; |
| 619 |
|
| 620 |
$firstRev = $this->revisionLookup->getFirstRevision( $this->getTitle() ); |
| 621 |
$lastRev = $this->getWikiPage()->getRevisionRecord(); |
| 622 |
$batch = $this->linkBatchFactory->newLinkBatch(); |
| 623 |
if ( $firstRev ) { |
| 624 |
$firstRevUser = $firstRev->getUser( RevisionRecord::FOR_THIS_USER, $user ); |
| 625 |
if ( $firstRevUser ) { |
| 626 |
$batch->add( NS_USER, $firstRevUser->getName() ); |
| 627 |
$batch->add( NS_USER_TALK, $firstRevUser->getName() ); |
| 628 |
} |
| 629 |
} |
| 630 |
|
| 631 |
if ( $lastRev ) { |
| 632 |
$lastRevUser = $lastRev->getUser( RevisionRecord::FOR_THIS_USER, $user ); |
| 633 |
if ( $lastRevUser ) { |
| 634 |
$batch->add( NS_USER, $lastRevUser->getName() ); |
| 635 |
$batch->add( NS_USER_TALK, $lastRevUser->getName() ); |
| 636 |
} |
| 637 |
} |
| 638 |
|
| 639 |
$batch->execute(); |
| 640 |
|
| 641 |
if ( $firstRev ) { |
| 642 |
|
| 643 |
$firstRevUser = $firstRev->getUser( RevisionRecord::FOR_THIS_USER, $user ); |
| 644 |
in |
| 645 |
|
| 646 |
|
| 647 |
$firstRevUserName = $firstRevUser ? $firstRevUser->getName() : '[HIDDEN]'; |
| 648 |
$pageInfo['header-edits'][] = [ |
| 649 |
$this->msg( 'pageinfo-firstuser', $firstRevUserName ), |
| 650 |
Linker::revUserTools( $firstRev ) |
| 651 |
]; |
| 652 |
|
| 653 |
|
| 654 |
$pageInfo['header-edits'][] = [ |
| 655 |
$this->msg( 'pageinfo-firsttime' ), |
| 656 |
$linkRenderer->makeKnownLink( |
| 657 |
$title, |
| 658 |
$lang->userTimeAndDate( $firstRev->getTimestamp(), $user ), |
| 659 |
[], |
| 660 |
[ 'oldid' => $firstRev->getId() ] |
| 661 |
) |
| 662 |
]; |
| 663 |
} |
| 664 |
|
| 665 |
if ( $lastRev ) { |
| 666 |
|
| 667 |
$lastRevUser = $lastRev->getUser( RevisionRecord::FOR_THIS_USER, $user ); |
| 668 |
in |
| 669 |
|
| 670 |
|
| 671 |
$lastRevUserName = $lastRevUser ? $lastRevUser->getName() : '[HIDDEN]'; |
| 672 |
$pageInfo['header-edits'][] = [ |
| 673 |
$this->msg( 'pageinfo-lastuser', $lastRevUserName ), |
| 674 |
Linker::revUserTools( $lastRev ) |
| 675 |
]; |
| 676 |
|
| 677 |
|
| 678 |
$pageInfo['header-edits'][] = [ |
| 679 |
$this->msg( 'pageinfo-lasttime' ), |
| 680 |
$linkRenderer->makeKnownLink( |
| 681 |
$title, |
| 682 |
$lang->userTimeAndDate( $this->getWikiPage()->getTimestamp(), $user ), |
| 683 |
[], |
| 684 |
[ 'oldid' => $this->getWikiPage()->getLatest() ] |
| 685 |
) |
| 686 |
]; |
| 687 |
} |
| 688 |
|
| 689 |
|
| 690 |
$pageInfo['header-edits'][] = [ |
| 691 |
$this->msg( 'pageinfo-edits' ), |
| 692 |
$lang->formatNum( $pageCounts['edits'] ) |
| 693 |
]; |
| 694 |
|
| 695 |
|
| 696 |
if ( $pageCounts['authors'] > 0 ) { |
| 697 |
$pageInfo['header-edits'][] = [ |
| 698 |
$this->msg( 'pageinfo-authors' ), |
| 699 |
$lang->formatNum( $pageCounts['authors'] ) |
| 700 |
]; |
| 701 |
} |
| 702 |
|
| 703 |
|
| 704 |
$pageInfo['header-edits'][] = [ |
| 705 |
$this->msg( |
| 706 |
'pageinfo-recent-edits', |
| 707 |
$lang->formatDuration( $config->get( MainConfigNames::RCMaxAge ) ) |
| 708 |
), |
| 709 |
$lang->formatNum( $pageCounts['recent_edits'] ) |
| 710 |
]; |
| 711 |
|
| 712 |
|
| 713 |
$pageInfo['header-edits'][] = [ |
| 714 |
$this->msg( 'pageinfo-recent-authors' ), |
| 715 |
$lang->formatNum( $pageCounts['recent_authors'] ) |
| 716 |
]; |
| 717 |
|
| 718 |
|
| 719 |
$wordIDs = $this->magicWordFactory->getDoubleUnderscoreArray()->getNames(); |
| 720 |
|
| 721 |
|
| 722 |
$localizedWords = $this->contentLanguage->getMagicWords(); |
| 723 |
|
| 724 |
$listItems = []; |
| 725 |
foreach ( $pageProperties as $property => $value ) { |
| 726 |
if ( in_array( $property, $wordIDs ) ) { |
| 727 |
$listItems[] = Html::element( 'li', [], $localizedWords[$property][1] ); |
| 728 |
} |
| 729 |
} |
| 730 |
|
| 731 |
$localizedList = Html::rawElement( 'ul', [], implode( '', $listItems ) ); |
| 732 |
$hiddenCategories = $this->getWikiPage()->getHiddenCategories(); |
| 733 |
|
| 734 |
if ( |
| 735 |
count( $listItems ) > 0 || |
| 736 |
count( $hiddenCategories ) > 0 || |
| 737 |
$pageCounts['transclusion']['from'] > 0 || |
| 738 |
$pageCounts['transclusion']['to'] > 0 |
| 739 |
) { |
| 740 |
$options = [ 'LIMIT' => $config->get( MainConfigNames::PageInfoTransclusionLimit ) ]; |
| 741 |
$transcludedTemplates = $title->getTemplateLinksFrom( $options ); |
| 742 |
if ( $config->get( MainConfigNames::MiserMode ) ) { |
| 743 |
$transcludedTargets = []; |
| 744 |
} else { |
| 745 |
$transcludedTargets = $title->getTemplateLinksTo( $options ); |
| 746 |
} |
| 747 |
|
| 748 |
|
| 749 |
$pageInfo['header-properties'] = []; |
| 750 |
|
| 751 |
|
| 752 |
if ( count( $listItems ) > 0 ) { |
| 753 |
$pageInfo['header-properties'][] = [ |
| 754 |
$this->msg( 'pageinfo-magic-words' )->numParams( count( $listItems ) ), |
| 755 |
$localizedList |
| 756 |
]; |
| 757 |
} |
| 758 |
|
| 759 |
|
| 760 |
if ( count( $hiddenCategories ) > 0 ) { |
| 761 |
$pageInfo['header-properties'][] = [ |
| 762 |
$this->msg( 'pageinfo-hidden-categories' ) |
| 763 |
->numParams( count( $hiddenCategories ) ), |
| 764 |
Linker::formatHiddenCategories( $hiddenCategories ) |
| 765 |
]; |
| 766 |
} |
| 767 |
|
| 768 |
|
| 769 |
if ( $pageCounts['transclusion']['from'] > 0 ) { |
| 770 |
if ( $pageCounts['transclusion']['from'] > count( $transcludedTemplates ) ) { |
| 771 |
$more = $this->msg( 'morenotlisted' )->escaped(); |
| 772 |
} else { |
| 773 |
$more = null; |
| 774 |
} |
| 775 |
|
| 776 |
$templateListFormatter = new TemplatesOnThisPageFormatter( |
| 777 |
$this->getContext(), |
| 778 |
$linkRenderer, |
| 779 |
$this->linkBatchFactory, |
| 780 |
$this->restrictionStore |
| 781 |
); |
| 782 |
|
| 783 |
$pageInfo['header-properties'][] = [ |
| 784 |
$this->msg( 'pageinfo-templates' ) |
| 785 |
->numParams( $pageCounts['transclusion']['from'] ), |
| 786 |
$templateListFormatter->format( $transcludedTemplates, false, $more ) |
| 787 |
]; |
| 788 |
} |
| 789 |
|
| 790 |
if ( !$config->get( MainConfigNames::MiserMode ) && $pageCounts['transclusion']['to'] > 0 ) { |
| 791 |
if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) { |
| 792 |
$more = $linkRenderer->makeLink( |
| 793 |
$whatLinksHere, |
| 794 |
$this->msg( 'moredotdotdot' )->text(), |
| 795 |
[], |
| 796 |
[ 'hidelinks' => 1, 'hideredirs' => 1 ] |
| 797 |
); |
| 798 |
} else { |
| 799 |
$more = null; |
| 800 |
} |
| 801 |
|
| 802 |
$templateListFormatter = new TemplatesOnThisPageFormatter( |
| 803 |
$this->getContext(), |
| 804 |
$linkRenderer, |
| 805 |
$this->linkBatchFactory, |
| 806 |
$this->restrictionStore |
| 807 |
); |
| 808 |
|
| 809 |
$pageInfo['header-properties'][] = [ |
| 810 |
$this->msg( 'pageinfo-transclusions' ) |
| 811 |
->numParams( $pageCounts['transclusion']['to'] ), |
| 812 |
$templateListFormatter->format( $transcludedTargets, false, $more ) |
| 813 |
]; |
| 814 |
} |
| 815 |
} |
| 816 |
|
| 817 |
return $pageInfo; |
| 818 |
} |
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
private function getNamespaceProtectionMessage( Title $title ): ?string { |
| 828 |
$rights = []; |
| 829 |
if ( $title->isRawHtmlMessage() ) { |
| 830 |
$rights[] = 'editsitecss'; |
| 831 |
$rights[] = 'editsitejs'; |
| 832 |
} elseif ( $title->isSiteCssConfigPage() ) { |
| 833 |
$rights[] = 'editsitecss'; |
| 834 |
} elseif ( $title->isSiteJsConfigPage() ) { |
| 835 |
$rights[] = 'editsitejs'; |
| 836 |
} elseif ( $title->isSiteJsonConfigPage() ) { |
| 837 |
$rights[] = 'editsitejson'; |
| 838 |
} elseif ( $title->isUserCssConfigPage() ) { |
| 839 |
$rights[] = 'editusercss'; |
| 840 |
} elseif ( $title->isUserJsConfigPage() ) { |
| 841 |
$rights[] = 'edituserjs'; |
| 842 |
} elseif ( $title->isUserJsonConfigPage() ) { |
| 843 |
$rights[] = 'edituserjson'; |
| 844 |
} else { |
| 845 |
$namespaceProtection = $this->context->getConfig()->get( MainConfigNames::NamespaceProtection ); |
| 846 |
$right = $namespaceProtection[$title->getNamespace()] ?? null; |
| 847 |
if ( $right ) { |
| 848 |
|
| 849 |
$rights = (array)$right; |
| 850 |
} |
| 851 |
} |
| 852 |
if ( $rights ) { |
| 853 |
return $this->msg( 'protect-fallback', $this->getLanguage()->commaList( $rights ) )->parse(); |
| 854 |
} else { |
| 855 |
return null; |
| 856 |
} |
| 857 |
} |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
private function pageCounts() { |
| 865 |
$page = $this->getWikiPage(); |
| 866 |
$fname = __METHOD__; |
| 867 |
$config = $this->context->getConfig(); |
| 868 |
$cache = $this->wanObjectCache; |
| 869 |
|
| 870 |
return $cache->getWithSetCallback( |
| 871 |
self::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ), |
| 872 |
WANObjectCache::TTL_WEEK, |
| 873 |
function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) { |
| 874 |
$title = $page->getTitle(); |
| 875 |
$id = $title->getArticleID(); |
| 876 |
|
| 877 |
$dbr = $this->dbProvider->getReplicaDatabase(); |
| 878 |
$setOpts += Database::getCacheSetOptions( $dbr ); |
| 879 |
|
| 880 |
$field = 'rev_actor'; |
| 881 |
$pageField = 'rev_page'; |
| 882 |
|
| 883 |
$watchedItemStore = $this->watchedItemStore; |
| 884 |
|
| 885 |
$result = []; |
| 886 |
$result['watchers'] = $watchedItemStore->countWatchers( $title ); |
| 887 |
|
| 888 |
if ( $config->get( MainConfigNames::ShowUpdatedMarker ) ) { |
| 889 |
$updated = (int)wfTimestamp( TS_UNIX, $page->getTimestamp() ); |
| 890 |
$result['visitingWatchers'] = $watchedItemStore->countVisitingWatchers( |
| 891 |
$title, |
| 892 |
$updated - $config->get( MainConfigNames::WatchersMaxAge ) |
| 893 |
); |
| 894 |
} |
| 895 |
|
| 896 |
|
| 897 |
$edits = (int)$dbr->newSelectQueryBuilder() |
| 898 |
->select( 'COUNT(*)' ) |
| 899 |
->from( 'revision' ) |
| 900 |
->where( [ 'rev_page' => $id ] ) |
| 901 |
->caller( $fname ) |
| 902 |
->fetchField(); |
| 903 |
$result['edits'] = $edits; |
| 904 |
|
| 905 |
|
| 906 |
if ( $config->get( MainConfigNames::MiserMode ) ) { |
| 907 |
$result['authors'] = 0; |
| 908 |
} else { |
| 909 |
$result['authors'] = (int)$dbr->newSelectQueryBuilder() |
| 910 |
->select( "COUNT(DISTINCT $field)" ) |
| 911 |
->from( 'revision' ) |
| 912 |
->where( [ |
| 913 |
$pageField => $id, |
| 914 |
$dbr->bitAnd( 'rev_deleted', RevisionRecord::DELETED_USER ) . ' = 0', |
| 915 |
] ) |
| 916 |
->caller( $fname ) |
| 917 |
->fetchField(); |
| 918 |
} |
| 919 |
|
| 920 |
|
| 921 |
$threshold = $dbr->timestamp( time() - $config->get( MainConfigNames::RCMaxAge ) ); |
| 922 |
|
| 923 |
|
| 924 |
$edits = (int)$dbr->newSelectQueryBuilder() |
| 925 |
->select( 'COUNT(rev_page)' ) |
| 926 |
->from( 'revision' ) |
| 927 |
->where( [ 'rev_page' => $id ] ) |
| 928 |
->andWhere( $dbr->expr( 'rev_timestamp', '>=', $threshold ) ) |
| 929 |
->caller( $fname ) |
| 930 |
->fetchField(); |
| 931 |
$result['recent_edits'] = $edits; |
| 932 |
|
| 933 |
|
| 934 |
$result['recent_authors'] = (int)$dbr->newSelectQueryBuilder() |
| 935 |
->select( "COUNT(DISTINCT $field)" ) |
| 936 |
->from( 'revision' ) |
| 937 |
->where( [ $pageField => $id ] ) |
| 938 |
->andWhere( [ |
| 939 |
$dbr->expr( 'rev_timestamp', '>=', $threshold ), |
| 940 |
$dbr->bitAnd( 'rev_deleted', RevisionRecord::DELETED_USER ) . ' = 0', |
| 941 |
] ) |
| 942 |
->caller( $fname ) |
| 943 |
->fetchField(); |
| 944 |
|
| 945 |
|
| 946 |
if ( $this->namespaceInfo->hasSubpages( $title->getNamespace() ) ) { |
| 947 |
$conds = [ 'page_namespace' => $title->getNamespace() ]; |
| 948 |
$conds[] = $dbr->expr( |
| 949 |
'page_title', |
| 950 |
IExpression::LIKE, |
| 951 |
new LikeValue( $title->getDBkey() . '/', $dbr->anyString() ) |
| 952 |
); |
| 953 |
|
| 954 |
|
| 955 |
$conds['page_is_redirect'] = 1; |
| 956 |
$result['subpages']['redirects'] = (int)$dbr->newSelectQueryBuilder() |
| 957 |
->select( 'COUNT(page_id)' ) |
| 958 |
->from( 'page' ) |
| 959 |
->where( $conds ) |
| 960 |
->caller( $fname ) |
| 961 |
->fetchField(); |
| 962 |
|
| 963 |
$conds['page_is_redirect'] = 0; |
| 964 |
$result['subpages']['nonredirects'] = (int)$dbr->newSelectQueryBuilder() |
| 965 |
->select( 'COUNT(page_id)' ) |
| 966 |
->from( 'page' ) |
| 967 |
->where( $conds ) |
| 968 |
->caller( $fname ) |
| 969 |
->fetchField(); |
| 970 |
|
| 971 |
|
| 972 |
$result['subpages']['total'] = $result['subpages']['redirects'] |
| 973 |
+ $result['subpages']['nonredirects']; |
| 974 |
} |
| 975 |
|
| 976 |
|
| 977 |
if ( $config->get( MainConfigNames::MiserMode ) ) { |
| 978 |
$result['transclusion']['to'] = 0; |
| 979 |
} else { |
| 980 |
$result['transclusion']['to'] = (int)$dbr->newSelectQueryBuilder() |
| 981 |
->select( 'COUNT(tl_from)' ) |
| 982 |
->from( 'templatelinks' ) |
| 983 |
->where( $this->linksMigration->getLinksConditions( 'templatelinks', $title ) ) |
| 984 |
->caller( $fname ) |
| 985 |
->fetchField(); |
| 986 |
} |
| 987 |
|
| 988 |
$result['transclusion']['from'] = (int)$dbr->newSelectQueryBuilder() |
| 989 |
->select( 'COUNT(*)' ) |
| 990 |
->from( 'templatelinks' ) |
| 991 |
->where( [ 'tl_from' => $title->getArticleID() ] ) |
| 992 |
->caller( $fname ) |
| 993 |
->fetchField(); |
| 994 |
|
| 995 |
return $result; |
| 996 |
} |
| 997 |
); |
| 998 |
} |
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
protected function getPageTitle() { |
| 1006 |
return $this->msg( 'pageinfo-title' )->plaintextParams( $this->getTitle()->getPrefixedText() ); |
| 1007 |
} |
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
protected function getDescription() { |
| 1015 |
return ''; |
| 1016 |
} |
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
protected static function getCacheKey( WANObjectCache $cache, PageIdentity $page, $revId ) { |
| 1025 |
return $cache->makeKey( 'infoaction', md5( (string)$page ), $revId, self::VERSION ); |
| 1026 |
} |
| 1027 |
} |