| Index: trunk/extensions/CentralNotice/CentralNotice.php |
| — | — | @@ -260,11 +260,11 @@ |
| 261 | 261 | // Also, don't run if the UserDailyContribs-extension isn't installed. |
| 262 | 262 | if ( $wgUser->isLoggedIn() && function_exists( 'getUserEditCountSince' ) ) { |
| 263 | 263 | |
| 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 ); |
| 266 | 266 | |
| 267 | 267 | // Cached ? |
| 268 | | - if ( !$data ) { |
| | 268 | + if ( !$value ) { |
| 269 | 269 | /** |
| 270 | 270 | * To be eligible, the user must match all of the following: |
| 271 | 271 | * - have an account |
| — | — | @@ -275,29 +275,31 @@ |
| 276 | 276 | * - have had their account registered for less than 30 days (on to the launch date) |
| 277 | 277 | */ |
| 278 | 278 | if ( $wgUser->isAllowed( 'bot' ) ) { |
| 279 | | - $data = false; |
| | 279 | + $value = false; |
| 280 | 280 | |
| 281 | 281 | } else { |
| 282 | | - global $wgNoticeBanner_Harvard2011_salt; |
| | 282 | + global $wgNoticeBanner_Harvard2011_salt, $wgContLang; |
| 283 | 283 | |
| 284 | 284 | $launchTimestamp = wfTimestamp( TS_UNIX, '2011-12-06 00:00:00' ); |
| 285 | 285 | $groups = $wgUser->getGroups(); |
| 286 | 286 | $registrationDate = $wgUser->getRegistration() ? $wgUser->getRegistration() : 0; |
| 287 | 287 | $daysOld = floor( ( $launchTimestamp - wfTimestamp( TS_UNIX, $registrationDate ) ) / ( 60*60*24 ) ); |
| 288 | 288 | $salt = $wgNoticeBanner_Harvard2011_salt; |
| 289 | | - $metrics = array( |
| 290 | | - // "username" the user's username |
| 291 | | - 'username' => $wgUser->getName(), |
| 292 | 289 | |
| | 290 | + // Variables |
| | 291 | + $hashData = array( |
| | 292 | + // "login" |
| | 293 | + 'login' => intval( $wgUser->getId() ), |
| | 294 | + |
| 293 | 295 | // "group" is the group name(s) of the user (comma-separated). |
| 294 | 296 | 'group' => join( ',', $groups ), |
| 295 | 297 | |
| 296 | 298 | // "duration" is the number of days since the user registered his (on the launching date). |
| 297 | 299 | // Note: Will be negative if user registered after launch date! |
| 298 | | - 'duration' => $daysOld, |
| | 300 | + 'duration' => intval( $daysOld ), |
| 299 | 301 | |
| 300 | 302 | // "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() ), |
| 302 | 304 | |
| 303 | 305 | // "last6monthseditcount" is the user's total number of edits in the last 180 days (on the launching date) |
| 304 | 306 | 'last6monthseditcount' => getUserEditCountSince( |
| — | — | @@ -306,27 +308,34 @@ |
| 307 | 309 | $launchTimestamp |
| 308 | 310 | ), |
| 309 | 311 | ); |
| 310 | | - $realData = array( |
| 311 | | - 'id' => $wgUser->getId(), |
| 312 | | - 'metrics' => $metrics, |
| 313 | | - 'hash' => md5( $salt . serialize( $metrics ) ), |
| 314 | | - ); |
| 315 | 312 | |
| | 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 | + |
| 316 | 325 | if ( |
| 317 | 326 | 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 ) |
| 320 | 329 | ) { |
| 321 | | - $data = $realData; |
| | 330 | + $value = $postData; |
| 322 | 331 | } else { |
| 323 | | - $data = false; |
| | 332 | + $value = false; |
| 324 | 333 | } |
| 325 | 334 | } |
| 326 | 335 | |
| 327 | | - $wgMemc->set( $cacheKey, $data, strtotime( '+10 days' ) ); |
| | 336 | + $wgMemc->set( $cacheKey, $value, strtotime( '+10 days' ) ); |
| 328 | 337 | } |
| 329 | 338 | |
| 330 | | - $vars['wgNoticeBanner_Harvard2011'] = $data; |
| | 339 | + $vars['wgNoticeBanner_Harvard2011'] = $value; |
| 331 | 340 | |
| 332 | 341 | } |
| 333 | 342 | |