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