summaryrefslogtreecommitdiff
path: root/extensions/ConfirmEdit/Captcha.php
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/ConfirmEdit/Captcha.php')
-rw-r--r--extensions/ConfirmEdit/Captcha.php64
1 files changed, 35 insertions, 29 deletions
diff --git a/extensions/ConfirmEdit/Captcha.php b/extensions/ConfirmEdit/Captcha.php
index 3d6494ff..0f78d36f 100644
--- a/extensions/ConfirmEdit/Captcha.php
+++ b/extensions/ConfirmEdit/Captcha.php
@@ -1,7 +1,6 @@
<?php
class SimpleCaptcha {
-
function getCaptcha() {
$a = mt_rand( 0, 100 );
$b = mt_rand( 0, 10 );
@@ -65,15 +64,15 @@ class SimpleCaptcha {
* Show a message asking the user to enter a captcha on edit
* The result will be treated as wiki text
*
- * @param $action Action being performed
+ * @param $action string Action being performed
* @return string
*/
function getMessage( $action ) {
$name = 'captcha-' . $action;
- $text = wfMsg( $name );
+ $text = wfMessage( $name )->text();
# Obtain a more tailored message, if possible, otherwise, fall back to
# the default for edits
- return wfEmptyMsg( $name, $text ) ? wfMsg( 'captcha-edit' ) : $text;
+ return wfMessage( $name, $text )->isDisabled() ? wfMessage( 'captcha-edit' )->text() : $text;
}
/**
@@ -156,7 +155,8 @@ class SimpleCaptcha {
if ( !$count ) {
$wgMemc->add( $key, 0, $wgCaptchaBadLoginExpiration );
}
- $count = $wgMemc->incr( $key );
+
+ $wgMemc->incr( $key );
}
return true;
}
@@ -181,8 +181,7 @@ class SimpleCaptcha {
if ( $wgCaptchaWhitelistIP ) {
global $wgRequest;
- // Compat: WebRequest::getIP is only available since MW 1.19.
- $ip = method_exists( $wgRequest, 'getIP' ) ? $wgRequest->getIP() : wfGetIP();
+ $ip = $wgRequest->getIP();
foreach ( $wgCaptchaWhitelistIP as $range ) {
if ( IP::isInRange( $ip, $range ) ) {
@@ -200,8 +199,7 @@ class SimpleCaptcha {
*/
function badLoginKey() {
global $wgRequest;
- // Compat: WebRequest::getIP is only available since MW 1.19.
- $ip = method_exists( $wgRequest, 'getIP' ) ? $wgRequest->getIP() : wfGetIP();
+ $ip = $wgRequest->getIP();
return wfMemcKey( 'captcha', 'badlogin', 'ip', $ip );
}
@@ -236,9 +234,10 @@ class SimpleCaptcha {
}
/**
- * @param EditPage $editPage
- * @param string $newtext
- * @param string $section
+ * @param $editPage EditPage
+ * @param $newtext string
+ * @param $section string
+ * @param $merged bool
* @return bool true if the captcha should run
*/
function shouldCheck( &$editPage, $newtext, $section, $merged = false ) {
@@ -316,8 +315,8 @@ class SimpleCaptcha {
global $wgCaptchaRegexes;
if ( $wgCaptchaRegexes ) {
- // Custom regex checks
- $oldtext = $this->loadText( $editPage, $section );
+ // Custom regex checks. Reuse $oldtext if set above.
+ $oldtext = isset( $oldtext ) ? $oldtext : $this->loadText( $editPage, $section );
foreach ( $wgCaptchaRegexes as $regex ) {
$newMatches = array();
@@ -348,15 +347,15 @@ class SimpleCaptcha {
/**
* Filter callback function for URL whitelisting
- * @param string url to check
+ * @param $url string to check
* @return bool true if unknown, false if whitelisted
* @access private
*/
function filterLink( $url ) {
global $wgCaptchaWhitelist;
- $source = wfMsgForContent( 'captcha-addurl-whitelist' );
+ $source = wfMessage( 'captcha-addurl-whitelist' )->inContentLanguage()->text();
- $whitelist = wfEmptyMsg( 'captcha-addurl-whitelist', $source )
+ $whitelist = wfMessage( 'captcha-addurl-whitelist', $source )->isDisabled()
? false
: $this->buildRegexes( explode( "\n", $source ) );
@@ -368,7 +367,7 @@ class SimpleCaptcha {
/**
* Build regex from whitelist
- * @param string lines from [[MediaWiki:Captcha-addurl-whitelist]]
+ * @param $lines string from [[MediaWiki:Captcha-addurl-whitelist]]
* @return string Regex or bool false if whitelist is empty
* @access private
*/
@@ -433,6 +432,10 @@ class SimpleCaptcha {
/**
* Backend function for confirmEdit() and confirmEditAPI()
+ * @param $editPage EditPage
+ * @param $newtext string
+ * @param $section
+ * @param $merged bool
* @return bool false if the CAPTCHA is rejected, true otherwise
*/
private function doConfirmEdit( $editPage, $newtext, $section, $merged = false ) {
@@ -476,6 +479,7 @@ class SimpleCaptcha {
* A more efficient edit filter callback based on the text after section merging
* @param EditPage $editPage
* @param string $newtext
+ * @return bool
*/
function confirmEditMerged( $editPage, $newtext ) {
return $this->confirmEdit( $editPage, $newtext, false, true );
@@ -508,7 +512,7 @@ class SimpleCaptcha {
$this->trigger = "new account '" . $u->getName() . "'";
if ( !$this->passCaptcha() ) {
- $message = wfMsg( 'captcha-createaccount-fail' );
+ $message = wfMessage( 'captcha-createaccount-fail' )->text();
return false;
}
}
@@ -517,8 +521,9 @@ class SimpleCaptcha {
/**
* Hook for user login form submissions.
- * @param User $u
- * @param string $message
+ * @param $u User
+ * @param $pass
+ * @param $retval
* @return bool true to continue, false to abort user creation
*/
function confirmUserLogin( $u, $pass, &$retval ) {
@@ -558,12 +563,12 @@ class SimpleCaptcha {
if ( defined( 'MW_API' ) ) {
# API mode
# Asking for captchas in the API is really silly
- $error = wfMsg( 'captcha-disabledinapi' );
+ $error = wfMessage( 'captcha-disabledinapi' )->text();
return false;
}
$this->trigger = "{$wgUser->getName()} sending email";
if ( !$this->passCaptcha() ) {
- $error = wfMsg( 'captcha-sendemail-fail' );
+ $error = wfMessage( 'captcha-sendemail-fail' )->text();
return false;
}
}
@@ -586,7 +591,7 @@ class SimpleCaptcha {
}
/**
- * @param $module ApiBae
+ * @param $module ApiBase
* @param $desc array
* @return bool
*/
@@ -678,7 +683,7 @@ class SimpleCaptcha {
* @access private
*/
function loadText( $editPage, $section ) {
- $rev = Revision::newFromTitle( $editPage->mTitle );
+ $rev = Revision::newFromTitle( $editPage->mTitle, false, Revision::READ_LATEST );
if ( is_null( $rev ) ) {
return "";
} else {
@@ -694,7 +699,8 @@ class SimpleCaptcha {
/**
* Extract a list of all recognized HTTP links in the text.
- * @param string $text
+ * @param $editpage EditPage
+ * @param $text string
* @return array of strings
*/
function findLinks( &$editpage, $text ) {
@@ -712,10 +718,10 @@ class SimpleCaptcha {
*/
function showHelp() {
global $wgOut;
- $wgOut->setPageTitle( wfMsg( 'captchahelp-title' ) );
- $wgOut->addWikiText( wfMsg( 'captchahelp-text' ) );
+ $wgOut->setPageTitle( wfMessage( 'captchahelp-title' )->text() );
+ $wgOut->addWikiMsg( 'captchahelp-text' );
if ( CaptchaStore::get()->cookiesNeeded() ) {
- $wgOut->addWikiText( wfMsg( 'captchahelp-cookies-needed' ) );
+ $wgOut->addWikiMsg( 'captchahelp-cookies-needed' );
}
}
}