[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/actions/ -> InfoAction.php (source)

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


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1