From aed5bcf7d0f4dc3ce4754ebc6a6162df01d3487a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Wed, 26 Jan 2022 19:57:36 +0100 Subject: [PATCH] ApiVisualEditor: Remove $wgTitle hack, set page for `{{PAGENAME}}` when needed Depends on core changes I242e042317 and I6e9356a6cc to set the context page for messages generated in Title::getEditNotices() and LogEventsList::showLogExtract() too. Set the context page for other messages whose overrides on Wikimedia wikis commonly depend on it, which I checked using Global Search, e.g. https://global-search.toolforge.org/?q=PAGENAME®ex=1&namespaces=8&title=Editingold Depends-On: I242e042317a1e16c8d51edbf7800c8b7d70d468e Depends-On: I6e9356a6cc3b9df9b508c3d37a0b9b75d6825efd Bug: T300184 Change-Id: I0746618b1f6da3e5fd213d8adad9b1f4ec2fe23b --- .phpcs.xml | 4 +--- includes/ApiVisualEditor.php | 19 +++++++------------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/.phpcs.xml b/.phpcs.xml index dfaa89489d..3e6d391732 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -1,8 +1,6 @@ - - - + 5 diff --git a/includes/ApiVisualEditor.php b/includes/ApiVisualEditor.php index 906386bf76..727268122e 100644 --- a/includes/ApiVisualEditor.php +++ b/includes/ApiVisualEditor.php @@ -161,12 +161,6 @@ class ApiVisualEditor extends ApiBase { case 'parse': case 'wikitext': case 'metadata': - // Dirty hack to provide the correct context for edit notices - // FIXME Don't write to globals! Eww. - global $wgTitle; - $wgTitle = $title; - RequestContext::getMain()->setTitle( $title ); - $preloaded = false; $restbaseHeaders = null; @@ -319,12 +313,12 @@ class ApiVisualEditor extends ApiBase { '{{fullurl:Special:UserLogin|returnto={{FULLPAGENAMEE}}}}', // Sign-up link '{{fullurl:Special:UserLogin/signup|returnto={{FULLPAGENAMEE}}}}' - )->parseAsBlock(); + )->page( $title )->parseAsBlock(); } // Old revision notice if ( $restoring ) { - $notices['editingold'] = $this->msg( 'editingold' )->parseAsBlock(); + $notices['editingold'] = $this->msg( 'editingold' )->page( $title )->parseAsBlock(); } if ( $this->readOnlyMode->isReadOnly() ) { @@ -343,12 +337,12 @@ class ApiVisualEditor extends ApiBase { wfExpandUrl( Skin::makeInternalOrExternalUrl( $this->msg( 'helppage' )->inContentLanguage()->text() ) ) - )->parseAsBlock(); + )->page( $title )->parseAsBlock(); // Page protected from creation if ( $title->getRestrictions( 'create' ) ) { $protectionNotices['titleprotectedwarning'] = - $this->msg( 'titleprotectedwarning' )->parseAsBlock() . + $this->msg( 'titleprotectedwarning' )->page( $title )->parseAsBlock() . $this->getLastLogEntry( $title, 'protect' ); } @@ -386,7 +380,7 @@ class ApiVisualEditor extends ApiBase { // Then it must be protected based on static groups (regular) $noticeMsg = 'protectedpagewarning'; } - $protectionNotices[$noticeMsg] = $this->msg( $noticeMsg )->parseAsBlock() . + $protectionNotices[$noticeMsg] = $this->msg( $noticeMsg )->page( $title )->parseAsBlock() . $this->getLastLogEntry( $title, 'protect' ); } @@ -395,7 +389,8 @@ class ApiVisualEditor extends ApiBase { if ( isset( $restrictions['edit'] ) ) { $protectedClasses[] = ' mw-textarea-cprotected'; - $notice = $this->msg( 'cascadeprotectedwarning', count( $sources ) )->parseAsBlock() . '
    '; + $notice = $this->msg( 'cascadeprotectedwarning', count( $sources ) ) + ->page( $title )->parseAsBlock() . '
      '; // Unfortunately there's no nice way to get only the pages which cause // editing to be restricted foreach ( $sources as $source ) {