r105450 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105449‎ | r105450 | r105451 >
Date:19:05, 7 December 2011
Author:krinkle
Status:ok
Tags:
Comment:
[HarvardResearch] Update output according new protocol and banner-javascript
* Follows-up r105239
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/CentralNotice.php
@@ -260,11 +260,11 @@
261261 // Also, don't run if the UserDailyContribs-extension isn't installed.
262262 if ( $wgUser->isLoggedIn() && function_exists( 'getUserEditCountSince' ) ) {
263263
264 - $cacheKey = wfMemcKey( 'CentralNotice', 'Harvard2011', $wgUser->getId() );
265 - $data = $wgMemc->get( $cacheKey );
 264+ $cacheKey = wfMemcKey( 'CentralNotice', 'Harvard2011', 'v1', $wgUser->getId() );
 265+ $value = $wgMemc->get( $cacheKey );
266266
267267 // Cached ?
268 - if ( !$data ) {
 268+ if ( !$value ) {
269269 /**
270270 * To be eligible, the user must match all of the following:
271271 * - have an account
@@ -275,29 +275,31 @@
276276 * - have had their account registered for less than 30 days (on to the launch date)
277277 */
278278 if ( $wgUser->isAllowed( 'bot' ) ) {
279 - $data = false;
 279+ $value = false;
280280
281281 } else {
282 - global $wgNoticeBanner_Harvard2011_salt;
 282+ global $wgNoticeBanner_Harvard2011_salt, $wgContLang;
283283
284284 $launchTimestamp = wfTimestamp( TS_UNIX, '2011-12-06 00:00:00' );
285285 $groups = $wgUser->getGroups();
286286 $registrationDate = $wgUser->getRegistration() ? $wgUser->getRegistration() : 0;
287287 $daysOld = floor( ( $launchTimestamp - wfTimestamp( TS_UNIX, $registrationDate ) ) / ( 60*60*24 ) );
288288 $salt = $wgNoticeBanner_Harvard2011_salt;
289 - $metrics = array(
290 - // "username" the user's username
291 - 'username' => $wgUser->getName(),
292289
 290+ // Variables
 291+ $hashData = array(
 292+ // "login"
 293+ 'login' => intval( $wgUser->getId() ),
 294+
293295 // "group" is the group name(s) of the user (comma-separated).
294296 'group' => join( ',', $groups ),
295297
296298 // "duration" is the number of days since the user registered his (on the launching date).
297299 // Note: Will be negative if user registered after launch date!
298 - 'duration' => $daysOld,
 300+ 'duration' => intval( $daysOld ),
299301
300302 // "editcounts" is the user's total number of edits
301 - 'editcounts' => $wgUser->getEditCount() == NULL ? 0 : $wgUser->getEditCount(),
 303+ 'editcounts' => $wgUser->getEditCount() == NULL ? 0 : intval( $wgUser->getEditCount() ),
302304
303305 // "last6monthseditcount" is the user's total number of edits in the last 180 days (on the launching date)
304306 'last6monthseditcount' => getUserEditCountSince(
@@ -306,27 +308,34 @@
307309 $launchTimestamp
308310 ),
309311 );
310 - $realData = array(
311 - 'id' => $wgUser->getId(),
312 - 'metrics' => $metrics,
313 - 'hash' => md5( $salt . serialize( $metrics ) ),
314 - );
315312
 313+ $postData = $hashData;
 314+
 315+ // "username" the user's username
 316+ $postData['username'] = $wgUser->getName();
 317+
 318+ // Security checksum. Prevent users from entering the survey with invalid metrics
 319+ $postData['secretkey'] = md5( $salt . serialize( $hashData ) );
 320+
 321+ // MD5 hash
 322+ $postData['lang'] = $wgContLang->getCode();
 323+ echo $salt . serialize( $hashData )."\n\n";
 324+
316325 if (
317326 in_array( 'sysop', $groups )
318 - || ( $metrics['editcounts'] >= 300 && $metrics['last6monthseditcount'] >= 20 )
319 - || ( $metrics['duration'] < 30 )
 327+ || ( $postData['editcounts'] >= 300 && $postData['last6monthseditcount'] >= 20 )
 328+ || ( $postData['duration'] < 30 )
320329 ) {
321 - $data = $realData;
 330+ $value = $postData;
322331 } else {
323 - $data = false;
 332+ $value = false;
324333 }
325334 }
326335
327 - $wgMemc->set( $cacheKey, $data, strtotime( '+10 days' ) );
 336+ $wgMemc->set( $cacheKey, $value, strtotime( '+10 days' ) );
328337 }
329338
330 - $vars['wgNoticeBanner_Harvard2011'] = $data;
 339+ $vars['wgNoticeBanner_Harvard2011'] = $value;
331340
332341 }
333342

Follow-up revisions

RevisionCommit summaryAuthorDate
r105452[HarvardResearch] Another tiny update...krinkle19:17, 7 December 2011
r105588CentralNotice MFT r105239, 105241, r105267, r105450, r105452, r105453, r105586reedy20:57, 8 December 2011
r105591[HardvardResearch] follow-up r105450, rm debugkrinkle21:17, 8 December 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r105239[HarvardResearch][CentralNotice] Temporary wgNoticeBanner_Harvard2011 data....krinkle22:54, 5 December 2011

Status & tagging log