61 private const VERSION = 1;
100 parent::__construct( $article, $context );
101 $this->contentLanguage = $contentLanguage;
102 $this->languageNameUtils = $languageNameUtils;
103 $this->linkBatchFactory = $linkBatchFactory;
104 $this->linkRenderer = $linkRenderer;
105 $this->dbProvider = $dbProvider;
106 $this->magicWordFactory = $magicWordFactory;
107 $this->namespaceInfo = $namespaceInfo;
108 $this->pageProps = $pageProps;
109 $this->repoGroup = $repoGroup;
110 $this->revisionLookup = $revisionLookup;
111 $this->wanObjectCache = $wanObjectCache;
112 $this->watchedItemStore = $watchedItemStore;
113 $this->redirectLookup = $redirectLookup;
114 $this->restrictionStore = $restrictionStore;
115 $this->linksMigration = $linksMigration;
116 $this->userFactory = $userFactory;
142 $services = MediaWikiServices::getInstance();
143 if ( $revid ===
null ) {
144 $revision = $services->getRevisionLookup()
145 ->getRevisionByTitle( $page, 0, IDBAccessObject::READ_LATEST );
146 $revid = $revision ? $revision->getId() : 0;
148 $cache = $services->getMainWANObjectCache();
150 $cache->delete( $key );
160 'mediawiki.interface.helpers.styles',
161 'mediawiki.action.styles',
170 $revRecord = $this->
getArticle()->fetchRevisionRecord();
173 return $this->
msg(
'missing-revision', $oldid )->parse();
174 } elseif ( !$revRecord->isCurrent() ) {
175 return $this->
msg(
'pageinfo-not-current' )->plain();
180 $msg = $this->
msg(
'pageinfo-header' );
181 $content = $msg->isDisabled() ?
'' : $msg->parse();
184 $pageInfo = $this->pageInfo();
190 foreach ( $pageInfo as
$header => $infoTable ) {
194 $content .= $this->makeHeader(
195 $this->
msg(
"pageinfo-$header" )->text(),
196 "mw-pageinfo-$header"
200 foreach ( $infoTable as $infoRow ) {
201 if ( $infoRow[0] ==
"below" ) {
202 $below = $infoRow[1] .
"\n";
205 $name = ( $infoRow[0] instanceof
Message ) ? $infoRow[0]->escaped() : $infoRow[0];
206 $value = ( $infoRow[1] instanceof
Message ) ? $infoRow[1]->escaped() : $infoRow[1];
207 $id = ( $infoRow[0] instanceof
Message ) ? $infoRow[0]->getKey() :
null;
208 $rows .= $this->getRow( $name, $value, $id ) .
"\n";
210 if ( $rows !==
'' ) {
211 $content .= Html::rawElement(
'table', [
'class' =>
'wikitable mw-page-info' ],
214 $content .=
"\n" . $below;
218 if ( !$this->
msg(
'pageinfo-footer' )->isDisabled() ) {
219 $content .= $this->
msg(
'pageinfo-footer' )->parse();
232 private function makeHeader(
$header, $canonicalId ) {
233 return Html::rawElement(
235 [
'id' => Sanitizer::escapeIdForAttribute(
$header ) ],
238 [
'id' => Sanitizer::escapeIdForAttribute( $canonicalId ) ],
251 private function getRow( $name, $value, $id ) {
252 return Html::rawElement(
255 'id' => $id ===
null ?
null :
'mw-' . $id,
256 'style' =>
'vertical-align: top;',
258 Html::rawElement(
'td', [], $name ) .
259 Html::rawElement(
'td', [], $value )
276 private function pageInfo() {
281 $config = $this->context->getConfig();
282 $linkRenderer = $this->linkRenderer;
284 $pageCounts = $this->pageCounts();
286 $pageProperties = $this->pageProps->getAllProperties( $title )[$id] ?? [];
290 $pageInfo[
'header-basic'] = [];
293 $displayTitle = $pageProperties[
'displaytitle'] ??
296 $pageInfo[
'header-basic'][] = [
297 $this->
msg(
'pageinfo-display-title' ),
302 $redirectTarget = $this->redirectLookup->getRedirectTarget( $this->
getWikiPage() );
303 if ( $redirectTarget !==
null ) {
304 $pageInfo[
'header-basic'][] = [
305 $this->
msg(
'pageinfo-redirectsto' ),
306 $linkRenderer->
makeLink( $redirectTarget ) .
307 $this->
msg(
'word-separator' )->escaped() .
308 $this->
msg(
'parentheses' )->rawParams( $linkRenderer->
makeLink(
310 $this->msg(
'pageinfo-redirectsto-info' )->text(),
312 [
'action' =>
'info' ]
319 $pageInfo[
'header-basic'][] = [
320 $this->
msg(
'pageinfo-default-sort' ),
321 htmlspecialchars( $sortKey )
325 $pageInfo[
'header-basic'][] = [
326 $this->
msg(
'pageinfo-length' ),
331 $pageInfo[
'header-basic'][] = [ $this->
msg(
'pageinfo-namespace-id' ), $title->
getNamespace() ];
333 if ( $pageNamespace ) {
334 $pageInfo[
'header-basic'][] = [ $this->
msg(
'pageinfo-namespace' ), $pageNamespace ];
338 $pageInfo[
'header-basic'][] = [ $this->
msg(
'pageinfo-article-id' ), $id ];
343 $pageLangHtml = $pageLang .
' - ' .
344 $this->languageNameUtils->getLanguageName( $pageLang, $lang->getCode() );
346 if ( $config->get( MainConfigNames::PageLanguageUseDB )
347 && $this->getAuthority()->probablyCan(
'pagelang', $title )
349 $pageLangHtml .= $this->
msg(
'word-separator' )->escaped();
350 $pageLangHtml .= $this->
msg(
'parentheses' )->rawParams( $linkRenderer->
makeLink(
351 SpecialPage::getTitleValueFor(
'PageLanguage', $title->
getPrefixedText() ),
352 $this->msg(
'pageinfo-language-change' )->text()
356 $pageInfo[
'header-basic'][] = [
357 $this->
msg(
'pageinfo-language' )->escaped(),
362 $modelHtml = htmlspecialchars( ContentHandler::getLocalizedName( $title->
getContentModel() ) );
364 if ( $this->
getAuthority()->probablyCan(
'editcontentmodel', $title ) ) {
365 $modelHtml .= $this->
msg(
'word-separator' )->escaped();
366 $modelHtml .= $this->
msg(
'parentheses' )->rawParams( $linkRenderer->
makeLink(
367 SpecialPage::getTitleValueFor(
'ChangeContentModel', $title->
getPrefixedText() ),
368 $this->msg(
'pageinfo-content-model-change' )->text()
372 $pageInfo[
'header-basic'][] = [
373 $this->
msg(
'pageinfo-content-model' ),
378 $pageUser = $this->userFactory->newFromName( $title->
getRootText() );
379 if ( $pageUser && $pageUser->getId() && !$pageUser->isHidden() ) {
380 $pageInfo[
'header-basic'][] = [
381 $this->
msg(
'pageinfo-user-id' ),
389 if ( isset( $pageProperties[
'noindex'] ) ) {
390 $parserOutput->setIndexPolicy(
'noindex' );
392 if ( isset( $pageProperties[
'index'] ) ) {
393 $parserOutput->setIndexPolicy(
'index' );
397 $policy = $this->
getArticle()->getRobotPolicy(
'view', $parserOutput );
398 $pageInfo[
'header-basic'][] = [
400 $this->
msg(
'pageinfo-robot-policy' ),
401 $this->
msg(
"pageinfo-robot-{$policy['index']}" )
404 $unwatchedPageThreshold = $config->get( MainConfigNames::UnwatchedPageThreshold );
405 if ( $this->
getAuthority()->isAllowed(
'unwatchedpages' ) ||
406 ( $unwatchedPageThreshold !==
false &&
407 $pageCounts[
'watchers'] >= $unwatchedPageThreshold )
410 $pageInfo[
'header-basic'][] = [
411 $this->
msg(
'pageinfo-watchers' ),
412 $lang->formatNum( $pageCounts[
'watchers'] )
415 $visiting = $pageCounts[
'visitingWatchers'] ??
null;
416 if ( $visiting !==
null && $config->get( MainConfigNames::ShowUpdatedMarker ) ) {
417 if ( $visiting > $config->get( MainConfigNames::UnwatchedPageSecret ) ||
418 $this->getAuthority()->isAllowed(
'unwatchedpages' )
420 $value = $lang->formatNum( $visiting );
422 $value = $this->
msg(
'pageinfo-few-visiting-watchers' );
424 $pageInfo[
'header-basic'][] = [
425 $this->
msg(
'pageinfo-visiting-watchers' ),
429 } elseif ( $unwatchedPageThreshold !==
false ) {
430 $pageInfo[
'header-basic'][] = [
431 $this->
msg(
'pageinfo-watchers' ),
432 $this->
msg(
'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
437 $whatLinksHere = SpecialPage::getTitleFor(
'Whatlinkshere', $title->
getPrefixedText() );
438 $pageInfo[
'header-basic'][] = [
441 $this->
msg(
'pageinfo-redirects-name' )->text(),
449 $this->
msg(
'pageinfo-redirects-value' )
455 $pageInfo[
'header-basic'][] = [
456 $this->
msg(
'pageinfo-contentpage' ),
457 $this->
msg(
'pageinfo-contentpage-yes' )
462 if ( $this->namespaceInfo->hasSubpages( $title->
getNamespace() ) ) {
463 $prefixIndex = SpecialPage::getTitleFor(
467 $pageInfo[
'header-basic'][] = [
470 $this->
msg(
'pageinfo-subpages-name' )->text()
473 isset( $pageCounts[
'subpages'] )
474 ? $this->
msg(
'pageinfo-subpages-value' )->numParams(
475 $pageCounts[
'subpages'][
'total'],
476 $pageCounts[
'subpages'][
'redirects'],
477 $pageCounts[
'subpages'][
'nonredirects']
478 ) : $this->
msg(
'pageinfo-subpages-value-unknown' )->rawParams(
480 $title, $this->msg(
'purge' )->text(), [], [
'action' =>
'purge' ] )
486 $category = Category::newFromTitle( $title );
488 $allCount = $category->getMemberCount();
489 $subcatCount = $category->getSubcatCount();
490 $fileCount = $category->getFileCount();
491 $pageCount = $category->getPageCount( Category::COUNT_CONTENT_PAGES );
493 $pageInfo[
'category-info'] = [
495 $this->
msg(
'pageinfo-category-total' ),
496 $lang->formatNum( $allCount )
499 $this->
msg(
'pageinfo-category-pages' ),
500 $lang->formatNum( $pageCount )
503 $this->
msg(
'pageinfo-category-subcats' ),
504 $lang->formatNum( $subcatCount )
507 $this->
msg(
'pageinfo-category-files' ),
508 $lang->formatNum( $fileCount )
515 $fileObj = $this->repoGroup->findFile( $title );
516 if ( $fileObj !==
false ) {
518 $output = Wikimedia\base_convert( $fileObj->getSha1(), 36, 16, 40 );
519 $pageInfo[
'header-basic'][] = [
520 $this->
msg(
'pageinfo-file-hash' ),
527 $pageInfo[
'header-restrictions'] = [];
530 if ( $this->restrictionStore->isCascadeProtected( $title ) ) {
532 $sources = $this->restrictionStore->getCascadeProtectionSources( $title )[0];
534 foreach ( $sources as $sourcePageIdentity ) {
535 $cascadingFrom .= Html::rawElement(
542 $cascadingFrom = Html::rawElement(
'ul', [], $cascadingFrom );
543 $pageInfo[
'header-restrictions'][] = [
544 $this->
msg(
'pageinfo-protect-cascading-from' ),
550 if ( $this->restrictionStore->areRestrictionsCascading( $title ) ) {
551 $pageInfo[
'header-restrictions'][] = [
552 $this->
msg(
'pageinfo-protect-cascading' ),
553 $this->
msg(
'pageinfo-protect-cascading-yes' )
558 foreach ( $this->restrictionStore->listApplicableRestrictionTypes( $title ) as $restrictionType ) {
559 $protections = $this->restrictionStore->getRestrictions( $title, $restrictionType );
561 switch ( count( $protections ) ) {
563 $message = $this->getNamespaceProtectionMessage( $title ) ??
565 $this->
msg(
'protect-default' )->escaped();
570 $message = $this->
msg(
'protect-level-' . $protections[0] );
571 if ( !$message->isDisabled() ) {
572 $message = $message->escaped();
579 $message = $this->
msg(
"protect-fallback", $lang->commaList( $protections ) )->parse();
582 $expiry = $this->restrictionStore->getRestrictionExpiry( $title, $restrictionType );
583 $formattedexpiry = $expiry ===
null ?
'' : $this->
msg(
585 $lang->formatExpiry( $expiry,
true,
'infinity', $user )
587 $message .= $this->
msg(
'word-separator' )->escaped() . $formattedexpiry;
591 $pageInfo[
'header-restrictions'][] = [
592 $this->
msg(
"restriction-$restrictionType" ), $message
595 $protectLog = SpecialPage::getTitleFor(
'Log' );
596 $pageInfo[
'header-restrictions'][] = [
600 $this->
msg(
'pageinfo-view-protect-log' )->text(),
611 $pageInfo[
'header-edits'] = [];
613 $firstRev = $this->revisionLookup->getFirstRevision( $this->
getTitle() );
614 $lastRev = $this->
getWikiPage()->getRevisionRecord();
615 $batch = $this->linkBatchFactory->newLinkBatch();
617 $firstRevUser = $firstRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
618 if ( $firstRevUser ) {
619 $batch->add(
NS_USER, $firstRevUser->getName() );
625 $lastRevUser = $lastRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
626 if ( $lastRevUser ) {
627 $batch->add(
NS_USER, $lastRevUser->getName() );
636 $firstRevUser = $firstRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
640 $firstRevUserName = $firstRevUser ? $firstRevUser->getName() :
'[HIDDEN]';
641 $pageInfo[
'header-edits'][] = [
642 $this->
msg(
'pageinfo-firstuser', $firstRevUserName ),
643 Linker::revUserTools( $firstRev )
647 $pageInfo[
'header-edits'][] = [
648 $this->
msg(
'pageinfo-firsttime' ),
651 $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ),
653 [
'oldid' => $firstRev->getId() ]
660 $lastRevUser = $lastRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
664 $lastRevUserName = $lastRevUser ? $lastRevUser->getName() :
'[HIDDEN]';
665 $pageInfo[
'header-edits'][] = [
666 $this->
msg(
'pageinfo-lastuser', $lastRevUserName ),
667 Linker::revUserTools( $lastRev )
671 $pageInfo[
'header-edits'][] = [
672 $this->
msg(
'pageinfo-lasttime' ),
675 $lang->userTimeAndDate( $this->getWikiPage()->getTimestamp(), $user ),
677 [
'oldid' => $this->getWikiPage()->getLatest() ]
683 $pageInfo[
'header-edits'][] = [
684 $this->
msg(
'pageinfo-edits' ),
685 $lang->formatNum( $pageCounts[
'edits'] )
689 if ( $pageCounts[
'authors'] > 0 ) {
690 $pageInfo[
'header-edits'][] = [
691 $this->
msg(
'pageinfo-authors' ),
692 $lang->formatNum( $pageCounts[
'authors'] )
697 $pageInfo[
'header-edits'][] = [
699 'pageinfo-recent-edits',
700 $lang->formatDuration( $config->get( MainConfigNames::RCMaxAge ) )
702 $lang->formatNum( $pageCounts[
'recent_edits'] )
706 $pageInfo[
'header-edits'][] = [
707 $this->
msg(
'pageinfo-recent-authors' ),
708 $lang->formatNum( $pageCounts[
'recent_authors'] )
712 $wordIDs = $this->magicWordFactory->getDoubleUnderscoreArray()->getNames();
715 $localizedWords = $this->contentLanguage->getMagicWords();
718 foreach ( $pageProperties as $property => $value ) {
719 if ( in_array( $property, $wordIDs ) ) {
720 $listItems[] = Html::element(
'li', [], $localizedWords[$property][1] );
724 $localizedList = Html::rawElement(
'ul', [], implode(
'', $listItems ) );
725 $hiddenCategories = $this->
getWikiPage()->getHiddenCategories();
728 count( $listItems ) > 0 ||
729 count( $hiddenCategories ) > 0 ||
730 $pageCounts[
'transclusion'][
'from'] > 0 ||
731 $pageCounts[
'transclusion'][
'to'] > 0
733 $options = [
'LIMIT' => $config->get( MainConfigNames::PageInfoTransclusionLimit ) ];
735 if ( $config->get( MainConfigNames::MiserMode ) ) {
736 $transcludedTargets = [];
742 $pageInfo[
'header-properties'] = [];
745 if ( count( $listItems ) > 0 ) {
746 $pageInfo[
'header-properties'][] = [
747 $this->
msg(
'pageinfo-magic-words' )->numParams( count( $listItems ) ),
753 if ( count( $hiddenCategories ) > 0 ) {
754 $pageInfo[
'header-properties'][] = [
755 $this->
msg(
'pageinfo-hidden-categories' )
756 ->numParams( count( $hiddenCategories ) ),
757 Linker::formatHiddenCategories( $hiddenCategories )
762 if ( $pageCounts[
'transclusion'][
'from'] > 0 ) {
763 if ( $pageCounts[
'transclusion'][
'from'] > count( $transcludedTemplates ) ) {
764 $more = $this->
msg(
'morenotlisted' )->escaped();
772 $this->linkBatchFactory,
773 $this->restrictionStore
776 $pageInfo[
'header-properties'][] = [
777 $this->
msg(
'pageinfo-templates' )
778 ->numParams( $pageCounts[
'transclusion'][
'from'] ),
779 $templateListFormatter->format( $transcludedTemplates,
false, $more )
783 if ( !$config->get( MainConfigNames::MiserMode ) && $pageCounts[
'transclusion'][
'to'] > 0 ) {
784 if ( $pageCounts[
'transclusion'][
'to'] > count( $transcludedTargets ) ) {
787 $this->
msg(
'moredotdotdot' )->text(),
789 [
'hidelinks' => 1,
'hideredirs' => 1 ]
798 $this->linkBatchFactory,
799 $this->restrictionStore
802 $pageInfo[
'header-properties'][] = [
803 $this->
msg(
'pageinfo-transclusions' )
804 ->numParams( $pageCounts[
'transclusion'][
'to'] ),
805 $templateListFormatter->format( $transcludedTargets,
false, $more )
820 private function getNamespaceProtectionMessage(
Title $title ): ?string {
823 $rights[] =
'editsitecss';
824 $rights[] =
'editsitejs';
826 $rights[] =
'editsitecss';
828 $rights[] =
'editsitejs';
830 $rights[] =
'editsitejson';
832 $rights[] =
'editusercss';
834 $rights[] =
'edituserjs';
836 $rights[] =
'edituserjson';
838 $namespaceProtection = $this->context->getConfig()->get( MainConfigNames::NamespaceProtection );
839 $right = $namespaceProtection[$title->
getNamespace()] ??
null;
842 $rights = (array)$right;
846 return $this->
msg(
'protect-fallback', $this->
getLanguage()->commaList( $rights ) )->parse();
857 private function pageCounts() {
858 $page = $this->getWikiPage();
860 $config = $this->context->getConfig();
861 $cache = $this->wanObjectCache;
863 return $cache->getWithSetCallback(
864 self::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ),
865 WANObjectCache::TTL_WEEK,
866 function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
867 $title = $page->getTitle();
870 $dbr = $this->dbProvider->getReplicaDatabase();
873 $field =
'rev_actor';
874 $pageField =
'rev_page';
876 $watchedItemStore = $this->watchedItemStore;
879 $result[
'watchers'] = $watchedItemStore->
countWatchers( $title );
881 if ( $config->get( MainConfigNames::ShowUpdatedMarker ) ) {
882 $updated = (int)
wfTimestamp( TS_UNIX, $page->getTimestamp() );
885 $updated - $config->get( MainConfigNames::WatchersMaxAge )
890 $edits = (int)$dbr->newSelectQueryBuilder()
891 ->select(
'COUNT(*)' )
893 ->where( [
'rev_page' => $id ] )
896 $result[
'edits'] = $edits;
899 if ( $config->get( MainConfigNames::MiserMode ) ) {
900 $result[
'authors'] = 0;
902 $result[
'authors'] = (int)$dbr->newSelectQueryBuilder()
903 ->select(
"COUNT(DISTINCT $field)" )
905 ->where( [ $pageField => $id ] )
911 $threshold = $dbr->timestamp( time() - $config->get( MainConfigNames::RCMaxAge ) );
914 $edits = (int)$dbr->newSelectQueryBuilder()
915 ->select(
'COUNT(rev_page)' )
917 ->where( [
'rev_page' => $id ] )
918 ->andWhere( $dbr->expr(
'rev_timestamp',
'>=', $threshold ) )
921 $result[
'recent_edits'] = $edits;
924 $result[
'recent_authors'] = (int)$dbr->newSelectQueryBuilder()
925 ->select(
"COUNT(DISTINCT $field)" )
927 ->where( [ $pageField => $id ] )
928 ->andWhere( [ $dbr->expr(
'rev_timestamp',
'>=', $threshold ) ] )
933 if ( $this->namespaceInfo->hasSubpages( $title->
getNamespace() ) ) {
934 $conds = [
'page_namespace' => $title->
getNamespace() ];
935 $conds[] = $dbr->expr(
942 $conds[
'page_is_redirect'] = 1;
943 $result[
'subpages'][
'redirects'] = (int)$dbr->newSelectQueryBuilder()
944 ->select(
'COUNT(page_id)' )
950 $conds[
'page_is_redirect'] = 0;
951 $result[
'subpages'][
'nonredirects'] = (int)$dbr->newSelectQueryBuilder()
952 ->select(
'COUNT(page_id)' )
959 $result[
'subpages'][
'total'] = $result[
'subpages'][
'redirects']
960 + $result[
'subpages'][
'nonredirects'];
964 if ( $config->get( MainConfigNames::MiserMode ) ) {
965 $result[
'transclusion'][
'to'] = 0;
967 $result[
'transclusion'][
'to'] = (int)$dbr->newSelectQueryBuilder()
968 ->select(
'COUNT(tl_from)' )
969 ->from(
'templatelinks' )
970 ->where( $this->linksMigration->getLinksConditions(
'templatelinks', $title ) )
975 $result[
'transclusion'][
'from'] = (int)$dbr->newSelectQueryBuilder()
976 ->select(
'COUNT(*)' )
977 ->from(
'templatelinks' )
993 return $this->msg(
'pageinfo-title' )->plaintextParams( $this->
getTitle()->getPrefixedText() );
1012 return $cache->
makeKey(
'infoaction', md5( (
string)$page ), $revId, self::VERSION );