Index: trunk/phase3/includes/Title.php |
— | — | @@ -63,6 +63,7 @@ |
64 | 64 | var $mFragment; // /< Title fragment (i.e. the bit after the #) |
65 | 65 | var $mArticleID = -1; // /< Article ID, fetched from the link cache on demand |
66 | 66 | var $mLatestID = false; // /< ID of most recent revision |
| 67 | + var $mCounter = -1; // /< Number of times this page has been viewed (-1 means "not loaded") |
67 | 68 | var $mRestrictions = array(); // /< Array of groups allowed to edit this article |
68 | 69 | var $mOldRestrictions = false; |
69 | 70 | var $mCascadeRestriction; ///< Cascade restrictions on this page to included templates and images? |
— | — | @@ -272,11 +273,14 @@ |
273 | 274 | $this->mRedirect = (bool)$row->page_is_redirect; |
274 | 275 | if ( isset( $row->page_latest ) ) |
275 | 276 | $this->mLatestID = (int)$row->page_latest; |
| 277 | + if ( isset( $row->page_counter ) ) |
| 278 | + $this->mCounter = (int)$row->page_counter; |
276 | 279 | } else { // page not found |
277 | 280 | $this->mArticleID = 0; |
278 | 281 | $this->mLength = 0; |
279 | 282 | $this->mRedirect = false; |
280 | 283 | $this->mLatestID = 0; |
| 284 | + $this->mCounter = 0; |
281 | 285 | } |
282 | 286 | } |
283 | 287 | |
— | — | @@ -2517,6 +2521,28 @@ |
2518 | 2522 | } |
2519 | 2523 | |
2520 | 2524 | /** |
| 2525 | + * Get the number of views of this page |
| 2526 | + * |
| 2527 | + * @return int The view count for the page |
| 2528 | + */ |
| 2529 | + public function getCount() { |
| 2530 | + if ( $this->mCounter == -1 ) { |
| 2531 | + if ( $this->exists() ) { |
| 2532 | + $dbr = wfGetDB( DB_SLAVE ); |
| 2533 | + $this->mCounter = $dbr->selectField( 'page', |
| 2534 | + 'page_counter', |
| 2535 | + array( 'page_id' => $this->getArticleID() ), |
| 2536 | + __METHOD__ |
| 2537 | + ); |
| 2538 | + } else { |
| 2539 | + $this->mCounter = 0; |
| 2540 | + } |
| 2541 | + } |
| 2542 | + |
| 2543 | + return $this->mCounter; |
| 2544 | + } |
| 2545 | + |
| 2546 | + /** |
2521 | 2547 | * Get the article ID for this Title from the link cache, |
2522 | 2548 | * adding it if necessary |
2523 | 2549 | * |
— | — | @@ -2628,6 +2654,7 @@ |
2629 | 2655 | $this->mRedirect = null; |
2630 | 2656 | $this->mLength = -1; |
2631 | 2657 | $this->mLatestID = false; |
| 2658 | + $this->mCounter = -1; |
2632 | 2659 | } |
2633 | 2660 | |
2634 | 2661 | /** |
Index: trunk/phase3/includes/SkinTemplate.php |
— | — | @@ -330,9 +330,8 @@ |
331 | 331 | $tpl->set( 'numberofwatchingusers', false ); |
332 | 332 | if ( $out->isArticle() && $title->exists() ) { |
333 | 333 | if ( $this->isRevisionCurrent() ) { |
334 | | - $page = WikiPage::factory( $title ); |
335 | 334 | if ( !$wgDisableCounters ) { |
336 | | - $viewcount = $page->getCount(); |
| 335 | + $viewcount = $title->getCount(); |
337 | 336 | if ( $viewcount ) { |
338 | 337 | $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() ); |
339 | 338 | } |
— | — | @@ -352,7 +351,8 @@ |
353 | 352 | } |
354 | 353 | |
355 | 354 | if ( $wgMaxCredits != 0 ) { |
356 | | - $tpl->set( 'credits', Action::factory( 'credits', $page, $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) ); |
| 355 | + $tpl->set( 'credits', Action::factory( 'credits', WikiPage::factory( $title ), |
| 356 | + $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) ); |
357 | 357 | } else { |
358 | 358 | $tpl->set( 'lastmod', $this->lastModified() ); |
359 | 359 | } |
Index: trunk/phase3/includes/WikiPage.php |
— | — | @@ -21,7 +21,6 @@ |
22 | 22 | /**@{{ |
23 | 23 | * @protected |
24 | 24 | */ |
25 | | - public $mCounter = -1; // !< Integer (-1 means "not loaded") |
26 | 25 | public $mDataLoaded = false; // !< Boolean |
27 | 26 | public $mIsRedirect = false; // !< Boolean |
28 | 27 | public $mLatest = false; // !< Integer (false means "not loaded") |
— | — | @@ -240,7 +239,6 @@ |
241 | 240 | public function clear() { |
242 | 241 | $this->mDataLoaded = false; |
243 | 242 | |
244 | | - $this->mCounter = -1; # Not loaded |
245 | 243 | $this->mRedirectTarget = null; # Title object if set |
246 | 244 | $this->mLastRevision = null; # Latest revision |
247 | 245 | $this->mTimestamp = ''; |
— | — | @@ -380,7 +378,6 @@ |
381 | 379 | # Old-fashioned restrictions |
382 | 380 | $this->mTitle->loadRestrictions( $data->page_restrictions ); |
383 | 381 | |
384 | | - $this->mCounter = intval( $data->page_counter ); |
385 | 382 | $this->mTouched = wfTimestamp( TS_MW, $data->page_touched ); |
386 | 383 | $this->mIsRedirect = intval( $data->page_is_redirect ); |
387 | 384 | $this->mLatest = intval( $data->page_latest ); |
— | — | @@ -420,25 +417,12 @@ |
421 | 418 | } |
422 | 419 | |
423 | 420 | /** |
| 421 | + * Get the number of views of this page |
| 422 | + * |
424 | 423 | * @return int The view count for the page |
425 | 424 | */ |
426 | 425 | public function getCount() { |
427 | | - if ( -1 == $this->mCounter ) { |
428 | | - $id = $this->getId(); |
429 | | - |
430 | | - if ( $id == 0 ) { |
431 | | - $this->mCounter = 0; |
432 | | - } else { |
433 | | - $dbr = wfGetDB( DB_SLAVE ); |
434 | | - $this->mCounter = $dbr->selectField( 'page', |
435 | | - 'page_counter', |
436 | | - array( 'page_id' => $id ), |
437 | | - __METHOD__ |
438 | | - ); |
439 | | - } |
440 | | - } |
441 | | - |
442 | | - return $this->mCounter; |
| 426 | + return $this->mTitle->getCount(); |
443 | 427 | } |
444 | 428 | |
445 | 429 | /** |