Ori.livneh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/227936
Change subject: Fix crash in ContentTranslationHooks::onSaveOptions()
......................................................................
Fix crash in ContentTranslationHooks::onSaveOptions()
It is not safe to chain $wgOut->getTitle()->isSpecial(), because
OutputPage::getTitle() can return null, and the code will crash.
This has occurred in production. Fix it by checking that $title is truthy.
While I'm here, clarify the flow of control by rephrasing some of the
conditionals.
Change-Id: I81b1d021d3cb5fe585c99b29192fd399bf841189
---
M ContentTranslation.hooks.php
1 file changed, 22 insertions(+), 13 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/36/227936/1
diff --git a/ContentTranslation.hooks.php b/ContentTranslation.hooks.php
index 5fc5932..dc7db2e 100644
--- a/ContentTranslation.hooks.php
+++ b/ContentTranslation.hooks.php
@@ -216,21 +216,30 @@
public static function onSaveOptions( $user, &$saveOptions ) {
$out = RequestContext::getMain()->getOutput();
- if (
- isset( $saveOptions['cx'] ) &&
- $saveOptions['cx'] === '1' &&
- !isset( $saveOptions['cx-know'] ) &&
- !$out->getTitle()->isSpecial( 'ContentTranslation' )
- ) {
- $out->addModules(
- array( 'ext.cx.betafeature.init',
'ext.cx.campaigns.contributionsmenu' )
- );
-
- // This make sure the auto-open contribution menu shown
exactly once.
- // and it is not in Special:CX
- $saveOptions['cx-know'] = true;
+ if ( !isset( $saveOptions['cx'] ) || $saveOptions['cx'] !== 1 )
{
+ // Not using ContentTranslation; bail.
+ return true;
}
+ if ( isset( $saveOptions['cx-know'] ) ) {
+ // The auto-open contribution menu has already been
shown; bail.
+ return true;
+ }
+
+ $title = $out->getTitle();
+ if ( $title && $title->isSpecial( 'ContentTranslation' ) ) {
+ // Don't show the menu on Special:ContentTranslation.
+ return true;
+ }
+
+ // Show the auto-open contribution menu and set the cx-know
preference
+ // as true to prevent it from being automatically shown in the
future.
+ $out->addModules( array(
+ 'ext.cx.betafeature.init',
+ 'ext.cx.campaigns.contributionsmenu',
+ ) );
+ $saveOptions['cx-know'] = true;
+
return true;
}
--
To view, visit https://gerrit.wikimedia.org/r/227936
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I81b1d021d3cb5fe585c99b29192fd399bf841189
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits