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 page information in an easily-manipulated format. Array keys are used so extensions
199 * may add additional information in arbitrary positions. Array values are arrays with one
200 * element to be rendered as a header, arrays with two elements to be rendered as a table row.
204 protected function pageInfo() {
207 $user = $this->getUser();
208 $lang = $this->getLanguage();
209 $title = $this->getTitle();
210 $id = $title->getArticleID();
211 $config = $this->context
->getConfig();
212 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
214 $pageCounts = $this->pageCounts( $this->page
);
216 $pageProperties = [];
217 $props = PageProps
::getInstance()->getAllProperties( $title );
218 if ( isset( $props[$id] ) ) {
219 $pageProperties = $props[$id];
224 $pageInfo['header-basic'] = [];
227 $displayTitle = $title->getPrefixedText();
228 if ( isset( $pageProperties['displaytitle'] ) ) {
229 $displayTitle = $pageProperties['displaytitle'];
232 $pageInfo['header-basic'][] = [
233 $this->msg( 'pageinfo-display-title' ), $displayTitle
236 // Is it a redirect? If so, where to?
237 if ( $title->isRedirect() ) {
238 $pageInfo['header-basic'][] = [
239 $this->msg( 'pageinfo-redirectsto' ),
240 $linkRenderer->makeLink( $this->page
->getRedirectTarget() ) .
241 $this->msg( 'word-separator' )->escaped() .
242 $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
243 $this->page
->getRedirectTarget(),
244 $this->msg( 'pageinfo-redirectsto-info' )->text(),
246 [ 'action' => 'info' ]
252 $sortKey = $title->getCategorySortkey();
253 if ( isset( $pageProperties['defaultsort'] ) ) {
254 $sortKey = $pageProperties['defaultsort'];
257 $sortKey = htmlspecialchars( $sortKey );
258 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-default-sort' ), $sortKey ];
260 // Page length (in bytes)
261 $pageInfo['header-basic'][] = [
262 $this->msg( 'pageinfo-length' ), $lang->formatNum( $title->getLength() )
265 // Page ID (number not localised, as it's a database ID)
266 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-article-id' ), $id ];
268 // Language in which the page content is (supposed to be) written
269 $pageLang = $title->getPageLanguage()->getCode();
271 $pageLangHtml = $pageLang . ' - ' .
272 Language
::fetchLanguageName( $pageLang, $lang->getCode() );
273 // Link to Special:PageLanguage with pre-filled page title if user has permissions
274 if ( $config->get( 'PageLanguageUseDB' )
275 && $title->userCan( 'pagelang', $user )
277 $pageLangHtml .= ' ' . $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
278 SpecialPage
::getTitleValueFor( 'PageLanguage', $title->getPrefixedText() ),
279 $this->msg( 'pageinfo-language-change' )->text()
283 $pageInfo['header-basic'][] = [
284 $this->msg( 'pageinfo-language' )->escaped(),
288 // Content model of the page
289 $modelHtml = htmlspecialchars( ContentHandler
::getLocalizedName( $title->getContentModel() ) );
290 // If the user can change it, add a link to Special:ChangeContentModel
291 if ( $config->get( 'ContentHandlerUseDB' )
292 && $title->userCan( 'editcontentmodel', $user )
294 $modelHtml .= ' ' . $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
295 SpecialPage
::getTitleValueFor( 'ChangeContentModel', $title->getPrefixedText() ),
296 $this->msg( 'pageinfo-content-model-change' )->text()
300 $pageInfo['header-basic'][] = [
301 $this->msg( 'pageinfo-content-model' ),
305 if ( $title->inNamespace( NS_USER
) ) {
306 $pageUser = User
::newFromName( $title->getRootText() );
307 if ( $pageUser && $pageUser->getId() && !$pageUser->isHidden() ) {
308 $pageInfo['header-basic'][] = [
309 $this->msg( 'pageinfo-user-id' ),
315 // Search engine status
316 $pOutput = new ParserOutput();
317 if ( isset( $pageProperties['noindex'] ) ) {
318 $pOutput->setIndexPolicy( 'noindex' );
320 if ( isset( $pageProperties['index'] ) ) {
321 $pOutput->setIndexPolicy( 'index' );
324 // Use robot policy logic
325 $policy = $this->page
->getRobotPolicy( 'view', $pOutput );
326 $pageInfo['header-basic'][] = [
327 // Messages: pageinfo-robot-index, pageinfo-robot-noindex
328 $this->msg( 'pageinfo-robot-policy' ),
329 $this->msg( "pageinfo-robot-${policy['index']}" )
332 $unwatchedPageThreshold = $config->get( 'UnwatchedPageThreshold' );
334 $user->isAllowed( 'unwatchedpages' ) ||
335 ( $unwatchedPageThreshold !== false &&
336 $pageCounts['watchers'] >= $unwatchedPageThreshold )
338 // Number of page watchers
339 $pageInfo['header-basic'][] = [
340 $this->msg( 'pageinfo-watchers' ),
341 $lang->formatNum( $pageCounts['watchers'] )
344 $config->get( 'ShowUpdatedMarker' ) &&
345 isset( $pageCounts['visitingWatchers'] )
347 $minToDisclose = $config->get( 'UnwatchedPageSecret' );
348 if ( $pageCounts['visitingWatchers'] > $minToDisclose ||
349 $user->isAllowed( 'unwatchedpages' ) ) {
350 $pageInfo['header-basic'][] = [
351 $this->msg( 'pageinfo-visiting-watchers' ),
352 $lang->formatNum( $pageCounts['visitingWatchers'] )
355 $pageInfo['header-basic'][] = [
356 $this->msg( 'pageinfo-visiting-watchers' ),
357 $this->msg( 'pageinfo-few-visiting-watchers' )
361 } elseif ( $unwatchedPageThreshold !== false ) {
362 $pageInfo['header-basic'][] = [
363 $this->msg( 'pageinfo-watchers' ),
364 $this->msg( 'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
368 // Redirects to this page
369 $whatLinksHere = SpecialPage
::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
370 $pageInfo['header-basic'][] = [
371 $linkRenderer->makeLink(
373 $this->msg( 'pageinfo-redirects-name' )->text(),
378 'hideimages' => $title->getNamespace() == NS_FILE
381 $this->msg( 'pageinfo-redirects-value' )
382 ->numParams( count( $title->getRedirectsHere() ) )
385 // Is it counted as a content page?
386 if ( $this->page
->isCountable() ) {
387 $pageInfo['header-basic'][] = [
388 $this->msg( 'pageinfo-contentpage' ),
389 $this->msg( 'pageinfo-contentpage-yes' )
393 // Subpages of this page, if subpages are enabled for the current NS
394 if ( MWNamespace
::hasSubpages( $title->getNamespace() ) ) {
395 $prefixIndex = SpecialPage
::getTitleFor(
396 'Prefixindex', $title->getPrefixedText() . '/' );
397 $pageInfo['header-basic'][] = [
398 $linkRenderer->makeLink(
400 $this->msg( 'pageinfo-subpages-name' )->text()
402 $this->msg( 'pageinfo-subpages-value' )
404 $pageCounts['subpages']['total'],
405 $pageCounts['subpages']['redirects'],
406 $pageCounts['subpages']['nonredirects'] )
410 if ( $title->inNamespace( NS_CATEGORY
) ) {
411 $category = Category
::newFromTitle( $title );
413 // $allCount is the total number of cat members,
414 // not the count of how many members are normal pages.
415 $allCount = (int)$category->getPageCount();
416 $subcatCount = (int)$category->getSubcatCount();
417 $fileCount = (int)$category->getFileCount();
418 $pagesCount = $allCount - $subcatCount - $fileCount;
420 $pageInfo['category-info'] = [
422 $this->msg( 'pageinfo-category-total' ),
423 $lang->formatNum( $allCount )
426 $this->msg( 'pageinfo-category-pages' ),
427 $lang->formatNum( $pagesCount )
430 $this->msg( 'pageinfo-category-subcats' ),
431 $lang->formatNum( $subcatCount )
434 $this->msg( 'pageinfo-category-files' ),
435 $lang->formatNum( $fileCount )
440 // Display image SHA-1 value
441 if ( $title->inNamespace( NS_FILE
) ) {
442 $fileObj = wfFindFile( $title );
443 if ( $fileObj !== false ) {
444 // Convert the base-36 sha1 value obtained from database to base-16
445 $output = Wikimedia\base_convert
( $fileObj->getSha1(), 36, 16, 40 );
446 $pageInfo['header-basic'][] = [
447 $this->msg( 'pageinfo-file-hash' ),
454 $pageInfo['header-restrictions'] = [];
456 // Is this page affected by the cascading protection of something which includes it?
457 if ( $title->isCascadeProtected() ) {
459 $sources = $title->getCascadeProtectionSources()[0];
461 foreach ( $sources as $sourceTitle ) {
462 $cascadingFrom .= Html
::rawElement(
463 'li', [], $linkRenderer->makeKnownLink( $sourceTitle ) );
466 $cascadingFrom = Html
::rawElement( 'ul', [], $cascadingFrom );
467 $pageInfo['header-restrictions'][] = [
468 $this->msg( 'pageinfo-protect-cascading-from' ),
473 // Is out protection set to cascade to other pages?
474 if ( $title->areRestrictionsCascading() ) {
475 $pageInfo['header-restrictions'][] = [
476 $this->msg( 'pageinfo-protect-cascading' ),
477 $this->msg( 'pageinfo-protect-cascading-yes' )
482 foreach ( $title->getRestrictionTypes() as $restrictionType ) {
483 $protectionLevel = implode( ', ', $title->getRestrictions( $restrictionType ) );
485 if ( $protectionLevel == '' ) {
487 $message = $this->msg( 'protect-default' )->escaped();
489 // Administrators only
490 // Messages: protect-level-autoconfirmed, protect-level-sysop
491 $message = $this->msg( "protect-level-$protectionLevel" );
492 if ( $message->isDisabled() ) {
493 // Require "$1" permission
494 $message = $this->msg( "protect-fallback", $protectionLevel )->parse();
496 $message = $message->escaped();
499 $expiry = $title->getRestrictionExpiry( $restrictionType );
500 $formattedexpiry = $this->msg( 'parentheses',
501 $lang->formatExpiry( $expiry ) )->escaped();
502 $message .= $this->msg( 'word-separator' )->escaped() . $formattedexpiry;
504 // Messages: restriction-edit, restriction-move, restriction-create,
505 // restriction-upload
506 $pageInfo['header-restrictions'][] = [
507 $this->msg( "restriction-$restrictionType" ), $message
511 if ( !$this->page
->exists() ) {
516 $pageInfo['header-edits'] = [];
518 $firstRev = $this->page
->getOldestRevision();
519 $lastRev = $this->page
->getRevision();
520 $batch = new LinkBatch
;
523 $firstRevUser = $firstRev->getUserText( Revision
::FOR_THIS_USER
);
524 if ( $firstRevUser !== '' ) {
525 $firstRevUserTitle = Title
::makeTitle( NS_USER
, $firstRevUser );
526 $batch->addObj( $firstRevUserTitle );
527 $batch->addObj( $firstRevUserTitle->getTalkPage() );
532 $lastRevUser = $lastRev->getUserText( Revision
::FOR_THIS_USER
);
533 if ( $lastRevUser !== '' ) {
534 $lastRevUserTitle = Title
::makeTitle( NS_USER
, $lastRevUser );
535 $batch->addObj( $lastRevUserTitle );
536 $batch->addObj( $lastRevUserTitle->getTalkPage() );
544 $pageInfo['header-edits'][] = [
545 $this->msg( 'pageinfo-firstuser' ),
546 Linker
::revUserTools( $firstRev )
549 // Date of page creation
550 $pageInfo['header-edits'][] = [
551 $this->msg( 'pageinfo-firsttime' ),
552 $linkRenderer->makeKnownLink(
554 $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ),
556 [ 'oldid' => $firstRev->getId() ]
563 $pageInfo['header-edits'][] = [
564 $this->msg( 'pageinfo-lastuser' ),
565 Linker
::revUserTools( $lastRev )
568 // Date of latest edit
569 $pageInfo['header-edits'][] = [
570 $this->msg( 'pageinfo-lasttime' ),
571 $linkRenderer->makeKnownLink(
573 $lang->userTimeAndDate( $this->page
->getTimestamp(), $user ),
575 [ 'oldid' => $this->page
->getLatest() ]
580 // Total number of edits
581 $pageInfo['header-edits'][] = [
582 $this->msg( 'pageinfo-edits' ), $lang->formatNum( $pageCounts['edits'] )
585 // Total number of distinct authors
586 if ( $pageCounts['authors'] > 0 ) {
587 $pageInfo['header-edits'][] = [
588 $this->msg( 'pageinfo-authors' ), $lang->formatNum( $pageCounts['authors'] )
592 // Recent number of edits (within past 30 days)
593 $pageInfo['header-edits'][] = [
594 $this->msg( 'pageinfo-recent-edits',
595 $lang->formatDuration( $config->get( 'RCMaxAge' ) ) ),
596 $lang->formatNum( $pageCounts['recent_edits'] )
599 // Recent number of distinct authors
600 $pageInfo['header-edits'][] = [
601 $this->msg( 'pageinfo-recent-authors' ),
602 $lang->formatNum( $pageCounts['recent_authors'] )
605 // Array of MagicWord objects
606 $magicWords = MagicWord
::getDoubleUnderscoreArray();
608 // Array of magic word IDs
609 $wordIDs = $magicWords->names
;
611 // Array of IDs => localized magic words
612 $localizedWords = $wgContLang->getMagicWords();
615 foreach ( $pageProperties as $property => $value ) {
616 if ( in_array( $property, $wordIDs ) ) {
617 $listItems[] = Html
::element( 'li', [], $localizedWords[$property][1] );
621 $localizedList = Html
::rawElement( 'ul', [], implode( '', $listItems ) );
622 $hiddenCategories = $this->page
->getHiddenCategories();
625 count( $listItems ) > 0 ||
626 count( $hiddenCategories ) > 0 ||
627 $pageCounts['transclusion']['from'] > 0 ||
628 $pageCounts['transclusion']['to'] > 0
630 $options = [ 'LIMIT' => $config->get( 'PageInfoTransclusionLimit' ) ];
631 $transcludedTemplates = $title->getTemplateLinksFrom( $options );
632 if ( $config->get( 'MiserMode' ) ) {
633 $transcludedTargets = [];
635 $transcludedTargets = $title->getTemplateLinksTo( $options );
639 $pageInfo['header-properties'] = [];
642 if ( count( $listItems ) > 0 ) {
643 $pageInfo['header-properties'][] = [
644 $this->msg( 'pageinfo-magic-words' )->numParams( count( $listItems ) ),
650 if ( count( $hiddenCategories ) > 0 ) {
651 $pageInfo['header-properties'][] = [
652 $this->msg( 'pageinfo-hidden-categories' )
653 ->numParams( count( $hiddenCategories ) ),
654 Linker
::formatHiddenCategories( $hiddenCategories )
658 // Transcluded templates
659 if ( $pageCounts['transclusion']['from'] > 0 ) {
660 if ( $pageCounts['transclusion']['from'] > count( $transcludedTemplates ) ) {
661 $more = $this->msg( 'morenotlisted' )->escaped();
666 $templateListFormatter = new TemplatesOnThisPageFormatter(
671 $pageInfo['header-properties'][] = [
672 $this->msg( 'pageinfo-templates' )
673 ->numParams( $pageCounts['transclusion']['from'] ),
674 $templateListFormatter->format( $transcludedTemplates, false, $more )
678 if ( !$config->get( 'MiserMode' ) && $pageCounts['transclusion']['to'] > 0 ) {
679 if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) {
680 $more = $linkRenderer->makeLink(
682 $this->msg( 'moredotdotdot' )->text(),
684 [ 'hidelinks' => 1, 'hideredirs' => 1 ]
690 $templateListFormatter = new TemplatesOnThisPageFormatter(
695 $pageInfo['header-properties'][] = [
696 $this->msg( 'pageinfo-transclusions' )
697 ->numParams( $pageCounts['transclusion']['to'] ),
698 $templateListFormatter->format( $transcludedTargets, false, $more )
707 * Returns page counts that would be too "expensive" to retrieve by normal means.
709 * @param WikiPage|Article|Page $page
712 protected function pageCounts( Page
$page ) {
714 $config = $this->context
->getConfig();
715 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
717 return $cache->getWithSetCallback(
718 self
::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ),
719 WANObjectCache
::TTL_WEEK
,
720 function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
721 global $wgActorTableSchemaMigrationStage;
723 $title = $page->getTitle();
724 $id = $title->getArticleID();
726 $dbr = wfGetDB( DB_REPLICA
);
727 $dbrWatchlist = wfGetDB( DB_REPLICA
, 'watchlist' );
728 $setOpts +
= Database
::getCacheSetOptions( $dbr, $dbrWatchlist );
730 if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW
) {
731 $tables = [ 'revision_actor_temp' ];
732 $field = 'revactor_actor';
733 $pageField = 'revactor_page';
734 $tsField = 'revactor_timestamp';
736 } elseif ( $wgActorTableSchemaMigrationStage === MIGRATION_OLD
) {
737 $tables = [ 'revision' ];
738 $field = 'rev_user_text';
739 $pageField = 'rev_page';
740 $tsField = 'rev_timestamp';
743 $tables = [ 'revision', 'revision_actor_temp', 'actor' ];
744 $field = 'COALESCE( actor_name, rev_user_text)';
745 $pageField = 'rev_page';
746 $tsField = 'rev_timestamp';
748 'revision_actor_temp' => [ 'LEFT JOIN', 'revactor_rev = rev_id' ],
749 'actor' => [ 'LEFT JOIN', 'revactor_actor = actor_id' ],
753 $watchedItemStore = MediaWikiServices
::getInstance()->getWatchedItemStore();
756 $result['watchers'] = $watchedItemStore->countWatchers( $title );
758 if ( $config->get( 'ShowUpdatedMarker' ) ) {
759 $updated = wfTimestamp( TS_UNIX
, $page->getTimestamp() );
760 $result['visitingWatchers'] = $watchedItemStore->countVisitingWatchers(
762 $updated - $config->get( 'WatchersMaxAge' )
766 // Total number of edits
767 $edits = (int)$dbr->selectField(
770 [ 'rev_page' => $id ],
773 $result['edits'] = $edits;
775 // Total number of distinct authors
776 if ( $config->get( 'MiserMode' ) ) {
777 $result['authors'] = 0;
779 $result['authors'] = (int)$dbr->selectField(
781 "COUNT(DISTINCT $field)",
782 [ $pageField => $id ],
789 // "Recent" threshold defined by RCMaxAge setting
790 $threshold = $dbr->timestamp( time() - $config->get( 'RCMaxAge' ) );
792 // Recent number of edits
793 $edits = (int)$dbr->selectField(
798 "rev_timestamp >= " . $dbr->addQuotes( $threshold )
802 $result['recent_edits'] = $edits;
804 // Recent number of distinct authors
805 $result['recent_authors'] = (int)$dbr->selectField(
807 "COUNT(DISTINCT $field)",
810 "$tsField >= " . $dbr->addQuotes( $threshold )
817 // Subpages (if enabled)
818 if ( MWNamespace
::hasSubpages( $title->getNamespace() ) ) {
819 $conds = [ 'page_namespace' => $title->getNamespace() ];
820 $conds[] = 'page_title ' .
821 $dbr->buildLike( $title->getDBkey() . '/', $dbr->anyString() );
823 // Subpages of this page (redirects)
824 $conds['page_is_redirect'] = 1;
825 $result['subpages']['redirects'] = (int)$dbr->selectField(
832 // Subpages of this page (non-redirects)
833 $conds['page_is_redirect'] = 0;
834 $result['subpages']['nonredirects'] = (int)$dbr->selectField(
841 // Subpages of this page (total)
842 $result['subpages']['total'] = $result['subpages']['redirects']
843 +
$result['subpages']['nonredirects'];
846 // Counts for the number of transclusion links (to/from)
847 if ( $config->get( 'MiserMode' ) ) {
848 $result['transclusion']['to'] = 0;
850 $result['transclusion']['to'] = (int)$dbr->selectField(
854 'tl_namespace' => $title->getNamespace(),
855 'tl_title' => $title->getDBkey()
861 $result['transclusion']['from'] = (int)$dbr->selectField(
864 [ 'tl_from' => $title->getArticleID() ],
874 * Returns the name that goes in the "<h1>" page title.
878 protected function getPageTitle() {
879 return $this->msg( 'pageinfo-title', $this->getTitle()->getPrefixedText() )->text();
883 * Get a list of contributors of $article
884 * @return string Html
886 protected function getContributors() {
887 $contributors = $this->page
->getContributors();
891 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
893 # Sift for real versus user names
894 /** @var User $user */
895 foreach ( $contributors as $user ) {
896 $page = $user->isAnon()
897 ? SpecialPage
::getTitleFor( 'Contributions', $user->getName() )
898 : $user->getUserPage();
900 $hiddenPrefs = $this->context
->getConfig()->get( 'HiddenPrefs' );
901 if ( $user->getId() == 0 ) {
902 $anon_ips[] = $linkRenderer->makeLink( $page, $user->getName() );
903 } elseif ( !in_array( 'realname', $hiddenPrefs ) && $user->getRealName() ) {
904 $real_names[] = $linkRenderer->makeLink( $page, $user->getRealName() );
906 $user_names[] = $linkRenderer->makeLink( $page, $user->getName() );
910 $lang = $this->getLanguage();
912 $real = $lang->listToText( $real_names );
914 # "ThisSite user(s) A, B and C"
915 if ( count( $user_names ) ) {
916 $user = $this->msg( 'siteusers' )
917 ->rawParams( $lang->listToText( $user_names ) )
918 ->params( count( $user_names ) )->escaped();
923 if ( count( $anon_ips ) ) {
924 $anon = $this->msg( 'anonusers' )
925 ->rawParams( $lang->listToText( $anon_ips ) )
926 ->params( count( $anon_ips ) )->escaped();
931 # This is the big list, all mooshed together. We sift for blank strings
933 foreach ( [ $real, $user, $anon ] as $s ) {
935 array_push( $fulllist, $s );
939 $count = count( $fulllist );
941 # "Based on work by ..."
943 ?
$this->msg( 'othercontribs' )->rawParams(
944 $lang->listToText( $fulllist ) )->params( $count )->escaped()
949 * Returns the description that goes below the "<h1>" tag.
953 protected function getDescription() {
958 * @param WANObjectCache $cache
959 * @param Title $title
963 protected static function getCacheKey( WANObjectCache
$cache, Title
$title, $revId ) {
964 return $cache->makeKey( 'infoaction', md5( $title->getPrefixedText() ), $revId, self
::VERSION
);