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