48 if ( $user->isBot() ) {
52 $editStash = MediaWikiServices::getInstance()->getPageEditStash();
54 $title = $page->getTitle();
56 if ( !ContentHandler::getForModelID( $params[
'contentmodel'] )
57 ->isSupportedFormat( $params[
'contentformat'] )
60 [
'apierror-badformat-generic', $params[
'contentformat'], $params[
'contentmodel'] ],
69 if ( $params[
'stashedtexthash'] !==
null ) {
71 $textHash = $params[
'stashedtexthash'];
72 if ( !preg_match(
'/^[0-9a-f]{40}$/', $textHash ) ) {
73 $this->
dieWithError(
'apierror-stashedit-missingtext',
'missingtext' );
75 $text = $editStash->fetchInputText( $textHash );
76 if ( !is_string( $text ) ) {
77 $this->
dieWithError(
'apierror-stashedit-missingtext',
'missingtext' );
82 $text = rtrim( str_replace(
"\r\n",
"\n", $params[
'text'] ) );
83 $textHash = sha1( $text );
86 $textContent = ContentHandler::makeContent(
87 $text,
$title, $params[
'contentmodel'], $params[
'contentformat'] );
89 $page = WikiPage::factory(
$title );
90 if ( $page->exists() ) {
92 $baseRev = Revision::newFromPageId( $page->getId(), $params[
'baserevid'] );
94 $this->
dieWithError( [
'apierror-nosuchrevid', $params[
'baserevid'] ] );
96 $currentRev = $page->getRevision();
98 $this->
dieWithError( [
'apierror-missingrev-pageid', $page->getId() ],
'missingrev' );
101 $editContent = $page->replaceSectionAtRev(
104 $params[
'sectiontitle'],
107 if ( !$editContent ) {
108 $this->
dieWithError(
'apierror-sectionreplacefailed',
'replacefailed' );
110 if ( $currentRev->getId() == $baseRev->getId() ) {
115 $baseContent = $baseRev->getContent();
116 $currentContent = $currentRev->getContent();
117 if ( !$baseContent || !$currentContent ) {
118 $this->
dieWithError( [
'apierror-missingcontent-pageid', $page->getId() ],
'missingrev' );
120 $handler = ContentHandler::getForModelID( $baseContent->getModel() );
121 $content = $handler->merge3( $baseContent, $editContent, $currentContent );
134 if ( $user->pingLimiter(
'stashedit' ) ) {
135 $status =
'ratelimited';
137 $status = $editStash->parseAndCache( $page,
$content, $user, $params[
'summary'] );
138 $editStash->stashInputText( $text, $textHash );
141 $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
142 $stats->increment(
"editstash.cache_stores.$status" );
144 $ret = [
'status' => $status ];
146 if ( $status !==
'ratelimited' || $params[
'stashedtexthash'] !==
null ) {
147 $ret[
'texthash'] = $textHash;
163 $editStash = MediaWikiServices::getInstance()->getPageEditStash();
165 return $editStash->parseAndCache( $page,
$content, $user, $summary );
184 'stashedtexthash' => [
This abstract class implements many basic API functions, and is the base of all API classes.
const PARAM_REQUIRED
(boolean) Is the parameter required?
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
getModuleName()
Get the name of the module being executed by this instance.
getTitleOrPageId( $params, $load=false)
Get a WikiPage object from a title or pageid param, if possible.
requireOnlyOneParameter( $params, $required)
Die if none or more than one of a certain set of parameters is set and not false.
Prepare an edit in shared cache so that it can be reused on edit.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
isInternal()
Indicates whether this module is "internal" Internal API modules are not (yet) intended for 3rd party...
needsToken()
Returns the token type this module requires in order to execute.
isWriteMode()
Indicates whether this module requires write mode.
mustBePosted()
Indicates whether this module must be called with a POST request.
parseAndStash(WikiPage $page, Content $content, User $user, $summary)
Class for managing stashed edits used by the page updater classes.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Class representing a MediaWiki article and history.
Base interface for content objects.