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