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' )
426 ->numParams( ceil( $config->get( MainConfigNames::WatchersMaxAge ) / 86400 ) ),
430 } elseif ( $unwatchedPageThreshold !==
false ) {
431 $pageInfo[
'header-basic'][] = [
432 $this->
msg(
'pageinfo-watchers' ),
433 $this->
msg(
'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
438 $whatLinksHere = SpecialPage::getTitleFor(
'Whatlinkshere', $title->
getPrefixedText() );
439 $pageInfo[
'header-basic'][] = [
442 $this->
msg(
'pageinfo-redirects-name' )->text(),
450 $this->
msg(
'pageinfo-redirects-value' )
456 $pageInfo[
'header-basic'][] = [
457 $this->
msg(
'pageinfo-contentpage' ),
458 $this->
msg(
'pageinfo-contentpage-yes' )
463 if ( $this->namespaceInfo->hasSubpages( $title->
getNamespace() ) ) {
464 $prefixIndex = SpecialPage::getTitleFor(
468 $pageInfo[
'header-basic'][] = [
471 $this->
msg(
'pageinfo-subpages-name' )->text()
474 isset( $pageCounts[
'subpages'] )
475 ? $this->
msg(
'pageinfo-subpages-value' )->numParams(
476 $pageCounts[
'subpages'][
'total'],
477 $pageCounts[
'subpages'][
'redirects'],
478 $pageCounts[
'subpages'][
'nonredirects']
479 ) : $this->
msg(
'pageinfo-subpages-value-unknown' )->rawParams(
481 $title, $this->msg(
'purge' )->text(), [], [
'action' =>
'purge' ] )
487 $category = Category::newFromTitle( $title );
489 $allCount = $category->getMemberCount();
490 $subcatCount = $category->getSubcatCount();
491 $fileCount = $category->getFileCount();
492 $pageCount = $category->getPageCount( Category::COUNT_CONTENT_PAGES );
494 $pageInfo[
'category-info'] = [
496 $this->
msg(
'pageinfo-category-total' ),
497 $lang->formatNum( $allCount )
500 $this->
msg(
'pageinfo-category-pages' ),
501 $lang->formatNum( $pageCount )
504 $this->
msg(
'pageinfo-category-subcats' ),
505 $lang->formatNum( $subcatCount )
508 $this->
msg(
'pageinfo-category-files' ),
509 $lang->formatNum( $fileCount )
516 $fileObj = $this->repoGroup->findFile( $title );
517 if ( $fileObj !==
false ) {
519 $output = Wikimedia\base_convert( $fileObj->getSha1(), 36, 16, 40 );
520 $pageInfo[
'header-basic'][] = [
521 $this->
msg(
'pageinfo-file-hash' ),
528 $pageInfo[
'header-restrictions'] = [];
531 if ( $this->restrictionStore->isCascadeProtected( $title ) ) {
533 $sources = $this->restrictionStore->getCascadeProtectionSources( $title )[0];
535 foreach ( $sources as $sourcePageIdentity ) {
536 $cascadingFrom .= Html::rawElement(
543 $cascadingFrom = Html::rawElement(
'ul', [], $cascadingFrom );
544 $pageInfo[
'header-restrictions'][] = [
545 $this->
msg(
'pageinfo-protect-cascading-from' ),
551 if ( $this->restrictionStore->areRestrictionsCascading( $title ) ) {
552 $pageInfo[
'header-restrictions'][] = [
553 $this->
msg(
'pageinfo-protect-cascading' ),
554 $this->
msg(
'pageinfo-protect-cascading-yes' )
559 foreach ( $this->restrictionStore->listApplicableRestrictionTypes( $title ) as $restrictionType ) {
560 $protections = $this->restrictionStore->getRestrictions( $title, $restrictionType );
562 switch ( count( $protections ) ) {
564 $message = $this->getNamespaceProtectionMessage( $title ) ??
566 $this->
msg(
'protect-default' )->escaped();
571 $message = $this->
msg(
'protect-level-' . $protections[0] );
572 if ( !$message->isDisabled() ) {
573 $message = $message->escaped();
580 $message = $this->
msg(
"protect-fallback", $lang->commaList( $protections ) )->parse();
583 $expiry = $this->restrictionStore->getRestrictionExpiry( $title, $restrictionType );
584 $formattedexpiry = $expiry ===
null ?
'' : $this->
msg(
586 $lang->formatExpiry( $expiry,
true,
'infinity', $user )
588 $message .= $this->
msg(
'word-separator' )->escaped() . $formattedexpiry;
592 $pageInfo[
'header-restrictions'][] = [
593 $this->
msg(
"restriction-$restrictionType" ), $message
596 $protectLog = SpecialPage::getTitleFor(
'Log' );
597 $pageInfo[
'header-restrictions'][] = [
601 $this->
msg(
'pageinfo-view-protect-log' )->text(),
612 $pageInfo[
'header-edits'] = [];
614 $firstRev = $this->revisionLookup->getFirstRevision( $this->
getTitle() );
615 $lastRev = $this->
getWikiPage()->getRevisionRecord();
616 $batch = $this->linkBatchFactory->newLinkBatch();
618 $firstRevUser = $firstRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
619 if ( $firstRevUser ) {
620 $batch->add(
NS_USER, $firstRevUser->getName() );
626 $lastRevUser = $lastRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
627 if ( $lastRevUser ) {
628 $batch->add(
NS_USER, $lastRevUser->getName() );
637 $firstRevUser = $firstRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
641 $firstRevUserName = $firstRevUser ? $firstRevUser->getName() :
'[HIDDEN]';
642 $pageInfo[
'header-edits'][] = [
643 $this->
msg(
'pageinfo-firstuser', $firstRevUserName ),
644 Linker::revUserTools( $firstRev )
648 $pageInfo[
'header-edits'][] = [
649 $this->
msg(
'pageinfo-firsttime' ),
652 $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ),
654 [
'oldid' => $firstRev->getId() ]
661 $lastRevUser = $lastRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
665 $lastRevUserName = $lastRevUser ? $lastRevUser->getName() :
'[HIDDEN]';
666 $pageInfo[
'header-edits'][] = [
667 $this->
msg(
'pageinfo-lastuser', $lastRevUserName ),
668 Linker::revUserTools( $lastRev )
672 $pageInfo[
'header-edits'][] = [
673 $this->
msg(
'pageinfo-lasttime' ),
676 $lang->userTimeAndDate( $this->getWikiPage()->getTimestamp(), $user ),
678 [
'oldid' => $this->getWikiPage()->getLatest() ]
684 $pageInfo[
'header-edits'][] = [
685 $this->
msg(
'pageinfo-edits' ),
686 $lang->formatNum( $pageCounts[
'edits'] )
690 if ( $pageCounts[
'authors'] > 0 ) {
691 $pageInfo[
'header-edits'][] = [
692 $this->
msg(
'pageinfo-authors' ),
693 $lang->formatNum( $pageCounts[
'authors'] )
698 $pageInfo[
'header-edits'][] = [
700 'pageinfo-recent-edits',
701 $lang->formatDuration( $config->get( MainConfigNames::RCMaxAge ) )
703 $lang->formatNum( $pageCounts[
'recent_edits'] )
707 $pageInfo[
'header-edits'][] = [
708 $this->
msg(
'pageinfo-recent-authors' ),
709 $lang->formatNum( $pageCounts[
'recent_authors'] )
713 $wordIDs = $this->magicWordFactory->getDoubleUnderscoreArray()->getNames();
716 $localizedWords = $this->contentLanguage->getMagicWords();
719 foreach ( $pageProperties as $property => $value ) {
720 if ( in_array( $property, $wordIDs ) ) {
721 $listItems[] = Html::element(
'li', [], $localizedWords[$property][1] );
725 $localizedList = Html::rawElement(
'ul', [], implode(
'', $listItems ) );
726 $hiddenCategories = $this->
getWikiPage()->getHiddenCategories();
729 count( $listItems ) > 0 ||
730 count( $hiddenCategories ) > 0 ||
731 $pageCounts[
'transclusion'][
'from'] > 0 ||
732 $pageCounts[
'transclusion'][
'to'] > 0
734 $options = [
'LIMIT' => $config->get( MainConfigNames::PageInfoTransclusionLimit ) ];
736 if ( $config->get( MainConfigNames::MiserMode ) ) {
737 $transcludedTargets = [];
743 $pageInfo[
'header-properties'] = [];
746 if ( count( $listItems ) > 0 ) {
747 $pageInfo[
'header-properties'][] = [
748 $this->
msg(
'pageinfo-magic-words' )->numParams( count( $listItems ) ),
754 if ( count( $hiddenCategories ) > 0 ) {
755 $pageInfo[
'header-properties'][] = [
756 $this->
msg(
'pageinfo-hidden-categories' )
757 ->numParams( count( $hiddenCategories ) ),
758 Linker::formatHiddenCategories( $hiddenCategories )
763 if ( $pageCounts[
'transclusion'][
'from'] > 0 ) {
764 if ( $pageCounts[
'transclusion'][
'from'] > count( $transcludedTemplates ) ) {
765 $more = $this->
msg(
'morenotlisted' )->escaped();
773 $this->linkBatchFactory,
774 $this->restrictionStore
777 $pageInfo[
'header-properties'][] = [
778 $this->
msg(
'pageinfo-templates' )
779 ->numParams( $pageCounts[
'transclusion'][
'from'] ),
780 $templateListFormatter->format( $transcludedTemplates,
false, $more )
784 if ( !$config->get( MainConfigNames::MiserMode ) && $pageCounts[
'transclusion'][
'to'] > 0 ) {
785 if ( $pageCounts[
'transclusion'][
'to'] > count( $transcludedTargets ) ) {
788 $this->
msg(
'moredotdotdot' )->text(),
790 [
'hidelinks' => 1,
'hideredirs' => 1 ]
799 $this->linkBatchFactory,
800 $this->restrictionStore
803 $pageInfo[
'header-properties'][] = [
804 $this->
msg(
'pageinfo-transclusions' )
805 ->numParams( $pageCounts[
'transclusion'][
'to'] ),
806 $templateListFormatter->format( $transcludedTargets,
false, $more )
821 private function getNamespaceProtectionMessage(
Title $title ): ?string {
824 $rights[] =
'editsitecss';
825 $rights[] =
'editsitejs';
827 $rights[] =
'editsitecss';
829 $rights[] =
'editsitejs';
831 $rights[] =
'editsitejson';
833 $rights[] =
'editusercss';
835 $rights[] =
'edituserjs';
837 $rights[] =
'edituserjson';
839 $namespaceProtection = $this->context->getConfig()->get( MainConfigNames::NamespaceProtection );
840 $right = $namespaceProtection[$title->
getNamespace()] ??
null;
843 $rights = (array)$right;
847 return $this->
msg(
'protect-fallback', $this->
getLanguage()->commaList( $rights ) )->parse();
858 private function pageCounts() {
859 $page = $this->getWikiPage();
861 $config = $this->context->getConfig();
862 $cache = $this->wanObjectCache;
864 return $cache->getWithSetCallback(
865 self::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ),
866 WANObjectCache::TTL_WEEK,
867 function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
868 $title = $page->getTitle();
871 $dbr = $this->dbProvider->getReplicaDatabase();
874 $field =
'rev_actor';
875 $pageField =
'rev_page';
877 $watchedItemStore = $this->watchedItemStore;
880 $result[
'watchers'] = $watchedItemStore->
countWatchers( $title );
882 if ( $config->get( MainConfigNames::ShowUpdatedMarker ) ) {
883 $updated = (int)
wfTimestamp( TS_UNIX, $page->getTimestamp() );
886 $updated - $config->get( MainConfigNames::WatchersMaxAge )
891 $edits = (int)$dbr->newSelectQueryBuilder()
892 ->select(
'COUNT(*)' )
894 ->where( [
'rev_page' => $id ] )
897 $result[
'edits'] = $edits;
900 if ( $config->get( MainConfigNames::MiserMode ) ) {
901 $result[
'authors'] = 0;
903 $result[
'authors'] = (int)$dbr->newSelectQueryBuilder()
904 ->select(
"COUNT(DISTINCT $field)" )
906 ->where( [ $pageField => $id ] )
912 $threshold = $dbr->timestamp( time() - $config->get( MainConfigNames::RCMaxAge ) );
915 $edits = (int)$dbr->newSelectQueryBuilder()
916 ->select(
'COUNT(rev_page)' )
918 ->where( [
'rev_page' => $id ] )
919 ->andWhere( $dbr->expr(
'rev_timestamp',
'>=', $threshold ) )
922 $result[
'recent_edits'] = $edits;
925 $result[
'recent_authors'] = (int)$dbr->newSelectQueryBuilder()
926 ->select(
"COUNT(DISTINCT $field)" )
928 ->where( [ $pageField => $id ] )
929 ->andWhere( [ $dbr->expr(
'rev_timestamp',
'>=', $threshold ) ] )
934 if ( $this->namespaceInfo->hasSubpages( $title->
getNamespace() ) ) {
935 $conds = [
'page_namespace' => $title->
getNamespace() ];
936 $conds[] = $dbr->expr(
943 $conds[
'page_is_redirect'] = 1;
944 $result[
'subpages'][
'redirects'] = (int)$dbr->newSelectQueryBuilder()
945 ->select(
'COUNT(page_id)' )
951 $conds[
'page_is_redirect'] = 0;
952 $result[
'subpages'][
'nonredirects'] = (int)$dbr->newSelectQueryBuilder()
953 ->select(
'COUNT(page_id)' )
960 $result[
'subpages'][
'total'] = $result[
'subpages'][
'redirects']
961 + $result[
'subpages'][
'nonredirects'];
965 if ( $config->get( MainConfigNames::MiserMode ) ) {
966 $result[
'transclusion'][
'to'] = 0;
968 $result[
'transclusion'][
'to'] = (int)$dbr->newSelectQueryBuilder()
969 ->select(
'COUNT(tl_from)' )
970 ->from(
'templatelinks' )
971 ->where( $this->linksMigration->getLinksConditions(
'templatelinks', $title ) )
976 $result[
'transclusion'][
'from'] = (int)$dbr->newSelectQueryBuilder()
977 ->select(
'COUNT(*)' )
978 ->from(
'templatelinks' )
994 return $this->msg(
'pageinfo-title' )->plaintextParams( $this->
getTitle()->getPrefixedText() );
1013 return $cache->
makeKey(
'infoaction', md5( (
string)$page ), $revId, self::VERSION );