X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fapi%2FApiEditPage.php;h=d6de834301938037c604ae32f0abcd48f688e065;hp=00daba94b5250ea96bec09e272dbfe4006ae186f;hb=f43fa6f4f0e2cb60b8543daad661b48a3e0653a9;hpb=040860277bb5e96557f6e761d1fbd9a5974e45de diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 00daba94b5..d6de834301 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -97,6 +97,7 @@ class ApiEditPage extends ApiBase { } else { $contentHandler = ContentHandler::getForModelID( $params['contentmodel'] ); } + $contentModel = $contentHandler->getModelID(); $name = $titleObj->getPrefixedDBkey(); $model = $contentHandler->getModelID(); @@ -111,11 +112,11 @@ class ApiEditPage extends ApiBase { } if ( !isset( $params['contentformat'] ) || $params['contentformat'] == '' ) { - $params['contentformat'] = $contentHandler->getDefaultFormat(); + $contentFormat = $contentHandler->getDefaultFormat(); + } else { + $contentFormat = $params['contentformat']; } - $contentFormat = $params['contentformat']; - if ( !$contentHandler->isSupportedFormat( $contentFormat ) ) { $this->dieUsage( "The requested format $contentFormat is not supported for content model " . @@ -265,9 +266,21 @@ class ApiEditPage extends ApiBase { if ( !$newContent ) { $this->dieUsageMsg( 'undo-failure' ); } - - $params['text'] = $newContent->serialize( $params['contentformat'] ); - + if ( empty( $params['contentmodel'] ) + && empty( $params['contentformat'] ) + ) { + // If we are reverting content model, the new content model + // might not support the current serialization format, in + // which case go back to the old serialization format, + // but only if the user hasn't specified a format/model + // parameter. + if ( !$newContent->isSupportedFormat( $contentFormat ) ) { + $contentFormat = $undoafterRev->getContentFormat(); + } + // Override content model with model of undid revision. + $contentModel = $newContent->getModel(); + } + $params['text'] = $newContent->serialize( $contentFormat ); // If no summary was given and we only undid one rev, // use an autosummary if ( is_null( $params['summary'] ) && @@ -288,7 +301,7 @@ class ApiEditPage extends ApiBase { $requestArray = [ 'wpTextbox1' => $params['text'], 'format' => $contentFormat, - 'model' => $contentHandler->getModelID(), + 'model' => $contentModel, 'wpEditToken' => $params['token'], 'wpIgnoreBlankSummary' => true, 'wpIgnoreBlankArticle' => true, @@ -519,7 +532,7 @@ class ApiEditPage extends ApiBase { case EditPage::AS_END: default: - // $status came from WikiPage::doEdit() + // $status came from WikiPage::doEditContent() $errors = $status->getErrorsArray(); $this->dieUsageMsg( $errors[0] ); // TODO: Add new errors to message map break;