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\Revision\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 $pageLangHtml = $pageLang . ' - ' .
284 Language
::fetchLanguageName( $pageLang, $lang->getCode() );
285 // Link to Special:PageLanguage with pre-filled page title if user has permissions
286 $permissionManager = $services->getPermissionManager();
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' );
346 if ( $permissionManager->userHasRight( $user, 'unwatchedpages' ) ||
347 ( $unwatchedPageThreshold !== false &&
348 $pageCounts['watchers'] >= $unwatchedPageThreshold )
350 // Number of page watchers
351 $pageInfo['header-basic'][] = [
352 $this->msg( 'pageinfo-watchers' ),
353 $lang->formatNum( $pageCounts['watchers'] )
356 $config->get( 'ShowUpdatedMarker' ) &&
357 isset( $pageCounts['visitingWatchers'] )
359 $minToDisclose = $config->get( 'UnwatchedPageSecret' );
360 if ( $pageCounts['visitingWatchers'] > $minToDisclose ||
361 $permissionManager->userHasRight( $user, 'unwatchedpages' ) ) {
362 $pageInfo['header-basic'][] = [
363 $this->msg( 'pageinfo-visiting-watchers' ),
364 $lang->formatNum( $pageCounts['visitingWatchers'] )
367 $pageInfo['header-basic'][] = [
368 $this->msg( 'pageinfo-visiting-watchers' ),
369 $this->msg( 'pageinfo-few-visiting-watchers' )
373 } elseif ( $unwatchedPageThreshold !== false ) {
374 $pageInfo['header-basic'][] = [
375 $this->msg( 'pageinfo-watchers' ),
376 $this->msg( 'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
380 // Redirects to this page
381 $whatLinksHere = SpecialPage
::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
382 $pageInfo['header-basic'][] = [
383 $linkRenderer->makeLink(
385 $this->msg( 'pageinfo-redirects-name' )->text(),
390 'hideimages' => $title->getNamespace() == NS_FILE
393 $this->msg( 'pageinfo-redirects-value' )
394 ->numParams( count( $title->getRedirectsHere() ) )
397 // Is it counted as a content page?
398 if ( $this->page
->isCountable() ) {
399 $pageInfo['header-basic'][] = [
400 $this->msg( 'pageinfo-contentpage' ),
401 $this->msg( 'pageinfo-contentpage-yes' )
405 // Subpages of this page, if subpages are enabled for the current NS
406 if ( $services->getNamespaceInfo()->hasSubpages( $title->getNamespace() ) ) {
407 $prefixIndex = SpecialPage
::getTitleFor(
408 'Prefixindex', $title->getPrefixedText() . '/' );
409 $pageInfo['header-basic'][] = [
410 $linkRenderer->makeLink(
412 $this->msg( 'pageinfo-subpages-name' )->text()
414 $this->msg( 'pageinfo-subpages-value' )
416 $pageCounts['subpages']['total'],
417 $pageCounts['subpages']['redirects'],
418 $pageCounts['subpages']['nonredirects'] )
422 if ( $title->inNamespace( NS_CATEGORY
) ) {
423 $category = Category
::newFromTitle( $title );
425 // $allCount is the total number of cat members,
426 // not the count of how many members are normal pages.
427 $allCount = (int)$category->getPageCount();
428 $subcatCount = (int)$category->getSubcatCount();
429 $fileCount = (int)$category->getFileCount();
430 $pagesCount = $allCount - $subcatCount - $fileCount;
432 $pageInfo['category-info'] = [
434 $this->msg( 'pageinfo-category-total' ),
435 $lang->formatNum( $allCount )
438 $this->msg( 'pageinfo-category-pages' ),
439 $lang->formatNum( $pagesCount )
442 $this->msg( 'pageinfo-category-subcats' ),
443 $lang->formatNum( $subcatCount )
446 $this->msg( 'pageinfo-category-files' ),
447 $lang->formatNum( $fileCount )
452 // Display image SHA-1 value
453 if ( $title->inNamespace( NS_FILE
) ) {
454 $fileObj = $services->getRepoGroup()->findFile( $title );
455 if ( $fileObj !== false ) {
456 // Convert the base-36 sha1 value obtained from database to base-16
457 $output = Wikimedia\base_convert
( $fileObj->getSha1(), 36, 16, 40 );
458 $pageInfo['header-basic'][] = [
459 $this->msg( 'pageinfo-file-hash' ),
466 $pageInfo['header-restrictions'] = [];
468 // Is this page affected by the cascading protection of something which includes it?
469 if ( $title->isCascadeProtected() ) {
471 $sources = $title->getCascadeProtectionSources()[0];
473 foreach ( $sources as $sourceTitle ) {
474 $cascadingFrom .= Html
::rawElement(
475 'li', [], $linkRenderer->makeKnownLink( $sourceTitle ) );
478 $cascadingFrom = Html
::rawElement( 'ul', [], $cascadingFrom );
479 $pageInfo['header-restrictions'][] = [
480 $this->msg( 'pageinfo-protect-cascading-from' ),
485 // Is out protection set to cascade to other pages?
486 if ( $title->areRestrictionsCascading() ) {
487 $pageInfo['header-restrictions'][] = [
488 $this->msg( 'pageinfo-protect-cascading' ),
489 $this->msg( 'pageinfo-protect-cascading-yes' )
494 foreach ( $title->getRestrictionTypes() as $restrictionType ) {
495 $protectionLevel = implode( ', ', $title->getRestrictions( $restrictionType ) );
497 if ( $protectionLevel == '' ) {
499 $message = $this->msg( 'protect-default' )->escaped();
501 // Administrators only
502 // Messages: protect-level-autoconfirmed, protect-level-sysop
503 $message = $this->msg( "protect-level-$protectionLevel" );
504 if ( $message->isDisabled() ) {
505 // Require "$1" permission
506 $message = $this->msg( "protect-fallback", $protectionLevel )->parse();
508 $message = $message->escaped();
511 $expiry = $title->getRestrictionExpiry( $restrictionType );
512 $formattedexpiry = $this->msg( 'parentheses',
513 $lang->formatExpiry( $expiry ) )->escaped();
514 $message .= $this->msg( 'word-separator' )->escaped() . $formattedexpiry;
516 // Messages: restriction-edit, restriction-move, restriction-create,
517 // restriction-upload
518 $pageInfo['header-restrictions'][] = [
519 $this->msg( "restriction-$restrictionType" ), $message
522 $protectLog = SpecialPage
::getTitleFor( 'Log' );
523 $pageInfo['header-restrictions'][] = [
525 $linkRenderer->makeKnownLink(
527 $this->msg( 'pageinfo-view-protect-log' )->text(),
529 [ 'type' => 'protect', 'page' => $title->getPrefixedText() ]
533 if ( !$this->page
->exists() ) {
538 $pageInfo['header-edits'] = [];
540 $firstRev = $this->page
->getOldestRevision();
541 $lastRev = $this->page
->getRevision();
542 $batch = new LinkBatch
;
545 $firstRevUser = $firstRev->getUserText( RevisionRecord
::FOR_THIS_USER
);
546 if ( $firstRevUser !== '' ) {
547 $firstRevUserTitle = Title
::makeTitle( NS_USER
, $firstRevUser );
548 $batch->addObj( $firstRevUserTitle );
549 $batch->addObj( $firstRevUserTitle->getTalkPage() );
554 $lastRevUser = $lastRev->getUserText( RevisionRecord
::FOR_THIS_USER
);
555 if ( $lastRevUser !== '' ) {
556 $lastRevUserTitle = Title
::makeTitle( NS_USER
, $lastRevUser );
557 $batch->addObj( $lastRevUserTitle );
558 $batch->addObj( $lastRevUserTitle->getTalkPage() );
566 $pageInfo['header-edits'][] = [
567 $this->msg( 'pageinfo-firstuser' ),
568 Linker
::revUserTools( $firstRev )
571 // Date of page creation
572 $pageInfo['header-edits'][] = [
573 $this->msg( 'pageinfo-firsttime' ),
574 $linkRenderer->makeKnownLink(
576 $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ),
578 [ 'oldid' => $firstRev->getId() ]
585 $pageInfo['header-edits'][] = [
586 $this->msg( 'pageinfo-lastuser' ),
587 Linker
::revUserTools( $lastRev )
590 // Date of latest edit
591 $pageInfo['header-edits'][] = [
592 $this->msg( 'pageinfo-lasttime' ),
593 $linkRenderer->makeKnownLink(
595 $lang->userTimeAndDate( $this->page
->getTimestamp(), $user ),
597 [ 'oldid' => $this->page
->getLatest() ]
602 // Total number of edits
603 $pageInfo['header-edits'][] = [
604 $this->msg( 'pageinfo-edits' ), $lang->formatNum( $pageCounts['edits'] )
607 // Total number of distinct authors
608 if ( $pageCounts['authors'] > 0 ) {
609 $pageInfo['header-edits'][] = [
610 $this->msg( 'pageinfo-authors' ), $lang->formatNum( $pageCounts['authors'] )
614 // Recent number of edits (within past 30 days)
615 $pageInfo['header-edits'][] = [
616 $this->msg( 'pageinfo-recent-edits',
617 $lang->formatDuration( $config->get( 'RCMaxAge' ) ) ),
618 $lang->formatNum( $pageCounts['recent_edits'] )
621 // Recent number of distinct authors
622 $pageInfo['header-edits'][] = [
623 $this->msg( 'pageinfo-recent-authors' ),
624 $lang->formatNum( $pageCounts['recent_authors'] )
627 // Array of MagicWord objects
628 $magicWords = $services->getMagicWordFactory()->getDoubleUnderscoreArray();
630 // Array of magic word IDs
631 $wordIDs = $magicWords->names
;
633 // Array of IDs => localized magic words
634 $localizedWords = $services->getContentLanguage()->getMagicWords();
637 foreach ( $pageProperties as $property => $value ) {
638 if ( in_array( $property, $wordIDs ) ) {
639 $listItems[] = Html
::element( 'li', [], $localizedWords[$property][1] );
643 $localizedList = Html
::rawElement( 'ul', [], implode( '', $listItems ) );
644 $hiddenCategories = $this->page
->getHiddenCategories();
647 count( $listItems ) > 0 ||
648 count( $hiddenCategories ) > 0 ||
649 $pageCounts['transclusion']['from'] > 0 ||
650 $pageCounts['transclusion']['to'] > 0
652 $options = [ 'LIMIT' => $config->get( 'PageInfoTransclusionLimit' ) ];
653 $transcludedTemplates = $title->getTemplateLinksFrom( $options );
654 if ( $config->get( 'MiserMode' ) ) {
655 $transcludedTargets = [];
657 $transcludedTargets = $title->getTemplateLinksTo( $options );
661 $pageInfo['header-properties'] = [];
664 if ( count( $listItems ) > 0 ) {
665 $pageInfo['header-properties'][] = [
666 $this->msg( 'pageinfo-magic-words' )->numParams( count( $listItems ) ),
672 if ( count( $hiddenCategories ) > 0 ) {
673 $pageInfo['header-properties'][] = [
674 $this->msg( 'pageinfo-hidden-categories' )
675 ->numParams( count( $hiddenCategories ) ),
676 Linker
::formatHiddenCategories( $hiddenCategories )
680 // Transcluded templates
681 if ( $pageCounts['transclusion']['from'] > 0 ) {
682 if ( $pageCounts['transclusion']['from'] > count( $transcludedTemplates ) ) {
683 $more = $this->msg( 'morenotlisted' )->escaped();
688 $templateListFormatter = new TemplatesOnThisPageFormatter(
693 $pageInfo['header-properties'][] = [
694 $this->msg( 'pageinfo-templates' )
695 ->numParams( $pageCounts['transclusion']['from'] ),
696 $templateListFormatter->format( $transcludedTemplates, false, $more )
700 if ( !$config->get( 'MiserMode' ) && $pageCounts['transclusion']['to'] > 0 ) {
701 if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) {
702 $more = $linkRenderer->makeLink(
704 $this->msg( 'moredotdotdot' )->text(),
706 [ 'hidelinks' => 1, 'hideredirs' => 1 ]
712 $templateListFormatter = new TemplatesOnThisPageFormatter(
717 $pageInfo['header-properties'][] = [
718 $this->msg( 'pageinfo-transclusions' )
719 ->numParams( $pageCounts['transclusion']['to'] ),
720 $templateListFormatter->format( $transcludedTargets, false, $more )
729 * Returns page counts that would be too "expensive" to retrieve by normal means.
731 * @param WikiPage|Article|Page $page
734 protected function pageCounts( Page
$page ) {
736 $config = $this->context
->getConfig();
737 $services = MediaWikiServices
::getInstance();
738 $cache = $services->getMainWANObjectCache();
740 return $cache->getWithSetCallback(
741 self
::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ),
742 WANObjectCache
::TTL_WEEK
,
743 function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname, $services ) {
744 $title = $page->getTitle();
745 $id = $title->getArticleID();
747 $dbr = wfGetDB( DB_REPLICA
);
748 $dbrWatchlist = wfGetDB( DB_REPLICA
, 'watchlist' );
749 $setOpts +
= Database
::getCacheSetOptions( $dbr, $dbrWatchlist );
751 $tables = [ 'revision_actor_temp' ];
752 $field = 'revactor_actor';
753 $pageField = 'revactor_page';
754 $tsField = 'revactor_timestamp';
757 $watchedItemStore = $services->getWatchedItemStore();
760 $result['watchers'] = $watchedItemStore->countWatchers( $title );
762 if ( $config->get( 'ShowUpdatedMarker' ) ) {
763 $updated = wfTimestamp( TS_UNIX
, $page->getTimestamp() );
764 $result['visitingWatchers'] = $watchedItemStore->countVisitingWatchers(
766 $updated - $config->get( 'WatchersMaxAge' )
770 // Total number of edits
771 $edits = (int)$dbr->selectField(
774 [ 'rev_page' => $id ],
777 $result['edits'] = $edits;
779 // Total number of distinct authors
780 if ( $config->get( 'MiserMode' ) ) {
781 $result['authors'] = 0;
783 $result['authors'] = (int)$dbr->selectField(
785 "COUNT(DISTINCT $field)",
786 [ $pageField => $id ],
793 // "Recent" threshold defined by RCMaxAge setting
794 $threshold = $dbr->timestamp( time() - $config->get( 'RCMaxAge' ) );
796 // Recent number of edits
797 $edits = (int)$dbr->selectField(
802 "rev_timestamp >= " . $dbr->addQuotes( $threshold )
806 $result['recent_edits'] = $edits;
808 // Recent number of distinct authors
809 $result['recent_authors'] = (int)$dbr->selectField(
811 "COUNT(DISTINCT $field)",
814 "$tsField >= " . $dbr->addQuotes( $threshold )
821 // Subpages (if enabled)
822 if ( $services->getNamespaceInfo()->hasSubpages( $title->getNamespace() ) ) {
823 $conds = [ 'page_namespace' => $title->getNamespace() ];
824 $conds[] = 'page_title ' .
825 $dbr->buildLike( $title->getDBkey() . '/', $dbr->anyString() );
827 // Subpages of this page (redirects)
828 $conds['page_is_redirect'] = 1;
829 $result['subpages']['redirects'] = (int)$dbr->selectField(
836 // Subpages of this page (non-redirects)
837 $conds['page_is_redirect'] = 0;
838 $result['subpages']['nonredirects'] = (int)$dbr->selectField(
845 // Subpages of this page (total)
846 $result['subpages']['total'] = $result['subpages']['redirects']
847 +
$result['subpages']['nonredirects'];
850 // Counts for the number of transclusion links (to/from)
851 if ( $config->get( 'MiserMode' ) ) {
852 $result['transclusion']['to'] = 0;
854 $result['transclusion']['to'] = (int)$dbr->selectField(
858 'tl_namespace' => $title->getNamespace(),
859 'tl_title' => $title->getDBkey()
865 $result['transclusion']['from'] = (int)$dbr->selectField(
868 [ 'tl_from' => $title->getArticleID() ],
878 * Returns the name that goes in the "<h1>" page title.
882 protected function getPageTitle() {
883 return $this->msg( 'pageinfo-title', $this->getTitle()->getPrefixedText() )->text();
887 * Get a list of contributors of $article
888 * @return string Html
890 protected function getContributors() {
891 $contributors = $this->page
->getContributors();
895 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
897 # Sift for real versus user names
898 /** @var User $user */
899 foreach ( $contributors as $user ) {
900 $page = $user->isAnon()
901 ? SpecialPage
::getTitleFor( 'Contributions', $user->getName() )
902 : $user->getUserPage();
904 $hiddenPrefs = $this->context
->getConfig()->get( 'HiddenPrefs' );
905 if ( $user->getId() == 0 ) {
906 $anon_ips[] = $linkRenderer->makeLink( $page, $user->getName() );
907 } elseif ( !in_array( 'realname', $hiddenPrefs ) && $user->getRealName() ) {
908 $real_names[] = $linkRenderer->makeLink( $page, $user->getRealName() );
910 $user_names[] = $linkRenderer->makeLink( $page, $user->getName() );
914 $lang = $this->getLanguage();
916 $real = $lang->listToText( $real_names );
918 # "ThisSite user(s) A, B and C"
919 if ( count( $user_names ) ) {
920 $user = $this->msg( 'siteusers' )
921 ->rawParams( $lang->listToText( $user_names ) )
922 ->params( count( $user_names ) )->escaped();
927 if ( count( $anon_ips ) ) {
928 $anon = $this->msg( 'anonusers' )
929 ->rawParams( $lang->listToText( $anon_ips ) )
930 ->params( count( $anon_ips ) )->escaped();
935 # This is the big list, all mooshed together. We sift for blank strings
937 foreach ( [ $real, $user, $anon ] as $s ) {
939 array_push( $fulllist, $s );
943 $count = count( $fulllist );
945 # "Based on work by ..."
947 ?
$this->msg( 'othercontribs' )->rawParams(
948 $lang->listToText( $fulllist ) )->params( $count )->escaped()
953 * Returns the description that goes below the "<h1>" tag.
957 protected function getDescription() {
962 * @param WANObjectCache $cache
963 * @param Title $title
967 protected static function getCacheKey( WANObjectCache
$cache, Title
$title, $revId ) {
968 return $cache->makeKey( 'infoaction', md5( $title->getPrefixedText() ), $revId, self
::VERSION
);