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