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&regex=1&namespaces=8&title=Editingold

Depends-On: I242e042317a1e16c8d51edbf7800c8b7d70d468e
Depends-On: I6e9356a6cc3b9df9b508c3d37a0b9b75d6825efd
Bug: T300184
Change-Id: I0746618b1f6da3e5fd213d8adad9b1f4ec2fe23b
This commit is contained in:
Bartosz Dziewoński 2022-01-26 19:57:36 +01:00
parent 839a62829d
commit aed5bcf7d0
2 changed files with 8 additions and 15 deletions

View file

@ -1,8 +1,6 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<ruleset> <ruleset>
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki"> <rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki" />
<exclude name="MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgTitle" />
</rule>
<rule ref="Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma"> <rule ref="Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma">
<severity>5</severity> <severity>5</severity>

View file

@ -161,12 +161,6 @@ class ApiVisualEditor extends ApiBase {
case 'parse': case 'parse':
case 'wikitext': case 'wikitext':
case 'metadata': 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; $preloaded = false;
$restbaseHeaders = null; $restbaseHeaders = null;
@ -319,12 +313,12 @@ class ApiVisualEditor extends ApiBase {
'{{fullurl:Special:UserLogin|returnto={{FULLPAGENAMEE}}}}', '{{fullurl:Special:UserLogin|returnto={{FULLPAGENAMEE}}}}',
// Sign-up link // Sign-up link
'{{fullurl:Special:UserLogin/signup|returnto={{FULLPAGENAMEE}}}}' '{{fullurl:Special:UserLogin/signup|returnto={{FULLPAGENAMEE}}}}'
)->parseAsBlock(); )->page( $title )->parseAsBlock();
} }
// Old revision notice // Old revision notice
if ( $restoring ) { if ( $restoring ) {
$notices['editingold'] = $this->msg( 'editingold' )->parseAsBlock(); $notices['editingold'] = $this->msg( 'editingold' )->page( $title )->parseAsBlock();
} }
if ( $this->readOnlyMode->isReadOnly() ) { if ( $this->readOnlyMode->isReadOnly() ) {
@ -343,12 +337,12 @@ class ApiVisualEditor extends ApiBase {
wfExpandUrl( Skin::makeInternalOrExternalUrl( wfExpandUrl( Skin::makeInternalOrExternalUrl(
$this->msg( 'helppage' )->inContentLanguage()->text() $this->msg( 'helppage' )->inContentLanguage()->text()
) ) ) )
)->parseAsBlock(); )->page( $title )->parseAsBlock();
// Page protected from creation // Page protected from creation
if ( $title->getRestrictions( 'create' ) ) { if ( $title->getRestrictions( 'create' ) ) {
$protectionNotices['titleprotectedwarning'] = $protectionNotices['titleprotectedwarning'] =
$this->msg( 'titleprotectedwarning' )->parseAsBlock() . $this->msg( 'titleprotectedwarning' )->page( $title )->parseAsBlock() .
$this->getLastLogEntry( $title, 'protect' ); $this->getLastLogEntry( $title, 'protect' );
} }
@ -386,7 +380,7 @@ class ApiVisualEditor extends ApiBase {
// Then it must be protected based on static groups (regular) // Then it must be protected based on static groups (regular)
$noticeMsg = 'protectedpagewarning'; $noticeMsg = 'protectedpagewarning';
} }
$protectionNotices[$noticeMsg] = $this->msg( $noticeMsg )->parseAsBlock() . $protectionNotices[$noticeMsg] = $this->msg( $noticeMsg )->page( $title )->parseAsBlock() .
$this->getLastLogEntry( $title, 'protect' ); $this->getLastLogEntry( $title, 'protect' );
} }
@ -395,7 +389,8 @@ class ApiVisualEditor extends ApiBase {
if ( isset( $restrictions['edit'] ) ) { if ( isset( $restrictions['edit'] ) ) {
$protectedClasses[] = ' mw-textarea-cprotected'; $protectedClasses[] = ' mw-textarea-cprotected';
$notice = $this->msg( 'cascadeprotectedwarning', count( $sources ) )->parseAsBlock() . '<ul>'; $notice = $this->msg( 'cascadeprotectedwarning', count( $sources ) )
->page( $title )->parseAsBlock() . '<ul>';
// Unfortunately there's no nice way to get only the pages which cause // Unfortunately there's no nice way to get only the pages which cause
// editing to be restricted // editing to be restricted
foreach ( $sources as $source ) { foreach ( $sources as $source ) {