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