MediaWiki 1.42.1
InfoAction.php
Go to the documentation of this file.
1<?php
54
61 private const VERSION = 1;
62
63 private Language $contentLanguage;
64 private LanguageNameUtils $languageNameUtils;
65 private LinkBatchFactory $linkBatchFactory;
66 private LinkRenderer $linkRenderer;
67 private IConnectionProvider $dbProvider;
68 private MagicWordFactory $magicWordFactory;
69 private NamespaceInfo $namespaceInfo;
70 private PageProps $pageProps;
71 private RepoGroup $repoGroup;
72 private RevisionLookup $revisionLookup;
73 private WANObjectCache $wanObjectCache;
74 private WatchedItemStoreInterface $watchedItemStore;
75 private RedirectLookup $redirectLookup;
76 private RestrictionStore $restrictionStore;
77 private LinksMigration $linksMigration;
78 private UserFactory $userFactory;
79
80 public function __construct(
81 Article $article,
82 IContextSource $context,
83 Language $contentLanguage,
84 LanguageNameUtils $languageNameUtils,
85 LinkBatchFactory $linkBatchFactory,
86 LinkRenderer $linkRenderer,
87 IConnectionProvider $dbProvider,
88 MagicWordFactory $magicWordFactory,
89 NamespaceInfo $namespaceInfo,
90 PageProps $pageProps,
91 RepoGroup $repoGroup,
92 RevisionLookup $revisionLookup,
93 WANObjectCache $wanObjectCache,
94 WatchedItemStoreInterface $watchedItemStore,
95 RedirectLookup $redirectLookup,
96 RestrictionStore $restrictionStore,
97 LinksMigration $linksMigration,
98 UserFactory $userFactory
99 ) {
100 parent::__construct( $article, $context );
101 $this->contentLanguage = $contentLanguage;
102 $this->languageNameUtils = $languageNameUtils;
103 $this->linkBatchFactory = $linkBatchFactory;
104 $this->linkRenderer = $linkRenderer;
105 $this->dbProvider = $dbProvider;
106 $this->magicWordFactory = $magicWordFactory;
107 $this->namespaceInfo = $namespaceInfo;
108 $this->pageProps = $pageProps;
109 $this->repoGroup = $repoGroup;
110 $this->revisionLookup = $revisionLookup;
111 $this->wanObjectCache = $wanObjectCache;
112 $this->watchedItemStore = $watchedItemStore;
113 $this->redirectLookup = $redirectLookup;
114 $this->restrictionStore = $restrictionStore;
115 $this->linksMigration = $linksMigration;
116 $this->userFactory = $userFactory;
117 }
118
120 public function getName() {
121 return 'info';
122 }
123
125 public function requiresUnblock() {
126 return false;
127 }
128
130 public function requiresWrite() {
131 return false;
132 }
133
141 public static function invalidateCache( PageIdentity $page, $revid = null ) {
142 $services = MediaWikiServices::getInstance();
143 if ( $revid === null ) {
144 $revision = $services->getRevisionLookup()
145 ->getRevisionByTitle( $page, 0, IDBAccessObject::READ_LATEST );
146 $revid = $revision ? $revision->getId() : 0;
147 }
148 $cache = $services->getMainWANObjectCache();
149 $key = self::getCacheKey( $cache, $page, $revid ?? 0 );
150 $cache->delete( $key );
151 }
152
158 public function onView() {
159 $this->getOutput()->addModuleStyles( [
160 'mediawiki.interface.helpers.styles',
161 'mediawiki.action.styles',
162 ] );
163
164 // "Help" button
165 $this->addHelpLink( 'Page information' );
166
167 // Validate revision
168 $oldid = $this->getArticle()->getOldID();
169 if ( $oldid ) {
170 $revRecord = $this->getArticle()->fetchRevisionRecord();
171
172 if ( !$revRecord ) {
173 return $this->msg( 'missing-revision', $oldid )->parse();
174 } elseif ( !$revRecord->isCurrent() ) {
175 return $this->msg( 'pageinfo-not-current' )->plain();
176 }
177 }
178
179 // Page header
180 $msg = $this->msg( 'pageinfo-header' );
181 $content = $msg->isDisabled() ? '' : $msg->parse();
182
183 // Get page information
184 $pageInfo = $this->pageInfo();
185
186 // Allow extensions to add additional information
187 $this->getHookRunner()->onInfoAction( $this->getContext(), $pageInfo );
188
189 // Render page information
190 foreach ( $pageInfo as $header => $infoTable ) {
191 // Messages:
192 // pageinfo-header-basic, pageinfo-header-edits, pageinfo-header-restrictions,
193 // pageinfo-header-properties, pageinfo-category-info
194 $content .= $this->makeHeader(
195 $this->msg( "pageinfo-$header" )->text(),
196 "mw-pageinfo-$header"
197 ) . "\n";
198 $rows = '';
199 $below = "";
200 foreach ( $infoTable as $infoRow ) {
201 if ( $infoRow[0] == "below" ) {
202 $below = $infoRow[1] . "\n";
203 continue;
204 }
205 $name = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->escaped() : $infoRow[0];
206 $value = ( $infoRow[1] instanceof Message ) ? $infoRow[1]->escaped() : $infoRow[1];
207 $id = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->getKey() : null;
208 $rows .= $this->getRow( $name, $value, $id ) . "\n";
209 }
210 if ( $rows !== '' ) {
211 $content .= Html::rawElement( 'table', [ 'class' => 'wikitable mw-page-info' ],
212 "\n" . $rows );
213 }
214 $content .= "\n" . $below;
215 }
216
217 // Page footer
218 if ( !$this->msg( 'pageinfo-footer' )->isDisabled() ) {
219 $content .= $this->msg( 'pageinfo-footer' )->parse();
220 }
221
222 return $content;
223 }
224
232 private function makeHeader( $header, $canonicalId ) {
233 return Html::rawElement(
234 'h2',
235 [ 'id' => Sanitizer::escapeIdForAttribute( $header ) ],
236 Html::element(
237 'span',
238 [ 'id' => Sanitizer::escapeIdForAttribute( $canonicalId ) ],
239 ''
240 ) .
241 htmlspecialchars( $header )
242 );
243 }
244
251 private function getRow( $name, $value, $id ) {
252 return Html::rawElement(
253 'tr',
254 [
255 'id' => $id === null ? null : 'mw-' . $id,
256 'style' => 'vertical-align: top;',
257 ],
258 Html::rawElement( 'td', [], $name ) .
259 Html::rawElement( 'td', [], $value )
260 );
261 }
262
276 private function pageInfo() {
277 $user = $this->getUser();
278 $lang = $this->getLanguage();
279 $title = $this->getTitle();
280 $id = $title->getArticleID();
281 $config = $this->context->getConfig();
282 $linkRenderer = $this->linkRenderer;
283
284 $pageCounts = $this->pageCounts();
285
286 $pageProperties = $this->pageProps->getAllProperties( $title )[$id] ?? [];
287
288 // Basic information
289 $pageInfo = [];
290 $pageInfo['header-basic'] = [];
291
292 // Display title
293 $displayTitle = $pageProperties['displaytitle'] ??
294 htmlspecialchars( $title->getPrefixedText(), ENT_NOQUOTES );
295
296 $pageInfo['header-basic'][] = [
297 $this->msg( 'pageinfo-display-title' ),
298 $displayTitle
299 ];
300
301 // Is it a redirect? If so, where to?
302 $redirectTarget = $this->redirectLookup->getRedirectTarget( $this->getWikiPage() );
303 if ( $redirectTarget !== null ) {
304 $pageInfo['header-basic'][] = [
305 $this->msg( 'pageinfo-redirectsto' ),
306 $linkRenderer->makeLink( $redirectTarget ) .
307 $this->msg( 'word-separator' )->escaped() .
308 $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
309 $redirectTarget,
310 $this->msg( 'pageinfo-redirectsto-info' )->text(),
311 [],
312 [ 'action' => 'info' ]
313 ) )->escaped()
314 ];
315 }
316
317 // Default sort key
318 $sortKey = $pageProperties['defaultsort'] ?? $title->getCategorySortkey();
319 $pageInfo['header-basic'][] = [
320 $this->msg( 'pageinfo-default-sort' ),
321 htmlspecialchars( $sortKey )
322 ];
323
324 // Page length (in bytes)
325 $pageInfo['header-basic'][] = [
326 $this->msg( 'pageinfo-length' ),
327 $lang->formatNum( $title->getLength() )
328 ];
329
330 // Page namespace
331 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-namespace-id' ), $title->getNamespace() ];
332 $pageNamespace = $title->getNsText();
333 if ( $pageNamespace ) {
334 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-namespace' ), $pageNamespace ];
335 }
336
337 // Page ID (number not localised, as it's a database ID)
338 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-article-id' ), $id ];
339
340 // Language in which the page content is (supposed to be) written
341 $pageLang = $title->getPageLanguage()->getCode();
342
343 $pageLangHtml = $pageLang . ' - ' .
344 $this->languageNameUtils->getLanguageName( $pageLang, $lang->getCode() );
345 // Link to Special:PageLanguage with pre-filled page title if user has permissions
346 if ( $config->get( MainConfigNames::PageLanguageUseDB )
347 && $this->getAuthority()->probablyCan( 'pagelang', $title )
348 ) {
349 $pageLangHtml .= $this->msg( 'word-separator' )->escaped();
350 $pageLangHtml .= $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
351 SpecialPage::getTitleValueFor( 'PageLanguage', $title->getPrefixedText() ),
352 $this->msg( 'pageinfo-language-change' )->text()
353 ) )->escaped();
354 }
355
356 $pageInfo['header-basic'][] = [
357 $this->msg( 'pageinfo-language' )->escaped(),
358 $pageLangHtml
359 ];
360
361 // Content model of the page
362 $modelHtml = htmlspecialchars( ContentHandler::getLocalizedName( $title->getContentModel() ) );
363 // If the user can change it, add a link to Special:ChangeContentModel
364 if ( $this->getAuthority()->probablyCan( 'editcontentmodel', $title ) ) {
365 $modelHtml .= $this->msg( 'word-separator' )->escaped();
366 $modelHtml .= $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
367 SpecialPage::getTitleValueFor( 'ChangeContentModel', $title->getPrefixedText() ),
368 $this->msg( 'pageinfo-content-model-change' )->text()
369 ) )->escaped();
370 }
371
372 $pageInfo['header-basic'][] = [
373 $this->msg( 'pageinfo-content-model' ),
374 $modelHtml
375 ];
376
377 if ( $title->inNamespace( NS_USER ) ) {
378 $pageUser = $this->userFactory->newFromName( $title->getRootText() );
379 if ( $pageUser && $pageUser->getId() && !$pageUser->isHidden() ) {
380 $pageInfo['header-basic'][] = [
381 $this->msg( 'pageinfo-user-id' ),
382 $pageUser->getId()
383 ];
384 }
385 }
386
387 // Search engine status
388 $parserOutput = new ParserOutput();
389 if ( isset( $pageProperties['noindex'] ) ) {
390 $parserOutput->setIndexPolicy( 'noindex' );
391 }
392 if ( isset( $pageProperties['index'] ) ) {
393 $parserOutput->setIndexPolicy( 'index' );
394 }
395
396 // Use robot policy logic
397 $policy = $this->getArticle()->getRobotPolicy( 'view', $parserOutput );
398 $pageInfo['header-basic'][] = [
399 // Messages: pageinfo-robot-index, pageinfo-robot-noindex
400 $this->msg( 'pageinfo-robot-policy' ),
401 $this->msg( "pageinfo-robot-{$policy['index']}" )
402 ];
403
404 $unwatchedPageThreshold = $config->get( MainConfigNames::UnwatchedPageThreshold );
405 if ( $this->getAuthority()->isAllowed( 'unwatchedpages' ) ||
406 ( $unwatchedPageThreshold !== false &&
407 $pageCounts['watchers'] >= $unwatchedPageThreshold )
408 ) {
409 // Number of page watchers
410 $pageInfo['header-basic'][] = [
411 $this->msg( 'pageinfo-watchers' ),
412 $lang->formatNum( $pageCounts['watchers'] )
413 ];
414
415 $visiting = $pageCounts['visitingWatchers'] ?? null;
416 if ( $visiting !== null && $config->get( MainConfigNames::ShowUpdatedMarker ) ) {
417 if ( $visiting > $config->get( MainConfigNames::UnwatchedPageSecret ) ||
418 $this->getAuthority()->isAllowed( 'unwatchedpages' )
419 ) {
420 $value = $lang->formatNum( $visiting );
421 } else {
422 $value = $this->msg( 'pageinfo-few-visiting-watchers' );
423 }
424 $pageInfo['header-basic'][] = [
425 $this->msg( 'pageinfo-visiting-watchers' ),
426 $value
427 ];
428 }
429 } elseif ( $unwatchedPageThreshold !== false ) {
430 $pageInfo['header-basic'][] = [
431 $this->msg( 'pageinfo-watchers' ),
432 $this->msg( 'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
433 ];
434 }
435
436 // Redirects to this page
437 $whatLinksHere = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
438 $pageInfo['header-basic'][] = [
439 $linkRenderer->makeLink(
440 $whatLinksHere,
441 $this->msg( 'pageinfo-redirects-name' )->text(),
442 [],
443 [
444 'hidelinks' => 1,
445 'hidetrans' => 1,
446 'hideimages' => $title->getNamespace() === NS_FILE
447 ]
448 ),
449 $this->msg( 'pageinfo-redirects-value' )
450 ->numParams( count( $title->getRedirectsHere() ) )
451 ];
452
453 // Is it counted as a content page?
454 if ( $this->getWikiPage()->isCountable() ) {
455 $pageInfo['header-basic'][] = [
456 $this->msg( 'pageinfo-contentpage' ),
457 $this->msg( 'pageinfo-contentpage-yes' )
458 ];
459 }
460
461 // Subpages of this page, if subpages are enabled for the current NS
462 if ( $this->namespaceInfo->hasSubpages( $title->getNamespace() ) ) {
463 $prefixIndex = SpecialPage::getTitleFor(
464 'Prefixindex',
465 $title->getPrefixedText() . '/'
466 );
467 $pageInfo['header-basic'][] = [
468 $linkRenderer->makeLink(
469 $prefixIndex,
470 $this->msg( 'pageinfo-subpages-name' )->text()
471 ),
472 // $wgNamespacesWithSubpages can be changed and this can be unset (T340749)
473 isset( $pageCounts['subpages'] )
474 ? $this->msg( 'pageinfo-subpages-value' )->numParams(
475 $pageCounts['subpages']['total'],
476 $pageCounts['subpages']['redirects'],
477 $pageCounts['subpages']['nonredirects']
478 ) : $this->msg( 'pageinfo-subpages-value-unknown' )->rawParams(
479 $linkRenderer->makeKnownLink(
480 $title, $this->msg( 'purge' )->text(), [], [ 'action' => 'purge' ] )
481 )
482 ];
483 }
484
485 if ( $title->inNamespace( NS_CATEGORY ) ) {
486 $category = Category::newFromTitle( $title );
487
488 $allCount = $category->getMemberCount();
489 $subcatCount = $category->getSubcatCount();
490 $fileCount = $category->getFileCount();
491 $pageCount = $category->getPageCount( Category::COUNT_CONTENT_PAGES );
492
493 $pageInfo['category-info'] = [
494 [
495 $this->msg( 'pageinfo-category-total' ),
496 $lang->formatNum( $allCount )
497 ],
498 [
499 $this->msg( 'pageinfo-category-pages' ),
500 $lang->formatNum( $pageCount )
501 ],
502 [
503 $this->msg( 'pageinfo-category-subcats' ),
504 $lang->formatNum( $subcatCount )
505 ],
506 [
507 $this->msg( 'pageinfo-category-files' ),
508 $lang->formatNum( $fileCount )
509 ]
510 ];
511 }
512
513 // Display image SHA-1 value
514 if ( $title->inNamespace( NS_FILE ) ) {
515 $fileObj = $this->repoGroup->findFile( $title );
516 if ( $fileObj !== false ) {
517 // Convert the base-36 sha1 value obtained from database to base-16
518 $output = Wikimedia\base_convert( $fileObj->getSha1(), 36, 16, 40 );
519 $pageInfo['header-basic'][] = [
520 $this->msg( 'pageinfo-file-hash' ),
521 $output
522 ];
523 }
524 }
525
526 // Page protection
527 $pageInfo['header-restrictions'] = [];
528
529 // Is this page affected by the cascading protection of something which includes it?
530 if ( $this->restrictionStore->isCascadeProtected( $title ) ) {
531 $cascadingFrom = '';
532 $sources = $this->restrictionStore->getCascadeProtectionSources( $title )[0];
533
534 foreach ( $sources as $sourcePageIdentity ) {
535 $cascadingFrom .= Html::rawElement(
536 'li',
537 [],
538 $linkRenderer->makeKnownLink( $sourcePageIdentity )
539 );
540 }
541
542 $cascadingFrom = Html::rawElement( 'ul', [], $cascadingFrom );
543 $pageInfo['header-restrictions'][] = [
544 $this->msg( 'pageinfo-protect-cascading-from' ),
545 $cascadingFrom
546 ];
547 }
548
549 // Is out protection set to cascade to other pages?
550 if ( $this->restrictionStore->areRestrictionsCascading( $title ) ) {
551 $pageInfo['header-restrictions'][] = [
552 $this->msg( 'pageinfo-protect-cascading' ),
553 $this->msg( 'pageinfo-protect-cascading-yes' )
554 ];
555 }
556
557 // Page protection
558 foreach ( $this->restrictionStore->listApplicableRestrictionTypes( $title ) as $restrictionType ) {
559 $protections = $this->restrictionStore->getRestrictions( $title, $restrictionType );
560
561 switch ( count( $protections ) ) {
562 case 0:
563 $message = $this->getNamespaceProtectionMessage( $title ) ??
564 // Allow all users by default
565 $this->msg( 'protect-default' )->escaped();
566 break;
567
568 case 1:
569 // Messages: protect-level-autoconfirmed, protect-level-sysop
570 $message = $this->msg( 'protect-level-' . $protections[0] );
571 if ( !$message->isDisabled() ) {
572 $message = $message->escaped();
573 break;
574 }
575 // Intentional fall-through if message is disabled (or non-existent)
576
577 default:
578 // Require "$1" permission
579 $message = $this->msg( "protect-fallback", $lang->commaList( $protections ) )->parse();
580 break;
581 }
582 $expiry = $this->restrictionStore->getRestrictionExpiry( $title, $restrictionType );
583 $formattedexpiry = $expiry === null ? '' : $this->msg(
584 'parentheses',
585 $lang->formatExpiry( $expiry, true, 'infinity', $user )
586 )->escaped();
587 $message .= $this->msg( 'word-separator' )->escaped() . $formattedexpiry;
588
589 // Messages: restriction-edit, restriction-move, restriction-create,
590 // restriction-upload
591 $pageInfo['header-restrictions'][] = [
592 $this->msg( "restriction-$restrictionType" ), $message
593 ];
594 }
595 $protectLog = SpecialPage::getTitleFor( 'Log' );
596 $pageInfo['header-restrictions'][] = [
597 'below',
598 $linkRenderer->makeKnownLink(
599 $protectLog,
600 $this->msg( 'pageinfo-view-protect-log' )->text(),
601 [],
602 [ 'type' => 'protect', 'page' => $title->getPrefixedText() ]
603 ),
604 ];
605
606 if ( !$this->getWikiPage()->exists() ) {
607 return $pageInfo;
608 }
609
610 // Edit history
611 $pageInfo['header-edits'] = [];
612
613 $firstRev = $this->revisionLookup->getFirstRevision( $this->getTitle() );
614 $lastRev = $this->getWikiPage()->getRevisionRecord();
615 $batch = $this->linkBatchFactory->newLinkBatch();
616 if ( $firstRev ) {
617 $firstRevUser = $firstRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
618 if ( $firstRevUser ) {
619 $batch->add( NS_USER, $firstRevUser->getName() );
620 $batch->add( NS_USER_TALK, $firstRevUser->getName() );
621 }
622 }
623
624 if ( $lastRev ) {
625 $lastRevUser = $lastRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
626 if ( $lastRevUser ) {
627 $batch->add( NS_USER, $lastRevUser->getName() );
628 $batch->add( NS_USER_TALK, $lastRevUser->getName() );
629 }
630 }
631
632 $batch->execute();
633
634 if ( $firstRev ) {
635 // Page creator
636 $firstRevUser = $firstRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
637 // Check if the username is available – it may have been suppressed, in
638 // which case use the invalid user name '[HIDDEN]' to get the wiki's
639 // default user gender.
640 $firstRevUserName = $firstRevUser ? $firstRevUser->getName() : '[HIDDEN]';
641 $pageInfo['header-edits'][] = [
642 $this->msg( 'pageinfo-firstuser', $firstRevUserName ),
643 Linker::revUserTools( $firstRev )
644 ];
645
646 // Date of page creation
647 $pageInfo['header-edits'][] = [
648 $this->msg( 'pageinfo-firsttime' ),
649 $linkRenderer->makeKnownLink(
650 $title,
651 $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ),
652 [],
653 [ 'oldid' => $firstRev->getId() ]
654 )
655 ];
656 }
657
658 if ( $lastRev ) {
659 // Latest editor
660 $lastRevUser = $lastRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
661 // Check if the username is available – it may have been suppressed, in
662 // which case use the invalid user name '[HIDDEN]' to get the wiki's
663 // default user gender.
664 $lastRevUserName = $lastRevUser ? $lastRevUser->getName() : '[HIDDEN]';
665 $pageInfo['header-edits'][] = [
666 $this->msg( 'pageinfo-lastuser', $lastRevUserName ),
667 Linker::revUserTools( $lastRev )
668 ];
669
670 // Date of latest edit
671 $pageInfo['header-edits'][] = [
672 $this->msg( 'pageinfo-lasttime' ),
673 $linkRenderer->makeKnownLink(
674 $title,
675 $lang->userTimeAndDate( $this->getWikiPage()->getTimestamp(), $user ),
676 [],
677 [ 'oldid' => $this->getWikiPage()->getLatest() ]
678 )
679 ];
680 }
681
682 // Total number of edits
683 $pageInfo['header-edits'][] = [
684 $this->msg( 'pageinfo-edits' ),
685 $lang->formatNum( $pageCounts['edits'] )
686 ];
687
688 // Total number of distinct authors
689 if ( $pageCounts['authors'] > 0 ) {
690 $pageInfo['header-edits'][] = [
691 $this->msg( 'pageinfo-authors' ),
692 $lang->formatNum( $pageCounts['authors'] )
693 ];
694 }
695
696 // Recent number of edits (within past 30 days)
697 $pageInfo['header-edits'][] = [
698 $this->msg(
699 'pageinfo-recent-edits',
700 $lang->formatDuration( $config->get( MainConfigNames::RCMaxAge ) )
701 ),
702 $lang->formatNum( $pageCounts['recent_edits'] )
703 ];
704
705 // Recent number of distinct authors
706 $pageInfo['header-edits'][] = [
707 $this->msg( 'pageinfo-recent-authors' ),
708 $lang->formatNum( $pageCounts['recent_authors'] )
709 ];
710
711 // Array of magic word IDs
712 $wordIDs = $this->magicWordFactory->getDoubleUnderscoreArray()->getNames();
713
714 // Array of IDs => localized magic words
715 $localizedWords = $this->contentLanguage->getMagicWords();
716
717 $listItems = [];
718 foreach ( $pageProperties as $property => $value ) {
719 if ( in_array( $property, $wordIDs ) ) {
720 $listItems[] = Html::element( 'li', [], $localizedWords[$property][1] );
721 }
722 }
723
724 $localizedList = Html::rawElement( 'ul', [], implode( '', $listItems ) );
725 $hiddenCategories = $this->getWikiPage()->getHiddenCategories();
726
727 if (
728 count( $listItems ) > 0 ||
729 count( $hiddenCategories ) > 0 ||
730 $pageCounts['transclusion']['from'] > 0 ||
731 $pageCounts['transclusion']['to'] > 0
732 ) {
733 $options = [ 'LIMIT' => $config->get( MainConfigNames::PageInfoTransclusionLimit ) ];
734 $transcludedTemplates = $title->getTemplateLinksFrom( $options );
735 if ( $config->get( MainConfigNames::MiserMode ) ) {
736 $transcludedTargets = [];
737 } else {
738 $transcludedTargets = $title->getTemplateLinksTo( $options );
739 }
740
741 // Page properties
742 $pageInfo['header-properties'] = [];
743
744 // Magic words
745 if ( count( $listItems ) > 0 ) {
746 $pageInfo['header-properties'][] = [
747 $this->msg( 'pageinfo-magic-words' )->numParams( count( $listItems ) ),
748 $localizedList
749 ];
750 }
751
752 // Hidden categories
753 if ( count( $hiddenCategories ) > 0 ) {
754 $pageInfo['header-properties'][] = [
755 $this->msg( 'pageinfo-hidden-categories' )
756 ->numParams( count( $hiddenCategories ) ),
757 Linker::formatHiddenCategories( $hiddenCategories )
758 ];
759 }
760
761 // Transcluded templates
762 if ( $pageCounts['transclusion']['from'] > 0 ) {
763 if ( $pageCounts['transclusion']['from'] > count( $transcludedTemplates ) ) {
764 $more = $this->msg( 'morenotlisted' )->escaped();
765 } else {
766 $more = null;
767 }
768
769 $templateListFormatter = new TemplatesOnThisPageFormatter(
770 $this->getContext(),
771 $linkRenderer,
772 $this->linkBatchFactory,
773 $this->restrictionStore
774 );
775
776 $pageInfo['header-properties'][] = [
777 $this->msg( 'pageinfo-templates' )
778 ->numParams( $pageCounts['transclusion']['from'] ),
779 $templateListFormatter->format( $transcludedTemplates, false, $more )
780 ];
781 }
782
783 if ( !$config->get( MainConfigNames::MiserMode ) && $pageCounts['transclusion']['to'] > 0 ) {
784 if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) {
785 $more = $linkRenderer->makeLink(
786 $whatLinksHere,
787 $this->msg( 'moredotdotdot' )->text(),
788 [],
789 [ 'hidelinks' => 1, 'hideredirs' => 1 ]
790 );
791 } else {
792 $more = null;
793 }
794
795 $templateListFormatter = new TemplatesOnThisPageFormatter(
796 $this->getContext(),
797 $linkRenderer,
798 $this->linkBatchFactory,
799 $this->restrictionStore
800 );
801
802 $pageInfo['header-properties'][] = [
803 $this->msg( 'pageinfo-transclusions' )
804 ->numParams( $pageCounts['transclusion']['to'] ),
805 $templateListFormatter->format( $transcludedTargets, false, $more )
806 ];
807 }
808 }
809
810 return $pageInfo;
811 }
812
820 private function getNamespaceProtectionMessage( Title $title ): ?string {
821 $rights = [];
822 if ( $title->isRawHtmlMessage() ) {
823 $rights[] = 'editsitecss';
824 $rights[] = 'editsitejs';
825 } elseif ( $title->isSiteCssConfigPage() ) {
826 $rights[] = 'editsitecss';
827 } elseif ( $title->isSiteJsConfigPage() ) {
828 $rights[] = 'editsitejs';
829 } elseif ( $title->isSiteJsonConfigPage() ) {
830 $rights[] = 'editsitejson';
831 } elseif ( $title->isUserCssConfigPage() ) {
832 $rights[] = 'editusercss';
833 } elseif ( $title->isUserJsConfigPage() ) {
834 $rights[] = 'edituserjs';
835 } elseif ( $title->isUserJsonConfigPage() ) {
836 $rights[] = 'edituserjson';
837 } else {
838 $namespaceProtection = $this->context->getConfig()->get( MainConfigNames::NamespaceProtection );
839 $right = $namespaceProtection[$title->getNamespace()] ?? null;
840 if ( $right ) {
841 // a single string as the value is allowed as well as an array
842 $rights = (array)$right;
843 }
844 }
845 if ( $rights ) {
846 return $this->msg( 'protect-fallback', $this->getLanguage()->commaList( $rights ) )->parse();
847 } else {
848 return null;
849 }
850 }
851
857 private function pageCounts() {
858 $page = $this->getWikiPage();
859 $fname = __METHOD__;
860 $config = $this->context->getConfig();
861 $cache = $this->wanObjectCache;
862
863 return $cache->getWithSetCallback(
864 self::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ),
865 WANObjectCache::TTL_WEEK,
866 function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
867 $title = $page->getTitle();
868 $id = $title->getArticleID();
869
870 $dbr = $this->dbProvider->getReplicaDatabase();
871 $setOpts += Database::getCacheSetOptions( $dbr );
872
873 $field = 'rev_actor';
874 $pageField = 'rev_page';
875
876 $watchedItemStore = $this->watchedItemStore;
877
878 $result = [];
879 $result['watchers'] = $watchedItemStore->countWatchers( $title );
880
881 if ( $config->get( MainConfigNames::ShowUpdatedMarker ) ) {
882 $updated = (int)wfTimestamp( TS_UNIX, $page->getTimestamp() );
883 $result['visitingWatchers'] = $watchedItemStore->countVisitingWatchers(
884 $title,
885 $updated - $config->get( MainConfigNames::WatchersMaxAge )
886 );
887 }
888
889 // Total number of edits
890 $edits = (int)$dbr->newSelectQueryBuilder()
891 ->select( 'COUNT(*)' )
892 ->from( 'revision' )
893 ->where( [ 'rev_page' => $id ] )
894 ->caller( $fname )
895 ->fetchField();
896 $result['edits'] = $edits;
897
898 // Total number of distinct authors
899 if ( $config->get( MainConfigNames::MiserMode ) ) {
900 $result['authors'] = 0;
901 } else {
902 $result['authors'] = (int)$dbr->newSelectQueryBuilder()
903 ->select( "COUNT(DISTINCT $field)" )
904 ->from( 'revision' )
905 ->where( [ $pageField => $id ] )
906 ->caller( $fname )
907 ->fetchField();
908 }
909
910 // "Recent" threshold defined by RCMaxAge setting
911 $threshold = $dbr->timestamp( time() - $config->get( MainConfigNames::RCMaxAge ) );
912
913 // Recent number of edits
914 $edits = (int)$dbr->newSelectQueryBuilder()
915 ->select( 'COUNT(rev_page)' )
916 ->from( 'revision' )
917 ->where( [ 'rev_page' => $id ] )
918 ->andWhere( $dbr->expr( 'rev_timestamp', '>=', $threshold ) )
919 ->caller( $fname )
920 ->fetchField();
921 $result['recent_edits'] = $edits;
922
923 // Recent number of distinct authors
924 $result['recent_authors'] = (int)$dbr->newSelectQueryBuilder()
925 ->select( "COUNT(DISTINCT $field)" )
926 ->from( 'revision' )
927 ->where( [ $pageField => $id ] )
928 ->andWhere( [ $dbr->expr( 'rev_timestamp', '>=', $threshold ) ] )
929 ->caller( $fname )
930 ->fetchField();
931
932 // Subpages (if enabled)
933 if ( $this->namespaceInfo->hasSubpages( $title->getNamespace() ) ) {
934 $conds = [ 'page_namespace' => $title->getNamespace() ];
935 $conds[] = $dbr->expr(
936 'page_title',
937 IExpression::LIKE,
938 new LikeValue( $title->getDBkey() . '/', $dbr->anyString() )
939 );
940
941 // Subpages of this page (redirects)
942 $conds['page_is_redirect'] = 1;
943 $result['subpages']['redirects'] = (int)$dbr->newSelectQueryBuilder()
944 ->select( 'COUNT(page_id)' )
945 ->from( 'page' )
946 ->where( $conds )
947 ->caller( $fname )
948 ->fetchField();
949 // Subpages of this page (non-redirects)
950 $conds['page_is_redirect'] = 0;
951 $result['subpages']['nonredirects'] = (int)$dbr->newSelectQueryBuilder()
952 ->select( 'COUNT(page_id)' )
953 ->from( 'page' )
954 ->where( $conds )
955 ->caller( $fname )
956 ->fetchField();
957
958 // Subpages of this page (total)
959 $result['subpages']['total'] = $result['subpages']['redirects']
960 + $result['subpages']['nonredirects'];
961 }
962
963 // Counts for the number of transclusion links (to/from)
964 if ( $config->get( MainConfigNames::MiserMode ) ) {
965 $result['transclusion']['to'] = 0;
966 } else {
967 $result['transclusion']['to'] = (int)$dbr->newSelectQueryBuilder()
968 ->select( 'COUNT(tl_from)' )
969 ->from( 'templatelinks' )
970 ->where( $this->linksMigration->getLinksConditions( 'templatelinks', $title ) )
971 ->caller( $fname )
972 ->fetchField();
973 }
974
975 $result['transclusion']['from'] = (int)$dbr->newSelectQueryBuilder()
976 ->select( 'COUNT(*)' )
977 ->from( 'templatelinks' )
978 ->where( [ 'tl_from' => $title->getArticleID() ] )
979 ->caller( $fname )
980 ->fetchField();
981
982 return $result;
983 }
984 );
985 }
986
992 protected function getPageTitle() {
993 return $this->msg( 'pageinfo-title' )->plaintextParams( $this->getTitle()->getPrefixedText() );
994 }
995
1001 protected function getDescription() {
1002 return '';
1003 }
1004
1011 protected static function getCacheKey( WANObjectCache $cache, PageIdentity $page, $revId ) {
1012 return $cache->makeKey( 'infoaction', md5( (string)$page ), $revId, self::VERSION );
1013 }
1014}
getUser()
getAuthority()
const NS_USER
Definition Defines.php:66
const NS_FILE
Definition Defines.php:70
const NS_USER_TALK
Definition Defines.php:67
const NS_CATEGORY
Definition Defines.php:78
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
getContext()
getCacheKey()
Get the cache key used to store status.
getWikiPage()
Get a WikiPage object.
Definition Action.php:190
getHookRunner()
Definition Action.php:255
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition Action.php:442
getOutput()
Get the OutputPage being used for this instance.
Definition Action.php:141
getArticle()
Get a Article object.
Definition Action.php:201
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition Action.php:223
getLanguage()
Shortcut to get the user Language being used for this instance.
Definition Action.php:180
Legacy class representing an editable page and handling UI for some page actions.
Definition Article.php:67
An action which just does something, without showing a form first.
Displays information about a page.
requiresWrite()
Whether this action requires the wiki not to be locked.Implementations of this methods must always re...
__construct(Article $article, IContextSource $context, Language $contentLanguage, LanguageNameUtils $languageNameUtils, LinkBatchFactory $linkBatchFactory, LinkRenderer $linkRenderer, IConnectionProvider $dbProvider, MagicWordFactory $magicWordFactory, NamespaceInfo $namespaceInfo, PageProps $pageProps, RepoGroup $repoGroup, RevisionLookup $revisionLookup, WANObjectCache $wanObjectCache, WatchedItemStoreInterface $watchedItemStore, RedirectLookup $redirectLookup, RestrictionStore $restrictionStore, LinksMigration $linksMigration, UserFactory $userFactory)
getPageTitle()
Returns the name that goes in the "<h1>" page title.
static getCacheKey(WANObjectCache $cache, PageIdentity $page, $revId)
onView()
Shows page information on GET request.
getDescription()
Returns the description that goes below the "<h1>" tag.
requiresUnblock()
Whether this action can still be executed by a blocked user.Implementations of this methods must alwa...
getName()
Return the name of the action this object responds to.1.17string Lowercase name
static invalidateCache(PageIdentity $page, $revid=null)
Clear the info cache for a given Title.
Base class for language-specific code.
Definition Language.php:63
Category objects are immutable, strictly speaking.
Definition Category.php:42
Handles formatting for the "templates used on this page" lists.
This class is a collection of static functions that serve two purposes:
Definition Html.php:56
A service that provides utilities to do with language names and codes.
Class that generates HTML for internal links.
makeKnownLink( $target, $text=null, array $extraAttribs=[], array $query=[])
Make a link that's styled as if the target page exists (usually a "blue link", although the styling m...
makeLink( $target, $text=null, array $extraAttribs=[], array $query=[])
Render a wikilink.
Some internal bits split of from Skin.php.
Definition Linker.php:65
Service for compat reading of links tables.
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:157
Gives access to properties of a page.
Definition PageProps.php:35
Store information about magic words, and create/cache MagicWord objects.
Rendered output of a wiki page, as parsed from wikitext.
HTML sanitizer for MediaWiki.
Definition Sanitizer.php:46
Page revision base class.
Parent class for all special pages.
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Represents a title within MediaWiki.
Definition Title.php:78
getPageLanguage()
Get the language in which the content of this page is written in wikitext.
Definition Title.php:3637
isUserJsConfigPage()
Is this a JS "config" sub-page of a user page?
Definition Title.php:1520
isRawHtmlMessage()
Is this a message which can contain raw HTML?
Definition Title.php:1588
getNsText()
Get the namespace text.
Definition Title.php:1140
isSiteJsonConfigPage()
Is this a sitewide JSON "config" page?
Definition Title.php:1552
isSiteJsConfigPage()
Is this a sitewide JS "config" page?
Definition Title.php:1570
inNamespace(int $ns)
Returns true if the title is inside the specified namespace.
Definition Title.php:1302
isUserCssConfigPage()
Is this a CSS "config" sub-page of a user page?
Definition Title.php:1492
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition Title.php:2593
getNamespace()
Get the namespace index, i.e.
Definition Title.php:1044
getTemplateLinksTo( $options=[])
Get an array of Title objects using this Title as a template Also stores the IDs in the link cache.
Definition Title.php:2837
getLength( $flags=0)
What is the length of this page? Uses link cache, adding it if necessary.
Definition Title.php:2636
getDBkey()
Get the main part with underscores.
Definition Title.php:1035
getContentModel( $flags=0)
Get the page's content model id, see the CONTENT_MODEL_XXX constants.
Definition Title.php:1066
getRootText()
Get the root page name text without a namespace, i.e.
Definition Title.php:1945
getTemplateLinksFrom( $options=[])
Get an array of Title objects used on this Title as a template Also stores the IDs in the link cache.
Definition Title.php:2919
getRedirectsHere( $ns=null)
Get all extant redirects to this Title.
Definition Title.php:3498
getPrefixedText()
Get the prefixed title with spaces.
Definition Title.php:1861
getCategorySortkey( $prefix='')
Returns the raw sort key to be used for categories, with the specified prefix.
Definition Title.php:3569
isSiteCssConfigPage()
Is this a sitewide CSS "config" page?
Definition Title.php:1534
isUserJsonConfigPage()
Is this a JSON "config" sub-page of a user page?
Definition Title.php:1506
Creates User objects.
Prioritized list of file repositories.
Definition RepoGroup.php:30
Multi-datacenter aware caching interface.
makeKey( $keygroup,... $components)
static getCacheSetOptions(?IReadableDatabase ... $dbs)
Merge the result of getSessionLagStatus() for several DBs using the most pessimistic values to estima...
Content of like value.
Definition LikeValue.php:14
Interface for objects which can provide a MediaWiki context on request.
Interface for objects (potentially) representing an editable wiki page.
Service for resolving a wiki page redirect.
Service for looking up page revisions.
countVisitingWatchers( $target, $threshold)
Number of page watchers who also visited a "recent" edit.
Provide primary and replica IDatabase connections.
$header