Merge "Update Chechen language namespace names from translatewiki"
[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 // Give grep a chance to find the usages:
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 // Give grep a chance to find the usages: pageinfo-robot-index, pageinfo-robot-noindex
285 $pageInfo['header-basic'][] = array(
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 // Give grep a chance to find the usages:
401 // protect-level-autoconfirmed, protect-level-sysop
402 $message = $this->msg( "protect-level-$protectionLevel" );
403 if ( $message->isDisabled() ) {
404 // Require "$1" permission
405 $message = $this->msg( "protect-fallback", $protectionLevel )->parse();
406 } else {
407 $message = $message->escaped();
408 }
409 }
410
411 // Give grep a chance to find the usages:
412 // restriction-edit, restriction-move, restriction-create, restriction-upload
413 $pageInfo['header-restrictions'][] = array(
414 $this->msg( "restriction-$restrictionType" ), $message
415 );
416 }
417
418 if ( !$this->page->exists() ) {
419 return $pageInfo;
420 }
421
422 // Edit history
423 $pageInfo['header-edits'] = array();
424
425 $firstRev = $this->page->getOldestRevision();
426 $lastRev = $this->page->getRevision();
427 $batch = new LinkBatch;
428
429 if ( $firstRev ) {
430 $firstRevUser = $firstRev->getUserText( Revision::FOR_THIS_USER );
431 if ( $firstRevUser !== '' ) {
432 $batch->add( NS_USER, $firstRevUser );
433 $batch->add( NS_USER_TALK, $firstRevUser );
434 }
435 }
436
437 if ( $lastRev ) {
438 $lastRevUser = $lastRev->getUserText( Revision::FOR_THIS_USER );
439 if ( $lastRevUser !== '' ) {
440 $batch->add( NS_USER, $lastRevUser );
441 $batch->add( NS_USER_TALK, $lastRevUser );
442 }
443 }
444
445 $batch->execute();
446
447 if ( $firstRev ) {
448 // Page creator
449 $pageInfo['header-edits'][] = array(
450 $this->msg( 'pageinfo-firstuser' ),
451 Linker::revUserTools( $firstRev )
452 );
453
454 // Date of page creation
455 $pageInfo['header-edits'][] = array(
456 $this->msg( 'pageinfo-firsttime' ),
457 Linker::linkKnown(
458 $title,
459 $lang->userTimeAndDate( $firstRev->getTimestamp(), $user ),
460 array(),
461 array( 'oldid' => $firstRev->getId() )
462 )
463 );
464 }
465
466 if ( $lastRev ) {
467 // Latest editor
468 $pageInfo['header-edits'][] = array(
469 $this->msg( 'pageinfo-lastuser' ),
470 Linker::revUserTools( $lastRev )
471 );
472
473 // Date of latest edit
474 $pageInfo['header-edits'][] = array(
475 $this->msg( 'pageinfo-lasttime' ),
476 Linker::linkKnown(
477 $title,
478 $lang->userTimeAndDate( $this->page->getTimestamp(), $user ),
479 array(),
480 array( 'oldid' => $this->page->getLatest() )
481 )
482 );
483 }
484
485 // Total number of edits
486 $pageInfo['header-edits'][] = array(
487 $this->msg( 'pageinfo-edits' ), $lang->formatNum( $pageCounts['edits'] )
488 );
489
490 // Total number of distinct authors
491 $pageInfo['header-edits'][] = array(
492 $this->msg( 'pageinfo-authors' ), $lang->formatNum( $pageCounts['authors'] )
493 );
494
495 // Recent number of edits (within past 30 days)
496 $pageInfo['header-edits'][] = array(
497 $this->msg( 'pageinfo-recent-edits', $lang->formatDuration( $wgRCMaxAge ) ),
498 $lang->formatNum( $pageCounts['recent_edits'] )
499 );
500
501 // Recent number of distinct authors
502 $pageInfo['header-edits'][] = array(
503 $this->msg( 'pageinfo-recent-authors' ), $lang->formatNum( $pageCounts['recent_authors'] )
504 );
505
506 // Array of MagicWord objects
507 $magicWords = MagicWord::getDoubleUnderscoreArray();
508
509 // Array of magic word IDs
510 $wordIDs = $magicWords->names;
511
512 // Array of IDs => localized magic words
513 $localizedWords = $wgContLang->getMagicWords();
514
515 $listItems = array();
516 foreach ( $pageProperties as $property => $value ) {
517 if ( in_array( $property, $wordIDs ) ) {
518 $listItems[] = Html::element( 'li', array(), $localizedWords[$property][1] );
519 }
520 }
521
522 $localizedList = Html::rawElement( 'ul', array(), implode( '', $listItems ) );
523 $hiddenCategories = $this->page->getHiddenCategories();
524
525 if (
526 count( $listItems ) > 0 ||
527 count( $hiddenCategories ) > 0 ||
528 $pageCounts['transclusion']['from'] > 0 ||
529 $pageCounts['transclusion']['to'] > 0
530 ) {
531 $options = array( 'LIMIT' => $wgPageInfoTransclusionLimit );
532 $transcludedTemplates = $title->getTemplateLinksFrom( $options );
533 $transcludedTargets = $title->getTemplateLinksTo( $options );
534
535 // Page properties
536 $pageInfo['header-properties'] = array();
537
538 // Magic words
539 if ( count( $listItems ) > 0 ) {
540 $pageInfo['header-properties'][] = array(
541 $this->msg( 'pageinfo-magic-words' )->numParams( count( $listItems ) ),
542 $localizedList
543 );
544 }
545
546 // Hidden categories
547 if ( count( $hiddenCategories ) > 0 ) {
548 $pageInfo['header-properties'][] = array(
549 $this->msg( 'pageinfo-hidden-categories' )
550 ->numParams( count( $hiddenCategories ) ),
551 Linker::formatHiddenCategories( $hiddenCategories )
552 );
553 }
554
555 // Transcluded templates
556 if ( $pageCounts['transclusion']['from'] > 0 ) {
557 if ( $pageCounts['transclusion']['from'] > count( $transcludedTemplates ) ) {
558 $more = $this->msg( 'morenotlisted' )->escaped();
559 } else {
560 $more = null;
561 }
562
563 $pageInfo['header-properties'][] = array(
564 $this->msg( 'pageinfo-templates' )
565 ->numParams( $pageCounts['transclusion']['from'] ),
566 Linker::formatTemplates(
567 $transcludedTemplates,
568 false,
569 false,
570 $more )
571 );
572 }
573
574 if ( $pageCounts['transclusion']['to'] > 0 ) {
575 if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) {
576 $more = Linker::link(
577 $whatLinksHere,
578 $this->msg( 'moredotdotdot' )->escaped(),
579 array(),
580 array( 'hidelinks' => 1, 'hideredirs' => 1 )
581 );
582 } else {
583 $more = null;
584 }
585
586 $pageInfo['header-properties'][] = array(
587 $this->msg( 'pageinfo-transclusions' )
588 ->numParams( $pageCounts['transclusion']['to'] ),
589 Linker::formatTemplates(
590 $transcludedTargets,
591 false,
592 false,
593 $more )
594 );
595 }
596 }
597
598 return $pageInfo;
599 }
600
601 /**
602 * Returns page counts that would be too "expensive" to retrieve by normal means.
603 *
604 * @param Title $title Title to get counts for
605 * @return array
606 */
607 protected static function pageCounts( Title $title ) {
608 global $wgRCMaxAge, $wgDisableCounters;
609
610 wfProfileIn( __METHOD__ );
611 $id = $title->getArticleID();
612
613 $dbr = wfGetDB( DB_SLAVE );
614 $result = array();
615
616 if ( !$wgDisableCounters ) {
617 // Number of views
618 $views = (int) $dbr->selectField(
619 'page',
620 'page_counter',
621 array( 'page_id' => $id ),
622 __METHOD__
623 );
624 $result['views'] = $views;
625 }
626
627 // Number of page watchers
628 $watchers = (int) $dbr->selectField(
629 'watchlist',
630 'COUNT(*)',
631 array(
632 'wl_namespace' => $title->getNamespace(),
633 'wl_title' => $title->getDBkey(),
634 ),
635 __METHOD__
636 );
637 $result['watchers'] = $watchers;
638
639 // Total number of edits
640 $edits = (int) $dbr->selectField(
641 'revision',
642 'COUNT(rev_page)',
643 array( 'rev_page' => $id ),
644 __METHOD__
645 );
646 $result['edits'] = $edits;
647
648 // Total number of distinct authors
649 $authors = (int) $dbr->selectField(
650 'revision',
651 'COUNT(DISTINCT rev_user_text)',
652 array( 'rev_page' => $id ),
653 __METHOD__
654 );
655 $result['authors'] = $authors;
656
657 // "Recent" threshold defined by $wgRCMaxAge
658 $threshold = $dbr->timestamp( time() - $wgRCMaxAge );
659
660 // Recent number of edits
661 $edits = (int) $dbr->selectField(
662 'revision',
663 'COUNT(rev_page)',
664 array(
665 'rev_page' => $id,
666 "rev_timestamp >= " . $dbr->addQuotes( $threshold )
667 ),
668 __METHOD__
669 );
670 $result['recent_edits'] = $edits;
671
672 // Recent number of distinct authors
673 $authors = (int) $dbr->selectField(
674 'revision',
675 'COUNT(DISTINCT rev_user_text)',
676 array(
677 'rev_page' => $id,
678 "rev_timestamp >= " . $dbr->addQuotes( $threshold )
679 ),
680 __METHOD__
681 );
682 $result['recent_authors'] = $authors;
683
684 // Subpages (if enabled)
685 if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) {
686 $conds = array( 'page_namespace' => $title->getNamespace() );
687 $conds[] = 'page_title ' . $dbr->buildLike( $title->getDBkey() . '/', $dbr->anyString() );
688
689 // Subpages of this page (redirects)
690 $conds['page_is_redirect'] = 1;
691 $result['subpages']['redirects'] = (int) $dbr->selectField(
692 'page',
693 'COUNT(page_id)',
694 $conds,
695 __METHOD__ );
696
697 // Subpages of this page (non-redirects)
698 $conds['page_is_redirect'] = 0;
699 $result['subpages']['nonredirects'] = (int) $dbr->selectField(
700 'page',
701 'COUNT(page_id)',
702 $conds,
703 __METHOD__
704 );
705
706 // Subpages of this page (total)
707 $result['subpages']['total'] = $result['subpages']['redirects']
708 + $result['subpages']['nonredirects'];
709 }
710
711 // Counts for the number of transclusion links (to/from)
712 $result['transclusion']['to'] = (int) $dbr->selectField(
713 'templatelinks',
714 'COUNT(tl_from)',
715 array(
716 'tl_namespace' => $title->getNamespace(),
717 'tl_title' => $title->getDBkey()
718 ),
719 __METHOD__
720 );
721
722 $result['transclusion']['from'] = (int) $dbr->selectField(
723 'templatelinks',
724 'COUNT(*)',
725 array( 'tl_from' => $title->getArticleID() ),
726 __METHOD__
727 );
728
729 wfProfileOut( __METHOD__ );
730 return $result;
731 }
732
733 /**
734 * Returns the name that goes in the "<h1>" page title.
735 *
736 * @return string
737 */
738 protected function getPageTitle() {
739 return $this->msg( 'pageinfo-title', $this->getTitle()->getPrefixedText() )->text();
740 }
741
742 /**
743 * Get a list of contributors of $article
744 * @return string: html
745 */
746 protected function getContributors() {
747 global $wgHiddenPrefs;
748
749 $contributors = $this->page->getContributors();
750 $real_names = array();
751 $user_names = array();
752 $anon_ips = array();
753
754 # Sift for real versus user names
755 foreach ( $contributors as $user ) {
756 $page = $user->isAnon()
757 ? SpecialPage::getTitleFor( 'Contributions', $user->getName() )
758 : $user->getUserPage();
759
760 if ( $user->getID() == 0 ) {
761 $anon_ips[] = Linker::link( $page, htmlspecialchars( $user->getName() ) );
762 } elseif ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
763 $real_names[] = Linker::link( $page, htmlspecialchars( $user->getRealName() ) );
764 } else {
765 $user_names[] = Linker::link( $page, htmlspecialchars( $user->getName() ) );
766 }
767 }
768
769 $lang = $this->getLanguage();
770
771 $real = $lang->listToText( $real_names );
772
773 # "ThisSite user(s) A, B and C"
774 if ( count( $user_names ) ) {
775 $user = $this->msg( 'siteusers' )->rawParams( $lang->listToText( $user_names ) )->params(
776 count( $user_names ) )->escaped();
777 } else {
778 $user = false;
779 }
780
781 if ( count( $anon_ips ) ) {
782 $anon = $this->msg( 'anonusers' )->rawParams( $lang->listToText( $anon_ips ) )->params(
783 count( $anon_ips ) )->escaped();
784 } else {
785 $anon = false;
786 }
787
788 # This is the big list, all mooshed together. We sift for blank strings
789 $fulllist = array();
790 foreach ( array( $real, $user, $anon ) as $s ) {
791 if ( $s !== '' ) {
792 array_push( $fulllist, $s );
793 }
794 }
795
796 $count = count( $fulllist );
797 # "Based on work by ..."
798 return $count
799 ? $this->msg( 'othercontribs' )->rawParams(
800 $lang->listToText( $fulllist ) )->params( $count )->escaped()
801 : '';
802 }
803
804 /**
805 * Returns the description that goes below the "<h1>" tag.
806 *
807 * @return string
808 */
809 protected function getDescription() {
810 return '';
811 }
812 }