EBernhardson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/201609

Change subject: Revert "Getting rid of some globals"
......................................................................

Revert "Getting rid of some globals"

This broke account creation for apps.

 <   anomie>bd808: Very likely $wgRequest !== 
               $loginForm->getContext()->getRequest() in 
SimpleCaptcha::addNewAccountApiForm(), so when it 
               uses $wgRequest to check later on it doesn't see the parameter 
renames made by that hook 
               function.

This reverts commit 23c6f2f04fe7616e057a3c7533e269f1800a84b3.

Change-Id: I793e7a987944d14c3be0eba4c4361793183a62b9
---
M Captcha.php
M ConfirmEditHooks.php
M FancyCaptcha.class.php
M QuestyCaptcha.class.php
4 files changed, 65 insertions(+), 81 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ConfirmEdit 
refs/changes/09/201609/1

diff --git a/Captcha.php b/Captcha.php
index 825fc5a..68da0e6 100644
--- a/Captcha.php
+++ b/Captcha.php
@@ -100,7 +100,7 @@
                $out = $context->getOutput();
                if ( isset( $page->ConfirmEdit_ActivateCaptcha ) ||
                        $this->showEditCaptcha ||
-                       $this->shouldCheck( $page, '', '', $context, false )
+                       $this->shouldCheck( $page, '', '', false )
                ) {
                        $out->addWikiText( $this->getMessage( $this->action ) );
                        $out->addHTML( $this->getForm() );
@@ -130,20 +130,16 @@
         * @return bool true to keep running callbacks
         */
        function injectEmailUser( &$form ) {
-               global $wgCaptchaTriggers;
-
-               $user = $form->getUser();
-               $out = $form->getOutput();
-
+               global $wgCaptchaTriggers, $wgOut, $wgUser;
                if ( $wgCaptchaTriggers['sendemail'] ) {
                        $this->action = 'sendemail';
-                       if ( $user->isAllowed( 'skipcaptcha' ) ) {
+                       if ( $wgUser->isAllowed( 'skipcaptcha' ) ) {
                                wfDebug( "ConfirmEdit: user group allows 
skipping captcha on email sending\n" );
                                return true;
                        }
                        $form->addFooterText(
                                "<div class='captcha'>" .
-                               $out->parse( $this->getMessage( 'sendemail' ) ) 
.
+                               $wgOut->parse( $this->getMessage( 'sendemail' ) 
) .
                                $this->getForm() .
                                "</div>\n" );
                }
@@ -157,19 +153,15 @@
         * @return bool true to keep running callbacks
         */
        function injectUserCreate( &$template ) {
-               global $wgCaptchaTriggers;
-
-               $user = $template->getSkin()->getUser();
-               $out = $template->getSkin()->getOutput();
-
+               global $wgCaptchaTriggers, $wgOut, $wgUser;
                if ( $wgCaptchaTriggers['createaccount'] ) {
                        $this->action = 'usercreate';
-                       if ( $user->isAllowed( 'skipcaptcha' ) ) {
+                       if ( $wgUser->isAllowed( 'skipcaptcha' ) ) {
                                wfDebug( "ConfirmEdit: user group allows 
skipping captcha on account creation\n" );
                                return true;
                        }
                        $captcha = "<div class='captcha'>" .
-                               $out->parse( $this->getMessage( 'createaccount' 
) ) .
+                               $wgOut->parse( $this->getMessage( 
'createaccount' ) ) .
                                $this->getForm() .
                                "</div>\n";
                        // for older MediaWiki versions
@@ -191,11 +183,11 @@
         */
        function injectUserLogin( &$template ) {
                if ( $this->isBadLoginTriggered() ) {
-                       $out = $template->getSkin()->getOutput();
+                       global $wgOut;
 
                        $this->action = 'badlogin';
                        $captcha = "<div class='captcha'>" .
-                               $out->parse( $this->getMessage( 'badlogin' ) ) .
+                               $wgOut->parse( $this->getMessage( 'badlogin' ) 
) .
                                $this->getForm() .
                                "</div>\n";
                        // for older MediaWiki versions
@@ -219,7 +211,6 @@
         */
        function triggerUserLogin( $user, $password, $retval ) {
                global $wgCaptchaTriggers, $wgCaptchaBadLoginExpiration, 
$wgMemc;
-
                if ( $retval == LoginForm::WRONG_PASS && 
$wgCaptchaTriggers['badlogin'] ) {
                        $key = $this->badLoginKey();
                        $count = $wgMemc->get( $key );
@@ -308,17 +299,12 @@
         * @param WikiPage $page
         * @param $content Content|string
         * @param $section string
-        * @param $context IContextSource
         * @param $isContent bool If true, $content is a Content object
         * @return bool true if the captcha should run
         */
-       function shouldCheck( WikiPage $page, $content, $section, 
IContextSource $context, $isContent = false ) {
-               global $wgEmailAuthentication, $ceAllowConfirmedEmail, 
$wgCaptchaRegexes;
-
+       function shouldCheck( WikiPage $page, $content, $section, $isContent = 
false ) {
                $title = $page->getTitle();
                $this->trigger = '';
-               $user = $context->getUser();
-
                if ( $isContent ) {
                        if ( $content->getModel() == CONTENT_MODEL_WIKITEXT ) {
                                $newtext = $content->getNativeData();
@@ -331,23 +317,27 @@
                        $isEmpty = $content === '';
                }
 
-               if ( $user->isAllowed( 'skipcaptcha' ) ) {
+               global $wgUser;
+               if ( $wgUser->isAllowed( 'skipcaptcha' ) ) {
                        wfDebug( "ConfirmEdit: user group allows skipping 
captcha\n" );
                        return false;
                }
                if ( $this->isIPWhitelisted() )
                        return false;
 
+
+               global $wgEmailAuthentication, $ceAllowConfirmedEmail;
                if ( $wgEmailAuthentication && $ceAllowConfirmedEmail &&
-                       $user->isEmailConfirmed() ) {
+                       $wgUser->isEmailConfirmed() ) {
                        wfDebug( "ConfirmEdit: user has confirmed mail, 
skipping captcha\n" );
                        return false;
                }
 
                if ( $this->captchaTriggers( $title, 'edit' ) ) {
                        // Check on all edits
+                       global $wgUser;
                        $this->trigger = sprintf( "edit trigger by '%s' at 
[[%s]]",
-                               $user->getName(),
+                               $wgUser->getName(),
                                $title->getPrefixedText() );
                        $this->action = 'edit';
                        wfDebug( "ConfirmEdit: checking all edits...\n" );
@@ -356,8 +346,9 @@
 
                if ( $this->captchaTriggers( $title, 'create' )  && 
!$title->exists() ) {
                        // Check if creating a page
+                       global $wgUser;
                        $this->trigger = sprintf( "Create trigger by '%s' at 
[[%s]]",
-                               $user->getName(),
+                               $wgUser->getName(),
                                $title->getPrefixedText() );
                        $this->action = 'create';
                        wfDebug( "ConfirmEdit: checking on page creation...\n" 
);
@@ -379,8 +370,8 @@
                        } else {
                                // Get link changes in the slowest way known to 
man
                                $oldtext = $this->loadText( $title, $section );
-                               $oldLinks = $this->findLinks( $title, $oldtext, 
$user );
-                               $newLinks = $this->findLinks( $title, $newtext, 
$user );
+                               $oldLinks = $this->findLinks( $title, $oldtext 
);
+                               $newLinks = $this->findLinks( $title, $newtext 
);
                        }
 
                        $unknownLinks = array_filter( $newLinks, array( &$this, 
'filterLink' ) );
@@ -388,9 +379,10 @@
                        $numLinks = count( $addedLinks );
 
                        if ( $numLinks > 0 ) {
+                               global $wgUser;
                                $this->trigger = sprintf( "%dx url trigger by 
'%s' at [[%s]]: %s",
                                        $numLinks,
-                                       $user->getName(),
+                                       $wgUser->getName(),
                                        $title->getPrefixedText(),
                                        implode( ", ", $addedLinks ) );
                                $this->action = 'addurl';
@@ -398,6 +390,7 @@
                        }
                }
 
+               global $wgCaptchaRegexes;
                if ( $newtext !== null && $wgCaptchaRegexes ) {
                        // Custom regex checks. Reuse $oldtext if set above.
                        $oldtext = isset( $oldtext ) ? $oldtext : 
$this->loadText( $title, $section );
@@ -412,10 +405,11 @@
 
                                        $numHits = count( $addedMatches );
                                        if ( $numHits > 0 ) {
+                                               global $wgUser;
                                                $this->trigger = sprintf( "%dx 
%s at [[%s]]: %s",
                                                        $numHits,
                                                        $regex,
-                                                       $user->getName(),
+                                                       $wgUser->getName(),
                                                        
$title->getPrefixedText(),
                                                        implode( ", ", 
$addedMatches ) );
                                                $this->action = 'edit';
@@ -555,20 +549,18 @@
         * @param WikiPage $page
         * @param $newtext string
         * @param $section
-        * @param IContextSource $context
         * @param $isContent bool
         * @return bool false if the CAPTCHA is rejected, true otherwise
         */
-       private function doConfirmEdit( WikiPage $page, $newtext, $section, 
IContextSource $context, $isContent = false ) {
-               $request = $context->getRequest();
-
-               if ( $request->getVal( 'captchaid' ) ) {
-                       $request->setVal( 'wpCaptchaId', $request->getVal( 
'captchaid' ) );
+       private function doConfirmEdit( WikiPage $page, $newtext, $section, 
$isContent = false ) {
+               global $wgRequest;
+               if ( $wgRequest->getVal( 'captchaid' ) ) {
+                       $wgRequest->setVal( 'wpCaptchaId', $wgRequest->getVal( 
'captchaid' ) );
                }
-               if ( $request->getVal( 'captchaword' ) ) {
-                       $request->setVal( 'wpCaptchaWord', $request->getVal( 
'captchaword' ) );
+               if ( $wgRequest->getVal( 'captchaword' ) ) {
+                       $wgRequest->setVal( 'wpCaptchaWord', 
$wgRequest->getVal( 'captchaword' ) );
                }
-               if ( $this->shouldCheck( $page, $newtext, $section, $context, 
$isContent ) ) {
+               if ( $this->shouldCheck( $page, $newtext, $section, $isContent 
) ) {
                        return $this->passCaptchaLimited();
                } else {
                        wfDebug( "ConfirmEdit: no need to show captcha.\n" );
@@ -594,7 +586,7 @@
                        return true;
                }
                $page = $context->getWikiPage();
-               if ( !$this->doConfirmEdit( $page, $content, false, $context, 
true ) ) {
+               if ( !$this->doConfirmEdit( $page, $content, false, true ) ) {
                        if ( $legacyMode ) {
                                $status->fatal( 'hookaborted' );
                        }
@@ -609,7 +601,7 @@
 
        function confirmEditAPI( $editPage, $newText, &$resultArr ) {
                $page = $editPage->getArticle()->getPage();
-               if ( !$this->doConfirmEdit( $page, $newText, false, 
$editPage->getArticle()->getContext(), false ) ) {
+               if ( !$this->doConfirmEdit( $page, $newText, false, false ) ) {
                        $this->addCaptchaAPI( $resultArr );
                        return false;
                }
@@ -647,17 +639,12 @@
         * Logic to check if we need to pass a captcha for the current user
         * to create a new account, or not
         *
-        * @param $user User
         * @return bool true to show captcha, false to skip captcha
         */
-       function needCreateAccountCaptcha( $user = null ) {
-               global $wgCaptchaTriggers;
-               if ( is_null( $user ) ) {
-                       global $wgUser;
-                       $user = $wgUser;
-               }
+       function needCreateAccountCaptcha() {
+               global $wgCaptchaTriggers, $wgUser;
                if ( $wgCaptchaTriggers['createaccount'] ) {
-                       if ( $user->isAllowed( 'skipcaptcha' ) ) {
+                       if ( $wgUser->isAllowed( 'skipcaptcha' ) ) {
                                wfDebug( "ConfirmEdit: user group allows 
skipping captcha on account creation\n" );
                                return false;
                        }
@@ -793,10 +780,9 @@
         * @return bool if passed, false if failed or new session
         */
        function passCaptcha() {
-               global $wgRequest;
-
-               $info = $this->retrieveCaptcha( $wgRequest );
+               $info = $this->retrieveCaptcha();
                if ( $info ) {
+                       global $wgRequest;
                        if ( $this->keyMatch( $wgRequest->getVal( 
'wpCaptchaWord' ), $info ) ) {
                                $this->log( "passed" );
                                $this->clearCaptcha( $info );
@@ -842,11 +828,11 @@
 
        /**
         * Fetch this session's captcha info.
-        * @param WebRequest
         * @return mixed array of info, or false if missing
         */
-       function retrieveCaptcha( WebRequest $request ) {
-               $index = $request->getVal( 'wpCaptchaId' );
+       function retrieveCaptcha() {
+               global $wgRequest;
+               $index = $wgRequest->getVal( 'wpCaptchaId' );
                return CaptchaStore::get()->retrieve( $index );
        }
 
@@ -884,14 +870,13 @@
         * Extract a list of all recognized HTTP links in the text.
         * @param $title Title
         * @param $text string
-        * @param $user User
         * @return array of strings
         */
-       function findLinks( $title, $text, User $user ) {
-               global $wgParser;
+       function findLinks( $title, $text ) {
+               global $wgParser, $wgUser;
 
                $options = new ParserOptions();
-               $text = $wgParser->preSaveTransform( $text, $title, $user, 
$options );
+               $text = $wgParser->preSaveTransform( $text, $title, $wgUser, 
$options );
                $out = $wgParser->parse( $text, $title, $options );
 
                return array_keys( $out->getExternalLinks() );
@@ -899,13 +884,13 @@
 
        /**
         * Show a page explaining what this wacky thing is.
-        * @param OutputPage
         */
-       function showHelp( OutputPage $out ) {
-               $out->setPageTitle( wfMessage( 'captchahelp-title' )->text() );
-               $out->addWikiMsg( 'captchahelp-text' );
+       function showHelp() {
+               global $wgOut;
+               $wgOut->setPageTitle( wfMessage( 'captchahelp-title' )->text() 
);
+               $wgOut->addWikiMsg( 'captchahelp-text' );
                if ( CaptchaStore::get()->cookiesNeeded() ) {
-                       $out->addWikiMsg( 'captchahelp-cookies-needed' );
+                       $wgOut->addWikiMsg( 'captchahelp-cookies-needed' );
                }
        }
 
@@ -918,12 +903,12 @@
         * @return hook return value
         */
        function addNewAccountApiForm( $apiModule, $loginForm ) {
-               $request = $loginForm->getContext()->getRequest();
+               global $wgRequest;
                $main = $apiModule->getMain();
 
                $id = $main->getVal( 'captchaid' );
                if ( $id ) {
-                       $request->setVal( 'wpCaptchaId', $id );
+                       $wgRequest->setVal( 'wpCaptchaId', $id );
 
                        // Suppress "unrecognized parameter" warning:
                        $main->getVal( 'wpCaptchaId' );
@@ -931,7 +916,7 @@
 
                $word = $main->getVal( 'captchaword' );
                if ( $word ) {
-                       $request->setVal( 'wpCaptchaWord', $word );
+                       $wgRequest->setVal( 'wpCaptchaWord', $word );
 
                        // Suppress "unrecognized parameter" warning:
                        $main->getVal( 'wpCaptchaWord' );
@@ -949,9 +934,7 @@
         * @return bool: Hook return value
         */
        function addNewAccountApiResult( $apiModule, $loginPage, &$result ) {
-               $user = $loginPage->getContext()->getUser();
-
-               if ( $result['result'] !== 'Success' && 
$this->needCreateAccountCaptcha( $user ) ) {
+               if ( $result['result'] !== 'Success' && 
$this->needCreateAccountCaptcha() ) {
 
                        // If we failed a captcha, override the generic 
'Warning' result string
                        if ( $result['result'] === 'Warning' && isset( 
$result['warnings'] ) ) {
diff --git a/ConfirmEditHooks.php b/ConfirmEditHooks.php
index 2d743f0..11badb3 100644
--- a/ConfirmEditHooks.php
+++ b/ConfirmEditHooks.php
@@ -125,7 +125,7 @@
                                }
                        case "help":
                        default:
-                               return $instance->showHelp( 
$this->getContext()->getOutput() );
+                               return $instance->showHelp();
                }
        }
 }
diff --git a/FancyCaptcha.class.php b/FancyCaptcha.class.php
index 87537f9..dee281f 100644
--- a/FancyCaptcha.class.php
+++ b/FancyCaptcha.class.php
@@ -327,11 +327,11 @@
        }
 
        function showImage() {
-               global $wgOut, $wgRequest;
+               global $wgOut;
 
                $wgOut->disable();
 
-               $info = $this->retrieveCaptcha( $wgRequest );
+               $info = $this->retrieveCaptcha();
                if ( $info ) {
                        $timestamp = new MWTimestamp();
                        $info['viewed'] = $timestamp->getTimestamp();
@@ -400,9 +400,9 @@
         * Delete a solved captcha image, if $wgCaptchaDeleteOnSolve is true.
         */
        function passCaptcha() {
-               global $wgCaptchaDeleteOnSolve, $wgRequest;
+               global $wgCaptchaDeleteOnSolve;
 
-               $info = $this->retrieveCaptcha( $wgRequest ); // get the 
captcha info before it gets deleted
+               $info = $this->retrieveCaptcha(); // get the captcha info 
before it gets deleted
                $pass = parent::passCaptcha();
 
                if ( $pass && $wgCaptchaDeleteOnSolve ) {
diff --git a/QuestyCaptcha.class.php b/QuestyCaptcha.class.php
index da6c79b..2e5274a 100644
--- a/QuestyCaptcha.class.php
+++ b/QuestyCaptcha.class.php
@@ -71,11 +71,12 @@
                return wfMessage( $name, $text )->isDisabled() ? wfMessage( 
'questycaptcha-edit' )->text() : $text;
        }
 
-       function showHelp( OutputPage $out ) {
-               $out->setPageTitle( wfMessage( 'captchahelp-title' )->text() );
-               $out->addWikiMsg( 'questycaptchahelp-text' );
+       function showHelp() {
+               global $wgOut;
+               $wgOut->setPageTitle( wfMessage( 'captchahelp-title' )->text() 
);
+               $wgOut->addWikiMsg( 'questycaptchahelp-text' );
                if ( CaptchaStore::get()->cookiesNeeded() ) {
-                       $out->addWikiMsg( 'captchahelp-cookies-needed' );
+                       $wgOut->addWikiMsg( 'captchahelp-cookies-needed' );
                }
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/201609
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I793e7a987944d14c3be0eba4c4361793183a62b9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ConfirmEdit
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to