Use DerivativeContext in ApiVisualEditorEdit

Using DerivativeContext also makes the code easier to read.
getContext() returns an IContextSource, in this interface has no
setRequest() method and this can fail for some kinds of IContextSource.
$view is a ContextSource, which implements setContext().
This also allows us pass in a new context with the right request object,
and also to set the title so we don't have different titles
on $view and the main context.

Change-Id: Ia575cd6163defeb423a542e342034cac5eb6108c
This commit is contained in:
Umherirrender 2019-01-30 22:03:09 +01:00 committed by Catrope
parent 49a53fb57c
commit c9a3bf9fa5

View file

@ -412,8 +412,10 @@ class ApiVisualEditorEdit extends ApiVisualEditor {
if ( class_exists( 'FlaggablePageView' ) ) {
$view = FlaggablePageView::singleton();
$originalRequest = $view->getContext()->getRequest();
$originalContext = $view->getContext();
$originalTitle = RequestContext::getMain()->getTitle();
$newContext = new DerivativeContext( $originalContext );
// Defeat !$this->isPageView( $request ) || $request->getVal( 'oldid' ) check in setPageContent
$newRequest = new DerivativeRequest(
$this->getRequest(),
@ -424,7 +426,9 @@ class ApiVisualEditorEdit extends ApiVisualEditor {
'action' => 'view'
] + $this->getRequest()->getValues()
);
$view->getContext()->setRequest( $newRequest );
$newContext->setRequest( $newRequest );
$newContext->setTitle( $title );
$view->setContext( $newContext );
RequestContext::getMain()->setTitle( $title );
// The two parameters here are references but we don't care
@ -433,7 +437,7 @@ class ApiVisualEditorEdit extends ApiVisualEditor {
$useParserCache = null;
$view->setPageContent( $outputDone, $useParserCache );
$view->displayTag();
$view->getContext()->setRequest( $originalRequest );
$view->setContext( $originalContext );
RequestContext::getMain()->setTitle( $originalTitle );
}