Merge "Fix positioning of jQuery.tipsy tooltip arrows"
[mediawiki.git] / includes / actions / InfoAction.php
blob7389ae2c027a0d54456af63e1a92ccb74e2a5c7b
1 <?php
2 /**
3 * Displays information about a page.
5 * Copyright © 2011 Alexandre Emsenhuber
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 * @file
22 * @ingroup Actions
25 /**
26 * Displays information about a page.
28 * @ingroup Actions
30 class InfoAction extends FormlessAction {
31 const VERSION = 1;
33 /**
34 * Returns the name of the action this object responds to.
36 * @return string Lowercase name
38 public function getName() {
39 return 'info';
42 /**
43 * Whether this action can still be executed by a blocked user.
45 * @return bool
47 public function requiresUnblock() {
48 return false;
51 /**
52 * Whether this action requires the wiki not to be locked.
54 * @return bool
56 public function requiresWrite() {
57 return false;
60 /**
61 * Clear the info cache for a given Title.
63 * @since 1.22
64 * @param Title $title Title to clear cache for
65 * @param int|null $revid Revision id to clear
67 public static function invalidateCache( Title $title, $revid = null ) {
68 if ( !$revid ) {
69 $revision = Revision::newFromTitle( $title, 0, Revision::READ_LATEST );
70 $revid = $revision ? $revision->getId() : null;
72 if ( $revid !== null ) {
73 $key = self::getCacheKey( $title, $revid );
74 ObjectCache::getMainWANInstance()->delete( $key );
78 /**
79 * Shows page information on GET request.
81 * @return string Page information that will be added to the output
83 public function onView() {
84 $content = '';
86 // Validate revision
87 $oldid = $this->page->getOldID();
88 if ( $oldid ) {
89 $revision = $this->page->getRevisionFetched();
91 // Revision is missing
92 if ( $revision === null ) {
93 return $this->msg( 'missing-revision', $oldid )->parse();
96 // Revision is not current
97 if ( !$revision->isCurrent() ) {
98 return $this->msg( 'pageinfo-not-current' )->plain();
102 // Page header
103 if ( !$this->msg( 'pageinfo-header' )->isDisabled() ) {
104 $content .= $this->msg( 'pageinfo-header' )->parse();
107 // Hide "This page is a member of # hidden categories" explanation
108 $content .= Html::element( 'style', array(),
109 '.mw-hiddenCategoriesExplanation { display: none; }' ) . "\n";
111 // Hide "Templates used on this page" explanation
112 $content .= Html::element( 'style', array(),
113 '.mw-templatesUsedExplanation { display: none; }' ) . "\n";
115 // Get page information
116 $pageInfo = $this->pageInfo();
118 // Allow extensions to add additional information
119 Hooks::run( 'InfoAction', array( $this->getContext(), &$pageInfo ) );
121 // Render page information
122 foreach ( $pageInfo as $header => $infoTable ) {
123 // Messages:
124 // pageinfo-header-basic, pageinfo-header-edits, pageinfo-header-restrictions,
125 // pageinfo-header-properties, pageinfo-category-info
126 $content .= $this->makeHeader( $this->msg( "pageinfo-${header}" )->escaped() ) . "\n";
127 $table = "\n";
128 foreach ( $infoTable as $infoRow ) {
129 $name = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->escaped() : $infoRow[0];
130 $value = ( $infoRow[1] instanceof Message ) ? $infoRow[1]->escaped() : $infoRow[1];
131 $id = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->getKey() : null;
132 $table = $this->addRow( $table, $name, $value, $id ) . "\n";
134 $content = $this->addTable( $content, $table ) . "\n";
137 // Page footer
138 if ( !$this->msg( 'pageinfo-footer' )->isDisabled() ) {
139 $content .= $this->msg( 'pageinfo-footer' )->parse();
142 return $content;
146 * Creates a header that can be added to the output.
148 * @param string $header The header text.
149 * @return string The HTML.
151 protected function makeHeader( $header ) {
152 $spanAttribs = array( 'class' => 'mw-headline', 'id' => Sanitizer::escapeId( $header ) );
154 return Html::rawElement( 'h2', array(), Html::element( 'span', $spanAttribs, $header ) );
158 * Adds a row to a table that will be added to the content.
160 * @param string $table The table that will be added to the content
161 * @param string $name The name of the row
162 * @param string $value The value of the row
163 * @param string $id The ID to use for the 'tr' element
164 * @return string The table with the row added
166 protected function addRow( $table, $name, $value, $id ) {
167 return $table .
168 Html::rawElement(
169 'tr',
170 $id === null ? array() : array( 'id' => 'mw-' . $id ),
171 Html::rawElement( 'td', array( 'style' => 'vertical-align: top;' ), $name ) .
172 Html::rawElement( 'td', array(), $value )
177 * Adds a table to the content that will be added to the output.
179 * @param string $content The content that will be added to the output
180 * @param string $table The table
181 * @return string The content with the table added
183 protected function addTable( $content, $table ) {
184 return $content . Html::rawElement( 'table', array( 'class' => 'wikitable mw-page-info' ),
185 $table );
189 * Returns page information in an easily-manipulated format. Array keys are used so extensions
190 * may add additional information in arbitrary positions. Array values are arrays with one
191 * element to be rendered as a header, arrays with two elements to be rendered as a table row.
193 * @return array
195 protected function pageInfo() {
196 global $wgContLang;
198 $user = $this->getUser();
199 $lang = $this->getLanguage();
200 $title = $this->getTitle();
201 $id = $title->getArticleID();
202 $config = $this->context->getConfig();
204 $pageCounts = $this->pageCounts( $this->page );
206 // Get page properties
207 $dbr = wfGetDB( DB_SLAVE );
208 $result = $dbr->select(
209 'page_props',
210 array( 'pp_propname', 'pp_value' ),
211 array( 'pp_page' => $id ),
212 __METHOD__
215 $pageProperties = array();
216 foreach ( $result as $row ) {
217 $pageProperties[$row->pp_propname] = $row->pp_value;
220 // Basic information
221 $pageInfo = array();
222 $pageInfo['header-basic'] = array();
224 // Display title
225 $displayTitle = $title->getPrefixedText();
226 if ( isset( $pageProperties['displaytitle'] ) ) {
227 $displayTitle = $pageProperties['displaytitle'];
230 $pageInfo['header-basic'][] = array(
231 $this->msg( 'pageinfo-display-title' ), $displayTitle
234 // Is it a redirect? If so, where to?
235 if ( $title->isRedirect() ) {
236 $pageInfo['header-basic'][] = array(
237 $this->msg( 'pageinfo-redirectsto' ),
238 Linker::link( $this->page->getRedirectTarget() ) .
239 $this->msg( 'word-separator' )->escaped() .
240 $this->msg( 'parentheses' )->rawParams( Linker::link(
241 $this->page->getRedirectTarget(),
242 $this->msg( 'pageinfo-redirectsto-info' )->escaped(),
243 array(),
244 array( 'action' => 'info' )
245 ) )->escaped()
249 // Default sort key
250 $sortKey = $title->getCategorySortkey();
251 if ( isset( $pageProperties['defaultsort'] ) ) {
252 $sortKey = $pageProperties['defaultsort'];
255 $sortKey = htmlspecialchars( $sortKey );
256 $pageInfo['header-basic'][] = array( $this->msg( 'pageinfo-default-sort' ), $sortKey );
258 // Page length (in bytes)
259 $pageInfo['header-basic'][] = array(
260 $this->msg( 'pageinfo-length' ), $lang->formatNum( $title->getLength() )
263 // Page ID (number not localised, as it's a database ID)
264 $pageInfo['header-basic'][] = array( $this->msg( 'pageinfo-article-id' ), $id );
266 // Language in which the page content is (supposed to be) written
267 $pageLang = $title->getPageLanguage()->getCode();
269 if ( $config->get( 'PageLanguageUseDB' )
270 && $this->getTitle()->userCan( 'pagelang', $this->getUser() )
272 // Link to Special:PageLanguage with pre-filled page title if user has permissions
273 $titleObj = SpecialPage::getTitleFor( 'PageLanguage', $title->getPrefixedText() );
274 $langDisp = Linker::link(
275 $titleObj,
276 $this->msg( 'pageinfo-language' )->escaped()
278 } else {
279 // Display just the message
280 $langDisp = $this->msg( 'pageinfo-language' )->escaped();
283 $pageInfo['header-basic'][] = array( $langDisp,
284 Language::fetchLanguageName( $pageLang, $lang->getCode() )
285 . ' ' . $this->msg( 'parentheses', $pageLang )->escaped() );
287 // Content model of the page
288 $pageInfo['header-basic'][] = array(
289 $this->msg( 'pageinfo-content-model' ),
290 htmlspecialchars( ContentHandler::getLocalizedName( $title->getContentModel() ) )
293 // Search engine status
294 $pOutput = new ParserOutput();
295 if ( isset( $pageProperties['noindex'] ) ) {
296 $pOutput->setIndexPolicy( 'noindex' );
298 if ( isset( $pageProperties['index'] ) ) {
299 $pOutput->setIndexPolicy( 'index' );
302 // Use robot policy logic
303 $policy = $this->page->getRobotPolicy( 'view', $pOutput );
304 $pageInfo['header-basic'][] = array(
305 // Messages: pageinfo-robot-index, pageinfo-robot-noindex
306 $this->msg( 'pageinfo-robot-policy' ),
307 $this->msg( "pageinfo-robot-${policy['index']}" )
310 $unwatchedPageThreshold = $config->get( 'UnwatchedPageThreshold' );
311 if (
312 $user->isAllowed( 'unwatchedpages' ) ||
313 ( $unwatchedPageThreshold !== false &&
314 $pageCounts['watchers'] >= $unwatchedPageThreshold )
316 // Number of page watchers
317 $pageInfo['header-basic'][] = array(
318 $this->msg( 'pageinfo-watchers' ),
319 $lang->formatNum( $pageCounts['watchers'] )
321 if (
322 $config->get( 'ShowUpdatedMarker' ) &&
323 isset( $pageCounts['visitingWatchers'] )
325 $minToDisclose = $config->get( 'UnwatchedPageSecret' );
326 if ( $pageCounts['visitingWatchers'] > $minToDisclose ||
327 $user->isAllowed( 'unwatchedpages' ) ) {
328 $pageInfo['header-basic'][] = array(
329 $this->msg( 'pageinfo-visiting-watchers' ),
330 $lang->formatNum( $pageCounts['visitingWatchers'] )
332 } else {
333 $pageInfo['header-basic'][] = array(
334 $this->msg( 'pageinfo-visiting-watchers' ),
335 $this->msg( 'pageinfo-few-visiting-watchers' )
339 } elseif ( $unwatchedPageThreshold !== false ) {
340 $pageInfo['header-basic'][] = array(
341 $this->msg( 'pageinfo-watchers' ),
342 $this->msg( 'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
346 // Redirects to this page
347 $whatLinksHere = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
348 $pageInfo['header-basic'][] = array(
349 Linker::link(
350 $whatLinksHere,
351 $this->msg( 'pageinfo-redirects-name' )->escaped(),
352 array(),
353 array(
354 'hidelinks' => 1,
355 'hidetrans' => 1,
356 'hideimages' => $title->getNamespace() == NS_FILE
359 $this->msg( 'pageinfo-redirects-value' )
360 ->numParams( count( $title->getRedirectsHere() ) )
363 // Is it counted as a content page?
364 if ( $this->page->isCountable() ) {
365 $pageInfo['header-basic'][] = array(
366 $this->msg( 'pageinfo-contentpage' ),
367 $this->msg( 'pageinfo-contentpage-yes' )
371 // Subpages of this page, if subpages are enabled for the current NS
372 if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) {
373 $prefixIndex = SpecialPage::getTitleFor(
374 'Prefixindex', $title->getPrefixedText() . '/' );
375 $pageInfo['header-basic'][] = array(
376 Linker::link( $prefixIndex, $this->msg( 'pageinfo-subpages-name' )->escaped() ),
377 $this->msg( 'pageinfo-subpages-value' )
378 ->numParams(
379 $pageCounts['subpages']['total'],
380 $pageCounts['subpages']['redirects'],
381 $pageCounts['subpages']['nonredirects'] )
385 if ( $title->inNamespace( NS_CATEGORY ) ) {
386 $category = Category::newFromTitle( $title );
388 // $allCount is the total number of cat members,
389 // not the count of how many members are normal pages.
390 $allCount = (int)$category->getPageCount();
391 $subcatCount = (int)$category->getSubcatCount();
392 $fileCount = (int)$category->getFileCount();
393 $pagesCount = $allCount - $subcatCount - $fileCount;
395 $pageInfo['category-info'] = array(
396 array(
397 $this->msg( 'pageinfo-category-total' ),
398 $lang->formatNum( $allCount )
400 array(
401 $this->msg( 'pageinfo-category-pages' ),
402 $lang->formatNum( $pagesCount )
404 array(
405 $this->msg( 'pageinfo-category-subcats' ),
406 $lang->formatNum( $subcatCount )
408 array(
409 $this->msg( 'pageinfo-category-files' ),
410 $lang->formatNum( $fileCount )
415 // Page protection
416 $pageInfo['header-restrictions'] = array();
418 // Is this page affected by the cascading protection of something which includes it?
419 if ( $title->isCascadeProtected() ) {
420 $cascadingFrom = '';
421 $sources = $title->getCascadeProtectionSources(); // Array deferencing is in PHP 5.4 :(
423 foreach ( $sources[0] as $sourceTitle ) {
424 $cascadingFrom .= Html::rawElement(
425 'li', array(), Linker::linkKnown( $sourceTitle ) );
428 $cascadingFrom = Html::rawElement( 'ul', array(), $cascadingFrom );
429 $pageInfo['header-restrictions'][] = array(
430 $this->msg( 'pageinfo-protect-cascading-from' ),
431 $cascadingFrom
435 // Is out protection set to cascade to other pages?
436 if ( $title->areRestrictionsCascading() ) {
437 $pageInfo['header-restrictions'][] = array(
438 $this->msg( 'pageinfo-protect-cascading' ),
439 $this->msg( 'pageinfo-protect-cascading-yes' )
443 // Page protection
444 foreach ( $title->getRestrictionTypes() as $restrictionType ) {
445 $protectionLevel = implode( ', ', $title->getRestrictions( $restrictionType ) );
447 if ( $protectionLevel == '' ) {
448 // Allow all users
449 $message = $this->msg( 'protect-default' )->escaped();
450 } else {
451 // Administrators only
452 // Messages: protect-level-autoconfirmed, protect-level-sysop
453 $message = $this->msg( "protect-level-$protectionLevel" );
454 if ( $message->isDisabled() ) {
455 // Require "$1" permission
456 $message = $this->msg( "protect-fallback", $protectionLevel )->parse();
457 } else {
458 $message = $message->escaped();
461 $expiry = $title->getRestrictionExpiry( $restrictionType );
462 $formattedexpiry = $this->msg( 'parentheses',
463 $this->getLanguage()->formatExpiry( $expiry ) )->escaped();
464 $message .= $this->msg( 'word-separator' )->escaped() . $formattedexpiry;
466 // Messages: restriction-edit, restriction-move, restriction-create,
467 // restriction-upload
468 $pageInfo['header-restrictions'][] = array(
469 $this->msg( "restriction-$restrictionType" ), $message
473 if ( !$this->page->exists() ) {
474 return $pageInfo;
477 // Edit history
478 $pageInfo['header-edits'] = array();
480 $firstRev = $this->page->getOldestRevision();
481 $lastRev = $this->page->getRevision();
482 $batch = new LinkBatch;
484 if ( $firstRev ) {
485 $firstRevUser = $firstRev->getUserText( Revision::FOR_THIS_USER );
486 if ( $firstRevUser !== '' ) {
487 $batch->add( NS_USER, $firstRevUser );
488 $batch->add( NS_USER_TALK, $firstRevUser );
492 if ( $lastRev ) {
493 $lastRevUser = $lastRev->getUserText( Revision::FOR_THIS_USER );
494 if ( $lastRevUser !== '' ) {
495 $batch->add( NS_USER, $lastRevUser );
496 $batch->add( NS_USER_TALK, $lastRevUser );
500 $batch->execute();
502 if ( $firstRev ) {
503 // Page creator
504 $pageInfo['header-edits'][] = array(
505 $this->msg( 'pageinfo-firstuser' ),
506 Linker::revUserTools( $firstRev )
509 // Date of page creation
510 $pageInfo['header-edits'][] = array(
511 $this->msg( 'pageinfo-firsttime' ),
512 Linker::linkKnown(
513 $title,
514 htmlspecialchars( $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ) ),
515 array(),
516 array( 'oldid' => $firstRev->getId() )
521 if ( $lastRev ) {
522 // Latest editor
523 $pageInfo['header-edits'][] = array(
524 $this->msg( 'pageinfo-lastuser' ),
525 Linker::revUserTools( $lastRev )
528 // Date of latest edit
529 $pageInfo['header-edits'][] = array(
530 $this->msg( 'pageinfo-lasttime' ),
531 Linker::linkKnown(
532 $title,
533 htmlspecialchars(
534 $lang->userTimeAndDate( $this->page->getTimestamp(), $user )
536 array(),
537 array( 'oldid' => $this->page->getLatest() )
542 // Total number of edits
543 $pageInfo['header-edits'][] = array(
544 $this->msg( 'pageinfo-edits' ), $lang->formatNum( $pageCounts['edits'] )
547 // Total number of distinct authors
548 if ( $pageCounts['authors'] > 0 ) {
549 $pageInfo['header-edits'][] = array(
550 $this->msg( 'pageinfo-authors' ), $lang->formatNum( $pageCounts['authors'] )
554 // Recent number of edits (within past 30 days)
555 $pageInfo['header-edits'][] = array(
556 $this->msg( 'pageinfo-recent-edits',
557 $lang->formatDuration( $config->get( 'RCMaxAge' ) ) ),
558 $lang->formatNum( $pageCounts['recent_edits'] )
561 // Recent number of distinct authors
562 $pageInfo['header-edits'][] = array(
563 $this->msg( 'pageinfo-recent-authors' ),
564 $lang->formatNum( $pageCounts['recent_authors'] )
567 // Array of MagicWord objects
568 $magicWords = MagicWord::getDoubleUnderscoreArray();
570 // Array of magic word IDs
571 $wordIDs = $magicWords->names;
573 // Array of IDs => localized magic words
574 $localizedWords = $wgContLang->getMagicWords();
576 $listItems = array();
577 foreach ( $pageProperties as $property => $value ) {
578 if ( in_array( $property, $wordIDs ) ) {
579 $listItems[] = Html::element( 'li', array(), $localizedWords[$property][1] );
583 $localizedList = Html::rawElement( 'ul', array(), implode( '', $listItems ) );
584 $hiddenCategories = $this->page->getHiddenCategories();
586 if (
587 count( $listItems ) > 0 ||
588 count( $hiddenCategories ) > 0 ||
589 $pageCounts['transclusion']['from'] > 0 ||
590 $pageCounts['transclusion']['to'] > 0
592 $options = array( 'LIMIT' => $config->get( 'PageInfoTransclusionLimit' ) );
593 $transcludedTemplates = $title->getTemplateLinksFrom( $options );
594 if ( $config->get( 'MiserMode' ) ) {
595 $transcludedTargets = array();
596 } else {
597 $transcludedTargets = $title->getTemplateLinksTo( $options );
600 // Page properties
601 $pageInfo['header-properties'] = array();
603 // Magic words
604 if ( count( $listItems ) > 0 ) {
605 $pageInfo['header-properties'][] = array(
606 $this->msg( 'pageinfo-magic-words' )->numParams( count( $listItems ) ),
607 $localizedList
611 // Hidden categories
612 if ( count( $hiddenCategories ) > 0 ) {
613 $pageInfo['header-properties'][] = array(
614 $this->msg( 'pageinfo-hidden-categories' )
615 ->numParams( count( $hiddenCategories ) ),
616 Linker::formatHiddenCategories( $hiddenCategories )
620 // Transcluded templates
621 if ( $pageCounts['transclusion']['from'] > 0 ) {
622 if ( $pageCounts['transclusion']['from'] > count( $transcludedTemplates ) ) {
623 $more = $this->msg( 'morenotlisted' )->escaped();
624 } else {
625 $more = null;
628 $pageInfo['header-properties'][] = array(
629 $this->msg( 'pageinfo-templates' )
630 ->numParams( $pageCounts['transclusion']['from'] ),
631 Linker::formatTemplates(
632 $transcludedTemplates,
633 false,
634 false,
635 $more )
639 if ( !$config->get( 'MiserMode' ) && $pageCounts['transclusion']['to'] > 0 ) {
640 if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) {
641 $more = Linker::link(
642 $whatLinksHere,
643 $this->msg( 'moredotdotdot' )->escaped(),
644 array(),
645 array( 'hidelinks' => 1, 'hideredirs' => 1 )
647 } else {
648 $more = null;
651 $pageInfo['header-properties'][] = array(
652 $this->msg( 'pageinfo-transclusions' )
653 ->numParams( $pageCounts['transclusion']['to'] ),
654 Linker::formatTemplates(
655 $transcludedTargets,
656 false,
657 false,
658 $more )
663 return $pageInfo;
667 * Returns page counts that would be too "expensive" to retrieve by normal means.
669 * @param WikiPage|Article|Page $page
670 * @return array
672 protected function pageCounts( Page $page ) {
673 $fname = __METHOD__;
674 $config = $this->context->getConfig();
676 return ObjectCache::getMainWANInstance()->getWithSetCallback(
677 self::getCacheKey( $page->getTitle(), $page->getLatest() ),
678 86400 * 7,
679 function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
680 $title = $page->getTitle();
681 $id = $title->getArticleID();
683 $dbr = wfGetDB( DB_SLAVE );
684 $dbrWatchlist = wfGetDB( DB_SLAVE, 'watchlist' );
686 $setOpts += Database::getCacheSetOptions( $dbr, $dbrWatchlist );
688 $result = array();
690 // Number of page watchers
691 $watchers = (int)$dbrWatchlist->selectField(
692 'watchlist',
693 'COUNT(*)',
694 array(
695 'wl_namespace' => $title->getNamespace(),
696 'wl_title' => $title->getDBkey(),
698 $fname
700 $result['watchers'] = $watchers;
702 if ( $config->get( 'ShowUpdatedMarker' ) ) {
703 // Threshold: last visited about 26 weeks before latest edit
704 $updated = wfTimestamp( TS_UNIX, $page->getTimestamp() );
705 $age = $config->get( 'WatchersMaxAge' );
706 $threshold = $dbrWatchlist->timestamp( $updated - $age );
707 // Number of page watchers who also visited a "recent" edit
708 $visitingWatchers = (int)$dbrWatchlist->selectField(
709 'watchlist',
710 'COUNT(*)',
711 array(
712 'wl_namespace' => $title->getNamespace(),
713 'wl_title' => $title->getDBkey(),
714 'wl_notificationtimestamp >= ' .
715 $dbrWatchlist->addQuotes( $threshold ) .
716 ' OR wl_notificationtimestamp IS NULL'
718 $fname
720 $result['visitingWatchers'] = $visitingWatchers;
723 // Total number of edits
724 $edits = (int)$dbr->selectField(
725 'revision',
726 'COUNT(*)',
727 array( 'rev_page' => $id ),
728 $fname
730 $result['edits'] = $edits;
732 // Total number of distinct authors
733 if ( $config->get( 'MiserMode' ) ) {
734 $result['authors'] = 0;
735 } else {
736 $result['authors'] = (int)$dbr->selectField(
737 'revision',
738 'COUNT(DISTINCT rev_user_text)',
739 array( 'rev_page' => $id ),
740 $fname
744 // "Recent" threshold defined by RCMaxAge setting
745 $threshold = $dbr->timestamp( time() - $config->get( 'RCMaxAge' ) );
747 // Recent number of edits
748 $edits = (int)$dbr->selectField(
749 'revision',
750 'COUNT(rev_page)',
751 array(
752 'rev_page' => $id,
753 "rev_timestamp >= " . $dbr->addQuotes( $threshold )
755 $fname
757 $result['recent_edits'] = $edits;
759 // Recent number of distinct authors
760 $result['recent_authors'] = (int)$dbr->selectField(
761 'revision',
762 'COUNT(DISTINCT rev_user_text)',
763 array(
764 'rev_page' => $id,
765 "rev_timestamp >= " . $dbr->addQuotes( $threshold )
767 $fname
770 // Subpages (if enabled)
771 if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) {
772 $conds = array( 'page_namespace' => $title->getNamespace() );
773 $conds[] = 'page_title ' .
774 $dbr->buildLike( $title->getDBkey() . '/', $dbr->anyString() );
776 // Subpages of this page (redirects)
777 $conds['page_is_redirect'] = 1;
778 $result['subpages']['redirects'] = (int)$dbr->selectField(
779 'page',
780 'COUNT(page_id)',
781 $conds,
782 $fname
785 // Subpages of this page (non-redirects)
786 $conds['page_is_redirect'] = 0;
787 $result['subpages']['nonredirects'] = (int)$dbr->selectField(
788 'page',
789 'COUNT(page_id)',
790 $conds,
791 $fname
794 // Subpages of this page (total)
795 $result['subpages']['total'] = $result['subpages']['redirects']
796 + $result['subpages']['nonredirects'];
799 // Counts for the number of transclusion links (to/from)
800 if ( $config->get( 'MiserMode' ) ) {
801 $result['transclusion']['to'] = 0;
802 } else {
803 $result['transclusion']['to'] = (int)$dbr->selectField(
804 'templatelinks',
805 'COUNT(tl_from)',
806 array(
807 'tl_namespace' => $title->getNamespace(),
808 'tl_title' => $title->getDBkey()
810 $fname
814 $result['transclusion']['from'] = (int)$dbr->selectField(
815 'templatelinks',
816 'COUNT(*)',
817 array( 'tl_from' => $title->getArticleID() ),
818 $fname
821 return $result;
827 * Returns the name that goes in the "<h1>" page title.
829 * @return string
831 protected function getPageTitle() {
832 return $this->msg( 'pageinfo-title', $this->getTitle()->getPrefixedText() )->text();
836 * Get a list of contributors of $article
837 * @return string Html
839 protected function getContributors() {
840 $contributors = $this->page->getContributors();
841 $real_names = array();
842 $user_names = array();
843 $anon_ips = array();
845 # Sift for real versus user names
846 /** @var $user User */
847 foreach ( $contributors as $user ) {
848 $page = $user->isAnon()
849 ? SpecialPage::getTitleFor( 'Contributions', $user->getName() )
850 : $user->getUserPage();
852 $hiddenPrefs = $this->context->getConfig()->get( 'HiddenPrefs' );
853 if ( $user->getID() == 0 ) {
854 $anon_ips[] = Linker::link( $page, htmlspecialchars( $user->getName() ) );
855 } elseif ( !in_array( 'realname', $hiddenPrefs ) && $user->getRealName() ) {
856 $real_names[] = Linker::link( $page, htmlspecialchars( $user->getRealName() ) );
857 } else {
858 $user_names[] = Linker::link( $page, htmlspecialchars( $user->getName() ) );
862 $lang = $this->getLanguage();
864 $real = $lang->listToText( $real_names );
866 # "ThisSite user(s) A, B and C"
867 if ( count( $user_names ) ) {
868 $user = $this->msg( 'siteusers' )
869 ->rawParams( $lang->listToText( $user_names ) )
870 ->params( count( $user_names ) )->escaped();
871 } else {
872 $user = false;
875 if ( count( $anon_ips ) ) {
876 $anon = $this->msg( 'anonusers' )
877 ->rawParams( $lang->listToText( $anon_ips ) )
878 ->params( count( $anon_ips ) )->escaped();
879 } else {
880 $anon = false;
883 # This is the big list, all mooshed together. We sift for blank strings
884 $fulllist = array();
885 foreach ( array( $real, $user, $anon ) as $s ) {
886 if ( $s !== '' ) {
887 array_push( $fulllist, $s );
891 $count = count( $fulllist );
893 # "Based on work by ..."
894 return $count
895 ? $this->msg( 'othercontribs' )->rawParams(
896 $lang->listToText( $fulllist ) )->params( $count )->escaped()
897 : '';
901 * Returns the description that goes below the "<h1>" tag.
903 * @return string
905 protected function getDescription() {
906 return '';
910 * @param Title $title
911 * @param int $revId
912 * @return string
914 protected static function getCacheKey( Title $title, $revId ) {
915 return wfMemcKey( 'infoaction', md5( $title->getPrefixedText() ), $revId, self::VERSION );