/** * 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 */ function insertOn(&$dbw) { global $wgDefaultExternalStore; $fname = 'Revision::insertOn'; wfProfileIn($fname); $data = $this->mText; $flags = Revision::compressRevisionText($data); # Write to external storage if required if ($wgDefaultExternalStore) { if (is_array($wgDefaultExternalStore)) { // Distribute storage across multiple clusters $store = $wgDefaultExternalStore[mt_rand(0, count($wgDefaultExternalStore) - 1)]; } else { $store = $wgDefaultExternalStore; } require_once 'ExternalStore.php'; // Store and get the URL $data = ExternalStore::insert($store, $data); if (!$data) { # This should only happen in the case of a configuration error, where the external store is not valid throw new MWException("Unable to store text to external storage {$store}"); } 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), $fname); $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), $fname); $this->mId = !is_null($rev_id) ? $rev_id : $dbw->insertId(); wfProfileOut($fname); return $this->mId; }