mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-23 22:13:34 +00:00
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:
parent
1926ab7b05
commit
3901a8a4f1
|
@ -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 ) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue