MediaWiki REL1_36
InfoAction.php
Go to the documentation of this file.
1<?php
29
36 private const VERSION = 1;
37
43 public function getName() {
44 return 'info';
45 }
46
52 public function requiresUnblock() {
53 return false;
54 }
55
61 public function requiresWrite() {
62 return false;
63 }
64
72 public static function invalidateCache( PageIdentity $page, $revid = null ) {
73 $services = MediaWikiServices::getInstance();
74 if ( !$revid ) {
75 $revision = $services->getRevisionLookup()
76 ->getRevisionByTitle( $page, 0, IDBAccessObject::READ_LATEST );
77 $revid = $revision ? $revision->getId() : null;
78 }
79 if ( $revid !== null ) {
80 $cache = $services->getMainWANObjectCache();
81 $key = self::getCacheKey( $cache, $page, $revid );
82 $cache->delete( $key );
83 }
84 }
85
91 public function onView() {
92 $this->getOutput()->addModuleStyles( 'mediawiki.interface.helpers.styles' );
93
94 $content = '';
95
96 // "Help" button
97 $this->addHelpLink( 'Page information' );
98
99 // Validate revision
100 $oldid = $this->getArticle()->getOldID();
101 if ( $oldid ) {
102 $revRecord = $this->getArticle()->fetchRevisionRecord();
103
104 // Revision is missing
105 if ( $revRecord === null ) {
106 return $this->msg( 'missing-revision', $oldid )->parse();
107 }
108
109 // Revision is not current
110 if ( !$revRecord->isCurrent() ) {
111 return $this->msg( 'pageinfo-not-current' )->plain();
112 }
113 }
114
115 // Page header
116 if ( !$this->msg( 'pageinfo-header' )->isDisabled() ) {
117 $content .= $this->msg( 'pageinfo-header' )->parse();
118 }
119
120 // Hide "This page is a member of # hidden categories" explanation
121 $content .= Html::element( 'style', [],
122 '.mw-hiddenCategoriesExplanation { display: none; }' ) . "\n";
123
124 // Hide "Templates used on this page" explanation
125 $content .= Html::element( 'style', [],
126 '.mw-templatesUsedExplanation { display: none; }' ) . "\n";
127
128 // Get page information
129 $pageInfo = $this->pageInfo();
130
131 // Allow extensions to add additional information
132 $this->getHookRunner()->onInfoAction( $this->getContext(), $pageInfo );
133
134 // Render page information
135 foreach ( $pageInfo as $header => $infoTable ) {
136 // Messages:
137 // pageinfo-header-basic, pageinfo-header-edits, pageinfo-header-restrictions,
138 // pageinfo-header-properties, pageinfo-category-info
139 $content .= $this->makeHeader(
140 $this->msg( "pageinfo-${header}" )->text(),
141 "mw-pageinfo-${header}"
142 ) . "\n";
143 $table = "\n";
144 $below = "";
145 foreach ( $infoTable as $infoRow ) {
146 if ( $infoRow[0] == "below" ) {
147 $below = $infoRow[1] . "\n";
148 continue;
149 }
150 $name = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->escaped() : $infoRow[0];
151 $value = ( $infoRow[1] instanceof Message ) ? $infoRow[1]->escaped() : $infoRow[1];
152 $id = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->getKey() : null;
153 $table = $this->addRow( $table, $name, $value, $id ) . "\n";
154 }
155 if ( $table === "\n" ) {
156 // Don't add tables with no rows
157 $content .= "\n" . $below;
158 } else {
159 $content = $this->addTable( $content, $table ) . "\n" . $below;
160 }
161 }
162
163 // Page footer
164 if ( !$this->msg( 'pageinfo-footer' )->isDisabled() ) {
165 $content .= $this->msg( 'pageinfo-footer' )->parse();
166 }
167
168 return $content;
169 }
170
178 protected function makeHeader( $header, $canonicalId ) {
179 $spanAttribs = [ 'class' => 'mw-headline', 'id' => Sanitizer::escapeIdForAttribute( $header ) ];
180 $h2Attribs = [ 'id' => Sanitizer::escapeIdForAttribute( $canonicalId ) ];
181
182 return Html::rawElement( 'h2', $h2Attribs, Html::element( 'span', $spanAttribs, $header ) );
183 }
184
194 protected function addRow( $table, $name, $value, $id ) {
195 return $table .
196 Html::rawElement(
197 'tr',
198 $id === null ? [] : [ 'id' => 'mw-' . $id ],
199 Html::rawElement( 'td', [ 'style' => 'vertical-align: top;' ], $name ) .
200 Html::rawElement( 'td', [], $value )
201 );
202 }
203
211 protected function addTable( $content, $table ) {
212 return $content . Html::rawElement( 'table', [ 'class' => 'wikitable mw-page-info' ],
213 $table );
214 }
215
228 protected function pageInfo() {
229 $services = MediaWikiServices::getInstance();
230
231 $user = $this->getUser();
232 $lang = $this->getLanguage();
233 $title = $this->getTitle();
234 $id = $title->getArticleID();
235 $config = $this->context->getConfig();
236 $linkRenderer = $services->getLinkRenderer();
237
238 $pageCounts = $this->pageCounts();
239
240 $props = PageProps::getInstance()->getAllProperties( $title );
241 $pageProperties = $props[$id] ?? [];
242
243 // Basic information
244 $pageInfo = [];
245 $pageInfo['header-basic'] = [];
246
247 // Display title
248 $displayTitle = $pageProperties['displaytitle'] ?? $title->getPrefixedText();
249
250 $pageInfo['header-basic'][] = [
251 $this->msg( 'pageinfo-display-title' ), $displayTitle
252 ];
253
254 // Is it a redirect? If so, where to?
255 $redirectTarget = $this->getWikiPage()->getRedirectTarget();
256 if ( $redirectTarget !== null ) {
257 $pageInfo['header-basic'][] = [
258 $this->msg( 'pageinfo-redirectsto' ),
259 $linkRenderer->makeLink( $redirectTarget ) .
260 $this->msg( 'word-separator' )->escaped() .
261 $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
262 $redirectTarget,
263 $this->msg( 'pageinfo-redirectsto-info' )->text(),
264 [],
265 [ 'action' => 'info' ]
266 ) )->escaped()
267 ];
268 }
269
270 // Default sort key
271 $sortKey = $pageProperties['defaultsort'] ?? $title->getCategorySortkey();
272
273 $sortKey = htmlspecialchars( $sortKey );
274 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-default-sort' ), $sortKey ];
275
276 // Page length (in bytes)
277 $pageInfo['header-basic'][] = [
278 $this->msg( 'pageinfo-length' ), $lang->formatNum( $title->getLength() )
279 ];
280
281 // Page namespace
282 $pageNamespace = $title->getNsText();
283 if ( $pageNamespace ) {
284 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-namespace' ), $pageNamespace ];
285 }
286
287 // Page ID (number not localised, as it's a database ID)
288 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-article-id' ), $id ];
289
290 // Language in which the page content is (supposed to be) written
291 $pageLang = $title->getPageLanguage()->getCode();
292
293 $pageLangHtml = $pageLang . ' - ' .
294 $services->getLanguageNameUtils()->getLanguageName( $pageLang, $lang->getCode() );
295 // Link to Special:PageLanguage with pre-filled page title if user has permissions
296 if ( $config->get( 'PageLanguageUseDB' )
297 && $this->getContext()->getAuthority()->probablyCan( 'pagelang', $title )
298 ) {
299 $pageLangHtml .= ' ' . $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
300 SpecialPage::getTitleValueFor( 'PageLanguage', $title->getPrefixedText() ),
301 $this->msg( 'pageinfo-language-change' )->text()
302 ) )->escaped();
303 }
304
305 $pageInfo['header-basic'][] = [
306 $this->msg( 'pageinfo-language' )->escaped(),
307 $pageLangHtml
308 ];
309
310 // Content model of the page
311 $modelHtml = htmlspecialchars( ContentHandler::getLocalizedName( $title->getContentModel() ) );
312 // If the user can change it, add a link to Special:ChangeContentModel
313 if ( $this->getContext()->getAuthority()->probablyCan( 'editcontentmodel', $title ) ) {
314 $modelHtml .= ' ' . $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
315 SpecialPage::getTitleValueFor( 'ChangeContentModel', $title->getPrefixedText() ),
316 $this->msg( 'pageinfo-content-model-change' )->text()
317 ) )->escaped();
318 }
319
320 $pageInfo['header-basic'][] = [
321 $this->msg( 'pageinfo-content-model' ),
322 $modelHtml
323 ];
324
325 if ( $title->inNamespace( NS_USER ) ) {
326 $pageUser = User::newFromName( $title->getRootText() );
327 if ( $pageUser && $pageUser->getId() && !$pageUser->isHidden() ) {
328 $pageInfo['header-basic'][] = [
329 $this->msg( 'pageinfo-user-id' ),
330 $pageUser->getId()
331 ];
332 }
333 }
334
335 // Search engine status
336 $pOutput = new ParserOutput();
337 if ( isset( $pageProperties['noindex'] ) ) {
338 $pOutput->setIndexPolicy( 'noindex' );
339 }
340 if ( isset( $pageProperties['index'] ) ) {
341 $pOutput->setIndexPolicy( 'index' );
342 }
343
344 // Use robot policy logic
345 $policy = $this->getArticle()->getRobotPolicy( 'view', $pOutput );
346 $pageInfo['header-basic'][] = [
347 // Messages: pageinfo-robot-index, pageinfo-robot-noindex
348 $this->msg( 'pageinfo-robot-policy' ),
349 $this->msg( "pageinfo-robot-${policy['index']}" )
350 ];
351
352 $unwatchedPageThreshold = $config->get( 'UnwatchedPageThreshold' );
353 if ( $this->getContext()->getAuthority()->isAllowed( 'unwatchedpages' ) ||
354 ( $unwatchedPageThreshold !== false &&
355 $pageCounts['watchers'] >= $unwatchedPageThreshold )
356 ) {
357 // Number of page watchers
358 $pageInfo['header-basic'][] = [
359 $this->msg( 'pageinfo-watchers' ),
360 $lang->formatNum( $pageCounts['watchers'] )
361 ];
362 if (
363 $config->get( 'ShowUpdatedMarker' ) &&
364 isset( $pageCounts['visitingWatchers'] )
365 ) {
366 $minToDisclose = $config->get( 'UnwatchedPageSecret' );
367 if ( $pageCounts['visitingWatchers'] > $minToDisclose ||
368 $this->getContext()->getAuthority()->isAllowed( 'unwatchedpages' ) ) {
369 $pageInfo['header-basic'][] = [
370 $this->msg( 'pageinfo-visiting-watchers' ),
371 $lang->formatNum( $pageCounts['visitingWatchers'] )
372 ];
373 } else {
374 $pageInfo['header-basic'][] = [
375 $this->msg( 'pageinfo-visiting-watchers' ),
376 $this->msg( 'pageinfo-few-visiting-watchers' )
377 ];
378 }
379 }
380 } elseif ( $unwatchedPageThreshold !== false ) {
381 $pageInfo['header-basic'][] = [
382 $this->msg( 'pageinfo-watchers' ),
383 $this->msg( 'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
384 ];
385 }
386
387 // Redirects to this page
388 $whatLinksHere = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
389 $pageInfo['header-basic'][] = [
390 $linkRenderer->makeLink(
391 $whatLinksHere,
392 $this->msg( 'pageinfo-redirects-name' )->text(),
393 [],
394 [
395 'hidelinks' => 1,
396 'hidetrans' => 1,
397 'hideimages' => $title->getNamespace() === NS_FILE
398 ]
399 ),
400 $this->msg( 'pageinfo-redirects-value' )
401 ->numParams( count( $title->getRedirectsHere() ) )
402 ];
403
404 // Is it counted as a content page?
405 if ( $this->getWikiPage()->isCountable() ) {
406 $pageInfo['header-basic'][] = [
407 $this->msg( 'pageinfo-contentpage' ),
408 $this->msg( 'pageinfo-contentpage-yes' )
409 ];
410 }
411
412 // Subpages of this page, if subpages are enabled for the current NS
413 if ( $services->getNamespaceInfo()->hasSubpages( $title->getNamespace() ) ) {
414 $prefixIndex = SpecialPage::getTitleFor(
415 'Prefixindex', $title->getPrefixedText() . '/' );
416 $pageInfo['header-basic'][] = [
417 $linkRenderer->makeLink(
418 $prefixIndex,
419 $this->msg( 'pageinfo-subpages-name' )->text()
420 ),
421 $this->msg( 'pageinfo-subpages-value' )
422 ->numParams(
423 $pageCounts['subpages']['total'],
424 $pageCounts['subpages']['redirects'],
425 $pageCounts['subpages']['nonredirects'] )
426 ];
427 }
428
429 if ( $title->inNamespace( NS_CATEGORY ) ) {
430 $category = Category::newFromTitle( $title );
431
432 // $allCount is the total number of cat members,
433 // not the count of how many members are normal pages.
434 $allCount = (int)$category->getPageCount();
435 $subcatCount = (int)$category->getSubcatCount();
436 $fileCount = (int)$category->getFileCount();
437 $pagesCount = $allCount - $subcatCount - $fileCount;
438
439 $pageInfo['category-info'] = [
440 [
441 $this->msg( 'pageinfo-category-total' ),
442 $lang->formatNum( $allCount )
443 ],
444 [
445 $this->msg( 'pageinfo-category-pages' ),
446 $lang->formatNum( $pagesCount )
447 ],
448 [
449 $this->msg( 'pageinfo-category-subcats' ),
450 $lang->formatNum( $subcatCount )
451 ],
452 [
453 $this->msg( 'pageinfo-category-files' ),
454 $lang->formatNum( $fileCount )
455 ]
456 ];
457 }
458
459 // Display image SHA-1 value
460 if ( $title->inNamespace( NS_FILE ) ) {
461 $fileObj = $services->getRepoGroup()->findFile( $title );
462 if ( $fileObj !== false ) {
463 // Convert the base-36 sha1 value obtained from database to base-16
464 $output = Wikimedia\base_convert( $fileObj->getSha1(), 36, 16, 40 );
465 $pageInfo['header-basic'][] = [
466 $this->msg( 'pageinfo-file-hash' ),
467 $output
468 ];
469 }
470 }
471
472 // Page protection
473 $pageInfo['header-restrictions'] = [];
474
475 // Is this page affected by the cascading protection of something which includes it?
476 if ( $title->isCascadeProtected() ) {
477 $cascadingFrom = '';
478 $sources = $title->getCascadeProtectionSources()[0];
479
480 foreach ( $sources as $sourceTitle ) {
481 $cascadingFrom .= Html::rawElement(
482 'li', [], $linkRenderer->makeKnownLink( $sourceTitle ) );
483 }
484
485 $cascadingFrom = Html::rawElement( 'ul', [], $cascadingFrom );
486 $pageInfo['header-restrictions'][] = [
487 $this->msg( 'pageinfo-protect-cascading-from' ),
488 $cascadingFrom
489 ];
490 }
491
492 // Is out protection set to cascade to other pages?
493 if ( $title->areRestrictionsCascading() ) {
494 $pageInfo['header-restrictions'][] = [
495 $this->msg( 'pageinfo-protect-cascading' ),
496 $this->msg( 'pageinfo-protect-cascading-yes' )
497 ];
498 }
499
500 // Page protection
501 foreach ( $title->getRestrictionTypes() as $restrictionType ) {
502 $protectionLevel = implode( ', ', $title->getRestrictions( $restrictionType ) );
503
504 if ( $protectionLevel == '' ) {
505 // Allow all users
506 $message = $this->msg( 'protect-default' )->escaped();
507 } else {
508 // Administrators only
509 // Messages: protect-level-autoconfirmed, protect-level-sysop
510 $message = $this->msg( "protect-level-$protectionLevel" );
511 if ( $message->isDisabled() ) {
512 // Require "$1" permission
513 $message = $this->msg( "protect-fallback", $protectionLevel )->parse();
514 } else {
515 $message = $message->escaped();
516 }
517 }
518 $expiry = $title->getRestrictionExpiry( $restrictionType );
519 $formattedexpiry = $this->msg( 'parentheses',
520 $lang->formatExpiry( $expiry ) )->escaped();
521 $message .= $this->msg( 'word-separator' )->escaped() . $formattedexpiry;
522
523 // Messages: restriction-edit, restriction-move, restriction-create,
524 // restriction-upload
525 $pageInfo['header-restrictions'][] = [
526 $this->msg( "restriction-$restrictionType" ), $message
527 ];
528 }
529 $protectLog = SpecialPage::getTitleFor( 'Log' );
530 $pageInfo['header-restrictions'][] = [
531 'below',
532 $linkRenderer->makeKnownLink(
533 $protectLog,
534 $this->msg( 'pageinfo-view-protect-log' )->text(),
535 [],
536 [ 'type' => 'protect', 'page' => $title->getPrefixedText() ]
537 ),
538 ];
539
540 if ( !$this->getWikiPage()->exists() ) {
541 return $pageInfo;
542 }
543
544 // Edit history
545 $pageInfo['header-edits'] = [];
546
547 $firstRev = MediaWikiServices::getInstance()
548 ->getRevisionLookup()
549 ->getFirstRevision( $this->getTitle() );
550 $lastRev = $this->getWikiPage()->getRevisionRecord();
551 $linkBatchFactory = $services->getLinkBatchFactory();
552 $batch = $linkBatchFactory->newLinkBatch();
553 if ( $firstRev ) {
554 $firstRevUser = $firstRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
555 if ( $firstRevUser ) {
556 $batch->add( NS_USER, $firstRevUser->getName() );
557 $batch->add( NS_USER_TALK, $firstRevUser->getName() );
558 }
559 }
560
561 if ( $lastRev ) {
562 $lastRevUser = $lastRev->getUser( RevisionRecord::FOR_THIS_USER, $user );
563 if ( $lastRevUser ) {
564 $batch->add( NS_USER, $lastRevUser->getName() );
565 $batch->add( NS_USER_TALK, $lastRevUser->getName() );
566 }
567 }
568
569 $batch->execute();
570
571 if ( $firstRev ) {
572 // Page creator
573 $pageInfo['header-edits'][] = [
574 $this->msg( 'pageinfo-firstuser' ),
575 Linker::revUserTools( $firstRev )
576 ];
577
578 // Date of page creation
579 $pageInfo['header-edits'][] = [
580 $this->msg( 'pageinfo-firsttime' ),
581 $linkRenderer->makeKnownLink(
582 $title,
583 $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ),
584 [],
585 [ 'oldid' => $firstRev->getId() ]
586 )
587 ];
588 }
589
590 if ( $lastRev ) {
591 // Latest editor
592 $pageInfo['header-edits'][] = [
593 $this->msg( 'pageinfo-lastuser' ),
594 Linker::revUserTools( $lastRev )
595 ];
596
597 // Date of latest edit
598 $pageInfo['header-edits'][] = [
599 $this->msg( 'pageinfo-lasttime' ),
600 $linkRenderer->makeKnownLink(
601 $title,
602 $lang->userTimeAndDate( $this->getWikiPage()->getTimestamp(), $user ),
603 [],
604 [ 'oldid' => $this->getWikiPage()->getLatest() ]
605 )
606 ];
607 }
608
609 // Total number of edits
610 $pageInfo['header-edits'][] = [
611 $this->msg( 'pageinfo-edits' ), $lang->formatNum( $pageCounts['edits'] )
612 ];
613
614 // Total number of distinct authors
615 if ( $pageCounts['authors'] > 0 ) {
616 $pageInfo['header-edits'][] = [
617 $this->msg( 'pageinfo-authors' ), $lang->formatNum( $pageCounts['authors'] )
618 ];
619 }
620
621 // Recent number of edits (within past 30 days)
622 $pageInfo['header-edits'][] = [
623 $this->msg( 'pageinfo-recent-edits',
624 $lang->formatDuration( $config->get( 'RCMaxAge' ) ) ),
625 $lang->formatNum( $pageCounts['recent_edits'] )
626 ];
627
628 // Recent number of distinct authors
629 $pageInfo['header-edits'][] = [
630 $this->msg( 'pageinfo-recent-authors' ),
631 $lang->formatNum( $pageCounts['recent_authors'] )
632 ];
633
634 // Array of MagicWord objects
635 $magicWords = $services->getMagicWordFactory()->getDoubleUnderscoreArray();
636
637 // Array of magic word IDs
638 $wordIDs = $magicWords->names;
639
640 // Array of IDs => localized magic words
641 $localizedWords = $services->getContentLanguage()->getMagicWords();
642
643 $listItems = [];
644 foreach ( $pageProperties as $property => $value ) {
645 if ( in_array( $property, $wordIDs ) ) {
646 $listItems[] = Html::element( 'li', [], $localizedWords[$property][1] );
647 }
648 }
649
650 $localizedList = Html::rawElement( 'ul', [], implode( '', $listItems ) );
651 $hiddenCategories = $this->getWikiPage()->getHiddenCategories();
652
653 if (
654 count( $listItems ) > 0 ||
655 count( $hiddenCategories ) > 0 ||
656 $pageCounts['transclusion']['from'] > 0 ||
657 $pageCounts['transclusion']['to'] > 0
658 ) {
659 $options = [ 'LIMIT' => $config->get( 'PageInfoTransclusionLimit' ) ];
660 $transcludedTemplates = $title->getTemplateLinksFrom( $options );
661 if ( $config->get( 'MiserMode' ) ) {
662 $transcludedTargets = [];
663 } else {
664 $transcludedTargets = $title->getTemplateLinksTo( $options );
665 }
666
667 // Page properties
668 $pageInfo['header-properties'] = [];
669
670 // Magic words
671 if ( count( $listItems ) > 0 ) {
672 $pageInfo['header-properties'][] = [
673 $this->msg( 'pageinfo-magic-words' )->numParams( count( $listItems ) ),
674 $localizedList
675 ];
676 }
677
678 // Hidden categories
679 if ( count( $hiddenCategories ) > 0 ) {
680 $pageInfo['header-properties'][] = [
681 $this->msg( 'pageinfo-hidden-categories' )
682 ->numParams( count( $hiddenCategories ) ),
683 Linker::formatHiddenCategories( $hiddenCategories )
684 ];
685 }
686
687 // Transcluded templates
688 if ( $pageCounts['transclusion']['from'] > 0 ) {
689 if ( $pageCounts['transclusion']['from'] > count( $transcludedTemplates ) ) {
690 $more = $this->msg( 'morenotlisted' )->escaped();
691 } else {
692 $more = null;
693 }
694
695 $templateListFormatter = new TemplatesOnThisPageFormatter(
696 $this->getContext(),
697 $linkRenderer
698 );
699
700 $pageInfo['header-properties'][] = [
701 $this->msg( 'pageinfo-templates' )
702 ->numParams( $pageCounts['transclusion']['from'] ),
703 $templateListFormatter->format( $transcludedTemplates, false, $more )
704 ];
705 }
706
707 if ( !$config->get( 'MiserMode' ) && $pageCounts['transclusion']['to'] > 0 ) {
708 if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) {
709 $more = $linkRenderer->makeLink(
710 $whatLinksHere,
711 $this->msg( 'moredotdotdot' )->text(),
712 [],
713 [ 'hidelinks' => 1, 'hideredirs' => 1 ]
714 );
715 } else {
716 $more = null;
717 }
718
719 $templateListFormatter = new TemplatesOnThisPageFormatter(
720 $this->getContext(),
721 $linkRenderer
722 );
723
724 $pageInfo['header-properties'][] = [
725 $this->msg( 'pageinfo-transclusions' )
726 ->numParams( $pageCounts['transclusion']['to'] ),
727 $templateListFormatter->format( $transcludedTargets, false, $more )
728 ];
729 }
730 }
731
732 return $pageInfo;
733 }
734
740 private function pageCounts() {
741 $page = $this->getWikiPage();
742 $fname = __METHOD__;
743 $config = $this->context->getConfig();
744 $services = MediaWikiServices::getInstance();
745 $cache = $services->getMainWANObjectCache();
746
747 return $cache->getWithSetCallback(
748 self::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ),
749 WANObjectCache::TTL_WEEK,
750 static function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname, $services ) {
751 $title = $page->getTitle();
752 $id = $title->getArticleID();
753
755 $dbrWatchlist = wfGetDB( DB_REPLICA, 'watchlist' );
756 $setOpts += Database::getCacheSetOptions( $dbr, $dbrWatchlist );
757
758 $tables = [ 'revision_actor_temp' ];
759 $field = 'revactor_actor';
760 $pageField = 'revactor_page';
761 $tsField = 'revactor_timestamp';
762 $joins = [];
763
764 $watchedItemStore = $services->getWatchedItemStore();
765
766 $result = [];
767 $result['watchers'] = $watchedItemStore->countWatchers( $title );
768
769 if ( $config->get( 'ShowUpdatedMarker' ) ) {
770 $updated = (int)wfTimestamp( TS_UNIX, $page->getTimestamp() );
771 $result['visitingWatchers'] = $watchedItemStore->countVisitingWatchers(
772 $title,
773 $updated - $config->get( 'WatchersMaxAge' )
774 );
775 }
776
777 // Total number of edits
778 $edits = (int)$dbr->selectField(
779 'revision',
780 'COUNT(*)',
781 [ 'rev_page' => $id ],
782 $fname
783 );
784 $result['edits'] = $edits;
785
786 // Total number of distinct authors
787 if ( $config->get( 'MiserMode' ) ) {
788 $result['authors'] = 0;
789 } else {
790 $result['authors'] = (int)$dbr->selectField(
791 $tables,
792 "COUNT(DISTINCT $field)",
793 [ $pageField => $id ],
794 $fname,
795 [],
796 $joins
797 );
798 }
799
800 // "Recent" threshold defined by RCMaxAge setting
801 $threshold = $dbr->timestamp( time() - $config->get( 'RCMaxAge' ) );
802
803 // Recent number of edits
804 $edits = (int)$dbr->selectField(
805 'revision',
806 'COUNT(rev_page)',
807 [
808 'rev_page' => $id,
809 "rev_timestamp >= " . $dbr->addQuotes( $threshold )
810 ],
811 $fname
812 );
813 $result['recent_edits'] = $edits;
814
815 // Recent number of distinct authors
816 $result['recent_authors'] = (int)$dbr->selectField(
817 $tables,
818 "COUNT(DISTINCT $field)",
819 [
820 $pageField => $id,
821 "$tsField >= " . $dbr->addQuotes( $threshold )
822 ],
823 $fname,
824 [],
825 $joins
826 );
827
828 // Subpages (if enabled)
829 if ( $services->getNamespaceInfo()->hasSubpages( $title->getNamespace() ) ) {
830 $conds = [ 'page_namespace' => $title->getNamespace() ];
831 $conds[] = 'page_title ' .
832 $dbr->buildLike( $title->getDBkey() . '/', $dbr->anyString() );
833
834 // Subpages of this page (redirects)
835 $conds['page_is_redirect'] = 1;
836 $result['subpages']['redirects'] = (int)$dbr->selectField(
837 'page',
838 'COUNT(page_id)',
839 $conds,
840 $fname
841 );
842
843 // Subpages of this page (non-redirects)
844 $conds['page_is_redirect'] = 0;
845 $result['subpages']['nonredirects'] = (int)$dbr->selectField(
846 'page',
847 'COUNT(page_id)',
848 $conds,
849 $fname
850 );
851
852 // Subpages of this page (total)
853 $result['subpages']['total'] = $result['subpages']['redirects']
854 + $result['subpages']['nonredirects'];
855 }
856
857 // Counts for the number of transclusion links (to/from)
858 if ( $config->get( 'MiserMode' ) ) {
859 $result['transclusion']['to'] = 0;
860 } else {
861 $result['transclusion']['to'] = (int)$dbr->selectField(
862 'templatelinks',
863 'COUNT(tl_from)',
864 [
865 'tl_namespace' => $title->getNamespace(),
866 'tl_title' => $title->getDBkey()
867 ],
868 $fname
869 );
870 }
871
872 $result['transclusion']['from'] = (int)$dbr->selectField(
873 'templatelinks',
874 'COUNT(*)',
875 [ 'tl_from' => $title->getArticleID() ],
876 $fname
877 );
878
879 return $result;
880 }
881 );
882 }
883
889 protected function getPageTitle() {
890 return $this->msg( 'pageinfo-title', $this->getTitle()->getPrefixedText() )->text();
891 }
892
898 protected function getDescription() {
899 return '';
900 }
901
908 protected static function getCacheKey( WANObjectCache $cache, PageIdentity $page, $revId ) {
909 return $cache->makeKey( 'infoaction', md5( (string)$page ), $revId, self::VERSION );
910 }
911}
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
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
$magicWords
@phpcs-require-sorted-array
getWikiPage()
Get a WikiPage object.
Definition Action.php:267
getHookRunner()
Definition Action.php:318
WikiPage Article ImagePage CategoryPage Page $page
Page on which we're performing the action.
Definition Action.php:53
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition Action.php:508
getTitle()
Shortcut to get the Title object from the page.
Definition Action.php:288
getContext()
Get the IContextSource in use here.
Definition Action.php:204
getOutput()
Get the OutputPage being used for this instance.
Definition Action.php:228
getUser()
Shortcut to get the User being used for this instance.
Definition Action.php:238
static exists(string $name)
Check if a given action is recognised, even if it's disabled.
Definition Action.php:195
getArticle()
Get a Article object.
Definition Action.php:278
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition Action.php:300
getLanguage()
Shortcut to get the user Language being used for this instance.
Definition Action.php:257
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.
makeHeader( $header, $canonicalId)
Creates a header that can be added to the output.
pageCounts()
Returns page counts that would be too "expensive" to retrieve by normal means.
getPageTitle()
Returns the name that goes in the "<h1>" page title.
pageInfo()
Returns an array of info groups (will be rendered as tables), keyed by group ID.
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.
getName()
Returns the name of the action this object responds to.
addRow( $table, $name, $value, $id)
Adds a row to a table that will be added to the content.
const VERSION
addTable( $content, $table)
Adds a table to the content that will be added to the output.
static invalidateCache(PageIdentity $page, $revid=null)
Clear the info cache for a given Title.
static formatHiddenCategories( $hiddencats)
Returns HTML for the "hidden categories on this page" list.
Definition Linker.php:2085
static revUserTools( $rev, $isPublic=false, $useParentheses=true)
Generate a user tool link cluster if the current user is allowed to view it.
Definition Linker.php:1147
MediaWikiServices is the service locator for the application scope of MediaWiki.
Page revision base class.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:136
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
static getTitleValueFor( $name, $subpage=false, $fragment='')
Get a localised TitleValue object for a specified special page name.
Handles formatting for the "templates used on this page" lists.
static newFromName( $name, $validate='valid')
Definition User.php:587
Multi-datacenter aware caching interface.
getTimestamp()
Definition WikiPage.php:943
getLatest( $wikiId=self::LOCAL)
Get the page_latest field.
Definition WikiPage.php:809
getTitle()
Get the title object of the article.
Definition WikiPage.php:335
Relational database abstraction object.
Definition Database.php:50
Interface for objects (potentially) representing an editable wiki page.
$cache
Definition mcc.php:33
const DB_REPLICA
Definition defines.php:25
$content
Definition router.php:76
if(!isset( $args[0])) $lang
$header