MovePage::moveSubpagesIfAllowed.
* The MWNamespace class is deprecated. Use MediaWikiServices::getNamespaceInfo.
* (T62260) Hard deprecate Language::getExtraUserToggles() method.
-* …
=== Other changes in 1.34 ===
* …
$this->newTitle = $newTitle;
}
+ /**
+ * Check if the user is allowed to perform the move.
+ *
+ * @param User $user
+ * @param string|null $reason To check against summary spam regex. Set to null to skip the check,
+ * for instance to display errors preemptively before the user has filled in a summary.
+ * @return Status
+ */
public function checkPermissions( User $user, $reason ) {
$status = new Status();
}
}
- if ( EditPage::matchSummarySpamRegex( $reason ) !== false ) {
+ if ( $reason !== null && EditPage::matchSummarySpamRegex( $reason ) !== false ) {
// This is kind of lame, won't display nice
$status->fatal( 'spamprotectiontext' );
}
* @return array|bool True on success, getUserPermissionsErrors()-like array on failure
*/
public function isValidMoveOperation( &$nt, $auth = true, $reason = '' ) {
+ wfDeprecated( __METHOD__, '1.25' );
+
global $wgUser;
if ( !( $nt instanceof Title ) ) {
public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true,
array $changeTags = []
) {
+ wfDeprecated( __METHOD__, '1.25' );
+
global $wgUser;
$mp = new MovePage( $this, $nt );
public function moveSubpages( $nt, $auth = true, $reason = '', $createRedirect = true,
array $changeTags = []
) {
- // Check permissions
- if ( !$this->userCan( 'move-subpages' ) ) {
- return [
- [ 'cant-move-subpages' ],
- ];
- }
- // Do the source and target namespaces support subpages?
- $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
- if ( !$nsInfo->hasSubpages( $this->mNamespace ) ) {
- return [
- [ 'namespace-nosubpages', $nsInfo->getCanonicalName( $this->mNamespace ) ],
- ];
- }
- if ( !$nsInfo->hasSubpages( $nt->getNamespace() ) ) {
- return [
- [ 'namespace-nosubpages', $nsInfo->getCanonicalName( $nt->getNamespace() ) ],
- ];
- }
+ wfDeprecated( __METHOD__, '1.34' );
global $wgUser;
+
$mp = new MovePage( $this, $nt );
$method = $auth ? 'moveSubpagesIfAllowed' : 'moveSubpages';
$result = $mp->$method( $wgUser, $reason, $createRedirect, $changeTags );
* @return bool
*/
public function isValidMoveTarget( $nt ) {
+ wfDeprecated( __METHOD__, '1.25' );
+
# Is it an existing file?
if ( $nt->getNamespace() == NS_FILE ) {
$file = wfLocalFile( $nt );
$deleteAndMove = false;
$moveOverShared = false;
+ $user = $this->getUser();
+
$newTitle = $this->newTitle;
if ( !$newTitle ) {
# If a title was supplied, probably from the move log revert
# link, check for validity. We can then show some diagnostic
# information and save a click.
- $newerr = $this->oldTitle->isValidMoveOperation( $newTitle );
- if ( is_array( $newerr ) ) {
- $err = $newerr;
+ $mp = new MovePage( $this->oldTitle, $newTitle );
+ $status = $mp->isValidMove();
+ $status->merge( $mp->checkPermissions( $user, null ) );
+ if ( $status->getErrors() ) {
+ $err = $status->getErrorsArray();
}
}
- $user = $this->getUser();
-
if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'articleexists'
&& $newTitle->quickUserCan( 'delete', $user )
) {
continue;
}
+ $mp = new MovePage( $oldSubpage, $newSubpage );
# This was copy-pasted from Renameuser, bleh.
- if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
+ if ( $newSubpage->exists() && !$mp->isValidMove()->isOk() ) {
$link = $linkRenderer->makeKnownLink( $newSubpage );
$extraOutput[] = $this->msg( 'movepage-page-exists' )->rawParams( $link )->escaped();
} else {
- $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason, $createRedirect );
+ $status = $mp->moveIfAllowed( $user, $this->reason, $createRedirect );
- if ( $success === true ) {
+ if ( $status->isOK() ) {
if ( $this->fixRedirects ) {
DoubleRedirectJob::fixRedirects( 'move', $oldSubpage, $newSubpage );
}
];
}
- /**
- * Integration test to catch regressions like T74870. Taken and modified
- * from SemanticMediaWiki
- *
- * @covers Title::moveTo
- */
- public function testTitleMoveCompleteIntegrationTest() {
- $oldTitle = Title::newFromText( 'Help:Some title' );
- WikiPage::factory( $oldTitle )->doEditContent( new WikitextContent( 'foo' ), 'bar' );
- $newTitle = Title::newFromText( 'Help:Some other title' );
- $this->assertNull(
- WikiPage::factory( $newTitle )->getRevision()
- );
-
- $this->assertTrue( $oldTitle->moveTo( $newTitle, false, 'test1', true ) );
- $this->assertNotNull(
- WikiPage::factory( $oldTitle )->getRevision()
- );
- $this->assertNotNull(
- WikiPage::factory( $newTitle )->getRevision()
- );
- }
-
/**
* Test for the move operation being aborted via the TitleMove hook
* @covers MovePage::move
$this->assertSame( $expected, $title->getLinkURL( $query, $query2, $proto ) );
}
+ /**
+ * Integration test to catch regressions like T74870. Taken and modified
+ * from SemanticMediaWiki
+ *
+ * @covers Title::moveTo
+ */
+ public function testTitleMoveCompleteIntegrationTest() {
+ $this->hideDeprecated( 'Title::moveTo' );
+
+ $oldTitle = Title::newFromText( 'Help:Some title' );
+ WikiPage::factory( $oldTitle )->doEditContent( new WikitextContent( 'foo' ), 'bar' );
+ $newTitle = Title::newFromText( 'Help:Some other title' );
+ $this->assertNull(
+ WikiPage::factory( $newTitle )->getRevision()
+ );
+
+ $this->assertTrue( $oldTitle->moveTo( $newTitle, false, 'test1', true ) );
+ $this->assertNotNull(
+ WikiPage::factory( $oldTitle )->getRevision()
+ );
+ $this->assertNotNull(
+ WikiPage::factory( $newTitle )->getRevision()
+ );
+ }
+
function tearDown() {
Title::clearCaches();
parent::tearDown();
* @covers Title::isValidMoveOperation
*/
public function testIsValidMoveOperation( $source, $target, $expected ) {
+ $this->hideDeprecated( 'Title::isValidMoveOperation' );
+
$this->setMwGlobals( 'wgContentHandlerUseDB', false );
$title = Title::newFromText( $source );
$nt = Title::newFromText( $target );