From 9cb12e3ee84671ea3a23be79b41777afe3713154 Mon Sep 17 00:00:00 2001 From: Subramanya Sastry Date: Fri, 6 Dec 2019 14:32:52 -0500 Subject: [PATCH] html2wt selser: Return http 409 if the previous revision is not found Note that we trigger this as an indication of failure to apply selective serialization on the page. Alternatively, we could fall back to regular serialization just like we would if selser were not requested. In that scenario, we would return serialized wikitext and the client will now encounter a failure when trying to save the serialized wikitext. But, http 409 is the correct response since we are not presuming that the client cannot handle this scenario. We are narrowly confining our response / error handling to what the client requested, and the client could retry a non-selser request that will succeed and then provide alternate handling in the lockdown scenario (ex: offer to the user to create a different page which avoids losing the created content). Bug: T238934 Change-Id: Iac17641159ab58614dbe34fd0729ac7d34dc3011 --- extension/src/Rest/Handler/ParsoidHandler.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/extension/src/Rest/Handler/ParsoidHandler.php b/extension/src/Rest/Handler/ParsoidHandler.php index 1807c8d99..eb544edea 100644 --- a/extension/src/Rest/Handler/ParsoidHandler.php +++ b/extension/src/Rest/Handler/ParsoidHandler.php @@ -804,12 +804,17 @@ protected function html2wt( Env $env, array $attribs, string $html = null ) { // clean round-tripping of HTML retrieved earlier with" // So, no oldid => no selser $hasOldId = (bool)$attribs['oldid']; - // FIXME: T234548/T234549 - this is deprecated: - // should use $env->topFrame->getSrcText() - $oldtext = $hasOldId ? $env->getPageMainContent() : ''; if ( $hasOldId && !empty( $this->parsoidSettings['useSelser'] ) ) { - $selserData = new SelserData( $oldtext, $oldhtml ); + if ( !$env->getPageConfig()->getRevisionContent() ) { + return $this->getResponseFactory()->createHttpError( 409, [ + 'message' => 'Could not find previous revision. Has the page been locked / deleted?' + ] ); + } + + // FIXME: T234548/T234549 - $env->getPageMainContent() is deprecated: + // should use $env->topFrame->getSrcText() + $selserData = new SelserData( $env->getPageMainContent(), $oldhtml ); } else { $selserData = null; }