/**
  * @param FlaggedRevision $frev
  * Removes flagged revision data for this page/id set
  * @return bool
  */
 private function unapproveRevision(FlaggedRevision $frev)
 {
     wfProfileIn(__METHOD__);
     # Get current stable version ID (for logging)
     $oldSv = FlaggedRevision::newFromStable($this->page, FR_MASTER);
     # Delete from flaggedrevs table
     $frev->delete();
     # Update the article review log
     $oldSvId = $oldSv ? $oldSv->getRevId() : 0;
     FlaggedRevsLog::updateReviewLog($this->page, $this->dims, $this->oldFlags, $this->comment, $this->oldid, $oldSvId, false);
     # Get the new stable version as of now
     $sv = FlaggedRevision::determineStable($this->page, FR_MASTER);
     # Update recent changes
     self::updateRecentChanges($frev->getRevision(), 'unpatrol', $sv);
     # Update page and tracking tables and clear cache
     $changed = FlaggedRevs::stableVersionUpdates($this->page, $sv, $oldSv);
     if ($changed) {
         FlaggedRevs::HTMLCacheUpdates($this->page);
         // purge pages that use this page
     }
     # Caller may want to get the change time
     $this->newLastChangeTime = '';
     wfProfileOut(__METHOD__);
     return true;
 }
 /**
  * Submit the form parameters for the page config to the DB.
  * 
  * @return mixed (true on success, error string on failure)
  */
 public function doSubmit()
 {
     # Double-check permissions
     if (!$this->isAllowed()) {
         return 'stablize_denied';
     }
     # Parse and cleanup the expiry time given...
     $expiry = $this->getExpiry();
     if ($expiry === false) {
         return 'stabilize_expiry_invalid';
     } elseif ($expiry !== Block::infinity() && $expiry < wfTimestampNow()) {
         return 'stabilize_expiry_old';
     }
     # Update the DB row with the new config...
     $changed = FRPageConfig::setStabilitySettings($this->page, $this->getNewConfig());
     # Log if this actually changed anything...
     if ($changed) {
         $article = new FlaggableWikiPage($this->page);
         if (FlaggedRevs::useOnlyIfProtected()) {
             # Config may have changed to allow stable versions, so refresh
             # the tracking table to account for any hidden reviewed versions...
             $frev = FlaggedRevision::determineStable($this->page, FR_MASTER);
             if ($frev) {
                 $article->updateStableVersion($frev);
             } else {
                 $article->clearStableVersion();
             }
         }
         # Update logs and make a null edit
         $nullRev = $this->updateLogsAndHistory($article);
         # Null edit may have been auto-reviewed already
         $frev = FlaggedRevision::newFromTitle($this->page, $nullRev->getId(), FR_MASTER);
         $updatesDone = (bool) $frev;
         // stableVersionUpdates() already called?
         # Check if this null edit is to be reviewed...
         if ($this->reviewThis && !$frev) {
             $flags = null;
             # Review this revision of the page...
             $ok = FlaggedRevs::autoReviewEdit($article, $this->user, $nullRev, $flags, true);
             if ($ok) {
                 FlaggedRevs::markRevisionPatrolled($nullRev);
                 // reviewed -> patrolled
                 $updatesDone = true;
                 // stableVersionUpdates() already called
             }
         }
         # Update page and tracking tables and clear cache.
         if (!$updatesDone) {
             FlaggedRevs::stableVersionUpdates($this->page);
         }
     }
     # Apply watchlist checkbox value (may be NULL)
     $this->updateWatchlist();
     # Take this opportunity to purge out expired configurations
     FRPageConfig::purgeExpiredConfigurations();
     return true;
 }
 /**
  * Update the page tables with a new stable version.
  * @param WikiPage|Title $page
  * @param FlaggedRevision|null $sv, the new stable version (optional)
  * @param FlaggedRevision|null $oldSv, the old stable version (optional)
  * @param Object editInfo Article edit info about the current revision (optional)
  * @return bool stable version text/file changed and FR_INCLUDES_STABLE
  */
 public static function stableVersionUpdates($page, $sv = null, $oldSv = null, $editInfo = null)
 {
     if ($page instanceof FlaggableWikiPage) {
         $article = $page;
     } elseif ($page instanceof WikiPage) {
         $article = FlaggableWikiPage::getTitleInstance($page->getTitle());
     } elseif ($page instanceof Title) {
         $article = FlaggableWikiPage::getTitleInstance($page);
     } else {
         throw new MWException("First argument must be a Title or WikiPage.");
     }
     $title = $article->getTitle();
     $changed = false;
     if ($oldSv === null) {
         // optional
         $oldSv = FlaggedRevision::newFromStable($title, FR_MASTER);
     }
     if ($sv === null) {
         // optional
         $sv = FlaggedRevision::determineStable($title, FR_MASTER);
     }
     if (!$sv) {
         # Empty flaggedrevs data for this page if there is no stable version
         $article->clearStableVersion();
         # Check if pages using this need to be refreshed...
         if (FlaggedRevs::inclusionSetting() == FR_INCLUDES_STABLE) {
             $changed = (bool) $oldSv;
         }
     } else {
         # Update flagged page related fields
         $article->updateStableVersion($sv, $editInfo ? $editInfo->revid : null);
         # Check if pages using this need to be invalidated/purged...
         if (FlaggedRevs::inclusionSetting() == FR_INCLUDES_STABLE) {
             $changed = !$oldSv || $sv->getRevId() != $oldSv->getRevId() || $sv->getFileTimestamp() != $oldSv->getFileTimestamp() || $sv->getFileSha1() != $oldSv->getFileSha1();
         }
         # Update template/file version cache...
         if ($editInfo && $sv->getRevId() != $editInfo->revid) {
             FRInclusionCache::setRevIncludes($title, $editInfo->revid, $editInfo->output);
         }
     }
     # Lazily rebuild dependancies on next parse (we invalidate below)
     FlaggedRevs::clearStableOnlyDeps($title->getArticleID());
     # Clear page cache
     $title->invalidateCache();
     self::purgeSquid($title);
     return $changed;
 }
