/**
  * Store a var dump to External Storage or the text table
  * Some of this code is stolen from Revision::insertOn and friends
  *
  * @param $vars AbuseFilterVariableHolder
  * @param $global bool
  *
  * @return int
  */
 public static function storeVarDump($vars, $global = false)
 {
     wfProfileIn(__METHOD__);
     global $wgCompressRevisions;
     // Get all variables yet set and compute old and new wikitext if not yet done
     // as those are needed for the diff view on top of the abuse log pages
     $vars = $vars->dumpAllVars(array('old_wikitext', 'new_wikitext'));
     // Vars is an array with native PHP data types (non-objects) now
     $text = serialize($vars);
     $flags = array('nativeDataArray');
     if ($wgCompressRevisions) {
         if (function_exists('gzdeflate')) {
             $text = gzdeflate($text);
             $flags[] = 'gzip';
         }
     }
     // Store to ES if applicable
     global $wgDefaultExternalStore, $wgAbuseFilterCentralDB;
     if ($wgDefaultExternalStore) {
         if ($global) {
             $text = ExternalStore::insertToForeignDefault($text, $wgAbuseFilterCentralDB);
         } else {
             $text = ExternalStore::insertToDefault($text);
         }
         $flags[] = 'external';
         if (!$text) {
             // Not mission-critical, just return nothing
             wfProfileOut(__METHOD__);
             return null;
         }
     }
     // Store to text table
     if ($global) {
         $dbw = wfGetDB(DB_MASTER, array(), $wgAbuseFilterCentralDB);
     } else {
         $dbw = wfGetDB(DB_MASTER);
     }
     $old_id = $dbw->nextSequenceValue('text_old_id_seq');
     $dbw->insert('text', array('old_id' => $old_id, 'old_text' => $text, 'old_flags' => implode(',', $flags)), __METHOD__);
     $text_id = $dbw->insertId();
     wfProfileOut(__METHOD__);
     return $text_id;
 }
 /**
  * Store a var dump to External Storage or the text table
  * Some of this code is stolen from Revision::insertOn and friends
  */
 public static function storeVarDump($vars, $global = false)
 {
     wfProfileIn(__METHOD__);
     global $wgCompressRevisions;
     if (is_array($vars) || is_object($vars)) {
         $text = serialize($vars);
     } else {
         $text = $vars;
     }
     $flags = array();
     if ($wgCompressRevisions) {
         if (function_exists('gzdeflate')) {
             $text = gzdeflate($text);
             $flags[] = 'gzip';
         }
     }
     // Store to ES if applicable
     global $wgDefaultExternalStore, $wgAbuseFilterCentralDB;
     if ($wgDefaultExternalStore) {
         if ($global) {
             $text = ExternalStore::insertToForeignDefault($text, $wgAbuseFilterCentralDB);
         } else {
             $text = ExternalStore::insertToDefault($text);
         }
         $flags[] = 'external';
         if (!$text) {
             // Not mission-critical, just return nothing
             wfProfileOut(__METHOD__);
             return null;
         }
     }
     // Store to text table
     if ($global) {
         $dbw = wfGetDB(DB_MASTER, array(), $wgAbuseFilterCentralDB);
     } else {
         $dbw = wfGetDB(DB_MASTER);
     }
     $old_id = $dbw->nextSequenceValue('text_old_id_seq');
     $dbw->insert('text', array('old_id' => $old_id, 'old_text' => $text, 'old_flags' => implode(',', $flags)), __METHOD__);
     $text_id = $dbw->insertId();
     wfProfileOut(__METHOD__);
     return $text_id;
 }