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