Many more function case mismatches
[mediawiki.git] / includes / actions / InfoAction.php
blobf7c30b71af00596e9e80086c9bcaf33600af7318
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 /**
26 * Displays information about a page.
28 * @ingroup Actions
30 class InfoAction extends FormlessAction {
31 const VERSION = 1;
33 /**
34 * Returns the name of the action this object responds to.
36 * @return string Lowercase name
38 public function getName() {
39 return 'info';
42 /**
43 * Whether this action can still be executed by a blocked user.
45 * @return bool
47 public function requiresUnblock() {
48 return false;
51 /**
52 * Whether this action requires the wiki not to be locked.
54 * @return bool
56 public function requiresWrite() {
57 return false;
60 /**
61 * Clear the info cache for a given Title.
63 * @since 1.22
64 * @param Title $title Title to clear cache for
65 * @param int|null $revid Revision id to clear
67 public static function invalidateCache( Title $title, $revid = null ) {
68 if ( !$revid ) {
69 $revision = Revision::newFromTitle( $title, 0, Revision::READ_LATEST );
70 $revid = $revision ? $revision->getId() : null;
72 if ( $revid !== null ) {
73 $key = self::getCacheKey( $title, $revid );
74 ObjectCache::getMainWANInstance()->delete( $key );
78 /**
79 * Shows page information on GET request.
81 * @return string Page information that will be added to the output
83 public function onView() {
84 $content = '';
86 // Validate revision
87 $oldid = $this->page->getOldID();
88 if ( $oldid ) {
89 $revision = $this->page->getRevisionFetched();
91 // Revision is missing
92 if ( $revision === null ) {
93 return $this->msg( 'missing-revision', $oldid )->parse();
96 // Revision is not current
97 if ( !$revision->isCurrent() ) {
98 return $this->msg( 'pageinfo-not-current' )->plain();
102 // Page header
103 if ( !$this->msg( 'pageinfo-header' )->isDisabled() ) {
104 $content .= $this->msg( 'pageinfo-header' )->parse();
107 // Hide "This page is a member of # hidden categories" explanation
108 $content .= Html::element( 'style', [],
109 '.mw-hiddenCategoriesExplanation { display: none; }' ) . "\n";
111 // Hide "Templates used on this page" explanation
112 $content .= Html::element( 'style', [],
113 '.mw-templatesUsedExplanation { display: none; }' ) . "\n";
115 // Get page information
116 $pageInfo = $this->pageInfo();
118 // Allow extensions to add additional information
119 Hooks::run( 'InfoAction', [ $this->getContext(), &$pageInfo ] );
121 // Render page information
122 foreach ( $pageInfo as $header => $infoTable ) {
123 // Messages:
124 // pageinfo-header-basic, pageinfo-header-edits, pageinfo-header-restrictions,
125 // pageinfo-header-properties, pageinfo-category-info
126 $content .= $this->makeHeader( $this->msg( "pageinfo-${header}" )->escaped() ) . "\n";
127 $table = "\n";
128 foreach ( $infoTable as $infoRow ) {
129 $name = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->escaped() : $infoRow[0];
130 $value = ( $infoRow[1] instanceof Message ) ? $infoRow[1]->escaped() : $infoRow[1];
131 $id = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->getKey() : null;
132 $table = $this->addRow( $table, $name, $value, $id ) . "\n";
134 $content = $this->addTable( $content, $table ) . "\n";
137 // Page footer
138 if ( !$this->msg( 'pageinfo-footer' )->isDisabled() ) {
139 $content .= $this->msg( 'pageinfo-footer' )->parse();
142 return $content;
146 * Creates a header that can be added to the output.
148 * @param string $header The header text.
149 * @return string The HTML.
151 protected function makeHeader( $header ) {
152 $spanAttribs = [ 'class' => 'mw-headline', 'id' => Sanitizer::escapeId( $header ) ];
154 return Html::rawElement( 'h2', [], Html::element( 'span', $spanAttribs, $header ) );
158 * Adds a row to a table that will be added to the content.
160 * @param string $table The table that will be added to the content
161 * @param string $name The name of the row
162 * @param string $value The value of the row
163 * @param string $id The ID to use for the 'tr' element
164 * @return string The table with the row added
166 protected function addRow( $table, $name, $value, $id ) {
167 return $table .
168 Html::rawElement(
169 'tr',
170 $id === null ? [] : [ 'id' => 'mw-' . $id ],
171 Html::rawElement( 'td', [ 'style' => 'vertical-align: top;' ], $name ) .
172 Html::rawElement( 'td', [], $value )
177 * Adds a table to the content that will be added to the output.
179 * @param string $content The content that will be added to the output
180 * @param string $table The table
181 * @return string The content with the table added
183 protected function addTable( $content, $table ) {
184 return $content . Html::rawElement( 'table', [ 'class' => 'wikitable mw-page-info' ],
185 $table );
189 * Returns page information in an easily-manipulated format. Array keys are used so extensions
190 * may add additional information in arbitrary positions. Array values are arrays with one
191 * element to be rendered as a header, arrays with two elements to be rendered as a table row.
193 * @return array
195 protected function pageInfo() {
196 global $wgContLang;
198 $user = $this->getUser();
199 $lang = $this->getLanguage();
200 $title = $this->getTitle();
201 $id = $title->getArticleID();
202 $config = $this->context->getConfig();
204 $pageCounts = $this->pageCounts( $this->page );
206 $pageProperties = [];
207 $props = PageProps::getInstance()->getAllProperties( $title );
208 if ( isset( $props[$id] ) ) {
209 $pageProperties = $props[$id];
212 // Basic information
213 $pageInfo = [];
214 $pageInfo['header-basic'] = [];
216 // Display title
217 $displayTitle = $title->getPrefixedText();
218 if ( isset( $pageProperties['displaytitle'] ) ) {
219 $displayTitle = $pageProperties['displaytitle'];
222 $pageInfo['header-basic'][] = [
223 $this->msg( 'pageinfo-display-title' ), $displayTitle
226 // Is it a redirect? If so, where to?
227 if ( $title->isRedirect() ) {
228 $pageInfo['header-basic'][] = [
229 $this->msg( 'pageinfo-redirectsto' ),
230 Linker::link( $this->page->getRedirectTarget() ) .
231 $this->msg( 'word-separator' )->escaped() .
232 $this->msg( 'parentheses' )->rawParams( Linker::link(
233 $this->page->getRedirectTarget(),
234 $this->msg( 'pageinfo-redirectsto-info' )->escaped(),
236 [ 'action' => 'info' ]
237 ) )->escaped()
241 // Default sort key
242 $sortKey = $title->getCategorySortkey();
243 if ( isset( $pageProperties['defaultsort'] ) ) {
244 $sortKey = $pageProperties['defaultsort'];
247 $sortKey = htmlspecialchars( $sortKey );
248 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-default-sort' ), $sortKey ];
250 // Page length (in bytes)
251 $pageInfo['header-basic'][] = [
252 $this->msg( 'pageinfo-length' ), $lang->formatNum( $title->getLength() )
255 // Page ID (number not localised, as it's a database ID)
256 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-article-id' ), $id ];
258 // Language in which the page content is (supposed to be) written
259 $pageLang = $title->getPageLanguage()->getCode();
261 if ( $config->get( 'PageLanguageUseDB' )
262 && $this->getTitle()->userCan( 'pagelang', $this->getUser() )
264 // Link to Special:PageLanguage with pre-filled page title if user has permissions
265 $titleObj = SpecialPage::getTitleFor( 'PageLanguage', $title->getPrefixedText() );
266 $langDisp = Linker::link(
267 $titleObj,
268 $this->msg( 'pageinfo-language' )->escaped()
270 } else {
271 // Display just the message
272 $langDisp = $this->msg( 'pageinfo-language' )->escaped();
275 $pageInfo['header-basic'][] = [ $langDisp,
276 Language::fetchLanguageName( $pageLang, $lang->getCode() )
277 . ' ' . $this->msg( 'parentheses', $pageLang )->escaped() ];
279 // Content model of the page
280 $pageInfo['header-basic'][] = [
281 $this->msg( 'pageinfo-content-model' ),
282 htmlspecialchars( ContentHandler::getLocalizedName( $title->getContentModel() ) )
285 // Search engine status
286 $pOutput = new ParserOutput();
287 if ( isset( $pageProperties['noindex'] ) ) {
288 $pOutput->setIndexPolicy( 'noindex' );
290 if ( isset( $pageProperties['index'] ) ) {
291 $pOutput->setIndexPolicy( 'index' );
294 // Use robot policy logic
295 $policy = $this->page->getRobotPolicy( 'view', $pOutput );
296 $pageInfo['header-basic'][] = [
297 // Messages: pageinfo-robot-index, pageinfo-robot-noindex
298 $this->msg( 'pageinfo-robot-policy' ),
299 $this->msg( "pageinfo-robot-${policy['index']}" )
302 $unwatchedPageThreshold = $config->get( 'UnwatchedPageThreshold' );
303 if (
304 $user->isAllowed( 'unwatchedpages' ) ||
305 ( $unwatchedPageThreshold !== false &&
306 $pageCounts['watchers'] >= $unwatchedPageThreshold )
308 // Number of page watchers
309 $pageInfo['header-basic'][] = [
310 $this->msg( 'pageinfo-watchers' ),
311 $lang->formatNum( $pageCounts['watchers'] )
313 if (
314 $config->get( 'ShowUpdatedMarker' ) &&
315 isset( $pageCounts['visitingWatchers'] )
317 $minToDisclose = $config->get( 'UnwatchedPageSecret' );
318 if ( $pageCounts['visitingWatchers'] > $minToDisclose ||
319 $user->isAllowed( 'unwatchedpages' ) ) {
320 $pageInfo['header-basic'][] = [
321 $this->msg( 'pageinfo-visiting-watchers' ),
322 $lang->formatNum( $pageCounts['visitingWatchers'] )
324 } else {
325 $pageInfo['header-basic'][] = [
326 $this->msg( 'pageinfo-visiting-watchers' ),
327 $this->msg( 'pageinfo-few-visiting-watchers' )
331 } elseif ( $unwatchedPageThreshold !== false ) {
332 $pageInfo['header-basic'][] = [
333 $this->msg( 'pageinfo-watchers' ),
334 $this->msg( 'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
338 // Redirects to this page
339 $whatLinksHere = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
340 $pageInfo['header-basic'][] = [
341 Linker::link(
342 $whatLinksHere,
343 $this->msg( 'pageinfo-redirects-name' )->escaped(),
346 'hidelinks' => 1,
347 'hidetrans' => 1,
348 'hideimages' => $title->getNamespace() == NS_FILE
351 $this->msg( 'pageinfo-redirects-value' )
352 ->numParams( count( $title->getRedirectsHere() ) )
355 // Is it counted as a content page?
356 if ( $this->page->isCountable() ) {
357 $pageInfo['header-basic'][] = [
358 $this->msg( 'pageinfo-contentpage' ),
359 $this->msg( 'pageinfo-contentpage-yes' )
363 // Subpages of this page, if subpages are enabled for the current NS
364 if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) {
365 $prefixIndex = SpecialPage::getTitleFor(
366 'Prefixindex', $title->getPrefixedText() . '/' );
367 $pageInfo['header-basic'][] = [
368 Linker::link( $prefixIndex, $this->msg( 'pageinfo-subpages-name' )->escaped() ),
369 $this->msg( 'pageinfo-subpages-value' )
370 ->numParams(
371 $pageCounts['subpages']['total'],
372 $pageCounts['subpages']['redirects'],
373 $pageCounts['subpages']['nonredirects'] )
377 if ( $title->inNamespace( NS_CATEGORY ) ) {
378 $category = Category::newFromTitle( $title );
380 // $allCount is the total number of cat members,
381 // not the count of how many members are normal pages.
382 $allCount = (int)$category->getPageCount();
383 $subcatCount = (int)$category->getSubcatCount();
384 $fileCount = (int)$category->getFileCount();
385 $pagesCount = $allCount - $subcatCount - $fileCount;
387 $pageInfo['category-info'] = [
389 $this->msg( 'pageinfo-category-total' ),
390 $lang->formatNum( $allCount )
393 $this->msg( 'pageinfo-category-pages' ),
394 $lang->formatNum( $pagesCount )
397 $this->msg( 'pageinfo-category-subcats' ),
398 $lang->formatNum( $subcatCount )
401 $this->msg( 'pageinfo-category-files' ),
402 $lang->formatNum( $fileCount )
407 // Page protection
408 $pageInfo['header-restrictions'] = [];
410 // Is this page affected by the cascading protection of something which includes it?
411 if ( $title->isCascadeProtected() ) {
412 $cascadingFrom = '';
413 $sources = $title->getCascadeProtectionSources()[0];
415 foreach ( $sources as $sourceTitle ) {
416 $cascadingFrom .= Html::rawElement(
417 'li', [], Linker::linkKnown( $sourceTitle ) );
420 $cascadingFrom = Html::rawElement( 'ul', [], $cascadingFrom );
421 $pageInfo['header-restrictions'][] = [
422 $this->msg( 'pageinfo-protect-cascading-from' ),
423 $cascadingFrom
427 // Is out protection set to cascade to other pages?
428 if ( $title->areRestrictionsCascading() ) {
429 $pageInfo['header-restrictions'][] = [
430 $this->msg( 'pageinfo-protect-cascading' ),
431 $this->msg( 'pageinfo-protect-cascading-yes' )
435 // Page protection
436 foreach ( $title->getRestrictionTypes() as $restrictionType ) {
437 $protectionLevel = implode( ', ', $title->getRestrictions( $restrictionType ) );
439 if ( $protectionLevel == '' ) {
440 // Allow all users
441 $message = $this->msg( 'protect-default' )->escaped();
442 } else {
443 // Administrators only
444 // Messages: protect-level-autoconfirmed, protect-level-sysop
445 $message = $this->msg( "protect-level-$protectionLevel" );
446 if ( $message->isDisabled() ) {
447 // Require "$1" permission
448 $message = $this->msg( "protect-fallback", $protectionLevel )->parse();
449 } else {
450 $message = $message->escaped();
453 $expiry = $title->getRestrictionExpiry( $restrictionType );
454 $formattedexpiry = $this->msg( 'parentheses',
455 $this->getLanguage()->formatExpiry( $expiry ) )->escaped();
456 $message .= $this->msg( 'word-separator' )->escaped() . $formattedexpiry;
458 // Messages: restriction-edit, restriction-move, restriction-create,
459 // restriction-upload
460 $pageInfo['header-restrictions'][] = [
461 $this->msg( "restriction-$restrictionType" ), $message
465 if ( !$this->page->exists() ) {
466 return $pageInfo;
469 // Edit history
470 $pageInfo['header-edits'] = [];
472 $firstRev = $this->page->getOldestRevision();
473 $lastRev = $this->page->getRevision();
474 $batch = new LinkBatch;
476 if ( $firstRev ) {
477 $firstRevUser = $firstRev->getUserText( Revision::FOR_THIS_USER );
478 if ( $firstRevUser !== '' ) {
479 $batch->add( NS_USER, $firstRevUser );
480 $batch->add( NS_USER_TALK, $firstRevUser );
484 if ( $lastRev ) {
485 $lastRevUser = $lastRev->getUserText( Revision::FOR_THIS_USER );
486 if ( $lastRevUser !== '' ) {
487 $batch->add( NS_USER, $lastRevUser );
488 $batch->add( NS_USER_TALK, $lastRevUser );
492 $batch->execute();
494 if ( $firstRev ) {
495 // Page creator
496 $pageInfo['header-edits'][] = [
497 $this->msg( 'pageinfo-firstuser' ),
498 Linker::revUserTools( $firstRev )
501 // Date of page creation
502 $pageInfo['header-edits'][] = [
503 $this->msg( 'pageinfo-firsttime' ),
504 Linker::linkKnown(
505 $title,
506 htmlspecialchars( $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ) ),
508 [ 'oldid' => $firstRev->getId() ]
513 if ( $lastRev ) {
514 // Latest editor
515 $pageInfo['header-edits'][] = [
516 $this->msg( 'pageinfo-lastuser' ),
517 Linker::revUserTools( $lastRev )
520 // Date of latest edit
521 $pageInfo['header-edits'][] = [
522 $this->msg( 'pageinfo-lasttime' ),
523 Linker::linkKnown(
524 $title,
525 htmlspecialchars(
526 $lang->userTimeAndDate( $this->page->getTimestamp(), $user )
529 [ 'oldid' => $this->page->getLatest() ]
534 // Total number of edits
535 $pageInfo['header-edits'][] = [
536 $this->msg( 'pageinfo-edits' ), $lang->formatNum( $pageCounts['edits'] )
539 // Total number of distinct authors
540 if ( $pageCounts['authors'] > 0 ) {
541 $pageInfo['header-edits'][] = [
542 $this->msg( 'pageinfo-authors' ), $lang->formatNum( $pageCounts['authors'] )
546 // Recent number of edits (within past 30 days)
547 $pageInfo['header-edits'][] = [
548 $this->msg( 'pageinfo-recent-edits',
549 $lang->formatDuration( $config->get( 'RCMaxAge' ) ) ),
550 $lang->formatNum( $pageCounts['recent_edits'] )
553 // Recent number of distinct authors
554 $pageInfo['header-edits'][] = [
555 $this->msg( 'pageinfo-recent-authors' ),
556 $lang->formatNum( $pageCounts['recent_authors'] )
559 // Array of MagicWord objects
560 $magicWords = MagicWord::getDoubleUnderscoreArray();
562 // Array of magic word IDs
563 $wordIDs = $magicWords->names;
565 // Array of IDs => localized magic words
566 $localizedWords = $wgContLang->getMagicWords();
568 $listItems = [];
569 foreach ( $pageProperties as $property => $value ) {
570 if ( in_array( $property, $wordIDs ) ) {
571 $listItems[] = Html::element( 'li', [], $localizedWords[$property][1] );
575 $localizedList = Html::rawElement( 'ul', [], implode( '', $listItems ) );
576 $hiddenCategories = $this->page->getHiddenCategories();
578 if (
579 count( $listItems ) > 0 ||
580 count( $hiddenCategories ) > 0 ||
581 $pageCounts['transclusion']['from'] > 0 ||
582 $pageCounts['transclusion']['to'] > 0
584 $options = [ 'LIMIT' => $config->get( 'PageInfoTransclusionLimit' ) ];
585 $transcludedTemplates = $title->getTemplateLinksFrom( $options );
586 if ( $config->get( 'MiserMode' ) ) {
587 $transcludedTargets = [];
588 } else {
589 $transcludedTargets = $title->getTemplateLinksTo( $options );
592 // Page properties
593 $pageInfo['header-properties'] = [];
595 // Magic words
596 if ( count( $listItems ) > 0 ) {
597 $pageInfo['header-properties'][] = [
598 $this->msg( 'pageinfo-magic-words' )->numParams( count( $listItems ) ),
599 $localizedList
603 // Hidden categories
604 if ( count( $hiddenCategories ) > 0 ) {
605 $pageInfo['header-properties'][] = [
606 $this->msg( 'pageinfo-hidden-categories' )
607 ->numParams( count( $hiddenCategories ) ),
608 Linker::formatHiddenCategories( $hiddenCategories )
612 // Transcluded templates
613 if ( $pageCounts['transclusion']['from'] > 0 ) {
614 if ( $pageCounts['transclusion']['from'] > count( $transcludedTemplates ) ) {
615 $more = $this->msg( 'morenotlisted' )->escaped();
616 } else {
617 $more = null;
620 $pageInfo['header-properties'][] = [
621 $this->msg( 'pageinfo-templates' )
622 ->numParams( $pageCounts['transclusion']['from'] ),
623 Linker::formatTemplates(
624 $transcludedTemplates,
625 false,
626 false,
627 $more )
631 if ( !$config->get( 'MiserMode' ) && $pageCounts['transclusion']['to'] > 0 ) {
632 if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) {
633 $more = Linker::link(
634 $whatLinksHere,
635 $this->msg( 'moredotdotdot' )->escaped(),
637 [ 'hidelinks' => 1, 'hideredirs' => 1 ]
639 } else {
640 $more = null;
643 $pageInfo['header-properties'][] = [
644 $this->msg( 'pageinfo-transclusions' )
645 ->numParams( $pageCounts['transclusion']['to'] ),
646 Linker::formatTemplates(
647 $transcludedTargets,
648 false,
649 false,
650 $more )
655 return $pageInfo;
659 * Returns page counts that would be too "expensive" to retrieve by normal means.
661 * @param WikiPage|Article|Page $page
662 * @return array
664 protected function pageCounts( Page $page ) {
665 $fname = __METHOD__;
666 $config = $this->context->getConfig();
668 return ObjectCache::getMainWANInstance()->getWithSetCallback(
669 self::getCacheKey( $page->getTitle(), $page->getLatest() ),
670 86400 * 7,
671 function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
672 $title = $page->getTitle();
673 $id = $title->getArticleID();
675 $dbr = wfGetDB( DB_SLAVE );
676 $dbrWatchlist = wfGetDB( DB_SLAVE, 'watchlist' );
678 $setOpts += Database::getCacheSetOptions( $dbr, $dbrWatchlist );
680 $watchedItemStore = WatchedItemStore::getDefaultInstance();
682 $result = [];
683 $result['watchers'] = $watchedItemStore->countWatchers( $title );
685 if ( $config->get( 'ShowUpdatedMarker' ) ) {
686 $updated = wfTimestamp( TS_UNIX, $page->getTimestamp() );
687 $result['visitingWatchers'] = $watchedItemStore->countVisitingWatchers(
688 $title,
689 $updated - $config->get( 'WatchersMaxAge' )
693 // Total number of edits
694 $edits = (int)$dbr->selectField(
695 'revision',
696 'COUNT(*)',
697 [ 'rev_page' => $id ],
698 $fname
700 $result['edits'] = $edits;
702 // Total number of distinct authors
703 if ( $config->get( 'MiserMode' ) ) {
704 $result['authors'] = 0;
705 } else {
706 $result['authors'] = (int)$dbr->selectField(
707 'revision',
708 'COUNT(DISTINCT rev_user_text)',
709 [ 'rev_page' => $id ],
710 $fname
714 // "Recent" threshold defined by RCMaxAge setting
715 $threshold = $dbr->timestamp( time() - $config->get( 'RCMaxAge' ) );
717 // Recent number of edits
718 $edits = (int)$dbr->selectField(
719 'revision',
720 'COUNT(rev_page)',
722 'rev_page' => $id,
723 "rev_timestamp >= " . $dbr->addQuotes( $threshold )
725 $fname
727 $result['recent_edits'] = $edits;
729 // Recent number of distinct authors
730 $result['recent_authors'] = (int)$dbr->selectField(
731 'revision',
732 'COUNT(DISTINCT rev_user_text)',
734 'rev_page' => $id,
735 "rev_timestamp >= " . $dbr->addQuotes( $threshold )
737 $fname
740 // Subpages (if enabled)
741 if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) {
742 $conds = [ 'page_namespace' => $title->getNamespace() ];
743 $conds[] = 'page_title ' .
744 $dbr->buildLike( $title->getDBkey() . '/', $dbr->anyString() );
746 // Subpages of this page (redirects)
747 $conds['page_is_redirect'] = 1;
748 $result['subpages']['redirects'] = (int)$dbr->selectField(
749 'page',
750 'COUNT(page_id)',
751 $conds,
752 $fname
755 // Subpages of this page (non-redirects)
756 $conds['page_is_redirect'] = 0;
757 $result['subpages']['nonredirects'] = (int)$dbr->selectField(
758 'page',
759 'COUNT(page_id)',
760 $conds,
761 $fname
764 // Subpages of this page (total)
765 $result['subpages']['total'] = $result['subpages']['redirects']
766 + $result['subpages']['nonredirects'];
769 // Counts for the number of transclusion links (to/from)
770 if ( $config->get( 'MiserMode' ) ) {
771 $result['transclusion']['to'] = 0;
772 } else {
773 $result['transclusion']['to'] = (int)$dbr->selectField(
774 'templatelinks',
775 'COUNT(tl_from)',
777 'tl_namespace' => $title->getNamespace(),
778 'tl_title' => $title->getDBkey()
780 $fname
784 $result['transclusion']['from'] = (int)$dbr->selectField(
785 'templatelinks',
786 'COUNT(*)',
787 [ 'tl_from' => $title->getArticleID() ],
788 $fname
791 return $result;
797 * Returns the name that goes in the "<h1>" page title.
799 * @return string
801 protected function getPageTitle() {
802 return $this->msg( 'pageinfo-title', $this->getTitle()->getPrefixedText() )->text();
806 * Get a list of contributors of $article
807 * @return string Html
809 protected function getContributors() {
810 $contributors = $this->page->getContributors();
811 $real_names = [];
812 $user_names = [];
813 $anon_ips = [];
815 # Sift for real versus user names
816 /** @var $user User */
817 foreach ( $contributors as $user ) {
818 $page = $user->isAnon()
819 ? SpecialPage::getTitleFor( 'Contributions', $user->getName() )
820 : $user->getUserPage();
822 $hiddenPrefs = $this->context->getConfig()->get( 'HiddenPrefs' );
823 if ( $user->getId() == 0 ) {
824 $anon_ips[] = Linker::link( $page, htmlspecialchars( $user->getName() ) );
825 } elseif ( !in_array( 'realname', $hiddenPrefs ) && $user->getRealName() ) {
826 $real_names[] = Linker::link( $page, htmlspecialchars( $user->getRealName() ) );
827 } else {
828 $user_names[] = Linker::link( $page, htmlspecialchars( $user->getName() ) );
832 $lang = $this->getLanguage();
834 $real = $lang->listToText( $real_names );
836 # "ThisSite user(s) A, B and C"
837 if ( count( $user_names ) ) {
838 $user = $this->msg( 'siteusers' )
839 ->rawParams( $lang->listToText( $user_names ) )
840 ->params( count( $user_names ) )->escaped();
841 } else {
842 $user = false;
845 if ( count( $anon_ips ) ) {
846 $anon = $this->msg( 'anonusers' )
847 ->rawParams( $lang->listToText( $anon_ips ) )
848 ->params( count( $anon_ips ) )->escaped();
849 } else {
850 $anon = false;
853 # This is the big list, all mooshed together. We sift for blank strings
854 $fulllist = [];
855 foreach ( [ $real, $user, $anon ] as $s ) {
856 if ( $s !== '' ) {
857 array_push( $fulllist, $s );
861 $count = count( $fulllist );
863 # "Based on work by ..."
864 return $count
865 ? $this->msg( 'othercontribs' )->rawParams(
866 $lang->listToText( $fulllist ) )->params( $count )->escaped()
867 : '';
871 * Returns the description that goes below the "<h1>" tag.
873 * @return string
875 protected function getDescription() {
876 return '';
880 * @param Title $title
881 * @param int $revId
882 * @return string
884 protected static function getCacheKey( Title $title, $revId ) {
885 return wfMemcKey( 'infoaction', md5( $title->getPrefixedText() ), $revId, self::VERSION );