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\Permissions\Authority;
|
||||
use MediaWiki\Permissions\PermissionStatus;
|
||||
use MediaWiki\Revision\MutableRevisionRecord;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Revision\RevisionStore;
|
||||
use MediaWiki\Revision\SlotRecord;
|
||||
|
|
@ -1027,52 +1026,12 @@ class MovePage {
|
|||
if ( $redirectContent ) {
|
||||
$redirectArticle = $this->wikiPageFactory->newFromTitle( $this->oldTitle );
|
||||
$redirectArticle->loadFromRow( false, WikiPage::READ_LOCKING ); // T48397
|
||||
$newid = $redirectArticle->insertOn( $dbw );
|
||||
if ( $newid ) { // sanity
|
||||
$this->oldTitle->resetArticleID( $newid );
|
||||
$redirectRevRecord = new MutableRevisionRecord( $this->oldTitle );
|
||||
$redirectRevRecord->setPageId( $newid )
|
||||
->setUser( $user )
|
||||
->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 );
|
||||
}
|
||||
$redirectArticle->newPageUpdater( $user )
|
||||
->setContent( SlotRecord::MAIN, $redirectContent )
|
||||
->addTags( $changeTags )
|
||||
->addSoftwareTag( 'mw-new-redirect' )
|
||||
->setUsePageCreationLog( false )
|
||||
->saveRevision( $commentObj );
|
||||
}
|
||||
|
||||
# Log the move
|
||||
|
|
|
|||
|
|
@ -193,6 +193,9 @@ class PageUpdater {
|
|||
*/
|
||||
private $flags = 0;
|
||||
|
||||
/** @var string[] */
|
||||
private $softwareTags = [];
|
||||
|
||||
/**
|
||||
* @param UserIdentity $author
|
||||
* @param WikiPage $wikiPage
|
||||
|
|
@ -253,6 +256,7 @@ class PageUpdater {
|
|||
]
|
||||
)
|
||||
);
|
||||
$this->softwareTags = $softwareTags;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -612,6 +616,21 @@ class PageUpdater {
|
|||
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.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue