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