jenkins-bot has submitted this change and it was merged.

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(-)

Approvals:
  Nikerabbit: Looks good to me, approved
  jenkins-bot: Verified



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: merged
Gerrit-Change-Id: I81b1d021d3cb5fe585c99b29192fd399bf841189
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: Amire80 <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Santhosh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to