https://www.mediawiki.org/wiki/Special:Code/MediaWiki/108281
Revision: 108281
Author: ialex
Date: 2012-01-06 20:26:53 +0000 (Fri, 06 Jan 2012)
Log Message:
-----------
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
trunk/phase3/includes/Title.php
trunk/phase3/includes/WikiPage.php
Modified: trunk/phase3/includes/SkinTemplate.php
===================================================================
--- trunk/phase3/includes/SkinTemplate.php 2012-01-06 20:26:28 UTC (rev
108280)
+++ trunk/phase3/includes/SkinTemplate.php 2012-01-06 20:26:53 UTC (rev
108281)
@@ -318,7 +318,7 @@
if ( $out->isArticle() && $title->exists() ) {
if ( $this->isRevisionCurrent() ) {
if ( !$wgDisableCounters ) {
- $viewcount = $title->getCount();
+ $viewcount =
$this->getWikiPage()->getCount();
if ( $viewcount ) {
$tpl->set( 'viewcount',
$this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
}
@@ -338,7 +338,7 @@
}
if ( $wgMaxCredits != 0 ) {
- $tpl->set( 'credits', Action::factory(
'credits', WikiPage::factory( $title ),
+ $tpl->set( 'credits', Action::factory(
'credits', $this->getWikiPage(),
$this->getContext()
)->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
} else {
$tpl->set( 'lastmod',
$this->lastModified() );
Modified: trunk/phase3/includes/Title.php
===================================================================
--- trunk/phase3/includes/Title.php 2012-01-06 20:26:28 UTC (rev 108280)
+++ trunk/phase3/includes/Title.php 2012-01-06 20:26:53 UTC (rev 108281)
@@ -63,7 +63,6 @@
var $mFragment; // /< Title fragment (i.e. the bit
after the #)
var $mArticleID = -1; // /< Article ID, fetched from the
link cache on demand
var $mLatestID = false; // /< ID of most recent revision
- var $mCounter = -1; // /< Number of times this page has
been viewed (-1 means "not loaded")
private $mEstimateRevisions; // /< Estimated number of revisions;
null of not loaded
var $mRestrictions = array(); // /< Array of groups allowed to edit
this article
var $mOldRestrictions = false;
@@ -274,14 +273,11 @@
$this->mRedirect = (bool)$row->page_is_redirect;
if ( isset( $row->page_latest ) )
$this->mLatestID = (int)$row->page_latest;
- if ( isset( $row->page_counter ) )
- $this->mCounter = (int)$row->page_counter;
} else { // page not found
$this->mArticleID = 0;
$this->mLength = 0;
$this->mRedirect = false;
$this->mLatestID = 0;
- $this->mCounter = 0;
}
}
@@ -2758,28 +2754,6 @@
}
/**
- * Get the number of views of this page
- *
- * @return int The view count for the page
- */
- public function getCount() {
- if ( $this->mCounter == -1 ) {
- if ( $this->exists() ) {
- $dbr = wfGetDB( DB_SLAVE );
- $this->mCounter = $dbr->selectField( 'page',
- 'page_counter',
- array( 'page_id' =>
$this->getArticleID() ),
- __METHOD__
- );
- } else {
- $this->mCounter = 0;
- }
- }
-
- return $this->mCounter;
- }
-
- /**
* Get the article ID for this Title from the link cache,
* adding it if necessary
*
@@ -2891,7 +2865,6 @@
$this->mRedirect = null;
$this->mLength = -1;
$this->mLatestID = false;
- $this->mCounter = -1;
$this->mEstimateRevisions = null;
}
Modified: trunk/phase3/includes/WikiPage.php
===================================================================
--- trunk/phase3/includes/WikiPage.php 2012-01-06 20:26:28 UTC (rev 108280)
+++ trunk/phase3/includes/WikiPage.php 2012-01-06 20:26:53 UTC (rev 108281)
@@ -48,6 +48,11 @@
protected $mTouched = '19700101000000';
/**
+ * @var int|null
+ */
+ protected $mCounter = null;
+
+ /**
* Constructor and clear the article
* @param $title Title Reference to a Title object.
*/
@@ -246,6 +251,7 @@
public function clear() {
$this->mDataLoaded = false;
+ $this->mCounter = null;
$this->mRedirectTarget = null; # Title object if set
$this->mLastRevision = null; # Latest revision
$this->mTouched = '19700101000000';
@@ -385,6 +391,7 @@
# Old-fashioned restrictions
$this->mTitle->loadRestrictions(
$data->page_restrictions );
+ $this->mCounter = intval( $data->page_counter );
$this->mTouched = wfTimestamp( TS_MW,
$data->page_touched );
$this->mIsRedirect = intval( $data->page_is_redirect );
$this->mLatest = intval( $data->page_latest );
@@ -424,12 +431,14 @@
}
/**
- * Get the number of views of this page
- *
* @return int The view count for the page
*/
public function getCount() {
- return $this->mTitle->getCount();
+ if ( !$this->mDataLoaded ) {
+ $this->loadPageData();
+ }
+
+ return $this->mCounter;
}
/**
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs