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