public function testUpdateUserParams()
 {
     $p = FRUserCounters::getUserParams(-1);
     # Assumes (main) IN content namespace
     $title = Title::makeTitleSafe(0, 'helloworld');
     $article = new Article($title);
     $copyP = $p;
     FRUserCounters::updateUserParams($copyP, $article, "Manual edit comment");
     $this->assertEquals($p['editComments'] + 1, $copyP['editComments'], "Manual summary");
     $copyP = $p;
     FRUserCounters::updateUserParams($copyP, $article, "/* section */");
     $this->assertEquals($p['editComments'], $copyP['editComments'], "Auto summary");
     $copyP = $p;
     FRUserCounters::updateUserParams($copyP, $article, "edit summary");
     $this->assertEquals($p['totalContentEdits'] + 1, $copyP['totalContentEdits'], "Content edit count on content edit");
     $expected = $p['uniqueContentPages'];
     $expected[] = 0;
     $this->assertEquals($expected, $copyP['uniqueContentPages'], "Unique content pages on content edit");
     # Assumes (user) NOT IN content namespace
     $title = Title::makeTitleSafe(NS_USER, 'helloworld');
     $article = new Article($title);
     $copyP = $p;
     FRUserCounters::updateUserParams($copyP, $article, "Manual edit comment");
     $this->assertEquals($p['editComments'] + 1, $copyP['editComments'], "Manual summary");
     $copyP = $p;
     FRUserCounters::updateUserParams($copyP, $article, "/* section */");
     $this->assertEquals($p['editComments'], $copyP['editComments'], "Auto summary");
     $title = Title::makeTitleSafe(NS_USER, 'helloworld');
     $article = new Article($title);
     $copyP = $p;
     FRUserCounters::updateUserParams($copyP, $article, "edit summary");
     $this->assertEquals($p['totalContentEdits'], $copyP['totalContentEdits'], "Content edit count on non-content edit");
     $this->assertEquals($p['uniqueContentPages'], $copyP['uniqueContentPages'], "Unique content pages on non-content edit");
 }
 public function execute()
 {
     global $wgContentNamespaces, $wgFlaggedRevsAutopromote;
     $this->output("Populating and updating flaggedrevs_promote table\n");
     $dbr = wfGetDB(DB_SLAVE);
     $dbw = wfGetDB(DB_MASTER);
     $start = $dbr->selectField('user', 'MIN(user_id)', false, __METHOD__);
     $end = $dbr->selectField('user', 'MAX(user_id)', false, __METHOD__);
     if (is_null($start) || is_null($end)) {
         $this->output("...user table seems to be empty.\n");
         return;
     }
     $count = 0;
     $changed = 0;
     for ($blockStart = $start; $blockStart <= $end; $blockStart += $this->mBatchSize) {
         $blockEnd = min($end, $blockStart + $this->mBatchSize - 1);
         $this->output("...doing user_id from {$blockStart} to {$blockEnd}\n");
         $cond = "user_id BETWEEN {$blockStart} AND {$blockEnd}\n";
         $res = $dbr->select('user', '*', $cond, __METHOD__);
         # Go through and clean up missing items, as well as correct fr_quality...
         foreach ($res as $row) {
             $dbw->begin();
             $user = User::newFromRow($row);
             $p = FRUserCounters::getUserParams($user->getId(), FR_FOR_UPDATE);
             $oldp = $p;
             # Get edit comments used
             $sres = $dbr->select('revision', '1', array('rev_user' => $user->getID(), "rev_comment NOT LIKE '/*%*/'"), __METHOD__, array('LIMIT' => max($wgFlaggedRevsAutopromote['editComments'], 500)));
             $p['editComments'] = $dbr->numRows($sres);
             # Get content page edits
             $sres = $dbr->select(array('revision', 'page'), '1', array('rev_user' => $user->getID(), 'page_id = rev_page', 'page_namespace' => $wgContentNamespaces), __METHOD__, array('LIMIT' => max($wgFlaggedRevsAutopromote['totalContentEdits'], 500)));
             $p['totalContentEdits'] = $dbr->numRows($sres);
             # Get unique content pages edited
             $sres = $dbr->select(array('revision', 'page'), 'DISTINCT(rev_page)', array('rev_user' => $user->getID(), 'page_id = rev_page', 'page_namespace' => $wgContentNamespaces), __METHOD__, array('LIMIT' => max($wgFlaggedRevsAutopromote['uniqueContentPages'], 50)));
             $p['uniqueContentPages'] = array();
             foreach ($sres as $innerRow) {
                 $p['uniqueContentPages'][] = (int) $innerRow->rev_page;
             }
             # Save the new params...
             if ($oldp != $p) {
                 FRUserCounters::saveUserParams($user->getId(), $p);
                 $changed++;
             }
             $count++;
             $dbw->commit();
         }
         wfWaitForSlaves(5);
     }
     $this->output("flaggedrevs_promote table update complete ..." . " {$count} rows [{$changed} changed or added]\n");
 }
 /**
  * Callback that autopromotes user according to the setting in
  * $wgFlaggedRevsAutopromote. This also handles user stats tallies.
  */
 public static function onArticleSaveComplete(Page $article, $user, $text, $summary, $m, $a, $b, &$f, $rev)
 {
     global $wgFlaggedRevsAutopromote, $wgFlaggedRevsAutoconfirm;
     # Ignore NULL edits or edits by anon users
     if (!$rev || !$user->getId()) {
         return true;
         # No sense in running counters if nothing uses them
     } elseif (!$wgFlaggedRevsAutopromote && !$wgFlaggedRevsAutoconfirm) {
         return true;
     }
     $p = FRUserCounters::getUserParams($user->getId(), FR_FOR_UPDATE);
     $changed = FRUserCounters::updateUserParams($p, $article, $summary);
     if ($changed) {
         FRUserCounters::saveUserParams($user->getId(), $p);
         // save any updates
     }
     return true;
 }