62 private const VERSION = 1;
101 parent::__construct( $article, $context );
102 $this->contentLanguage = $contentLanguage;
103 $this->languageNameUtils = $languageNameUtils;
104 $this->linkBatchFactory = $linkBatchFactory;
105 $this->linkRenderer = $linkRenderer;
106 $this->dbProvider = $dbProvider;
107 $this->magicWordFactory = $magicWordFactory;
108 $this->namespaceInfo = $namespaceInfo;
109 $this->pageProps = $pageProps;
110 $this->repoGroup = $repoGroup;
111 $this->revisionLookup = $revisionLookup;
112 $this->wanObjectCache = $wanObjectCache;
113 $this->watchedItemStore = $watchedItemStore;
114 $this->redirectLookup = $redirectLookup;
115 $this->restrictionStore = $restrictionStore;
116 $this->linksMigration = $linksMigration;
117 $this->userFactory = $userFactory;
143 $services = MediaWikiServices::getInstance();
144 if ( $revid ===
null ) {
145 $revision = $services->getRevisionLookup()
146 ->getRevisionByTitle( $page, 0, IDBAccessObject::READ_LATEST );
147 $revid = $revision ? $revision->getId() : 0;
149 $cache = $services->getMainWANObjectCache();
151 $cache->delete( $key );
161 'mediawiki.interface.helpers.styles',
162 'mediawiki.action.styles',
171 $revRecord = $this->
getArticle()->fetchRevisionRecord();
174 return $this->
msg(
'missing-revision', $oldid )->parse();
175 } elseif ( !$revRecord->isCurrent() ) {
176 return $this->
msg(
'pageinfo-not-current' )->plain();
181 $msg = $this->
msg(
'pageinfo-header' );
182 $content = $msg->isDisabled() ?
'' : $msg->parse();
185 $pageInfo = $this->pageInfo();
191 foreach ( $pageInfo as
$header => $infoTable ) {
195 $content .= $this->makeHeader(
196 $this->
msg(
"pageinfo-$header" )->text(),
197 "mw-pageinfo-$header"
201 foreach ( $infoTable as $infoRow ) {
202 if ( $infoRow[0] ==
"below" ) {
203 $below = $infoRow[1] .
"\n";
206 $name = ( $infoRow[0] instanceof
Message ) ? $infoRow[0]->escaped() : $infoRow[0];
207 $value = ( $infoRow[1] instanceof
Message ) ? $infoRow[1]->escaped() : $infoRow[1];
208 $id = ( $infoRow[0] instanceof
Message ) ? $infoRow[0]->getKey() :
null;
209 $rows .= $this->getRow( $name, $value, $id ) .
"\n";
211 if ( $rows !==
'' ) {
212 $content .= Html::rawElement(
'table', [
'class' =>
'wikitable mw-page-info' ],
215 $content .=
"\n" . $below;
219 if ( !$this->
msg(
'pageinfo-footer' )->isDisabled() ) {
220 $content .= $this->
msg(
'pageinfo-footer' )->parse();
233 private function makeHeader(
$header, $canonicalId ) {
234 return Html::rawElement(
236 [
'id' => Sanitizer::escapeIdForAttribute(
$header ) ],
239 [
'id' => Sanitizer::escapeIdForAttribute( $canonicalId ) ],
253 private function getRow( $name, $value, $id ) {
254 return Html::rawElement(
257 'id' => $id ===
null ?
null :
'mw-' . $id,
258 'style' =>
'vertical-align: top;',
260 Html::rawElement(
'td', [], $name ) .
261 Html::rawElement(
'td', [], $value )
278 private function pageInfo() {
283 $config = $this->context->getConfig();
284 $linkRenderer = $this->linkRenderer;
286 $pageCounts = $this->pageCounts();
288 $pageProperties = $this->pageProps->getAllProperties( $title )[$id] ?? [];
292 $pageInfo[
'header-basic'] = [];
295 $displayTitle = $pageProperties[
'displaytitle'] ??
298 $pageInfo[
'header-basic'][] = [
299 $this->
msg(
'pageinfo-display-title' ),
304 $redirectTarget = $this->redirectLookup->getRedirectTarget( $this->
getWikiPage() );
305 if ( $redirectTarget !==
null ) {
306 $pageInfo[
'header-basic'][] = [
307 $this->
msg(
'pageinfo-redirectsto' ),
308 $linkRenderer->
makeLink( $redirectTarget ) .
309 $this->
msg(
'word-separator' )->escaped() .
310 $this->
msg(
'parentheses' )->rawParams( $linkRenderer->
makeLink(
312 $this->msg(
'pageinfo-redirectsto-info' )->text(),
314 [
'action' =>
'info' ]
321 $pageInfo[
'header-basic'][] = [
322 $this->
msg(
'pageinfo-default-sort' ),
323 htmlspecialchars( $sortKey )
327 $pageInfo[
'header-basic'][] = [
328 $this->
msg(
'pageinfo-length' ),
333 $pageInfo[
'header-basic'][] = [ $this->
msg(
'pageinfo-namespace-id' ), $title->
getNamespace() ];
335 if ( $pageNamespace ) {
336 $pageInfo[
'header-basic'][] = [ $this->
msg(
'pageinfo-namespace' ), $pageNamespace ];
340 $pageInfo[
'header-basic'][] = [ $this->
msg(
'pageinfo-article-id' ), $id ];
345 $pageLangHtml = $pageLang .
' - ' .
346 $this->languageNameUtils->getLanguageName( $pageLang, $lang->getCode() );
348 if ( $config->get( MainConfigNames::PageLanguageUseDB )
349 && $this->getAuthority()->probablyCan(
'pagelang', $title )
351 $pageLangHtml .= $this->
msg(
'word-separator' )->escaped();
352 $pageLangHtml .= $this->
msg(
'parentheses' )->rawParams( $linkRenderer->
makeLink(
353 SpecialPage::getTitleValueFor(
'PageLanguage', $title->
getPrefixedText() ),
354 $this->msg(
'pageinfo-language-change' )->text()
358 $pageInfo[
'header-basic'][] = [
359 $this->
msg(
'pageinfo-language' )->escaped(),
364 $modelHtml = htmlspecialchars( ContentHandler::getLocalizedName( $title->
getContentModel() ) );
366 if ( $this->
getAuthority()->probablyCan(
'editcontentmodel', $title ) ) {
367 $modelHtml .= $this->
msg(
'word-separator' )->escaped();
368 $modelHtml .= $this->
msg(
'parentheses' )->rawParams( $linkRenderer->
makeLink(
369 SpecialPage::getTitleValueFor(
'ChangeContentModel', $title->
getPrefixedText() ),
370 $this->msg(
'pageinfo-content-model-change' )->text()
374 $pageInfo[
'header-basic'][] = [
375 $this->
msg(
'pageinfo-content-model' ),
380 $pageUser = $this->userFactory->newFromName( $title->
getRootText() );
381 if ( $pageUser && $pageUser->getId() && !$pageUser->isHidden() ) {
382 $pageInfo[
'header-basic'][] = [
383 $this->
msg(
'pageinfo-user-id' ),
391 if ( isset( $pageProperties[
'noindex'] ) ) {
392 $parserOutput->setIndexPolicy(
'noindex' );
394 if ( isset( $pageProperties[
'index'] ) ) {
395 $parserOutput->setIndexPolicy(
'index' );
399 $policy = $this->
getArticle()->getRobotPolicy(
'view', $parserOutput );
400 $pageInfo[
'header-basic'][] = [
402 $this->
msg(
'pageinfo-robot-policy' ),
403 $this->
msg(
"pageinfo-robot-{$policy['index']}" )
406 $unwatchedPageThreshold = $config->get( MainConfigNames::UnwatchedPageThreshold );
407 if ( $this->
getAuthority()->isAllowed(
'unwatchedpages' ) ||
408 ( $unwatchedPageThreshold !==
false &&
409 $pageCounts[
'watchers'] >= $unwatchedPageThreshold )
412 $pageInfo[
'header-basic'][] = [
413 $this->
msg(
'pageinfo-watchers' ),
414 $lang->formatNum( $pageCounts[
'watchers'] )
417 $visiting = $pageCounts[
'visitingWatchers'] ??
null;
418 if ( $visiting !==
null && $config->get( MainConfigNames::ShowUpdatedMarker ) ) {
419 if ( $visiting > $config->get( MainConfigNames::UnwatchedPageSecret ) ||
420 $this->getAuthority()->isAllowed(
'unwatchedpages' )
422 $value = $lang->formatNum( $visiting );
424 $value = $this->
msg(
'pageinfo-few-visiting-watchers' );
426 $pageInfo[
'header-basic'][] = [
427 $this->
msg(
'pageinfo-visiting-watchers' )
428 ->numParams( ceil( $config->get( MainConfigNames::WatchersMaxAge ) / 86400 ) ),
432 } elseif ( $unwatchedPageThreshold !==
false ) {
433 $pageInfo[
'header-basic'][] = [
434 $this->
msg(
'pageinfo-watchers' ),
435 $this->
msg(
'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
440 $whatLinksHere = SpecialPage::getTitleFor(
'Whatlinkshere', $title->
getPrefixedText() );
441 $pageInfo[
'header-basic'][] = [
444 $this->
msg(
'pageinfo-redirects-name' )->text(),
452 $this->
msg(
'pageinfo-redirects-value' )
458 $pageInfo[
'header-basic'][] = [
459 $this->
msg(
'pageinfo-contentpage' ),
460 $this->
msg(
'pageinfo-contentpage-yes' )
465 if ( $this->namespaceInfo->hasSubpages( $title->
getNamespace() ) ) {
466 $prefixIndex = SpecialPage::getTitleFor(
470 $pageInfo[
'header-basic'][] = [
473 $this->
msg(
'pageinfo-subpages-name' )->text()
476 isset( $pageCounts[
'subpages'] )
477 ? $this->
msg(
'pageinfo-subpages-value' )->numParams(
478 $pageCounts[
'subpages'][
'total'],
479 $pageCounts[
'subpages'][
'redirects'],
480 $pageCounts[
'subpages'][
'nonredirects']
481 ) : $this->
msg(
'pageinfo-subpages-value-unknown' )->rawParams(
483 $title, $this->msg(
'purge' )->text(), [], [
'action' =>
'purge' ] )
489 $category = Category::newFromTitle( $title );
491 $allCount = $category->getMemberCount();
492 $subcatCount = $category->getSubcatCount();
493 $fileCount = $category->getFileCount();
494 $pageCount = $category->getPageCount( Category::COUNT_CONTENT_PAGES );
496 $pageInfo[
'category-info'] = [
498 $this->
msg(
'pageinfo-category-total' ),
499 $lang->formatNum( $allCount )
502 $this->
msg(
'pageinfo-category-pages' ),
503 $lang->formatNum( $pageCount )
506 $this->
msg(
'pageinfo-category-subcats' ),
507 $lang->formatNum( $subcatCount )
510 $this->
msg(
'pageinfo-category-files' ),
511 $lang->formatNum( $fileCount )
518 $fileObj = $this->repoGroup->findFile( $title );
519 if ( $fileObj !==
false ) {
521 $output = Wikimedia\base_convert( $fileObj->getSha1(), 36, 16, 40 );
522 $pageInfo[
'header-basic'][] = [
523 $this->
msg(
'pageinfo-file-hash' ),
530 $pageInfo[
'header-restrictions'] = [];
533 if ( $this->restrictionStore->isCascadeProtected( $title ) ) {
535 $sources = $this->restrictionStore->getCascadeProtectionSources( $title )[0];
537 foreach ( $sources as $sourcePageIdentity ) {
538 $cascadingFrom .= Html::rawElement(
545 $cascadingFrom = Html::rawElement(
'ul', [], $cascadingFrom );
546 $pageInfo[
'header-restrictions'][] = [
547 $this->
msg(
'pageinfo-protect-cascading-from' ),
553 if ( $this->restrictionStore->areRestrictionsCascading( $title ) ) {
554 $pageInfo[
'header-restrictions'][] = [
555 $this->
msg(
'pageinfo-protect-cascading' ),
556 $this->
msg(
'pageinfo-protect-cascading-yes' )
561 foreach ( $this->restrictionStore->listApplicableRestrictionTypes( $title ) as $restrictionType ) {
562 $protections = $this->restrictionStore->getRestrictions( $title, $restrictionType );
564 switch ( count( $protections ) ) {
566 $message = $this->getNamespaceProtectionMessage( $title ) ??
568 $this->
msg(
'protect-default' )->escaped();
573 $message = $this->
msg(
'protect-level-' . $protections[0] );
574 if ( !$message->isDisabled() ) {
575 $message = $message->escaped();
582 $message = $this->
msg(
"protect-fallback", $lang->commaList( $protections ) )->parse();
585 $expiry = $this->restrictionStore->getRestrictionExpiry( $title, $restrictionType );
586 $formattedexpiry = $expiry ===
null ?
'' : $this->
msg(
588 $lang->formatExpiry( $expiry,
true,
'infinity', $user )
590 $message .= $this->
msg(
'word-separator' )->escaped() . $formattedexpiry;
594 $pageInfo[
'header-restrictions'][] = [
595 $this->
msg(
"restriction-$restrictionType" ), $message
598 $protectLog = SpecialPage::getTitleFor(
'Log' );
599 $pageInfo[
'header-restrictions'][] = [
603 $this->
msg(
'pageinfo-view-protect-log' )->text(),
614 $pageInfo[
'header-edits'] = [];
616 $firstRev = $this->revisionLookup->getFirstRevision( $this->
getTitle() );
617 $lastRev = $this->
getWikiPage()->getRevisionRecord();
618 $batch = $this->linkBatchFactory->newLinkBatch();
620 $firstRevUser = $firstRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
621 if ( $firstRevUser ) {
622 $batch->add(
NS_USER, $firstRevUser->getName() );
628 $lastRevUser = $lastRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
629 if ( $lastRevUser ) {
630 $batch->add(
NS_USER, $lastRevUser->getName() );
639 $firstRevUser = $firstRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
643 $firstRevUserName = $firstRevUser ? $firstRevUser->getName() :
'[HIDDEN]';
644 $pageInfo[
'header-edits'][] = [
645 $this->
msg(
'pageinfo-firstuser', $firstRevUserName ),
646 Linker::revUserTools( $firstRev )
650 $pageInfo[
'header-edits'][] = [
651 $this->
msg(
'pageinfo-firsttime' ),
654 $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ),
656 [
'oldid' => $firstRev->getId() ]
663 $lastRevUser = $lastRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
667 $lastRevUserName = $lastRevUser ? $lastRevUser->getName() :
'[HIDDEN]';
668 $pageInfo[
'header-edits'][] = [
669 $this->
msg(
'pageinfo-lastuser', $lastRevUserName ),
670 Linker::revUserTools( $lastRev )
674 $pageInfo[
'header-edits'][] = [
675 $this->
msg(
'pageinfo-lasttime' ),
678 $lang->userTimeAndDate( $this->getWikiPage()->getTimestamp(), $user ),
680 [
'oldid' => $this->getWikiPage()->getLatest() ]
686 $pageInfo[
'header-edits'][] = [
687 $this->
msg(
'pageinfo-edits' ),
688 $lang->formatNum( $pageCounts[
'edits'] )
692 if ( $pageCounts[
'authors'] > 0 ) {
693 $pageInfo[
'header-edits'][] = [
694 $this->
msg(
'pageinfo-authors' ),
695 $lang->formatNum( $pageCounts[
'authors'] )
700 $pageInfo[
'header-edits'][] = [
702 'pageinfo-recent-edits',
703 $lang->formatDuration( $config->get( MainConfigNames::RCMaxAge ) )
705 $lang->formatNum( $pageCounts[
'recent_edits'] )
709 $pageInfo[
'header-edits'][] = [
710 $this->
msg(
'pageinfo-recent-authors' ),
711 $lang->formatNum( $pageCounts[
'recent_authors'] )
715 $wordIDs = $this->magicWordFactory->getDoubleUnderscoreArray()->getNames();
718 $localizedWords = $this->contentLanguage->getMagicWords();
721 foreach ( $pageProperties as $property => $value ) {
722 if ( in_array( $property, $wordIDs ) ) {
723 $listItems[] = Html::element(
'li', [], $localizedWords[$property][1] );
727 $localizedList = Html::rawElement(
'ul', [], implode(
'', $listItems ) );
728 $hiddenCategories = $this->
getWikiPage()->getHiddenCategories();
731 count( $listItems ) > 0 ||
732 count( $hiddenCategories ) > 0 ||
733 $pageCounts[
'transclusion'][
'from'] > 0 ||
734 $pageCounts[
'transclusion'][
'to'] > 0
736 $options = [
'LIMIT' => $config->get( MainConfigNames::PageInfoTransclusionLimit ) ];
738 if ( $config->get( MainConfigNames::MiserMode ) ) {
739 $transcludedTargets = [];
745 $pageInfo[
'header-properties'] = [];
748 if ( count( $listItems ) > 0 ) {
749 $pageInfo[
'header-properties'][] = [
750 $this->
msg(
'pageinfo-magic-words' )->numParams( count( $listItems ) ),
756 if ( count( $hiddenCategories ) > 0 ) {
757 $pageInfo[
'header-properties'][] = [
758 $this->
msg(
'pageinfo-hidden-categories' )
759 ->numParams( count( $hiddenCategories ) ),
760 Linker::formatHiddenCategories( $hiddenCategories )
765 if ( $pageCounts[
'transclusion'][
'from'] > 0 ) {
766 if ( $pageCounts[
'transclusion'][
'from'] > count( $transcludedTemplates ) ) {
767 $more = $this->
msg(
'morenotlisted' )->escaped();
775 $this->linkBatchFactory,
776 $this->restrictionStore
779 $pageInfo[
'header-properties'][] = [
780 $this->
msg(
'pageinfo-templates' )
781 ->numParams( $pageCounts[
'transclusion'][
'from'] ),
782 $templateListFormatter->format( $transcludedTemplates,
false, $more )
786 if ( !$config->get( MainConfigNames::MiserMode ) && $pageCounts[
'transclusion'][
'to'] > 0 ) {
787 if ( $pageCounts[
'transclusion'][
'to'] > count( $transcludedTargets ) ) {
790 $this->
msg(
'moredotdotdot' )->text(),
792 [
'hidelinks' => 1,
'hideredirs' => 1 ]
801 $this->linkBatchFactory,
802 $this->restrictionStore
805 $pageInfo[
'header-properties'][] = [
806 $this->
msg(
'pageinfo-transclusions' )
807 ->numParams( $pageCounts[
'transclusion'][
'to'] ),
808 $templateListFormatter->format( $transcludedTargets,
false, $more )
823 private function getNamespaceProtectionMessage(
Title $title ): ?string {
826 $rights[] =
'editsitecss';
827 $rights[] =
'editsitejs';
829 $rights[] =
'editsitecss';
831 $rights[] =
'editsitejs';
833 $rights[] =
'editsitejson';
835 $rights[] =
'editusercss';
837 $rights[] =
'edituserjs';
839 $rights[] =
'edituserjson';
841 $namespaceProtection = $this->context->getConfig()->get( MainConfigNames::NamespaceProtection );
842 $right = $namespaceProtection[$title->
getNamespace()] ??
null;
845 $rights = (array)$right;
849 return $this->
msg(
'protect-fallback', $this->
getLanguage()->commaList( $rights ) )->parse();
860 private function pageCounts() {
861 $page = $this->getWikiPage();
863 $config = $this->context->getConfig();
864 $cache = $this->wanObjectCache;
866 return $cache->getWithSetCallback(
867 self::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ),
868 WANObjectCache::TTL_WEEK,
869 function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
870 $title = $page->getTitle();
873 $dbr = $this->dbProvider->getReplicaDatabase();
876 $field =
'rev_actor';
877 $pageField =
'rev_page';
879 $watchedItemStore = $this->watchedItemStore;
882 $result[
'watchers'] = $watchedItemStore->
countWatchers( $title );
884 if ( $config->get( MainConfigNames::ShowUpdatedMarker ) ) {
885 $updated = (int)
wfTimestamp( TS_UNIX, $page->getTimestamp() );
888 $updated - $config->get( MainConfigNames::WatchersMaxAge )
893 $edits = (int)$dbr->newSelectQueryBuilder()
894 ->select(
'COUNT(*)' )
896 ->where( [
'rev_page' => $id ] )
899 $result[
'edits'] = $edits;
902 if ( $config->get( MainConfigNames::MiserMode ) ) {
903 $result[
'authors'] = 0;
905 $result[
'authors'] = (int)$dbr->newSelectQueryBuilder()
906 ->select(
"COUNT(DISTINCT $field)" )
908 ->where( [ $pageField => $id ] )
914 $threshold = $dbr->timestamp( time() - $config->get( MainConfigNames::RCMaxAge ) );
917 $edits = (int)$dbr->newSelectQueryBuilder()
918 ->select(
'COUNT(rev_page)' )
920 ->where( [
'rev_page' => $id ] )
921 ->andWhere( $dbr->expr(
'rev_timestamp',
'>=', $threshold ) )
924 $result[
'recent_edits'] = $edits;
927 $result[
'recent_authors'] = (int)$dbr->newSelectQueryBuilder()
928 ->select(
"COUNT(DISTINCT $field)" )
930 ->where( [ $pageField => $id ] )
931 ->andWhere( [ $dbr->expr(
'rev_timestamp',
'>=', $threshold ) ] )
936 if ( $this->namespaceInfo->hasSubpages( $title->
getNamespace() ) ) {
937 $conds = [
'page_namespace' => $title->
getNamespace() ];
938 $conds[] = $dbr->expr(
945 $conds[
'page_is_redirect'] = 1;
946 $result[
'subpages'][
'redirects'] = (int)$dbr->newSelectQueryBuilder()
947 ->select(
'COUNT(page_id)' )
953 $conds[
'page_is_redirect'] = 0;
954 $result[
'subpages'][
'nonredirects'] = (int)$dbr->newSelectQueryBuilder()
955 ->select(
'COUNT(page_id)' )
962 $result[
'subpages'][
'total'] = $result[
'subpages'][
'redirects']
963 + $result[
'subpages'][
'nonredirects'];
967 if ( $config->get( MainConfigNames::MiserMode ) ) {
968 $result[
'transclusion'][
'to'] = 0;
970 $result[
'transclusion'][
'to'] = (int)$dbr->newSelectQueryBuilder()
971 ->select(
'COUNT(tl_from)' )
972 ->from(
'templatelinks' )
973 ->where( $this->linksMigration->getLinksConditions(
'templatelinks', $title ) )
978 $result[
'transclusion'][
'from'] = (int)$dbr->newSelectQueryBuilder()
979 ->select(
'COUNT(*)' )
980 ->from(
'templatelinks' )
996 return $this->msg(
'pageinfo-title' )->plaintextParams( $this->
getTitle()->getPrefixedText() );
1015 return $cache->
makeKey(
'infoaction', md5( (
string)$page ), $revId, self::VERSION );