r108281 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108280‎ | r108281 | r108282 >
Date:20:26, 6 January 2012
Author:ialex
Status:ok
Tags:
Comment:
Revert r105790 and move back view counter back to WikiPage with two modifications:
* WikiPage::$mCounter is now marked as protected
* Call WikiPage::loadPageData() from WikiPage::getCount() if the count is not set intead of loading the page_counter field only
Modified paths:
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/WikiPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Title.php
@@ -63,7 +63,6 @@
6464 var $mFragment; // /< Title fragment (i.e. the bit after the #)
6565 var $mArticleID = -1; // /< Article ID, fetched from the link cache on demand
6666 var $mLatestID = false; // /< ID of most recent revision
67 - var $mCounter = -1; // /< Number of times this page has been viewed (-1 means "not loaded")
6867 private $mEstimateRevisions; // /< Estimated number of revisions; null of not loaded
6968 var $mRestrictions = array(); // /< Array of groups allowed to edit this article
7069 var $mOldRestrictions = false;
@@ -274,14 +273,11 @@
275274 $this->mRedirect = (bool)$row->page_is_redirect;
276275 if ( isset( $row->page_latest ) )
277276 $this->mLatestID = (int)$row->page_latest;
278 - if ( isset( $row->page_counter ) )
279 - $this->mCounter = (int)$row->page_counter;
280277 } else { // page not found
281278 $this->mArticleID = 0;
282279 $this->mLength = 0;
283280 $this->mRedirect = false;
284281 $this->mLatestID = 0;
285 - $this->mCounter = 0;
286282 }
287283 }
288284
@@ -2758,28 +2754,6 @@
27592755 }
27602756
27612757 /**
2762 - * Get the number of views of this page
2763 - *
2764 - * @return int The view count for the page
2765 - */
2766 - public function getCount() {
2767 - if ( $this->mCounter == -1 ) {
2768 - if ( $this->exists() ) {
2769 - $dbr = wfGetDB( DB_SLAVE );
2770 - $this->mCounter = $dbr->selectField( 'page',
2771 - 'page_counter',
2772 - array( 'page_id' => $this->getArticleID() ),
2773 - __METHOD__
2774 - );
2775 - } else {
2776 - $this->mCounter = 0;
2777 - }
2778 - }
2779 -
2780 - return $this->mCounter;
2781 - }
2782 -
2783 - /**
27842758 * Get the article ID for this Title from the link cache,
27852759 * adding it if necessary
27862760 *
@@ -2891,7 +2865,6 @@
28922866 $this->mRedirect = null;
28932867 $this->mLength = -1;
28942868 $this->mLatestID = false;
2895 - $this->mCounter = -1;
28962869 $this->mEstimateRevisions = null;
28972870 }
28982871
Index: trunk/phase3/includes/SkinTemplate.php
@@ -318,7 +318,7 @@
319319 if ( $out->isArticle() && $title->exists() ) {
320320 if ( $this->isRevisionCurrent() ) {
321321 if ( !$wgDisableCounters ) {
322 - $viewcount = $title->getCount();
 322+ $viewcount = $this->getWikiPage()->getCount();
323323 if ( $viewcount ) {
324324 $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
325325 }
@@ -338,7 +338,7 @@
339339 }
340340
341341 if ( $wgMaxCredits != 0 ) {
342 - $tpl->set( 'credits', Action::factory( 'credits', WikiPage::factory( $title ),
 342+ $tpl->set( 'credits', Action::factory( 'credits', $this->getWikiPage(),
343343 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
344344 } else {
345345 $tpl->set( 'lastmod', $this->lastModified() );
Index: trunk/phase3/includes/WikiPage.php
@@ -48,6 +48,11 @@
4949 protected $mTouched = '19700101000000';
5050
5151 /**
 52+ * @var int|null
 53+ */
 54+ protected $mCounter = null;
 55+
 56+ /**
5257 * Constructor and clear the article
5358 * @param $title Title Reference to a Title object.
5459 */
@@ -246,6 +251,7 @@
247252 public function clear() {
248253 $this->mDataLoaded = false;
249254
 255+ $this->mCounter = null;
250256 $this->mRedirectTarget = null; # Title object if set
251257 $this->mLastRevision = null; # Latest revision
252258 $this->mTouched = '19700101000000';
@@ -385,6 +391,7 @@
386392 # Old-fashioned restrictions
387393 $this->mTitle->loadRestrictions( $data->page_restrictions );
388394
 395+ $this->mCounter = intval( $data->page_counter );
389396 $this->mTouched = wfTimestamp( TS_MW, $data->page_touched );
390397 $this->mIsRedirect = intval( $data->page_is_redirect );
391398 $this->mLatest = intval( $data->page_latest );
@@ -424,12 +431,14 @@
425432 }
426433
427434 /**
428 - * Get the number of views of this page
429 - *
430435 * @return int The view count for the page
431436 */
432437 public function getCount() {
433 - return $this->mTitle->getCount();
 438+ if ( !$this->mDataLoaded ) {
 439+ $this->loadPageData();
 440+ }
 441+
 442+ return $this->mCounter;
434443 }
435444
436445 /**

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r105790Moved view count from WikiPage to Title; avoids an extra DB query when showin...ialex11:30, 11 December 2011

Status & tagging log