23 private $jsonDiffFunction;
38 $this->jsonDiffFunction = $jsonDiffFunction;
47 self::PARAM_SOURCE =>
'path',
48 ParamValidator::PARAM_TYPE =>
'string',
49 ParamValidator::PARAM_REQUIRED =>
true,
52 self::PARAM_SOURCE =>
'body',
53 ParamValidator::PARAM_TYPE =>
'string',
54 ParamValidator::PARAM_REQUIRED =>
true,
57 self::PARAM_SOURCE =>
'body',
58 ParamValidator::PARAM_TYPE =>
'string',
59 ParamValidator::PARAM_REQUIRED =>
true,
62 self::PARAM_SOURCE =>
'body',
63 ParamValidator::PARAM_TYPE =>
'string',
64 ParamValidator::PARAM_REQUIRED =>
false,
67 self::PARAM_SOURCE =>
'body',
68 ParamValidator::PARAM_TYPE =>
'array',
69 ParamValidator::PARAM_REQUIRED =>
false,
74 + parent::getParamSettings();
82 '@phan-var array $body';
85 $baseRevId = $body[
'latest'][
'id'] ?? 0;
87 $contentmodel = $body[
'content_model'] ?:
null;
89 if ( $contentmodel !==
null && !$this->contentHandlerFactory->isDefinedModel( $contentmodel ) ) {
91 new MessageValue(
'rest-bad-content-model', [ $contentmodel ] ), 400
102 'text' => $body[
'source'],
103 'summary' => $body[
'comment'],
107 if ( $contentmodel !==
null ) {
108 $params[
'contentmodel'] = $contentmodel;
111 if ( $baseRevId > 0 ) {
112 $params[
'baserevid'] = $baseRevId;
125 if ( isset( $data[
'edit'][
'nochange'] ) ) {
130 $currentRev = $this->revisionLookup->getRevisionByTitle( $title );
132 $data[
'edit'][
'newrevid'] = $currentRev->getId();
133 $data[
'edit'][
'newtimestamp']
134 = MWTimestamp::convert( TS_ISO_8601, $currentRev->getTimestamp() );
137 return parent::mapActionModuleResult( $data );
147 if ( $code ===
'articleexists' ) {
150 new MessageValue(
'rest-update-cannot-create-page', [ $title ] ),
155 if ( $code ===
'editconflict' ) {
156 $data = $this->getConflictData();
160 parent::throwHttpExceptionForActionModuleError( $msg, $statusCode );
176 private function getConflictData() {
178 '@phan-var array $body';
179 $baseRevId = $body[
'latest'][
'id'] ?? 0;
182 $baseRev = $this->revisionLookup->getRevisionById( $baseRevId );
183 $currentRev = $this->revisionLookup->getRevisionByTitle( $title );
185 if ( !$baseRev || !$currentRev ) {
189 $baseContent = $baseRev->getContent(
191 RevisionRecord::FOR_THIS_USER,
194 $currentContent = $currentRev->getContent(
196 RevisionRecord::FOR_THIS_USER,
200 if ( !$baseContent || !$currentContent ) {
204 $model = $body[
'content_model'] ?: $baseContent->getModel();
205 $contentHandler = $this->contentHandlerFactory->getContentHandler( $model );
206 $newContent = $contentHandler->unserializeContent( $body[
'source'] );
215 $localDiff = $this->getDiff( $baseContent, $newContent );
216 $remoteDiff = $this->getDiff( $baseContent, $currentContent );
218 if ( !$localDiff || !$remoteDiff ) {
223 'base' => $baseRev->getId(),
224 'current' => $currentRev->getId(),
225 'local' => $localDiff,
226 'remote' => $remoteDiff,
239 if ( !is_callable( $this->jsonDiffFunction ) ) {
243 $json = ( $this->jsonDiffFunction )( $from->
getText(), $to->
getText(), 2 );
array $params
The job parameters.
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.