2020-01-11 23:49:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
2024-08-07 21:37:34 +00:00
|
|
|
namespace MediaWiki\Content;
|
|
|
|
|
|
|
|
|
|
use ChangeTags;
|
|
|
|
|
use LogFormatterFactory;
|
|
|
|
|
use ManualLogEntry;
|
2024-02-08 14:56:54 +00:00
|
|
|
use MediaWiki\Context\DerivativeContext;
|
|
|
|
|
use MediaWiki\Context\IContextSource;
|
|
|
|
|
use MediaWiki\Context\RequestContext;
|
2020-05-30 19:10:58 +00:00
|
|
|
use MediaWiki\HookContainer\HookContainer;
|
|
|
|
|
use MediaWiki\HookContainer\HookRunner;
|
2024-06-16 18:18:23 +00:00
|
|
|
use MediaWiki\Message\Message;
|
2021-03-02 21:29:46 +00:00
|
|
|
use MediaWiki\Page\PageIdentity;
|
2022-04-10 14:37:23 +00:00
|
|
|
use MediaWiki\Page\WikiPageFactory;
|
2021-03-02 21:29:46 +00:00
|
|
|
use MediaWiki\Permissions\Authority;
|
|
|
|
|
use MediaWiki\Permissions\PermissionStatus;
|
2020-05-30 19:10:58 +00:00
|
|
|
use MediaWiki\Revision\RevisionLookup;
|
2020-04-13 00:10:07 +00:00
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2023-08-25 12:29:41 +00:00
|
|
|
use MediaWiki\Status\Status;
|
2021-03-02 21:29:46 +00:00
|
|
|
use MediaWiki\User\UserFactory;
|
2024-08-07 21:37:34 +00:00
|
|
|
use MWException;
|
|
|
|
|
use WikiPage;
|
2020-01-11 23:49:41 +00:00
|
|
|
|
|
|
|
|
/**
|
2022-04-08 15:13:15 +00:00
|
|
|
* Backend logic for changing the content model of a page.
|
2020-01-11 23:49:41 +00:00
|
|
|
*
|
2022-04-08 15:13:15 +00:00
|
|
|
* Note that you can create a new page directly with a desired content
|
|
|
|
|
* model and format, e.g. via EditPage or externally from ApiEditPage.
|
2020-01-11 23:49:41 +00:00
|
|
|
*
|
|
|
|
|
* @since 1.35
|
2020-04-11 08:10:18 +00:00
|
|
|
* @author DannyS712
|
2020-01-11 23:49:41 +00:00
|
|
|
*/
|
|
|
|
|
class ContentModelChange {
|
2020-05-30 19:10:58 +00:00
|
|
|
/** @var IContentHandlerFactory */
|
|
|
|
|
private $contentHandlerFactory;
|
|
|
|
|
/** @var HookRunner */
|
|
|
|
|
private $hookRunner;
|
|
|
|
|
/** @var RevisionLookup */
|
|
|
|
|
private $revLookup;
|
2021-03-02 21:29:46 +00:00
|
|
|
/** @var UserFactory */
|
|
|
|
|
private $userFactory;
|
2024-07-12 21:46:41 +00:00
|
|
|
private LogFormatterFactory $logFormatterFactory;
|
2021-03-02 21:29:46 +00:00
|
|
|
/** @var Authority making the change */
|
|
|
|
|
private $performer;
|
2020-05-30 19:10:58 +00:00
|
|
|
/** @var WikiPage */
|
2020-01-11 23:49:41 +00:00
|
|
|
private $page;
|
2022-04-10 14:37:23 +00:00
|
|
|
/** @var PageIdentity */
|
|
|
|
|
private $pageIdentity;
|
2020-05-30 19:10:58 +00:00
|
|
|
/** @var string */
|
2020-01-11 23:49:41 +00:00
|
|
|
private $newModel;
|
2020-05-30 19:10:58 +00:00
|
|
|
/** @var string[] tags to add */
|
2020-01-11 23:49:41 +00:00
|
|
|
private $tags;
|
2020-05-30 19:10:58 +00:00
|
|
|
/** @var Content */
|
2020-01-11 23:49:41 +00:00
|
|
|
private $newContent;
|
2020-05-30 19:10:58 +00:00
|
|
|
/** @var int|false latest revision id, or false if creating */
|
2020-01-11 23:49:41 +00:00
|
|
|
private $latestRevId;
|
2020-05-30 19:10:58 +00:00
|
|
|
/** @var string 'new' or 'change' */
|
2020-01-11 23:49:41 +00:00
|
|
|
private $logAction;
|
2020-05-30 19:10:58 +00:00
|
|
|
/** @var string 'apierror-' or empty string, for status messages */
|
2020-01-11 23:49:41 +00:00
|
|
|
private $msgPrefix;
|
|
|
|
|
|
2020-05-30 19:10:58 +00:00
|
|
|
/**
|
2022-04-08 15:13:15 +00:00
|
|
|
* @internal Create via the ContentModelChangeFactory service.
|
2024-08-07 21:37:34 +00:00
|
|
|
*
|
2020-05-30 19:10:58 +00:00
|
|
|
* @param IContentHandlerFactory $contentHandlerFactory
|
|
|
|
|
* @param HookContainer $hookContainer
|
|
|
|
|
* @param RevisionLookup $revLookup
|
2021-03-02 21:29:46 +00:00
|
|
|
* @param UserFactory $userFactory
|
2022-04-10 14:37:23 +00:00
|
|
|
* @param WikiPageFactory $wikiPageFactory
|
2024-07-12 21:46:41 +00:00
|
|
|
* @param LogFormatterFactory $logFormatterFactory
|
2021-03-02 21:29:46 +00:00
|
|
|
* @param Authority $performer
|
2022-04-10 14:37:23 +00:00
|
|
|
* @param PageIdentity $page
|
2020-05-30 19:10:58 +00:00
|
|
|
* @param string $newModel
|
|
|
|
|
*/
|
2020-01-11 23:49:41 +00:00
|
|
|
public function __construct(
|
2020-05-30 19:10:58 +00:00
|
|
|
IContentHandlerFactory $contentHandlerFactory,
|
|
|
|
|
HookContainer $hookContainer,
|
|
|
|
|
RevisionLookup $revLookup,
|
2021-03-02 21:29:46 +00:00
|
|
|
UserFactory $userFactory,
|
2022-04-10 14:37:23 +00:00
|
|
|
WikiPageFactory $wikiPageFactory,
|
2024-07-12 21:46:41 +00:00
|
|
|
LogFormatterFactory $logFormatterFactory,
|
2021-03-02 21:29:46 +00:00
|
|
|
Authority $performer,
|
2022-04-10 14:37:23 +00:00
|
|
|
PageIdentity $page,
|
2020-05-30 19:10:58 +00:00
|
|
|
string $newModel
|
2020-01-11 23:49:41 +00:00
|
|
|
) {
|
2020-05-30 19:10:58 +00:00
|
|
|
$this->contentHandlerFactory = $contentHandlerFactory;
|
|
|
|
|
$this->hookRunner = new HookRunner( $hookContainer );
|
|
|
|
|
$this->revLookup = $revLookup;
|
2021-03-02 21:29:46 +00:00
|
|
|
$this->userFactory = $userFactory;
|
2024-07-12 21:46:41 +00:00
|
|
|
$this->logFormatterFactory = $logFormatterFactory;
|
2020-05-30 19:10:58 +00:00
|
|
|
|
2021-03-02 21:29:46 +00:00
|
|
|
$this->performer = $performer;
|
2022-04-10 14:37:23 +00:00
|
|
|
$this->page = $wikiPageFactory->newFromTitle( $page );
|
|
|
|
|
$this->pageIdentity = $page;
|
2020-01-11 23:49:41 +00:00
|
|
|
$this->newModel = $newModel;
|
|
|
|
|
|
|
|
|
|
// SpecialChangeContentModel doesn't support tags
|
|
|
|
|
// api can specify tags via ::setTags, which also checks if user can add
|
|
|
|
|
// the tags specified
|
|
|
|
|
$this->tags = [];
|
|
|
|
|
|
|
|
|
|
// Requires createNewContent to be called first
|
|
|
|
|
$this->logAction = '';
|
|
|
|
|
|
|
|
|
|
// Defaults to nothing, for special page
|
|
|
|
|
$this->msgPrefix = '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $msgPrefix
|
|
|
|
|
*/
|
|
|
|
|
public function setMessagePrefix( $msgPrefix ) {
|
|
|
|
|
$this->msgPrefix = $msgPrefix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-02 21:29:46 +00:00
|
|
|
* @param callable $authorizer ( string $action, PageIdentity $target, PermissionStatus $status )
|
2024-08-07 21:37:34 +00:00
|
|
|
*
|
2021-03-02 21:29:46 +00:00
|
|
|
* @return PermissionStatus
|
2020-01-11 23:49:41 +00:00
|
|
|
*/
|
2021-03-02 21:29:46 +00:00
|
|
|
private function authorizeInternal( callable $authorizer ): PermissionStatus {
|
2020-01-11 23:49:41 +00:00
|
|
|
$current = $this->page->getTitle();
|
|
|
|
|
$titleWithNewContentModel = clone $current;
|
|
|
|
|
$titleWithNewContentModel->setContentModel( $this->newModel );
|
|
|
|
|
|
2021-03-02 21:29:46 +00:00
|
|
|
$status = PermissionStatus::newEmpty();
|
2022-04-10 14:37:23 +00:00
|
|
|
$authorizer( 'editcontentmodel', $this->pageIdentity, $status );
|
|
|
|
|
$authorizer( 'edit', $this->pageIdentity, $status );
|
2021-03-02 21:29:46 +00:00
|
|
|
$authorizer( 'editcontentmodel', $titleWithNewContentModel, $status );
|
|
|
|
|
$authorizer( 'edit', $titleWithNewContentModel, $status );
|
2024-08-07 21:37:34 +00:00
|
|
|
|
2021-03-02 21:29:46 +00:00
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-09-02 19:08:26 +00:00
|
|
|
* Check whether $performer can execute the content model change.
|
2021-03-02 21:29:46 +00:00
|
|
|
*
|
|
|
|
|
* @note this method does not guarantee full permissions check, so it should
|
2022-09-02 19:08:26 +00:00
|
|
|
* only be used to to decide whether to show a content model change form.
|
|
|
|
|
* To authorize the content model change action use {@link self::authorizeChange} instead.
|
2021-03-02 21:29:46 +00:00
|
|
|
*
|
|
|
|
|
* @return PermissionStatus
|
|
|
|
|
*/
|
|
|
|
|
public function probablyCanChange(): PermissionStatus {
|
|
|
|
|
return $this->authorizeInternal(
|
|
|
|
|
function ( string $action, PageIdentity $target, PermissionStatus $status ) {
|
|
|
|
|
return $this->performer->probablyCan( $action, $target, $status );
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-09-02 19:08:26 +00:00
|
|
|
* Authorize the content model change by $performer.
|
2021-03-02 21:29:46 +00:00
|
|
|
*
|
2022-09-02 19:08:26 +00:00
|
|
|
* @note this method should be used right before the actual content model change is performed.
|
|
|
|
|
* To check whether a current performer has the potential to change the content model of the page,
|
2021-03-02 21:29:46 +00:00
|
|
|
* use {@link self::probablyCanChange} instead.
|
|
|
|
|
*
|
|
|
|
|
* @return PermissionStatus
|
|
|
|
|
*/
|
|
|
|
|
public function authorizeChange(): PermissionStatus {
|
|
|
|
|
return $this->authorizeInternal(
|
|
|
|
|
function ( string $action, PageIdentity $target, PermissionStatus $status ) {
|
|
|
|
|
return $this->performer->authorizeWrite( $action, $target, $status );
|
|
|
|
|
}
|
2020-01-11 23:49:41 +00:00
|
|
|
);
|
2021-03-02 21:29:46 +00:00
|
|
|
}
|
2020-01-11 23:49:41 +00:00
|
|
|
|
2021-03-02 21:29:46 +00:00
|
|
|
/**
|
|
|
|
|
* Check user can edit and editcontentmodel before and after
|
|
|
|
|
*
|
|
|
|
|
* @deprecated since 1.36. Use ::probablyCanChange or ::authorizeChange instead.
|
2024-06-06 01:05:36 +00:00
|
|
|
* @return array Errors in legacy error array format
|
2021-03-02 21:29:46 +00:00
|
|
|
*/
|
|
|
|
|
public function checkPermissions() {
|
|
|
|
|
wfDeprecated( __METHOD__, '1.36' );
|
|
|
|
|
$status = $this->authorizeInternal(
|
|
|
|
|
function ( string $action, PageIdentity $target, PermissionStatus $status ) {
|
|
|
|
|
return $this->performer->definitelyCan( $action, $target, $status );
|
|
|
|
|
} );
|
|
|
|
|
return $status->toLegacyErrorArray();
|
2020-01-11 23:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Specify the tags the user wants to add, and check permissions
|
|
|
|
|
*
|
|
|
|
|
* @param string[] $tags
|
2024-08-07 21:37:34 +00:00
|
|
|
*
|
2020-01-11 23:49:41 +00:00
|
|
|
* @return Status
|
|
|
|
|
*/
|
|
|
|
|
public function setTags( $tags ) {
|
2021-03-02 21:29:46 +00:00
|
|
|
$tagStatus = ChangeTags::canAddTagsAccompanyingChange( $tags, $this->performer );
|
2020-01-11 23:49:41 +00:00
|
|
|
if ( $tagStatus->isOK() ) {
|
|
|
|
|
$this->tags = $tags;
|
2024-08-07 21:37:34 +00:00
|
|
|
|
2020-01-11 23:49:41 +00:00
|
|
|
return Status::newGood();
|
|
|
|
|
} else {
|
|
|
|
|
return $tagStatus;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Status
|
|
|
|
|
*/
|
|
|
|
|
private function createNewContent() {
|
2020-05-30 19:10:58 +00:00
|
|
|
$contentHandlerFactory = $this->contentHandlerFactory;
|
2020-01-11 23:49:41 +00:00
|
|
|
|
|
|
|
|
$title = $this->page->getTitle();
|
2022-04-10 14:37:23 +00:00
|
|
|
$latestRevRecord = $this->revLookup->getRevisionByTitle( $this->pageIdentity );
|
2020-01-11 23:49:41 +00:00
|
|
|
|
2020-04-13 00:10:07 +00:00
|
|
|
if ( $latestRevRecord ) {
|
|
|
|
|
$latestContent = $latestRevRecord->getContent( SlotRecord::MAIN );
|
2020-01-11 23:49:41 +00:00
|
|
|
$latestHandler = $latestContent->getContentHandler();
|
|
|
|
|
$latestModel = $latestContent->getModel();
|
|
|
|
|
if ( !$latestHandler->supportsDirectEditing() ) {
|
|
|
|
|
// Only reachable via api
|
|
|
|
|
return Status::newFatal(
|
|
|
|
|
'apierror-changecontentmodel-nodirectediting',
|
|
|
|
|
ContentHandler::getLocalizedName( $latestModel )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$newModel = $this->newModel;
|
|
|
|
|
if ( $newModel === $latestModel ) {
|
|
|
|
|
// Only reachable via api
|
|
|
|
|
return Status::newFatal( 'apierror-nochanges' );
|
|
|
|
|
}
|
|
|
|
|
$newHandler = $contentHandlerFactory->getContentHandler( $newModel );
|
|
|
|
|
if ( !$newHandler->canBeUsedOn( $title ) ) {
|
|
|
|
|
// Only reachable via api
|
|
|
|
|
return Status::newFatal(
|
|
|
|
|
'apierror-changecontentmodel-cannotbeused',
|
|
|
|
|
ContentHandler::getLocalizedName( $newModel ),
|
|
|
|
|
Message::plaintextParam( $title->getPrefixedText() )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$newContent = $newHandler->unserializeContent(
|
|
|
|
|
$latestContent->serialize()
|
|
|
|
|
);
|
|
|
|
|
} catch ( MWException $e ) {
|
|
|
|
|
// Messages: changecontentmodel-cannot-convert,
|
|
|
|
|
// apierror-changecontentmodel-cannot-convert
|
|
|
|
|
return Status::newFatal(
|
|
|
|
|
$this->msgPrefix . 'changecontentmodel-cannot-convert',
|
|
|
|
|
Message::plaintextParam( $title->getPrefixedText() ),
|
|
|
|
|
ContentHandler::getLocalizedName( $newModel )
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-04-13 00:10:07 +00:00
|
|
|
$this->latestRevId = $latestRevRecord->getId();
|
2020-01-11 23:49:41 +00:00
|
|
|
$this->logAction = 'change';
|
|
|
|
|
} else {
|
|
|
|
|
// Page doesn't exist, create an empty content object
|
|
|
|
|
$newContent = $contentHandlerFactory
|
|
|
|
|
->getContentHandler( $this->newModel )
|
|
|
|
|
->makeEmptyContent();
|
|
|
|
|
$this->latestRevId = false;
|
|
|
|
|
$this->logAction = 'new';
|
|
|
|
|
}
|
|
|
|
|
$this->newContent = $newContent;
|
2024-08-07 21:37:34 +00:00
|
|
|
|
2020-01-11 23:49:41 +00:00
|
|
|
return Status::newGood();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-02 21:29:46 +00:00
|
|
|
* Handle change and logging after validation
|
2020-01-11 23:49:41 +00:00
|
|
|
*
|
|
|
|
|
* Can still be intercepted by hooks
|
|
|
|
|
*
|
|
|
|
|
* @param IContextSource $context
|
|
|
|
|
* @param string $comment
|
|
|
|
|
* @param bool $bot Mark as a bot edit if the user can
|
2024-08-07 21:37:34 +00:00
|
|
|
*
|
2020-01-11 23:49:41 +00:00
|
|
|
* @return Status
|
|
|
|
|
*/
|
|
|
|
|
public function doContentModelChange(
|
|
|
|
|
IContextSource $context,
|
2022-06-28 22:54:06 +00:00
|
|
|
string $comment,
|
2020-01-11 23:49:41 +00:00
|
|
|
$bot
|
|
|
|
|
) {
|
|
|
|
|
$status = $this->createNewContent();
|
|
|
|
|
if ( !$status->isGood() ) {
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$page = $this->page;
|
|
|
|
|
$title = $page->getTitle();
|
2021-03-02 21:29:46 +00:00
|
|
|
$user = $this->userFactory->newFromAuthority( $this->performer );
|
2020-01-11 23:49:41 +00:00
|
|
|
|
|
|
|
|
// Create log entry
|
|
|
|
|
$log = new ManualLogEntry( 'contentmodel', $this->logAction );
|
2021-03-02 21:29:46 +00:00
|
|
|
$log->setPerformer( $this->performer->getUser() );
|
2020-01-11 23:49:41 +00:00
|
|
|
$log->setTarget( $title );
|
|
|
|
|
$log->setComment( $comment );
|
|
|
|
|
$log->setParameters( [
|
|
|
|
|
'4::oldmodel' => $title->getContentModel(),
|
|
|
|
|
'5::newmodel' => $this->newModel
|
|
|
|
|
] );
|
|
|
|
|
$log->addTags( $this->tags );
|
|
|
|
|
|
2024-07-12 21:46:41 +00:00
|
|
|
$formatter = $this->logFormatterFactory->newFromEntry( $log );
|
2020-01-11 23:49:41 +00:00
|
|
|
$formatter->setContext( RequestContext::newExtraneousContext( $title ) );
|
|
|
|
|
$reason = $formatter->getPlainActionText();
|
|
|
|
|
|
|
|
|
|
if ( $comment !== '' ) {
|
|
|
|
|
$reason .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $comment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run edit filters
|
|
|
|
|
$derivativeContext = new DerivativeContext( $context );
|
|
|
|
|
$derivativeContext->setTitle( $title );
|
|
|
|
|
$derivativeContext->setWikiPage( $page );
|
|
|
|
|
$status = new Status();
|
|
|
|
|
|
|
|
|
|
$newContent = $this->newContent;
|
|
|
|
|
|
2020-05-30 19:10:58 +00:00
|
|
|
if ( !$this->hookRunner->onEditFilterMergedContent( $derivativeContext, $newContent,
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$status, $reason, $user, false )
|
2020-01-11 23:49:41 +00:00
|
|
|
) {
|
|
|
|
|
if ( $status->isGood() ) {
|
|
|
|
|
// TODO: extensions should really specify an error message
|
|
|
|
|
$status->fatal( 'hookaborted' );
|
|
|
|
|
}
|
2024-08-07 21:37:34 +00:00
|
|
|
|
2020-01-11 23:49:41 +00:00
|
|
|
return $status;
|
|
|
|
|
}
|
2021-06-26 14:45:27 +00:00
|
|
|
if ( !$status->isOK() ) {
|
2024-04-08 19:01:35 +00:00
|
|
|
if ( !$status->getMessages() ) {
|
2021-06-26 14:45:27 +00:00
|
|
|
$status->fatal( 'hookaborted' );
|
|
|
|
|
}
|
2024-08-07 21:37:34 +00:00
|
|
|
|
2021-06-26 14:45:27 +00:00
|
|
|
return $status;
|
|
|
|
|
}
|
2020-01-11 23:49:41 +00:00
|
|
|
|
|
|
|
|
// Make the edit
|
|
|
|
|
$flags = $this->latestRevId ? EDIT_UPDATE : EDIT_NEW;
|
|
|
|
|
$flags |= EDIT_INTERNAL;
|
2021-03-02 21:29:46 +00:00
|
|
|
if ( $bot && $this->performer->isAllowed( 'bot' ) ) {
|
2020-01-11 23:49:41 +00:00
|
|
|
$flags |= EDIT_FORCE_BOT;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-24 08:42:19 +00:00
|
|
|
$status = $page->doUserEditContent(
|
2020-01-11 23:49:41 +00:00
|
|
|
$newContent,
|
2021-06-24 08:42:19 +00:00
|
|
|
$this->performer,
|
2020-01-11 23:49:41 +00:00
|
|
|
$reason,
|
|
|
|
|
$flags,
|
|
|
|
|
$this->latestRevId,
|
|
|
|
|
$this->tags
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$logid = $log->insert();
|
|
|
|
|
$log->publish( $logid );
|
|
|
|
|
|
|
|
|
|
$values = [
|
|
|
|
|
'logid' => $logid
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return Status::newGood( $values );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2024-08-07 21:37:34 +00:00
|
|
|
|
|
|
|
|
/** @deprecated class alias since 1.43 */
|
|
|
|
|
class_alias( ContentModelChange::class, 'ContentModelChange' );
|