/**
  * Common implementation for the APIEditBeforeSave, EditFilterMerged
  * and EditFilterMergedContent hooks.
  *
  * @param IContextSource $context the context of the edit
  * @param Content|null $content the new Content generated by the edit
  * @param string $text new page content (subject of filtering)
  * @param Status $status  Error message to return
  * @param string $summary Edit summary for page
  * @param bool $minoredit whether this is a minor edit according to the user.
  *
  * @return bool
  */
 public static function filterEdit(IContextSource $context, $content, $text, Status $status, $summary, $minoredit)
 {
     // Load vars
     $vars = new AbuseFilterVariableHolder();
     $title = $context->getTitle();
     // Some edits are running through multiple hooks, but we only want to filter them once
     if (isset($title->editAlreadyFiltered)) {
         return true;
     } elseif ($title) {
         $title->editAlreadyFiltered = true;
     }
     self::$successful_action_vars = false;
     self::$last_edit_page = false;
     $user = $context->getUser();
     // Check for null edits.
     $oldtext = '';
     $oldcontent = null;
     if ($title instanceof Title && $title->canExist() && $title->exists()) {
         // Make sure we load the latest text saved in database (bug 31656)
         $page = $context->getWikiPage();
         $revision = $page->getRevision();
         if (!$revision) {
             return true;
         }
         if (defined('MW_SUPPORTS_CONTENTHANDLER')) {
             $oldcontent = $revision->getContent(Revision::RAW);
             $oldtext = AbuseFilter::contentToString($oldcontent);
         } else {
             $oldtext = AbuseFilter::revisionToString($revision, Revision::RAW);
         }
         // Cache article object so we can share a parse operation
         $articleCacheKey = $title->getNamespace() . ':' . $title->getText();
         AFComputedVariable::$articleCache[$articleCacheKey] = $page;
     } else {
         $page = null;
     }
     // Don't trigger for null edits.
     if ($content && $oldcontent && $oldcontent->equals($content)) {
         // Compare Content objects if available
         return true;
     } else {
         if (strcmp($oldtext, $text) == 0) {
             // Otherwise, compare strings
             return true;
         }
     }
     $vars->addHolders(AbuseFilter::generateUserVars($user), AbuseFilter::generateTitleVars($title, 'ARTICLE'));
     $vars->setVar('action', 'edit');
     $vars->setVar('summary', $summary);
     $vars->setVar('minor_edit', $minoredit);
     $vars->setVar('old_wikitext', $oldtext);
     $vars->setVar('new_wikitext', $text);
     // TODO: set old_content and new_content vars, use them
     $vars->addHolders(AbuseFilter::getEditVars($title, $page));
     $filter_result = AbuseFilter::filterAction($vars, $title);
     if (!$filter_result->isOK()) {
         $status->merge($filter_result);
         return true;
         // re-show edit form
     }
     self::$successful_action_vars = $vars;
     self::$last_edit_page = $page;
     return true;
 }