/**
  * 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;
 }
Exemple #2
0
 /**
  * Insert a new revision into the database, returning the new revision ID
  * number on success and dies horribly on failure.
  *
  * @param $dbw DatabaseBase: (master connection)
  * @throws MWException
  * @return Integer
  */
 public function insertOn($dbw)
 {
     global $wgDefaultExternalStore, $wgContentHandlerUseDB;
     wfProfileIn(__METHOD__);
     $this->checkContentModel();
     $data = $this->mText;
     $flags = self::compressRevisionText($data);
     # Write to external storage if required
     if ($wgDefaultExternalStore) {
         // Store and get the URL
         $data = ExternalStore::insertToDefault($data);
         if (!$data) {
             wfProfileOut(__METHOD__);
             throw new MWException("Unable to store text to external storage");
         }
         if ($flags) {
             $flags .= ',';
         }
         $flags .= 'external';
     }
     # Record the text (or external storage URL) to the text table
     if (!isset($this->mTextId)) {
         $old_id = $dbw->nextSequenceValue('text_old_id_seq');
         $dbw->insert('text', array('old_id' => $old_id, 'old_text' => $data, 'old_flags' => $flags), __METHOD__);
         $this->mTextId = $dbw->insertId();
     }
     if ($this->mComment === null) {
         $this->mComment = "";
     }
     # Record the edit in revisions
     $rev_id = isset($this->mId) ? $this->mId : $dbw->nextSequenceValue('revision_rev_id_seq');
     $row = array('rev_id' => $rev_id, 'rev_page' => $this->mPage, 'rev_text_id' => $this->mTextId, 'rev_comment' => $this->mComment, 'rev_minor_edit' => $this->mMinorEdit ? 1 : 0, 'rev_user' => $this->mUser, 'rev_user_text' => $this->mUserText, 'rev_timestamp' => $dbw->timestamp($this->mTimestamp), 'rev_deleted' => $this->mDeleted, 'rev_len' => $this->mSize, 'rev_parent_id' => is_null($this->mParentId) ? $this->getPreviousRevisionId($dbw) : $this->mParentId, 'rev_sha1' => is_null($this->mSha1) ? Revision::base36Sha1($this->mText) : $this->mSha1);
     if ($wgContentHandlerUseDB) {
         //NOTE: Store null for the default model and format, to save space.
         //XXX: Makes the DB sensitive to changed defaults. Make this behavior optional? Only in miser mode?
         $model = $this->getContentModel();
         $format = $this->getContentFormat();
         $title = $this->getTitle();
         if ($title === null) {
             wfProfileOut(__METHOD__);
             throw new MWException("Insufficient information to determine the title of the revision's page!");
         }
         $defaultModel = ContentHandler::getDefaultModelFor($title);
         $defaultFormat = ContentHandler::getForModelID($defaultModel)->getDefaultFormat();
         $row['rev_content_model'] = $model === $defaultModel ? null : $model;
         $row['rev_content_format'] = $format === $defaultFormat ? null : $format;
     }
     $dbw->insert('revision', $row, __METHOD__);
     $this->mId = !is_null($rev_id) ? $rev_id : $dbw->insertId();
     wfRunHooks('RevisionInsertComplete', array(&$this, $data, $flags));
     wfProfileOut(__METHOD__);
     return $this->mId;
 }
