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