| Index: branches/wmf/1.18wmf1/extensions/CentralNotice/CentralNotice.php |
| — | — | @@ -89,6 +89,17 @@ |
| 90 | 90 | 'messages' => 'centralnotice-documentwrite-error' |
| 91 | 91 | ); |
| 92 | 92 | |
| | 93 | +// Temporary setting to enable and configure info for Harvard banner on en.wikipedia.org |
| | 94 | +$wgNoticeBanner_Harvard2011 = array( |
| | 95 | + 'enable' => false, |
| | 96 | + 'salt' => 'default', |
| | 97 | +); |
| | 98 | + |
| | 99 | +/** |
| | 100 | + * UnitTestsList hook handler |
| | 101 | + * @param $files array |
| | 102 | + * @return bool |
| | 103 | + */ |
| 93 | 104 | function efCentralNoticeUnitTests( &$files ) { |
| 94 | 105 | $files[] = dirname( __FILE__ ) . '/tests/CentralNoticeTest.php'; |
| 95 | 106 | return true; |
| — | — | @@ -146,6 +157,11 @@ |
| 147 | 158 | } |
| 148 | 159 | } |
| 149 | 160 | |
| | 161 | +/** |
| | 162 | + * LoadExtensionSchemaUpdates hook handler |
| | 163 | + * @param $updater DatabaseUpdater|null |
| | 164 | + * @return bool |
| | 165 | + */ |
| 150 | 166 | function efCentralNoticeSchema( $updater = null ) { |
| 151 | 167 | $base = dirname( __FILE__ ); |
| 152 | 168 | if ( $updater === null ) { |
| — | — | @@ -200,26 +216,43 @@ |
| 201 | 217 | return true; |
| 202 | 218 | } |
| 203 | 219 | |
| | 220 | +/** |
| | 221 | + * BeforePageDisplay hook handler |
| | 222 | + * @param $out OutputPage |
| | 223 | + * @param $skin Skin |
| | 224 | + * @return bool |
| | 225 | + */ |
| 204 | 226 | function efCentralNoticeLoader( $out, $skin ) { |
| 205 | | - global $wgOut; |
| 206 | | - |
| 207 | 227 | // Include '.js' to exempt script from squid cache expiration override |
| 208 | 228 | $centralLoader = SpecialPage::getTitleFor( 'BannerController' )->getLocalUrl( 'cache=/cn.js' ); |
| 209 | 229 | |
| 210 | 230 | // Insert the banner controller Javascript into the page |
| 211 | | - $wgOut->addScriptFile( $centralLoader ); |
| | 231 | + $out->addScriptFile( $centralLoader ); |
| 212 | 232 | |
| 213 | 233 | return true; |
| 214 | 234 | } |
| 215 | 235 | |
| | 236 | +/** |
| | 237 | + * SkinAfterBottomScripts hook handler |
| | 238 | + * @param $skin Skin |
| | 239 | + * @param $text string |
| | 240 | + * @return bool |
| | 241 | + */ |
| 216 | 242 | function efCentralNoticeGeoLoader( $skin, &$text ) { |
| 217 | 243 | // Insert the geo IP lookup |
| 218 | 244 | $text .= Html::linkedScript( "//geoiplookup.wikimedia.org/" ); |
| 219 | 245 | return true; |
| 220 | 246 | } |
| 221 | 247 | |
| | 248 | +/** |
| | 249 | + * MakeGlobalVariablesScript hook handler |
| | 250 | + * @param $vars array |
| | 251 | + * @return bool |
| | 252 | + */ |
| 222 | 253 | function efCentralNoticeDefaults( &$vars ) { |
| 223 | | - global $wgNoticeProject; |
| | 254 | + // Using global $wgUser for compatibility with 1.18 |
| | 255 | + global $wgNoticeProject, $wgUser, $wgMemc, $wgNoticeBanner_Harvard2011, $wgContLang; |
| | 256 | + |
| 224 | 257 | // Initialize global Javascript variables. We initialize Geo with empty values so if the geo |
| 225 | 258 | // IP lookup fails we don't have any surprises. |
| 226 | 259 | $geo = (object)array(); |
| — | — | @@ -227,9 +260,98 @@ |
| 228 | 261 | $geo->{'country'} = ''; |
| 229 | 262 | $vars['Geo'] = $geo; // change this to wgGeo as soon as Mark updates on his end |
| 230 | 263 | $vars['wgNoticeProject'] = $wgNoticeProject; |
| | 264 | + |
| | 265 | + // XXX: Temporary WMF-specific code for the 2011 Harvard survey invitation banner. |
| | 266 | + // Only do this for logged-in users, keeping anonymous user output equal (for Squid-cache). |
| | 267 | + // Also, don't run if the UserDailyContribs-extension isn't installed. |
| | 268 | + if ( $wgNoticeBanner_Harvard2011['enable'] && $wgUser->isLoggedIn() && function_exists( 'getUserEditCountSince' ) ) { |
| | 269 | + |
| | 270 | + $cacheKey = wfMemcKey( 'CentralNotice', 'Harvard2011', 'v1', $wgUser->getId() ); |
| | 271 | + $value = $wgMemc->get( $cacheKey ); |
| | 272 | + |
| | 273 | + // Cached ? |
| | 274 | + if ( !$value ) { |
| | 275 | + /** |
| | 276 | + * To be eligible, the user must match all of the following: |
| | 277 | + * - have an account |
| | 278 | + * - not be a bot (userright=bot) |
| | 279 | + * .. and match one of the following: |
| | 280 | + * - be an admin (group=sysop) |
| | 281 | + * - have an editcount higher than 300, of which 20 within the last 180 days (on the launch date) |
| | 282 | + * - have had their account registered for less than 30 days (on to the launch date) |
| | 283 | + */ |
| | 284 | + if ( $wgUser->isAllowed( 'bot' ) ) { |
| | 285 | + $value = false; |
| | 286 | + |
| | 287 | + } else { |
| | 288 | + |
| | 289 | + $launchTimestamp = wfTimestamp( TS_UNIX, '2011-12-08 00:00:00' ); |
| | 290 | + $groups = $wgUser->getGroups(); |
| | 291 | + $registrationDate = $wgUser->getRegistration() ? $wgUser->getRegistration() : 0; |
| | 292 | + $daysOld = floor( ( $launchTimestamp - wfTimestamp( TS_UNIX, $registrationDate ) ) / ( 60*60*24 ) ); |
| | 293 | + $salt = $wgNoticeBanner_Harvard2011['salt']; |
| | 294 | + |
| | 295 | + // Variables |
| | 296 | + $hashData = array( |
| | 297 | + // "login" |
| | 298 | + 'login' => intval( $wgUser->getId() ), |
| | 299 | + |
| | 300 | + // "group" is the group name(s) of the user (comma-separated). |
| | 301 | + 'group' => implode( ',', $groups ), |
| | 302 | + |
| | 303 | + // "duration" is the number of days since the user registered his (on the launching date). |
| | 304 | + // Note: Will be negative if user registered after launch date! |
| | 305 | + 'duration' => intval( $daysOld ), |
| | 306 | + |
| | 307 | + // "editcounts" is the user's total number of edits |
| | 308 | + 'editcounts' => $wgUser->getEditCount() == null ? 0 : intval( $wgUser->getEditCount() ), |
| | 309 | + |
| | 310 | + // "last6monthseditcount" is the user's total number of edits in the last 180 days (on the launching date) |
| | 311 | + 'last6monthseditcount' => getUserEditCountSince( |
| | 312 | + $launchTimestamp - ( 180*24*3600 ), |
| | 313 | + $wgUser, |
| | 314 | + $launchTimestamp |
| | 315 | + ), |
| | 316 | + ); |
| | 317 | + |
| | 318 | + $postData = $hashData; |
| | 319 | + |
| | 320 | + // "username" the user's username |
| | 321 | + $postData['username'] = $wgUser->getName(); |
| | 322 | + |
| | 323 | + // Security checksum. Prevent users from entering the survey with invalid metrics |
| | 324 | + $postData['secretkey'] = md5( $salt . serialize( $hashData ) ); |
| | 325 | + |
| | 326 | + // MD5 hash |
| | 327 | + $postData['lang'] = $wgContLang->getCode(); |
| | 328 | + echo $salt . serialize( $hashData )."\n\n"; |
| | 329 | + |
| | 330 | + if ( |
| | 331 | + in_array( 'sysop', $groups ) |
| | 332 | + || ( $postData['duration'] >= 180 && $postData['editcounts'] >= 300 && $postData['last6monthseditcount'] >= 20 ) |
| | 333 | + || ( $postData['duration'] < 30 ) |
| | 334 | + ) { |
| | 335 | + $value = $postData; |
| | 336 | + } else { |
| | 337 | + $value = false; |
| | 338 | + } |
| | 339 | + } |
| | 340 | + |
| | 341 | + $wgMemc->set( $cacheKey, $value, strtotime( '+10 days' ) ); |
| | 342 | + } |
| | 343 | + |
| | 344 | + $vars['wgNoticeBanner_Harvard2011'] = $value; |
| | 345 | + |
| | 346 | + } |
| | 347 | + |
| 231 | 348 | return true; |
| 232 | 349 | } |
| 233 | 350 | |
| | 351 | +/** |
| | 352 | + * SiteNoticeAfter hook handler |
| | 353 | + * @param $notice string |
| | 354 | + * @return bool |
| | 355 | + */ |
| 234 | 356 | function efCentralNoticeDisplay( &$notice ) { |
| 235 | 357 | // setup siteNotice div |
| 236 | 358 | $notice = |
| Property changes on: branches/wmf/1.18wmf1/extensions/CentralNotice/CentralNotice.php |
| ___________________________________________________________________ |
| Modified: svn:mergeinfo |
| 237 | 359 | Merged /trunk/extensions/CentralNotice/CentralNotice.php:r105239,105241,105267,105450,105452-105453,105586 |
| Index: branches/wmf/1.18wmf1/extensions/CentralNotice/CentralNotice.db.php |
| — | — | @@ -14,6 +14,12 @@ |
| 15 | 15 | /** |
| 16 | 16 | * Return campaigns in the system within given constraints |
| 17 | 17 | * By default returns enabled campaigns, if $enabled set to false, returns both enabled and disabled campaigns |
| | 18 | + * @param $project string |
| | 19 | + * @param $language string |
| | 20 | + * @param $date string |
| | 21 | + * @param $enabled bool |
| | 22 | + * @param $preferred string |
| | 23 | + * @param $location string |
| 18 | 24 | * @return an array of ids |
| 19 | 25 | */ |
| 20 | 26 | static function getCampaigns( $project = false, $language = false, $date = false, $enabled = true, $preferred = false, $location = false ) { |
| — | — | @@ -289,7 +295,10 @@ |
| 290 | 296 | * Lookup function for active banners under a given language/project/location. This function is |
| 291 | 297 | * called by SpecialBannerListLoader::getJsonList() in order to build the banner list JSON for |
| 292 | 298 | * each project. |
| 293 | | - * @return a 2D array of running banners with associated weights and settings |
| | 299 | + * @param $project string |
| | 300 | + * @param $language string |
| | 301 | + * @param $location string |
| | 302 | + * @return array a 2D array of running banners with associated weights and settings |
| 294 | 303 | */ |
| 295 | 304 | static function getBannersByTarget( $project, $language, $location = null ) { |
| 296 | 305 | global $wgCentralDBname; |
| — | — | @@ -371,6 +380,8 @@ |
| 372 | 381 | |
| 373 | 382 | /** |
| 374 | 383 | * See if a given campaign exists in the database |
| | 384 | + * @param $campaignName string |
| | 385 | + * @return bool |
| 375 | 386 | */ |
| 376 | 387 | public static function campaignExists( $campaignName ) { |
| 377 | 388 | global $wgCentralDBname; |
| — | — | @@ -382,6 +393,8 @@ |
| 383 | 394 | |
| 384 | 395 | /** |
| 385 | 396 | * See if a given banner exists in the database |
| | 397 | + * @param $bannerName string |
| | 398 | + * @return bool |
| 386 | 399 | */ |
| 387 | 400 | public static function bannerExists( $bannerName ) { |
| 388 | 401 | global $wgCentralDBname; |
| — | — | @@ -399,6 +412,7 @@ |
| 400 | 413 | /** |
| 401 | 414 | * Return all of the available countries for geotargeting |
| 402 | 415 | * (This should probably be moved to a core database table at some point.) |
| | 416 | + * @return array |
| 403 | 417 | */ |
| 404 | 418 | static function getCountriesList() { |
| 405 | 419 | return array( |
| Property changes on: branches/wmf/1.18wmf1/extensions/CentralNotice/CentralNotice.db.php |
| ___________________________________________________________________ |
| Modified: svn:mergeinfo |
| 406 | 420 | Merged /trunk/extensions/CentralNotice/CentralNotice.db.php:r105586 |
| Property changes on: branches/wmf/1.18wmf1/extensions/CentralNotice |
| ___________________________________________________________________ |
| Modified: svn:mergeinfo |
| 407 | 421 | Merged /trunk/extensions/CentralNotice:r105239,105241,105267,105450,105452-105453,105586 |