47 parent::__construct( $main, $action );
54 if ( $user->isBot() ) {
59 $title = $page->getTitle();
62 if ( !$this->contentHandlerFactory
63 ->getContentHandler( $params[
'contentmodel'] )
64 ->isSupportedFormat( $params[
'contentformat'] )
67 [
'apierror-badformat-generic', $params[
'contentformat'], $params[
'contentmodel'] ],
74 if ( $params[
'stashedtexthash'] !==
null ) {
76 $textHash = $params[
'stashedtexthash'];
77 if ( !preg_match(
'/^[0-9a-f]{40}$/', $textHash ) ) {
78 $this->
dieWithError(
'apierror-stashedit-missingtext',
'missingtext' );
80 $text = $this->pageEditStash->fetchInputText( $textHash );
81 if ( !is_string( $text ) ) {
82 $this->
dieWithError(
'apierror-stashedit-missingtext',
'missingtext' );
87 $text = rtrim( str_replace(
"\r\n",
"\n", $params[
'text'] ) );
88 $textHash = sha1( $text );
91 $textContent = $this->contentHandlerFactory
92 ->getContentHandler( $params[
'contentmodel'] )
93 ->unserializeContent( $text, $params[
'contentformat'] );
95 $page = $this->wikiPageFactory->newFromTitle( $title );
96 if ( $page->exists() ) {
98 $baseRev = $this->revisionLookup->getRevisionByPageId(
103 $this->
dieWithError( [
'apierror-nosuchrevid', $params[
'baserevid'] ] );
105 $currentRev = $page->getRevisionRecord();
106 if ( !$currentRev ) {
107 $this->
dieWithError( [
'apierror-missingrev-pageid', $page->getId() ],
'missingrev' );
110 $editContent = $page->replaceSectionAtRev(
113 $params[
'sectiontitle'],
116 if ( !$editContent ) {
117 $this->
dieWithError(
'apierror-sectionreplacefailed',
'replacefailed' );
119 if ( $currentRev->getId() == $baseRev->getId() ) {
121 $content = $editContent;
124 $baseContent = $baseRev->getContent( SlotRecord::MAIN );
125 $currentContent = $currentRev->getContent( SlotRecord::MAIN );
126 if ( !$baseContent || !$currentContent ) {
127 $this->
dieWithError( [
'apierror-missingcontent-pageid', $page->getId() ],
'missingrev' );
130 $baseModel = $baseContent->getModel();
131 $currentModel = $currentContent->getModel();
136 $content = $this->contentHandlerFactory
137 ->getContentHandler( $baseModel )
138 ->merge3( $baseContent, $editContent, $currentContent );
139 }
catch ( Exception $e ) {
142 [
'apierror-contentmodel-mismatch', $currentModel, $baseModel ]
150 $content = $textContent;
159 if ( !$user->authorizeWrite(
'stashedit', $title ) ) {
160 $status =
'ratelimited';
162 $user = $this->getUserForPreview();
163 $updater = $page->newPageUpdater( $user );
164 $status = $this->pageEditStash->parseAndCache( $updater, $content, $user, $params[
'summary'] );
165 $this->pageEditStash->stashInputText( $text, $textHash );
168 $this->statsFactory->getCounter(
'editstash_cache_stores_total' )
169 ->setLabel(
'status', $status )
172 $ret = [
'status' => $status ];
174 if ( $status !==
'ratelimited' || $params[
'stashedtexthash'] !==
null ) {
175 $ret[
'texthash'] = $textHash;
183 if ( $this->tempUserCreator->shouldAutoCreate( $user,
'edit' ) ) {
184 return $this->userFactory->newUnsavedTempUser(
185 $this->tempUserCreator->getStashedName( $this->getRequest()->getSession() )
195 ParamValidator::PARAM_TYPE =>
'string',
196 ParamValidator::PARAM_REQUIRED => true
199 ParamValidator::PARAM_TYPE =>
'string',
202 ParamValidator::PARAM_TYPE =>
'string'
205 ParamValidator::PARAM_TYPE =>
'text',
206 ParamValidator::PARAM_DEFAULT => null
208 'stashedtexthash' => [
209 ParamValidator::PARAM_TYPE =>
'string',
210 ParamValidator::PARAM_DEFAULT => null
213 ParamValidator::PARAM_TYPE =>
'string',
214 ParamValidator::PARAM_DEFAULT =>
''
217 ParamValidator::PARAM_TYPE => $this->contentHandlerFactory->getContentModels(),
218 ParamValidator::PARAM_REQUIRED => true
221 ParamValidator::PARAM_TYPE => $this->contentHandlerFactory->getAllContentFormats(),
222 ParamValidator::PARAM_REQUIRED => true
225 ParamValidator::PARAM_TYPE =>
'integer',
226 ParamValidator::PARAM_REQUIRED => true
253 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Stashedit';
258class_alias( ApiStashEdit::class,
'ApiStashEdit' );
This is the main API class, used for both external and internal processing.
Service for creating WikiPage objects.
Manage the pre-emptive page parsing for edits to wiki pages.