ApiVisualEditorEdit: Switch to non-global FlaggablePageView::newFromTitle

Introduced in FlaggedRevs with Idbdab9a7396 (6bfd276e64), and I've
migrated consumers away from the singleton in I192b962147 (5ee96e5ca7)
and I04fdbd497b8 (bbdfc4c024).

The one thing that remains global by default is the context, but
VE already avoids that with setContext, and (correctly) restores this
afterward since the FlaggablePageView object is re-used by title.
That's exactly as terrible as it sounds, but at least it's a bit more
visible after my refactor.

Bug: T314008
Change-Id: I0008818ec821c35c570d9db9c82f737783e6729b
This commit is contained in:
Timo Tijhof 2022-08-08 12:03:45 +01:00 committed by Krinkle
parent 1926ab7b05
commit 3901a8a4f1
2 changed files with 4 additions and 9 deletions

View file

@ -10,9 +10,10 @@
class FlaggablePageView extends ContextSource {
/**
* @param Title|MediaWiki\Page\PageIdentity $title
* @return self
*/
public static function singleton() {
public static function newFromTitle( $title ) {
}
/**

View file

@ -484,11 +484,7 @@ class ApiVisualEditorEdit extends ApiBase {
$result['isRedirect'] = (string)$title->isRedirect();
if ( ExtensionRegistry::getInstance()->isLoaded( 'FlaggedRevs' ) ) {
$globalContext = RequestContext::getMain();
$globalTitle = $globalContext->getTitle();
$newContext = new DerivativeContext( $globalContext );
$newContext = new DerivativeContext( RequestContext::getMain() );
// Defeat !$this->isPageView( $request ) || $request->getVal( 'oldid' ) check in setPageContent
$newRequest = new DerivativeRequest(
$this->getRequest(),
@ -501,11 +497,10 @@ class ApiVisualEditorEdit extends ApiBase {
);
$newContext->setRequest( $newRequest );
$newContext->setTitle( $title );
$globalContext->setTitle( $title );
// Must be after $globalContext->setTitle since FlaggedRevs constructor
// inspects global Title
$view = FlaggablePageView::singleton();
$view = FlaggablePageView::newFromTitle( $title );
// Most likely identical to $globalState, but not our concern
$originalContext = $view->getContext();
$view->setContext( $newContext );
@ -518,7 +513,6 @@ class ApiVisualEditorEdit extends ApiBase {
$view->setPageContent( $outputDone, $useParserCache );
$view->displayTag();
$view->setContext( $originalContext );
$globalContext->setTitle( $globalTitle );
}
$lang = $this->getLanguage();