91 $dbw = $this->loadBalancer->getConnectionRef(
DB_PRIMARY );
93 # Sneak a single revision into place
94 $user = $importableRevision->
getUserObj() ?: $this->userFactory->newFromName( $importableRevision->
getUser() );
96 $userId = $user->getId();
97 $userText = $user->getName();
100 $userText = $importableRevision->
getUser();
101 $user = $this->userFactory->newAnonymous();
105 Title::clearCaches();
107 $page = $this->wikiPageFactory->newFromTitle( $importableRevision->
getTitle() );
108 $page->loadPageData( WikiPage::READ_LATEST );
109 $mustCreatePage = !$page->exists();
110 if ( $mustCreatePage ) {
111 $pageId = $page->insertOn( $dbw );
113 $pageId = $page->getId();
118 $prior = (bool)$dbw->selectField(
'revision',
'1',
119 [
'rev_page' => $pageId,
120 'rev_timestamp' => $dbw->timestamp( $importableRevision->
getTimestamp() ),
126 $this->logger->debug( __METHOD__ .
": skipping existing revision for [[" .
127 $importableRevision->
getTitle()->getPrefixedText() .
"]], timestamp " .
137 $this->logger->debug( __METHOD__ .
': got invalid $pageId when importing revision of [[' .
138 $importableRevision->
getTitle()->getPrefixedText() .
']], timestamp ' .
146 $qi = $this->revisionStore->getQueryInfo();
147 $prevRevRow = $dbw->selectRow( $qi[
'tables'], $qi[
'fields'],
149 'rev_page' => $pageId,
150 'rev_timestamp <= ' . $dbw->addQuotes( $dbw->timestamp( $importableRevision->
getTimestamp() ) ),
154 'rev_timestamp DESC',
161 # @todo FIXME: Use original rev_id optionally (better for backups)
164 $revisionRecord->setParentId( $prevRevRow ? (
int)$prevRevRow->rev_id : 0 );
165 $revisionRecord->setComment(
166 CommentStoreComment::newUnsavedComment( $importableRevision->
getComment() )
170 $revUser = $this->userFactory->newFromAnyId( $userId, $userText );
171 }
catch ( InvalidArgumentException $ex ) {
172 $revUser = RequestContext::getMain()->getUser();
174 $revisionRecord->setUser( $revUser );
176 $originalRevision = $prevRevRow
177 ? $this->revisionStore->newRevisionFromRow(
179 IDBAccessObject::READ_LATEST,
184 foreach ( $importableRevision->
getSlotRoles() as $role ) {
185 if ( !$this->slotRoleRegistry->isDefinedRole( $role ) ) {
186 throw new MWException(
"Undefined slot role $role" );
189 $newContent = $importableRevision->
getContent( $role );
190 if ( !$originalRevision || !$originalRevision->hasSlot( $role ) ) {
191 $revisionRecord->setContent( $role, $newContent );
193 $originalSlot = $originalRevision->getSlot( $role );
194 if ( !$originalSlot->hasSameContent( $importableRevision->
getSlot( $role ) ) ) {
195 $revisionRecord->setContent( $role, $newContent );
197 $revisionRecord->inheritSlot( $originalRevision->getSlot( $role ) );
202 $revisionRecord->setTimestamp( $importableRevision->
getTimestamp() );
203 $revisionRecord->setMinorEdit( $importableRevision->
getMinor() );
204 $revisionRecord->setPageId( $pageId );
206 $latestRevId = $page->getLatest();
208 $inserted = $this->revisionStore->insertRevisionOn( $revisionRecord, $dbw );
209 if ( $latestRevId ) {
212 $latestRevTimestamp = (int)$this->revisionStore->getTimestampFromId(
214 RevisionStore::READ_LATEST
217 $latestRevTimestamp = 0;
219 if ( $importableRevision->
getTimestamp() >= $latestRevTimestamp ) {
220 $changed = $page->updateRevisionOn( $dbw, $inserted, $latestRevId );
225 $tags = $importableRevision->
getTags();
226 if ( $tags !== [] ) {
230 if ( $changed !==
false && $this->doUpdates ) {
231 $this->logger->debug( __METHOD__ .
": running updates" );
235 'created' => $mustCreatePage,
236 'oldcountable' =>
'no-change',
237 'causeAction' =>
'import-page',
238 'causeAgent' => $user->getName(),
241 $updater = $this->pageUpdaterFactory->newDerivedPageDataUpdater( $page );
242 $updater->prepareUpdate( $inserted, $options );
243 $updater->doUpdates();