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 if ( !$this->msg( 'pageinfo-header' )->isDisabled() ) {
108 $content .= $this->msg( 'pageinfo-header' )->parse();
111 // Hide "This page is a member of # hidden categories" explanation
112 $content .= Html
::element( 'style', [],
113 '.mw-hiddenCategoriesExplanation { display: none; }' ) . "\n";
115 // Hide "Templates used on this page" explanation
116 $content .= Html
::element( 'style', [],
117 '.mw-templatesUsedExplanation { display: none; }' ) . "\n";
119 // Get page information
120 $pageInfo = $this->pageInfo();
122 // Allow extensions to add additional information
123 Hooks
::run( 'InfoAction', [ $this->getContext(), &$pageInfo ] );
125 // Render page information
126 foreach ( $pageInfo as $header => $infoTable ) {
128 // pageinfo-header-basic, pageinfo-header-edits, pageinfo-header-restrictions,
129 // pageinfo-header-properties, pageinfo-category-info
130 $content .= $this->makeHeader(
131 $this->msg( "pageinfo-${header}" )->text(),
132 "mw-pageinfo-${header}"
135 foreach ( $infoTable as $infoRow ) {
136 $name = ( $infoRow[0] instanceof Message
) ?
$infoRow[0]->escaped() : $infoRow[0];
137 $value = ( $infoRow[1] instanceof Message
) ?
$infoRow[1]->escaped() : $infoRow[1];
138 $id = ( $infoRow[0] instanceof Message
) ?
$infoRow[0]->getKey() : null;
139 $table = $this->addRow( $table, $name, $value, $id ) . "\n";
141 $content = $this->addTable( $content, $table ) . "\n";
145 if ( !$this->msg( 'pageinfo-footer' )->isDisabled() ) {
146 $content .= $this->msg( 'pageinfo-footer' )->parse();
153 * Creates a header that can be added to the output.
155 * @param string $header The header text.
156 * @param string $canonicalId
157 * @return string The HTML.
159 protected function makeHeader( $header, $canonicalId ) {
160 $spanAttribs = [ 'class' => 'mw-headline', 'id' => Sanitizer
::escapeIdForAttribute( $header ) ];
161 $h2Attribs = [ 'id' => Sanitizer
::escapeIdForAttribute( $canonicalId ) ];
163 return Html
::rawElement( 'h2', $h2Attribs, Html
::element( 'span', $spanAttribs, $header ) );
167 * Adds a row to a table that will be added to the content.
169 * @param string $table The table that will be added to the content
170 * @param string $name The name of the row
171 * @param string $value The value of the row
172 * @param string $id The ID to use for the 'tr' element
173 * @return string The table with the row added
175 protected function addRow( $table, $name, $value, $id ) {
179 $id === null ?
[] : [ 'id' => 'mw-' . $id ],
180 Html
::rawElement( 'td', [ 'style' => 'vertical-align: top;' ], $name ) .
181 Html
::rawElement( 'td', [], $value )
186 * Adds a table to the content that will be added to the output.
188 * @param string $content The content that will be added to the output
189 * @param string $table
190 * @return string The content with the table added
192 protected function addTable( $content, $table ) {
193 return $content . Html
::rawElement( 'table', [ 'class' => 'wikitable mw-page-info' ],
198 * Returns an array of info groups (will be rendered as tables), keyed by group ID.
199 * Group IDs are arbitrary and used so that extensions may add additional information in
200 * arbitrary positions (and as message keys for section headers for the tables, prefixed
202 * Each info group is a non-associative array of info items (rendered as table rows).
203 * Each info item is an array with two elements: the first describes the type of
204 * information, the second the value for the current page. Both can be strings (will be
205 * interpreted as raw HTML) or messages (will be interpreted as plain text and escaped).
209 protected function pageInfo() {
212 $user = $this->getUser();
213 $lang = $this->getLanguage();
214 $title = $this->getTitle();
215 $id = $title->getArticleID();
216 $config = $this->context
->getConfig();
217 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
219 $pageCounts = $this->pageCounts( $this->page
);
221 $pageProperties = [];
222 $props = PageProps
::getInstance()->getAllProperties( $title );
223 if ( isset( $props[$id] ) ) {
224 $pageProperties = $props[$id];
229 $pageInfo['header-basic'] = [];
232 $displayTitle = $title->getPrefixedText();
233 if ( isset( $pageProperties['displaytitle'] ) ) {
234 $displayTitle = $pageProperties['displaytitle'];
237 $pageInfo['header-basic'][] = [
238 $this->msg( 'pageinfo-display-title' ), $displayTitle
241 // Is it a redirect? If so, where to?
242 if ( $title->isRedirect() ) {
243 $pageInfo['header-basic'][] = [
244 $this->msg( 'pageinfo-redirectsto' ),
245 $linkRenderer->makeLink( $this->page
->getRedirectTarget() ) .
246 $this->msg( 'word-separator' )->escaped() .
247 $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
248 $this->page
->getRedirectTarget(),
249 $this->msg( 'pageinfo-redirectsto-info' )->text(),
251 [ 'action' => 'info' ]
257 $sortKey = $title->getCategorySortkey();
258 if ( isset( $pageProperties['defaultsort'] ) ) {
259 $sortKey = $pageProperties['defaultsort'];
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() )
270 // Page ID (number not localised, as it's a database ID)
271 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-article-id' ), $id ];
273 // Language in which the page content is (supposed to be) written
274 $pageLang = $title->getPageLanguage()->getCode();
276 $pageLangHtml = $pageLang . ' - ' .
277 Language
::fetchLanguageName( $pageLang, $lang->getCode() );
278 // Link to Special:PageLanguage with pre-filled page title if user has permissions
279 if ( $config->get( 'PageLanguageUseDB' )
280 && $title->userCan( 'pagelang', $user )
282 $pageLangHtml .= ' ' . $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
283 SpecialPage
::getTitleValueFor( 'PageLanguage', $title->getPrefixedText() ),
284 $this->msg( 'pageinfo-language-change' )->text()
288 $pageInfo['header-basic'][] = [
289 $this->msg( 'pageinfo-language' )->escaped(),
293 // Content model of the page
294 $modelHtml = htmlspecialchars( ContentHandler
::getLocalizedName( $title->getContentModel() ) );
295 // If the user can change it, add a link to Special:ChangeContentModel
296 if ( $config->get( 'ContentHandlerUseDB' )
297 && $title->userCan( 'editcontentmodel', $user )
299 $modelHtml .= ' ' . $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
300 SpecialPage
::getTitleValueFor( 'ChangeContentModel', $title->getPrefixedText() ),
301 $this->msg( 'pageinfo-content-model-change' )->text()
305 $pageInfo['header-basic'][] = [
306 $this->msg( 'pageinfo-content-model' ),
310 if ( $title->inNamespace( NS_USER
) ) {
311 $pageUser = User
::newFromName( $title->getRootText() );
312 if ( $pageUser && $pageUser->getId() && !$pageUser->isHidden() ) {
313 $pageInfo['header-basic'][] = [
314 $this->msg( 'pageinfo-user-id' ),
320 // Search engine status
321 $pOutput = new ParserOutput();
322 if ( isset( $pageProperties['noindex'] ) ) {
323 $pOutput->setIndexPolicy( 'noindex' );
325 if ( isset( $pageProperties['index'] ) ) {
326 $pOutput->setIndexPolicy( 'index' );
329 // Use robot policy logic
330 $policy = $this->page
->getRobotPolicy( 'view', $pOutput );
331 $pageInfo['header-basic'][] = [
332 // Messages: pageinfo-robot-index, pageinfo-robot-noindex
333 $this->msg( 'pageinfo-robot-policy' ),
334 $this->msg( "pageinfo-robot-${policy['index']}" )
337 $unwatchedPageThreshold = $config->get( 'UnwatchedPageThreshold' );
339 $user->isAllowed( 'unwatchedpages' ) ||
340 ( $unwatchedPageThreshold !== false &&
341 $pageCounts['watchers'] >= $unwatchedPageThreshold )
343 // Number of page watchers
344 $pageInfo['header-basic'][] = [
345 $this->msg( 'pageinfo-watchers' ),
346 $lang->formatNum( $pageCounts['watchers'] )
349 $config->get( 'ShowUpdatedMarker' ) &&
350 isset( $pageCounts['visitingWatchers'] )
352 $minToDisclose = $config->get( 'UnwatchedPageSecret' );
353 if ( $pageCounts['visitingWatchers'] > $minToDisclose ||
354 $user->isAllowed( 'unwatchedpages' ) ) {
355 $pageInfo['header-basic'][] = [
356 $this->msg( 'pageinfo-visiting-watchers' ),
357 $lang->formatNum( $pageCounts['visitingWatchers'] )
360 $pageInfo['header-basic'][] = [
361 $this->msg( 'pageinfo-visiting-watchers' ),
362 $this->msg( 'pageinfo-few-visiting-watchers' )
366 } elseif ( $unwatchedPageThreshold !== false ) {
367 $pageInfo['header-basic'][] = [
368 $this->msg( 'pageinfo-watchers' ),
369 $this->msg( 'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
373 // Redirects to this page
374 $whatLinksHere = SpecialPage
::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
375 $pageInfo['header-basic'][] = [
376 $linkRenderer->makeLink(
378 $this->msg( 'pageinfo-redirects-name' )->text(),
383 'hideimages' => $title->getNamespace() == NS_FILE
386 $this->msg( 'pageinfo-redirects-value' )
387 ->numParams( count( $title->getRedirectsHere() ) )
390 // Is it counted as a content page?
391 if ( $this->page
->isCountable() ) {
392 $pageInfo['header-basic'][] = [
393 $this->msg( 'pageinfo-contentpage' ),
394 $this->msg( 'pageinfo-contentpage-yes' )
398 // Subpages of this page, if subpages are enabled for the current NS
399 if ( MWNamespace
::hasSubpages( $title->getNamespace() ) ) {
400 $prefixIndex = SpecialPage
::getTitleFor(
401 'Prefixindex', $title->getPrefixedText() . '/' );
402 $pageInfo['header-basic'][] = [
403 $linkRenderer->makeLink(
405 $this->msg( 'pageinfo-subpages-name' )->text()
407 $this->msg( 'pageinfo-subpages-value' )
409 $pageCounts['subpages']['total'],
410 $pageCounts['subpages']['redirects'],
411 $pageCounts['subpages']['nonredirects'] )
415 if ( $title->inNamespace( NS_CATEGORY
) ) {
416 $category = Category
::newFromTitle( $title );
418 // $allCount is the total number of cat members,
419 // not the count of how many members are normal pages.
420 $allCount = (int)$category->getPageCount();
421 $subcatCount = (int)$category->getSubcatCount();
422 $fileCount = (int)$category->getFileCount();
423 $pagesCount = $allCount - $subcatCount - $fileCount;
425 $pageInfo['category-info'] = [
427 $this->msg( 'pageinfo-category-total' ),
428 $lang->formatNum( $allCount )
431 $this->msg( 'pageinfo-category-pages' ),
432 $lang->formatNum( $pagesCount )
435 $this->msg( 'pageinfo-category-subcats' ),
436 $lang->formatNum( $subcatCount )
439 $this->msg( 'pageinfo-category-files' ),
440 $lang->formatNum( $fileCount )
445 // Display image SHA-1 value
446 if ( $title->inNamespace( NS_FILE
) ) {
447 $fileObj = wfFindFile( $title );
448 if ( $fileObj !== false ) {
449 // Convert the base-36 sha1 value obtained from database to base-16
450 $output = Wikimedia\base_convert
( $fileObj->getSha1(), 36, 16, 40 );
451 $pageInfo['header-basic'][] = [
452 $this->msg( 'pageinfo-file-hash' ),
459 $pageInfo['header-restrictions'] = [];
461 // Is this page affected by the cascading protection of something which includes it?
462 if ( $title->isCascadeProtected() ) {
464 $sources = $title->getCascadeProtectionSources()[0];
466 foreach ( $sources as $sourceTitle ) {
467 $cascadingFrom .= Html
::rawElement(
468 'li', [], $linkRenderer->makeKnownLink( $sourceTitle ) );
471 $cascadingFrom = Html
::rawElement( 'ul', [], $cascadingFrom );
472 $pageInfo['header-restrictions'][] = [
473 $this->msg( 'pageinfo-protect-cascading-from' ),
478 // Is out protection set to cascade to other pages?
479 if ( $title->areRestrictionsCascading() ) {
480 $pageInfo['header-restrictions'][] = [
481 $this->msg( 'pageinfo-protect-cascading' ),
482 $this->msg( 'pageinfo-protect-cascading-yes' )
487 foreach ( $title->getRestrictionTypes() as $restrictionType ) {
488 $protectionLevel = implode( ', ', $title->getRestrictions( $restrictionType ) );
490 if ( $protectionLevel == '' ) {
492 $message = $this->msg( 'protect-default' )->escaped();
494 // Administrators only
495 // Messages: protect-level-autoconfirmed, protect-level-sysop
496 $message = $this->msg( "protect-level-$protectionLevel" );
497 if ( $message->isDisabled() ) {
498 // Require "$1" permission
499 $message = $this->msg( "protect-fallback", $protectionLevel )->parse();
501 $message = $message->escaped();
504 $expiry = $title->getRestrictionExpiry( $restrictionType );
505 $formattedexpiry = $this->msg( 'parentheses',
506 $lang->formatExpiry( $expiry ) )->escaped();
507 $message .= $this->msg( 'word-separator' )->escaped() . $formattedexpiry;
509 // Messages: restriction-edit, restriction-move, restriction-create,
510 // restriction-upload
511 $pageInfo['header-restrictions'][] = [
512 $this->msg( "restriction-$restrictionType" ), $message
516 if ( !$this->page
->exists() ) {
521 $pageInfo['header-edits'] = [];
523 $firstRev = $this->page
->getOldestRevision();
524 $lastRev = $this->page
->getRevision();
525 $batch = new LinkBatch
;
528 $firstRevUser = $firstRev->getUserText( Revision
::FOR_THIS_USER
);
529 if ( $firstRevUser !== '' ) {
530 $firstRevUserTitle = Title
::makeTitle( NS_USER
, $firstRevUser );
531 $batch->addObj( $firstRevUserTitle );
532 $batch->addObj( $firstRevUserTitle->getTalkPage() );
537 $lastRevUser = $lastRev->getUserText( Revision
::FOR_THIS_USER
);
538 if ( $lastRevUser !== '' ) {
539 $lastRevUserTitle = Title
::makeTitle( NS_USER
, $lastRevUser );
540 $batch->addObj( $lastRevUserTitle );
541 $batch->addObj( $lastRevUserTitle->getTalkPage() );
549 $pageInfo['header-edits'][] = [
550 $this->msg( 'pageinfo-firstuser' ),
551 Linker
::revUserTools( $firstRev )
554 // Date of page creation
555 $pageInfo['header-edits'][] = [
556 $this->msg( 'pageinfo-firsttime' ),
557 $linkRenderer->makeKnownLink(
559 $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ),
561 [ 'oldid' => $firstRev->getId() ]
568 $pageInfo['header-edits'][] = [
569 $this->msg( 'pageinfo-lastuser' ),
570 Linker
::revUserTools( $lastRev )
573 // Date of latest edit
574 $pageInfo['header-edits'][] = [
575 $this->msg( 'pageinfo-lasttime' ),
576 $linkRenderer->makeKnownLink(
578 $lang->userTimeAndDate( $this->page
->getTimestamp(), $user ),
580 [ 'oldid' => $this->page
->getLatest() ]
585 // Total number of edits
586 $pageInfo['header-edits'][] = [
587 $this->msg( 'pageinfo-edits' ), $lang->formatNum( $pageCounts['edits'] )
590 // Total number of distinct authors
591 if ( $pageCounts['authors'] > 0 ) {
592 $pageInfo['header-edits'][] = [
593 $this->msg( 'pageinfo-authors' ), $lang->formatNum( $pageCounts['authors'] )
597 // Recent number of edits (within past 30 days)
598 $pageInfo['header-edits'][] = [
599 $this->msg( 'pageinfo-recent-edits',
600 $lang->formatDuration( $config->get( 'RCMaxAge' ) ) ),
601 $lang->formatNum( $pageCounts['recent_edits'] )
604 // Recent number of distinct authors
605 $pageInfo['header-edits'][] = [
606 $this->msg( 'pageinfo-recent-authors' ),
607 $lang->formatNum( $pageCounts['recent_authors'] )
610 // Array of MagicWord objects
611 $magicWords = MagicWord
::getDoubleUnderscoreArray();
613 // Array of magic word IDs
614 $wordIDs = $magicWords->names
;
616 // Array of IDs => localized magic words
617 $localizedWords = $wgContLang->getMagicWords();
620 foreach ( $pageProperties as $property => $value ) {
621 if ( in_array( $property, $wordIDs ) ) {
622 $listItems[] = Html
::element( 'li', [], $localizedWords[$property][1] );
626 $localizedList = Html
::rawElement( 'ul', [], implode( '', $listItems ) );
627 $hiddenCategories = $this->page
->getHiddenCategories();
630 count( $listItems ) > 0 ||
631 count( $hiddenCategories ) > 0 ||
632 $pageCounts['transclusion']['from'] > 0 ||
633 $pageCounts['transclusion']['to'] > 0
635 $options = [ 'LIMIT' => $config->get( 'PageInfoTransclusionLimit' ) ];
636 $transcludedTemplates = $title->getTemplateLinksFrom( $options );
637 if ( $config->get( 'MiserMode' ) ) {
638 $transcludedTargets = [];
640 $transcludedTargets = $title->getTemplateLinksTo( $options );
644 $pageInfo['header-properties'] = [];
647 if ( count( $listItems ) > 0 ) {
648 $pageInfo['header-properties'][] = [
649 $this->msg( 'pageinfo-magic-words' )->numParams( count( $listItems ) ),
655 if ( count( $hiddenCategories ) > 0 ) {
656 $pageInfo['header-properties'][] = [
657 $this->msg( 'pageinfo-hidden-categories' )
658 ->numParams( count( $hiddenCategories ) ),
659 Linker
::formatHiddenCategories( $hiddenCategories )
663 // Transcluded templates
664 if ( $pageCounts['transclusion']['from'] > 0 ) {
665 if ( $pageCounts['transclusion']['from'] > count( $transcludedTemplates ) ) {
666 $more = $this->msg( 'morenotlisted' )->escaped();
671 $templateListFormatter = new TemplatesOnThisPageFormatter(
676 $pageInfo['header-properties'][] = [
677 $this->msg( 'pageinfo-templates' )
678 ->numParams( $pageCounts['transclusion']['from'] ),
679 $templateListFormatter->format( $transcludedTemplates, false, $more )
683 if ( !$config->get( 'MiserMode' ) && $pageCounts['transclusion']['to'] > 0 ) {
684 if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) {
685 $more = $linkRenderer->makeLink(
687 $this->msg( 'moredotdotdot' )->text(),
689 [ 'hidelinks' => 1, 'hideredirs' => 1 ]
695 $templateListFormatter = new TemplatesOnThisPageFormatter(
700 $pageInfo['header-properties'][] = [
701 $this->msg( 'pageinfo-transclusions' )
702 ->numParams( $pageCounts['transclusion']['to'] ),
703 $templateListFormatter->format( $transcludedTargets, false, $more )
712 * Returns page counts that would be too "expensive" to retrieve by normal means.
714 * @param WikiPage|Article|Page $page
717 protected function pageCounts( Page
$page ) {
719 $config = $this->context
->getConfig();
720 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
722 return $cache->getWithSetCallback(
723 self
::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ),
724 WANObjectCache
::TTL_WEEK
,
725 function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
726 global $wgActorTableSchemaMigrationStage;
728 $title = $page->getTitle();
729 $id = $title->getArticleID();
731 $dbr = wfGetDB( DB_REPLICA
);
732 $dbrWatchlist = wfGetDB( DB_REPLICA
, 'watchlist' );
733 $setOpts +
= Database
::getCacheSetOptions( $dbr, $dbrWatchlist );
735 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
736 $tables = [ 'revision_actor_temp' ];
737 $field = 'revactor_actor';
738 $pageField = 'revactor_page';
739 $tsField = 'revactor_timestamp';
741 } elseif ( $wgActorTableSchemaMigrationStage === MIGRATION_OLD
) {
742 $tables = [ 'revision' ];
743 $field = 'rev_user_text';
744 $pageField = 'rev_page';
745 $tsField = 'rev_timestamp';
748 $tables = [ 'revision', 'revision_actor_temp', 'actor' ];
749 $field = 'COALESCE( actor_name, rev_user_text)';
750 $pageField = 'rev_page';
751 $tsField = 'rev_timestamp';
753 'revision_actor_temp' => [ 'LEFT JOIN', 'revactor_rev = rev_id' ],
754 'actor' => [ 'LEFT JOIN', 'revactor_actor = actor_id' ],
758 $watchedItemStore = MediaWikiServices
::getInstance()->getWatchedItemStore();
761 $result['watchers'] = $watchedItemStore->countWatchers( $title );
763 if ( $config->get( 'ShowUpdatedMarker' ) ) {
764 $updated = wfTimestamp( TS_UNIX
, $page->getTimestamp() );
765 $result['visitingWatchers'] = $watchedItemStore->countVisitingWatchers(
767 $updated - $config->get( 'WatchersMaxAge' )
771 // Total number of edits
772 $edits = (int)$dbr->selectField(
775 [ 'rev_page' => $id ],
778 $result['edits'] = $edits;
780 // Total number of distinct authors
781 if ( $config->get( 'MiserMode' ) ) {
782 $result['authors'] = 0;
784 $result['authors'] = (int)$dbr->selectField(
786 "COUNT(DISTINCT $field)",
787 [ $pageField => $id ],
794 // "Recent" threshold defined by RCMaxAge setting
795 $threshold = $dbr->timestamp( time() - $config->get( 'RCMaxAge' ) );
797 // Recent number of edits
798 $edits = (int)$dbr->selectField(
803 "rev_timestamp >= " . $dbr->addQuotes( $threshold )
807 $result['recent_edits'] = $edits;
809 // Recent number of distinct authors
810 $result['recent_authors'] = (int)$dbr->selectField(
812 "COUNT(DISTINCT $field)",
815 "$tsField >= " . $dbr->addQuotes( $threshold )
822 // Subpages (if enabled)
823 if ( MWNamespace
::hasSubpages( $title->getNamespace() ) ) {
824 $conds = [ 'page_namespace' => $title->getNamespace() ];
825 $conds[] = 'page_title ' .
826 $dbr->buildLike( $title->getDBkey() . '/', $dbr->anyString() );
828 // Subpages of this page (redirects)
829 $conds['page_is_redirect'] = 1;
830 $result['subpages']['redirects'] = (int)$dbr->selectField(
837 // Subpages of this page (non-redirects)
838 $conds['page_is_redirect'] = 0;
839 $result['subpages']['nonredirects'] = (int)$dbr->selectField(
846 // Subpages of this page (total)
847 $result['subpages']['total'] = $result['subpages']['redirects']
848 +
$result['subpages']['nonredirects'];
851 // Counts for the number of transclusion links (to/from)
852 if ( $config->get( 'MiserMode' ) ) {
853 $result['transclusion']['to'] = 0;
855 $result['transclusion']['to'] = (int)$dbr->selectField(
859 'tl_namespace' => $title->getNamespace(),
860 'tl_title' => $title->getDBkey()
866 $result['transclusion']['from'] = (int)$dbr->selectField(
869 [ 'tl_from' => $title->getArticleID() ],
879 * Returns the name that goes in the "<h1>" page title.
883 protected function getPageTitle() {
884 return $this->msg( 'pageinfo-title', $this->getTitle()->getPrefixedText() )->text();
888 * Get a list of contributors of $article
889 * @return string Html
891 protected function getContributors() {
892 $contributors = $this->page
->getContributors();
896 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
898 # Sift for real versus user names
899 /** @var User $user */
900 foreach ( $contributors as $user ) {
901 $page = $user->isAnon()
902 ? SpecialPage
::getTitleFor( 'Contributions', $user->getName() )
903 : $user->getUserPage();
905 $hiddenPrefs = $this->context
->getConfig()->get( 'HiddenPrefs' );
906 if ( $user->getId() == 0 ) {
907 $anon_ips[] = $linkRenderer->makeLink( $page, $user->getName() );
908 } elseif ( !in_array( 'realname', $hiddenPrefs ) && $user->getRealName() ) {
909 $real_names[] = $linkRenderer->makeLink( $page, $user->getRealName() );
911 $user_names[] = $linkRenderer->makeLink( $page, $user->getName() );
915 $lang = $this->getLanguage();
917 $real = $lang->listToText( $real_names );
919 # "ThisSite user(s) A, B and C"
920 if ( count( $user_names ) ) {
921 $user = $this->msg( 'siteusers' )
922 ->rawParams( $lang->listToText( $user_names ) )
923 ->params( count( $user_names ) )->escaped();
928 if ( count( $anon_ips ) ) {
929 $anon = $this->msg( 'anonusers' )
930 ->rawParams( $lang->listToText( $anon_ips ) )
931 ->params( count( $anon_ips ) )->escaped();
936 # This is the big list, all mooshed together. We sift for blank strings
938 foreach ( [ $real, $user, $anon ] as $s ) {
940 array_push( $fulllist, $s );
944 $count = count( $fulllist );
946 # "Based on work by ..."
948 ?
$this->msg( 'othercontribs' )->rawParams(
949 $lang->listToText( $fulllist ) )->params( $count )->escaped()
954 * Returns the description that goes below the "<h1>" tag.
958 protected function getDescription() {
963 * @param WANObjectCache $cache
964 * @param Title $title
968 protected static function getCacheKey( WANObjectCache
$cache, Title
$title, $revId ) {
969 return $cache->makeKey( 'infoaction', md5( $title->getPrefixedText() ), $revId, self
::VERSION
);