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