70 private const VERSION = 1;
73 private LanguageNameUtils $languageNameUtils;
93 LanguageNameUtils $languageNameUtils,
109 parent::__construct( $article,
$context );
110 $this->contentLanguage = $contentLanguage;
111 $this->languageNameUtils = $languageNameUtils;
112 $this->linkBatchFactory = $linkBatchFactory;
113 $this->linkRenderer = $linkRenderer;
114 $this->dbProvider = $dbProvider;
115 $this->magicWordFactory = $magicWordFactory;
116 $this->namespaceInfo = $namespaceInfo;
117 $this->pageProps = $pageProps;
118 $this->repoGroup = $repoGroup;
119 $this->revisionLookup = $revisionLookup;
120 $this->wanObjectCache = $wanObjectCache;
121 $this->watchedItemStore = $watchedItemStore;
122 $this->redirectLookup = $redirectLookup;
123 $this->restrictionStore = $restrictionStore;
124 $this->linksMigration = $linksMigration;
125 $this->userFactory = $userFactory;
152 if ( $revid ===
null ) {
153 $revision = $services->getRevisionLookup()
154 ->getRevisionByTitle( $page, 0, IDBAccessObject::READ_LATEST );
155 $revid = $revision ? $revision->getId() : 0;
157 $cache = $services->getMainWANObjectCache();
159 $cache->delete( $key );
169 'mediawiki.interface.helpers.styles',
170 'mediawiki.action.styles',
179 $revRecord = $this->
getArticle()->fetchRevisionRecord();
182 return $this->
msg(
'missing-revision', $oldid )->parse();
183 } elseif ( !$revRecord->isCurrent() ) {
184 return $this->
msg(
'pageinfo-not-current' )->plain();
189 $msg = $this->
msg(
'pageinfo-header' );
190 $content = $msg->isDisabled() ?
'' : $msg->parse();
193 $pageInfo = $this->pageInfo();
199 foreach ( $pageInfo as $header => $infoTable ) {
203 $content .= $this->makeHeader(
204 $this->
msg(
"pageinfo-$header" )->text(),
205 "mw-pageinfo-$header"
209 foreach ( $infoTable as $infoRow ) {
210 if ( $infoRow[0] ==
"below" ) {
211 $below = $infoRow[1] .
"\n";
214 $name = ( $infoRow[0] instanceof
Message ) ? $infoRow[0]->escaped() : $infoRow[0];
215 $value = ( $infoRow[1] instanceof
Message ) ? $infoRow[1]->escaped() : $infoRow[1];
216 $id = ( $infoRow[0] instanceof
Message ) ? $infoRow[0]->getKey() :
null;
217 $rows .= $this->getRow( $name, $value, $id ) .
"\n";
219 if ( $rows !==
'' ) {
220 $content .= Html::rawElement(
'table', [
'class' =>
'wikitable mw-page-info' ],
223 $content .=
"\n" . $below;
227 if ( !$this->
msg(
'pageinfo-footer' )->isDisabled() ) {
228 $content .= $this->
msg(
'pageinfo-footer' )->parse();
241 private function makeHeader( $header, $canonicalId ) {
242 return Html::rawElement(
244 [
'id' => Sanitizer::escapeIdForAttribute( $header ) ],
247 [
'id' => Sanitizer::escapeIdForAttribute( $canonicalId ) ],
250 htmlspecialchars( $header )
261 private function getRow( $name, $value, $id ) {
262 return Html::rawElement(
265 'id' => $id ===
null ?
null :
'mw-' . $id,
266 'style' =>
'vertical-align: top;',
268 Html::rawElement(
'td', [], $name ) .
269 Html::rawElement(
'td', [], $value )
286 private function pageInfo() {
290 $id = $title->getArticleID();
291 $config = $this->context->getConfig();
292 $linkRenderer = $this->linkRenderer;
294 $pageCounts = $this->pageCounts();
296 $pageProperties = $this->pageProps->getAllProperties( $title )[$id] ?? [];
300 $pageInfo[
'header-basic'] = [];
303 $displayTitle = $pageProperties[
'displaytitle'] ??
304 htmlspecialchars( $title->getPrefixedText(), ENT_NOQUOTES );
306 $pageInfo[
'header-basic'][] = [
307 $this->
msg(
'pageinfo-display-title' ),
312 $redirectTarget = $this->redirectLookup->getRedirectTarget( $this->
getWikiPage() );
313 if ( $redirectTarget !==
null ) {
314 $pageInfo[
'header-basic'][] = [
315 $this->
msg(
'pageinfo-redirectsto' ),
316 $linkRenderer->
makeLink( $redirectTarget ) .
317 $this->
msg(
'word-separator' )->escaped() .
318 $this->
msg(
'parentheses' )->rawParams( $linkRenderer->
makeLink(
320 $this->msg(
'pageinfo-redirectsto-info' )->text(),
322 [
'action' =>
'info' ]
328 $sortKey = $pageProperties[
'defaultsort'] ?? $title->getCategorySortkey();
329 $pageInfo[
'header-basic'][] = [
330 $this->
msg(
'pageinfo-default-sort' ),
331 htmlspecialchars( $sortKey )
335 $pageInfo[
'header-basic'][] = [
336 $this->
msg(
'pageinfo-length' ),
337 $lang->formatNum( $title->getLength() )
341 $pageInfo[
'header-basic'][] = [ $this->
msg(
'pageinfo-namespace-id' ), $title->getNamespace() ];
342 $pageNamespace = $title->getNsText();
343 if ( $pageNamespace ) {
344 $pageInfo[
'header-basic'][] = [ $this->
msg(
'pageinfo-namespace' ), $pageNamespace ];
348 $pageInfo[
'header-basic'][] = [ $this->
msg(
'pageinfo-article-id' ), $id ];
351 $pageLang = $title->getPageLanguage()->getCode();
353 $pageLangHtml = $pageLang .
' - ' .
354 $this->languageNameUtils->getLanguageName( $pageLang, $lang->getCode() );
357 && $this->getAuthority()->probablyCan(
'pagelang', $title )
359 $pageLangHtml .= $this->
msg(
'word-separator' )->escaped();
360 $pageLangHtml .= $this->
msg(
'parentheses' )->rawParams( $linkRenderer->
makeLink(
362 $this->msg(
'pageinfo-language-change' )->text()
366 $pageInfo[
'header-basic'][] = [
367 $this->
msg(
'pageinfo-language' )->escaped(),
374 if ( $this->
getAuthority()->probablyCan(
'editcontentmodel', $title ) ) {
375 $modelHtml .= $this->
msg(
'word-separator' )->escaped();
376 $modelHtml .= $this->
msg(
'parentheses' )->rawParams( $linkRenderer->
makeLink(
378 $this->msg(
'pageinfo-content-model-change' )->text()
382 $pageInfo[
'header-basic'][] = [
383 $this->
msg(
'pageinfo-content-model' ),
387 if ( $title->inNamespace(
NS_USER ) ) {
388 $pageUser = $this->userFactory->newFromName( $title->getRootText() );
389 if ( $pageUser && $pageUser->getId() && !$pageUser->isHidden() ) {
390 $pageInfo[
'header-basic'][] = [
391 $this->
msg(
'pageinfo-user-id' ),
398 $parserOutput =
new ParserOutput();
399 if ( isset( $pageProperties[
'noindex'] ) ) {
400 $parserOutput->setIndexPolicy(
'noindex' );
402 if ( isset( $pageProperties[
'index'] ) ) {
403 $parserOutput->setIndexPolicy(
'index' );
407 $policy = $this->
getArticle()->getRobotPolicy(
'view', $parserOutput );
408 $pageInfo[
'header-basic'][] = [
410 $this->
msg(
'pageinfo-robot-policy' ),
411 $this->
msg(
"pageinfo-robot-{$policy['index']}" )
415 if ( $this->
getAuthority()->isAllowed(
'unwatchedpages' ) ||
416 ( $unwatchedPageThreshold !==
false &&
417 $pageCounts[
'watchers'] >= $unwatchedPageThreshold )
420 $pageInfo[
'header-basic'][] = [
421 $this->
msg(
'pageinfo-watchers' ),
422 $lang->formatNum( $pageCounts[
'watchers'] )
425 $visiting = $pageCounts[
'visitingWatchers'] ??
null;
428 $this->getAuthority()->isAllowed(
'unwatchedpages' )
430 $value = $lang->formatNum( $visiting );
432 $value = $this->
msg(
'pageinfo-few-visiting-watchers' );
434 $pageInfo[
'header-basic'][] = [
435 $this->
msg(
'pageinfo-visiting-watchers' )
440 } elseif ( $unwatchedPageThreshold !==
false ) {
441 $pageInfo[
'header-basic'][] = [
442 $this->
msg(
'pageinfo-watchers' ),
443 $this->
msg(
'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
449 $pageInfo[
'header-basic'][] = [
452 $this->
msg(
'pageinfo-redirects-name' )->text(),
457 'hideimages' => $title->getNamespace() ===
NS_FILE
460 $this->
msg(
'pageinfo-redirects-value' )
461 ->numParams( count( $title->getRedirectsHere() ) )
466 $pageInfo[
'header-basic'][] = [
467 $this->
msg(
'pageinfo-contentpage' ),
468 $this->
msg(
'pageinfo-contentpage-yes' )
473 if ( $this->namespaceInfo->hasSubpages( $title->getNamespace() ) ) {
476 $title->getPrefixedText() .
'/'
478 $pageInfo[
'header-basic'][] = [
481 $this->
msg(
'pageinfo-subpages-name' )->text()
484 isset( $pageCounts[
'subpages'] )
485 ? $this->
msg(
'pageinfo-subpages-value' )->numParams(
486 $pageCounts[
'subpages'][
'total'],
487 $pageCounts[
'subpages'][
'redirects'],
488 $pageCounts[
'subpages'][
'nonredirects']
489 ) : $this->
msg(
'pageinfo-subpages-value-unknown' )->rawParams(
491 $title, $this->msg(
'purge' )->text(), [], [
'action' =>
'purge' ] )
499 $allCount = $category->getMemberCount();
500 $subcatCount = $category->getSubcatCount();
501 $fileCount = $category->getFileCount();
504 $pageInfo[
'category-info'] = [
506 $this->
msg(
'pageinfo-category-total' ),
507 $lang->formatNum( $allCount )
510 $this->
msg(
'pageinfo-category-pages' ),
511 $lang->formatNum( $pageCount )
514 $this->
msg(
'pageinfo-category-subcats' ),
515 $lang->formatNum( $subcatCount )
518 $this->
msg(
'pageinfo-category-files' ),
519 $lang->formatNum( $fileCount )
525 if ( $title->inNamespace(
NS_FILE ) ) {
526 $fileObj = $this->repoGroup->findFile( $title );
527 if ( $fileObj !==
false ) {
529 $output = \Wikimedia\base_convert( $fileObj->getSha1(), 36, 16, 40 );
530 $pageInfo[
'header-basic'][] = [
531 $this->
msg(
'pageinfo-file-hash' ),
538 $pageInfo[
'header-restrictions'] = [];
541 if ( $this->restrictionStore->isCascadeProtected( $title ) ) {
543 $sources = $this->restrictionStore->getCascadeProtectionSources( $title )[0];
545 foreach ( $sources as $sourcePageIdentity ) {
546 $cascadingFrom .= Html::rawElement(
553 $cascadingFrom = Html::rawElement(
'ul', [], $cascadingFrom );
554 $pageInfo[
'header-restrictions'][] = [
555 $this->
msg(
'pageinfo-protect-cascading-from' ),
561 if ( $this->restrictionStore->areRestrictionsCascading( $title ) ) {
562 $pageInfo[
'header-restrictions'][] = [
563 $this->
msg(
'pageinfo-protect-cascading' ),
564 $this->
msg(
'pageinfo-protect-cascading-yes' )
569 foreach ( $this->restrictionStore->listApplicableRestrictionTypes( $title ) as $restrictionType ) {
570 $protections = $this->restrictionStore->getRestrictions( $title, $restrictionType );
572 switch ( count( $protections ) ) {
574 $message = $this->getNamespaceProtectionMessage( $title ) ??
576 $this->
msg(
'protect-default' )->escaped();
581 $message = $this->
msg(
'protect-level-' . $protections[0] );
582 if ( !$message->isDisabled() ) {
583 $message = $message->escaped();
590 $message = $this->
msg(
"protect-fallback", $lang->commaList( $protections ) )->parse();
593 $expiry = $this->restrictionStore->getRestrictionExpiry( $title, $restrictionType );
594 $formattedexpiry = $expiry ===
null ?
'' : $this->
msg(
596 $lang->formatExpiry( $expiry,
true,
'infinity', $user )
598 $message .= $this->
msg(
'word-separator' )->escaped() . $formattedexpiry;
602 $pageInfo[
'header-restrictions'][] = [
603 $this->
msg(
"restriction-$restrictionType" ), $message
607 $pageInfo[
'header-restrictions'][] = [
611 $this->
msg(
'pageinfo-view-protect-log' )->text(),
613 [
'type' =>
'protect',
'page' => $title->getPrefixedText() ]
622 $pageInfo[
'header-edits'] = [];
624 $firstRev = $this->revisionLookup->getFirstRevision( $this->
getTitle() );
625 $lastRev = $this->
getWikiPage()->getRevisionRecord();
626 $batch = $this->linkBatchFactory->newLinkBatch()
627 ->setCaller( __METHOD__ );
629 $firstRevUser = $firstRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
630 if ( $firstRevUser ) {
631 $batch->addUser( $firstRevUser );
636 $lastRevUser = $lastRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
637 if ( $lastRevUser ) {
638 $batch->addUser( $lastRevUser );
646 $firstRevUser = $firstRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
650 $firstRevUserName = $firstRevUser ? $firstRevUser->getName() :
'[HIDDEN]';
651 $pageInfo[
'header-edits'][] = [
652 $this->
msg(
'pageinfo-firstuser', $firstRevUserName ),
653 Linker::revUserTools( $firstRev )
657 $pageInfo[
'header-edits'][] = [
658 $this->
msg(
'pageinfo-firsttime' ),
661 $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ),
663 [
'oldid' => $firstRev->getId() ]
670 $lastRevUser = $lastRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
674 $lastRevUserName = $lastRevUser ? $lastRevUser->getName() :
'[HIDDEN]';
675 $pageInfo[
'header-edits'][] = [
676 $this->
msg(
'pageinfo-lastuser', $lastRevUserName ),
677 Linker::revUserTools( $lastRev )
681 $pageInfo[
'header-edits'][] = [
682 $this->
msg(
'pageinfo-lasttime' ),
685 $lang->userTimeAndDate( $this->getWikiPage()->getTimestamp(), $user ),
687 [
'oldid' => $this->getWikiPage()->getLatest() ]
693 $pageInfo[
'header-edits'][] = [
694 $this->
msg(
'pageinfo-edits' ),
695 $lang->formatNum( $pageCounts[
'edits'] )
699 if ( $pageCounts[
'authors'] > 0 ) {
700 $pageInfo[
'header-edits'][] = [
701 $this->
msg(
'pageinfo-authors' ),
702 $lang->formatNum( $pageCounts[
'authors'] )
707 $pageInfo[
'header-edits'][] = [
709 'pageinfo-recent-edits',
712 $lang->formatNum( $pageCounts[
'recent_edits'] )
716 $pageInfo[
'header-edits'][] = [
717 $this->
msg(
'pageinfo-recent-authors' ),
718 $lang->formatNum( $pageCounts[
'recent_authors'] )
722 $wordIDs = $this->magicWordFactory->getDoubleUnderscoreArray()->getNames();
725 $localizedWords = $this->contentLanguage->getMagicWords();
728 foreach ( $pageProperties as $property => $value ) {
729 if ( in_array( $property, $wordIDs ) ) {
730 $listItems[] =
Html::element(
'li', [], $localizedWords[$property][1] );
734 $localizedList = Html::rawElement(
'ul', [], implode(
'', $listItems ) );
735 $hiddenCategories = $this->
getWikiPage()->getHiddenCategories();
738 count( $listItems ) > 0 ||
739 count( $hiddenCategories ) > 0 ||
740 $pageCounts[
'transclusion'][
'from'] > 0 ||
741 $pageCounts[
'transclusion'][
'to'] > 0
744 $transcludedTemplates = $title->getTemplateLinksFrom( $options );
746 $transcludedTargets = [];
748 $transcludedTargets = $title->getTemplateLinksTo( $options );
752 $pageInfo[
'header-properties'] = [];
755 if ( count( $listItems ) > 0 ) {
756 $pageInfo[
'header-properties'][] = [
757 $this->
msg(
'pageinfo-magic-words' )->numParams( count( $listItems ) ),
763 if ( count( $hiddenCategories ) > 0 ) {
764 $pageInfo[
'header-properties'][] = [
765 $this->
msg(
'pageinfo-hidden-categories' )
766 ->numParams( count( $hiddenCategories ) ),
767 Linker::formatHiddenCategories( $hiddenCategories )
772 if ( $pageCounts[
'transclusion'][
'from'] > 0 ) {
773 if ( $pageCounts[
'transclusion'][
'from'] > count( $transcludedTemplates ) ) {
774 $more = $this->
msg(
'morenotlisted' )->escaped();
779 $templateListFormatter =
new TemplatesOnThisPageFormatter(
782 $this->linkBatchFactory,
783 $this->restrictionStore
786 $pageInfo[
'header-properties'][] = [
787 $this->
msg(
'pageinfo-templates' )
788 ->numParams( $pageCounts[
'transclusion'][
'from'] ),
789 $templateListFormatter->format( $transcludedTemplates,
false, $more )
794 if ( $pageCounts[
'transclusion'][
'to'] > count( $transcludedTargets ) ) {
797 $this->
msg(
'moredotdotdot' )->text(),
799 [
'hidelinks' => 1,
'hideredirs' => 1 ]
805 $templateListFormatter =
new TemplatesOnThisPageFormatter(
808 $this->linkBatchFactory,
809 $this->restrictionStore
812 $pageInfo[
'header-properties'][] = [
813 $this->
msg(
'pageinfo-transclusions' )
814 ->numParams( $pageCounts[
'transclusion'][
'to'] ),
815 $templateListFormatter->format( $transcludedTargets,
false, $more )
830 private function getNamespaceProtectionMessage( Title $title ): ?string {
832 if ( $title->isRawHtmlMessage() ) {
833 $rights[] =
'editsitecss';
834 $rights[] =
'editsitejs';
835 } elseif ( $title->isSiteCssConfigPage() ) {
836 $rights[] =
'editsitecss';
837 } elseif ( $title->isSiteJsConfigPage() ) {
838 $rights[] =
'editsitejs';
839 } elseif ( $title->isSiteJsonConfigPage() ) {
840 $rights[] =
'editsitejson';
841 } elseif ( $title->isUserCssConfigPage() ) {
842 $rights[] =
'editusercss';
843 } elseif ( $title->isUserJsConfigPage() ) {
844 $rights[] =
'edituserjs';
845 } elseif ( $title->isUserJsonConfigPage() ) {
846 $rights[] =
'edituserjson';
849 $right = $namespaceProtection[$title->getNamespace()] ??
null;
852 $rights = (array)$right;
856 return $this->
msg(
'protect-fallback', $this->
getLanguage()->commaList( $rights ) )->parse();
867 private function pageCounts() {
868 $page = $this->getWikiPage();
870 $config = $this->context->getConfig();
871 $cache = $this->wanObjectCache;
873 return $cache->getWithSetCallback(
874 self::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ),
875 WANObjectCache::TTL_WEEK,
876 function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
877 $title = $page->getTitle();
878 $id = $title->getArticleID();
880 $dbr = $this->dbProvider->getReplicaDatabase();
883 $field =
'rev_actor';
884 $pageField =
'rev_page';
886 $watchedItemStore = $this->watchedItemStore;
889 $result[
'watchers'] = $watchedItemStore->
countWatchers( $title );
892 $updated = (int)
wfTimestamp( TS_UNIX, $page->getTimestamp() );
900 $edits = (int)$dbr->newSelectQueryBuilder()
901 ->select(
'COUNT(*)' )
903 ->where( [
'rev_page' => $id ] )
906 $result[
'edits'] = $edits;
910 $result[
'authors'] = 0;
912 $result[
'authors'] = (int)$dbr->newSelectQueryBuilder()
913 ->select(
"COUNT(DISTINCT $field)" )
915 ->where( [ $pageField => $id ] )
924 $edits = (int)$dbr->newSelectQueryBuilder()
925 ->select(
'COUNT(rev_page)' )
927 ->where( [
'rev_page' => $id ] )
928 ->andWhere( $dbr->expr(
'rev_timestamp',
'>=', $threshold ) )
931 $result[
'recent_edits'] = $edits;
934 $result[
'recent_authors'] = (int)$dbr->newSelectQueryBuilder()
935 ->select(
"COUNT(DISTINCT $field)" )
937 ->where( [ $pageField => $id ] )
938 ->andWhere( [ $dbr->expr(
'rev_timestamp',
'>=', $threshold ) ] )
943 if ( $this->namespaceInfo->hasSubpages( $title->getNamespace() ) ) {
944 $conds = [
'page_namespace' => $title->getNamespace() ];
945 $conds[] = $dbr->expr(
948 new LikeValue( $title->getDBkey() .
'/', $dbr->anyString() )
952 $conds[
'page_is_redirect'] = 1;
953 $result[
'subpages'][
'redirects'] = (int)$dbr->newSelectQueryBuilder()
954 ->select(
'COUNT(page_id)' )
960 $conds[
'page_is_redirect'] = 0;
961 $result[
'subpages'][
'nonredirects'] = (int)$dbr->newSelectQueryBuilder()
962 ->select(
'COUNT(page_id)' )
969 $result[
'subpages'][
'total'] = $result[
'subpages'][
'redirects']
970 + $result[
'subpages'][
'nonredirects'];
975 $result[
'transclusion'][
'to'] = 0;
977 $result[
'transclusion'][
'to'] = (int)$dbr->newSelectQueryBuilder()
978 ->select(
'COUNT(tl_from)' )
979 ->from(
'templatelinks' )
980 ->where( $this->linksMigration->getLinksConditions(
'templatelinks', $title ) )
985 $result[
'transclusion'][
'from'] = (int)$dbr->newSelectQueryBuilder()
986 ->select(
'COUNT(*)' )
987 ->from(
'templatelinks' )
988 ->where( [
'tl_from' => $title->getArticleID() ] )
1003 return $this->msg(
'pageinfo-title' )->plaintextParams( $this->
getTitle()->getPrefixedText() );
1022 return $cache->
makeKey(
'infoaction', md5( (
string)$page ), $revId, self::VERSION );