MovePage - use PageUpdater to create redirect page
After parent patch MovePage changed code is covered by tests, plus tested locally quite a bit. Seems to work. Change-Id: I0f8db203eb4aa767e5e1f3067f3a9e35835f38ea
This commit is contained in:
parent
b1b9c296b7
commit
e33f6b4b8e
2 changed files with 25 additions and 47 deletions
|
|
@ -31,7 +31,6 @@ use MediaWiki\Page\PageIdentity;
|
||||||
use MediaWiki\Page\WikiPageFactory;
|
use MediaWiki\Page\WikiPageFactory;
|
||||||
use MediaWiki\Permissions\Authority;
|
use MediaWiki\Permissions\Authority;
|
||||||
use MediaWiki\Permissions\PermissionStatus;
|
use MediaWiki\Permissions\PermissionStatus;
|
||||||
use MediaWiki\Revision\MutableRevisionRecord;
|
|
||||||
use MediaWiki\Revision\RevisionRecord;
|
use MediaWiki\Revision\RevisionRecord;
|
||||||
use MediaWiki\Revision\RevisionStore;
|
use MediaWiki\Revision\RevisionStore;
|
||||||
use MediaWiki\Revision\SlotRecord;
|
use MediaWiki\Revision\SlotRecord;
|
||||||
|
|
@ -1027,52 +1026,12 @@ class MovePage {
|
||||||
if ( $redirectContent ) {
|
if ( $redirectContent ) {
|
||||||
$redirectArticle = $this->wikiPageFactory->newFromTitle( $this->oldTitle );
|
$redirectArticle = $this->wikiPageFactory->newFromTitle( $this->oldTitle );
|
||||||
$redirectArticle->loadFromRow( false, WikiPage::READ_LOCKING ); // T48397
|
$redirectArticle->loadFromRow( false, WikiPage::READ_LOCKING ); // T48397
|
||||||
$newid = $redirectArticle->insertOn( $dbw );
|
$redirectArticle->newPageUpdater( $user )
|
||||||
if ( $newid ) { // sanity
|
->setContent( SlotRecord::MAIN, $redirectContent )
|
||||||
$this->oldTitle->resetArticleID( $newid );
|
->addTags( $changeTags )
|
||||||
$redirectRevRecord = new MutableRevisionRecord( $this->oldTitle );
|
->addSoftwareTag( 'mw-new-redirect' )
|
||||||
$redirectRevRecord->setPageId( $newid )
|
->setUsePageCreationLog( false )
|
||||||
->setUser( $user )
|
->saveRevision( $commentObj );
|
||||||
->setComment( $commentObj )
|
|
||||||
->setContent( SlotRecord::MAIN, $redirectContent )
|
|
||||||
->setTimestamp( MWTimestamp::now( TS_MW ) );
|
|
||||||
|
|
||||||
$inserted = $this->revisionStore->insertRevisionOn(
|
|
||||||
$redirectRevRecord,
|
|
||||||
$dbw
|
|
||||||
);
|
|
||||||
$redirectRevId = $inserted->getId();
|
|
||||||
$redirectArticle->updateRevisionOn( $dbw, $inserted, 0 );
|
|
||||||
|
|
||||||
$fakeTags = [];
|
|
||||||
$this->hookRunner->onRevisionFromEditComplete(
|
|
||||||
$redirectArticle,
|
|
||||||
$inserted,
|
|
||||||
false,
|
|
||||||
$user,
|
|
||||||
$fakeTags
|
|
||||||
);
|
|
||||||
|
|
||||||
// Clear all caches to make sure no stale information is used
|
|
||||||
// when parsing the newly created redirect. Without this, moves would fail
|
|
||||||
// under certain conditions when Lua core runs on the new page.
|
|
||||||
// It is not entirely clear why this is needed, we just found that
|
|
||||||
// it fixes the issue at hand (T279832).
|
|
||||||
Title::clearCaches();
|
|
||||||
|
|
||||||
$redirectArticle->doEditUpdates(
|
|
||||||
$inserted,
|
|
||||||
$user,
|
|
||||||
[ 'created' => true ]
|
|
||||||
);
|
|
||||||
|
|
||||||
// make a copy because of log entry below
|
|
||||||
$redirectTags = $changeTags;
|
|
||||||
if ( in_array( 'mw-new-redirect', ChangeTags::getSoftwareTags() ) ) {
|
|
||||||
$redirectTags[] = 'mw-new-redirect';
|
|
||||||
}
|
|
||||||
ChangeTags::addTags( $redirectTags, null, $redirectRevId, null );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Log the move
|
# Log the move
|
||||||
|
|
|
||||||
|
|
@ -193,6 +193,9 @@ class PageUpdater {
|
||||||
*/
|
*/
|
||||||
private $flags = 0;
|
private $flags = 0;
|
||||||
|
|
||||||
|
/** @var string[] */
|
||||||
|
private $softwareTags = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param UserIdentity $author
|
* @param UserIdentity $author
|
||||||
* @param WikiPage $wikiPage
|
* @param WikiPage $wikiPage
|
||||||
|
|
@ -253,6 +256,7 @@ class PageUpdater {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
$this->softwareTags = $softwareTags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -612,6 +616,21 @@ class PageUpdater {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets software tag to this update. If the tag is not defined in the
|
||||||
|
* current software tags, it's ignored.
|
||||||
|
*
|
||||||
|
* @since 1.38
|
||||||
|
* @param string $tag
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function addSoftwareTag( string $tag ): self {
|
||||||
|
if ( in_array( $tag, $this->softwareTags ) ) {
|
||||||
|
$this->addTag( $tag );
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of tags set using the addTag() method.
|
* Returns the list of tags set using the addTag() method.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue