MediaWiki  master
MovePage Class Reference

Handles the backend logic of moving a page from one title to another. More...

Collaboration diagram for MovePage:

Public Member Functions

 __construct (Title $oldTitle, Title $newTitle, ServiceOptions $options=null, ILoadBalancer $loadBalancer=null, NamespaceInfo $nsInfo=null, WatchedItemStoreInterface $watchedItems=null, RepoGroup $repoGroup=null, IContentHandlerFactory $contentHandlerFactory=null, RevisionStore $revisionStore=null, SpamChecker $spamChecker=null, HookContainer $hookContainer=null, WikiPageFactory $wikiPageFactory=null, UserFactory $userFactory=null, UserEditTracker $userEditTracker=null, MovePageFactory $movePageFactory=null, CollationFactory $collationFactory=null, PageUpdaterFactory $pageUpdaterFactory=null)
 
 authorizeMove (Authority $performer, string $reason=null)
 Authorize the move by $performer. More...
 
 checkPermissions (Authority $performer, $reason)
 Check if the user is allowed to perform the move. More...
 
 isValidMove ()
 Does various checks that the move is valid. More...
 
 move (UserIdentity $user, $reason=null, $createRedirect=true, array $changeTags=[])
 Move a page without taking user permissions into account. More...
 
 moveIfAllowed (Authority $performer, $reason=null, $createRedirect=true, array $changeTags=[])
 Same as move(), but with permissions checks. More...
 
 moveSubpages (UserIdentity $user, $reason=null, $createRedirect=true, array $changeTags=[])
 Move the source page's subpages to be subpages of the target page, without checking user permissions. More...
 
 moveSubpagesIfAllowed (Authority $performer, $reason=null, $createRedirect=true, array $changeTags=[])
 Move the source page's subpages to be subpages of the target page, with user permission checks. More...
 
 probablyCanMove (Authority $performer, string $reason=null)
 Check whether $performer can execute the move. More...
 

Public Attributes

CollationFactory $collationFactory
 
const CONSTRUCTOR_OPTIONS
 

Protected Member Functions

 isValidFileMove ()
 Checks for when a file is being moved. More...
 
 isValidMoveTarget ()
 Checks if $this can be moved to a given Title. More...
 

Protected Attributes

ILoadBalancer $loadBalancer
 
Title $newTitle
 
NamespaceInfo $nsInfo
 
Title $oldTitle
 
ServiceOptions $options
 
RepoGroup $repoGroup
 
WatchedItemStoreInterface $watchedItems
 

Private Member Functions

 authorizeInternal (callable $authorizer, Authority $performer, ?string $reason)
 
 moveFile ( $oldTitle, $newTitle)
 Move a file associated with a page to a new location. More...
 
 moveSubpagesInternal (callable $subpageMoveCallback)
 
 moveToInternal (UserIdentity $user, &$nt, $reason='', $createRedirect=true, array $changeTags=[])
 Move page to a title which is either a redirect to the source page or nonexistent. More...
 
 moveUnsafe (UserIdentity $user, $reason, $createRedirect, array $changeTags)
 Moves without any sort of safety or other checks. More...
 

Private Attributes

IContentHandlerFactory $contentHandlerFactory
 
HookRunner $hookRunner
 
MovePageFactory $movePageFactory
 
PageUpdaterFactory $pageUpdaterFactory
 
RevisionStore $revisionStore
 
SpamChecker $spamChecker
 
UserEditTracker $userEditTracker
 
UserFactory $userFactory
 
WikiPageFactory $wikiPageFactory
 

Detailed Description

Handles the backend logic of moving a page from one title to another.

Since
1.24

Definition at line 50 of file MovePage.php.

Constructor & Destructor Documentation

◆ __construct()

MovePage::__construct ( Title  $oldTitle,
Title  $newTitle,
ServiceOptions  $options = null,
ILoadBalancer  $loadBalancer = null,
NamespaceInfo  $nsInfo = null,
WatchedItemStoreInterface  $watchedItems = null,
RepoGroup  $repoGroup = null,
IContentHandlerFactory  $contentHandlerFactory = null,
RevisionStore  $revisionStore = null,
SpamChecker  $spamChecker = null,
HookContainer  $hookContainer = null,
WikiPageFactory  $wikiPageFactory = null,
UserFactory  $userFactory = null,
UserEditTracker  $userEditTracker = null,
MovePageFactory  $movePageFactory = null,
CollationFactory  $collationFactory = null,
PageUpdaterFactory  $pageUpdaterFactory = null 
)
Access: internal
Extensions should use the MovePageFactory.
Parameters
Title$oldTitle
Title$newTitle
ServiceOptions | null$options
ILoadBalancer | null$loadBalancer
NamespaceInfo | null$nsInfo
WatchedItemStoreInterface | null$watchedItems
RepoGroup | null$repoGroup
IContentHandlerFactory | null$contentHandlerFactory
RevisionStore | null$revisionStore
SpamChecker | null$spamChecker
HookContainer | null$hookContainer
WikiPageFactory | null$wikiPageFactory
UserFactory | null$userFactory
UserEditTracker | null$userEditTracker
MovePageFactory | null$movePageFactory
CollationFactory | null$collationFactory
PageUpdaterFactory | null$pageUpdaterFactory
Deprecated:
since 1.34, hard deprecated since 1.37. Use MovePageFactory instead.

Definition at line 159 of file MovePage.php.

References $collationFactory, $contentHandlerFactory, $loadBalancer, $movePageFactory, $newTitle, $nsInfo, $oldTitle, $options, $pageUpdaterFactory, $repoGroup, $revisionStore, $spamChecker, $userEditTracker, $userFactory, $watchedItems, $wikiPageFactory, and wfDeprecatedMsg().

Member Function Documentation

◆ authorizeInternal()

MovePage::authorizeInternal ( callable  $authorizer,
Authority  $performer,
?string  $reason 
)
private
Parameters
callable$authorizer( string $action, PageIdentity $target, PermissionStatus $status )
Authority$performer
string | null$reason
Returns
PermissionStatus

Definition at line 221 of file MovePage.php.

References MediaWiki\Permissions\Authority\isAllowed(), and Status\wrap().

Referenced by authorizeMove(), checkPermissions(), and probablyCanMove().

◆ authorizeMove()

MovePage::authorizeMove ( Authority  $performer,
string  $reason = null 
)

Authorize the move by $performer.

Note
this method should be used right before the actual move is performed. To check whether a current performer has the potential to move the page, use self::probablyCanMove instead.
Parameters
Authority$performer
string | null$reason
Returns
PermissionStatus

Definition at line 288 of file MovePage.php.

References authorizeInternal(), and MediaWiki\Permissions\Authority\authorizeWrite().

Referenced by moveIfAllowed().

◆ checkPermissions()

MovePage::checkPermissions ( Authority  $performer,
  $reason 
)

Check if the user is allowed to perform the move.

Parameters
Authority$performer
string | null$reasonTo 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.
Deprecated:
since 1.36, use ::authorizeMove or ::probablyCanMove instead.
Returns
Status

Definition at line 307 of file MovePage.php.

References authorizeInternal(), MediaWiki\Permissions\Authority\definitelyCan(), and Status\wrap().

◆ isValidFileMove()

MovePage::isValidFileMove ( )
protected

Checks for when a file is being moved.

Returns
Status

Definition at line 405 of file MovePage.php.

References $file, File\checkExtensionCompatibility(), NS_FILE, and wfStripIllegalFilenameChars().

Referenced by isValidMove().

◆ isValidMove()

MovePage::isValidMove ( )

Does various checks that the move is valid.

Only things based on the two titles should be checked here.

Returns
Status

Definition at line 325 of file MovePage.php.

References ContentHandler\getLocalizedName(), isValidFileMove(), NS_FILE, and wfMessage().

Referenced by move(), and moveIfAllowed().

◆ isValidMoveTarget()

MovePage::isValidMoveTarget ( )
protected

Checks if $this can be moved to a given Title.

  • Selects for update, so don't call it unless you mean business
Since
1.25
Returns
bool

Definition at line 434 of file MovePage.php.

References $content, $file, NS_FILE, and wfDebug().

◆ move()

MovePage::move ( UserIdentity  $user,
  $reason = null,
  $createRedirect = true,
array  $changeTags = [] 
)

Move a page without taking user permissions into account.

Only checks if the move is itself invalid, e.g., trying to move a special page or trying to move a page onto one that already exists.

Parameters
UserIdentity$user
string | null$reason
bool | null$createRedirect
string[]$changeTagsChange tags to apply to the entry in the move log
Returns
Status

Definition at line 490 of file MovePage.php.

References isValidMove(), and moveUnsafe().

◆ moveFile()