Пример #4
0
 protected function update_flaggedpages($start = null)
 {
     $this->output("Populating and correcting flaggedpages/flaggedpage_config columns\n");
     $BATCH_SIZE = 300;
     $db = wfGetDB(DB_MASTER);
     if ($start === null) {
         $start = $db->selectField('page', 'MIN(page_id)', false, __METHOD__);
     }
     $end = $db->selectField('page', 'MAX(page_id)', false, __METHOD__);
     if (is_null($start) || is_null($end)) {
         $this->output("...flaggedpages table seems to be empty.\n");
         return;
     }
     # Do remaining chunk
     $end += $BATCH_SIZE - 1;
     $blockStart = $start;
     $blockEnd = $start + $BATCH_SIZE - 1;
     $count = $deleted = $fixed = 0;
     while ($blockEnd <= $end) {
         $this->output("...doing page_id from {$blockStart} to {$blockEnd}\n");
         $cond = "page_id BETWEEN {$blockStart} AND {$blockEnd}";
         $res = $db->select('page', array('page_id', 'page_namespace', 'page_title', 'page_latest'), $cond, __METHOD__);
         # Go through and update the de-normalized references...
         $db->begin();
         foreach ($res as $row) {
             $title = Title::newFromRow($row);
             $article = new FlaggableWikiPage($title);
             $oldFrev = FlaggedRevision::newFromStable($title, FR_MASTER);
             $frev = FlaggedRevision::determineStable($title, FR_MASTER);
             # Update fp_stable, fp_quality, and fp_reviewed
             if ($frev) {
                 $article->updateStableVersion($frev, $row->page_latest);
                 $changed = !$oldFrev || $oldFrev->getRevId() != $frev->getRevId();
                 # Somethings broke? Delete the row...
             } else {
                 $article->clearStableVersion();
                 if ($db->affectedRows() > 0) {
                     $deleted++;
                 }
                 $changed = (bool) $oldFrev;
             }
             # Get the latest revision
             $revRow = $db->selectRow('revision', '*', array('rev_page' => $row->page_id), __METHOD__, array('ORDER BY' => 'rev_timestamp DESC'));
             # Correct page_latest if needed (import/files made plenty of bad rows)
             if ($revRow) {
                 $revision = new Revision($revRow);
                 if ($article->updateIfNewerOn($db, $revision)) {
                     $fixed++;
                 }
             }
             if ($changed) {
                 # Lazily rebuild dependancies on next parse (we invalidate below)
                 FlaggedRevs::clearStableOnlyDeps($title);
                 $title->invalidateCache();
             }
             $count++;
         }
         $db->freeResult($res);
         # Remove manual config settings that simply restate the site defaults
         $db->delete('flaggedpage_config', array("fpc_page_id BETWEEN {$blockStart} AND {$blockEnd}", 'fpc_override' => intval(FlaggedRevs::isStableShownByDefault()), 'fpc_level' => ''), __METHOD__);
         $deleted = $deleted + $db->affectedRows();
         $db->commit();
         $blockStart += $BATCH_SIZE;
         $blockEnd += $BATCH_SIZE;
         wfWaitForSlaves(5);
     }
     $this->output("flaggedpage columns update complete ..." . " {$count} rows [{$fixed} fixed] [{$deleted} deleted]\n");
 }