76 parent::__construct( $main, $action );
89 if ( $user->isBot() ) {
94 $title = $page->getTitle();
97 if ( !$this->contentHandlerFactory
98 ->getContentHandler( $params[
'contentmodel'] )
99 ->isSupportedFormat( $params[
'contentformat'] )
102 [
'apierror-badformat-generic', $params[
'contentformat'], $params[
'contentmodel'] ],
111 if ( $params[
'stashedtexthash'] !==
null ) {
113 $textHash = $params[
'stashedtexthash'];
114 if ( !preg_match(
'/^[0-9a-f]{40}$/', $textHash ) ) {
115 $this->
dieWithError(
'apierror-stashedit-missingtext',
'missingtext' );
117 $text = $this->pageEditStash->fetchInputText( $textHash );
118 if ( !is_string( $text ) ) {
119 $this->
dieWithError(
'apierror-stashedit-missingtext',
'missingtext' );
124 $text = rtrim( str_replace(
"\r\n",
"\n", $params[
'text'] ) );
125 $textHash = sha1( $text );
128 $textContent = ContentHandler::makeContent(
129 $text,
$title, $params[
'contentmodel'], $params[
'contentformat'] );
131 $page = $this->wikiPageFactory->newFromTitle(
$title );
132 if ( $page->exists() ) {
134 $baseRev = $this->revisionLookup->getRevisionByPageId(
139 $this->
dieWithError( [
'apierror-nosuchrevid', $params[
'baserevid'] ] );
141 $currentRev = $page->getRevisionRecord();
142 if ( !$currentRev ) {
143 $this->
dieWithError( [
'apierror-missingrev-pageid', $page->getId() ],
'missingrev' );
146 $editContent = $page->replaceSectionAtRev(
149 $params[
'sectiontitle'],
152 if ( !$editContent ) {
153 $this->
dieWithError(
'apierror-sectionreplacefailed',
'replacefailed' );
155 if ( $currentRev->getId() == $baseRev->getId() ) {
160 $baseContent = $baseRev->getContent( SlotRecord::MAIN );
161 $currentContent = $currentRev->getContent( SlotRecord::MAIN );
162 if ( !$baseContent || !$currentContent ) {
163 $this->
dieWithError( [
'apierror-missingcontent-pageid', $page->getId() ],
'missingrev' );
166 $baseModel = $baseContent->getModel();
167 $currentModel = $currentContent->getModel();
172 $content = $this->contentHandlerFactory
173 ->getContentHandler( $baseModel )
174 ->merge3( $baseContent, $editContent, $currentContent );
175 }
catch ( Exception $e ) {
177 'wrap' => ApiMessage::create(
178 [
'apierror-contentmodel-mismatch', $currentModel, $baseModel ]
195 if ( $user->pingLimiter(
'stashedit' ) ) {
196 $status =
'ratelimited';
198 $status = $this->pageEditStash->parseAndCache( $page,
$content, $user, $params[
'summary'] );
199 $this->pageEditStash->stashInputText( $text, $textHash );
202 $this->statsdDataFactory->increment(
"editstash.cache_stores.$status" );
204 $ret = [
'status' => $status ];
206 if ( $status !==
'ratelimited' || $params[
'stashedtexthash'] !==
null ) {
207 $ret[
'texthash'] = $textHash;
223 return $this->pageEditStash->parseAndCache( $page,
$content, $user, $summary ??
'' );
242 'stashedtexthash' => [
This abstract class implements many basic API functions, and is the base of all API classes.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
requireOnlyOneParameter( $params,... $required)
Die if none or more than one of a certain set of parameters is set and not false.
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.
dieWithException(Throwable $exception, array $options=[])
Abort execution with an error derived from a throwable.
This is the main API class, used for both external and internal processing.
Prepare an edit in shared cache so that it can be reused on edit.
PageEditStash $pageEditStash
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
WikiPageFactory $wikiPageFactory
RevisionLookup $revisionLookup
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
IContentHandlerFactory $contentHandlerFactory
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.
IBufferingStatsdDataFactory $statsdDataFactory
parseAndStash(WikiPage $page, Content $content, UserIdentity $user, $summary)
isWriteMode()
Indicates whether this module requires write mode.
__construct(ApiMain $main, $action, IContentHandlerFactory $contentHandlerFactory, PageEditStash $pageEditStash, RevisionLookup $revisionLookup, IBufferingStatsdDataFactory $statsdDataFactory, WikiPageFactory $wikiPageFactory)
mustBePosted()
Indicates whether this module must be called with a POST request.
Class for managing stashed edits used by the page updater classes.
Class representing a MediaWiki article and history.
Base interface for content objects.
MediaWiki adaptation of StatsdDataFactory that provides buffering functionality.