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}"
136 foreach ( $infoTable as $infoRow ) {
137 if ( $infoRow[0] == "below" ) {
138 $below = $infoRow[1] . "\n";
141 $name = ( $infoRow[0] instanceof Message
) ?
$infoRow[0]->escaped() : $infoRow[0];
142 $value = ( $infoRow[1] instanceof Message
) ?
$infoRow[1]->escaped() : $infoRow[1];
143 $id = ( $infoRow[0] instanceof Message
) ?
$infoRow[0]->getKey() : null;
144 $table = $this->addRow( $table, $name, $value, $id ) . "\n";
146 $content = $this->addTable( $content, $table ) . "\n" . $below;
150 if ( !$this->msg( 'pageinfo-footer' )->isDisabled() ) {
151 $content .= $this->msg( 'pageinfo-footer' )->parse();
158 * Creates a header that can be added to the output.
160 * @param string $header The header text.
161 * @param string $canonicalId
162 * @return string The HTML.
164 protected function makeHeader( $header, $canonicalId ) {
165 $spanAttribs = [ 'class' => 'mw-headline', 'id' => Sanitizer
::escapeIdForAttribute( $header ) ];
166 $h2Attribs = [ 'id' => Sanitizer
::escapeIdForAttribute( $canonicalId ) ];
168 return Html
::rawElement( 'h2', $h2Attribs, Html
::element( 'span', $spanAttribs, $header ) );
172 * Adds a row to a table that will be added to the content.
174 * @param string $table The table that will be added to the content
175 * @param string $name The name of the row
176 * @param string $value The value of the row
177 * @param string|null $id The ID to use for the 'tr' element
178 * @return string The table with the row added
180 protected function addRow( $table, $name, $value, $id ) {
184 $id === null ?
[] : [ 'id' => 'mw-' . $id ],
185 Html
::rawElement( 'td', [ 'style' => 'vertical-align: top;' ], $name ) .
186 Html
::rawElement( 'td', [], $value )
191 * Adds a table to the content that will be added to the output.
193 * @param string $content The content that will be added to the output
194 * @param string $table
195 * @return string The content with the table added
197 protected function addTable( $content, $table ) {
198 return $content . Html
::rawElement( 'table', [ 'class' => 'wikitable mw-page-info' ],
203 * Returns an array of info groups (will be rendered as tables), keyed by group ID.
204 * Group IDs are arbitrary and used so that extensions may add additional information in
205 * arbitrary positions (and as message keys for section headers for the tables, prefixed
207 * Each info group is a non-associative array of info items (rendered as table rows).
208 * Each info item is an array with two elements: the first describes the type of
209 * information, the second the value for the current page. Both can be strings (will be
210 * interpreted as raw HTML) or messages (will be interpreted as plain text and escaped).
214 protected function pageInfo() {
215 $services = MediaWikiServices
::getInstance();
217 $user = $this->getUser();
218 $lang = $this->getLanguage();
219 $title = $this->getTitle();
220 $id = $title->getArticleID();
221 $config = $this->context
->getConfig();
222 $linkRenderer = $services->getLinkRenderer();
224 $pageCounts = $this->pageCounts( $this->page
);
226 $props = PageProps
::getInstance()->getAllProperties( $title );
227 $pageProperties = $props[$id] ??
[];
231 $pageInfo['header-basic'] = [];
234 $displayTitle = $pageProperties['displaytitle'] ??
$title->getPrefixedText();
236 $pageInfo['header-basic'][] = [
237 $this->msg( 'pageinfo-display-title' ), $displayTitle
240 // Is it a redirect? If so, where to?
241 $redirectTarget = $this->page
->getRedirectTarget();
242 if ( $redirectTarget !== null ) {
243 $pageInfo['header-basic'][] = [
244 $this->msg( 'pageinfo-redirectsto' ),
245 $linkRenderer->makeLink( $redirectTarget ) .
246 $this->msg( 'word-separator' )->escaped() .
247 $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
249 $this->msg( 'pageinfo-redirectsto-info' )->text(),
251 [ 'action' => 'info' ]
257 $sortKey = $pageProperties['defaultsort'] ??
$title->getCategorySortkey();
259 $sortKey = htmlspecialchars( $sortKey );
260 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-default-sort' ), $sortKey ];
262 // Page length (in bytes)
263 $pageInfo['header-basic'][] = [
264 $this->msg( 'pageinfo-length' ), $lang->formatNum( $title->getLength() )
268 $pageNamespace = $title->getNsText();
269 if ( $pageNamespace ) {
270 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-namespace' ), $pageNamespace ];
273 // Page ID (number not localised, as it's a database ID)
274 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-article-id' ), $id ];
276 // Language in which the page content is (supposed to be) written
277 $pageLang = $title->getPageLanguage()->getCode();
279 $pageLangHtml = $pageLang . ' - ' .
280 Language
::fetchLanguageName( $pageLang, $lang->getCode() );
281 // Link to Special:PageLanguage with pre-filled page title if user has permissions
282 if ( $config->get( 'PageLanguageUseDB' )
283 && $title->userCan( 'pagelang', $user )
285 $pageLangHtml .= ' ' . $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
286 SpecialPage
::getTitleValueFor( 'PageLanguage', $title->getPrefixedText() ),
287 $this->msg( 'pageinfo-language-change' )->text()
291 $pageInfo['header-basic'][] = [
292 $this->msg( 'pageinfo-language' )->escaped(),
296 // Content model of the page
297 $modelHtml = htmlspecialchars( ContentHandler
::getLocalizedName( $title->getContentModel() ) );
298 // If the user can change it, add a link to Special:ChangeContentModel
299 if ( $config->get( 'ContentHandlerUseDB' )
300 && $title->userCan( 'editcontentmodel', $user )
302 $modelHtml .= ' ' . $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
303 SpecialPage
::getTitleValueFor( 'ChangeContentModel', $title->getPrefixedText() ),
304 $this->msg( 'pageinfo-content-model-change' )->text()
308 $pageInfo['header-basic'][] = [
309 $this->msg( 'pageinfo-content-model' ),
313 if ( $title->inNamespace( NS_USER
) ) {
314 $pageUser = User
::newFromName( $title->getRootText() );
315 if ( $pageUser && $pageUser->getId() && !$pageUser->isHidden() ) {
316 $pageInfo['header-basic'][] = [
317 $this->msg( 'pageinfo-user-id' ),
323 // Search engine status
324 $pOutput = new ParserOutput();
325 if ( isset( $pageProperties['noindex'] ) ) {
326 $pOutput->setIndexPolicy( 'noindex' );
328 if ( isset( $pageProperties['index'] ) ) {
329 $pOutput->setIndexPolicy( 'index' );
332 // Use robot policy logic
333 $policy = $this->page
->getRobotPolicy( 'view', $pOutput );
334 $pageInfo['header-basic'][] = [
335 // Messages: pageinfo-robot-index, pageinfo-robot-noindex
336 $this->msg( 'pageinfo-robot-policy' ),
337 $this->msg( "pageinfo-robot-${policy['index']}" )
340 $unwatchedPageThreshold = $config->get( 'UnwatchedPageThreshold' );
342 $user->isAllowed( 'unwatchedpages' ) ||
343 ( $unwatchedPageThreshold !== false &&
344 $pageCounts['watchers'] >= $unwatchedPageThreshold )
346 // Number of page watchers
347 $pageInfo['header-basic'][] = [
348 $this->msg( 'pageinfo-watchers' ),
349 $lang->formatNum( $pageCounts['watchers'] )
352 $config->get( 'ShowUpdatedMarker' ) &&
353 isset( $pageCounts['visitingWatchers'] )
355 $minToDisclose = $config->get( 'UnwatchedPageSecret' );
356 if ( $pageCounts['visitingWatchers'] > $minToDisclose ||
357 $user->isAllowed( 'unwatchedpages' ) ) {
358 $pageInfo['header-basic'][] = [
359 $this->msg( 'pageinfo-visiting-watchers' ),
360 $lang->formatNum( $pageCounts['visitingWatchers'] )
363 $pageInfo['header-basic'][] = [
364 $this->msg( 'pageinfo-visiting-watchers' ),
365 $this->msg( 'pageinfo-few-visiting-watchers' )
369 } elseif ( $unwatchedPageThreshold !== false ) {
370 $pageInfo['header-basic'][] = [
371 $this->msg( 'pageinfo-watchers' ),
372 $this->msg( 'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
376 // Redirects to this page
377 $whatLinksHere = SpecialPage
::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
378 $pageInfo['header-basic'][] = [
379 $linkRenderer->makeLink(
381 $this->msg( 'pageinfo-redirects-name' )->text(),
386 'hideimages' => $title->getNamespace() == NS_FILE
389 $this->msg( 'pageinfo-redirects-value' )
390 ->numParams( count( $title->getRedirectsHere() ) )
393 // Is it counted as a content page?
394 if ( $this->page
->isCountable() ) {
395 $pageInfo['header-basic'][] = [
396 $this->msg( 'pageinfo-contentpage' ),
397 $this->msg( 'pageinfo-contentpage-yes' )
401 // Subpages of this page, if subpages are enabled for the current NS
402 if ( MWNamespace
::hasSubpages( $title->getNamespace() ) ) {
403 $prefixIndex = SpecialPage
::getTitleFor(
404 'Prefixindex', $title->getPrefixedText() . '/' );
405 $pageInfo['header-basic'][] = [
406 $linkRenderer->makeLink(
408 $this->msg( 'pageinfo-subpages-name' )->text()
410 $this->msg( 'pageinfo-subpages-value' )
412 $pageCounts['subpages']['total'],
413 $pageCounts['subpages']['redirects'],
414 $pageCounts['subpages']['nonredirects'] )
418 if ( $title->inNamespace( NS_CATEGORY
) ) {
419 $category = Category
::newFromTitle( $title );
421 // $allCount is the total number of cat members,
422 // not the count of how many members are normal pages.
423 $allCount = (int)$category->getPageCount();
424 $subcatCount = (int)$category->getSubcatCount();
425 $fileCount = (int)$category->getFileCount();
426 $pagesCount = $allCount - $subcatCount - $fileCount;
428 $pageInfo['category-info'] = [
430 $this->msg( 'pageinfo-category-total' ),
431 $lang->formatNum( $allCount )
434 $this->msg( 'pageinfo-category-pages' ),
435 $lang->formatNum( $pagesCount )
438 $this->msg( 'pageinfo-category-subcats' ),
439 $lang->formatNum( $subcatCount )
442 $this->msg( 'pageinfo-category-files' ),
443 $lang->formatNum( $fileCount )
448 // Display image SHA-1 value
449 if ( $title->inNamespace( NS_FILE
) ) {
450 $fileObj = wfFindFile( $title );
451 if ( $fileObj !== false ) {
452 // Convert the base-36 sha1 value obtained from database to base-16
453 $output = Wikimedia\base_convert
( $fileObj->getSha1(), 36, 16, 40 );
454 $pageInfo['header-basic'][] = [
455 $this->msg( 'pageinfo-file-hash' ),
462 $pageInfo['header-restrictions'] = [];
464 // Is this page affected by the cascading protection of something which includes it?
465 if ( $title->isCascadeProtected() ) {
467 $sources = $title->getCascadeProtectionSources()[0];
469 foreach ( $sources as $sourceTitle ) {
470 $cascadingFrom .= Html
::rawElement(
471 'li', [], $linkRenderer->makeKnownLink( $sourceTitle ) );
474 $cascadingFrom = Html
::rawElement( 'ul', [], $cascadingFrom );
475 $pageInfo['header-restrictions'][] = [
476 $this->msg( 'pageinfo-protect-cascading-from' ),
481 // Is out protection set to cascade to other pages?
482 if ( $title->areRestrictionsCascading() ) {
483 $pageInfo['header-restrictions'][] = [
484 $this->msg( 'pageinfo-protect-cascading' ),
485 $this->msg( 'pageinfo-protect-cascading-yes' )
490 foreach ( $title->getRestrictionTypes() as $restrictionType ) {
491 $protectionLevel = implode( ', ', $title->getRestrictions( $restrictionType ) );
493 if ( $protectionLevel == '' ) {
495 $message = $this->msg( 'protect-default' )->escaped();
497 // Administrators only
498 // Messages: protect-level-autoconfirmed, protect-level-sysop
499 $message = $this->msg( "protect-level-$protectionLevel" );
500 if ( $message->isDisabled() ) {
501 // Require "$1" permission
502 $message = $this->msg( "protect-fallback", $protectionLevel )->parse();
504 $message = $message->escaped();
507 $expiry = $title->getRestrictionExpiry( $restrictionType );
508 $formattedexpiry = $this->msg( 'parentheses',
509 $lang->formatExpiry( $expiry ) )->escaped();
510 $message .= $this->msg( 'word-separator' )->escaped() . $formattedexpiry;
512 // Messages: restriction-edit, restriction-move, restriction-create,
513 // restriction-upload
514 $pageInfo['header-restrictions'][] = [
515 $this->msg( "restriction-$restrictionType" ), $message
518 $protectLog = SpecialPage
::getTitleFor( 'Log' );
519 $pageInfo['header-restrictions'][] = [
521 $linkRenderer->makeKnownLink(
523 $this->msg( 'pageinfo-view-protect-log' )->text(),
525 [ 'type' => 'protect', 'page' => $title->getPrefixedText() ]
529 if ( !$this->page
->exists() ) {
534 $pageInfo['header-edits'] = [];
536 $firstRev = $this->page
->getOldestRevision();
537 $lastRev = $this->page
->getRevision();
538 $batch = new LinkBatch
;
541 $firstRevUser = $firstRev->getUserText( Revision
::FOR_THIS_USER
);
542 if ( $firstRevUser !== '' ) {
543 $firstRevUserTitle = Title
::makeTitle( NS_USER
, $firstRevUser );
544 $batch->addObj( $firstRevUserTitle );
545 $batch->addObj( $firstRevUserTitle->getTalkPage() );
550 $lastRevUser = $lastRev->getUserText( Revision
::FOR_THIS_USER
);
551 if ( $lastRevUser !== '' ) {
552 $lastRevUserTitle = Title
::makeTitle( NS_USER
, $lastRevUser );
553 $batch->addObj( $lastRevUserTitle );
554 $batch->addObj( $lastRevUserTitle->getTalkPage() );
562 $pageInfo['header-edits'][] = [
563 $this->msg( 'pageinfo-firstuser' ),
564 Linker
::revUserTools( $firstRev )
567 // Date of page creation
568 $pageInfo['header-edits'][] = [
569 $this->msg( 'pageinfo-firsttime' ),
570 $linkRenderer->makeKnownLink(
572 $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ),
574 [ 'oldid' => $firstRev->getId() ]
581 $pageInfo['header-edits'][] = [
582 $this->msg( 'pageinfo-lastuser' ),
583 Linker
::revUserTools( $lastRev )
586 // Date of latest edit
587 $pageInfo['header-edits'][] = [
588 $this->msg( 'pageinfo-lasttime' ),
589 $linkRenderer->makeKnownLink(
591 $lang->userTimeAndDate( $this->page
->getTimestamp(), $user ),
593 [ 'oldid' => $this->page
->getLatest() ]
598 // Total number of edits
599 $pageInfo['header-edits'][] = [
600 $this->msg( 'pageinfo-edits' ), $lang->formatNum( $pageCounts['edits'] )
603 // Total number of distinct authors
604 if ( $pageCounts['authors'] > 0 ) {
605 $pageInfo['header-edits'][] = [
606 $this->msg( 'pageinfo-authors' ), $lang->formatNum( $pageCounts['authors'] )
610 // Recent number of edits (within past 30 days)
611 $pageInfo['header-edits'][] = [
612 $this->msg( 'pageinfo-recent-edits',
613 $lang->formatDuration( $config->get( 'RCMaxAge' ) ) ),
614 $lang->formatNum( $pageCounts['recent_edits'] )
617 // Recent number of distinct authors
618 $pageInfo['header-edits'][] = [
619 $this->msg( 'pageinfo-recent-authors' ),
620 $lang->formatNum( $pageCounts['recent_authors'] )
623 // Array of MagicWord objects
624 $magicWords = $services->getMagicWordFactory()->getDoubleUnderscoreArray();
626 // Array of magic word IDs
627 $wordIDs = $magicWords->names
;
629 // Array of IDs => localized magic words
630 $localizedWords = $services->getContentLanguage()->getMagicWords();
633 foreach ( $pageProperties as $property => $value ) {
634 if ( in_array( $property, $wordIDs ) ) {
635 $listItems[] = Html
::element( 'li', [], $localizedWords[$property][1] );
639 $localizedList = Html
::rawElement( 'ul', [], implode( '', $listItems ) );
640 $hiddenCategories = $this->page
->getHiddenCategories();
643 count( $listItems ) > 0 ||
644 count( $hiddenCategories ) > 0 ||
645 $pageCounts['transclusion']['from'] > 0 ||
646 $pageCounts['transclusion']['to'] > 0
648 $options = [ 'LIMIT' => $config->get( 'PageInfoTransclusionLimit' ) ];
649 $transcludedTemplates = $title->getTemplateLinksFrom( $options );
650 if ( $config->get( 'MiserMode' ) ) {
651 $transcludedTargets = [];
653 $transcludedTargets = $title->getTemplateLinksTo( $options );
657 $pageInfo['header-properties'] = [];
660 if ( count( $listItems ) > 0 ) {
661 $pageInfo['header-properties'][] = [
662 $this->msg( 'pageinfo-magic-words' )->numParams( count( $listItems ) ),
668 if ( count( $hiddenCategories ) > 0 ) {
669 $pageInfo['header-properties'][] = [
670 $this->msg( 'pageinfo-hidden-categories' )
671 ->numParams( count( $hiddenCategories ) ),
672 Linker
::formatHiddenCategories( $hiddenCategories )
676 // Transcluded templates
677 if ( $pageCounts['transclusion']['from'] > 0 ) {
678 if ( $pageCounts['transclusion']['from'] > count( $transcludedTemplates ) ) {
679 $more = $this->msg( 'morenotlisted' )->escaped();
684 $templateListFormatter = new TemplatesOnThisPageFormatter(
689 $pageInfo['header-properties'][] = [
690 $this->msg( 'pageinfo-templates' )
691 ->numParams( $pageCounts['transclusion']['from'] ),
692 $templateListFormatter->format( $transcludedTemplates, false, $more )
696 if ( !$config->get( 'MiserMode' ) && $pageCounts['transclusion']['to'] > 0 ) {
697 if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) {
698 $more = $linkRenderer->makeLink(
700 $this->msg( 'moredotdotdot' )->text(),
702 [ 'hidelinks' => 1, 'hideredirs' => 1 ]
708 $templateListFormatter = new TemplatesOnThisPageFormatter(
713 $pageInfo['header-properties'][] = [
714 $this->msg( 'pageinfo-transclusions' )
715 ->numParams( $pageCounts['transclusion']['to'] ),
716 $templateListFormatter->format( $transcludedTargets, false, $more )
725 * Returns page counts that would be too "expensive" to retrieve by normal means.
727 * @param WikiPage|Article|Page $page
730 protected function pageCounts( Page
$page ) {
732 $config = $this->context
->getConfig();
733 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
735 return $cache->getWithSetCallback(
736 self
::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ),
737 WANObjectCache
::TTL_WEEK
,
738 function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
739 global $wgActorTableSchemaMigrationStage;
741 $title = $page->getTitle();
742 $id = $title->getArticleID();
744 $dbr = wfGetDB( DB_REPLICA
);
745 $dbrWatchlist = wfGetDB( DB_REPLICA
, 'watchlist' );
746 $setOpts +
= Database
::getCacheSetOptions( $dbr, $dbrWatchlist );
748 if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_READ_NEW
) {
749 $tables = [ 'revision_actor_temp' ];
750 $field = 'revactor_actor';
751 $pageField = 'revactor_page';
752 $tsField = 'revactor_timestamp';
755 $tables = [ 'revision' ];
756 $field = 'rev_user_text';
757 $pageField = 'rev_page';
758 $tsField = 'rev_timestamp';
762 $watchedItemStore = MediaWikiServices
::getInstance()->getWatchedItemStore();
765 $result['watchers'] = $watchedItemStore->countWatchers( $title );
767 if ( $config->get( 'ShowUpdatedMarker' ) ) {
768 $updated = wfTimestamp( TS_UNIX
, $page->getTimestamp() );
769 $result['visitingWatchers'] = $watchedItemStore->countVisitingWatchers(
771 $updated - $config->get( 'WatchersMaxAge' )
775 // Total number of edits
776 $edits = (int)$dbr->selectField(
779 [ 'rev_page' => $id ],
782 $result['edits'] = $edits;
784 // Total number of distinct authors
785 if ( $config->get( 'MiserMode' ) ) {
786 $result['authors'] = 0;
788 $result['authors'] = (int)$dbr->selectField(
790 "COUNT(DISTINCT $field)",
791 [ $pageField => $id ],
798 // "Recent" threshold defined by RCMaxAge setting
799 $threshold = $dbr->timestamp( time() - $config->get( 'RCMaxAge' ) );
801 // Recent number of edits
802 $edits = (int)$dbr->selectField(
807 "rev_timestamp >= " . $dbr->addQuotes( $threshold )
811 $result['recent_edits'] = $edits;
813 // Recent number of distinct authors
814 $result['recent_authors'] = (int)$dbr->selectField(
816 "COUNT(DISTINCT $field)",
819 "$tsField >= " . $dbr->addQuotes( $threshold )
826 // Subpages (if enabled)
827 if ( MWNamespace
::hasSubpages( $title->getNamespace() ) ) {
828 $conds = [ 'page_namespace' => $title->getNamespace() ];
829 $conds[] = 'page_title ' .
830 $dbr->buildLike( $title->getDBkey() . '/', $dbr->anyString() );
832 // Subpages of this page (redirects)
833 $conds['page_is_redirect'] = 1;
834 $result['subpages']['redirects'] = (int)$dbr->selectField(
841 // Subpages of this page (non-redirects)
842 $conds['page_is_redirect'] = 0;
843 $result['subpages']['nonredirects'] = (int)$dbr->selectField(
850 // Subpages of this page (total)
851 $result['subpages']['total'] = $result['subpages']['redirects']
852 +
$result['subpages']['nonredirects'];
855 // Counts for the number of transclusion links (to/from)
856 if ( $config->get( 'MiserMode' ) ) {
857 $result['transclusion']['to'] = 0;
859 $result['transclusion']['to'] = (int)$dbr->selectField(
863 'tl_namespace' => $title->getNamespace(),
864 'tl_title' => $title->getDBkey()
870 $result['transclusion']['from'] = (int)$dbr->selectField(
873 [ 'tl_from' => $title->getArticleID() ],
883 * Returns the name that goes in the "<h1>" page title.
887 protected function getPageTitle() {
888 return $this->msg( 'pageinfo-title', $this->getTitle()->getPrefixedText() )->text();
892 * Get a list of contributors of $article
893 * @return string Html
895 protected function getContributors() {
896 $contributors = $this->page
->getContributors();
900 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
902 # Sift for real versus user names
903 /** @var User $user */
904 foreach ( $contributors as $user ) {
905 $page = $user->isAnon()
906 ? SpecialPage
::getTitleFor( 'Contributions', $user->getName() )
907 : $user->getUserPage();
909 $hiddenPrefs = $this->context
->getConfig()->get( 'HiddenPrefs' );
910 if ( $user->getId() == 0 ) {
911 $anon_ips[] = $linkRenderer->makeLink( $page, $user->getName() );
912 } elseif ( !in_array( 'realname', $hiddenPrefs ) && $user->getRealName() ) {
913 $real_names[] = $linkRenderer->makeLink( $page, $user->getRealName() );
915 $user_names[] = $linkRenderer->makeLink( $page, $user->getName() );
919 $lang = $this->getLanguage();
921 $real = $lang->listToText( $real_names );
923 # "ThisSite user(s) A, B and C"
924 if ( count( $user_names ) ) {
925 $user = $this->msg( 'siteusers' )
926 ->rawParams( $lang->listToText( $user_names ) )
927 ->params( count( $user_names ) )->escaped();
932 if ( count( $anon_ips ) ) {
933 $anon = $this->msg( 'anonusers' )
934 ->rawParams( $lang->listToText( $anon_ips ) )
935 ->params( count( $anon_ips ) )->escaped();
940 # This is the big list, all mooshed together. We sift for blank strings
942 foreach ( [ $real, $user, $anon ] as $s ) {
944 array_push( $fulllist, $s );
948 $count = count( $fulllist );
950 # "Based on work by ..."
952 ?
$this->msg( 'othercontribs' )->rawParams(
953 $lang->listToText( $fulllist ) )->params( $count )->escaped()
958 * Returns the description that goes below the "<h1>" tag.
962 protected function getDescription() {
967 * @param WANObjectCache $cache
968 * @param Title $title
972 protected static function getCacheKey( WANObjectCache
$cache, Title
$title, $revId ) {
973 return $cache->makeKey( 'infoaction', md5( $title->getPrefixedText() ), $revId, self
::VERSION
);