MediaWiki master
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(
426 'pageinfo-visiting-watchers',
427 $title->getPageLanguage()->formatTimePeriod(
428 $config->get( MainConfigNames::WatchersMaxAge ),
429 [ 'avoid' => 'avoidhours', 'noabbrevs' => true ]
430 )
431 ),
432 $value
433 ];
434 }
435 } elseif ( $unwatchedPageThreshold !== false ) {
436 $pageInfo['header-basic'][] = [
437 $this->msg( 'pageinfo-watchers' ),
438 $this->msg( 'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
439 ];
440 }
441
442 // Redirects to this page
443 $whatLinksHere = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
444 $pageInfo['header-basic'][] = [
445 $linkRenderer->makeLink(
446 $whatLinksHere,
447 $this->msg( 'pageinfo-redirects-name' )->text(),
448 [],
449 [
450 'hidelinks' => 1,
451 'hidetrans' => 1,
452 'hideimages' => $title->getNamespace() === NS_FILE
453 ]
454 ),
455 $this->msg( 'pageinfo-redirects-value' )
456 ->numParams( count( $title->getRedirectsHere() ) )
457 ];
458
459 // Is it counted as a content page?
460 if ( $this->getWikiPage()->isCountable() ) {
461 $pageInfo['header-basic'][] = [
462 $this->msg( 'pageinfo-contentpage' ),
463 $this->msg( 'pageinfo-contentpage-yes' )
464 ];
465 }
466
467 // Subpages of this page, if subpages are enabled for the current NS
468 if ( $this->namespaceInfo->hasSubpages( $title->getNamespace() ) ) {
469 $prefixIndex = SpecialPage::getTitleFor(
470 'Prefixindex',
471 $title->getPrefixedText() . '/'
472 );
473 $pageInfo['header-basic'][] = [
474 $linkRenderer->makeLink(
475 $prefixIndex,
476 $this->msg( 'pageinfo-subpages-name' )->text()
477 ),
478 // $wgNamespacesWithSubpages can be changed and this can be unset (T340749)
479 isset( $pageCounts['subpages'] )
480 ? $this->msg( 'pageinfo-subpages-value' )->numParams(
481 $pageCounts['subpages']['total'],
482 $pageCounts['subpages']['redirects'],
483 $pageCounts['subpages']['nonredirects']
484 ) : $this->msg( 'pageinfo-subpages-value-unknown' )->rawParams(
485 $linkRenderer->makeKnownLink(
486 $title, $this->msg( 'purge' )->text(), [], [ 'action' => 'purge' ] )
487 )
488 ];
489 }
490
491 if ( $title->inNamespace( NS_CATEGORY ) ) {
492 $category = Category::newFromTitle( $title );
493
494 $allCount = $category->getMemberCount();
495 $subcatCount = $category->getSubcatCount();
496 $fileCount = $category->getFileCount();
497 $pageCount = $category->getPageCount( Category::COUNT_CONTENT_PAGES );
498
499 $pageInfo['category-info'] = [
500 [
501 $this->msg( 'pageinfo-category-total' ),
502 $lang->formatNum( $allCount )
503 ],
504 [
505 $this->msg( 'pageinfo-category-pages' ),
506 $lang->formatNum( $pageCount )
507 ],
508 [
509 $this->msg( 'pageinfo-category-subcats' ),
510 $lang->formatNum( $subcatCount )
511 ],
512 [
513 $this->msg( 'pageinfo-category-files' ),
514 $lang->formatNum( $fileCount )
515 ]
516 ];
517 }
518
519 // Display image SHA-1 value
520 if ( $title->inNamespace( NS_FILE ) ) {
521 $fileObj = $this->repoGroup->findFile( $title );
522 if ( $fileObj !== false ) {
523 // Convert the base-36 sha1 value obtained from database to base-16
524 $output = Wikimedia\base_convert( $fileObj->getSha1(), 36, 16, 40 );
525 $pageInfo['header-basic'][] = [
526 $this->msg( 'pageinfo-file-hash' ),
527 $output
528 ];
529 }
530 }
531
532 // Page protection
533 $pageInfo['header-restrictions'] = [];
534
535 // Is this page affected by the cascading protection of something which includes it?
536 if ( $this->restrictionStore->isCascadeProtected( $title ) ) {
537 $cascadingFrom = '';
538 $sources = $this->restrictionStore->getCascadeProtectionSources( $title )[0];
539
540 foreach ( $sources as $sourcePageIdentity ) {
541 $cascadingFrom .= Html::rawElement(
542 'li',
543 [],
544 $linkRenderer->makeKnownLink( $sourcePageIdentity )
545 );
546 }
547
548 $cascadingFrom = Html::rawElement( 'ul', [], $cascadingFrom );
549 $pageInfo['header-restrictions'][] = [
550 $this->msg( 'pageinfo-protect-cascading-from' ),
551 $cascadingFrom
552 ];
553 }
554
555 // Is out protection set to cascade to other pages?
556 if ( $this->restrictionStore->areRestrictionsCascading( $title ) ) {
557 $pageInfo['header-restrictions'][] = [
558 $this->msg( 'pageinfo-protect-cascading' ),
559 $this->msg( 'pageinfo-protect-cascading-yes' )
560 ];
561 }
562
563 // Page protection
564 foreach ( $this->restrictionStore->listApplicableRestrictionTypes( $title ) as $restrictionType ) {
565 $protections = $this->restrictionStore->getRestrictions( $title, $restrictionType );
566
567 switch ( count( $protections ) ) {
568 case 0:
569 $message = $this->getNamespaceProtectionMessage( $title ) ??
570 // Allow all users by default
571 $this->msg( 'protect-default' )->escaped();
572 break;
573
574 case 1:
575 // Messages: protect-level-autoconfirmed, protect-level-sysop
576 $message = $this->msg( 'protect-level-' . $protections[0] );
577 if ( !$message->isDisabled() ) {
578 $message = $message->escaped();
579 break;
580 }
581 // Intentional fall-through if message is disabled (or non-existent)
582
583 default:
584 // Require "$1" permission
585 $message = $this->msg( "protect-fallback", $lang->commaList( $protections ) )->parse();
586 break;
587 }
588 $expiry = $this->restrictionStore->getRestrictionExpiry( $title, $restrictionType );
589 $formattedexpiry = $expiry === null ? '' : $this->msg(
590 'parentheses',
591 $lang->formatExpiry( $expiry, true, 'infinity', $user )
592 )->escaped();
593 $message .= $this->msg( 'word-separator' )->escaped() . $formattedexpiry;
594
595 // Messages: restriction-edit, restriction-move, restriction-create,
596 // restriction-upload
597 $pageInfo['header-restrictions'][] = [
598 $this->msg( "restriction-$restrictionType" ), $message
599 ];
600 }
601 $protectLog = SpecialPage::getTitleFor( 'Log' );
602 $pageInfo['header-restrictions'][] = [
603 'below',
604 $linkRenderer->makeKnownLink(
605 $protectLog,
606 $this->msg( 'pageinfo-view-protect-log' )->text(),
607 [],
608 [ 'type' => 'protect', 'page' => $title->getPrefixedText() ]
609 ),
610 ];
611
612 if ( !$this->getWikiPage()->exists() ) {
613 return $pageInfo;
614 }
615
616 // Edit history
617 $pageInfo['header-edits'] = [];
618
619 $firstRev = $this->revisionLookup->getFirstRevision( $this->getTitle() );
620 $lastRev = $this->getWikiPage()->getRevisionRecord();
621 $batch = $this->linkBatchFactory->newLinkBatch();
622 if ( $firstRev ) {
623 $firstRevUser = $firstRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
624 if ( $firstRevUser ) {
625 $batch->add( NS_USER, $firstRevUser->getName() );
626 $batch->add( NS_USER_TALK, $firstRevUser->getName() );
627 }
628 }
629
630 if ( $lastRev ) {
631 $lastRevUser = $lastRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
632 if ( $lastRevUser ) {
633 $batch->add( NS_USER, $lastRevUser->getName() );
634 $batch->add( NS_USER_TALK, $lastRevUser->getName() );
635 }
636 }
637
638 $batch->execute();
639
640 if ( $firstRev ) {
641 // Page creator
642 $firstRevUser = $firstRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
643 // Check if the username is available – it may have been suppressed, in
644 // which case use the invalid user name '[HIDDEN]' to get the wiki's
645 // default user gender.
646 $firstRevUserName = $firstRevUser ? $firstRevUser->getName() : '[HIDDEN]';
647 $pageInfo['header-edits'][] = [
648 $this->msg( 'pageinfo-firstuser', $firstRevUserName ),
649 Linker::revUserTools( $firstRev )
650 ];
651
652 // Date of page creation
653 $pageInfo['header-edits'][] = [
654 $this->msg( 'pageinfo-firsttime' ),
655 $linkRenderer->makeKnownLink(
656 $title,
657 $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ),
658 [],
659 [ 'oldid' => $firstRev->getId() ]
660 )
661 ];
662 }
663
664 if ( $lastRev ) {
665 // Latest editor
666 $lastRevUser = $lastRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
667 // Check if the username is available – it may have been suppressed, in
668 // which case use the invalid user name '[HIDDEN]' to get the wiki's
669 // default user gender.
670 $lastRevUserName = $lastRevUser ? $lastRevUser->getName() : '[HIDDEN]';
671 $pageInfo['header-edits'][] = [
672 $this->msg( 'pageinfo-lastuser', $lastRevUserName ),
673 Linker::revUserTools( $lastRev )
674 ];
675
676 // Date of latest edit
677 $pageInfo['header-edits'][] = [
678 $this->msg( 'pageinfo-lasttime' ),
679 $linkRenderer->makeKnownLink(
680 $title,
681 $lang->userTimeAndDate( $this->getWikiPage()->getTimestamp(), $user ),
682 [],
683 [ 'oldid' => $this->getWikiPage()->getLatest() ]
684 )
685 ];
686 }
687
688 // Total number of edits
689 $pageInfo['header-edits'][] = [
690 $this->msg( 'pageinfo-edits' ),
691 $lang->formatNum( $pageCounts['edits'] )
692 ];
693
694 // Total number of distinct authors
695 if ( $pageCounts['authors'] > 0 ) {
696 $pageInfo['header-edits'][] = [
697 $this->msg( 'pageinfo-authors' ),
698 $lang->formatNum( $pageCounts['authors'] )
699 ];
700 }
701
702 // Recent number of edits (within past 30 days)
703 $pageInfo['header-edits'][] = [
704 $this->msg(
705 'pageinfo-recent-edits',
706 $lang->formatDuration( $config->get( MainConfigNames::RCMaxAge ) )
707 ),
708 $lang->formatNum( $pageCounts['recent_edits'] )
709 ];
710
711 // Recent number of distinct authors
712 $pageInfo['header-edits'][] = [
713 $this->msg( 'pageinfo-recent-authors' ),
714 $lang->formatNum( $pageCounts['recent_authors'] )
715 ];
716
717 // Array of magic word IDs
718 $wordIDs = $this->magicWordFactory->getDoubleUnderscoreArray()->getNames();
719
720 // Array of IDs => localized magic words
721 $localizedWords = $this->contentLanguage->getMagicWords();
722
723 $listItems = [];
724 foreach ( $pageProperties as $property => $value ) {
725 if ( in_array( $property, $wordIDs ) ) {
726 $listItems[] = Html::element( 'li', [], $localizedWords[$property][1] );
727 }
728 }
729
730 $localizedList = Html::rawElement( 'ul', [], implode( '', $listItems ) );
731 $hiddenCategories = $this->getWikiPage()->getHiddenCategories();
732
733 if (
734 count( $listItems ) > 0 ||
735 count( $hiddenCategories ) > 0 ||
736 $pageCounts['transclusion']['from'] > 0 ||
737 $pageCounts['transclusion']['to'] > 0
738 ) {
739 $options = [ 'LIMIT' => $config->get( MainConfigNames::PageInfoTransclusionLimit ) ];
740 $transcludedTemplates = $title->getTemplateLinksFrom( $options );
741 if ( $config->get( MainConfigNames::MiserMode ) ) {
742 $transcludedTargets = [];
743 } else {
744 $transcludedTargets = $title->getTemplateLinksTo( $options );
745 }
746
747 // Page properties
748 $pageInfo['header-properties'] = [];
749
750 // Magic words
751 if ( count( $listItems ) > 0 ) {
752 $pageInfo['header-properties'][] = [
753 $this->msg( 'pageinfo-magic-words' )->numParams( count( $listItems ) ),
754 $localizedList
755 ];
756 }
757
758 // Hidden categories
759 if ( count( $hiddenCategories ) > 0 ) {
760 $pageInfo['header-properties'][] = [
761 $this->msg( 'pageinfo-hidden-categories' )
762 ->numParams( count( $hiddenCategories ) ),
763 Linker::formatHiddenCategories( $hiddenCategories )
764 ];
765 }
766
767 // Transcluded templates
768 if ( $pageCounts['transclusion']['from'] > 0 ) {
769 if ( $pageCounts['transclusion']['from'] > count( $transcludedTemplates ) ) {
770 $more = $this->msg( 'morenotlisted' )->escaped();
771 } else {
772 $more = null;
773 }
774
775 $templateListFormatter = new TemplatesOnThisPageFormatter(
776 $this->getContext(),
777 $linkRenderer,
778 $this->linkBatchFactory,
779 $this->restrictionStore
780 );
781
782 $pageInfo['header-properties'][] = [
783 $this->msg( 'pageinfo-templates' )
784 ->numParams( $pageCounts['transclusion']['from'] ),
785 $templateListFormatter->format( $transcludedTemplates, false, $more )
786 ];
787 }
788
789 if ( !$config->get( MainConfigNames::MiserMode ) && $pageCounts['transclusion']['to'] > 0 ) {
790 if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) {
791 $more = $linkRenderer->makeLink(
792 $whatLinksHere,
793 $this->msg( 'moredotdotdot' )->text(),
794 [],
795 [ 'hidelinks' => 1, 'hideredirs' => 1 ]
796 );
797 } else {
798 $more = null;
799 }
800
801 $templateListFormatter = new TemplatesOnThisPageFormatter(
802 $this->getContext(),
803 $linkRenderer,
804 $this->linkBatchFactory,
805 $this->restrictionStore
806 );
807
808 $pageInfo['header-properties'][] = [
809 $this->msg( 'pageinfo-transclusions' )
810 ->numParams( $pageCounts['transclusion']['to'] ),
811 $templateListFormatter->format( $transcludedTargets, false, $more )
812 ];
813 }
814 }
815
816 return $pageInfo;
817 }
818
826 private function getNamespaceProtectionMessage( Title $title ): ?string {
827 $rights = [];
828 if ( $title->isRawHtmlMessage() ) {
829 $rights[] = 'editsitecss';
830 $rights[] = 'editsitejs';
831 } elseif ( $title->isSiteCssConfigPage() ) {
832 $rights[] = 'editsitecss';
833 } elseif ( $title->isSiteJsConfigPage() ) {
834 $rights[] = 'editsitejs';
835 } elseif ( $title->isSiteJsonConfigPage() ) {
836 $rights[] = 'editsitejson';
837 } elseif ( $title->isUserCssConfigPage() ) {
838 $rights[] = 'editusercss';
839 } elseif ( $title->isUserJsConfigPage() ) {
840 $rights[] = 'edituserjs';
841 } elseif ( $title->isUserJsonConfigPage() ) {
842 $rights[] = 'edituserjson';
843 } else {
844 $namespaceProtection = $this->context->getConfig()->get( MainConfigNames::NamespaceProtection );
845 $right = $namespaceProtection[$title->getNamespace()] ?? null;
846 if ( $right ) {
847 // a single string as the value is allowed as well as an array
848 $rights = (array)$right;
849 }
850 }
851 if ( $rights ) {
852 return $this->msg( 'protect-fallback', $this->getLanguage()->commaList( $rights ) )->parse();
853 } else {
854 return null;
855 }
856 }
857
863 private function pageCounts() {
864 $page = $this->getWikiPage();
865 $fname = __METHOD__;
866 $config = $this->context->getConfig();
867 $cache = $this->wanObjectCache;
868
869 return $cache->getWithSetCallback(
870 self::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ),
871 WANObjectCache::TTL_WEEK,
872 function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
873 $title = $page->getTitle();
874 $id = $title->getArticleID();
875
876 $dbr = $this->dbProvider->getReplicaDatabase();
877 $setOpts += Database::getCacheSetOptions( $dbr );
878
879 $field = 'rev_actor';
880 $pageField = 'rev_page';
881
882 $watchedItemStore = $this->watchedItemStore;
883
884 $result = [];
885 $result['watchers'] = $watchedItemStore->countWatchers( $title );
886
887 if ( $config->get( MainConfigNames::ShowUpdatedMarker ) ) {
888 $updated = (int)wfTimestamp( TS_UNIX, $page->getTimestamp() );
889 $result['visitingWatchers'] = $watchedItemStore->countVisitingWatchers(
890 $title,
891 $updated - $config->get( MainConfigNames::WatchersMaxAge )
892 );
893 }
894
895 // Total number of edits
896 $edits = (int)$dbr->newSelectQueryBuilder()
897 ->select( 'COUNT(*)' )
898 ->from( 'revision' )
899 ->where( [ 'rev_page' => $id ] )
900 ->caller( $fname )
901 ->fetchField();
902 $result['edits'] = $edits;
903
904 // Total number of distinct authors
905 if ( $config->get( MainConfigNames::MiserMode ) ) {
906 $result['authors'] = 0;
907 } else {
908 $result['authors'] = (int)$dbr->newSelectQueryBuilder()
909 ->select( "COUNT(DISTINCT $field)" )
910 ->from( 'revision' )
911 ->where( [ $pageField => $id ] )
912 ->caller( $fname )
913 ->fetchField();
914 }
915
916 // "Recent" threshold defined by RCMaxAge setting
917 $threshold = $dbr->timestamp( time() - $config->get( MainConfigNames::RCMaxAge ) );
918
919 // Recent number of edits
920 $edits = (int)$dbr->newSelectQueryBuilder()
921 ->select( 'COUNT(rev_page)' )
922 ->from( 'revision' )
923 ->where( [ 'rev_page' => $id ] )
924 ->andWhere( $dbr->expr( 'rev_timestamp', '>=', $threshold ) )
925 ->caller( $fname )
926 ->fetchField();
927 $result['recent_edits'] = $edits;
928
929 // Recent number of distinct authors
930 $result['recent_authors'] = (int)$dbr->newSelectQueryBuilder()
931 ->select( "COUNT(DISTINCT $field)" )
932 ->from( 'revision' )
933 ->where( [ $pageField => $id ] )
934 ->andWhere( [ $dbr->expr( 'rev_timestamp', '>=', $threshold ) ] )
935 ->caller( $fname )
936 ->fetchField();
937
938 // Subpages (if enabled)
939 if ( $this->namespaceInfo->hasSubpages( $title->getNamespace() ) ) {
940 $conds = [ 'page_namespace' => $title->getNamespace() ];
941 $conds[] = $dbr->expr(
942 'page_title',
943 IExpression::LIKE,
944 new LikeValue( $title->getDBkey() . '/', $dbr->anyString() )
945 );
946
947 // Subpages of this page (redirects)
948 $conds['page_is_redirect'] = 1;
949 $result['subpages']['redirects'] = (int)$dbr->newSelectQueryBuilder()
950 ->select( 'COUNT(page_id)' )
951 ->from( 'page' )
952 ->where( $conds )
953 ->caller( $fname )
954 ->fetchField();
955 // Subpages of this page (non-redirects)
956 $conds['page_is_redirect'] = 0;
957 $result['subpages']['nonredirects'] = (int)$dbr->newSelectQueryBuilder()
958 ->select( 'COUNT(page_id)' )
959 ->from( 'page' )
960 ->where( $conds )
961 ->caller( $fname )
962 ->fetchField();
963
964 // Subpages of this page (total)
965 $result['subpages']['total'] = $result['subpages']['redirects']
966 + $result['subpages']['nonredirects'];
967 }
968
969 // Counts for the number of transclusion links (to/from)
970 if ( $config->get( MainConfigNames::MiserMode ) ) {
971 $result['transclusion']['to'] = 0;
972 } else {
973 $result['transclusion']['to'] = (int)$dbr->newSelectQueryBuilder()
974 ->select( 'COUNT(tl_from)' )
975 ->from( 'templatelinks' )
976 ->where( $this->linksMigration->getLinksConditions( 'templatelinks', $title ) )
977 ->caller( $fname )
978 ->fetchField();
979 }
980
981 $result['transclusion']['from'] = (int)$dbr->newSelectQueryBuilder()
982 ->select( 'COUNT(*)' )
983 ->from( 'templatelinks' )
984 ->where( [ 'tl_from' => $title->getArticleID() ] )
985 ->caller( $fname )
986 ->fetchField();
987
988 return $result;
989 }
990 );
991 }
992
998 protected function getPageTitle() {
999 return $this->msg( 'pageinfo-title' )->plaintextParams( $this->getTitle()->getPrefixedText() );
1000 }
1001
1007 protected function getDescription() {
1008 return '';
1009 }
1010
1017 protected static function getCacheKey( WANObjectCache $cache, PageIdentity $page, $revId ) {
1018 return $cache->makeKey( 'infoaction', md5( (string)$page ), $revId, self::VERSION );
1019 }
1020}
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:158
Gives access to properties of a page.
Definition PageProps.php:35
Store information about magic words, and create/cache MagicWord objects.
ParserOutput is a rendering of a Content object or a message.
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