Skip to content

Commit

Permalink
html2wt selser: Return http 409 if the previous revision is not found
Browse files Browse the repository at this point in the history
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
  • Loading branch information
subbuss authored and cscott committed Dec 19, 2019
1 parent 5ccfe69 commit 9cb12e3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions extension/src/Rest/Handler/ParsoidHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 9cb12e3

Please sign in to comment.