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