MovePage::moveFile (   $oldTitle,
  $newTitle 
)
private

Move a file associated with a page to a new location.

Can also be used to revert after a DB failure.

Access: internal
Parameters
Title$oldTitleOld location to move the file from.
Title$newTitleNew location to move the file to.
Returns
Status

Definition at line 812 of file MovePage.php.

References $file, $newTitle, $oldTitle, and StatusValue\newGood().

Referenced by moveUnsafe().

◆ moveIfAllowed()

MovePage::moveIfAllowed ( Authority  $performer,
  $reason = null,
  $createRedirect = true,
array  $changeTags = [] 
)

Same as move(), but with permissions checks.

Parameters
Authority$performer
string | null$reason
bool | null$createRedirectIgnored if user doesn't have suppressredirect permission
string[]$changeTagsChange tags to apply to the entry in the move log
Returns
Status

Definition at line 510 of file MovePage.php.

References authorizeMove(), ChangeTags\canAddTagsAccompanyingChange(), MediaWiki\Permissions\Authority\getUser(), MediaWiki\Permissions\Authority\isAllowed(), isValidMove(), and moveUnsafe().

◆ moveSubpages()

MovePage::moveSubpages ( UserIdentity  $user,
  $reason = null,
  $createRedirect = true,
array  $changeTags = [] 
)

Move the source page's subpages to be subpages of the target page, without checking user permissions.

The caller is responsible for moving the source page itself. We will still not do moves that are inherently not allowed, nor will we move more than $wgMaximumMovedPages.

Parameters
UserIdentity$user
string | null$reasonThe reason for the move
bool | null$createRedirectWhether to create redirects from the old subpages to the new ones
string[]$changeTagsApplied to entries in the move log and redirect page revision
Returns
Status Good if no errors occurred. Ok if at least one page succeeded. The "value" of the top-level status is an array containing the per-title status for each page. For any move that succeeded, the "value" of the per-title status is the new page title.

Definition at line 549 of file MovePage.php.

References moveSubpagesInternal().

◆ moveSubpagesIfAllowed()

MovePage::moveSubpagesIfAllowed ( Authority  $performer,
  $reason = null,
  $createRedirect = true,
array  $changeTags = [] 
)

Move the source page's subpages to be subpages of the target page, with user permission checks.

The caller is responsible for moving the source page itself.

Parameters
Authority$performer
string | null$reasonThe reason for the move
bool | null$createRedirectWhether to create redirects from the old subpages to the new ones. Ignored if the user doesn't have the 'suppressredirect' right.
string[]$changeTagsApplied to entries in the move log and redirect page revision
Returns
Status Good if no errors occurred. Ok if at least one page succeeded. The "value" of the top-level status is an array containing the per-title status for each page. For any move that succeeded, the "value" of the per-title status is the new page title.

Definition at line 574 of file MovePage.php.

References MediaWiki\Permissions\Authority\authorizeWrite(), moveSubpagesInternal(), and StatusValue\newFatal().

◆ moveSubpagesInternal()

MovePage::moveSubpagesInternal ( callable  $subpageMoveCallback)
private
Parameters
callable$subpageMoveCallback
Returns
Status
Exceptions
MWException

Definition at line 594 of file MovePage.php.

References StringUtils\escapeRegexReplacement(), Title\makeTitleSafe(), StatusValue\newFatal(), and StatusValue\newGood().

Referenced by moveSubpages(), and moveSubpagesIfAllowed().

◆ moveToInternal()

MovePage::moveToInternal ( UserIdentity  $user,
$nt,
  $reason = '',
  $createRedirect = true,
array  $changeTags = [] 
)
private

Move page to a title which is either a redirect to the source page or nonexistent.

Todo:
This was basically directly moved from Title, it should be split into smaller functions
Parameters
UserIdentity$userdoing the move
Title&$ntThe page to move to, which should be a redirect or non-existent
string$reasonThe reason for the move
bool$createRedirectWhether to leave a redirect at the old title. Does not check if the user has the suppressredirect right
string[]$changeTagsChange tags to apply to the entry in the move log
Returns
RevisionRecord|Status The revision created by the move or Status object on failure

Definition at line 841 of file MovePage.php.

References $oldTitle, $options, DB_PRIMARY, EDIT_SUPPRESS_RC, MediaWiki\User\UserIdentity\getName(), RequestContext\newExtraneousContext(), LogFormatter\newFromEntry(), CommentStoreComment\newUnsavedComment(), NS_CATEGORY, WikiPage\onArticleCreate(), WikiPage\onArticleDelete(), and wfMessage().

