diff --git a/Captcha.php b/Captcha.php
index 0fd168d8e..5170914a0 100644
--- a/Captcha.php
+++ b/Captcha.php
@@ -103,7 +103,7 @@ class SimpleCaptcha {
$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() );
@@ -133,20 +133,16 @@ class SimpleCaptcha {
* @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(
"
" .
- $out->parse( $this->getMessage( 'sendemail' ) ) .
+ $wgOut->parse( $this->getMessage( 'sendemail' ) ) .
$this->getForm() .
"
\n" );
}
@@ -160,19 +156,15 @@ class SimpleCaptcha {
* @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 = "" .
- $out->parse( $this->getMessage( 'createaccount' ) ) .
+ $wgOut->parse( $this->getMessage( 'createaccount' ) ) .
$this->getForm() .
"
\n";
// for older MediaWiki versions
@@ -194,11 +186,11 @@ class SimpleCaptcha {
*/
function injectUserLogin( &$template ) {
if ( $this->isBadLoginTriggered() ) {
- $out = $template->getSkin()->getOutput();
+ global $wgOut;
$this->action = 'badlogin';
$captcha = "" .
- $out->parse( $this->getMessage( 'badlogin' ) ) .
+ $wgOut->parse( $this->getMessage( 'badlogin' ) ) .
$this->getForm() .
"
\n";
// for older MediaWiki versions
@@ -222,7 +214,6 @@ class SimpleCaptcha {
*/
function triggerUserLogin( $user, $password, $retval ) {
global $wgCaptchaTriggers, $wgCaptchaBadLoginExpiration, $wgMemc;
-
if ( $retval == LoginForm::WRONG_PASS && $wgCaptchaTriggers['badlogin'] ) {
$key = $this->badLoginKey();
$count = $wgMemc->get( $key );
@@ -311,18 +302,14 @@ class SimpleCaptcha {
* @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()
@@ -342,23 +329,27 @@ class SimpleCaptcha {
$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" );
@@ -367,8 +358,9 @@ class SimpleCaptcha {
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" );
@@ -399,9 +391,10 @@ class SimpleCaptcha {
$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';
@@ -409,6 +402,7 @@ class SimpleCaptcha {
}
}
+ global $wgCaptchaRegexes;
if ( $newtext !== null && $wgCaptchaRegexes ) {
// Custom regex checks. Reuse $oldtext if set above.
$oldtext = isset( $oldtext ) ? $oldtext : $this->loadText( $title, $section, $loadOldtextFlags );
@@ -423,10 +417,11 @@ class SimpleCaptcha {
$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';
@@ -566,20 +561,18 @@ class SimpleCaptcha {
* @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" );
@@ -605,7 +598,7 @@ class SimpleCaptcha {
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' );
}
@@ -620,7 +613,7 @@ class SimpleCaptcha {
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;
}
@@ -658,17 +651,12 @@ class SimpleCaptcha {
* 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;
}
@@ -813,6 +801,7 @@ class SimpleCaptcha {
$info = $this->retrieveCaptcha( $wgRequest );
if ( $info ) {
+ global $wgRequest;
if ( $this->keyMatch( $wgRequest->getVal( 'wpCaptchaWord' ), $info ) ) {
$this->log( "passed" );
$this->clearCaptcha( $info );
@@ -860,11 +849,11 @@ class SimpleCaptcha {
/**
* 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 );
}
@@ -903,14 +892,13 @@ class SimpleCaptcha {
* 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() );
@@ -918,13 +906,13 @@ class SimpleCaptcha {
/**
* 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' );
}
}
@@ -937,12 +925,12 @@ class SimpleCaptcha {
* @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' );
@@ -950,7 +938,7 @@ class SimpleCaptcha {
$word = $main->getVal( 'captchaword' );
if ( $word ) {
- $request->setVal( 'wpCaptchaWord', $word );
+ $wgRequest->setVal( 'wpCaptchaWord', $word );
// Suppress "unrecognized parameter" warning:
$main->getVal( 'wpCaptchaWord' );
@@ -968,9 +956,7 @@ class SimpleCaptcha {
* @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 2d743f0a8..11badb350 100644
--- a/ConfirmEditHooks.php
+++ b/ConfirmEditHooks.php
@@ -125,7 +125,7 @@ class CaptchaSpecialPage extends UnlistedSpecialPage {
}
case "help":
default:
- return $instance->showHelp( $this->getContext()->getOutput() );
+ return $instance->showHelp();
}
}
}
diff --git a/FancyCaptcha.class.php b/FancyCaptcha.class.php
index ce3cdd1cb..06164b113 100644
--- a/FancyCaptcha.class.php
+++ b/FancyCaptcha.class.php
@@ -327,11 +327,11 @@ class FancyCaptcha extends SimpleCaptcha {
}
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 @@ class FancyCaptcha extends SimpleCaptcha {
* 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 da6c79b27..2e5274a80 100644
--- a/QuestyCaptcha.class.php
+++ b/QuestyCaptcha.class.php
@@ -71,11 +71,12 @@ class QuestyCaptcha extends SimpleCaptcha {
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' );
}
}
}