MediaWiki  1.29.1
InfoAction.php
Go to the documentation of this file.
1 <?php
27 
33 class InfoAction extends FormlessAction {
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  $key = self::getCacheKey( $title, $revid );
77  ObjectCache::getMainWANInstance()->delete( $key );
78  }
79  }
80 
86  public function onView() {
87  $content = '';
88 
89  // Validate revision
90  $oldid = $this->page->getOldID();
91  if ( $oldid ) {
92  $revision = $this->page->getRevisionFetched();
93 
94  // Revision is missing
95  if ( $revision === null ) {
96  return $this->msg( 'missing-revision', $oldid )->parse();
97  }
98 
99  // Revision is not current
100  if ( !$revision->isCurrent() ) {
101  return $this->msg( 'pageinfo-not-current' )->plain();
102  }
103  }
104 
105  // Page header
106  if ( !$this->msg( 'pageinfo-header' )->isDisabled() ) {
107  $content .= $this->msg( 'pageinfo-header' )->parse();
108  }
109 
110  // Hide "This page is a member of # hidden categories" explanation
111  $content .= Html::element( 'style', [],
112  '.mw-hiddenCategoriesExplanation { display: none; }' ) . "\n";
113 
114  // Hide "Templates used on this page" explanation
115  $content .= Html::element( 'style', [],
116  '.mw-templatesUsedExplanation { display: none; }' ) . "\n";
117 
118  // Get page information
119  $pageInfo = $this->pageInfo();
120 
121  // Allow extensions to add additional information
122  Hooks::run( 'InfoAction', [ $this->getContext(), &$pageInfo ] );
123 
124  // Render page information
125  foreach ( $pageInfo as $header => $infoTable ) {
126  // Messages:
127  // pageinfo-header-basic, pageinfo-header-edits, pageinfo-header-restrictions,
128  // pageinfo-header-properties, pageinfo-category-info
129  $content .= $this->makeHeader( $this->msg( "pageinfo-${header}" )->escaped() ) . "\n";
130  $table = "\n";
131  foreach ( $infoTable as $infoRow ) {
132  $name = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->escaped() : $infoRow[0];
133  $value = ( $infoRow[1] instanceof Message ) ? $infoRow[1]->escaped() : $infoRow[1];
134  $id = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->getKey() : null;
135  $table = $this->addRow( $table, $name, $value, $id ) . "\n";
136  }
137  $content = $this->addTable( $content, $table ) . "\n";
138  }
139 
140  // Page footer
141  if ( !$this->msg( 'pageinfo-footer' )->isDisabled() ) {
142  $content .= $this->msg( 'pageinfo-footer' )->parse();
143  }
144 
145  return $content;
146  }
147 
154  protected function makeHeader( $header ) {
155  $spanAttribs = [ 'class' => 'mw-headline', 'id' => Sanitizer::escapeId( $header ) ];
156 
157  return Html::rawElement( 'h2', [], Html::element( 'span', $spanAttribs, $header ) );
158  }
159 
169  protected function addRow( $table, $name, $value, $id ) {
170  return $table .
172  'tr',
173  $id === null ? [] : [ 'id' => 'mw-' . $id ],
174  Html::rawElement( 'td', [ 'style' => 'vertical-align: top;' ], $name ) .
175  Html::rawElement( 'td', [], $value )
176  );
177  }
178 
186  protected function addTable( $content, $table ) {
187  return $content . Html::rawElement( 'table', [ 'class' => 'wikitable mw-page-info' ],
188  $table );
189  }
190 
198  protected function pageInfo() {
200 
201  $user = $this->getUser();
202  $lang = $this->getLanguage();
203  $title = $this->getTitle();
204  $id = $title->getArticleID();
205  $config = $this->context->getConfig();
206  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
207 
208  $pageCounts = $this->pageCounts( $this->page );
209 
210  $pageProperties = [];
211  $props = PageProps::getInstance()->getAllProperties( $title );
212  if ( isset( $props[$id] ) ) {
213  $pageProperties = $props[$id];
214  }
215 
216  // Basic information
217  $pageInfo = [];
218  $pageInfo['header-basic'] = [];
219 
220  // Display title
221  $displayTitle = $title->getPrefixedText();
222  if ( isset( $pageProperties['displaytitle'] ) ) {
223  $displayTitle = $pageProperties['displaytitle'];
224  }
225 
226  $pageInfo['header-basic'][] = [
227  $this->msg( 'pageinfo-display-title' ), $displayTitle
228  ];
229 
230  // Is it a redirect? If so, where to?
231  if ( $title->isRedirect() ) {
232  $pageInfo['header-basic'][] = [
233  $this->msg( 'pageinfo-redirectsto' ),
234  $linkRenderer->makeLink( $this->page->getRedirectTarget() ) .
235  $this->msg( 'word-separator' )->escaped() .
236  $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
237  $this->page->getRedirectTarget(),
238  $this->msg( 'pageinfo-redirectsto-info' )->text(),
239  [],
240  [ 'action' => 'info' ]
241  ) )->escaped()
242  ];
243  }
244 
245  // Default sort key
246  $sortKey = $title->getCategorySortkey();
247  if ( isset( $pageProperties['defaultsort'] ) ) {
248  $sortKey = $pageProperties['defaultsort'];
249  }
250 
251  $sortKey = htmlspecialchars( $sortKey );
252  $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-default-sort' ), $sortKey ];
253 
254  // Page length (in bytes)
255  $pageInfo['header-basic'][] = [
256  $this->msg( 'pageinfo-length' ), $lang->formatNum( $title->getLength() )
257  ];
258 
259  // Page ID (number not localised, as it's a database ID)
260  $pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-article-id' ), $id ];
261 
262  // Language in which the page content is (supposed to be) written
263  $pageLang = $title->getPageLanguage()->getCode();
264 
265  $pageLangHtml = $pageLang . ' - ' .
266  Language::fetchLanguageName( $pageLang, $lang->getCode() );
267  // Link to Special:PageLanguage with pre-filled page title if user has permissions
268  if ( $config->get( 'PageLanguageUseDB' )
269  && $title->userCan( 'pagelang', $user )
270  ) {
271  $pageLangHtml .= ' ' . $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
272  SpecialPage::getTitleValueFor( 'PageLanguage', $title->getPrefixedText() ),
273  $this->msg( 'pageinfo-language-change' )->text()
274  ) )->escaped();
275  }
276 
277  $pageInfo['header-basic'][] = [
278  $this->msg( 'pageinfo-language' )->escaped(),
279  $pageLangHtml
280  ];
281 
282  // Content model of the page
283  $modelHtml = htmlspecialchars( ContentHandler::getLocalizedName( $title->getContentModel() ) );
284  // If the user can change it, add a link to Special:ChangeContentModel
285  if ( $config->get( 'ContentHandlerUseDB' )
286  && $title->userCan( 'editcontentmodel', $user )
287  ) {
288  $modelHtml .= ' ' . $this->msg( 'parentheses' )->rawParams( $linkRenderer->makeLink(
289  SpecialPage::getTitleValueFor( 'ChangeContentModel', $title->getPrefixedText() ),
290  $this->msg( 'pageinfo-content-model-change' )->text()
291  ) )->escaped();
292  }
293 
294  $pageInfo['header-basic'][] = [
295  $this->msg( 'pageinfo-content-model' ),
296  $modelHtml
297  ];
298 
299  if ( $title->inNamespace( NS_USER ) ) {
300  $pageUser = User::newFromName( $title->getRootText() );
301  if ( $pageUser && $pageUser->getId() && !$pageUser->isHidden() ) {
302  $pageInfo['header-basic'][] = [
303  $this->msg( 'pageinfo-user-id' ),
304  $pageUser->getId()
305  ];
306  }
307  }
308 
309  // Search engine status
310  $pOutput = new ParserOutput();
311  if ( isset( $pageProperties['noindex'] ) ) {
312  $pOutput->setIndexPolicy( 'noindex' );
313  }
314  if ( isset( $pageProperties['index'] ) ) {
315  $pOutput->setIndexPolicy( 'index' );
316  }
317 
318  // Use robot policy logic
319  $policy = $this->page->getRobotPolicy( 'view', $pOutput );
320  $pageInfo['header-basic'][] = [
321  // Messages: pageinfo-robot-index, pageinfo-robot-noindex
322  $this->msg( 'pageinfo-robot-policy' ),
323  $this->msg( "pageinfo-robot-${policy['index']}" )
324  ];
325 
326  $unwatchedPageThreshold = $config->get( 'UnwatchedPageThreshold' );
327  if (
328  $user->isAllowed( 'unwatchedpages' ) ||
329  ( $unwatchedPageThreshold !== false &&
330  $pageCounts['watchers'] >= $unwatchedPageThreshold )
331  ) {
332  // Number of page watchers
333  $pageInfo['header-basic'][] = [
334  $this->msg( 'pageinfo-watchers' ),
335  $lang->formatNum( $pageCounts['watchers'] )
336  ];
337  if (
338  $config->get( 'ShowUpdatedMarker' ) &&
339  isset( $pageCounts['visitingWatchers'] )
340  ) {
341  $minToDisclose = $config->get( 'UnwatchedPageSecret' );
342  if ( $pageCounts['visitingWatchers'] > $minToDisclose ||
343  $user->isAllowed( 'unwatchedpages' ) ) {
344  $pageInfo['header-basic'][] = [
345  $this->msg( 'pageinfo-visiting-watchers' ),
346  $lang->formatNum( $pageCounts['visitingWatchers'] )
347  ];
348  } else {
349  $pageInfo['header-basic'][] = [
350  $this->msg( 'pageinfo-visiting-watchers' ),
351  $this->msg( 'pageinfo-few-visiting-watchers' )
352  ];
353  }
354  }
355  } elseif ( $unwatchedPageThreshold !== false ) {
356  $pageInfo['header-basic'][] = [
357  $this->msg( 'pageinfo-watchers' ),
358  $this->msg( 'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
359  ];
360  }
361 
362  // Redirects to this page
363  $whatLinksHere = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
364  $pageInfo['header-basic'][] = [
365  $linkRenderer->makeLink(
366  $whatLinksHere,
367  $this->msg( 'pageinfo-redirects-name' )->text(),
368  [],
369  [
370  'hidelinks' => 1,
371  'hidetrans' => 1,
372  'hideimages' => $title->getNamespace() == NS_FILE
373  ]
374  ),
375  $this->msg( 'pageinfo-redirects-value' )
376  ->numParams( count( $title->getRedirectsHere() ) )
377  ];
378 
379  // Is it counted as a content page?
380  if ( $this->page->isCountable() ) {
381  $pageInfo['header-basic'][] = [
382  $this->msg( 'pageinfo-contentpage' ),
383  $this->msg( 'pageinfo-contentpage-yes' )
384  ];
385  }
386 
387  // Subpages of this page, if subpages are enabled for the current NS
388  if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) {
389  $prefixIndex = SpecialPage::getTitleFor(
390  'Prefixindex', $title->getPrefixedText() . '/' );
391  $pageInfo['header-basic'][] = [
392  Linker::link( $prefixIndex, $this->msg( 'pageinfo-subpages-name' )->escaped() ),
393  $this->msg( 'pageinfo-subpages-value' )
394  ->numParams(
395  $pageCounts['subpages']['total'],
396  $pageCounts['subpages']['redirects'],
397  $pageCounts['subpages']['nonredirects'] )
398  ];
399  }
400 
401  if ( $title->inNamespace( NS_CATEGORY ) ) {
402  $category = Category::newFromTitle( $title );
403 
404  // $allCount is the total number of cat members,
405  // not the count of how many members are normal pages.
406  $allCount = (int)$category->getPageCount();
407  $subcatCount = (int)$category->getSubcatCount();
408  $fileCount = (int)$category->getFileCount();
409  $pagesCount = $allCount - $subcatCount - $fileCount;
410 
411  $pageInfo['category-info'] = [
412  [
413  $this->msg( 'pageinfo-category-total' ),
414  $lang->formatNum( $allCount )
415  ],
416  [
417  $this->msg( 'pageinfo-category-pages' ),
418  $lang->formatNum( $pagesCount )
419  ],
420  [
421  $this->msg( 'pageinfo-category-subcats' ),
422  $lang->formatNum( $subcatCount )
423  ],
424  [
425  $this->msg( 'pageinfo-category-files' ),
426  $lang->formatNum( $fileCount )
427  ]
428  ];
429  }
430 
431  // Page protection
432  $pageInfo['header-restrictions'] = [];
433 
434  // Is this page affected by the cascading protection of something which includes it?
435  if ( $title->isCascadeProtected() ) {
436  $cascadingFrom = '';
437  $sources = $title->getCascadeProtectionSources()[0];
438 
439  foreach ( $sources as $sourceTitle ) {
440  $cascadingFrom .= Html::rawElement(
441  'li', [], $linkRenderer->makeKnownLink( $sourceTitle ) );
442  }
443 
444  $cascadingFrom = Html::rawElement( 'ul', [], $cascadingFrom );
445  $pageInfo['header-restrictions'][] = [
446  $this->msg( 'pageinfo-protect-cascading-from' ),
447  $cascadingFrom
448  ];
449  }
450 
451  // Is out protection set to cascade to other pages?
452  if ( $title->areRestrictionsCascading() ) {
453  $pageInfo['header-restrictions'][] = [
454  $this->msg( 'pageinfo-protect-cascading' ),
455  $this->msg( 'pageinfo-protect-cascading-yes' )
456  ];
457  }
458 
459  // Page protection
460  foreach ( $title->getRestrictionTypes() as $restrictionType ) {
461  $protectionLevel = implode( ', ', $title->getRestrictions( $restrictionType ) );
462 
463  if ( $protectionLevel == '' ) {
464  // Allow all users
465  $message = $this->msg( 'protect-default' )->escaped();
466  } else {
467  // Administrators only
468  // Messages: protect-level-autoconfirmed, protect-level-sysop
469  $message = $this->msg( "protect-level-$protectionLevel" );
470  if ( $message->isDisabled() ) {
471  // Require "$1" permission
472  $message = $this->msg( "protect-fallback", $protectionLevel )->parse();
473  } else {
474  $message = $message->escaped();
475  }
476  }
477  $expiry = $title->getRestrictionExpiry( $restrictionType );
478  $formattedexpiry = $this->msg( 'parentheses',
479  $lang->formatExpiry( $expiry ) )->escaped();
480  $message .= $this->msg( 'word-separator' )->escaped() . $formattedexpiry;
481 
482  // Messages: restriction-edit, restriction-move, restriction-create,
483  // restriction-upload
484  $pageInfo['header-restrictions'][] = [
485  $this->msg( "restriction-$restrictionType" ), $message
486  ];
487  }
488 
489  if ( !$this->page->exists() ) {
490  return $pageInfo;
491  }
492 
493  // Edit history
494  $pageInfo['header-edits'] = [];
495 
496  $firstRev = $this->page->getOldestRevision();
497  $lastRev = $this->page->getRevision();
498  $batch = new LinkBatch;
499 
500  if ( $firstRev ) {
501  $firstRevUser = $firstRev->getUserText( Revision::FOR_THIS_USER );
502  if ( $firstRevUser !== '' ) {
503  $firstRevUserTitle = Title::makeTitle( NS_USER, $firstRevUser );
504  $batch->addObj( $firstRevUserTitle );
505  $batch->addObj( $firstRevUserTitle->getTalkPage() );
506  }
507  }
508 
509  if ( $lastRev ) {
510  $lastRevUser = $lastRev->getUserText( Revision::FOR_THIS_USER );
511  if ( $lastRevUser !== '' ) {
512  $lastRevUserTitle = Title::makeTitle( NS_USER, $lastRevUser );
513  $batch->addObj( $lastRevUserTitle );
514  $batch->addObj( $lastRevUserTitle->getTalkPage() );
515  }
516  }
517 
518  $batch->execute();
519 
520  if ( $firstRev ) {
521  // Page creator
522  $pageInfo['header-edits'][] = [
523  $this->msg( 'pageinfo-firstuser' ),
524  Linker::revUserTools( $firstRev )
525  ];
526 
527  // Date of page creation
528  $pageInfo['header-edits'][] = [
529  $this->msg( 'pageinfo-firsttime' ),
530  $linkRenderer->makeKnownLink(
531  $title,
532  $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ),
533  [],
534  [ 'oldid' => $firstRev->getId() ]
535  )
536  ];
537  }
538 
539  if ( $lastRev ) {
540  // Latest editor
541  $pageInfo['header-edits'][] = [
542  $this->msg( 'pageinfo-lastuser' ),
543  Linker::revUserTools( $lastRev )
544  ];
545 
546  // Date of latest edit
547  $pageInfo['header-edits'][] = [
548  $this->msg( 'pageinfo-lasttime' ),
549  $linkRenderer->makeKnownLink(
550  $title,
551  $lang->userTimeAndDate( $this->page->getTimestamp(), $user ),
552  [],
553  [ 'oldid' => $this->page->getLatest() ]
554  )
555  ];
556  }
557 
558  // Total number of edits
559  $pageInfo['header-edits'][] = [
560  $this->msg( 'pageinfo-edits' ), $lang->formatNum( $pageCounts['edits'] )
561  ];
562 
563  // Total number of distinct authors
564  if ( $pageCounts['authors'] > 0 ) {
565  $pageInfo['header-edits'][] = [
566  $this->msg( 'pageinfo-authors' ), $lang->formatNum( $pageCounts['authors'] )
567  ];
568  }
569 
570  // Recent number of edits (within past 30 days)
571  $pageInfo['header-edits'][] = [
572  $this->msg( 'pageinfo-recent-edits',
573  $lang->formatDuration( $config->get( 'RCMaxAge' ) ) ),
574  $lang->formatNum( $pageCounts['recent_edits'] )
575  ];
576 
577  // Recent number of distinct authors
578  $pageInfo['header-edits'][] = [
579  $this->msg( 'pageinfo-recent-authors' ),
580  $lang->formatNum( $pageCounts['recent_authors'] )
581  ];
582 
583  // Array of MagicWord objects
585 
586  // Array of magic word IDs
587  $wordIDs = $magicWords->names;
588 
589  // Array of IDs => localized magic words
590  $localizedWords = $wgContLang->getMagicWords();
591 
592  $listItems = [];
593  foreach ( $pageProperties as $property => $value ) {
594  if ( in_array( $property, $wordIDs ) ) {
595  $listItems[] = Html::element( 'li', [], $localizedWords[$property][1] );
596  }
597  }
598 
599  $localizedList = Html::rawElement( 'ul', [], implode( '', $listItems ) );
600  $hiddenCategories = $this->page->getHiddenCategories();
601 
602  if (
603  count( $listItems ) > 0 ||
604  count( $hiddenCategories ) > 0 ||
605  $pageCounts['transclusion']['from'] > 0 ||
606  $pageCounts['transclusion']['to'] > 0
607  ) {
608  $options = [ 'LIMIT' => $config->get( 'PageInfoTransclusionLimit' ) ];
609  $transcludedTemplates = $title->getTemplateLinksFrom( $options );
610  if ( $config->get( 'MiserMode' ) ) {
611  $transcludedTargets = [];
612  } else {
613  $transcludedTargets = $title->getTemplateLinksTo( $options );
614  }
615 
616  // Page properties
617  $pageInfo['header-properties'] = [];
618 
619  // Magic words
620  if ( count( $listItems ) > 0 ) {
621  $pageInfo['header-properties'][] = [
622  $this->msg( 'pageinfo-magic-words' )->numParams( count( $listItems ) ),
623  $localizedList
624  ];
625  }
626 
627  // Hidden categories
628  if ( count( $hiddenCategories ) > 0 ) {
629  $pageInfo['header-properties'][] = [
630  $this->msg( 'pageinfo-hidden-categories' )
631  ->numParams( count( $hiddenCategories ) ),
632  Linker::formatHiddenCategories( $hiddenCategories )
633  ];
634  }
635 
636  // Transcluded templates
637  if ( $pageCounts['transclusion']['from'] > 0 ) {
638  if ( $pageCounts['transclusion']['from'] > count( $transcludedTemplates ) ) {
639  $more = $this->msg( 'morenotlisted' )->escaped();
640  } else {
641  $more = null;
642  }
643 
644  $templateListFormatter = new TemplatesOnThisPageFormatter(
645  $this->getContext(),
647  );
648 
649  $pageInfo['header-properties'][] = [
650  $this->msg( 'pageinfo-templates' )
651  ->numParams( $pageCounts['transclusion']['from'] ),
652  $templateListFormatter->format( $transcludedTemplates, false, $more )
653  ];
654  }
655 
656  if ( !$config->get( 'MiserMode' ) && $pageCounts['transclusion']['to'] > 0 ) {
657  if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) {
658  $more = $linkRenderer->makeLink(
659  $whatLinksHere,
660  $this->msg( 'moredotdotdot' )->text(),
661  [],
662  [ 'hidelinks' => 1, 'hideredirs' => 1 ]
663  );
664  } else {
665  $more = null;
666  }
667 
668  $templateListFormatter = new TemplatesOnThisPageFormatter(
669  $this->getContext(),
671  );
672 
673  $pageInfo['header-properties'][] = [
674  $this->msg( 'pageinfo-transclusions' )
675  ->numParams( $pageCounts['transclusion']['to'] ),
676  $templateListFormatter->format( $transcludedTargets, false, $more )
677  ];
678  }
679  }
680 
681  return $pageInfo;
682  }
683 
690  protected function pageCounts( Page $page ) {
691  $fname = __METHOD__;
692  $config = $this->context->getConfig();
693 
694  return ObjectCache::getMainWANInstance()->getWithSetCallback(
695  self::getCacheKey( $page->getTitle(), $page->getLatest() ),
697  function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
698  $title = $page->getTitle();
699  $id = $title->getArticleID();
700 
701  $dbr = wfGetDB( DB_REPLICA );
702  $dbrWatchlist = wfGetDB( DB_REPLICA, 'watchlist' );
703  $setOpts += Database::getCacheSetOptions( $dbr, $dbrWatchlist );
704 
705  $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
706 
707  $result = [];
708  $result['watchers'] = $watchedItemStore->countWatchers( $title );
709 
710  if ( $config->get( 'ShowUpdatedMarker' ) ) {
711  $updated = wfTimestamp( TS_UNIX, $page->getTimestamp() );
712  $result['visitingWatchers'] = $watchedItemStore->countVisitingWatchers(
713  $title,
714  $updated - $config->get( 'WatchersMaxAge' )
715  );
716  }
717 
718  // Total number of edits
719  $edits = (int)$dbr->selectField(
720  'revision',
721  'COUNT(*)',
722  [ 'rev_page' => $id ],
723  $fname
724  );
725  $result['edits'] = $edits;
726 
727  // Total number of distinct authors
728  if ( $config->get( 'MiserMode' ) ) {
729  $result['authors'] = 0;
730  } else {
731  $result['authors'] = (int)$dbr->selectField(
732  'revision',
733  'COUNT(DISTINCT rev_user_text)',
734  [ 'rev_page' => $id ],
735  $fname
736  );
737  }
738 
739  // "Recent" threshold defined by RCMaxAge setting
740  $threshold = $dbr->timestamp( time() - $config->get( 'RCMaxAge' ) );
741 
742  // Recent number of edits
743  $edits = (int)$dbr->selectField(
744  'revision',
745  'COUNT(rev_page)',
746  [
747  'rev_page' => $id,
748  "rev_timestamp >= " . $dbr->addQuotes( $threshold )
749  ],
750  $fname
751  );
752  $result['recent_edits'] = $edits;
753 
754  // Recent number of distinct authors
755  $result['recent_authors'] = (int)$dbr->selectField(
756  'revision',
757  'COUNT(DISTINCT rev_user_text)',
758  [
759  'rev_page' => $id,
760  "rev_timestamp >= " . $dbr->addQuotes( $threshold )
761  ],
762  $fname
763  );
764 
765  // Subpages (if enabled)
766  if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) {
767  $conds = [ 'page_namespace' => $title->getNamespace() ];
768  $conds[] = 'page_title ' .
769  $dbr->buildLike( $title->getDBkey() . '/', $dbr->anyString() );
770 
771  // Subpages of this page (redirects)
772  $conds['page_is_redirect'] = 1;
773  $result['subpages']['redirects'] = (int)$dbr->selectField(
774  'page',
775  'COUNT(page_id)',
776  $conds,
777  $fname
778  );
779 
780  // Subpages of this page (non-redirects)
781  $conds['page_is_redirect'] = 0;
782  $result['subpages']['nonredirects'] = (int)$dbr->selectField(
783  'page',
784  'COUNT(page_id)',
785  $conds,
786  $fname
787  );
788 
789  // Subpages of this page (total)
790  $result['subpages']['total'] = $result['subpages']['redirects']
791  + $result['subpages']['nonredirects'];
792  }
793 
794  // Counts for the number of transclusion links (to/from)
795  if ( $config->get( 'MiserMode' ) ) {
796  $result['transclusion']['to'] = 0;
797  } else {
798  $result['transclusion']['to'] = (int)$dbr->selectField(
799  'templatelinks',
800  'COUNT(tl_from)',
801  [
802  'tl_namespace' => $title->getNamespace(),
803  'tl_title' => $title->getDBkey()
804  ],
805  $fname
806  );
807  }
808 
809  $result['transclusion']['from'] = (int)$dbr->selectField(
810  'templatelinks',
811  'COUNT(*)',
812  [ 'tl_from' => $title->getArticleID() ],
813  $fname
814  );
815 
816  return $result;
817  }
818  );
819  }
820 
826  protected function getPageTitle() {
827  return $this->msg( 'pageinfo-title', $this->getTitle()->getPrefixedText() )->text();
828  }
829 
834  protected function getContributors() {
835  $contributors = $this->page->getContributors();
836  $real_names = [];
837  $user_names = [];
838  $anon_ips = [];
839  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
840 
841  # Sift for real versus user names
842 
843  foreach ( $contributors as $user ) {
844  $page = $user->isAnon()
845  ? SpecialPage::getTitleFor( 'Contributions', $user->getName() )
846  : $user->getUserPage();
847 
848  $hiddenPrefs = $this->context->getConfig()->get( 'HiddenPrefs' );
849  if ( $user->getId() == 0 ) {
850  $anon_ips[] = $linkRenderer->makeLink( $page, $user->getName() );
851  } elseif ( !in_array( 'realname', $hiddenPrefs ) && $user->getRealName() ) {
852  $real_names[] = $linkRenderer->makeLink( $page, $user->getRealName() );
853  } else {
854  $user_names[] = $linkRenderer->makeLink( $page, $user->getName() );
855  }
856  }
857 
858  $lang = $this->getLanguage();
859 
860  $real = $lang->listToText( $real_names );
861 
862  # "ThisSite user(s) A, B and C"
863  if ( count( $user_names ) ) {
864  $user = $this->msg( 'siteusers' )
865  ->rawParams( $lang->listToText( $user_names ) )
866  ->params( count( $user_names ) )->escaped();
867  } else {
868  $user = false;
869  }
870 
871  if ( count( $anon_ips ) ) {
872  $anon = $this->msg( 'anonusers' )
873  ->rawParams( $lang->listToText( $anon_ips ) )
874  ->params( count( $anon_ips ) )->escaped();
875  } else {
876  $anon = false;
877  }
878 
879  # This is the big list, all mooshed together. We sift for blank strings
880  $fulllist = [];
881  foreach ( [ $real, $user, $anon ] as $s ) {
882  if ( $s !== '' ) {
883  array_push( $fulllist, $s );
884  }
885  }
886 
887  $count = count( $fulllist );
888 
889  # "Based on work by ..."
890  return $count
891  ? $this->msg( 'othercontribs' )->rawParams(
892  $lang->listToText( $fulllist ) )->params( $count )->escaped()
893  : '';
894  }
895 
901  protected function getDescription() {
902  return '';
903  }
904 
910  protected static function getCacheKey( Title $title, $revId ) {
911  return wfMemcKey( 'infoaction', md5( $title->getPrefixedText() ), $revId, self::VERSION );
912  }
913 }
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:45
Page
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
Definition: Page.php:24
ParserOutput
Definition: ParserOutput.php:24
LinkBatch
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:34
FormlessAction
An action which just does something, without showing a form first.
Definition: FormlessAction.php:28
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
captcha-old.count
count
Definition: captcha-old.py:225
text
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:12
InfoAction\getDescription
getDescription()
Returns the description that goes below the "<h1>" tag.
Definition: InfoAction.php:901
$result
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. '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 '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:1954
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1994
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$user
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 account $user
Definition: hooks.txt:246
InfoAction\requiresWrite
requiresWrite()
Whether this action requires the wiki not to be locked.
Definition: InfoAction.php:59
$fname
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition: Setup.php:36
NS_FILE
const NS_FILE
Definition: Defines.php:68
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:556
$s
$s
Definition: mergeMessageFileList.php:188
$linkRenderer
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:1956
SpecialPage\getTitleFor
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,...
Definition: SpecialPage.php:82
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:304
InfoAction\makeHeader
makeHeader( $header)
Creates a header that can be added to the output.
Definition: InfoAction.php:154
InfoAction\getName
getName()
Returns the name of the action this object responds to.
Definition: InfoAction.php:41
InfoAction\getContributors
getContributors()
Get a list of contributors of $article.
Definition: InfoAction.php:834
php
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:35
Linker\formatHiddenCategories
static formatHiddenCategories( $hiddencats)
Returns HTML for the "hidden categories on this page" list.
Definition: Linker.php:1884
Revision\FOR_THIS_USER
const FOR_THIS_USER
Definition: Revision.php:99
Revision\newFromTitle
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target.
Definition: Revision.php:134
Action\getContext
getContext()
Get the IContextSource in use here.
Definition: Action.php:178
InfoAction
Displays information about a page.
Definition: InfoAction.php:33
wfMemcKey
wfMemcKey()
Make a cache key for the local wiki.
Definition: GlobalFunctions.php:2961
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
$property
$property
Definition: styleTest.css.php:44
InfoAction\getPageTitle
getPageTitle()
Returns the name that goes in the "<h1>" page title.
Definition: InfoAction.php:826
SpecialPage\getTitleValueFor
static getTitleValueFor( $name, $subpage=false, $fragment='')
Get a localised TitleValue object for a specified special page name.
Definition: SpecialPage.php:97
$content
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 and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
Definition: hooks.txt:1049
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3060
Linker\revUserTools
static revUserTools( $rev, $isPublic=false)
Generate a user tool link cluster if the current user is allowed to view it.
Definition: Linker.php:1055
PageProps\getInstance
static getInstance()
Definition: PageProps.php:66
InfoAction\getCacheKey
static getCacheKey(Title $title, $revId)
Definition: InfoAction.php:910
MWNamespace\hasSubpages
static hasSubpages( $index)
Does the namespace allow subpages?
Definition: MWNamespace.php:330
$contributors
$contributors
Definition: updateCredits.php:36
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:514
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
InfoAction\VERSION
const VERSION
Definition: InfoAction.php:34
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:76
$magicWords
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
InfoAction\addRow
addRow( $table, $name, $value, $id)
Adds a row to a table that will be added to the content.
Definition: InfoAction.php:169
Category\newFromTitle
static newFromTitle( $title)
Factory function.
Definition: Category.php:140
Action\getUser
getUser()
Shortcut to get the User being used for this instance.
Definition: Action.php:217
InfoAction\pageInfo
pageInfo()
Returns page information in an easily-manipulated format.
Definition: InfoAction.php:198
TemplatesOnThisPageFormatter
Handles formatting for the "templates used on this page" lists.
Definition: TemplatesOnThisPageFormatter.php:30
InfoAction\addTable
addTable( $content, $table)
Adds a table to the content that will be added to the output.
Definition: InfoAction.php:186
$value
$value
Definition: styleTest.css.php:45
ContentHandler\getLocalizedName
static getLocalizedName( $name, Language $lang=null)
Returns the localized name for a given content model.
Definition: ContentHandler.php:348
$header
$header
Definition: updateCredits.php:35
Linker\link
static link( $target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
Definition: Linker.php:107
Action\getTitle
getTitle()
Shortcut to get the Title object from the page.
Definition: Action.php:246
Language\fetchLanguageName
static fetchLanguageName( $code, $inLanguage=null, $include='all')
Definition: Language.php:891
InfoAction\requiresUnblock
requiresUnblock()
Whether this action can still be executed by a blocked user.
Definition: InfoAction.php:50
IExpiringStore\TTL_WEEK
const TTL_WEEK
Definition: IExpiringStore.php:36
Action\msg
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:256
InfoAction\onView
onView()
Shows page information on GET request.
Definition: InfoAction.php:86
page
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached my talk page
Definition: hooks.txt:2536
Title
Represents a title within MediaWiki.
Definition: Title.php:39
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
Action\$page
$page
Page on which we're performing the action.
Definition: Action.php:44
ObjectCache\getMainWANInstance
static getMainWANInstance()
Get the main WAN cache object.
Definition: ObjectCache.php:370
as
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
Definition: distributors.txt:9
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
Action\getLanguage
getLanguage()
Shortcut to get the user Language being used for this instance.
Definition: Action.php:236
NS_USER
const NS_USER
Definition: Defines.php:64
InfoAction\invalidateCache
static invalidateCache(Title $title, $revid=null)
Clear the info cache for a given Title.
Definition: InfoAction.php:70
MagicWord\getDoubleUnderscoreArray
static getDoubleUnderscoreArray()
Get a MagicWordArray of double-underscore entities.
Definition: MagicWord.php:308
$batch
$batch
Definition: linkcache.txt:23
$revId
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 and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context $revId
Definition: hooks.txt:1049
InfoAction\pageCounts
pageCounts(Page $page)
Returns page counts that would be too "expensive" to retrieve by normal means.
Definition: InfoAction.php:690
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
$options
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 and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1049
$wgContLang
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 content language as $wgContLang
Definition: design.txt:56