Referenced by moveUnsafe().

◆ moveUnsafe()

MovePage::moveUnsafe ( UserIdentity  $user,
  $reason,
  $createRedirect,
array  $changeTags 
)
private

Moves without any sort of safety or other checks.

Hooks can still fail the move, however.

Parameters
UserIdentity$user
string$reason
bool$createRedirect
string[]$changeTagsChange tags to apply to the entry in the move log
Returns
Status

Definition at line 665 of file MovePage.php.

References $res, DeferredUpdates\addUpdate(), DB_PRIMARY, moveFile(), moveToInternal(), StatusValue\newGood(), NS_FILE, and wfMessage().

Referenced by move(), and moveIfAllowed().

◆ probablyCanMove()

MovePage::probablyCanMove ( Authority  $performer,
string  $reason = null 
)

Check whether $performer can execute the move.

Note
this method does not guarantee full permissions check, so it should only be used to to decide whether to show a move form. To authorize the move action use self::authorizeMove instead.
Parameters
Authority$performer
string | null$reason
Returns
PermissionStatus

Definition at line 267 of file MovePage.php.

References authorizeInternal(), and MediaWiki\Permissions\Authority\probablyCan().

Member Data Documentation

◆ $collationFactory

CollationFactory MovePage::$collationFactory

Definition at line 124 of file MovePage.php.

Referenced by __construct().

◆ $contentHandlerFactory

IContentHandlerFactory MovePage::$contentHandlerFactory
private

Definition at line 90 of file MovePage.php.

Referenced by __construct().

◆ $hookRunner

HookRunner MovePage::$hookRunner
private

Definition at line 105 of file MovePage.php.

◆ $loadBalancer

ILoadBalancer MovePage::$loadBalancer
protected

Definition at line 70 of file MovePage.php.

Referenced by __construct().

◆ $movePageFactory

MovePageFactory MovePage::$movePageFactory
private

Definition at line 121 of file MovePage.php.

Referenced by __construct().

◆ $newTitle

Title MovePage::$newTitle
protected

Definition at line 60 of file MovePage.php.

Referenced by __construct(), and moveFile().

◆ $nsInfo

NamespaceInfo MovePage::$nsInfo
protected

Definition at line 75 of file MovePage.php.

Referenced by __construct().

◆ $oldTitle

Title MovePage::$oldTitle
protected

Definition at line 55 of file MovePage.php.

Referenced by __construct(), moveFile(), and moveToInternal().

◆ $options

ServiceOptions MovePage::$options
protected

Definition at line 65 of file MovePage.php.

Referenced by __construct(), and moveToInternal().

◆ $pageUpdaterFactory

PageUpdaterFactory MovePage::$pageUpdaterFactory
private

Definition at line 135 of file MovePage.php.

Referenced by __construct().

◆ $repoGroup

RepoGroup MovePage::$repoGroup
protected

Definition at line 85 of file MovePage.php.

Referenced by __construct().

◆ $revisionStore

RevisionStore MovePage::$revisionStore
private

Definition at line 95 of file MovePage.php.

Referenced by __construct().

◆ $spamChecker

SpamChecker MovePage::$spamChecker
private

Definition at line 100 of file MovePage.php.

Referenced by __construct().

◆ $userEditTracker

UserEditTracker MovePage::$userEditTracker
private

Definition at line 118 of file MovePage.php.

Referenced by __construct().

◆ $userFactory

UserFactory MovePage::$userFactory
private

Definition at line 115 of file MovePage.php.

Referenced by __construct().

◆ $watchedItems

WatchedItemStoreInterface MovePage::$watchedItems
protected

Definition at line 80 of file MovePage.php.

Referenced by __construct().

◆ $wikiPageFactory

WikiPageFactory MovePage::$wikiPageFactory
private

Definition at line 110 of file MovePage.php.

Referenced by __construct().

◆ CONSTRUCTOR_OPTIONS

const MovePage::CONSTRUCTOR_OPTIONS
Initial value:
= [
'CategoryCollation',
'MaximumMovedPages',
]
Access: internal
For use by PageCommandFactory

Definition at line 129 of file MovePage.php.

Referenced by Page\PageCommandFactory\newMovePage().


The documentation for this class was generated from the following file: