r93116 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93115‎ | r93116 | r93117 >
Date:21:05, 25 July 2011
Author:reedy
Status:ok
Tags:
Comment:
Trim whitespace
Modified paths:
  • /trunk/extensions/EditPageTracking/EditPageTracking.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EditPageTracking/EditPageTracking.php
@@ -24,105 +24,107 @@
2525 $wgEditPageTrackingRegistrationCutoff = null;
2626
2727 abstract class EditPageTracking {
28 -
 28+
2929 /**
3030 * Applies EditPageTracking schema updates.
 31+ *
 32+ * @param $updater DatabaseUpdater
3133 */
3234 public static function doSchemaUpdates( $updater = null ) {
3335 $updater->addExtensionUpdate( array( 'addTable', 'edit_page_tracking',
3436 dirname(__FILE__).'/edit_page_tracking.sql', true ) );
35 -
 37+
3638 return true;
3739 }
38 -
 40+
3941 /**
4042 * Monitors edit page usage
4143 */
4244 public static function onEditForm( EditPage $editPage ) {
4345 global $wgUser, $wgEditPageTrackingRegistrationCutoff, $wgMemc;
44 -
 46+
4547 // Anonymous users
4648 if ( $wgUser->isAnon() ) {
4749 return true;
4850 }
49 -
 51+
5052 if ( $wgEditPageTrackingRegistrationCutoff &&
5153 $wgUser->getRegistration() < $wgEditPageTrackingRegistrationCutoff )
5254 {
5355 // User registered before the cutoff
5456 return true;
5557 }
56 -
 58+
5759 if ( EditPageTracking::getFirstEditPage( $wgUser ) ) {
5860 // Already stored.
5961 return true;
6062 }
61 -
 63+
6264 // Record it
6365 $dbw = wfGetDB( DB_MASTER );
64 -
 66+
6567 $title = $editPage->getArticle()->getTitle();
6668 $timestamp = wfTimestampNow();
67 -
 69+
6870 $row = array(
6971 'ept_user' => $wgUser->getId(),
7072 'ept_namespace' => $title->getNamespace(),
7173 'ept_title' => $title->getDBkey(),
7274 'ept_timestamp' => $dbw->timestamp( $timestamp ),
7375 );
74 -
 76+
7577 $dbw->insert( 'edit_page_tracking', $row, __METHOD__ );
76 -
 78+
7779 $wgUser->mFirstEditPage = $timestamp;
78 -
 80+
7981 $cacheKey = wfMemcKey( 'first-edit-page', $wgUser->getId() );
8082 $wgMemc->set($cacheKey, $timestamp, 86400);
81 -
 83+
8284 return true;
8385 }
84 -
85 - /**
 86+
 87+ /**
8688 * Gets the first time a user opened an edit page
87 - * @param $user The User to check.
 89+ * @param $user User The User to check.
8890 * @return The timestamp of the first time the user opened an edit page.
8991 * false for an anonymous user, null for a user who has never opened an edit page.
9092 */
9193 public static function getFirstEditPage( $user ) {
9294 global $wgMemc;
93 -
 95+
9496 if ( isset($user->mFirstEditPage) ) {
9597 return $user->mFirstEditPage;
9698 }
97 -
 99+
98100 if ( $user->isAnon() ) {
99101 return false;
100102 }
101 -
 103+
102104 $cacheKey = wfMemcKey( 'first-edit-page', $user->getId() );
103105 $cacheVal = $wgMemc->get($cacheKey);
104 -
 106+
105107 if ( $cacheVal !== false ) {
106108 $user->mFirstEditPage = $cacheVal;
107109 return $cacheVal;
108110 }
109 -
 111+
110112 $dbr = wfGetDB( DB_SLAVE );
111 -
 113+
112114 $res = $dbr->select( 'edit_page_tracking', 'ept_timestamp',
113115 array( 'ept_user' => $user->getID() ),
114116 __METHOD__, array( 'ORDER BY' => 'ept_timestamp asc' ) );
115 -
 117+
116118 if ( $dbr->numRows($res) == 0 ) {
117119 $user->mFirstEditPage = null;
118120 $wgMemc->set( $cacheKey, null, 86400 );
119121 return null;
120122 }
121 -
 123+
122124 $row = $dbr->fetchObject( $res );
123 -
 125+
124126 $user->mFirstEditPage = wfTimestamp( TS_MW, $row->ept_timestamp );
125127 $wgMemc->set($cacheKey, $user->mFirstEditPage, 86400);
126 -
 128+
127129 return $user->mFirstEditPage;
128130 }
129131

Status & tagging log