Added autopatrol parameter to MarkPatrolled and MarkPatrolledComplete hooks
[lhc/web/wiklou.git] / includes / actions / InfoAction.php
1 <?php
2 /**
3 * Displays information about a page.
4 *
5 * Copyright © 2011 Alexandre Emsenhuber
6 *
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.
11 *
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.
16 *
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
20 *
21 * @file
22 * @ingroup Actions
23 */
24
25 /**
26 * Displays information about a page.
27 *
28 * @ingroup Actions
29 */
30 class InfoAction extends FormlessAction {
31 const VERSION = 1;
32
33 /**
34 * Returns the name of the action this object responds to.
35 *
36 * @return string Lowercase name
37 */
38 public function getName() {
39 return 'info';
40 }
41
42 /**
43 * Whether this action can still be executed by a blocked user.
44 *
45 * @return bool
46 */
47 public function requiresUnblock() {
48 return false;
49 }
50
51 /**
52 * Whether this action requires the wiki not to be locked.
53 *
54 * @return bool
55 */
56 public function requiresWrite() {
57 return false;
58 }
59
60 /**
61 * Clear the info cache for a given Title.
62 *
63 * @since 1.22
64 * @param Title $title Title to clear cache for
65 * @param int|null $revid Revision id to clear
66 */
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;
71 }
72 if ( $revid !== null ) {
73 $key = self::getCacheKey( $title, $revid );
74 ObjectCache::getMainWANInstance()->delete( $key );
75 }
76 }
77
78 /**
79 * Shows page information on GET request.
80 *
81 * @return string Page information that will be added to the output
82 */
83 public function onView() {
84 $content = '';
85
86 // Validate revision
87 $oldid = $this->page->getOldID();
88 if ( $oldid ) {
89 $revision = $this->page->getRevisionFetched();
90
91 // Revision is missing
92 if ( $revision === null ) {
93 return $this->msg( 'missing-revision', $oldid )->parse();
94 }
95
96 // Revision is not current
97 if ( !$revision->isCurrent() ) {
98 return $this->msg( 'pageinfo-not-current' )->plain();
99 }
100 }
101
102 // Page header
103 if ( !$this->msg( 'pageinfo-header' )->isDisabled() ) {
104 $content .= $this->msg( 'pageinfo-header' )->parse();
105 }
106
107 // Hide "This page is a member of # hidden categories" explanation
108 $content .= Html::element( 'style', array(),
109 '.mw-hiddenCategoriesExplanation { display: none; }' ) . "\n";
110
111 // Hide "Templates used on this page" explanation
112 $content .= Html::element( 'style', array(),
113 '.mw-templatesUsedExplanation { display: none; }' ) . "\n";
114
115 // Get page information
116 $pageInfo = $this->pageInfo();
117
118 // Allow extensions to add additional information
119 Hooks::run( 'InfoAction', array( $this->getContext(), &$pageInfo ) );
120
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";
133 }
134 $content = $this->addTable( $content, $table ) . "\n";
135 }
136
137 // Page footer
138 if ( !$this->msg( 'pageinfo-footer' )->isDisabled() ) {
139 $content .= $this->msg( 'pageinfo-footer' )->parse();
140 }
141
142 // Page credits
143 /*if ( $this->page->exists() ) {
144 $content .= Html::rawElement( 'div', array( 'id' => 'mw-credits' ), $this->getContributors() );
145 }*/
146
147 return $content;
148 }
149
150 /**
151 * Creates a header that can be added to the output.
152 *
153 * @param string $header The header text.
154 * @return string The HTML.
155 */
156 protected function makeHeader( $header ) {
157 $spanAttribs = array( 'class' => 'mw-headline', 'id' => Sanitizer::escapeId( $header ) );
158
159 return Html::rawElement( 'h2', array(), Html::element( 'span', $spanAttribs, $header ) );
160 }
161
162 /**
163 * Adds a row to a table that will be added to the content.
164 *
165 * @param string $table The table that will be added to the content
166 * @param string $name The name of the row
167 * @param string $value The value of the row
168 * @param string $id The ID to use for the 'tr' element
169 * @return string The table with the row added
170 */
171 protected function addRow( $table, $name, $value, $id ) {
172 return $table . Html::rawElement( 'tr', $id === null ? array() : array( 'id' => 'mw-' . $id ),
173 Html::rawElement( 'td', array( 'style' => 'vertical-align: top;' ), $name ) .
174 Html::rawElement( 'td', array(), $value )
175 );
176 }
177
178 /**
179 * Adds a table to the content that will be added to the output.
180 *
181 * @param string $content The content that will be added to the output
182 * @param string $table The table
183 * @return string The content with the table added
184 */
185 protected function addTable( $content, $table ) {
186 return $content . Html::rawElement( 'table', array( 'class' => 'wikitable mw-page-info' ),
187 $table );
188 }
189
190 /**
191 * Returns page information in an easily-manipulated format. Array keys are used so extensions
192 * may add additional information in arbitrary positions. Array values are arrays with one
193 * element to be rendered as a header, arrays with two elements to be rendered as a table row.
194 *
195 * @return array
196 */
197 protected function pageInfo() {
198 global $wgContLang;
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 // Get page properties
209 $dbr = wfGetDB( DB_SLAVE );
210 $result = $dbr->select(
211 'page_props',
212 array( 'pp_propname', 'pp_value' ),
213 array( 'pp_page' => $id ),
214 __METHOD__
215 );
216
217 $pageProperties = array();
218 foreach ( $result as $row ) {
219 $pageProperties[$row->pp_propname] = $row->pp_value;
220 }
221
222 // Basic information
223 $pageInfo = array();
224 $pageInfo['header-basic'] = array();
225
226 // Display title
227 $displayTitle = $title->getPrefixedText();
228 if ( isset( $pageProperties['displaytitle'] ) ) {
229 $displayTitle = $pageProperties['displaytitle'];
230 }
231
232 $pageInfo['header-basic'][] = array(
233 $this->msg( 'pageinfo-display-title' ), $displayTitle
234 );
235
236 // Is it a redirect? If so, where to?
237 if ( $title->isRedirect() ) {
238 $pageInfo['header-basic'][] = array(
239 $this->msg( 'pageinfo-redirectsto' ),
240 Linker::link( $this->page->getRedirectTarget() ) .
241 $this->msg( 'word-separator' )->escaped() .
242 $this->msg( 'parentheses' )->rawParams( Linker::link(
243 $this->page->getRedirectTarget(),
244 $this->msg( 'pageinfo-redirectsto-info' )->escaped(),
245 array(),
246 array( 'action' => 'info' )
247 ) )->escaped()
248 );
249 }
250
251 // Default sort key
252 $sortKey = $title->getCategorySortkey();
253 if ( isset( $pageProperties['defaultsort'] ) ) {
254 $sortKey = $pageProperties['defaultsort'];
255 }
256
257 $sortKey = htmlspecialchars( $sortKey );
258 $pageInfo['header-basic'][] = array( $this->msg( 'pageinfo-default-sort' ), $sortKey );
259
260 // Page length (in bytes)
261 $pageInfo['header-basic'][] = array(
262 $this->msg( 'pageinfo-length' ), $lang->formatNum( $title->getLength() )
263 );
264
265 // Page ID (number not localised, as it's a database ID)
266 $pageInfo['header-basic'][] = array( $this->msg( 'pageinfo-article-id' ), $id );
267
268 // Language in which the page content is (supposed to be) written
269 $pageLang = $title->getPageLanguage()->getCode();
270
271 if ( $config->get( 'PageLanguageUseDB' )
272 && $this->getTitle()->userCan( 'pagelang', $this->getUser() )
273 ) {
274 // Link to Special:PageLanguage with pre-filled page title if user has permissions
275 $titleObj = SpecialPage::getTitleFor( 'PageLanguage', $title->getPrefixedText() );
276 $langDisp = Linker::link(
277 $titleObj,
278 $this->msg( 'pageinfo-language' )->escaped()
279 );
280 } else {
281 // Display just the message
282 $langDisp = $this->msg( 'pageinfo-language' )->escaped();
283 }
284
285 $pageInfo['header-basic'][] = array( $langDisp,
286 Language::fetchLanguageName( $pageLang, $lang->getCode() )
287 . ' ' . $this->msg( 'parentheses', $pageLang )->escaped() );
288
289 // Content model of the page
290 $pageInfo['header-basic'][] = array(
291 $this->msg( 'pageinfo-content-model' ),
292 htmlspecialchars( ContentHandler::getLocalizedName( $title->getContentModel() ) )
293 );
294
295 // Search engine status
296 $pOutput = new ParserOutput();
297 if ( isset( $pageProperties['noindex'] ) ) {
298 $pOutput->setIndexPolicy( 'noindex' );
299 }
300 if ( isset( $pageProperties['index'] ) ) {
301 $pOutput->setIndexPolicy( 'index' );
302 }
303
304 // Use robot policy logic
305 $policy = $this->page->getRobotPolicy( 'view', $pOutput );
306 $pageInfo['header-basic'][] = array(
307 // Messages: pageinfo-robot-index, pageinfo-robot-noindex
308 $this->msg( 'pageinfo-robot-policy' ), $this->msg( "pageinfo-robot-${policy['index']}" )
309 );
310
311 $unwatchedPageThreshold = $config->get( 'UnwatchedPageThreshold' );
312 if (
313 $user->isAllowed( 'unwatchedpages' ) ||
314 ( $unwatchedPageThreshold !== false &&
315 $pageCounts['watchers'] >= $unwatchedPageThreshold )
316 ) {
317 // Number of page watchers
318 $pageInfo['header-basic'][] = array(
319 $this->msg( 'pageinfo-watchers' ),
320 $lang->formatNum( $pageCounts['watchers'] )
321 );
322 if (
323 $config->get( 'ShowUpdatedMarker' ) &&
324 isset( $pageCounts['visitingWatchers'] )
325 ) {
326 $minToDisclose = $config->get( 'UnwatchedPageSecret' );
327 if ( $pageCounts['visitingWatchers'] > $minToDisclose ||
328 $user->isAllowed( 'unwatchedpages' ) ) {
329 $pageInfo['header-basic'][] = array(
330 $this->msg( 'pageinfo-visiting-watchers' ),
331 $lang->formatNum( $pageCounts['visitingWatchers'] )
332 );
333 } else {
334 $pageInfo['header-basic'][] = array(
335 $this->msg( 'pageinfo-visiting-watchers' ),
336 $this->msg( 'pageinfo-few-visiting-watchers' )
337 );
338 }
339 }
340 } elseif ( $unwatchedPageThreshold !== false ) {
341 $pageInfo['header-basic'][] = array(
342 $this->msg( 'pageinfo-watchers' ),
343 $this->msg( 'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold )
344 );
345 }
346
347 // Redirects to this page
348 $whatLinksHere = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
349 $pageInfo['header-basic'][] = array(
350 Linker::link(
351 $whatLinksHere,
352 $this->msg( 'pageinfo-redirects-name' )->escaped(),
353 array(),
354 array(
355 'hidelinks' => 1,
356 'hidetrans' => 1,
357 'hideimages' => $title->getNamespace() == NS_FILE
358 )
359 ),
360 $this->msg( 'pageinfo-redirects-value' )
361 ->numParams( count( $title->getRedirectsHere() ) )
362 );
363
364 // Is it counted as a content page?
365 if ( $this->page->isCountable() ) {
366 $pageInfo['header-basic'][] = array(
367 $this->msg( 'pageinfo-contentpage' ),
368 $this->msg( 'pageinfo-contentpage-yes' )
369 );
370 }
371
372 // Subpages of this page, if subpages are enabled for the current NS
373 if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) {
374 $prefixIndex = SpecialPage::getTitleFor( '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'] )
382 );
383 }
384
385 if ( $title->inNamespace( NS_CATEGORY ) ) {
386 $category = Category::newFromTitle( $title );
387
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;
394
395 $pageInfo['category-info'] = array(
396 array(
397 $this->msg( 'pageinfo-category-total' ),
398 $lang->formatNum( $allCount )
399 ),
400 array(
401 $this->msg( 'pageinfo-category-pages' ),
402 $lang->formatNum( $pagesCount )
403 ),
404 array(
405 $this->msg( 'pageinfo-category-subcats' ),
406 $lang->formatNum( $subcatCount )
407 ),
408 array(
409 $this->msg( 'pageinfo-category-files' ),
410 $lang->formatNum( $fileCount )
411 )
412 );
413 }
414
415 // Page protection
416 $pageInfo['header-restrictions'] = array();
417
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 :(
422
423 foreach ( $sources[0] as $sourceTitle ) {
424 $cascadingFrom .= Html::rawElement( 'li', array(), Linker::linkKnown( $sourceTitle ) );
425 }
426
427 $cascadingFrom = Html::rawElement( 'ul', array(), $cascadingFrom );
428 $pageInfo['header-restrictions'][] = array(
429 $this->msg( 'pageinfo-protect-cascading-from' ),
430 $cascadingFrom
431 );
432 }
433
434 // Is out protection set to cascade to other pages?
435 if ( $title->areRestrictionsCascading() ) {
436 $pageInfo['header-restrictions'][] = array(
437 $this->msg( 'pageinfo-protect-cascading' ),
438 $this->msg( 'pageinfo-protect-cascading-yes' )
439 );
440 }
441
442 // Page protection
443 foreach ( $title->getRestrictionTypes() as $restrictionType ) {
444 $protectionLevel = implode( ', ', $title->getRestrictions( $restrictionType ) );
445
446 if ( $protectionLevel == '' ) {
447 // Allow all users
448 $message = $this->msg( 'protect-default' )->escaped();
449 } else {
450 // Administrators only
451 // Messages: protect-level-autoconfirmed, protect-level-sysop
452 $message = $this->msg( "protect-level-$protectionLevel" );
453 if ( $message->isDisabled() ) {
454 // Require "$1" permission
455 $message = $this->msg( "protect-fallback", $protectionLevel )->parse();
456 } else {
457 $message = $message->escaped();
458 }
459 }
460 $expiry = $title->getRestrictionExpiry( $restrictionType );
461 $formattedexpiry = $this->msg( 'parentheses',
462 $this->getLanguage()->formatExpiry( $expiry ) )->escaped();
463 $message .= $this->msg( 'word-separator' )->escaped() . $formattedexpiry;
464
465 // Messages: restriction-edit, restriction-move, restriction-create,
466 // restriction-upload
467 $pageInfo['header-restrictions'][] = array(
468 $this->msg( "restriction-$restrictionType" ), $message
469 );
470 }
471
472 if ( !$this->page->exists() ) {
473 return $pageInfo;
474 }
475
476 // Edit history
477 $pageInfo['header-edits'] = array();
478
479 $firstRev = $this->page->getOldestRevision();
480 $lastRev = $this->page->getRevision();
481 $batch = new LinkBatch;
482
483 if ( $firstRev ) {
484 $firstRevUser = $firstRev->getUserText( Revision::FOR_THIS_USER );
485 if ( $firstRevUser !== '' ) {
486 $batch->add( NS_USER, $firstRevUser );
487 $batch->add( NS_USER_TALK, $firstRevUser );
488 }
489 }
490
491 if ( $lastRev ) {
492 $lastRevUser = $lastRev->getUserText( Revision::FOR_THIS_USER );
493 if ( $lastRevUser !== '' ) {
494 $batch->add( NS_USER, $lastRevUser );
495 $batch->add( NS_USER_TALK, $lastRevUser );
496 }
497 }
498
499 $batch->execute();
500
501 if ( $firstRev ) {
502 // Page creator
503 $pageInfo['header-edits'][] = array(
504 $this->msg( 'pageinfo-firstuser' ),
505 Linker::revUserTools( $firstRev )
506 );
507
508 // Date of page creation
509 $pageInfo['header-edits'][] = array(
510 $this->msg( 'pageinfo-firsttime' ),
511 Linker::linkKnown(
512 $title,
513 htmlspecialchars( $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ) ),
514 array(),
515 array( 'oldid' => $firstRev->getId() )
516 )
517 );
518 }
519
520 if ( $lastRev ) {
521 // Latest editor
522 $pageInfo['header-edits'][] = array(
523 $this->msg( 'pageinfo-lastuser' ),
524 Linker::revUserTools( $lastRev )
525 );
526
527 // Date of latest edit
528 $pageInfo['header-edits'][] = array(
529 $this->msg( 'pageinfo-lasttime' ),
530 Linker::linkKnown(
531 $title,
532 htmlspecialchars( $lang->userTimeAndDate( $this->page->getTimestamp(), $user ) ),
533 array(),
534 array( 'oldid' => $this->page->getLatest() )
535 )
536 );
537 }
538
539 // Total number of edits
540 $pageInfo['header-edits'][] = array(
541 $this->msg( 'pageinfo-edits' ), $lang->formatNum( $pageCounts['edits'] )
542 );
543
544 // Total number of distinct authors
545 if ( $pageCounts['authors'] > 0 ) {
546 $pageInfo['header-edits'][] = array(
547 $this->msg( 'pageinfo-authors' ), $lang->formatNum( $pageCounts['authors'] )
548 );
549 }
550
551 // Recent number of edits (within past 30 days)
552 $pageInfo['header-edits'][] = array(
553 $this->msg( 'pageinfo-recent-edits', $lang->formatDuration( $config->get( 'RCMaxAge' ) ) ),
554 $lang->formatNum( $pageCounts['recent_edits'] )
555 );
556
557 // Recent number of distinct authors
558 $pageInfo['header-edits'][] = array(
559 $this->msg( 'pageinfo-recent-authors' ), $lang->formatNum( $pageCounts['recent_authors'] )
560 );
561
562 // Array of MagicWord objects
563 $magicWords = MagicWord::getDoubleUnderscoreArray();
564
565 // Array of magic word IDs
566 $wordIDs = $magicWords->names;
567
568 // Array of IDs => localized magic words
569 $localizedWords = $wgContLang->getMagicWords();
570
571 $listItems = array();
572 foreach ( $pageProperties as $property => $value ) {
573 if ( in_array( $property, $wordIDs ) ) {
574 $listItems[] = Html::element( 'li', array(), $localizedWords[$property][1] );
575 }
576 }
577
578 $localizedList = Html::rawElement( 'ul', array(), implode( '', $listItems ) );
579 $hiddenCategories = $this->page->getHiddenCategories();
580
581 if (
582 count( $listItems ) > 0 ||
583 count( $hiddenCategories ) > 0 ||
584 $pageCounts['transclusion']['from'] > 0 ||
585 $pageCounts['transclusion']['to'] > 0
586 ) {
587 $options = array( 'LIMIT' => $config->get( 'PageInfoTransclusionLimit' ) );
588 $transcludedTemplates = $title->getTemplateLinksFrom( $options );
589 if ( $config->get( 'MiserMode' ) ) {
590 $transcludedTargets = array();
591 } else {
592 $transcludedTargets = $title->getTemplateLinksTo( $options );
593 }
594
595 // Page properties
596 $pageInfo['header-properties'] = array();
597
598 // Magic words
599 if ( count( $listItems ) > 0 ) {
600 $pageInfo['header-properties'][] = array(
601 $this->msg( 'pageinfo-magic-words' )->numParams( count( $listItems ) ),
602 $localizedList
603 );
604 }
605
606 // Hidden categories
607 if ( count( $hiddenCategories ) > 0 ) {
608 $pageInfo['header-properties'][] = array(
609 $this->msg( 'pageinfo-hidden-categories' )
610 ->numParams( count( $hiddenCategories ) ),
611 Linker::formatHiddenCategories( $hiddenCategories )
612 );
613 }
614
615 // Transcluded templates
616 if ( $pageCounts['transclusion']['from'] > 0 ) {
617 if ( $pageCounts['transclusion']['from'] > count( $transcludedTemplates ) ) {
618 $more = $this->msg( 'morenotlisted' )->escaped();
619 } else {
620 $more = null;
621 }
622
623 $pageInfo['header-properties'][] = array(
624 $this->msg( 'pageinfo-templates' )
625 ->numParams( $pageCounts['transclusion']['from'] ),
626 Linker::formatTemplates(
627 $transcludedTemplates,
628 false,
629 false,
630 $more )
631 );
632 }
633
634 if ( !$config->get( 'MiserMode' ) && $pageCounts['transclusion']['to'] > 0 ) {
635 if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) {
636 $more = Linker::link(
637 $whatLinksHere,
638 $this->msg( 'moredotdotdot' )->escaped(),
639 array(),
640 array( 'hidelinks' => 1, 'hideredirs' => 1 )
641 );
642 } else {
643 $more = null;
644 }
645
646 $pageInfo['header-properties'][] = array(
647 $this->msg( 'pageinfo-transclusions' )
648 ->numParams( $pageCounts['transclusion']['to'] ),
649 Linker::formatTemplates(
650 $transcludedTargets,
651 false,
652 false,
653 $more )
654 );
655 }
656 }
657
658 return $pageInfo;
659 }
660
661 /**
662 * Returns page counts that would be too "expensive" to retrieve by normal means.
663 *
664 * @param WikiPage|Article|Page $page
665 * @return array
666 */
667 protected function pageCounts( Page $page ) {
668 $fname = __METHOD__;
669 $config = $this->context->getConfig();
670
671 return ObjectCache::getMainWANInstance()->getWithSetCallback(
672 self::getCacheKey( $page->getTitle(), $page->getLatest() ),
673 function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
674 $title = $page->getTitle();
675 $id = $title->getArticleID();
676
677 $dbrWatchlist = wfGetDB( DB_SLAVE, 'watchlist' );
678 $result = array();
679
680 // Number of page watchers
681 $watchers = (int)$dbrWatchlist->selectField(
682 'watchlist',
683 'COUNT(*)',
684 array(
685 'wl_namespace' => $title->getNamespace(),
686 'wl_title' => $title->getDBkey(),
687 ),
688 $fname
689 );
690 $result['watchers'] = $watchers;
691
692 if ( $config->get( 'ShowUpdatedMarker' ) ) {
693 // Threshold: last visited about 26 weeks before latest edit
694 $updated = wfTimestamp( TS_UNIX, $page->getTimestamp() );
695 $age = $config->get( 'WatchersMaxAge' );
696 $threshold = $dbrWatchlist->timestamp( $updated - $age );
697 // Number of page watchers who also visited a "recent" edit
698 $visitingWatchers = (int)$dbrWatchlist->selectField(
699 'watchlist',
700 'COUNT(*)',
701 array(
702 'wl_namespace' => $title->getNamespace(),
703 'wl_title' => $title->getDBkey(),
704 'wl_notificationtimestamp >= ' . $dbrWatchlist->addQuotes( $threshold ) .
705 ' OR wl_notificationtimestamp IS NULL'
706 ),
707 $fname
708 );
709 $result['visitingWatchers'] = $visitingWatchers;
710 }
711
712 $dbr = wfGetDB( DB_SLAVE );
713 // Total number of edits
714 $edits = (int)$dbr->selectField(
715 'revision',
716 'COUNT(*)',
717 array( 'rev_page' => $id ),
718 $fname
719 );
720 $result['edits'] = $edits;
721
722 // Total number of distinct authors
723 if ( $config->get( 'MiserMode' ) ) {
724 $result['authors'] = 0;
725 } else {
726 $result['authors'] = (int)$dbr->selectField(
727 'revision',
728 'COUNT(DISTINCT rev_user_text)',
729 array( 'rev_page' => $id ),
730 $fname
731 );
732 }
733
734 // "Recent" threshold defined by RCMaxAge setting
735 $threshold = $dbr->timestamp( time() - $config->get( 'RCMaxAge' ) );
736
737 // Recent number of edits
738 $edits = (int)$dbr->selectField(
739 'revision',
740 'COUNT(rev_page)',
741 array(
742 'rev_page' => $id,
743 "rev_timestamp >= " . $dbr->addQuotes( $threshold )
744 ),
745 $fname
746 );
747 $result['recent_edits'] = $edits;
748
749 // Recent number of distinct authors
750 $result['recent_authors'] = (int)$dbr->selectField(
751 'revision',
752 'COUNT(DISTINCT rev_user_text)',
753 array(
754 'rev_page' => $id,
755 "rev_timestamp >= " . $dbr->addQuotes( $threshold )
756 ),
757 $fname
758 );
759
760 // Subpages (if enabled)
761 if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) {
762 $conds = array( 'page_namespace' => $title->getNamespace() );
763 $conds[] = 'page_title ' .
764 $dbr->buildLike( $title->getDBkey() . '/', $dbr->anyString() );
765
766 // Subpages of this page (redirects)
767 $conds['page_is_redirect'] = 1;
768 $result['subpages']['redirects'] = (int)$dbr->selectField(
769 'page',
770 'COUNT(page_id)',
771 $conds,
772 $fname
773 );
774
775 // Subpages of this page (non-redirects)
776 $conds['page_is_redirect'] = 0;
777 $result['subpages']['nonredirects'] = (int)$dbr->selectField(
778 'page',
779 'COUNT(page_id)',
780 $conds,
781 $fname
782 );
783
784 // Subpages of this page (total)
785 $result['subpages']['total'] = $result['subpages']['redirects']
786 + $result['subpages']['nonredirects'];
787 }
788
789 // Counts for the number of transclusion links (to/from)
790 if ( $config->get( 'MiserMode' ) ) {
791 $result['transclusion']['to'] = 0;
792 } else {
793 $result['transclusion']['to'] = (int)$dbr->selectField(
794 'templatelinks',
795 'COUNT(tl_from)',
796 array(
797 'tl_namespace' => $title->getNamespace(),
798 'tl_title' => $title->getDBkey()
799 ),
800 $fname
801 );
802 }
803
804 $result['transclusion']['from'] = (int)$dbr->selectField(
805 'templatelinks',
806 'COUNT(*)',
807 array( 'tl_from' => $title->getArticleID() ),
808 $fname
809 );
810
811 $setOpts = array( 'since' => $dbr->trxTimestamp() );
812
813 return $result;
814 },
815 86400 * 7
816 );
817 }
818
819 /**
820 * Returns the name that goes in the "<h1>" page title.
821 *
822 * @return string
823 */
824 protected function getPageTitle() {
825 return $this->msg( 'pageinfo-title', $this->getTitle()->getPrefixedText() )->text();
826 }
827
828 /**
829 * Get a list of contributors of $article
830 * @return string Html
831 */
832 protected function getContributors() {
833 $contributors = $this->page->getContributors();
834 $real_names = array();
835 $user_names = array();
836 $anon_ips = array();
837
838 # Sift for real versus user names
839 /** @var $user User */
840 foreach ( $contributors as $user ) {
841 $page = $user->isAnon()
842 ? SpecialPage::getTitleFor( 'Contributions', $user->getName() )
843 : $user->getUserPage();
844
845 $hiddenPrefs = $this->context->getConfig()->get( 'HiddenPrefs' );
846 if ( $user->getID() == 0 ) {
847 $anon_ips[] = Linker::link( $page, htmlspecialchars( $user->getName() ) );
848 } elseif ( !in_array( 'realname', $hiddenPrefs ) && $user->getRealName() ) {
849 $real_names[] = Linker::link( $page, htmlspecialchars( $user->getRealName() ) );
850 } else {
851 $user_names[] = Linker::link( $page, htmlspecialchars( $user->getName() ) );
852 }
853 }
854
855 $lang = $this->getLanguage();
856
857 $real = $lang->listToText( $real_names );
858
859 # "ThisSite user(s) A, B and C"
860 if ( count( $user_names ) ) {
861 $user = $this->msg( 'siteusers' )->rawParams( $lang->listToText( $user_names ) )->params(
862 count( $user_names ) )->escaped();
863 } else {
864 $user = false;
865 }
866
867 if ( count( $anon_ips ) ) {
868 $anon = $this->msg( 'anonusers' )->rawParams( $lang->listToText( $anon_ips ) )->params(
869 count( $anon_ips ) )->escaped();
870 } else {
871 $anon = false;
872 }
873
874 # This is the big list, all mooshed together. We sift for blank strings
875 $fulllist = array();
876 foreach ( array( $real, $user, $anon ) as $s ) {
877 if ( $s !== '' ) {
878 array_push( $fulllist, $s );
879 }
880 }
881
882 $count = count( $fulllist );
883
884 # "Based on work by ..."
885 return $count
886 ? $this->msg( 'othercontribs' )->rawParams(
887 $lang->listToText( $fulllist ) )->params( $count )->escaped()
888 : '';
889 }
890
891 /**
892 * Returns the description that goes below the "<h1>" tag.
893 *
894 * @return string
895 */
896 protected function getDescription() {
897 return '';
898 }
899
900 /**
901 * @param Title $title
902 * @param int $revId
903 * @return string
904 */
905 protected static function getCacheKey( Title $title, $revId ) {
906 return wfMemcKey( 'infoaction', md5( $title->getPrefixedText() ), $revId, self::VERSION );
907 }
908 }