Example #1
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;
 }
Example #2
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
  */
 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;
 }
Example #3
0
 /**
  * Insert a new empty page record for this article.
  * This *must* be followed up by creating a revision
  * and running $this->updateToLatest( $rev_id );
  * or else the record will be left in a funky state.
  * Best if all done inside a transaction.
  *
  * @param Database $dbw
  * @param string   $restrictions
  * @return int     The newly created page_id key
  * @private
  */
 function insertOn(&$dbw, $restrictions = '')
 {
     wfProfileIn(__METHOD__);
     $page_id = $dbw->nextSequenceValue('page_page_id_seq');
     $dbw->insert('page', array('page_id' => $page_id, 'page_namespace' => $this->mTitle->getNamespace(), 'page_title' => $this->mTitle->getDBkey(), 'page_counter' => 0, 'page_restrictions' => $restrictions, 'page_is_redirect' => 0, 'page_is_new' => 1, 'page_random' => wfRandom(), 'page_touched' => $dbw->timestamp(), 'page_latest' => 0, 'page_len' => 0), __METHOD__);
     $newid = $dbw->insertId();
     $this->mTitle->resetArticleId($newid);
     wfProfileOut(__METHOD__);
     return $newid;
 }
Example #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
  */
 function insertOn(&$dbw)
 {
     $fname = 'Revision::insertOn';
     wfProfileIn($fname);
     $mungedText = $this->mText;
     $flags = Revision::compressRevisionText($mungedText);
     # Record the text 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' => $mungedText, '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 = $dbw->insertId();
     wfProfileOut($fname);
     return $this->mId;
 }