+ /**
+ * @param Content $content Pre-save transform content
+ * @param integer $flags
+ * @param User $user
+ * @param string $summary
+ * @param array $meta
+ * @return Status
+ * @throws DBUnexpectedError
+ * @throws Exception
+ * @throws FatalError
+ * @throws MWException
+ */
+ private function doCreate(
+ Content $content, $flags, User $user, $summary, array $meta
+ ) {
+ global $wgUseRCPatrol, $wgUseNPPatrol;
+
+ $status = Status::newGood( array( 'new' => true, 'revision' => null ) );
+
+ $now = wfTimestampNow();
+ $newsize = $content->getSize();
+ $prepStatus = $content->prepareSave( $this, $flags, $meta['oldId'], $user );
+ $status->merge( $prepStatus );
+ if ( !$status->isOK() ) {
+ return $status;
+ }
+
+ $dbw = wfGetDB( DB_MASTER );
+ $dbw->begin( __METHOD__ );
+
+ // Add the page record unless one already exists for the title
+ $newid = $this->insertOn( $dbw );
+ if ( $newid === false ) {
+ $dbw->commit( __METHOD__ ); // nothing inserted
+ $status->fatal( 'edit-already-exists' );
+
+ return $status; // nothing done
+ }
+
+ // At this point we are now comitted to returning an OK
+ // status unless some DB query error or other exception comes up.
+ // This way callers don't have to call rollback() if $status is bad
+ // unless they actually try to catch exceptions (which is rare).
+
+ // @TODO: pass content object?!
+ $revision = new Revision( array(
+ 'page' => $newid,
+ 'title' => $this->mTitle, // for determining the default content model
+ 'comment' => $summary,
+ 'minor_edit' => $meta['minor'],
+ 'text' => $meta['serialized'],
+ 'len' => $newsize,
+ 'user' => $user->getId(),
+ 'user_text' => $user->getName(),
+ 'timestamp' => $now,
+ 'content_model' => $content->getModel(),
+ 'content_format' => $meta['serialFormat'],
+ ) );
+
+ // Save the revision text...
+ $revisionId = $revision->insertOn( $dbw );
+ // Update the page record with revision data
+ if ( !$this->updateRevisionOn( $dbw, $revision, 0 ) ) {
+ $dbw->rollback( __METHOD__ );
+ throw new MWException( "Failed to update page row to use new revision." );
+ }
+
+ Hooks::run( 'NewRevisionFromEditComplete', array( $this, $revision, false, $user ) );
+
+ // Update recentchanges
+ if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
+ // Mark as patrolled if the user can do so
+ $patrolled = ( $wgUseRCPatrol || $wgUseNPPatrol ) &&
+ !count( $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
+ // Add RC row to the DB
+ RecentChange::notifyNew(
+ $now,
+ $this->mTitle,
+ $revision->isMinor(),