Expose $wgMaxArticleSize in siteinfo query api
[mediawiki.git] / includes / actions / InfoAction.php
blob7be2aa7566776803af1dd9255c170c21c9dfa8c5
1 <?php
2 /**
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
21 * @file
22 * @ingroup Actions
25 use MediaWiki\MediaWikiServices;
27 /**
28 * Displays information about a page.
30 * @ingroup Actions
32 class InfoAction extends FormlessAction {
33 const VERSION = 1;
35 /**
36 * Returns the name of the action this object responds to.
38 * @return string Lowercase name
40 public function getName() {
41 return 'info';
44 /**
45 * Whether this action can still be executed by a blocked user.
47 * @return bool
49 public function requiresUnblock() {
50 return false;
53 /**
54 * Whether this action requires the wiki not to be locked.
56 * @return bool
58 public function requiresWrite() {
59 return false;
62 /**
63 * Clear the info cache for a given Title.
65 * @since 1.22
66 * @param Title $title Title to clear cache for
67 * @param int|null $revid Revision id to clear
69 public static function invalidateCache( Title $title, $revid = null ) {
70 if ( !$revid ) {
71 $revision = Revision::newFromTitle( $title, 0, Revision::READ_LATEST );
72 $revid = $revision ? $revision->getId() : null;
74 if ( $revid !== null ) {
75 $key = self::getCacheKey( $title, $revid );
76 ObjectCache::getMainWANInstance()->delete( $key );
80 /**
81 * Shows page information on GET request.
83 * @return string Page information that will be added to the output
85 public function onView() {
86 $content = '';
88 // Validate revision
89 $oldid = $this->page->getOldID();
90 if ( $oldid ) {
91 $revision = $this->page->getRevisionFetched();
93 // Revision is missing
94 if ( $revision === null ) {
95 return $this->msg( 'missing-revision', $oldid )->parse();
98 // Revision is not current
99 if ( !$revision->isCurrent() ) {
100 return $this->msg( 'pageinfo-not-current' )->plain();
104 // Page header
105 if ( !$this->msg( 'pageinfo-header' )->isDisabled() ) {
106 $content .= $this->msg( 'pageinfo-header' )->parse();
109 // Hide "This page is a member of # hidden categories" explanation
110 $content .= Html::element( 'style', [],
111 '.mw-hiddenCategoriesExplanation { display: none; }' ) . "\n";
113 // Hide "Templates used on this page" explanation
114 $content .= Html::element( 'style', [],
115 '.mw-templatesUsedExplanation { display: none; }' ) . "\n";
117 // Get page information
118 $pageInfo = $this->pageInfo();
120 // Allow extensions to add additional information
121 Hooks::run( 'InfoAction', [ $this->getContext(), &$pageInfo ] );
123 // Render page information
124 foreach ( $pageInfo as $header => $infoTable ) {
125 // Messages:
126 // pageinfo-header-basic, pageinfo-header-edits, pageinfo-header-restrictions,
127 // pageinfo-header-properties, pageinfo-category-info
128 $content .= $this->makeHeader( $this->msg( "pageinfo-${header}" )->escaped() ) . "\n";
129 $table = "\n";
130 foreach ( $infoTable as $infoRow ) {
131 $name = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->escaped() : $infoRow[0];
132 $value = ( $infoRow[1] instanceof Message ) ? $infoRow[1]->escaped() : $infoRow[1];
133 $id = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->getKey() : null;
134 $table = $this->addRow( $table, $name, $value, $id ) . "\n";
136 $content = $this->addTable( $content, $table ) . "\n";
139 // Page footer
140 if ( !$this->msg( 'pageinfo-footer' )->isDisabled() ) {
141 $content .= $this->msg( 'pageinfo-footer' )->parse();
144 return $content;
148 * Creates a header that can be added to the output.
150 * @param string $header The header text.
151 * @return string The HTML.
153 protected function makeHeader( $header ) {
154 $spanAttribs = [ 'class' => 'mw-headline', 'id' => Sanitizer::escapeId( $header ) ];
156 return Html::rawElement( 'h2', [], Html::element( 'span', $spanAttribs, $header ) );
160 * Adds a row to a table that will be added to the content.
162 * @param string $table The table that will be added to the content
163 * @param string $name The name of the row
164 * @param string $value The value of the row
165 * @param string $id The ID to use for the 'tr' element
166 * @return string The table with the row added
168 protected function addRow( $table, $name, $value, $id ) {
169 return $table .
170 Html::rawElement(
171 'tr',
172 $id === null ? [] : [ 'id' => 'mw-' . $id ],
173 Html::rawElement( 'td', [ 'style' => 'vertical-align: top;' ], $name ) .
174 Html::rawElement( 'td', [], $value )
179 * Adds a table to the content that will be added to the output.
181 * @param string $content The content that will be added to the output
182 * @param string $table The table
183 * @return string The content with the table added
185 protected function addTable( $content, $table ) {
186 return $content . Html::rawElement( 'table', [ 'class' => 'wikitable mw-page-info' ],
187 $table );
191 * Returns page information in an easily-manipulated format. Array keys are used so extensions
192 * may add additional information in arbitrary positions. Array values are arrays with one
193 * element to be rendered as a header, arrays with two elements to be rendered as a table row.
195 * @return array
197 protected function pageInfo() {
198 global $wgContLang;
200 $user = $this->getUser();
201 $lang = $this->getLanguage();
202 $title = $this->getTitle();
203 $id = $title->getArticleID();
204 $config = $this->context->getConfig();
206 $pageCounts = $this->pageCounts( $this->page );
208 $pageProperties = [];
209 $props = PageProps::getInstance()->getAllProperties( $title );
210 if ( isset( $props[$id] ) ) {
211 $pageProperties = $props[$id];
214 // Basic information
215 $pageInfo = [];
216 $pageInfo['header-basic'] = [];
218 // Display title
219 $displayTitle = $title->getPrefixedText();
220 if ( isset( $pageProperties['displaytitle'] ) ) {
221 $displayTitle = $pageProperties['displaytitle'];
224 $pageInfo['header-basic'][] = [
225 $this->msg( 'pageinfo-display-title' ), $displayTitle
228 // Is it a redirect? If so, where to?
229 if ( $title->isRedirect() ) {
230 $pageInfo['header-basic'][] = [
231 $this->msg( 'pageinfo-redirectsto' ),
232 Linker::link( $this->page->getRedirectTarget() ) .
233 $this->msg( 'word-separator' )->escaped() .
234 $this->msg( 'parentheses' )->rawParams( Linker::link(
235 $this->page->getRedirectTarget(),
236 $this->msg( 'pageinfo-redirectsto-info' )->escaped(),
238 [ 'action' => 'info' ]
239 ) )->escaped()
243 // Default sort key
244 $sortKey = $title->getCategorySortkey();
245 if ( isset( $pageProperties['defaultsort'] ) ) {
246 $sortKey = $pageProperties['defaultsort'];
249 $sortKey = htmlspecialchars( $sortKey );
250 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-default-sort' ), $sortKey ];
252 // Page length (in bytes)
253 $pageInfo['header-basic'][] = [
254 $this->msg( 'pageinfo-length' ), $lang->formatNum( $title->getLength() )
257 // Page ID (number not localised, as it's a database ID)
258 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-article-id' ), $id ];
260 // Language in which the page content is (supposed to be) written
261 $pageLang = $title->getPageLanguage()->getCode();
263 if ( $config->get( 'PageLanguageUseDB' )
264 && $this->getTitle()->userCan( 'pagelang', $this->getUser() )
266 // Link to Special:PageLanguage with pre-filled page title if user has permissions
267 $titleObj = SpecialPage::getTitleFor( 'PageLanguage', $title->getPrefixedText() );
268 $langDisp = Linker::link(
269 $titleObj,
270 $this->msg( 'pageinfo-language' )->escaped()
272 } else {
273 // Display just the message
274 $langDisp = $this->msg( 'pageinfo-language' )->escaped();
277 $pageInfo['header-basic'][] = [ $langDisp,
278 Language::fetchLanguageName( $pageLang, $lang->getCode() )
279 . ' ' . $this->msg( 'parentheses', $pageLang )->escaped() ];
281 // Content model of the page
282 $pageInfo['header-basic'][] = [
283 $this->msg( 'pageinfo-content-model' ),
284 htmlspecialchars( ContentHandler::getLocalizedName( $title->getContentModel() ) )
287 // Search engine status
288 $pOutput = new ParserOutput();
289 if ( isset( $pageProperties['noindex'] ) ) {
290 $pOutput->setIndexPolicy( 'noindex' );
292 if ( isset( $pageProperties['index'] ) ) {
293 $pOutput->setIndexPolicy( 'index' );
296 // Use robot policy logic
297 $policy = $this->page->getRobotPolicy( 'view', $pOutput );
298 $pageInfo['header-basic'][] = [
299 // Messages: pageinfo-robot-index, pageinfo-robot-noindex
300 $this->msg( 'pageinfo-robot-policy' ),
301 $this->msg( "pageinfo-robot-${policy['index']}" )
304 $unwatchedPageThreshold = $config->get( 'UnwatchedPageThreshold' );
305 if (
306 $user->isAllowed( 'unwatchedpages' ) ||
307 ( $unwatchedPageThreshold !== false &&
308 $pageCounts['watchers'] >= $unwatchedPageThreshold )
310 // Number of page watchers
311 $pageInfo['header-basic'][] = [
312 $this->msg( 'pageinfo-watchers' ),
313 $lang->formatNum( $pageCounts['watchers'] )
315 if (
316 $config->get( 'ShowUpdatedMarker' ) &&
317 isset( $pageCounts['visitingWatchers'] )
319 $minToDisclose = $config->get( 'UnwatchedPageSecret' );
320 if ( $pageCounts['visitingWatchers'] > $minToDisclose ||
321 $user->isAllowed( 'unwatchedpages' ) ) {
322 $pageInfo['header-basic'][] = [
323 $this->msg( 'pageinfo-visiting-watchers' ),
324 $lang->formatNum( $pageCounts['visitingWatchers'] )
326 } else {
327 $pageInfo['header-basic'][] = [
328 $this->msg( 'pageinfo-visiting-watchers' ),
329 $this->msg( 'pageinfo-few-visiting-watchers' )
333 } elseif ( $unwatchedPageThreshold !== false ) {
334 $pageInfo['header-basic'][] = [
335 $this->msg( 'pageinfo-watchers' ),
336 $this->msg( 'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
340 // Redirects to this page
341 $whatLinksHere = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
342 $pageInfo['header-basic'][] = [
343 Linker::link(
344 $whatLinksHere,
345 $this->msg( 'pageinfo-redirects-name' )->escaped(),
348 'hidelinks' => 1,
349 'hidetrans' => 1,
350 'hideimages' => $title->getNamespace() == NS_FILE
353 $this->msg( 'pageinfo-redirects-value' )
354 ->numParams( count( $title->getRedirectsHere() ) )
357 // Is it counted as a content page?
358 if ( $this->page->isCountable() ) {
359 $pageInfo['header-basic'][] = [
360 $this->msg( 'pageinfo-contentpage' ),
361 $this->msg( 'pageinfo-contentpage-yes' )
365 // Subpages of this page, if subpages are enabled for the current NS
366 if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) {
367 $prefixIndex = SpecialPage::getTitleFor(
368 'Prefixindex', $title->getPrefixedText() . '/' );
369 $pageInfo['header-basic'][] = [
370 Linker::link( $prefixIndex, $this->msg( 'pageinfo-subpages-name' )->escaped() ),
371 $this->msg( 'pageinfo-subpages-value' )
372 ->numParams(
373 $pageCounts['subpages']['total'],
374 $pageCounts['subpages']['redirects'],
375 $pageCounts['subpages']['nonredirects'] )
379 if ( $title->inNamespace( NS_CATEGORY ) ) {
380 $category = Category::newFromTitle( $title );
382 // $allCount is the total number of cat members,
383 // not the count of how many members are normal pages.
384 $allCount = (int)$category->getPageCount();
385 $subcatCount = (int)$category->getSubcatCount();
386 $fileCount = (int)$category->getFileCount();
387 $pagesCount = $allCount - $subcatCount - $fileCount;
389 $pageInfo['category-info'] = [
391 $this->msg( 'pageinfo-category-total' ),
392 $lang->formatNum( $allCount )
395 $this->msg( 'pageinfo-category-pages' ),
396 $lang->formatNum( $pagesCount )
399 $this->msg( 'pageinfo-category-subcats' ),
400 $lang->formatNum( $subcatCount )
403 $this->msg( 'pageinfo-category-files' ),
404 $lang->formatNum( $fileCount )
409 // Page protection
410 $pageInfo['header-restrictions'] = [];
412 // Is this page affected by the cascading protection of something which includes it?
413 if ( $title->isCascadeProtected() ) {
414 $cascadingFrom = '';
415 $sources = $title->getCascadeProtectionSources()[0];
417 foreach ( $sources as $sourceTitle ) {
418 $cascadingFrom .= Html::rawElement(
419 'li', [], Linker::linkKnown( $sourceTitle ) );
422 $cascadingFrom = Html::rawElement( 'ul', [], $cascadingFrom );
423 $pageInfo['header-restrictions'][] = [
424 $this->msg( 'pageinfo-protect-cascading-from' ),
425 $cascadingFrom
429 // Is out protection set to cascade to other pages?
430 if ( $title->areRestrictionsCascading() ) {
431 $pageInfo['header-restrictions'][] = [
432 $this->msg( 'pageinfo-protect-cascading' ),
433 $this->msg( 'pageinfo-protect-cascading-yes' )
437 // Page protection
438 foreach ( $title->getRestrictionTypes() as $restrictionType ) {
439 $protectionLevel = implode( ', ', $title->getRestrictions( $restrictionType ) );
441 if ( $protectionLevel == '' ) {
442 // Allow all users
443 $message = $this->msg( 'protect-default' )->escaped();
444 } else {
445 // Administrators only
446 // Messages: protect-level-autoconfirmed, protect-level-sysop
447 $message = $this->msg( "protect-level-$protectionLevel" );
448 if ( $message->isDisabled() ) {
449 // Require "$1" permission
450 $message = $this->msg( "protect-fallback", $protectionLevel )->parse();
451 } else {
452 $message = $message->escaped();
455 $expiry = $title->getRestrictionExpiry( $restrictionType );
456 $formattedexpiry = $this->msg( 'parentheses',
457 $this->getLanguage()->formatExpiry( $expiry ) )->escaped();
458 $message .= $this->msg( 'word-separator' )->escaped() . $formattedexpiry;
460 // Messages: restriction-edit, restriction-move, restriction-create,
461 // restriction-upload
462 $pageInfo['header-restrictions'][] = [
463 $this->msg( "restriction-$restrictionType" ), $message
467 if ( !$this->page->exists() ) {
468 return $pageInfo;
471 // Edit history
472 $pageInfo['header-edits'] = [];
474 $firstRev = $this->page->getOldestRevision();
475 $lastRev = $this->page->getRevision();
476 $batch = new LinkBatch;
478 if ( $firstRev ) {
479 $firstRevUser = $firstRev->getUserText( Revision::FOR_THIS_USER );
480 if ( $firstRevUser !== '' ) {
481 $firstRevUserTitle = Title::makeTitle( NS_USER, $firstRevUser );
482 $batch->addObj( $firstRevUserTitle );
483 $batch->addObj( $firstRevUserTitle->getTalkPage() );
487 if ( $lastRev ) {
488 $lastRevUser = $lastRev->getUserText( Revision::FOR_THIS_USER );
489 if ( $lastRevUser !== '' ) {
490 $lastRevUserTitle = Title::makeTitle( NS_USER, $lastRevUser );
491 $batch->addObj( $lastRevUserTitle );
492 $batch->addObj( $lastRevUserTitle->getTalkPage() );
496 $batch->execute();
498 if ( $firstRev ) {
499 // Page creator
500 $pageInfo['header-edits'][] = [
501 $this->msg( 'pageinfo-firstuser' ),
502 Linker::revUserTools( $firstRev )
505 // Date of page creation
506 $pageInfo['header-edits'][] = [
507 $this->msg( 'pageinfo-firsttime' ),
508 Linker::linkKnown(
509 $title,
510 htmlspecialchars( $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ) ),
512 [ 'oldid' => $firstRev->getId() ]
517 if ( $lastRev ) {
518 // Latest editor
519 $pageInfo['header-edits'][] = [
520 $this->msg( 'pageinfo-lastuser' ),
521 Linker::revUserTools( $lastRev )
524 // Date of latest edit
525 $pageInfo['header-edits'][] = [
526 $this->msg( 'pageinfo-lasttime' ),
527 Linker::linkKnown(
528 $title,
529 htmlspecialchars(
530 $lang->userTimeAndDate( $this->page->getTimestamp(), $user )
533 [ 'oldid' => $this->page->getLatest() ]
538 // Total number of edits
539 $pageInfo['header-edits'][] = [
540 $this->msg( 'pageinfo-edits' ), $lang->formatNum( $pageCounts['edits'] )
543 // Total number of distinct authors
544 if ( $pageCounts['authors'] > 0 ) {
545 $pageInfo['header-edits'][] = [
546 $this->msg( 'pageinfo-authors' ), $lang->formatNum( $pageCounts['authors'] )
550 // Recent number of edits (within past 30 days)
551 $pageInfo['header-edits'][] = [
552 $this->msg( 'pageinfo-recent-edits',
553 $lang->formatDuration( $config->get( 'RCMaxAge' ) ) ),
554 $lang->formatNum( $pageCounts['recent_edits'] )
557 // Recent number of distinct authors
558 $pageInfo['header-edits'][] = [
559 $this->msg( 'pageinfo-recent-authors' ),
560 $lang->formatNum( $pageCounts['recent_authors'] )
563 // Array of MagicWord objects
564 $magicWords = MagicWord::getDoubleUnderscoreArray();
566 // Array of magic word IDs
567 $wordIDs = $magicWords->names;
569 // Array of IDs => localized magic words
570 $localizedWords = $wgContLang->getMagicWords();
572 $listItems = [];
573 foreach ( $pageProperties as $property => $value ) {
574 if ( in_array( $property, $wordIDs ) ) {
575 $listItems[] = Html::element( 'li', [], $localizedWords[$property][1] );
579 $localizedList = Html::rawElement( 'ul', [], implode( '', $listItems ) );
580 $hiddenCategories = $this->page->getHiddenCategories();
582 if (
583 count( $listItems ) > 0 ||
584 count( $hiddenCategories ) > 0 ||
585 $pageCounts['transclusion']['from'] > 0 ||
586 $pageCounts['transclusion']['to'] > 0
588 $options = [ 'LIMIT' => $config->get( 'PageInfoTransclusionLimit' ) ];
589 $transcludedTemplates = $title->getTemplateLinksFrom( $options );
590 if ( $config->get( 'MiserMode' ) ) {
591 $transcludedTargets = [];
592 } else {
593 $transcludedTargets = $title->getTemplateLinksTo( $options );
596 // Page properties
597 $pageInfo['header-properties'] = [];
599 // Magic words
600 if ( count( $listItems ) > 0 ) {
601 $pageInfo['header-properties'][] = [
602 $this->msg( 'pageinfo-magic-words' )->numParams( count( $listItems ) ),
603 $localizedList
607 // Hidden categories
608 if ( count( $hiddenCategories ) > 0 ) {
609 $pageInfo['header-properties'][] = [
610 $this->msg( 'pageinfo-hidden-categories' )
611 ->numParams( count( $hiddenCategories ) ),
612 Linker::formatHiddenCategories( $hiddenCategories )
616 // Transcluded templates
617 if ( $pageCounts['transclusion']['from'] > 0 ) {
618 if ( $pageCounts['transclusion']['from'] > count( $transcludedTemplates ) ) {
619 $more = $this->msg( 'morenotlisted' )->escaped();
620 } else {
621 $more = null;
624 $pageInfo['header-properties'][] = [
625 $this->msg( 'pageinfo-templates' )
626 ->numParams( $pageCounts['transclusion']['from'] ),
627 Linker::formatTemplates(
628 $transcludedTemplates,
629 false,
630 false,
631 $more )
635 if ( !$config->get( 'MiserMode' ) && $pageCounts['transclusion']['to'] > 0 ) {
636 if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) {
637 $more = Linker::link(
638 $whatLinksHere,
639 $this->msg( 'moredotdotdot' )->escaped(),
641 [ 'hidelinks' => 1, 'hideredirs' => 1 ]
643 } else {
644 $more = null;
647 $pageInfo['header-properties'][] = [
648 $this->msg( 'pageinfo-transclusions' )
649 ->numParams( $pageCounts['transclusion']['to'] ),
650 Linker::formatTemplates(
651 $transcludedTargets,
652 false,
653 false,
654 $more )
659 return $pageInfo;
663 * Returns page counts that would be too "expensive" to retrieve by normal means.
665 * @param WikiPage|Article|Page $page
666 * @return array
668 protected function pageCounts( Page $page ) {
669 $fname = __METHOD__;
670 $config = $this->context->getConfig();
672 return ObjectCache::getMainWANInstance()->getWithSetCallback(
673 self::getCacheKey( $page->getTitle(), $page->getLatest() ),
674 86400 * 7,
675 function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
676 $title = $page->getTitle();
677 $id = $title->getArticleID();
679 $dbr = wfGetDB( DB_SLAVE );
680 $dbrWatchlist = wfGetDB( DB_SLAVE, 'watchlist' );
682 $setOpts += Database::getCacheSetOptions( $dbr, $dbrWatchlist );
684 $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
686 $result = [];
687 $result['watchers'] = $watchedItemStore->countWatchers( $title );
689 if ( $config->get( 'ShowUpdatedMarker' ) ) {
690 $updated = wfTimestamp( TS_UNIX, $page->getTimestamp() );
691 $result['visitingWatchers'] = $watchedItemStore->countVisitingWatchers(
692 $title,
693 $updated - $config->get( 'WatchersMaxAge' )
697 // Total number of edits
698 $edits = (int)$dbr->selectField(
699 'revision',
700 'COUNT(*)',
701 [ 'rev_page' => $id ],
702 $fname
704 $result['edits'] = $edits;
706 // Total number of distinct authors
707 if ( $config->get( 'MiserMode' ) ) {
708 $result['authors'] = 0;
709 } else {
710 $result['authors'] = (int)$dbr->selectField(
711 'revision',
712 'COUNT(DISTINCT rev_user_text)',
713 [ 'rev_page' => $id ],
714 $fname
718 // "Recent" threshold defined by RCMaxAge setting
719 $threshold = $dbr->timestamp( time() - $config->get( 'RCMaxAge' ) );
721 // Recent number of edits
722 $edits = (int)$dbr->selectField(
723 'revision',
724 'COUNT(rev_page)',
726 'rev_page' => $id,
727 "rev_timestamp >= " . $dbr->addQuotes( $threshold )
729 $fname
731 $result['recent_edits'] = $edits;
733 // Recent number of distinct authors
734 $result['recent_authors'] = (int)$dbr->selectField(
735 'revision',
736 'COUNT(DISTINCT rev_user_text)',
738 'rev_page' => $id,
739 "rev_timestamp >= " . $dbr->addQuotes( $threshold )
741 $fname
744 // Subpages (if enabled)
745 if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) {
746 $conds = [ 'page_namespace' => $title->getNamespace() ];
747 $conds[] = 'page_title ' .
748 $dbr->buildLike( $title->getDBkey() . '/', $dbr->anyString() );
750 // Subpages of this page (redirects)
751 $conds['page_is_redirect'] = 1;
752 $result['subpages']['redirects'] = (int)$dbr->selectField(
753 'page',
754 'COUNT(page_id)',
755 $conds,
756 $fname
759 // Subpages of this page (non-redirects)
760 $conds['page_is_redirect'] = 0;
761 $result['subpages']['nonredirects'] = (int)$dbr->selectField(
762 'page',
763 'COUNT(page_id)',
764 $conds,
765 $fname
768 // Subpages of this page (total)
769 $result['subpages']['total'] = $result['subpages']['redirects']
770 + $result['subpages']['nonredirects'];
773 // Counts for the number of transclusion links (to/from)
774 if ( $config->get( 'MiserMode' ) ) {
775 $result['transclusion']['to'] = 0;
776 } else {
777 $result['transclusion']['to'] = (int)$dbr->selectField(
778 'templatelinks',
779 'COUNT(tl_from)',
781 'tl_namespace' => $title->getNamespace(),
782 'tl_title' => $title->getDBkey()
784 $fname
788 $result['transclusion']['from'] = (int)$dbr->selectField(
789 'templatelinks',
790 'COUNT(*)',
791 [ 'tl_from' => $title->getArticleID() ],
792 $fname
795 return $result;
801 * Returns the name that goes in the "<h1>" page title.
803 * @return string
805 protected function getPageTitle() {
806 return $this->msg( 'pageinfo-title', $this->getTitle()->getPrefixedText() )->text();
810 * Get a list of contributors of $article
811 * @return string Html
813 protected function getContributors() {
814 $contributors = $this->page->getContributors();
815 $real_names = [];
816 $user_names = [];
817 $anon_ips = [];
819 # Sift for real versus user names
820 /** @var $user User */
821 foreach ( $contributors as $user ) {
822 $page = $user->isAnon()
823 ? SpecialPage::getTitleFor( 'Contributions', $user->getName() )
824 : $user->getUserPage();
826 $hiddenPrefs = $this->context->getConfig()->get( 'HiddenPrefs' );
827 if ( $user->getId() == 0 ) {
828 $anon_ips[] = Linker::link( $page, htmlspecialchars( $user->getName() ) );
829 } elseif ( !in_array( 'realname', $hiddenPrefs ) && $user->getRealName() ) {
830 $real_names[] = Linker::link( $page, htmlspecialchars( $user->getRealName() ) );
831 } else {
832 $user_names[] = Linker::link( $page, htmlspecialchars( $user->getName() ) );
836 $lang = $this->getLanguage();
838 $real = $lang->listToText( $real_names );
840 # "ThisSite user(s) A, B and C"
841 if ( count( $user_names ) ) {
842 $user = $this->msg( 'siteusers' )
843 ->rawParams( $lang->listToText( $user_names ) )
844 ->params( count( $user_names ) )->escaped();
845 } else {
846 $user = false;
849 if ( count( $anon_ips ) ) {
850 $anon = $this->msg( 'anonusers' )
851 ->rawParams( $lang->listToText( $anon_ips ) )
852 ->params( count( $anon_ips ) )->escaped();
853 } else {
854 $anon = false;
857 # This is the big list, all mooshed together. We sift for blank strings
858 $fulllist = [];
859 foreach ( [ $real, $user, $anon ] as $s ) {
860 if ( $s !== '' ) {
861 array_push( $fulllist, $s );
865 $count = count( $fulllist );
867 # "Based on work by ..."
868 return $count
869 ? $this->msg( 'othercontribs' )->rawParams(
870 $lang->listToText( $fulllist ) )->params( $count )->escaped()
871 : '';
875 * Returns the description that goes below the "<h1>" tag.
877 * @return string
879 protected function getDescription() {
880 return '';
884 * @param Title $title
885 * @param int $revId
886 * @return string
888 protected static function getCacheKey( Title $title, $revId ) {
889 return wfMemcKey( 'infoaction', md5( $title->getPrefixedText() ), $revId, self::VERSION );