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,
89 self::PARAM_SOURCE =>
'body',
90 ParamValidator::PARAM_TYPE =>
'string',
91 ParamValidator::PARAM_REQUIRED =>
false,
92 ParamValidator::PARAM_DEFAULT =>
'',
104 $baseRevId = $body[
'latest'][
'id'] ?? 0;
106 $contentmodel = $body[
'content_model'] ?:
null;
108 if ( $contentmodel !==
null && !$this->contentHandlerFactory->isDefinedModel( $contentmodel ) ) {
110 new MessageValue(
'rest-bad-content-model', [ $contentmodel ] ), 400
119 'text' => $body[
'source'],
120 'summary' => $body[
'comment'],
124 if ( $contentmodel !==
null ) {
125 $params[
'contentmodel'] = $contentmodel;
128 if ( $baseRevId > 0 ) {
129 $params[
'baserevid'] = $baseRevId;
130 $params[
'nocreate'] =
true;
132 $params[
'createonly'] =
true;
142 if ( isset( $data[
'edit'][
'nochange'] ) ) {
147 $currentRev = $this->revisionLookup->getRevisionByTitle(
$title );
149 $data[
'edit'][
'newrevid'] = $currentRev->getId();
150 $data[
'edit'][
'newtimestamp']
151 = MWTimestamp::convert( TS_ISO_8601, $currentRev->getTimestamp() );
154 return parent::mapActionModuleResult( $data );
164 if ( $code ===
'articleexists' ) {
172 if ( $code ===
'editconflict' ) {
177 parent::throwHttpExceptionForActionModuleError( $msg, $statusCode );
195 $baseRevId = $body[
'latest'][
'id'] ?? 0;
198 $baseRev = $this->revisionLookup->getRevisionById( $baseRevId );
199 $currentRev = $this->revisionLookup->getRevisionByTitle(
$title );
201 if ( !$baseRev || !$currentRev ) {
205 $baseContent = $baseRev->getContent(
207 RevisionRecord::FOR_THIS_USER,
210 $currentContent = $currentRev->getContent(
212 RevisionRecord::FOR_THIS_USER,
216 if ( !$baseContent || !$currentContent ) {
220 $model = $body[
'content_model'] ?: $baseContent->getModel();
221 $contentHandler = $this->contentHandlerFactory->getContentHandler( $model );
222 $newContent = $contentHandler->unserializeContent( $body[
'source'] );
231 $localDiff = $this->
getDiff( $baseContent, $newContent );
232 $remoteDiff = $this->
getDiff( $baseContent, $currentContent );
234 if ( !$localDiff || !$remoteDiff ) {
239 'base' => $baseRev->getId(),
240 'current' => $currentRev->getId(),
241 'local' => $localDiff,
242 'remote' => $remoteDiff,
255 if ( !is_callable( $this->jsonDiffFunction ) ) {
260 return FormatJson::decode( $json, FormatJson::FORCE_ASSOC );
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.