89 $dbw = $this->loadBalancer->getConnectionRef(
DB_PRIMARY );
91 # Sneak a single revision into place
92 $user = $importableRevision->
getUserObj() ?: $this->userFactory->newFromName( $importableRevision->
getUser() );
94 $userId = $user->getId();
95 $userText = $user->getName();
98 $userText = $importableRevision->
getUser();
99 $user = $this->userFactory->newAnonymous();
103 Title::clearCaches();
105 $page = $this->wikiPageFactory->newFromTitle( $importableRevision->
getTitle() );
106 $page->loadPageData( WikiPage::READ_LATEST );
107 $mustCreatePage = !$page->exists();
108 if ( $mustCreatePage ) {
109 $pageId = $page->insertOn( $dbw );
111 $pageId = $page->getId();
116 $prior = (bool)$dbw->selectField(
'revision',
'1',
117 [
'rev_page' => $pageId,
118 'rev_timestamp' => $dbw->timestamp( $importableRevision->
getTimestamp() ),
124 $this->logger->debug( __METHOD__ .
": skipping existing revision for [[" .
125 $importableRevision->
getTitle()->getPrefixedText() .
"]], timestamp " .
135 $this->logger->debug( __METHOD__ .
': got invalid $pageId when importing revision of [[' .
136 $importableRevision->
getTitle()->getPrefixedText() .
']], timestamp ' .
144 $qi = $this->revisionStore->getQueryInfo();
145 $prevRevRow = $dbw->selectRow( $qi[
'tables'], $qi[
'fields'],
147 'rev_page' => $pageId,
148 'rev_timestamp <= ' . $dbw->addQuotes( $dbw->timestamp( $importableRevision->
getTimestamp() ) ),
152 'rev_timestamp DESC',
159 # @todo FIXME: Use original rev_id optionally (better for backups)
162 $revisionRecord->setParentId( $prevRevRow ? (
int)$prevRevRow->rev_id : 0 );
163 $revisionRecord->setComment(
164 CommentStoreComment::newUnsavedComment( $importableRevision->
getComment() )
168 $revUser = $this->userFactory->newFromAnyId( $userId, $userText );
169 }
catch ( InvalidArgumentException $ex ) {
170 $revUser = RequestContext::getMain()->getUser();
172 $revisionRecord->setUser( $revUser );
174 $originalRevision = $prevRevRow
175 ? $this->revisionStore->newRevisionFromRow(
177 IDBAccessObject::READ_LATEST,
182 foreach ( $importableRevision->
getSlotRoles() as $role ) {
183 if ( !$this->slotRoleRegistry->isDefinedRole( $role ) ) {
184 throw new MWException(
"Undefined slot role $role" );
187 $newContent = $importableRevision->
getContent( $role );
188 if ( !$originalRevision || !$originalRevision->hasSlot( $role ) ) {
189 $revisionRecord->setContent( $role, $newContent );
191 $originalSlot = $originalRevision->getSlot( $role );
192 if ( !$originalSlot->hasSameContent( $importableRevision->
getSlot( $role ) ) ) {
193 $revisionRecord->setContent( $role, $newContent );
195 $revisionRecord->inheritSlot( $originalRevision->getSlot( $role ) );
200 $revisionRecord->setTimestamp( $importableRevision->
getTimestamp() );
201 $revisionRecord->setMinorEdit( $importableRevision->
getMinor() );
202 $revisionRecord->setPageId( $pageId );
204 $latestRevId = $page->getLatest();
206 $inserted = $this->revisionStore->insertRevisionOn( $revisionRecord, $dbw );
207 if ( $latestRevId ) {
210 $latestRevTimestamp = (int)$this->revisionStore->getTimestampFromId(
212 RevisionStore::READ_LATEST
215 $latestRevTimestamp = 0;
217 if ( $importableRevision->
getTimestamp() >= $latestRevTimestamp ) {
218 $changed = $page->updateRevisionOn( $dbw, $inserted, $latestRevId );
223 $tags = $importableRevision->
getTags();
224 if ( $tags !== [] ) {
228 if ( $changed !==
false && $this->doUpdates ) {
229 $this->logger->debug( __METHOD__ .
": running updates" );
233 'created' => $mustCreatePage,
234 'oldcountable' =>
'no-change',
235 'causeAction' =>
'edit-page',
236 'causeAgent' => $user->getName(),
239 $updater = $this->pageUpdaterFactory->newDerivedPageDataUpdater( $page );
240 $updater->prepareUpdate( $inserted, $options );
241 $updater->doUpdates();