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