MediaWiki REL1_31
InfoAction.php
Go to the documentation of this file.
1<?php
27
34 const VERSION = 1;
35
41 public function getName() {
42 return 'info';
43 }
44
50 public function requiresUnblock() {
51 return false;
52 }
53
59 public function requiresWrite() {
60 return false;
61 }
62
70 public static function invalidateCache( Title $title, $revid = null ) {
71 if ( !$revid ) {
72 $revision = Revision::newFromTitle( $title, 0, Revision::READ_LATEST );
73 $revid = $revision ? $revision->getId() : null;
74 }
75 if ( $revid !== null ) {
76 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
77 $key = self::getCacheKey( $cache, $title, $revid );
78 $cache->delete( $key );
79 }
80 }
81
87 public function onView() {
88 $content = '';
89
90 // Validate revision
91 $oldid = $this->page->getOldID();
92 if ( $oldid ) {
93 $revision = $this->page->getRevisionFetched();
94
95 // Revision is missing
96 if ( $revision === null ) {
97 return $this->msg( 'missing-revision', $oldid )->parse();
98 }
99
100 // Revision is not current
101 if ( !$revision->isCurrent() ) {
102 return $this->msg( 'pageinfo-not-current' )->plain();
103 }
104 }
105
106 // Page header
107 if ( !$this->msg( 'pageinfo-header' )->isDisabled() ) {
108 $content .= $this->msg( 'pageinfo-header' )->parse();
109 }
110
111 // Hide "This page is a member of # hidden categories" explanation
112 $content .= Html::element( 'style', [],
113 '.mw-hiddenCategoriesExplanation { display: none; }' ) . "\n";
114
115 // Hide "Templates used on this page" explanation
116 $content .= Html::element( 'style', [],
117 '.mw-templatesUsedExplanation { display: none; }' ) . "\n";
118
119 // Get page information
120 $pageInfo = $this->pageInfo();
121
122 // Allow extensions to add additional information
123 Hooks::run( 'InfoAction', [ $this->getContext(), &$pageInfo ] );
124
125 // Render page information
126 foreach ( $pageInfo as $header => $infoTable ) {
127 // Messages:
128 // pageinfo-header-basic, pageinfo-header-edits, pageinfo-header-restrictions,
129 // pageinfo-header-properties, pageinfo-category-info
130 $content .= $this->makeHeader(
131 $this->msg( "pageinfo-${header}" )->text(),
132 "mw-pageinfo-${header}"
133 ) . "\n";
134 $table = "\n";
135 foreach ( $infoTable as $infoRow ) {
136 $name = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->escaped() : $infoRow[0];
137 $value = ( $infoRow[1] instanceof Message ) ? $infoRow[1]->escaped() : $infoRow[1];
138 $id = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->getKey() : null;
139 $table = $this->addRow( $table, $name, $value, $id ) . "\n";
140 }
141 $content = $this->addTable( $content, $table ) . "\n";
142 }
143
144 // Page footer
145 if ( !$this->msg( 'pageinfo-footer' )->isDisabled() ) {
146 $content .= $this->msg( 'pageinfo-footer' )->parse();
147 }
148
149 return $content;
150 }
151
159 protected function makeHeader( $header, $canonicalId ) {
160 $spanAttribs = [ 'class' => 'mw-headline', 'id' => Sanitizer::escapeIdForAttribute( $header ) ];
161 $h2Attribs = [ 'id' => Sanitizer::escapeIdForAttribute( $canonicalId ) ];
162
163 return Html::rawElement( 'h2', $h2Attribs, Html::element( 'span', $spanAttribs, $header ) );
164 }
165
175 protected function addRow( $table, $name, $value, $id ) {
176 return $table .
177 Html::rawElement(
178 'tr',
179 $id === null ? [] : [ 'id' => 'mw-' . $id ],
180 Html::rawElement( 'td', [ 'style' => 'vertical-align: top;' ], $name ) .
181 Html::rawElement( 'td', [], $value )
182 );
183 }
184
192 protected function addTable( $content, $table ) {
193 return $content . Html::rawElement( 'table', [ 'class' => 'wikitable mw-page-info' ],
194 $table );
195 }
196
204 protected function pageInfo() {
206
207 $user = $this->getUser();
208 $lang = $this->getLanguage();
209 $title = $this->getTitle();
210 $id = $title->getArticleID();
211 $config = $this->context->getConfig();
212 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
213
214 $pageCounts = $this->pageCounts( $this->page );
215
216 $pageProperties = [];
217 $props = PageProps::getInstance()->getAllProperties( $title );
218 if ( isset( $props[$id] ) ) {
219 $pageProperties = $props[$id];
220 }
221
222 // Basic information
223 $pageInfo = [];
224 $pageInfo['header-basic'] = [];
225
226 // Display title
227 $displayTitle = $title->getPrefixedText();
228 if ( isset( $pageProperties['displaytitle'] ) ) {
229 $displayTitle = $pageProperties['displaytitle'];
230 }
231
232 $pageInfo['header-basic'][] = [
233 $this->msg( 'pageinfo-display-title' ), $displayTitle
234 ];
235
236 // Is it a redirect? If so, where to?
237 if ( $title->isRedirect() ) {
238 $pageInfo['header-basic'][] = [
239 $this->msg( 'pageinfo-redirectsto' ),
240 $linkRenderer->makeLink( $this->page->getRedirectTarget() ) .
241 $this->msg( 'word-separator' )->escaped() .
242 $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
243 $this->page->getRedirectTarget(),
244 $this->msg( 'pageinfo-redirectsto-info' )->text(),
245 [],
246 [ 'action' => 'info' ]
247 ) )->escaped()
248 ];
249 }
250
251 // Default sort key
252 $sortKey = $title->getCategorySortkey();
253 if ( isset( $pageProperties['defaultsort'] ) ) {
254 $sortKey = $pageProperties['defaultsort'];
255 }
256
257 $sortKey = htmlspecialchars( $sortKey );
258 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-default-sort' ), $sortKey ];
259
260 // Page length (in bytes)
261 $pageInfo['header-basic'][] = [
262 $this->msg( 'pageinfo-length' ), $lang->formatNum( $title->getLength() )
263 ];
264
265 // Page ID (number not localised, as it's a database ID)
266 $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-article-id' ), $id ];
267
268 // Language in which the page content is (supposed to be) written
269 $pageLang = $title->getPageLanguage()->getCode();
270
271 $pageLangHtml = $pageLang . ' - ' .
272 Language::fetchLanguageName( $pageLang, $lang->getCode() );
273 // Link to Special:PageLanguage with pre-filled page title if user has permissions
274 if ( $config->get( 'PageLanguageUseDB' )
275 && $title->userCan( 'pagelang', $user )
276 ) {
277 $pageLangHtml .= ' ' . $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
278 SpecialPage::getTitleValueFor( 'PageLanguage', $title->getPrefixedText() ),
279 $this->msg( 'pageinfo-language-change' )->text()
280 ) )->escaped();
281 }
282
283 $pageInfo['header-basic'][] = [
284 $this->msg( 'pageinfo-language' )->escaped(),
285 $pageLangHtml
286 ];
287
288 // Content model of the page
289 $modelHtml = htmlspecialchars( ContentHandler::getLocalizedName( $title->getContentModel() ) );
290 // If the user can change it, add a link to Special:ChangeContentModel
291 if ( $config->get( 'ContentHandlerUseDB' )
292 && $title->userCan( 'editcontentmodel', $user )
293 ) {
294 $modelHtml .= ' ' . $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
295 SpecialPage::getTitleValueFor( 'ChangeContentModel', $title->getPrefixedText() ),
296 $this->msg( 'pageinfo-content-model-change' )->text()
297 ) )->escaped();
298 }
299
300 $pageInfo['header-basic'][] = [
301 $this->msg( 'pageinfo-content-model' ),
302 $modelHtml
303 ];
304
305 if ( $title->inNamespace( NS_USER ) ) {
306 $pageUser = User::newFromName( $title->getRootText() );
307 if ( $pageUser && $pageUser->getId() && !$pageUser->isHidden() ) {
308 $pageInfo['header-basic'][] = [
309 $this->msg( 'pageinfo-user-id' ),
310 $pageUser->getId()
311 ];
312 }
313 }
314
315 // Search engine status
316 $pOutput = new ParserOutput();
317 if ( isset( $pageProperties['noindex'] ) ) {
318 $pOutput->setIndexPolicy( 'noindex' );
319 }
320 if ( isset( $pageProperties['index'] ) ) {
321 $pOutput->setIndexPolicy( 'index' );
322 }
323
324 // Use robot policy logic
325 $policy = $this->page->getRobotPolicy( 'view', $pOutput );
326 $pageInfo['header-basic'][] = [
327 // Messages: pageinfo-robot-index, pageinfo-robot-noindex
328 $this->msg( 'pageinfo-robot-policy' ),
329 $this->msg( "pageinfo-robot-${policy['index']}" )
330 ];
331
332 $unwatchedPageThreshold = $config->get( 'UnwatchedPageThreshold' );
333 if (
334 $user->isAllowed( 'unwatchedpages' ) ||
335 ( $unwatchedPageThreshold !== false &&
336 $pageCounts['watchers'] >= $unwatchedPageThreshold )
337 ) {
338 // Number of page watchers
339 $pageInfo['header-basic'][] = [
340 $this->msg( 'pageinfo-watchers' ),
341 $lang->formatNum( $pageCounts['watchers'] )
342 ];
343 if (
344 $config->get( 'ShowUpdatedMarker' ) &&
345 isset( $pageCounts['visitingWatchers'] )
346 ) {
347 $minToDisclose = $config->get( 'UnwatchedPageSecret' );
348 if ( $pageCounts['visitingWatchers'] > $minToDisclose ||
349 $user->isAllowed( 'unwatchedpages' ) ) {
350 $pageInfo['header-basic'][] = [
351 $this->msg( 'pageinfo-visiting-watchers' ),
352 $lang->formatNum( $pageCounts['visitingWatchers'] )
353 ];
354 } else {
355 $pageInfo['header-basic'][] = [
356 $this->msg( 'pageinfo-visiting-watchers' ),
357 $this->msg( 'pageinfo-few-visiting-watchers' )
358 ];
359 }
360 }
361 } elseif ( $unwatchedPageThreshold !== false ) {
362 $pageInfo['header-basic'][] = [
363 $this->msg( 'pageinfo-watchers' ),
364 $this->msg( 'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
365 ];
366 }
367
368 // Redirects to this page
369 $whatLinksHere = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
370 $pageInfo['header-basic'][] = [
371 $linkRenderer->makeLink(
372 $whatLinksHere,
373 $this->msg( 'pageinfo-redirects-name' )->text(),
374 [],
375 [
376 'hidelinks' => 1,
377 'hidetrans' => 1,
378 'hideimages' => $title->getNamespace() == NS_FILE
379 ]
380 ),
381 $this->msg( 'pageinfo-redirects-value' )
382 ->numParams( count( $title->getRedirectsHere() ) )
383 ];
384
385 // Is it counted as a content page?
386 if ( $this->page->isCountable() ) {
387 $pageInfo['header-basic'][] = [
388 $this->msg( 'pageinfo-contentpage' ),
389 $this->msg( 'pageinfo-contentpage-yes' )
390 ];
391 }
392
393 // Subpages of this page, if subpages are enabled for the current NS
394 if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) {
395 $prefixIndex = SpecialPage::getTitleFor(
396 'Prefixindex', $title->getPrefixedText() . '/' );
397 $pageInfo['header-basic'][] = [
398 $linkRenderer->makeLink(
399 $prefixIndex,
400 $this->msg( 'pageinfo-subpages-name' )->text()
401 ),
402 $this->msg( 'pageinfo-subpages-value' )
403 ->numParams(
404 $pageCounts['subpages']['total'],
405 $pageCounts['subpages']['redirects'],
406 $pageCounts['subpages']['nonredirects'] )
407 ];
408 }
409
410 if ( $title->inNamespace( NS_CATEGORY ) ) {
411 $category = Category::newFromTitle( $title );
412
413 // $allCount is the total number of cat members,
414 // not the count of how many members are normal pages.
415 $allCount = (int)$category->getPageCount();
416 $subcatCount = (int)$category->getSubcatCount();
417 $fileCount = (int)$category->getFileCount();
418 $pagesCount = $allCount - $subcatCount - $fileCount;
419
420 $pageInfo['category-info'] = [
421 [
422 $this->msg( 'pageinfo-category-total' ),
423 $lang->formatNum( $allCount )
424 ],
425 [
426 $this->msg( 'pageinfo-category-pages' ),
427 $lang->formatNum( $pagesCount )
428 ],
429 [
430 $this->msg( 'pageinfo-category-subcats' ),
431 $lang->formatNum( $subcatCount )
432 ],
433 [
434 $this->msg( 'pageinfo-category-files' ),
435 $lang->formatNum( $fileCount )
436 ]
437 ];
438 }
439
440 // Display image SHA-1 value
441 if ( $title->inNamespace( NS_FILE ) ) {
442 $fileObj = wfFindFile( $title );
443 if ( $fileObj !== false ) {
444 // Convert the base-36 sha1 value obtained from database to base-16
445 $output = Wikimedia\base_convert( $fileObj->getSha1(), 36, 16, 40 );
446 $pageInfo['header-basic'][] = [
447 $this->msg( 'pageinfo-file-hash' ),
448 $output
449 ];
450 }
451 }
452
453 // Page protection
454 $pageInfo['header-restrictions'] = [];
455
456 // Is this page affected by the cascading protection of something which includes it?
457 if ( $title->isCascadeProtected() ) {
458 $cascadingFrom = '';
459 $sources = $title->getCascadeProtectionSources()[0];
460
461 foreach ( $sources as $sourceTitle ) {
462 $cascadingFrom .= Html::rawElement(
463 'li', [], $linkRenderer->makeKnownLink( $sourceTitle ) );
464 }
465
466 $cascadingFrom = Html::rawElement( 'ul', [], $cascadingFrom );
467 $pageInfo['header-restrictions'][] = [
468 $this->msg( 'pageinfo-protect-cascading-from' ),
469 $cascadingFrom
470 ];
471 }
472
473 // Is out protection set to cascade to other pages?
474 if ( $title->areRestrictionsCascading() ) {
475 $pageInfo['header-restrictions'][] = [
476 $this->msg( 'pageinfo-protect-cascading' ),
477 $this->msg( 'pageinfo-protect-cascading-yes' )
478 ];
479 }
480
481 // Page protection
482 foreach ( $title->getRestrictionTypes() as $restrictionType ) {
483 $protectionLevel = implode( ', ', $title->getRestrictions( $restrictionType ) );
484
485 if ( $protectionLevel == '' ) {
486 // Allow all users
487 $message = $this->msg( 'protect-default' )->escaped();
488 } else {
489 // Administrators only
490 // Messages: protect-level-autoconfirmed, protect-level-sysop
491 $message = $this->msg( "protect-level-$protectionLevel" );
492 if ( $message->isDisabled() ) {
493 // Require "$1" permission
494 $message = $this->msg( "protect-fallback", $protectionLevel )->parse();
495 } else {
496 $message = $message->escaped();
497 }
498 }
499 $expiry = $title->getRestrictionExpiry( $restrictionType );
500 $formattedexpiry = $this->msg( 'parentheses',
501 $lang->formatExpiry( $expiry ) )->escaped();
502 $message .= $this->msg( 'word-separator' )->escaped() . $formattedexpiry;
503
504 // Messages: restriction-edit, restriction-move, restriction-create,
505 // restriction-upload
506 $pageInfo['header-restrictions'][] = [
507 $this->msg( "restriction-$restrictionType" ), $message
508 ];
509 }
510
511 if ( !$this->page->exists() ) {
512 return $pageInfo;
513 }
514
515 // Edit history
516 $pageInfo['header-edits'] = [];
517
518 $firstRev = $this->page->getOldestRevision();
519 $lastRev = $this->page->getRevision();
520 $batch = new LinkBatch;
521
522 if ( $firstRev ) {
523 $firstRevUser = $firstRev->getUserText( Revision::FOR_THIS_USER );
524 if ( $firstRevUser !== '' ) {
525 $firstRevUserTitle = Title::makeTitle( NS_USER, $firstRevUser );
526 $batch->addObj( $firstRevUserTitle );
527 $batch->addObj( $firstRevUserTitle->getTalkPage() );
528 }
529 }
530
531 if ( $lastRev ) {
532 $lastRevUser = $lastRev->getUserText( Revision::FOR_THIS_USER );
533 if ( $lastRevUser !== '' ) {
534 $lastRevUserTitle = Title::makeTitle( NS_USER, $lastRevUser );
535 $batch->addObj( $lastRevUserTitle );
536 $batch->addObj( $lastRevUserTitle->getTalkPage() );
537 }
538 }
539
540 $batch->execute();
541
542 if ( $firstRev ) {
543 // Page creator
544 $pageInfo['header-edits'][] = [
545 $this->msg( 'pageinfo-firstuser' ),
546 Linker::revUserTools( $firstRev )
547 ];
548
549 // Date of page creation
550 $pageInfo['header-edits'][] = [
551 $this->msg( 'pageinfo-firsttime' ),
552 $linkRenderer->makeKnownLink(
553 $title,
554 $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ),
555 [],
556 [ 'oldid' => $firstRev->getId() ]
557 )
558 ];
559 }
560
561 if ( $lastRev ) {
562 // Latest editor
563 $pageInfo['header-edits'][] = [
564 $this->msg( 'pageinfo-lastuser' ),
565 Linker::revUserTools( $lastRev )
566 ];
567
568 // Date of latest edit
569 $pageInfo['header-edits'][] = [
570 $this->msg( 'pageinfo-lasttime' ),
571 $linkRenderer->makeKnownLink(
572 $title,
573 $lang->userTimeAndDate( $this->page->getTimestamp(), $user ),
574 [],
575 [ 'oldid' => $this->page->getLatest() ]
576 )
577 ];
578 }
579
580 // Total number of edits
581 $pageInfo['header-edits'][] = [
582 $this->msg( 'pageinfo-edits' ), $lang->formatNum( $pageCounts['edits'] )
583 ];
584
585 // Total number of distinct authors
586 if ( $pageCounts['authors'] > 0 ) {
587 $pageInfo['header-edits'][] = [
588 $this->msg( 'pageinfo-authors' ), $lang->formatNum( $pageCounts['authors'] )
589 ];
590 }
591
592 // Recent number of edits (within past 30 days)
593 $pageInfo['header-edits'][] = [
594 $this->msg( 'pageinfo-recent-edits',
595 $lang->formatDuration( $config->get( 'RCMaxAge' ) ) ),
596 $lang->formatNum( $pageCounts['recent_edits'] )
597 ];
598
599 // Recent number of distinct authors
600 $pageInfo['header-edits'][] = [
601 $this->msg( 'pageinfo-recent-authors' ),
602 $lang->formatNum( $pageCounts['recent_authors'] )
603 ];
604
605 // Array of MagicWord objects
607
608 // Array of magic word IDs
609 $wordIDs = $magicWords->names;
610
611 // Array of IDs => localized magic words
612 $localizedWords = $wgContLang->getMagicWords();
613
614 $listItems = [];
615 foreach ( $pageProperties as $property => $value ) {
616 if ( in_array( $property, $wordIDs ) ) {
617 $listItems[] = Html::element( 'li', [], $localizedWords[$property][1] );
618 }
619 }
620
621 $localizedList = Html::rawElement( 'ul', [], implode( '', $listItems ) );
622 $hiddenCategories = $this->page->getHiddenCategories();
623
624 if (
625 count( $listItems ) > 0 ||
626 count( $hiddenCategories ) > 0 ||
627 $pageCounts['transclusion']['from'] > 0 ||
628 $pageCounts['transclusion']['to'] > 0
629 ) {
630 $options = [ 'LIMIT' => $config->get( 'PageInfoTransclusionLimit' ) ];
631 $transcludedTemplates = $title->getTemplateLinksFrom( $options );
632 if ( $config->get( 'MiserMode' ) ) {
633 $transcludedTargets = [];
634 } else {
635 $transcludedTargets = $title->getTemplateLinksTo( $options );
636 }
637
638 // Page properties
639 $pageInfo['header-properties'] = [];
640
641 // Magic words
642 if ( count( $listItems ) > 0 ) {
643 $pageInfo['header-properties'][] = [
644 $this->msg( 'pageinfo-magic-words' )->numParams( count( $listItems ) ),
645 $localizedList
646 ];
647 }
648
649 // Hidden categories
650 if ( count( $hiddenCategories ) > 0 ) {
651 $pageInfo['header-properties'][] = [
652 $this->msg( 'pageinfo-hidden-categories' )
653 ->numParams( count( $hiddenCategories ) ),
654 Linker::formatHiddenCategories( $hiddenCategories )
655 ];
656 }
657
658 // Transcluded templates
659 if ( $pageCounts['transclusion']['from'] > 0 ) {
660 if ( $pageCounts['transclusion']['from'] > count( $transcludedTemplates ) ) {
661 $more = $this->msg( 'morenotlisted' )->escaped();
662 } else {
663 $more = null;
664 }
665
666 $templateListFormatter = new TemplatesOnThisPageFormatter(
667 $this->getContext(),
669 );
670
671 $pageInfo['header-properties'][] = [
672 $this->msg( 'pageinfo-templates' )
673 ->numParams( $pageCounts['transclusion']['from'] ),
674 $templateListFormatter->format( $transcludedTemplates, false, $more )
675 ];
676 }
677
678 if ( !$config->get( 'MiserMode' ) && $pageCounts['transclusion']['to'] > 0 ) {
679 if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) {
680 $more = $linkRenderer->makeLink(
681 $whatLinksHere,
682 $this->msg( 'moredotdotdot' )->text(),
683 [],
684 [ 'hidelinks' => 1, 'hideredirs' => 1 ]
685 );
686 } else {
687 $more = null;
688 }
689
690 $templateListFormatter = new TemplatesOnThisPageFormatter(
691 $this->getContext(),
693 );
694
695 $pageInfo['header-properties'][] = [
696 $this->msg( 'pageinfo-transclusions' )
697 ->numParams( $pageCounts['transclusion']['to'] ),
698 $templateListFormatter->format( $transcludedTargets, false, $more )
699 ];
700 }
701 }
702
703 return $pageInfo;
704 }
705
712 protected function pageCounts( Page $page ) {
713 $fname = __METHOD__;
714 $config = $this->context->getConfig();
715 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
716
717 return $cache->getWithSetCallback(
718 self::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ),
719 WANObjectCache::TTL_WEEK,
720 function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
722
723 $title = $page->getTitle();
724 $id = $title->getArticleID();
725
727 $dbrWatchlist = wfGetDB( DB_REPLICA, 'watchlist' );
728 $setOpts += Database::getCacheSetOptions( $dbr, $dbrWatchlist );
729
731 $tables = [ 'revision_actor_temp' ];
732 $field = 'revactor_actor';
733 $pageField = 'revactor_page';
734 $tsField = 'revactor_timestamp';
735 $joins = [];
737 $tables = [ 'revision' ];
738 $field = 'rev_user_text';
739 $pageField = 'rev_page';
740 $tsField = 'rev_timestamp';
741 $joins = [];
742 } else {
743 $tables = [ 'revision', 'revision_actor_temp', 'actor' ];
744 $field = 'COALESCE( actor_name, rev_user_text)';
745 $pageField = 'rev_page';
746 $tsField = 'rev_timestamp';
747 $joins = [
748 'revision_actor_temp' => [ 'LEFT JOIN', 'revactor_rev = rev_id' ],
749 'actor' => [ 'LEFT JOIN', 'revactor_actor = actor_id' ],
750 ];
751 }
752
753 $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
754
755 $result = [];
756 $result['watchers'] = $watchedItemStore->countWatchers( $title );
757
758 if ( $config->get( 'ShowUpdatedMarker' ) ) {
759 $updated = wfTimestamp( TS_UNIX, $page->getTimestamp() );
760 $result['visitingWatchers'] = $watchedItemStore->countVisitingWatchers(
761 $title,
762 $updated - $config->get( 'WatchersMaxAge' )
763 );
764 }
765
766 // Total number of edits
767 $edits = (int)$dbr->selectField(
768 'revision',
769 'COUNT(*)',
770 [ 'rev_page' => $id ],
771 $fname
772 );
773 $result['edits'] = $edits;
774
775 // Total number of distinct authors
776 if ( $config->get( 'MiserMode' ) ) {
777 $result['authors'] = 0;
778 } else {
779 $result['authors'] = (int)$dbr->selectField(
780 $tables,
781 "COUNT(DISTINCT $field)",
782 [ $pageField => $id ],
783 $fname,
784 [],
785 $joins
786 );
787 }
788
789 // "Recent" threshold defined by RCMaxAge setting
790 $threshold = $dbr->timestamp( time() - $config->get( 'RCMaxAge' ) );
791
792 // Recent number of edits
793 $edits = (int)$dbr->selectField(
794 'revision',
795 'COUNT(rev_page)',
796 [
797 'rev_page' => $id,
798 "rev_timestamp >= " . $dbr->addQuotes( $threshold )
799 ],
800 $fname
801 );
802 $result['recent_edits'] = $edits;
803
804 // Recent number of distinct authors
805 $result['recent_authors'] = (int)$dbr->selectField(
806 $tables,
807 "COUNT(DISTINCT $field)",
808 [
809 $pageField => $id,
810 "$tsField >= " . $dbr->addQuotes( $threshold )
811 ],
812 $fname,
813 [],
814 $joins
815 );
816
817 // Subpages (if enabled)
818 if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) {
819 $conds = [ 'page_namespace' => $title->getNamespace() ];
820 $conds[] = 'page_title ' .
821 $dbr->buildLike( $title->getDBkey() . '/', $dbr->anyString() );
822
823 // Subpages of this page (redirects)
824 $conds['page_is_redirect'] = 1;
825 $result['subpages']['redirects'] = (int)$dbr->selectField(
826 'page',
827 'COUNT(page_id)',
828 $conds,
829 $fname
830 );
831
832 // Subpages of this page (non-redirects)
833 $conds['page_is_redirect'] = 0;
834 $result['subpages']['nonredirects'] = (int)$dbr->selectField(
835 'page',
836 'COUNT(page_id)',
837 $conds,
838 $fname
839 );
840
841 // Subpages of this page (total)
842 $result['subpages']['total'] = $result['subpages']['redirects']
843 + $result['subpages']['nonredirects'];
844 }
845
846 // Counts for the number of transclusion links (to/from)
847 if ( $config->get( 'MiserMode' ) ) {
848 $result['transclusion']['to'] = 0;
849 } else {
850 $result['transclusion']['to'] = (int)$dbr->selectField(
851 'templatelinks',
852 'COUNT(tl_from)',
853 [
854 'tl_namespace' => $title->getNamespace(),
855 'tl_title' => $title->getDBkey()
856 ],
857 $fname
858 );
859 }
860
861 $result['transclusion']['from'] = (int)$dbr->selectField(
862 'templatelinks',
863 'COUNT(*)',
864 [ 'tl_from' => $title->getArticleID() ],
865 $fname
866 );
867
868 return $result;
869 }
870 );
871 }
872
878 protected function getPageTitle() {
879 return $this->msg( 'pageinfo-title', $this->getTitle()->getPrefixedText() )->text();
880 }
881
886 protected function getContributors() {
887 $contributors = $this->page->getContributors();
888 $real_names = [];
889 $user_names = [];
890 $anon_ips = [];
891 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
892
893 # Sift for real versus user names
895 foreach ( $contributors as $user ) {
896 $page = $user->isAnon()
897 ? SpecialPage::getTitleFor( 'Contributions', $user->getName() )
898 : $user->getUserPage();
899
900 $hiddenPrefs = $this->context->getConfig()->get( 'HiddenPrefs' );
901 if ( $user->getId() == 0 ) {
902 $anon_ips[] = $linkRenderer->makeLink( $page, $user->getName() );
903 } elseif ( !in_array( 'realname', $hiddenPrefs ) && $user->getRealName() ) {
904 $real_names[] = $linkRenderer->makeLink( $page, $user->getRealName() );
905 } else {
906 $user_names[] = $linkRenderer->makeLink( $page, $user->getName() );
907 }
908 }
909
910 $lang = $this->getLanguage();
911
912 $real = $lang->listToText( $real_names );
913
914 # "ThisSite user(s) A, B and C"
915 if ( count( $user_names ) ) {
916 $user = $this->msg( 'siteusers' )
917 ->rawParams( $lang->listToText( $user_names ) )
918 ->params( count( $user_names ) )->escaped();
919 } else {
920 $user = false;
921 }
922
923 if ( count( $anon_ips ) ) {
924 $anon = $this->msg( 'anonusers' )
925 ->rawParams( $lang->listToText( $anon_ips ) )
926 ->params( count( $anon_ips ) )->escaped();
927 } else {
928 $anon = false;
929 }
930
931 # This is the big list, all mooshed together. We sift for blank strings
932 $fulllist = [];
933 foreach ( [ $real, $user, $anon ] as $s ) {
934 if ( $s !== '' ) {
935 array_push( $fulllist, $s );
936 }
937 }
938
939 $count = count( $fulllist );
940
941 # "Based on work by ..."
942 return $count
943 ? $this->msg( 'othercontribs' )->rawParams(
944 $lang->listToText( $fulllist ) )->params( $count )->escaped()
945 : '';
946 }
947
953 protected function getDescription() {
954 return '';
955 }
956
963 protected static function getCacheKey( WANObjectCache $cache, Title $title, $revId ) {
964 return $cache->makeKey( 'infoaction', md5( $title->getPrefixedText() ), $revId, self::VERSION );
965 }
966}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
target page
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfFindFile( $title, $options=[])
Find a file.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition Setup.php:112
$page
Page on which we're performing the action.
Definition Action.php:44
getTitle()
Shortcut to get the Title object from the page.
Definition Action.php:246
getContext()
Get the IContextSource in use here.
Definition Action.php:178
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
Definition Action.php:256
getUser()
Shortcut to get the User being used for this instance.
Definition Action.php:217
getLanguage()
Shortcut to get the user Language being used for this instance.
Definition Action.php:236
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.
getPageTitle()
Returns the name that goes in the "<h1>" page title.
pageInfo()
Returns page information in an easily-manipulated format.
pageCounts(Page $page)
Returns page counts that would be too "expensive" to retrieve by normal means.
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 getCacheKey(WANObjectCache $cache, Title $title, $revId)
static invalidateCache(Title $title, $revid=null)
Clear the info cache for a given Title.
getContributors()
Get a list of contributors of $article.
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition LinkBatch.php:34
static revUserTools( $rev, $isPublic=false)
Generate a user tool link cluster if the current user is allowed to view it.
Definition Linker.php:1070
static formatHiddenCategories( $hiddencats)
Returns HTML for the "hidden categories on this page" list.
Definition Linker.php:1917
static getDoubleUnderscoreArray()
Get a MagicWordArray of double-underscore entities.
MediaWikiServices is the service locator for the application scope of MediaWiki.
The Message class provides methods which fulfil two basic services:
Definition Message.php:159
static getInstance()
Definition PageProps.php:66
Handles formatting for the "templates used on this page" lists.
Represents a title within MediaWiki.
Definition Title.php:39
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:591
Multi-datacenter aware caching interface.
Relational database abstraction object.
Definition Database.php:48
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition design.txt:57
when a variable name is used in a function
Definition design.txt:94
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition design.txt:18
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
const NS_USER
Definition Defines.php:76
const NS_FILE
Definition Defines.php:80
const MIGRATION_NEW
Definition Defines.php:305
const MIGRATION_OLD
Definition Defines.php:302
const NS_CATEGORY
Definition Defines.php:88
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition hooks.txt:1993
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2255
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Definition hooks.txt:1015
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:2001
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:964
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:302
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
Definition hooks.txt:2056
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition hooks.txt:247
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
Definition Page.php:24
$batch
Definition linkcache.txt:23
magicword txt Magic Words are some phrases used in the wikitext They are used for two that looks like templates but that don t accept any parameter *Parser functions(like {{fullurl:...}}, {{#special:...}}) $magicWords['en']
Definition magicword.txt:33
$cache
Definition mcc.php:33
const DB_REPLICA
Definition defines.php:25
$property
if(!isset( $args[0])) $lang
$header
$contributors