3 * Displays information about a page.
5 * Copyright © 2011 Alexandre Emsenhuber
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 use MediaWiki\MediaWikiServices
;
26 use MediaWiki\Storage\RevisionRecord
;
27 use Wikimedia\Rdbms\Database
;
30 * Displays information about a page.
34 class InfoAction
extends FormlessAction
{
38 * Returns the name of the action this object responds to.
40 * @return string Lowercase name
42 public function getName() {
47 * Whether this action can still be executed by a blocked user.
51 public function requiresUnblock() {
56 * Whether this action requires the wiki not to be locked.
60 public function requiresWrite() {
65 * Clear the info cache for a given Title.
68 * @param Title $title Title to clear cache for
69 * @param int|null $revid Revision id to clear
71 public static function invalidateCache( Title
$title, $revid = null ) {
73 $revision = Revision
::newFromTitle( $title, 0, Revision
::READ_LATEST
);
74 $revid = $revision ?
$revision->getId() : null;
76 if ( $revid !== null ) {
77 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
78 $key = self
::getCacheKey( $cache, $title, $revid );
79 $cache->delete( $key );
84 * Shows page information on GET request.
86 * @return string Page information that will be added to the output
88 public function onView() {
92 $oldid = $this->page
->getOldID();
94 $revision = $this->page
->getRevisionFetched();
96 // Revision is missing
97 if ( $revision === null ) {
98 return $this->msg( 'missing-revision', $oldid )->parse();
101 // Revision is not current
102 if ( !$revision->isCurrent() ) {
103 return $this->msg( 'pageinfo-not-current' )->plain();
108 $this->addHelpLink( 'Page information' );
111 if ( !$this->msg( 'pageinfo-header' )->isDisabled() ) {
112 $content .= $this->msg( 'pageinfo-header' )->parse();
115 // Hide "This page is a member of # hidden categories" explanation
116 $content .= Html
::element( 'style', [],
117 '.mw-hiddenCategoriesExplanation { display: none; }' ) . "\n";
119 // Hide "Templates used on this page" explanation
120 $content .= Html
::element( 'style', [],
121 '.mw-templatesUsedExplanation { display: none; }' ) . "\n";
123 // Get page information
124 $pageInfo = $this->pageInfo();
126 // Allow extensions to add additional information
127 Hooks
::run( 'InfoAction', [ $this->getContext(), &$pageInfo ] );
129 // Render page information
130 foreach ( $pageInfo as $header => $infoTable ) {
132 // pageinfo-header-basic, pageinfo-header-edits, pageinfo-header-restrictions,
133 // pageinfo-header-properties, pageinfo-category-info
134 $content .= $this->makeHeader(
135 $this->msg( "pageinfo-${header}" )->text(),
136 "mw-pageinfo-${header}"
140 foreach ( $infoTable as $infoRow ) {
141 if ( $infoRow[0] == "below" ) {
142 $below = $infoRow[1] . "\n";
145 $name = ( $infoRow[0] instanceof Message
) ?
$infoRow[0]->escaped() : $infoRow[0];
146 $value = ( $infoRow[1] instanceof Message
) ?
$infoRow[1]->escaped() : $infoRow[1];
147 $id = ( $infoRow[0] instanceof Message
) ?
$infoRow[0]->getKey() : null;
148 $table = $this->addRow( $table, $name, $value, $id ) . "\n";
150 $content = $this->addTable( $content, $table ) . "\n" . $below;
154 if ( !$this->msg( 'pageinfo-footer' )->isDisabled() ) {
155 $content .= $this->msg( 'pageinfo-footer' )->parse();
162 * Creates a header that can be added to the output.
164 * @param string $header The header text.
165 * @param string $canonicalId
166 * @return string The HTML.
168 protected function makeHeader( $header, $canonicalId ) {
169 $spanAttribs = [ 'class' => 'mw-headline', 'id' => Sanitizer
::escapeIdForAttribute( $header ) ];
170 $h2Attribs = [ 'id' => Sanitizer
::escapeIdForAttribute( $canonicalId ) ];
172 return Html
::rawElement( 'h2', $h2Attribs, Html
::element( 'span', $spanAttribs, $header ) );
176 * Adds a row to a table that will be added to the content.
178 * @param string $table The table that will be added to the content
179 * @param string $name The name of the row
180 * @param string $value The value of the row
181 * @param string|null $id The ID to use for the 'tr' element
182 * @return string The table with the row added
184 protected function addRow( $table, $name, $value, $id ) {
188 $id === null ?
[] : [ 'id' => 'mw-' . $id ],
189 Html
::rawElement( 'td', [ 'style' => 'vertical-align: top;' ], $name ) .
190 Html
::rawElement( 'td', [], $value )
195 * Adds a table to the content that will be added to the output.
197 * @param string $content The content that will be added to the output
198 * @param string $table
199 * @return string The content with the table added
201 protected function addTable( $content, $table ) {
202 return $content . Html
::rawElement( 'table', [ 'class' => 'wikitable mw-page-info' ],
207 * Returns an array of info groups (will be rendered as tables), keyed by group ID.
208 * Group IDs are arbitrary and used so that extensions may add additional information in
209 * arbitrary positions (and as message keys for section headers for the tables, prefixed
211 * Each info group is a non-associative array of info items (rendered as table rows).
212 * Each info item is an array with two elements: the first describes the type of
213 * information, the second the value for the current page. Both can be strings (will be
214 * interpreted as raw HTML) or messages (will be interpreted as plain text and escaped).
218 protected function pageInfo() {
219 $services = MediaWikiServices
::getInstance();
221 $user = $this->getUser();
222 $lang = $this->getLanguage();
223 $title = $this->getTitle();
224 $id = $title->getArticleID();
225 $config = $this->context
->getConfig();
226 $linkRenderer = $services->getLinkRenderer();
228 $pageCounts = $this->pageCounts( $this->page
);
230 $props = PageProps
::getInstance()->getAllProperties( $title );
231 $pageProperties = $props[$id] ??
[];
235 $pageInfo['header-basic'] = [];
238 $displayTitle = $pageProperties['displaytitle'] ??
$title->getPrefixedText();
240 $pageInfo['header-basic'][] = [
241 $this->msg( 'pageinfo-display-title' ), $displayTitle
244 // Is it a redirect? If so, where to?
245 $redirectTarget = $this->page
->getRedirectTarget();
246 if ( $redirectTarget !== null ) {
247 $pageInfo['header-basic'][] = [
248 $this->msg( 'pageinfo-redirectsto' ),
249 $linkRenderer->makeLink( $redirectTarget ) .
250 $this->msg( 'word-separator' )->escaped() .
251 $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
253 $this->msg( 'pageinfo-redirectsto-info' )->text(),
255 [ 'action' => 'info' ]
261 $sortKey = $pageProperties['defaultsort'] ??
$title->getCategorySortkey();
263 $sortKey = htmlspecialchars( $sortKey );
264 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-default-sort' ), $sortKey ];
266 // Page length (in bytes)
267 $pageInfo['header-basic'][] = [
268 $this->msg( 'pageinfo-length' ), $lang->formatNum( $title->getLength() )
272 $pageNamespace = $title->getNsText();
273 if ( $pageNamespace ) {
274 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-namespace' ), $pageNamespace ];
277 // Page ID (number not localised, as it's a database ID)
278 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-article-id' ), $id ];
280 // Language in which the page content is (supposed to be) written
281 $pageLang = $title->getPageLanguage()->getCode();
283 $permissionManager = MediaWikiServices
::getInstance()->getPermissionManager();
285 $pageLangHtml = $pageLang . ' - ' .
286 Language
::fetchLanguageName( $pageLang, $lang->getCode() );
287 // Link to Special:PageLanguage with pre-filled page title if user has permissions
288 if ( $config->get( 'PageLanguageUseDB' )
289 && $permissionManager->userCan( 'pagelang', $user, $title )
291 $pageLangHtml .= ' ' . $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
292 SpecialPage
::getTitleValueFor( 'PageLanguage', $title->getPrefixedText() ),
293 $this->msg( 'pageinfo-language-change' )->text()
297 $pageInfo['header-basic'][] = [
298 $this->msg( 'pageinfo-language' )->escaped(),
302 // Content model of the page
303 $modelHtml = htmlspecialchars( ContentHandler
::getLocalizedName( $title->getContentModel() ) );
304 // If the user can change it, add a link to Special:ChangeContentModel
305 if ( $config->get( 'ContentHandlerUseDB' )
306 && $permissionManager->userCan( 'editcontentmodel', $user, $title )
308 $modelHtml .= ' ' . $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
309 SpecialPage
::getTitleValueFor( 'ChangeContentModel', $title->getPrefixedText() ),
310 $this->msg( 'pageinfo-content-model-change' )->text()
314 $pageInfo['header-basic'][] = [
315 $this->msg( 'pageinfo-content-model' ),
319 if ( $title->inNamespace( NS_USER
) ) {
320 $pageUser = User
::newFromName( $title->getRootText() );
321 if ( $pageUser && $pageUser->getId() && !$pageUser->isHidden() ) {
322 $pageInfo['header-basic'][] = [
323 $this->msg( 'pageinfo-user-id' ),
329 // Search engine status
330 $pOutput = new ParserOutput();
331 if ( isset( $pageProperties['noindex'] ) ) {
332 $pOutput->setIndexPolicy( 'noindex' );
334 if ( isset( $pageProperties['index'] ) ) {
335 $pOutput->setIndexPolicy( 'index' );
338 // Use robot policy logic
339 $policy = $this->page
->getRobotPolicy( 'view', $pOutput );
340 $pageInfo['header-basic'][] = [
341 // Messages: pageinfo-robot-index, pageinfo-robot-noindex
342 $this->msg( 'pageinfo-robot-policy' ),
343 $this->msg( "pageinfo-robot-${policy['index']}" )
346 $unwatchedPageThreshold = $config->get( 'UnwatchedPageThreshold' );
348 $user->isAllowed( 'unwatchedpages' ) ||
349 ( $unwatchedPageThreshold !== false &&
350 $pageCounts['watchers'] >= $unwatchedPageThreshold )
352 // Number of page watchers
353 $pageInfo['header-basic'][] = [
354 $this->msg( 'pageinfo-watchers' ),
355 $lang->formatNum( $pageCounts['watchers'] )
358 $config->get( 'ShowUpdatedMarker' ) &&
359 isset( $pageCounts['visitingWatchers'] )
361 $minToDisclose = $config->get( 'UnwatchedPageSecret' );
362 if ( $pageCounts['visitingWatchers'] > $minToDisclose ||
363 $user->isAllowed( 'unwatchedpages' ) ) {
364 $pageInfo['header-basic'][] = [
365 $this->msg( 'pageinfo-visiting-watchers' ),
366 $lang->formatNum( $pageCounts['visitingWatchers'] )
369 $pageInfo['header-basic'][] = [
370 $this->msg( 'pageinfo-visiting-watchers' ),
371 $this->msg( 'pageinfo-few-visiting-watchers' )
375 } elseif ( $unwatchedPageThreshold !== false ) {
376 $pageInfo['header-basic'][] = [
377 $this->msg( 'pageinfo-watchers' ),
378 $this->msg( 'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
382 // Redirects to this page
383 $whatLinksHere = SpecialPage
::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
384 $pageInfo['header-basic'][] = [
385 $linkRenderer->makeLink(
387 $this->msg( 'pageinfo-redirects-name' )->text(),
392 'hideimages' => $title->getNamespace() == NS_FILE
395 $this->msg( 'pageinfo-redirects-value' )
396 ->numParams( count( $title->getRedirectsHere() ) )
399 // Is it counted as a content page?
400 if ( $this->page
->isCountable() ) {
401 $pageInfo['header-basic'][] = [
402 $this->msg( 'pageinfo-contentpage' ),
403 $this->msg( 'pageinfo-contentpage-yes' )
407 // Subpages of this page, if subpages are enabled for the current NS
408 if ( $services->getNamespaceInfo()->hasSubpages( $title->getNamespace() ) ) {
409 $prefixIndex = SpecialPage
::getTitleFor(
410 'Prefixindex', $title->getPrefixedText() . '/' );
411 $pageInfo['header-basic'][] = [
412 $linkRenderer->makeLink(
414 $this->msg( 'pageinfo-subpages-name' )->text()
416 $this->msg( 'pageinfo-subpages-value' )
418 $pageCounts['subpages']['total'],
419 $pageCounts['subpages']['redirects'],
420 $pageCounts['subpages']['nonredirects'] )
424 if ( $title->inNamespace( NS_CATEGORY
) ) {
425 $category = Category
::newFromTitle( $title );
427 // $allCount is the total number of cat members,
428 // not the count of how many members are normal pages.
429 $allCount = (int)$category->getPageCount();
430 $subcatCount = (int)$category->getSubcatCount();
431 $fileCount = (int)$category->getFileCount();
432 $pagesCount = $allCount - $subcatCount - $fileCount;
434 $pageInfo['category-info'] = [
436 $this->msg( 'pageinfo-category-total' ),
437 $lang->formatNum( $allCount )
440 $this->msg( 'pageinfo-category-pages' ),
441 $lang->formatNum( $pagesCount )
444 $this->msg( 'pageinfo-category-subcats' ),
445 $lang->formatNum( $subcatCount )
448 $this->msg( 'pageinfo-category-files' ),
449 $lang->formatNum( $fileCount )
454 // Display image SHA-1 value
455 if ( $title->inNamespace( NS_FILE
) ) {
456 $fileObj = $services->getRepoGroup()->findFile( $title );
457 if ( $fileObj !== false ) {
458 // Convert the base-36 sha1 value obtained from database to base-16
459 $output = Wikimedia\base_convert
( $fileObj->getSha1(), 36, 16, 40 );
460 $pageInfo['header-basic'][] = [
461 $this->msg( 'pageinfo-file-hash' ),
468 $pageInfo['header-restrictions'] = [];
470 // Is this page affected by the cascading protection of something which includes it?
471 if ( $title->isCascadeProtected() ) {
473 $sources = $title->getCascadeProtectionSources()[0];
475 foreach ( $sources as $sourceTitle ) {
476 $cascadingFrom .= Html
::rawElement(
477 'li', [], $linkRenderer->makeKnownLink( $sourceTitle ) );
480 $cascadingFrom = Html
::rawElement( 'ul', [], $cascadingFrom );
481 $pageInfo['header-restrictions'][] = [
482 $this->msg( 'pageinfo-protect-cascading-from' ),
487 // Is out protection set to cascade to other pages?
488 if ( $title->areRestrictionsCascading() ) {
489 $pageInfo['header-restrictions'][] = [
490 $this->msg( 'pageinfo-protect-cascading' ),
491 $this->msg( 'pageinfo-protect-cascading-yes' )
496 foreach ( $title->getRestrictionTypes() as $restrictionType ) {
497 $protectionLevel = implode( ', ', $title->getRestrictions( $restrictionType ) );
499 if ( $protectionLevel == '' ) {
501 $message = $this->msg( 'protect-default' )->escaped();
503 // Administrators only
504 // Messages: protect-level-autoconfirmed, protect-level-sysop
505 $message = $this->msg( "protect-level-$protectionLevel" );
506 if ( $message->isDisabled() ) {
507 // Require "$1" permission
508 $message = $this->msg( "protect-fallback", $protectionLevel )->parse();
510 $message = $message->escaped();
513 $expiry = $title->getRestrictionExpiry( $restrictionType );
514 $formattedexpiry = $this->msg( 'parentheses',
515 $lang->formatExpiry( $expiry ) )->escaped();
516 $message .= $this->msg( 'word-separator' )->escaped() . $formattedexpiry;
518 // Messages: restriction-edit, restriction-move, restriction-create,
519 // restriction-upload
520 $pageInfo['header-restrictions'][] = [
521 $this->msg( "restriction-$restrictionType" ), $message
524 $protectLog = SpecialPage
::getTitleFor( 'Log' );
525 $pageInfo['header-restrictions'][] = [
527 $linkRenderer->makeKnownLink(
529 $this->msg( 'pageinfo-view-protect-log' )->text(),
531 [ 'type' => 'protect', 'page' => $title->getPrefixedText() ]
535 if ( !$this->page
->exists() ) {
540 $pageInfo['header-edits'] = [];
542 $firstRev = $this->page
->getOldestRevision();
543 $lastRev = $this->page
->getRevision();
544 $batch = new LinkBatch
;
547 $firstRevUser = $firstRev->getUserText( RevisionRecord
::FOR_THIS_USER
);
548 if ( $firstRevUser !== '' ) {
549 $firstRevUserTitle = Title
::makeTitle( NS_USER
, $firstRevUser );
550 $batch->addObj( $firstRevUserTitle );
551 $batch->addObj( $firstRevUserTitle->getTalkPage() );
556 $lastRevUser = $lastRev->getUserText( RevisionRecord
::FOR_THIS_USER
);
557 if ( $lastRevUser !== '' ) {
558 $lastRevUserTitle = Title
::makeTitle( NS_USER
, $lastRevUser );
559 $batch->addObj( $lastRevUserTitle );
560 $batch->addObj( $lastRevUserTitle->getTalkPage() );
568 $pageInfo['header-edits'][] = [
569 $this->msg( 'pageinfo-firstuser' ),
570 Linker
::revUserTools( $firstRev )
573 // Date of page creation
574 $pageInfo['header-edits'][] = [
575 $this->msg( 'pageinfo-firsttime' ),
576 $linkRenderer->makeKnownLink(
578 $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ),
580 [ 'oldid' => $firstRev->getId() ]
587 $pageInfo['header-edits'][] = [
588 $this->msg( 'pageinfo-lastuser' ),
589 Linker
::revUserTools( $lastRev )
592 // Date of latest edit
593 $pageInfo['header-edits'][] = [
594 $this->msg( 'pageinfo-lasttime' ),
595 $linkRenderer->makeKnownLink(
597 $lang->userTimeAndDate( $this->page
->getTimestamp(), $user ),
599 [ 'oldid' => $this->page
->getLatest() ]
604 // Total number of edits
605 $pageInfo['header-edits'][] = [
606 $this->msg( 'pageinfo-edits' ), $lang->formatNum( $pageCounts['edits'] )
609 // Total number of distinct authors
610 if ( $pageCounts['authors'] > 0 ) {
611 $pageInfo['header-edits'][] = [
612 $this->msg( 'pageinfo-authors' ), $lang->formatNum( $pageCounts['authors'] )
616 // Recent number of edits (within past 30 days)
617 $pageInfo['header-edits'][] = [
618 $this->msg( 'pageinfo-recent-edits',
619 $lang->formatDuration( $config->get( 'RCMaxAge' ) ) ),
620 $lang->formatNum( $pageCounts['recent_edits'] )
623 // Recent number of distinct authors
624 $pageInfo['header-edits'][] = [
625 $this->msg( 'pageinfo-recent-authors' ),
626 $lang->formatNum( $pageCounts['recent_authors'] )
629 // Array of MagicWord objects
630 $magicWords = $services->getMagicWordFactory()->getDoubleUnderscoreArray();
632 // Array of magic word IDs
633 $wordIDs = $magicWords->names
;
635 // Array of IDs => localized magic words
636 $localizedWords = $services->getContentLanguage()->getMagicWords();
639 foreach ( $pageProperties as $property => $value ) {
640 if ( in_array( $property, $wordIDs ) ) {
641 $listItems[] = Html
::element( 'li', [], $localizedWords[$property][1] );
645 $localizedList = Html
::rawElement( 'ul', [], implode( '', $listItems ) );
646 $hiddenCategories = $this->page
->getHiddenCategories();
649 count( $listItems ) > 0 ||
650 count( $hiddenCategories ) > 0 ||
651 $pageCounts['transclusion']['from'] > 0 ||
652 $pageCounts['transclusion']['to'] > 0
654 $options = [ 'LIMIT' => $config->get( 'PageInfoTransclusionLimit' ) ];
655 $transcludedTemplates = $title->getTemplateLinksFrom( $options );
656 if ( $config->get( 'MiserMode' ) ) {
657 $transcludedTargets = [];
659 $transcludedTargets = $title->getTemplateLinksTo( $options );
663 $pageInfo['header-properties'] = [];
666 if ( count( $listItems ) > 0 ) {
667 $pageInfo['header-properties'][] = [
668 $this->msg( 'pageinfo-magic-words' )->numParams( count( $listItems ) ),
674 if ( count( $hiddenCategories ) > 0 ) {
675 $pageInfo['header-properties'][] = [
676 $this->msg( 'pageinfo-hidden-categories' )
677 ->numParams( count( $hiddenCategories ) ),
678 Linker
::formatHiddenCategories( $hiddenCategories )
682 // Transcluded templates
683 if ( $pageCounts['transclusion']['from'] > 0 ) {
684 if ( $pageCounts['transclusion']['from'] > count( $transcludedTemplates ) ) {
685 $more = $this->msg( 'morenotlisted' )->escaped();
690 $templateListFormatter = new TemplatesOnThisPageFormatter(
695 $pageInfo['header-properties'][] = [
696 $this->msg( 'pageinfo-templates' )
697 ->numParams( $pageCounts['transclusion']['from'] ),
698 $templateListFormatter->format( $transcludedTemplates, false, $more )
702 if ( !$config->get( 'MiserMode' ) && $pageCounts['transclusion']['to'] > 0 ) {
703 if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) {
704 $more = $linkRenderer->makeLink(
706 $this->msg( 'moredotdotdot' )->text(),
708 [ 'hidelinks' => 1, 'hideredirs' => 1 ]
714 $templateListFormatter = new TemplatesOnThisPageFormatter(
719 $pageInfo['header-properties'][] = [
720 $this->msg( 'pageinfo-transclusions' )
721 ->numParams( $pageCounts['transclusion']['to'] ),
722 $templateListFormatter->format( $transcludedTargets, false, $more )
731 * Returns page counts that would be too "expensive" to retrieve by normal means.
733 * @param WikiPage|Article|Page $page
736 protected function pageCounts( Page
$page ) {
738 $config = $this->context
->getConfig();
739 $services = MediaWikiServices
::getInstance();
740 $cache = $services->getMainWANObjectCache();
742 return $cache->getWithSetCallback(
743 self
::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ),
744 WANObjectCache
::TTL_WEEK
,
745 function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname, $services ) {
746 global $wgActorTableSchemaMigrationStage;
748 $title = $page->getTitle();
749 $id = $title->getArticleID();
751 $dbr = wfGetDB( DB_REPLICA
);
752 $dbrWatchlist = wfGetDB( DB_REPLICA
, 'watchlist' );
753 $setOpts +
= Database
::getCacheSetOptions( $dbr, $dbrWatchlist );
755 if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_READ_NEW
) {
756 $tables = [ 'revision_actor_temp' ];
757 $field = 'revactor_actor';
758 $pageField = 'revactor_page';
759 $tsField = 'revactor_timestamp';
762 $tables = [ 'revision' ];
763 $field = 'rev_user_text';
764 $pageField = 'rev_page';
765 $tsField = 'rev_timestamp';
769 $watchedItemStore = $services->getWatchedItemStore();
772 $result['watchers'] = $watchedItemStore->countWatchers( $title );
774 if ( $config->get( 'ShowUpdatedMarker' ) ) {
775 $updated = wfTimestamp( TS_UNIX
, $page->getTimestamp() );
776 $result['visitingWatchers'] = $watchedItemStore->countVisitingWatchers(
778 $updated - $config->get( 'WatchersMaxAge' )
782 // Total number of edits
783 $edits = (int)$dbr->selectField(
786 [ 'rev_page' => $id ],
789 $result['edits'] = $edits;
791 // Total number of distinct authors
792 if ( $config->get( 'MiserMode' ) ) {
793 $result['authors'] = 0;
795 $result['authors'] = (int)$dbr->selectField(
797 "COUNT(DISTINCT $field)",
798 [ $pageField => $id ],
805 // "Recent" threshold defined by RCMaxAge setting
806 $threshold = $dbr->timestamp( time() - $config->get( 'RCMaxAge' ) );
808 // Recent number of edits
809 $edits = (int)$dbr->selectField(
814 "rev_timestamp >= " . $dbr->addQuotes( $threshold )
818 $result['recent_edits'] = $edits;
820 // Recent number of distinct authors
821 $result['recent_authors'] = (int)$dbr->selectField(
823 "COUNT(DISTINCT $field)",
826 "$tsField >= " . $dbr->addQuotes( $threshold )
833 // Subpages (if enabled)
834 if ( $services->getNamespaceInfo()->hasSubpages( $title->getNamespace() ) ) {
835 $conds = [ 'page_namespace' => $title->getNamespace() ];
836 $conds[] = 'page_title ' .
837 $dbr->buildLike( $title->getDBkey() . '/', $dbr->anyString() );
839 // Subpages of this page (redirects)
840 $conds['page_is_redirect'] = 1;
841 $result['subpages']['redirects'] = (int)$dbr->selectField(
848 // Subpages of this page (non-redirects)
849 $conds['page_is_redirect'] = 0;
850 $result['subpages']['nonredirects'] = (int)$dbr->selectField(
857 // Subpages of this page (total)
858 $result['subpages']['total'] = $result['subpages']['redirects']
859 +
$result['subpages']['nonredirects'];
862 // Counts for the number of transclusion links (to/from)
863 if ( $config->get( 'MiserMode' ) ) {
864 $result['transclusion']['to'] = 0;
866 $result['transclusion']['to'] = (int)$dbr->selectField(
870 'tl_namespace' => $title->getNamespace(),
871 'tl_title' => $title->getDBkey()
877 $result['transclusion']['from'] = (int)$dbr->selectField(
880 [ 'tl_from' => $title->getArticleID() ],
890 * Returns the name that goes in the "<h1>" page title.
894 protected function getPageTitle() {
895 return $this->msg( 'pageinfo-title', $this->getTitle()->getPrefixedText() )->text();
899 * Get a list of contributors of $article
900 * @return string Html
902 protected function getContributors() {
903 $contributors = $this->page
->getContributors();
907 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
909 # Sift for real versus user names
910 /** @var User $user */
911 foreach ( $contributors as $user ) {
912 $page = $user->isAnon()
913 ? SpecialPage
::getTitleFor( 'Contributions', $user->getName() )
914 : $user->getUserPage();
916 $hiddenPrefs = $this->context
->getConfig()->get( 'HiddenPrefs' );
917 if ( $user->getId() == 0 ) {
918 $anon_ips[] = $linkRenderer->makeLink( $page, $user->getName() );
919 } elseif ( !in_array( 'realname', $hiddenPrefs ) && $user->getRealName() ) {
920 $real_names[] = $linkRenderer->makeLink( $page, $user->getRealName() );
922 $user_names[] = $linkRenderer->makeLink( $page, $user->getName() );
926 $lang = $this->getLanguage();
928 $real = $lang->listToText( $real_names );
930 # "ThisSite user(s) A, B and C"
931 if ( count( $user_names ) ) {
932 $user = $this->msg( 'siteusers' )
933 ->rawParams( $lang->listToText( $user_names ) )
934 ->params( count( $user_names ) )->escaped();
939 if ( count( $anon_ips ) ) {
940 $anon = $this->msg( 'anonusers' )
941 ->rawParams( $lang->listToText( $anon_ips ) )
942 ->params( count( $anon_ips ) )->escaped();
947 # This is the big list, all mooshed together. We sift for blank strings
949 foreach ( [ $real, $user, $anon ] as $s ) {
951 array_push( $fulllist, $s );
955 $count = count( $fulllist );
957 # "Based on work by ..."
959 ?
$this->msg( 'othercontribs' )->rawParams(
960 $lang->listToText( $fulllist ) )->params( $count )->escaped()
965 * Returns the description that goes below the "<h1>" tag.
969 protected function getDescription() {
974 * @param WANObjectCache $cache
975 * @param Title $title
979 protected static function getCacheKey( WANObjectCache
$cache, Title
$title, $revId ) {
980 return $cache->makeKey( 'infoaction', md5( $title->getPrefixedText() ), $revId, self
::VERSION
);