User:Leucosticte/Junkyard3

public function doEditContent( Content $content, $summary, $flags = 0, $baseRevId = false,               User $user = null, $serialisation_format = null, $timestamp = null        ) { global $wgUser, $wgUseAutomaticEditSummaries, $wgUseRCPatrol, $wgUseNPPatrol;

// Low-level sanity check if ( $this->mTitle->getText === '' ) { throw new MWException( 'Something is trying to edit an article with an empty title' ); }

wfProfileIn( __METHOD__ );

if ( !$content->getContentHandler->canBeUsedOn( $this->getTitle ) ) { wfProfileOut( __METHOD__ ); return Status::newFatal( 'content-not-allowed-here',                               ContentHandler::getLocalizedName( $content->getModel ),                                $this->getTitle->getPrefixedText ); }

$user = is_null( $user ) ? $wgUser : $user; $status = Status::newGood( array );

// Load the data from the master database if needed. // The caller may already loaded it from the master or even loaded it using // SELECT FOR UPDATE, so do not override that using clear. $this->loadPageData( 'fromdbmaster' );

$flags = $this->checkFlags( $flags );

// handle hook $hook_args = array( &$this, &$user, &$content, &$summary,                                                       $flags & EDIT_MINOR, null, null, &$flags, &$status );

if ( !wfRunHooks( 'PageContentSave', $hook_args )                       || !ContentHandler::runLegacyHooks( 'ArticleSave', $hook_args ) ) {

wfDebug( __METHOD__ . ": ArticleSave or ArticleSaveContent hook aborted save!\n" );

if ( $status->isOK ) { $status->fatal( 'edit-hook-aborted' ); }

wfProfileOut( __METHOD__ ); return $status; }

// Silently ignore EDIT_MINOR if not allowed $isminor = ( $flags & EDIT_MINOR ) && $user->isAllowed( 'minoredit' ); $bot = $flags & EDIT_FORCE_BOT;

$old_content = $this->getContent( Revision::RAW ); // current revision's content

$dbw = wfGetDB( DB_MASTER );

// See if the timestamp we're using is the latest timestamp; if not, pull the // revision that's slightly older than that one if ( $old_content) { $oldTimestamp = $this->getTimestamp; } else { $oldTimestamp = 0; // Page doesn't exist yet }               if ( $timestamp && $oldTimestamp && $timestamp < $oldTimestamp ) { $olderRevision = $dbw->selectRow (                       'revision',                        array( 'rev_id' ),                        array( 'rev_timestamp' => $timestamp ),                        __METHOD__,                        array( 'ORDER_BY' => 'rev_timestamp DESC' )                    ); $oldId = $olderRevision->rev_id; $this->mTimestamp = $timestamp; } else { $oldsize = $old_content ? $old_content->getSize : 0; $oldid = $this->getLatest; $oldIsRedirect = $this->isRedirect; $oldcountable = $this->isCountable; $now = wfTimestampNow; $this->mTimestamp = $now;

$handler = $content->getContentHandler;

// Provide autosummaries if one is not provided and autosummaries are enabled. if ( $wgUseAutomaticEditSummaries && $flags & EDIT_AUTOSUMMARY && $summary == '' ) { if ( !$old_content ) { $old_content = null; }                           $summary = $handler->getAutosummary( $old_content, $content, $flags ); }               }

$editInfo = $this->prepareContentForEdit( $content, null, $user, $serialisation_format ); $serialized = $editInfo->pst;

/**                * @var Content $content */               $content = $editInfo->pstContent; $newsize = $content->getSize;

if ( $flags & EDIT_UPDATE ) { // Update article, but only if changed. $status->value['new'] = false;

if ( !$oldid ) { // Article gone missing wfDebug( __METHOD__ . ": EDIT_UPDATE specified but article doesn't exist\n" ); $status->fatal( 'edit-gone-missing' );

wfProfileOut( __METHOD__ ); return $status; } elseif ( !$old_content ) { // Sanity check for bug 37225 wfProfileOut( __METHOD__ ); throw new MWException( "Could not find text for current revision {$oldid}." ); }

$revision = new Revision( array( 'page'      => $this->getId, 'title'     => $this->getTitle, // for determining the default content model 'comment'   => $summary, 'minor_edit' => $isminor, 'text'      => $serialized, 'len'       => $newsize, 'parent_id' => $oldid, 'user'      => $user->getId, 'user_text' => $user->getName, 'timestamp' => $timestamp, 'content_model' => $content->getModel, 'content_format' => $serialisation_format, ) ); // XXX: pass content object?!

// THIS IS THE CHANGE WE MADE (new hook) $hook_args = array( &$this, &$user, $content, $summary,                           $flags & EDIT_MINOR, &$flags, &$revision, &$status, $baseRevId ); wfRunHooks( 'PageContentSaveRevision', $hook_args );

$changed = !$content->equals( $old_content );

if ( $changed ) { if ( !$content->isValid ) { wfProfileOut( __METHOD__ ); throw new MWException( "New content failed validity check!" ); }

$dbw->begin( __METHOD__ );

$prepStatus = $content->prepareSave( $this, $flags, $baseRevId, $user ); $status->merge( $prepStatus );

if ( !$status->isOK ) { $dbw->rollback( __METHOD__ );

wfProfileOut( __METHOD__ ); return $status; }

$revisionId = $revision->insertOn( $dbw );

// Update page //				// Note that we use $this->mLatest instead of fetching a value from the master DB // during the course of this function. This makes sure that EditPage can detect // edit conflicts reliably, either by $ok here, or by $article->getTimestamp // before this function is called. A previous function used a separate query, this // creates a window where concurrent edits can cause an ignored edit conflict. $ok = $this->updateRevisionOn( $dbw, $revision, $oldid, $oldIsRedirect );

if ( !$ok ) { // Belated edit conflict! Run away!! $status->fatal( 'edit-conflict' );

$dbw->rollback( __METHOD__ );

wfProfileOut( __METHOD__ ); return $status; }

wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, $baseRevId, $user ) ); // Update recentchanges if ( !( $flags & EDIT_SUPPRESS_RC ) ) { // Mark as patrolled if the user can do so					$patrolled = $wgUseRCPatrol && !count(						$this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) ); // Add RC row to the DB					$rc = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $user, $summary,						$oldid, $this->getTimestamp, $bot, '', $oldsize, $newsize,						$revisionId, $patrolled					);

// Log auto-patrolled edits if ( $patrolled ) { PatrolLog::record( $rc, true, $user ); }				}				$user->incEditCount; $dbw->commit( __METHOD__ ); } else { // Bug 32948: revision ID must be set to page and // related variables correctly $revision->setId( $this->getLatest ); }

// Update links tables, site stats, etc.			$this->doEditUpdates(				$revision,				$user,				array( 'changed' => $changed, 'oldcountable' => $oldcountable )			);

if ( !$changed ) { $status->warning( 'edit-no-change' ); $revision = null; // Update page_touched, this is usually implicit in the page update // Other cache updates are done in onArticleEdit $this->mTitle->invalidateCache; }		} else { // Create new article $status->value['new'] = true;

$dbw->begin( __METHOD__ );

$prepStatus = $content->prepareSave( $this, $flags, $baseRevId, $user ); $status->merge( $prepStatus );

if ( !$status->isOK ) { $dbw->rollback( __METHOD__ );

wfProfileOut( __METHOD__ ); return $status; }

$status->merge( $prepStatus );

// Add the page record; stake our claim on this title! // This will return false if the article already exists $newid = $this->insertOn( $dbw );

if ( $newid === false ) { $dbw->rollback( __METHOD__ ); $status->fatal( 'edit-already-exists' );

wfProfileOut( __METHOD__ ); return $status; }

// Save the revision text... $revision = new Revision( array( 'page'      => $newid, 'title'     => $this->getTitle, // for determining the default content model 'comment'   => $summary, 'minor_edit' => $isminor, 'text'      => $serialized, 'len'       => $newsize, 'user'      => $user->getId, 'user_text' => $user->getName, 'timestamp' => $now, 'content_model' => $content->getModel, 'content_format' => $serialisation_format, ) );

// THIS IS THE CHANGE WE MADE (new hook) // FIXME: New name because in two places. $hook_args = array( &$this, &$user, $content, $summary,                           $flags & EDIT_MINOR, &$flags, &$revision, &$status, $baseRevId ); wfRunHooks( 'PageContentSaveRevision', $hook_args );