55 parent::__construct( $main, $action );
57 $this->contentHandlerFactory = $contentHandlerFactory;
58 $this->pageEditStash = $pageEditStash;
59 $this->revisionLookup = $revisionLookup;
60 $this->stats = $statsFactory;
61 $this->wikiPageFactory = $wikiPageFactory;
62 $this->tempUserCreator = $tempUserCreator;
63 $this->userFactory = $userFactory;
70 if ( $user->isBot() ) {
75 $title = $page->getTitle();
78 if ( !$this->contentHandlerFactory
79 ->getContentHandler( $params[
'contentmodel'] )
80 ->isSupportedFormat( $params[
'contentformat'] )
83 [
'apierror-badformat-generic', $params[
'contentformat'], $params[
'contentmodel'] ],
90 if ( $params[
'stashedtexthash'] !==
null ) {
92 $textHash = $params[
'stashedtexthash'];
93 if ( !preg_match(
'/^[0-9a-f]{40}$/', $textHash ) ) {
94 $this->
dieWithError(
'apierror-stashedit-missingtext',
'missingtext' );
96 $text = $this->pageEditStash->fetchInputText( $textHash );
97 if ( !is_string( $text ) ) {
98 $this->
dieWithError(
'apierror-stashedit-missingtext',
'missingtext' );
103 $text = rtrim( str_replace(
"\r\n",
"\n", $params[
'text'] ) );
104 $textHash = sha1( $text );
107 $textContent = $this->contentHandlerFactory
108 ->getContentHandler( $params[
'contentmodel'] )
109 ->unserializeContent( $text, $params[
'contentformat'] );
111 $page = $this->wikiPageFactory->newFromTitle( $title );
112 if ( $page->exists() ) {
114 $baseRev = $this->revisionLookup->getRevisionByPageId(
119 $this->
dieWithError( [
'apierror-nosuchrevid', $params[
'baserevid'] ] );
121 $currentRev = $page->getRevisionRecord();
122 if ( !$currentRev ) {
123 $this->
dieWithError( [
'apierror-missingrev-pageid', $page->getId() ],
'missingrev' );
126 $editContent = $page->replaceSectionAtRev(
129 $params[
'sectiontitle'],
132 if ( !$editContent ) {
133 $this->
dieWithError(
'apierror-sectionreplacefailed',
'replacefailed' );
135 if ( $currentRev->getId() == $baseRev->getId() ) {
137 $content = $editContent;
140 $baseContent = $baseRev->getContent( SlotRecord::MAIN );
141 $currentContent = $currentRev->getContent( SlotRecord::MAIN );
142 if ( !$baseContent || !$currentContent ) {
143 $this->
dieWithError( [
'apierror-missingcontent-pageid', $page->getId() ],
'missingrev' );
146 $baseModel = $baseContent->getModel();
147 $currentModel = $currentContent->getModel();
152 $content = $this->contentHandlerFactory
153 ->getContentHandler( $baseModel )
154 ->merge3( $baseContent, $editContent, $currentContent );
155 }
catch ( Exception $e ) {
158 [
'apierror-contentmodel-mismatch', $currentModel, $baseModel ]
166 $content = $textContent;
175 if ( !$user->authorizeWrite(
'stashedit', $title ) ) {
176 $status =
'ratelimited';
178 $user = $this->getUserForPreview();
179 $updater = $page->newPageUpdater( $user );
180 $status = $this->pageEditStash->parseAndCache( $updater, $content, $user, $params[
'summary'] );
181 $this->pageEditStash->stashInputText( $text, $textHash );
184 $this->stats->getCounter(
'editstash_cache_stores_total' )
185 ->setLabel(
'status', $status )
188 $ret = [
'status' => $status ];
190 if ( $status !==
'ratelimited' || $params[
'stashedtexthash'] !==
null ) {
191 $ret[
'texthash'] = $textHash;
199 if ( $this->tempUserCreator->shouldAutoCreate( $user,
'edit' ) ) {
200 return $this->userFactory->newUnsavedTempUser(
201 $this->tempUserCreator->getStashedName( $this->getRequest()->getSession() )
211 ParamValidator::PARAM_TYPE =>
'string',
212 ParamValidator::PARAM_REQUIRED => true
215 ParamValidator::PARAM_TYPE =>
'string',
218 ParamValidator::PARAM_TYPE =>
'string'
221 ParamValidator::PARAM_TYPE =>
'text',
222 ParamValidator::PARAM_DEFAULT => null
224 'stashedtexthash' => [
225 ParamValidator::PARAM_TYPE =>
'string',
226 ParamValidator::PARAM_DEFAULT => null
229 ParamValidator::PARAM_TYPE =>
'string',
230 ParamValidator::PARAM_DEFAULT =>
''
233 ParamValidator::PARAM_TYPE => $this->contentHandlerFactory->getContentModels(),
234 ParamValidator::PARAM_REQUIRED => true
237 ParamValidator::PARAM_TYPE => $this->contentHandlerFactory->getAllContentFormats(),
238 ParamValidator::PARAM_REQUIRED => true
241 ParamValidator::PARAM_TYPE =>
'integer',
242 ParamValidator::PARAM_REQUIRED => true
269 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Stashedit';
274class_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.