Exemple #3
0
 /**
  * Insert a new revision into the database, returning the new revision ID
  * number on success and dies horribly on failure.
  *
  * @param IDatabase $dbw (master connection)
  * @throws MWException
  * @return int
  */
 public function insertOn($dbw)
 {
     global $wgDefaultExternalStore, $wgContentHandlerUseDB;
     // Not allowed to have rev_page equal to 0, false, etc.
     if (!$this->mPage) {
         $title = $this->getTitle();
         if ($title instanceof Title) {
             $titleText = ' for page ' . $title->getPrefixedText();
         } else {
             $titleText = '';
         }
         throw new MWException("Cannot insert revision{$titleText}: page ID must be nonzero");
     }
     $this->checkContentModel();
     $data = $this->mText;
     $flags = self::compressRevisionText($data);
     # Write to external storage if required
     if ($wgDefaultExternalStore) {
         // Store and get the URL
         $data = ExternalStore::insertToDefault($data);
         if (!$data) {
             throw new MWException("Unable to store text to external storage");
         }
         if ($flags) {
             $flags .= ',';
         }
         $flags .= 'external';
     }
     # Record the text (or external storage URL) to the text table
     if ($this->mTextId === null) {
         $old_id = $dbw->nextSequenceValue('text_old_id_seq');
         $dbw->insert('text', array('old_id' => $old_id, 'old_text' => $data, 'old_flags' => $flags), __METHOD__);
         $this->mTextId = $dbw->insertId();
     }
     if ($this->mComment === null) {
         $this->mComment = "";
     }
     # Record the edit in revisions
     $rev_id = $this->mId !== null ? $this->mId : $dbw->nextSequenceValue('revision_rev_id_seq');
     $row = array('rev_id' => $rev_id, 'rev_page' => $this->mPage, 'rev_text_id' => $this->mTextId, 'rev_comment' => $this->mComment, 'rev_minor_edit' => $this->mMinorEdit ? 1 : 0, 'rev_user' => $this->mUser, 'rev_user_text' => $this->mUserText, 'rev_timestamp' => $dbw->timestamp($this->mTimestamp), 'rev_deleted' => $this->mDeleted, 'rev_len' => $this->mSize, 'rev_parent_id' => $this->mParentId === null ? $this->getPreviousRevisionId($dbw) : $this->mParentId, 'rev_sha1' => $this->mSha1 === null ? Revision::base36Sha1($this->mText) : $this->mSha1);
     if ($wgContentHandlerUseDB) {
         // NOTE: Store null for the default model and format, to save space.
         // XXX: Makes the DB sensitive to changed defaults.
         // Make this behavior optional? Only in miser mode?
         $model = $this->getContentModel();
         $format = $this->getContentFormat();
         $title = $this->getTitle();
         if ($title === null) {
             throw new MWException("Insufficient information to determine the title of the " . "revision's page!");
         }
         $defaultModel = ContentHandler::getDefaultModelFor($title);
         $defaultFormat = ContentHandler::getForModelID($defaultModel)->getDefaultFormat();
         $row['rev_content_model'] = $model === $defaultModel ? null : $model;
         $row['rev_content_format'] = $format === $defaultFormat ? null : $format;
     }
     $dbw->insert('revision', $row, __METHOD__);
     $this->mId = $rev_id !== null ? $rev_id : $dbw->insertId();
     // Assertion to try to catch T92046
     if ((int) $this->mId === 0) {
         throw new UnexpectedValueException('After insert, Revision mId is ' . var_export($this->mId, 1) . ': ' . var_export($row, 1));
     }
     Hooks::run('RevisionInsertComplete', array(&$this, $data, $flags));
     return $this->mId;
 }
Exemple #4
0
 /**
  * Insert a new revision into the database, returning the new revision ID
  * number on success and dies horribly on failure.
  *
  * @param Database $dbw
  * @return int
  */
 public function insertOn($dbw)
 {
     global $wgDefaultExternalStore;
     wfProfileIn(__METHOD__);
     $data = $this->mText;
     $flags = Revision::compressRevisionText($data);
     # Write to external storage if required
     if ($wgDefaultExternalStore) {
         // Store and get the URL
         $data = ExternalStore::insertToDefault($data);
         if (!$data) {
             throw new MWException("Unable to store text to external storage");
         }
         if ($flags) {
             $flags .= ',';
         }
         $flags .= 'external';
     }
     # Record the text (or external storage URL) to the text table
     if (!isset($this->mTextId)) {
         $old_id = $dbw->nextSequenceValue('text_old_id_val');
         $dbw->insert('text', array('old_id' => $old_id, 'old_text' => $data, 'old_flags' => $flags), __METHOD__);
         $this->mTextId = $dbw->insertId();
     }
     # Record the edit in revisions
     $rev_id = isset($this->mId) ? $this->mId : $dbw->nextSequenceValue('rev_rev_id_val');
     $dbw->insert('revision', array('rev_id' => $rev_id, 'rev_page' => $this->mPage, 'rev_text_id' => $this->mTextId, 'rev_comment' => $this->mComment, 'rev_minor_edit' => $this->mMinorEdit ? 1 : 0, 'rev_user' => $this->mUser, 'rev_user_text' => $this->mUserText, 'rev_timestamp' => $dbw->timestamp($this->mTimestamp), 'rev_deleted' => $this->mDeleted, 'rev_len' => $this->mSize, 'rev_parent_id' => is_null($this->mParentId) ? $this->getPreviousRevisionId($dbw) : $this->mParentId), __METHOD__);
     $this->mId = !is_null($rev_id) ? $rev_id : $dbw->insertId();
     wfRunHooks('RevisionInsertComplete', array(&$this, $data, $flags));
     wfProfileOut(__METHOD__);
     return $this->mId;
 }
 /**
  * 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;
 }