jenkins-bot has submitted this change and it was merged.
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
(cherry picked from commit 804903b4a7cf3a829ae22fcc3c7b00f8aa851cb9)
---
M Captcha.php
M ConfirmEditHooks.php
M FancyCaptcha.class.php
M QuestyCaptcha.class.php
4 files changed, 62 insertions(+), 75 deletions(-)
Approvals:
EBernhardson: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Captcha.php b/Captcha.php
index e928c3a..8c2d005 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,18 +299,14 @@
* @param WikiPage $page
* @param $content Content|string
* @param $section string
- * @param $context IContextSource
* @param $isContent bool If true, $content is a Content object
* @param $oldtext string The content of the revision prior to
$content. When
* null this will be loaded from the database.
* @return bool true if the captcha should run
*/
- function shouldCheck( WikiPage $page, $content, $section,
IContextSource $context, $isContent = false, $oldtext = null ) {
- global $wgEmailAuthentication, $ceAllowConfirmedEmail,
$wgCaptchaRegexes;
-
+ function shouldCheck( WikiPage $page, $content, $section, $isContent =
false, $oldtext = null ) {
$title = $page->getTitle();
$this->trigger = '';
- $user = $context->getUser();
if ( $oldtext === null ) {
$loadOldtextFlags = $context->getRequest()->wasPosted()
@@ -339,23 +326,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" );
@@ -364,8 +355,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"
);
@@ -396,9 +388,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';
@@ -406,6 +399,7 @@
}
}
+ global $wgCaptchaRegexes;
if ( $newtext !== null && $wgCaptchaRegexes ) {
// Custom regex checks. Reuse $oldtext if set above.
$oldtext = isset( $oldtext ) ? $oldtext :
$this->loadText( $title, $section, $loadOldtextFlags );
@@ -420,10 +414,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';
@@ -563,20 +558,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" );
@@ -602,7 +595,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' );
}
@@ -617,7 +610,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;
}
@@ -655,17 +648,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;
}
@@ -805,6 +793,7 @@
$info = $this->retrieveCaptcha( $wgRequest );
if ( $info ) {
+ global $wgRequest;
if ( $this->keyMatch( $wgRequest->getVal(
'wpCaptchaWord' ), $info ) ) {
$this->log( "passed" );
$this->clearCaptcha( $info );
@@ -850,11 +839,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 );
}
@@ -893,14 +882,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() );
@@ -908,13 +896,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' );
}
}
@@ -927,12 +915,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' );
@@ -940,7 +928,7 @@
$word = $main->getVal( 'captchaword' );
if ( $word ) {
- $request->setVal( 'wpCaptchaWord', $word );
+ $wgRequest->setVal( 'wpCaptchaWord', $word );
// Suppress "unrecognized parameter" warning:
$main->getVal( 'wpCaptchaWord' );
@@ -958,9 +946,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 ce3cdd1..06164b1 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/201620
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I793e7a987944d14c3be0eba4c4361793183a62b9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ConfirmEdit
Gerrit-Branch: wmf/1.25wmf24
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits