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