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 Wikimedia\Rdbms\Database
;
29 * Displays information about a page.
33 class InfoAction
extends FormlessAction
{
37 * Returns the name of the action this object responds to.
39 * @return string Lowercase name
41 public function getName() {
46 * Whether this action can still be executed by a blocked user.
50 public function requiresUnblock() {
55 * Whether this action requires the wiki not to be locked.
59 public function requiresWrite() {
64 * Clear the info cache for a given Title.
67 * @param Title $title Title to clear cache for
68 * @param int|null $revid Revision id to clear
70 public static function invalidateCache( Title
$title, $revid = null ) {
72 $revision = Revision
::newFromTitle( $title, 0, Revision
::READ_LATEST
);
73 $revid = $revision ?
$revision->getId() : null;
75 if ( $revid !== null ) {
76 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
77 $key = self
::getCacheKey( $cache, $title, $revid );
78 $cache->delete( $key );
83 * Shows page information on GET request.
85 * @return string Page information that will be added to the output
87 public function onView() {
91 $oldid = $this->page
->getOldID();
93 $revision = $this->page
->getRevisionFetched();
95 // Revision is missing
96 if ( $revision === null ) {
97 return $this->msg( 'missing-revision', $oldid )->parse();
100 // Revision is not current
101 if ( !$revision->isCurrent() ) {
102 return $this->msg( 'pageinfo-not-current' )->plain();
107 $this->addHelpLink( 'Page information' );
110 if ( !$this->msg( 'pageinfo-header' )->isDisabled() ) {
111 $content .= $this->msg( 'pageinfo-header' )->parse();
114 // Hide "This page is a member of # hidden categories" explanation
115 $content .= Html
::element( 'style', [],
116 '.mw-hiddenCategoriesExplanation { display: none; }' ) . "\n";
118 // Hide "Templates used on this page" explanation
119 $content .= Html
::element( 'style', [],
120 '.mw-templatesUsedExplanation { display: none; }' ) . "\n";
122 // Get page information
123 $pageInfo = $this->pageInfo();
125 // Allow extensions to add additional information
126 Hooks
::run( 'InfoAction', [ $this->getContext(), &$pageInfo ] );
128 // Render page information
129 foreach ( $pageInfo as $header => $infoTable ) {
131 // pageinfo-header-basic, pageinfo-header-edits, pageinfo-header-restrictions,
132 // pageinfo-header-properties, pageinfo-category-info
133 $content .= $this->makeHeader(
134 $this->msg( "pageinfo-${header}" )->text(),
135 "mw-pageinfo-${header}"
139 foreach ( $infoTable as $infoRow ) {
140 if ( $infoRow[0] == "below" ) {
141 $below = $infoRow[1] . "\n";
144 $name = ( $infoRow[0] instanceof Message
) ?
$infoRow[0]->escaped() : $infoRow[0];
145 $value = ( $infoRow[1] instanceof Message
) ?
$infoRow[1]->escaped() : $infoRow[1];
146 $id = ( $infoRow[0] instanceof Message
) ?
$infoRow[0]->getKey() : null;
147 $table = $this->addRow( $table, $name, $value, $id ) . "\n";
149 $content = $this->addTable( $content, $table ) . "\n" . $below;
153 if ( !$this->msg( 'pageinfo-footer' )->isDisabled() ) {
154 $content .= $this->msg( 'pageinfo-footer' )->parse();
161 * Creates a header that can be added to the output.
163 * @param string $header The header text.
164 * @param string $canonicalId
165 * @return string The HTML.
167 protected function makeHeader( $header, $canonicalId ) {
168 $spanAttribs = [ 'class' => 'mw-headline', 'id' => Sanitizer
::escapeIdForAttribute( $header ) ];
169 $h2Attribs = [ 'id' => Sanitizer
::escapeIdForAttribute( $canonicalId ) ];
171 return Html
::rawElement( 'h2', $h2Attribs, Html
::element( 'span', $spanAttribs, $header ) );
175 * Adds a row to a table that will be added to the content.
177 * @param string $table The table that will be added to the content
178 * @param string $name The name of the row
179 * @param string $value The value of the row
180 * @param string|null $id The ID to use for the 'tr' element
181 * @return string The table with the row added
183 protected function addRow( $table, $name, $value, $id ) {
187 $id === null ?
[] : [ 'id' => 'mw-' . $id ],
188 Html
::rawElement( 'td', [ 'style' => 'vertical-align: top;' ], $name ) .
189 Html
::rawElement( 'td', [], $value )
194 * Adds a table to the content that will be added to the output.
196 * @param string $content The content that will be added to the output
197 * @param string $table
198 * @return string The content with the table added
200 protected function addTable( $content, $table ) {
201 return $content . Html
::rawElement( 'table', [ 'class' => 'wikitable mw-page-info' ],
206 * Returns an array of info groups (will be rendered as tables), keyed by group ID.
207 * Group IDs are arbitrary and used so that extensions may add additional information in
208 * arbitrary positions (and as message keys for section headers for the tables, prefixed
210 * Each info group is a non-associative array of info items (rendered as table rows).
211 * Each info item is an array with two elements: the first describes the type of
212 * information, the second the value for the current page. Both can be strings (will be
213 * interpreted as raw HTML) or messages (will be interpreted as plain text and escaped).
217 protected function pageInfo() {
218 $services = MediaWikiServices
::getInstance();
220 $user = $this->getUser();
221 $lang = $this->getLanguage();
222 $title = $this->getTitle();
223 $id = $title->getArticleID();
224 $config = $this->context
->getConfig();
225 $linkRenderer = $services->getLinkRenderer();
227 $pageCounts = $this->pageCounts( $this->page
);
229 $props = PageProps
::getInstance()->getAllProperties( $title );
230 $pageProperties = $props[$id] ??
[];
234 $pageInfo['header-basic'] = [];
237 $displayTitle = $pageProperties['displaytitle'] ??
$title->getPrefixedText();
239 $pageInfo['header-basic'][] = [
240 $this->msg( 'pageinfo-display-title' ), $displayTitle
243 // Is it a redirect? If so, where to?
244 $redirectTarget = $this->page
->getRedirectTarget();
245 if ( $redirectTarget !== null ) {
246 $pageInfo['header-basic'][] = [
247 $this->msg( 'pageinfo-redirectsto' ),
248 $linkRenderer->makeLink( $redirectTarget ) .
249 $this->msg( 'word-separator' )->escaped() .
250 $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
252 $this->msg( 'pageinfo-redirectsto-info' )->text(),
254 [ 'action' => 'info' ]
260 $sortKey = $pageProperties['defaultsort'] ??
$title->getCategorySortkey();
262 $sortKey = htmlspecialchars( $sortKey );
263 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-default-sort' ), $sortKey ];
265 // Page length (in bytes)
266 $pageInfo['header-basic'][] = [
267 $this->msg( 'pageinfo-length' ), $lang->formatNum( $title->getLength() )
271 $pageNamespace = $title->getNsText();
272 if ( $pageNamespace ) {
273 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-namespace' ), $pageNamespace ];
276 // Page ID (number not localised, as it's a database ID)
277 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-article-id' ), $id ];
279 // Language in which the page content is (supposed to be) written
280 $pageLang = $title->getPageLanguage()->getCode();
282 $permissionManager = MediaWikiServices
::getInstance()->getPermissionManager();
284 $pageLangHtml = $pageLang . ' - ' .
285 Language
::fetchLanguageName( $pageLang, $lang->getCode() );
286 // Link to Special:PageLanguage with pre-filled page title if user has permissions
287 if ( $config->get( 'PageLanguageUseDB' )
288 && $permissionManager->userCan( 'pagelang', $user, $title )
290 $pageLangHtml .= ' ' . $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
291 SpecialPage
::getTitleValueFor( 'PageLanguage', $title->getPrefixedText() ),
292 $this->msg( 'pageinfo-language-change' )->text()
296 $pageInfo['header-basic'][] = [
297 $this->msg( 'pageinfo-language' )->escaped(),
301 // Content model of the page
302 $modelHtml = htmlspecialchars( ContentHandler
::getLocalizedName( $title->getContentModel() ) );
303 // If the user can change it, add a link to Special:ChangeContentModel
304 if ( $config->get( 'ContentHandlerUseDB' )
305 && $permissionManager->userCan( 'editcontentmodel', $user, $title )
307 $modelHtml .= ' ' . $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
308 SpecialPage
::getTitleValueFor( 'ChangeContentModel', $title->getPrefixedText() ),
309 $this->msg( 'pageinfo-content-model-change' )->text()
313 $pageInfo['header-basic'][] = [
314 $this->msg( 'pageinfo-content-model' ),
318 if ( $title->inNamespace( NS_USER
) ) {
319 $pageUser = User
::newFromName( $title->getRootText() );
320 if ( $pageUser && $pageUser->getId() && !$pageUser->isHidden() ) {
321 $pageInfo['header-basic'][] = [
322 $this->msg( 'pageinfo-user-id' ),
328 // Search engine status
329 $pOutput = new ParserOutput();
330 if ( isset( $pageProperties['noindex'] ) ) {
331 $pOutput->setIndexPolicy( 'noindex' );
333 if ( isset( $pageProperties['index'] ) ) {
334 $pOutput->setIndexPolicy( 'index' );
337 // Use robot policy logic
338 $policy = $this->page
->getRobotPolicy( 'view', $pOutput );
339 $pageInfo['header-basic'][] = [
340 // Messages: pageinfo-robot-index, pageinfo-robot-noindex
341 $this->msg( 'pageinfo-robot-policy' ),
342 $this->msg( "pageinfo-robot-${policy['index']}" )
345 $unwatchedPageThreshold = $config->get( 'UnwatchedPageThreshold' );
347 $user->isAllowed( 'unwatchedpages' ) ||
348 ( $unwatchedPageThreshold !== false &&
349 $pageCounts['watchers'] >= $unwatchedPageThreshold )
351 // Number of page watchers
352 $pageInfo['header-basic'][] = [
353 $this->msg( 'pageinfo-watchers' ),
354 $lang->formatNum( $pageCounts['watchers'] )
357 $config->get( 'ShowUpdatedMarker' ) &&
358 isset( $pageCounts['visitingWatchers'] )
360 $minToDisclose = $config->get( 'UnwatchedPageSecret' );
361 if ( $pageCounts['visitingWatchers'] > $minToDisclose ||
362 $user->isAllowed( 'unwatchedpages' ) ) {
363 $pageInfo['header-basic'][] = [
364 $this->msg( 'pageinfo-visiting-watchers' ),
365 $lang->formatNum( $pageCounts['visitingWatchers'] )
368 $pageInfo['header-basic'][] = [
369 $this->msg( 'pageinfo-visiting-watchers' ),
370 $this->msg( 'pageinfo-few-visiting-watchers' )
374 } elseif ( $unwatchedPageThreshold !== false ) {
375 $pageInfo['header-basic'][] = [
376 $this->msg( 'pageinfo-watchers' ),
377 $this->msg( 'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
381 // Redirects to this page
382 $whatLinksHere = SpecialPage
::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
383 $pageInfo['header-basic'][] = [
384 $linkRenderer->makeLink(
386 $this->msg( 'pageinfo-redirects-name' )->text(),
391 'hideimages' => $title->getNamespace() == NS_FILE
394 $this->msg( 'pageinfo-redirects-value' )
395 ->numParams( count( $title->getRedirectsHere() ) )
398 // Is it counted as a content page?
399 if ( $this->page
->isCountable() ) {
400 $pageInfo['header-basic'][] = [
401 $this->msg( 'pageinfo-contentpage' ),
402 $this->msg( 'pageinfo-contentpage-yes' )
406 // Subpages of this page, if subpages are enabled for the current NS
407 if ( $services->getNamespaceInfo()->hasSubpages( $title->getNamespace() ) ) {
408 $prefixIndex = SpecialPage
::getTitleFor(
409 'Prefixindex', $title->getPrefixedText() . '/' );
410 $pageInfo['header-basic'][] = [
411 $linkRenderer->makeLink(
413 $this->msg( 'pageinfo-subpages-name' )->text()
415 $this->msg( 'pageinfo-subpages-value' )
417 $pageCounts['subpages']['total'],
418 $pageCounts['subpages']['redirects'],
419 $pageCounts['subpages']['nonredirects'] )
423 if ( $title->inNamespace( NS_CATEGORY
) ) {
424 $category = Category
::newFromTitle( $title );
426 // $allCount is the total number of cat members,
427 // not the count of how many members are normal pages.
428 $allCount = (int)$category->getPageCount();
429 $subcatCount = (int)$category->getSubcatCount();
430 $fileCount = (int)$category->getFileCount();
431 $pagesCount = $allCount - $subcatCount - $fileCount;
433 $pageInfo['category-info'] = [
435 $this->msg( 'pageinfo-category-total' ),
436 $lang->formatNum( $allCount )
439 $this->msg( 'pageinfo-category-pages' ),
440 $lang->formatNum( $pagesCount )
443 $this->msg( 'pageinfo-category-subcats' ),
444 $lang->formatNum( $subcatCount )
447 $this->msg( 'pageinfo-category-files' ),
448 $lang->formatNum( $fileCount )
453 // Display image SHA-1 value
454 if ( $title->inNamespace( NS_FILE
) ) {
455 $fileObj = $services->getRepoGroup()->findFile( $title );
456 if ( $fileObj !== false ) {
457 // Convert the base-36 sha1 value obtained from database to base-16
458 $output = Wikimedia\base_convert
( $fileObj->getSha1(), 36, 16, 40 );
459 $pageInfo['header-basic'][] = [
460 $this->msg( 'pageinfo-file-hash' ),
467 $pageInfo['header-restrictions'] = [];
469 // Is this page affected by the cascading protection of something which includes it?
470 if ( $title->isCascadeProtected() ) {
472 $sources = $title->getCascadeProtectionSources()[0];
474 foreach ( $sources as $sourceTitle ) {
475 $cascadingFrom .= Html
::rawElement(
476 'li', [], $linkRenderer->makeKnownLink( $sourceTitle ) );
479 $cascadingFrom = Html
::rawElement( 'ul', [], $cascadingFrom );
480 $pageInfo['header-restrictions'][] = [
481 $this->msg( 'pageinfo-protect-cascading-from' ),
486 // Is out protection set to cascade to other pages?
487 if ( $title->areRestrictionsCascading() ) {
488 $pageInfo['header-restrictions'][] = [
489 $this->msg( 'pageinfo-protect-cascading' ),
490 $this->msg( 'pageinfo-protect-cascading-yes' )
495 foreach ( $title->getRestrictionTypes() as $restrictionType ) {
496 $protectionLevel = implode( ', ', $title->getRestrictions( $restrictionType ) );
498 if ( $protectionLevel == '' ) {
500 $message = $this->msg( 'protect-default' )->escaped();
502 // Administrators only
503 // Messages: protect-level-autoconfirmed, protect-level-sysop
504 $message = $this->msg( "protect-level-$protectionLevel" );
505 if ( $message->isDisabled() ) {
506 // Require "$1" permission
507 $message = $this->msg( "protect-fallback", $protectionLevel )->parse();
509 $message = $message->escaped();
512 $expiry = $title->getRestrictionExpiry( $restrictionType );
513 $formattedexpiry = $this->msg( 'parentheses',
514 $lang->formatExpiry( $expiry ) )->escaped();
515 $message .= $this->msg( 'word-separator' )->escaped() . $formattedexpiry;
517 // Messages: restriction-edit, restriction-move, restriction-create,
518 // restriction-upload
519 $pageInfo['header-restrictions'][] = [
520 $this->msg( "restriction-$restrictionType" ), $message
523 $protectLog = SpecialPage
::getTitleFor( 'Log' );
524 $pageInfo['header-restrictions'][] = [
526 $linkRenderer->makeKnownLink(
528 $this->msg( 'pageinfo-view-protect-log' )->text(),
530 [ 'type' => 'protect', 'page' => $title->getPrefixedText() ]
534 if ( !$this->page
->exists() ) {
539 $pageInfo['header-edits'] = [];
541 $firstRev = $this->page
->getOldestRevision();
542 $lastRev = $this->page
->getRevision();
543 $batch = new LinkBatch
;
546 $firstRevUser = $firstRev->getUserText( Revision
::FOR_THIS_USER
);
547 if ( $firstRevUser !== '' ) {
548 $firstRevUserTitle = Title
::makeTitle( NS_USER
, $firstRevUser );
549 $batch->addObj( $firstRevUserTitle );
550 $batch->addObj( $firstRevUserTitle->getTalkPage() );
555 $lastRevUser = $lastRev->getUserText( Revision
::FOR_THIS_USER
);
556 if ( $lastRevUser !== '' ) {
557 $lastRevUserTitle = Title
::makeTitle( NS_USER
, $lastRevUser );
558 $batch->addObj( $lastRevUserTitle );
559 $batch->addObj( $lastRevUserTitle->getTalkPage() );
567 $pageInfo['header-edits'][] = [
568 $this->msg( 'pageinfo-firstuser' ),
569 Linker
::revUserTools( $firstRev )
572 // Date of page creation
573 $pageInfo['header-edits'][] = [
574 $this->msg( 'pageinfo-firsttime' ),
575 $linkRenderer->makeKnownLink(
577 $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ),
579 [ 'oldid' => $firstRev->getId() ]
586 $pageInfo['header-edits'][] = [
587 $this->msg( 'pageinfo-lastuser' ),
588 Linker
::revUserTools( $lastRev )
591 // Date of latest edit
592 $pageInfo['header-edits'][] = [
593 $this->msg( 'pageinfo-lasttime' ),
594 $linkRenderer->makeKnownLink(
596 $lang->userTimeAndDate( $this->page
->getTimestamp(), $user ),
598 [ 'oldid' => $this->page
->getLatest() ]
603 // Total number of edits
604 $pageInfo['header-edits'][] = [
605 $this->msg( 'pageinfo-edits' ), $lang->formatNum( $pageCounts['edits'] )
608 // Total number of distinct authors
609 if ( $pageCounts['authors'] > 0 ) {
610 $pageInfo['header-edits'][] = [
611 $this->msg( 'pageinfo-authors' ), $lang->formatNum( $pageCounts['authors'] )
615 // Recent number of edits (within past 30 days)
616 $pageInfo['header-edits'][] = [
617 $this->msg( 'pageinfo-recent-edits',
618 $lang->formatDuration( $config->get( 'RCMaxAge' ) ) ),
619 $lang->formatNum( $pageCounts['recent_edits'] )
622 // Recent number of distinct authors
623 $pageInfo['header-edits'][] = [
624 $this->msg( 'pageinfo-recent-authors' ),
625 $lang->formatNum( $pageCounts['recent_authors'] )
628 // Array of MagicWord objects
629 $magicWords = $services->getMagicWordFactory()->getDoubleUnderscoreArray();
631 // Array of magic word IDs
632 $wordIDs = $magicWords->names
;
634 // Array of IDs => localized magic words
635 $localizedWords = $services->getContentLanguage()->getMagicWords();
638 foreach ( $pageProperties as $property => $value ) {
639 if ( in_array( $property, $wordIDs ) ) {
640 $listItems[] = Html
::element( 'li', [], $localizedWords[$property][1] );
644 $localizedList = Html
::rawElement( 'ul', [], implode( '', $listItems ) );
645 $hiddenCategories = $this->page
->getHiddenCategories();
648 count( $listItems ) > 0 ||
649 count( $hiddenCategories ) > 0 ||
650 $pageCounts['transclusion']['from'] > 0 ||
651 $pageCounts['transclusion']['to'] > 0
653 $options = [ 'LIMIT' => $config->get( 'PageInfoTransclusionLimit' ) ];
654 $transcludedTemplates = $title->getTemplateLinksFrom( $options );
655 if ( $config->get( 'MiserMode' ) ) {
656 $transcludedTargets = [];
658 $transcludedTargets = $title->getTemplateLinksTo( $options );
662 $pageInfo['header-properties'] = [];
665 if ( count( $listItems ) > 0 ) {
666 $pageInfo['header-properties'][] = [
667 $this->msg( 'pageinfo-magic-words' )->numParams( count( $listItems ) ),
673 if ( count( $hiddenCategories ) > 0 ) {
674 $pageInfo['header-properties'][] = [
675 $this->msg( 'pageinfo-hidden-categories' )
676 ->numParams( count( $hiddenCategories ) ),
677 Linker
::formatHiddenCategories( $hiddenCategories )
681 // Transcluded templates
682 if ( $pageCounts['transclusion']['from'] > 0 ) {
683 if ( $pageCounts['transclusion']['from'] > count( $transcludedTemplates ) ) {
684 $more = $this->msg( 'morenotlisted' )->escaped();
689 $templateListFormatter = new TemplatesOnThisPageFormatter(
694 $pageInfo['header-properties'][] = [
695 $this->msg( 'pageinfo-templates' )
696 ->numParams( $pageCounts['transclusion']['from'] ),
697 $templateListFormatter->format( $transcludedTemplates, false, $more )
701 if ( !$config->get( 'MiserMode' ) && $pageCounts['transclusion']['to'] > 0 ) {
702 if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) {
703 $more = $linkRenderer->makeLink(
705 $this->msg( 'moredotdotdot' )->text(),
707 [ 'hidelinks' => 1, 'hideredirs' => 1 ]
713 $templateListFormatter = new TemplatesOnThisPageFormatter(
718 $pageInfo['header-properties'][] = [
719 $this->msg( 'pageinfo-transclusions' )
720 ->numParams( $pageCounts['transclusion']['to'] ),
721 $templateListFormatter->format( $transcludedTargets, false, $more )
730 * Returns page counts that would be too "expensive" to retrieve by normal means.
732 * @param WikiPage|Article|Page $page
735 protected function pageCounts( Page
$page ) {
737 $config = $this->context
->getConfig();
738 $services = MediaWikiServices
::getInstance();
739 $cache = $services->getMainWANObjectCache();
741 return $cache->getWithSetCallback(
742 self
::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ),
743 WANObjectCache
::TTL_WEEK
,
744 function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname, $services ) {
745 global $wgActorTableSchemaMigrationStage;
747 $title = $page->getTitle();
748 $id = $title->getArticleID();
750 $dbr = wfGetDB( DB_REPLICA
);
751 $dbrWatchlist = wfGetDB( DB_REPLICA
, 'watchlist' );
752 $setOpts +
= Database
::getCacheSetOptions( $dbr, $dbrWatchlist );
754 if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_READ_NEW
) {
755 $tables = [ 'revision_actor_temp' ];
756 $field = 'revactor_actor';
757 $pageField = 'revactor_page';
758 $tsField = 'revactor_timestamp';
761 $tables = [ 'revision' ];
762 $field = 'rev_user_text';
763 $pageField = 'rev_page';
764 $tsField = 'rev_timestamp';
768 $watchedItemStore = $services->getWatchedItemStore();
771 $result['watchers'] = $watchedItemStore->countWatchers( $title );
773 if ( $config->get( 'ShowUpdatedMarker' ) ) {
774 $updated = wfTimestamp( TS_UNIX
, $page->getTimestamp() );
775 $result['visitingWatchers'] = $watchedItemStore->countVisitingWatchers(
777 $updated - $config->get( 'WatchersMaxAge' )
781 // Total number of edits
782 $edits = (int)$dbr->selectField(
785 [ 'rev_page' => $id ],
788 $result['edits'] = $edits;
790 // Total number of distinct authors
791 if ( $config->get( 'MiserMode' ) ) {
792 $result['authors'] = 0;
794 $result['authors'] = (int)$dbr->selectField(
796 "COUNT(DISTINCT $field)",
797 [ $pageField => $id ],
804 // "Recent" threshold defined by RCMaxAge setting
805 $threshold = $dbr->timestamp( time() - $config->get( 'RCMaxAge' ) );
807 // Recent number of edits
808 $edits = (int)$dbr->selectField(
813 "rev_timestamp >= " . $dbr->addQuotes( $threshold )
817 $result['recent_edits'] = $edits;
819 // Recent number of distinct authors
820 $result['recent_authors'] = (int)$dbr->selectField(
822 "COUNT(DISTINCT $field)",
825 "$tsField >= " . $dbr->addQuotes( $threshold )
832 // Subpages (if enabled)
833 if ( $services->getNamespaceInfo()->hasSubpages( $title->getNamespace() ) ) {
834 $conds = [ 'page_namespace' => $title->getNamespace() ];
835 $conds[] = 'page_title ' .
836 $dbr->buildLike( $title->getDBkey() . '/', $dbr->anyString() );
838 // Subpages of this page (redirects)
839 $conds['page_is_redirect'] = 1;
840 $result['subpages']['redirects'] = (int)$dbr->selectField(
847 // Subpages of this page (non-redirects)
848 $conds['page_is_redirect'] = 0;
849 $result['subpages']['nonredirects'] = (int)$dbr->selectField(
856 // Subpages of this page (total)
857 $result['subpages']['total'] = $result['subpages']['redirects']
858 +
$result['subpages']['nonredirects'];
861 // Counts for the number of transclusion links (to/from)
862 if ( $config->get( 'MiserMode' ) ) {
863 $result['transclusion']['to'] = 0;
865 $result['transclusion']['to'] = (int)$dbr->selectField(
869 'tl_namespace' => $title->getNamespace(),
870 'tl_title' => $title->getDBkey()
876 $result['transclusion']['from'] = (int)$dbr->selectField(
879 [ 'tl_from' => $title->getArticleID() ],
889 * Returns the name that goes in the "<h1>" page title.
893 protected function getPageTitle() {
894 return $this->msg( 'pageinfo-title', $this->getTitle()->getPrefixedText() )->text();
898 * Get a list of contributors of $article
899 * @return string Html
901 protected function getContributors() {
902 $contributors = $this->page
->getContributors();
906 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
908 # Sift for real versus user names
909 /** @var User $user */
910 foreach ( $contributors as $user ) {
911 $page = $user->isAnon()
912 ? SpecialPage
::getTitleFor( 'Contributions', $user->getName() )
913 : $user->getUserPage();
915 $hiddenPrefs = $this->context
->getConfig()->get( 'HiddenPrefs' );
916 if ( $user->getId() == 0 ) {
917 $anon_ips[] = $linkRenderer->makeLink( $page, $user->getName() );
918 } elseif ( !in_array( 'realname', $hiddenPrefs ) && $user->getRealName() ) {
919 $real_names[] = $linkRenderer->makeLink( $page, $user->getRealName() );
921 $user_names[] = $linkRenderer->makeLink( $page, $user->getName() );
925 $lang = $this->getLanguage();
927 $real = $lang->listToText( $real_names );
929 # "ThisSite user(s) A, B and C"
930 if ( count( $user_names ) ) {
931 $user = $this->msg( 'siteusers' )
932 ->rawParams( $lang->listToText( $user_names ) )
933 ->params( count( $user_names ) )->escaped();
938 if ( count( $anon_ips ) ) {
939 $anon = $this->msg( 'anonusers' )
940 ->rawParams( $lang->listToText( $anon_ips ) )
941 ->params( count( $anon_ips ) )->escaped();
946 # This is the big list, all mooshed together. We sift for blank strings
948 foreach ( [ $real, $user, $anon ] as $s ) {
950 array_push( $fulllist, $s );
954 $count = count( $fulllist );
956 # "Based on work by ..."
958 ?
$this->msg( 'othercontribs' )->rawParams(
959 $lang->listToText( $fulllist ) )->params( $count )->escaped()
964 * Returns the description that goes below the "<h1>" tag.
968 protected function getDescription() {
973 * @param WANObjectCache $cache
974 * @param Title $title
978 protected static function getCacheKey( WANObjectCache
$cache, Title
$title, $revId ) {
979 return $cache->makeKey( 'infoaction', md5( $title->getPrefixedText() ), $revId, self
::VERSION
);