25 private $jsonDiffFunction;
40 $this->jsonDiffFunction = $jsonDiffFunction;
49 self::PARAM_SOURCE =>
'path',
50 ParamValidator::PARAM_TYPE =>
'string',
51 ParamValidator::PARAM_REQUIRED =>
true,
60 if ( $contentType !==
'application/json' ) {
63 [
'content_type' => $contentType ]
69 self::PARAM_SOURCE =>
'body',
70 ParamValidator::PARAM_TYPE =>
'string',
71 ParamValidator::PARAM_REQUIRED =>
true,
74 self::PARAM_SOURCE =>
'body',
75 ParamValidator::PARAM_TYPE =>
'string',
76 ParamValidator::PARAM_REQUIRED =>
true,
79 self::PARAM_SOURCE =>
'body',
80 ParamValidator::PARAM_TYPE =>
'string',
81 ParamValidator::PARAM_REQUIRED =>
false,
84 self::PARAM_SOURCE =>
'body',
85 ParamValidator::PARAM_TYPE =>
'array',
86 ParamValidator::PARAM_REQUIRED =>
false,
88 ] + $this->getTokenParamDefinition() );
98 $baseRevId = $body[
'latest'][
'id'] ?? 0;
100 $contentmodel = $body[
'content_model'] ?:
null;
102 if ( $contentmodel !==
null && !$this->contentHandlerFactory->isDefinedModel( $contentmodel ) ) {
104 new MessageValue(
'rest-bad-content-model', [ $contentmodel ] ), 400
108 $token = $this->getToken() ?? $this->
getUser()->getEditToken();
113 'text' => $body[
'source'],
114 'summary' => $body[
'comment'],
118 if ( $contentmodel !==
null ) {
119 $params[
'contentmodel'] = $contentmodel;
122 if ( $baseRevId > 0 ) {
123 $params[
'baserevid'] = $baseRevId;
124 $params[
'nocreate'] =
true;
126 $params[
'createonly'] =
true;
136 if ( isset( $data[
'edit'][
'nochange'] ) ) {
141 $currentRev = $this->revisionLookup->getRevisionByTitle(
$title );
143 $data[
'edit'][
'newrevid'] = $currentRev->getId();
144 $data[
'edit'][
'newtimestamp']
145 = MWTimestamp::convert( TS_ISO_8601, $currentRev->getTimestamp() );
148 return parent::mapActionModuleResult( $data );
158 if ( $code ===
'articleexists' ) {
166 if ( $code ===
'editconflict' ) {
167 $data = $this->getConflictData();
171 parent::throwHttpExceptionForActionModuleError( $msg, $statusCode );
187 private function getConflictData() {
189 $baseRevId = $body[
'latest'][
'id'] ?? 0;
192 $baseRev = $this->revisionLookup->getRevisionById( $baseRevId );
193 $currentRev = $this->revisionLookup->getRevisionByTitle(
$title );
195 if ( !$baseRev || !$currentRev ) {
199 $baseContent = $baseRev->getContent(
201 RevisionRecord::FOR_THIS_USER,
204 $currentContent = $currentRev->getContent(
206 RevisionRecord::FOR_THIS_USER,
210 if ( !$baseContent || !$currentContent ) {
214 $model = $body[
'content_model'] ?: $baseContent->getModel();
215 $contentHandler = $this->contentHandlerFactory->getContentHandler( $model );
216 $newContent = $contentHandler->unserializeContent( $body[
'source'] );
225 $localDiff = $this->getDiff( $baseContent, $newContent );
226 $remoteDiff = $this->getDiff( $baseContent, $currentContent );
228 if ( !$localDiff || !$remoteDiff ) {
233 'base' => $baseRev->getId(),
234 'current' => $currentRev->getId(),
235 'local' => $localDiff,
236 'remote' => $remoteDiff,
249 if ( !is_callable( $this->jsonDiffFunction ) ) {
253 $json = ( $this->jsonDiffFunction )( $from->
getText(), $to->
getText(), 2 );
Library for creating and parsing MW-style timestamps.
Do-nothing body validator.
Content object implementation for representing flat text.
getText()
Returns the text represented by this Content object, as a string.
Interface for messages with machine-readable data for use by the API.
getApiCode()
Returns a machine-readable code for use by the API.