2007-11-12 07:42:25 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class SimpleCaptcha {
|
2014-05-30 14:33:05 +00:00
|
|
|
|
private $showEditCaptcha = false;
|
|
|
|
|
|
2008-02-28 17:42:23 +00:00
|
|
|
|
function getCaptcha() {
|
2009-07-19 15:13:01 +00:00
|
|
|
|
$a = mt_rand( 0, 100 );
|
|
|
|
|
$b = mt_rand( 0, 10 );
|
2010-10-29 19:31:07 +00:00
|
|
|
|
|
|
|
|
|
/* Minus sign is used in the question. UTF-8,
|
|
|
|
|
since the api uses text/plain, not text/html */
|
|
|
|
|
$op = mt_rand( 0, 1 ) ? '+' : '−';
|
2008-02-28 17:42:23 +00:00
|
|
|
|
|
2011-12-08 14:22:41 +00:00
|
|
|
|
// No space before and after $op, to ensure correct
|
|
|
|
|
// directionality.
|
|
|
|
|
$test = "$a$op$b";
|
2009-07-19 15:13:01 +00:00
|
|
|
|
$answer = ( $op == '+' ) ? ( $a + $b ) : ( $a - $b );
|
|
|
|
|
return array( 'question' => $test, 'answer' => $answer );
|
2008-02-28 17:42:23 +00:00
|
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
|
|
|
|
|
|
function addCaptchaAPI( &$resultArr ) {
|
2008-02-28 17:42:23 +00:00
|
|
|
|
$captcha = $this->getCaptcha();
|
|
|
|
|
$index = $this->storeCaptcha( $captcha );
|
|
|
|
|
$resultArr['captcha']['type'] = 'simple';
|
2008-02-29 21:44:21 +00:00
|
|
|
|
$resultArr['captcha']['mime'] = 'text/plain';
|
2008-02-28 17:42:23 +00:00
|
|
|
|
$resultArr['captcha']['id'] = $index;
|
|
|
|
|
$resultArr['captcha']['question'] = $captcha['question'];
|
|
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Insert a captcha prompt into the edit form.
|
|
|
|
|
* This sample implementation generates a simple arithmetic operation;
|
|
|
|
|
* it would be easy to defeat by machine.
|
|
|
|
|
*
|
|
|
|
|
* Override this!
|
|
|
|
|
*
|
|
|
|
|
* @return string HTML
|
|
|
|
|
*/
|
|
|
|
|
function getForm() {
|
2008-02-28 17:42:23 +00:00
|
|
|
|
$captcha = $this->getCaptcha();
|
|
|
|
|
$index = $this->storeCaptcha( $captcha );
|
2007-11-12 07:42:25 +00:00
|
|
|
|
|
2014-04-07 17:25:45 +00:00
|
|
|
|
return "<p><label for=\"wpCaptchaWord\">{$captcha['question']} = </label>" .
|
2008-12-20 09:32:47 +00:00
|
|
|
|
Xml::element( 'input', array(
|
2007-11-12 07:42:25 +00:00
|
|
|
|
'name' => 'wpCaptchaWord',
|
2014-07-30 01:39:22 +00:00
|
|
|
|
'class' => 'mw-ui-input',
|
2007-11-12 07:42:25 +00:00
|
|
|
|
'id' => 'wpCaptchaWord',
|
2013-06-28 18:36:31 +00:00
|
|
|
|
'size' => 5,
|
2013-05-03 01:09:51 +00:00
|
|
|
|
'autocomplete' => 'off',
|
2007-11-12 07:42:25 +00:00
|
|
|
|
'tabindex' => 1 ) ) . // tab in before the edit textarea
|
|
|
|
|
"</p>\n" .
|
2008-12-20 09:32:47 +00:00
|
|
|
|
Xml::element( 'input', array(
|
2007-11-12 07:42:25 +00:00
|
|
|
|
'type' => 'hidden',
|
|
|
|
|
'name' => 'wpCaptchaId',
|
|
|
|
|
'id' => 'wpCaptchaId',
|
|
|
|
|
'value' => $index ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-30 14:33:05 +00:00
|
|
|
|
* Show error message for missing or incorrect captcha on EditPage.
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
* @param EditPage $editPage
|
2007-11-12 07:42:25 +00:00
|
|
|
|
* @param OutputPage $out
|
|
|
|
|
*/
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
function showEditFormFields( &$editPage, &$out ) {
|
|
|
|
|
$page = $editPage->getArticle()->getPage();
|
|
|
|
|
if ( !isset( $page->ConfirmEdit_ActivateCaptcha ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
unset( $page->ConfirmEdit_ActivateCaptcha );
|
2014-05-30 14:33:05 +00:00
|
|
|
|
$out->addHTML(
|
|
|
|
|
Html::openElement(
|
|
|
|
|
'div',
|
|
|
|
|
array(
|
|
|
|
|
'id' => 'mw-confirmedit-error-area',
|
|
|
|
|
'class' => 'errorbox'
|
|
|
|
|
)
|
|
|
|
|
) .
|
|
|
|
|
Html::element(
|
|
|
|
|
'strong',
|
|
|
|
|
array(),
|
|
|
|
|
$out->msg( 'errorpagetitle' )->text()
|
|
|
|
|
) .
|
|
|
|
|
Html::element(
|
|
|
|
|
'div',
|
|
|
|
|
array( 'id' => 'errorbox-body' ),
|
|
|
|
|
$out->msg( 'captcha-sendemail-fail' )->text()
|
|
|
|
|
) .
|
|
|
|
|
Html::closeElement( 'div' )
|
|
|
|
|
);
|
|
|
|
|
$this->showEditCaptcha = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Insert the captcha prompt into an edit form.
|
|
|
|
|
* @param EditPage $editPage
|
|
|
|
|
*/
|
2015-02-27 18:29:04 +00:00
|
|
|
|
function editShowCaptcha( $editPage ) {
|
2014-05-30 14:33:05 +00:00
|
|
|
|
$context = $editPage->getArticle()->getContext();
|
|
|
|
|
$page = $editPage->getArticle()->getPage();
|
|
|
|
|
$out = $context->getOutput();
|
|
|
|
|
if ( isset( $page->ConfirmEdit_ActivateCaptcha ) ||
|
|
|
|
|
$this->showEditCaptcha ||
|
2014-12-14 21:16:57 +00:00
|
|
|
|
$this->shouldCheck( $page, '', '', $context, false )
|
2014-05-30 14:33:05 +00:00
|
|
|
|
) {
|
|
|
|
|
$out->addWikiText( $this->getMessage( $this->action ) );
|
|
|
|
|
$out->addHTML( $this->getForm() );
|
|
|
|
|
}
|
|
|
|
|
unset( $page->ConfirmEdit_ActivateCaptcha );
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show a message asking the user to enter a captcha on edit
|
|
|
|
|
* The result will be treated as wiki text
|
|
|
|
|
*
|
2012-09-02 12:26:25 +00:00
|
|
|
|
* @param $action string Action being performed
|
2007-11-12 07:42:25 +00:00
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function getMessage( $action ) {
|
|
|
|
|
$name = 'captcha-' . $action;
|
2012-08-16 21:21:50 +00:00
|
|
|
|
$text = wfMessage( $name )->text();
|
2007-11-12 07:42:25 +00:00
|
|
|
|
# Obtain a more tailored message, if possible, otherwise, fall back to
|
|
|
|
|
# the default for edits
|
2012-08-16 21:21:50 +00:00
|
|
|
|
return wfMessage( $name, $text )->isDisabled() ? wfMessage( 'captcha-edit' )->text() : $text;
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-04-10 21:26:03 +00:00
|
|
|
|
/**
|
|
|
|
|
* Inject whazawhoo
|
|
|
|
|
* @fixme if multiple thingies insert a header, could break
|
2011-04-24 11:41:49 +00:00
|
|
|
|
* @param $form HTMLForm
|
2010-04-10 21:26:03 +00:00
|
|
|
|
* @return bool true to keep running callbacks
|
|
|
|
|
*/
|
|
|
|
|
function injectEmailUser( &$form ) {
|
2014-12-14 21:16:57 +00:00
|
|
|
|
global $wgCaptchaTriggers;
|
|
|
|
|
|
|
|
|
|
$user = $form->getUser();
|
|
|
|
|
$out = $form->getOutput();
|
|
|
|
|
|
2010-04-10 21:26:03 +00:00
|
|
|
|
if ( $wgCaptchaTriggers['sendemail'] ) {
|
2015-01-18 13:39:02 +00:00
|
|
|
|
$this->action = 'sendemail';
|
2014-12-14 21:16:57 +00:00
|
|
|
|
if ( $user->isAllowed( 'skipcaptcha' ) ) {
|
2010-04-10 21:26:03 +00:00
|
|
|
|
wfDebug( "ConfirmEdit: user group allows skipping captcha on email sending\n" );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-11-23 19:09:57 +00:00
|
|
|
|
$form->addFooterText(
|
2010-04-10 21:26:03 +00:00
|
|
|
|
"<div class='captcha'>" .
|
2014-12-14 21:16:57 +00:00
|
|
|
|
$out->parse( $this->getMessage( 'sendemail' ) ) .
|
2010-04-10 21:26:03 +00:00
|
|
|
|
$this->getForm() .
|
|
|
|
|
"</div>\n" );
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Inject whazawhoo
|
|
|
|
|
* @fixme if multiple thingies insert a header, could break
|
2011-04-24 11:41:49 +00:00
|
|
|
|
* @param QuickTemplate $template
|
2007-11-12 07:42:25 +00:00
|
|
|
|
* @return bool true to keep running callbacks
|
|
|
|
|
*/
|
2009-09-26 00:49:32 +00:00
|
|
|
|
function injectUserCreate( &$template ) {
|
2014-12-14 21:16:57 +00:00
|
|
|
|
global $wgCaptchaTriggers;
|
|
|
|
|
|
|
|
|
|
$user = $template->getSkin()->getUser();
|
|
|
|
|
$out = $template->getSkin()->getOutput();
|
|
|
|
|
|
2009-07-19 15:13:01 +00:00
|
|
|
|
if ( $wgCaptchaTriggers['createaccount'] ) {
|
2015-01-18 13:39:02 +00:00
|
|
|
|
$this->action = 'usercreate';
|
2014-12-14 21:16:57 +00:00
|
|
|
|
if ( $user->isAllowed( 'skipcaptcha' ) ) {
|
2008-08-07 17:05:10 +00:00
|
|
|
|
wfDebug( "ConfirmEdit: user group allows skipping captcha on account creation\n" );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-01-14 16:34:23 +00:00
|
|
|
|
$captcha = "<div class='captcha'>" .
|
2014-12-14 21:16:57 +00:00
|
|
|
|
$out->parse( $this->getMessage( 'createaccount' ) ) .
|
2007-11-12 07:42:25 +00:00
|
|
|
|
$this->getForm() .
|
2015-01-14 16:34:23 +00:00
|
|
|
|
"</div>\n";
|
|
|
|
|
// for older MediaWiki versions
|
|
|
|
|
if ( is_callable( array( $template, 'extend' ) ) ) {
|
|
|
|
|
$template->extend( 'extrafields', $captcha );
|
|
|
|
|
} else {
|
|
|
|
|
$template->set( 'header', $captcha );
|
|
|
|
|
}
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Inject a captcha into the user login form after a failed
|
|
|
|
|
* password attempt as a speedbump for mass attacks.
|
2009-09-26 00:49:32 +00:00
|
|
|
|
* @fixme if multiple thingies insert a header, could break
|
2011-04-24 11:41:49 +00:00
|
|
|
|
* @param $template QuickTemplate
|
2007-11-12 07:42:25 +00:00
|
|
|
|
* @return bool true to keep running callbacks
|
|
|
|
|
*/
|
2009-09-26 00:49:32 +00:00
|
|
|
|
function injectUserLogin( &$template ) {
|
2009-07-19 15:13:01 +00:00
|
|
|
|
if ( $this->isBadLoginTriggered() ) {
|
2014-12-14 21:16:57 +00:00
|
|
|
|
$out = $template->getSkin()->getOutput();
|
2015-01-18 13:39:02 +00:00
|
|
|
|
|
|
|
|
|
$this->action = 'badlogin';
|
2015-01-14 16:34:23 +00:00
|
|
|
|
$captcha = "<div class='captcha'>" .
|
2014-12-14 21:16:57 +00:00
|
|
|
|
$out->parse( $this->getMessage( 'badlogin' ) ) .
|
2007-11-12 07:42:25 +00:00
|
|
|
|
$this->getForm() .
|
2015-01-14 16:34:23 +00:00
|
|
|
|
"</div>\n";
|
|
|
|
|
// for older MediaWiki versions
|
|
|
|
|
if ( is_callable( array( $template, 'extend' ) ) ) {
|
|
|
|
|
$template->extend( 'extrafields', $captcha );
|
|
|
|
|
} else {
|
|
|
|
|
$template->set( 'header', $captcha );
|
|
|
|
|
}
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* When a bad login attempt is made, increment an expiring counter
|
|
|
|
|
* in the memcache cloud. Later checks for this may trigger a
|
|
|
|
|
* captcha display to prevent too many hits from the same place.
|
|
|
|
|
* @param User $user
|
|
|
|
|
* @param string $password
|
|
|
|
|
* @param int $retval authentication return value
|
|
|
|
|
* @return bool true to keep running callbacks
|
|
|
|
|
*/
|
|
|
|
|
function triggerUserLogin( $user, $password, $retval ) {
|
|
|
|
|
global $wgCaptchaTriggers, $wgCaptchaBadLoginExpiration, $wgMemc;
|
2014-12-14 21:16:57 +00:00
|
|
|
|
|
2009-09-26 00:49:32 +00:00
|
|
|
|
if ( $retval == LoginForm::WRONG_PASS && $wgCaptchaTriggers['badlogin'] ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
|
$key = $this->badLoginKey();
|
|
|
|
|
$count = $wgMemc->get( $key );
|
2009-07-19 15:13:01 +00:00
|
|
|
|
if ( !$count ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
|
$wgMemc->add( $key, 0, $wgCaptchaBadLoginExpiration );
|
|
|
|
|
}
|
2012-08-16 21:21:50 +00:00
|
|
|
|
|
|
|
|
|
$wgMemc->incr( $key );
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Check if a bad login has already been registered for this
|
|
|
|
|
* IP address. If so, require a captcha.
|
|
|
|
|
* @return bool
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
|
|
|
|
function isBadLoginTriggered() {
|
2011-12-21 23:39:53 +00:00
|
|
|
|
global $wgMemc, $wgCaptchaTriggers, $wgCaptchaBadLoginAttempts;
|
|
|
|
|
return $wgCaptchaTriggers['badlogin'] && intval( $wgMemc->get( $this->badLoginKey() ) ) >= $wgCaptchaBadLoginAttempts;
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
|
|
2009-05-09 14:00:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* Check if the IP is allowed to skip captchas
|
|
|
|
|
*/
|
|
|
|
|
function isIPWhitelisted() {
|
|
|
|
|
global $wgCaptchaWhitelistIP;
|
2012-01-12 08:58:40 +00:00
|
|
|
|
|
2009-07-19 15:13:01 +00:00
|
|
|
|
if ( $wgCaptchaWhitelistIP ) {
|
2011-12-13 21:24:03 +00:00
|
|
|
|
global $wgRequest;
|
2012-01-12 08:58:40 +00:00
|
|
|
|
|
2012-09-02 12:26:25 +00:00
|
|
|
|
$ip = $wgRequest->getIP();
|
2012-01-12 08:58:40 +00:00
|
|
|
|
|
2009-05-09 14:00:13 +00:00
|
|
|
|
foreach ( $wgCaptchaWhitelistIP as $range ) {
|
|
|
|
|
if ( IP::isInRange( $ip, $range ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Internal cache key for badlogin checks.
|
|
|
|
|
* @return string
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
|
|
|
|
function badLoginKey() {
|
2011-12-13 21:24:03 +00:00
|
|
|
|
global $wgRequest;
|
2012-09-02 12:26:25 +00:00
|
|
|
|
$ip = $wgRequest->getIP();
|
2012-03-18 16:07:21 +00:00
|
|
|
|
return wfMemcKey( 'captcha', 'badlogin', 'ip', $ip );
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Check if the submitted form matches the captcha session data provided
|
|
|
|
|
* by the plugin when the form was generated.
|
|
|
|
|
*
|
|
|
|
|
* Override this!
|
|
|
|
|
*
|
2008-01-24 21:42:21 +00:00
|
|
|
|
* @param string $answer
|
2007-11-12 07:42:25 +00:00
|
|
|
|
* @param array $info
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2008-01-24 21:42:21 +00:00
|
|
|
|
function keyMatch( $answer, $info ) {
|
|
|
|
|
return $answer == $info['answer'];
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
|
|
/**
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
* @param Title $title
|
2007-11-12 07:42:25 +00:00
|
|
|
|
* @param string $action (edit/create/addurl...)
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
* @return bool true if action triggers captcha on $title's namespace
|
2007-11-12 07:42:25 +00:00
|
|
|
|
*/
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
function captchaTriggers( $title, $action ) {
|
2009-07-19 15:13:01 +00:00
|
|
|
|
global $wgCaptchaTriggers, $wgCaptchaTriggersOnNamespace;
|
|
|
|
|
// Special config for this NS?
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
if ( isset( $wgCaptchaTriggersOnNamespace[$title->getNamespace()][$action] ) )
|
|
|
|
|
return $wgCaptchaTriggersOnNamespace[$title->getNamespace()][$action];
|
2007-11-12 07:42:25 +00:00
|
|
|
|
|
2009-07-19 15:13:01 +00:00
|
|
|
|
return ( !empty( $wgCaptchaTriggers[$action] ) ); // Default
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
* @param WikiPage $page
|
|
|
|
|
* @param $content Content|string
|
2012-08-16 21:21:50 +00:00
|
|
|
|
* @param $section string
|
2014-12-14 21:16:57 +00:00
|
|
|
|
* @param $context IContextSource
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
* @param $isContent bool If true, $content is a Content object
|
2007-11-12 07:42:25 +00:00
|
|
|
|
* @return bool true if the captcha should run
|
|
|
|
|
*/
|
2014-12-14 21:16:57 +00:00
|
|
|
|
function shouldCheck( WikiPage $page, $content, $section, IContextSource $context, $isContent = false ) {
|
|
|
|
|
global $wgEmailAuthentication, $ceAllowConfirmedEmail, $wgCaptchaRegexes;
|
|
|
|
|
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
$title = $page->getTitle();
|
2007-11-12 07:42:25 +00:00
|
|
|
|
$this->trigger = '';
|
2014-12-14 21:16:57 +00:00
|
|
|
|
$user = $context->getUser();
|
|
|
|
|
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
if ( $isContent ) {
|
|
|
|
|
if ( $content->getModel() == CONTENT_MODEL_WIKITEXT ) {
|
|
|
|
|
$newtext = $content->getNativeData();
|
|
|
|
|
} else {
|
|
|
|
|
$newtext = null;
|
|
|
|
|
}
|
2015-02-27 18:29:04 +00:00
|
|
|
|
$isEmpty = $content->isEmpty();
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
} else {
|
|
|
|
|
$newtext = $content;
|
2015-02-27 18:29:04 +00:00
|
|
|
|
$isEmpty = $content === '';
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
}
|
2007-11-12 07:42:25 +00:00
|
|
|
|
|
2014-12-14 21:16:57 +00:00
|
|
|
|
if ( $user->isAllowed( 'skipcaptcha' ) ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
|
wfDebug( "ConfirmEdit: user group allows skipping captcha\n" );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
|
if ( $this->isIPWhitelisted() )
|
2009-05-09 14:00:13 +00:00
|
|
|
|
return false;
|
2009-08-03 09:34:39 +00:00
|
|
|
|
|
2009-07-19 15:13:01 +00:00
|
|
|
|
if ( $wgEmailAuthentication && $ceAllowConfirmedEmail &&
|
2014-12-14 21:16:57 +00:00
|
|
|
|
$user->isEmailConfirmed() ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
|
wfDebug( "ConfirmEdit: user has confirmed mail, skipping captcha\n" );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
if ( $this->captchaTriggers( $title, 'edit' ) ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
|
// Check on all edits
|
|
|
|
|
$this->trigger = sprintf( "edit trigger by '%s' at [[%s]]",
|
2014-12-14 21:16:57 +00:00
|
|
|
|
$user->getName(),
|
2007-11-12 07:42:25 +00:00
|
|
|
|
$title->getPrefixedText() );
|
|
|
|
|
$this->action = 'edit';
|
|
|
|
|
wfDebug( "ConfirmEdit: checking all edits...\n" );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
if ( $this->captchaTriggers( $title, 'create' ) && !$title->exists() ) {
|
2009-07-19 15:13:01 +00:00
|
|
|
|
// Check if creating a page
|
2007-11-12 07:42:25 +00:00
|
|
|
|
$this->trigger = sprintf( "Create trigger by '%s' at [[%s]]",
|
2014-12-14 21:16:57 +00:00
|
|
|
|
$user->getName(),
|
2007-11-12 07:42:25 +00:00
|
|
|
|
$title->getPrefixedText() );
|
|
|
|
|
$this->action = 'create';
|
|
|
|
|
wfDebug( "ConfirmEdit: checking on page creation...\n" );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-27 18:29:04 +00:00
|
|
|
|
if ( !$isEmpty && $this->captchaTriggers( $title, 'addurl' ) ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
|
// Only check edits that add URLs
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
if ( $isContent ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
|
// Get links from the database
|
|
|
|
|
$oldLinks = $this->getLinksFromTracker( $title );
|
|
|
|
|
// Share a parse operation with Article::doEdit()
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
$editInfo = $page->prepareContentForEdit( $content );
|
|
|
|
|
if ( $editInfo->output ) {
|
|
|
|
|
$newLinks = array_keys( $editInfo->output->getExternalLinks() );
|
|
|
|
|
} else {
|
|
|
|
|
$newLinks = array();
|
|
|
|
|
}
|
2007-11-12 07:42:25 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Get link changes in the slowest way known to man
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
$oldtext = $this->loadText( $title, $section );
|
2014-12-14 21:16:57 +00:00
|
|
|
|
$oldLinks = $this->findLinks( $title, $oldtext, $user );
|
|
|
|
|
$newLinks = $this->findLinks( $title, $newtext, $user );
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$unknownLinks = array_filter( $newLinks, array( &$this, 'filterLink' ) );
|
|
|
|
|
$addedLinks = array_diff( $unknownLinks, $oldLinks );
|
|
|
|
|
$numLinks = count( $addedLinks );
|
|
|
|
|
|
2009-07-19 15:13:01 +00:00
|
|
|
|
if ( $numLinks > 0 ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
|
$this->trigger = sprintf( "%dx url trigger by '%s' at [[%s]]: %s",
|
|
|
|
|
$numLinks,
|
2014-12-14 21:16:57 +00:00
|
|
|
|
$user->getName(),
|
2007-11-12 07:42:25 +00:00
|
|
|
|
$title->getPrefixedText(),
|
|
|
|
|
implode( ", ", $addedLinks ) );
|
|
|
|
|
$this->action = 'addurl';
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
if ( $newtext !== null && $wgCaptchaRegexes ) {
|
2012-09-26 21:15:39 +00:00
|
|
|
|
// Custom regex checks. Reuse $oldtext if set above.
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
$oldtext = isset( $oldtext ) ? $oldtext : $this->loadText( $title, $section );
|
2007-11-12 07:42:25 +00:00
|
|
|
|
|
2009-07-19 15:13:01 +00:00
|
|
|
|
foreach ( $wgCaptchaRegexes as $regex ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
|
$newMatches = array();
|
2009-07-19 15:13:01 +00:00
|
|
|
|
if ( preg_match_all( $regex, $newtext, $newMatches ) ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
|
$oldMatches = array();
|
|
|
|
|
preg_match_all( $regex, $oldtext, $oldMatches );
|
|
|
|
|
|
|
|
|
|
$addedMatches = array_diff( $newMatches[0], $oldMatches[0] );
|
|
|
|
|
|
|
|
|
|
$numHits = count( $addedMatches );
|
2009-07-19 15:13:01 +00:00
|
|
|
|
if ( $numHits > 0 ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
|
$this->trigger = sprintf( "%dx %s at [[%s]]: %s",
|
|
|
|
|
$numHits,
|
|
|
|
|
$regex,
|
2014-12-14 21:16:57 +00:00
|
|
|
|
$user->getName(),
|
2007-11-12 07:42:25 +00:00
|
|
|
|
$title->getPrefixedText(),
|
|
|
|
|
implode( ", ", $addedMatches ) );
|
|
|
|
|
$this->action = 'edit';
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Filter callback function for URL whitelisting
|
2012-09-02 12:26:25 +00:00
|
|
|
|
* @param $url string to check
|
2007-11-12 07:42:25 +00:00
|
|
|
|
* @return bool true if unknown, false if whitelisted
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
|
|
|
|
function filterLink( $url ) {
|
|
|
|
|
global $wgCaptchaWhitelist;
|
2013-11-23 17:59:53 +00:00
|
|
|
|
static $regexes = null;
|
2007-11-12 07:42:25 +00:00
|
|
|
|
|
2013-11-23 17:59:53 +00:00
|
|
|
|
if ( $regexes === null ) {
|
|
|
|
|
$source = wfMessage( 'captcha-addurl-whitelist' )->inContentLanguage();
|
2007-11-12 07:42:25 +00:00
|
|
|
|
|
2013-11-23 17:59:53 +00:00
|
|
|
|
$regexes = $source->isDisabled()
|
|
|
|
|
? array()
|
|
|
|
|
: $this->buildRegexes( explode( "\n", $source->plain() ) );
|
2007-11-12 07:42:25 +00:00
|
|
|
|
|
2013-11-23 17:59:53 +00:00
|
|
|
|
if ( $wgCaptchaWhitelist !== false ) {
|
|
|
|
|
array_unshift( $regexes, $wgCaptchaWhitelist );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $regexes as $regex ) {
|
|
|
|
|
if ( preg_match( $regex, $url ) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Build regex from whitelist
|
2012-09-02 12:26:25 +00:00
|
|
|
|
* @param $lines string from [[MediaWiki:Captcha-addurl-whitelist]]
|
2013-11-23 17:59:53 +00:00
|
|
|
|
* @return array Regexes
|
2007-11-12 07:42:25 +00:00
|
|
|
|
* @access private
|
|
|
|
|
*/
|
|
|
|
|
function buildRegexes( $lines ) {
|
|
|
|
|
# Code duplicated from the SpamBlacklist extension (r19197)
|
2013-11-23 17:59:53 +00:00
|
|
|
|
# and later modified.
|
2007-11-12 07:42:25 +00:00
|
|
|
|
|
|
|
|
|
# Strip comments and whitespace, then remove blanks
|
|
|
|
|
$lines = array_filter( array_map( 'trim', preg_replace( '/#.*$/', '', $lines ) ) );
|
|
|
|
|
|
|
|
|
|
# No lines, don't make a regex which will match everything
|
|
|
|
|
if ( count( $lines ) == 0 ) {
|
|
|
|
|
wfDebug( "No lines\n" );
|
2013-11-23 17:59:53 +00:00
|
|
|
|
return array();
|
2007-11-12 07:42:25 +00:00
|
|
|
|
} else {
|
|
|
|
|
# Make regex
|
|
|
|
|
# It's faster using the S modifier even though it will usually only be run once
|
2009-07-19 15:13:01 +00:00
|
|
|
|
// $regex = 'http://+[a-z0-9_\-.]*(' . implode( '|', $lines ) . ')';
|
|
|
|
|
// return '/' . str_replace( '/', '\/', preg_replace('|\\\*/|', '/', $regex) ) . '/Si';
|
2013-11-23 17:59:53 +00:00
|
|
|
|
$regexes = array();
|
|
|
|
|
$regexStart = array(
|
2014-10-22 14:10:37 +00:00
|
|
|
|
'normal' => '/^(?:https?:)?\/\/+[a-z0-9_\-.]*(?:',
|
2013-11-23 17:59:53 +00:00
|
|
|
|
'noprotocol' => '/^(?:',
|
|
|
|
|
);
|
|
|
|
|
$regexEnd = array(
|
|
|
|
|
'normal' => ')/Si',
|
|
|
|
|
'noprotocol' => ')/Si',
|
|
|
|
|
);
|
2007-11-12 07:42:25 +00:00
|
|
|
|
$regexMax = 4096;
|
2013-11-23 17:59:53 +00:00
|
|
|
|
$build = array();
|
2009-07-19 15:13:01 +00:00
|
|
|
|
foreach ( $lines as $line ) {
|
2013-11-23 17:59:53 +00:00
|
|
|
|
# Extract flags from the line
|
|
|
|
|
$options = array();
|
|
|
|
|
if ( preg_match( '/^(.*?)\s*<([^<>]*)>$/', $line, $matches ) ) {
|
|
|
|
|
if ( $matches[1] === '' ) {
|
|
|
|
|
wfDebug( "Line with empty regex\n" );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$line = $matches[1];
|
|
|
|
|
$opts = preg_split( '/\s*\|\s*/', trim( $matches[2] ) );
|
|
|
|
|
foreach ( $opts as $opt ) {
|
|
|
|
|
$opt = strtolower( $opt );
|
|
|
|
|
if ( $opt == 'noprotocol' ) {
|
|
|
|
|
$options['noprotocol'] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$key = isset( $options['noprotocol'] ) ? 'noprotocol' : 'normal';
|
|
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
|
// FIXME: not very robust size check, but should work. :)
|
2013-11-23 17:59:53 +00:00
|
|
|
|
if ( !isset( $build[$key] ) ) {
|
|
|
|
|
$build[$key] = $line;
|
|
|
|
|
} elseif ( strlen( $build[$key] ) + strlen( $line ) > $regexMax ) {
|
|
|
|
|
$regexes[] = $regexStart[$key] .
|
|
|
|
|
str_replace( '/', '\/', preg_replace( '|\\\*/|', '/', $build[$key] ) ) .
|
|
|
|
|
$regexEnd[$key];
|
|
|
|
|
$build[$key] = $line;
|
2007-11-12 07:42:25 +00:00
|
|
|
|
} else {
|
2013-11-23 17:59:53 +00:00
|
|
|
|
$build[$key] .= '|' . $line;
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-23 17:59:53 +00:00
|
|
|
|
foreach ( $build as $key => $value ) {
|
|
|
|
|
$regexes[] = $regexStart[$key] .
|
|
|
|
|
str_replace( '/', '\/', preg_replace( '|\\\*/|', '/', $build[$key] ) ) .
|
|
|
|
|
$regexEnd[$key];
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|
|
|
|
|
return $regexes;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load external links from the externallinks table
|
2011-04-24 11:41:49 +00:00
|
|
|
|
* @param $title Title
|
|
|
|
|
* @return Array
|
2007-11-12 07:42:25 +00:00
|
|
|
|
*/
|
|
|
|
|
function getLinksFromTracker( $title ) {
|
2010-02-13 23:03:40 +00:00
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2012-03-11 19:04:37 +00:00
|
|
|
|
$id = $title->getArticleID(); // should be zero queries
|
2009-07-19 15:13:01 +00:00
|
|
|
|
$res = $dbr->select( 'externallinks', array( 'el_to' ),
|
2007-11-12 07:42:25 +00:00
|
|
|
|
array( 'el_from' => $id ), __METHOD__ );
|
|
|
|
|
$links = array();
|
2010-10-29 21:30:20 +00:00
|
|
|
|
foreach ( $res as $row ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
|
$links[] = $row->el_to;
|
|
|
|
|
}
|
|
|
|
|
return $links;
|
2008-02-28 17:42:23 +00:00
|
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
|
/**
|
2008-02-28 17:42:23 +00:00
|
|
|
|
* Backend function for confirmEdit() and confirmEditAPI()
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
* @param WikiPage $page
|
2012-08-16 21:21:50 +00:00
|
|
|
|
* @param $newtext string
|
|
|
|
|
* @param $section
|
2014-12-14 21:16:57 +00:00
|
|
|
|
* @param IContextSource $context
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
* @param $isContent bool
|
2008-02-28 17:42:23 +00:00
|
|
|
|
* @return bool false if the CAPTCHA is rejected, true otherwise
|
2007-11-12 07:42:25 +00:00
|
|
|
|
*/
|
2014-12-14 21:16:57 +00:00
|
|
|
|
private function doConfirmEdit( WikiPage $page, $newtext, $section, IContextSource $context, $isContent = false ) {
|
|
|
|
|
$request = $context->getRequest();
|
|
|
|
|
|
|
|
|
|
if ( $request->getVal( 'captchaid' ) ) {
|
|
|
|
|
$request->setVal( 'wpCaptchaId', $request->getVal( 'captchaid' ) );
|
2011-11-23 20:37:13 +00:00
|
|
|
|
}
|
2014-12-14 21:16:57 +00:00
|
|
|
|
if ( $request->getVal( 'captchaword' ) ) {
|
|
|
|
|
$request->setVal( 'wpCaptchaWord', $request->getVal( 'captchaword' ) );
|
2011-11-23 20:37:13 +00:00
|
|
|
|
}
|
2014-12-14 21:16:57 +00:00
|
|
|
|
if ( $this->shouldCheck( $page, $newtext, $section, $context, $isContent ) ) {
|
2015-01-02 22:56:02 +00:00
|
|
|
|
return $this->passCaptchaLimited();
|
2007-11-12 07:42:25 +00:00
|
|
|
|
} else {
|
|
|
|
|
wfDebug( "ConfirmEdit: no need to show captcha.\n" );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-28 17:42:23 +00:00
|
|
|
|
/**
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
* An efficient edit filter callback based on the text after section merging
|
|
|
|
|
* @param RequestContext $context
|
|
|
|
|
* @param Content $content
|
|
|
|
|
* @param Status $status
|
|
|
|
|
* @param $summary
|
|
|
|
|
* @param $user
|
|
|
|
|
* @param $minorEdit
|
|
|
|
|
* @return bool
|
2008-02-28 17:42:23 +00:00
|
|
|
|
*/
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
function confirmEditMerged( $context, $content, $status, $summary, $user, $minorEdit ) {
|
|
|
|
|
$legacyMode = !defined( 'MW_EDITFILTERMERGED_SUPPORTS_API' );
|
|
|
|
|
if ( defined( 'MW_API' ) && $legacyMode ) {
|
2008-02-28 17:42:23 +00:00
|
|
|
|
# API mode
|
2009-07-19 15:13:01 +00:00
|
|
|
|
# The CAPTCHA was already checked and approved
|
2008-02-28 17:42:23 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
$page = $context->getWikiPage();
|
2014-12-14 21:16:57 +00:00
|
|
|
|
if ( !$this->doConfirmEdit( $page, $content, false, $context, true ) ) {
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
if ( $legacyMode ) {
|
|
|
|
|
$status->fatal( 'hookaborted' );
|
|
|
|
|
}
|
|
|
|
|
$status->value = EditPage::AS_HOOK_ERROR_EXPECTED;
|
|
|
|
|
$status->apiHookResult = array();
|
|
|
|
|
$this->addCaptchaAPI( $status->apiHookResult );
|
|
|
|
|
$page->ConfirmEdit_ActivateCaptcha = true;
|
|
|
|
|
return $legacyMode;
|
2008-02-28 17:42:23 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
function confirmEditAPI( $editPage, $newText, &$resultArr ) {
|
|
|
|
|
$page = $editPage->getArticle()->getPage();
|
2014-12-14 21:16:57 +00:00
|
|
|
|
if ( !$this->doConfirmEdit( $page, $newText, false, $editPage->getArticle()->getContext(), false ) ) {
|
2009-07-19 15:13:01 +00:00
|
|
|
|
$this->addCaptchaAPI( $resultArr );
|
2008-02-28 17:42:23 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-11-23 19:09:57 +00:00
|
|
|
|
|
2008-02-28 17:42:23 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2007-11-12 07:42:25 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Hook for user creation form submissions.
|
|
|
|
|
* @param User $u
|
|
|
|
|
* @param string $message
|
2014-01-17 20:56:56 +00:00
|
|
|
|
* @param Status $status
|
2007-11-12 07:42:25 +00:00
|
|
|
|
* @return bool true to continue, false to abort user creation
|
|
|
|
|
*/
|
2014-01-17 20:56:56 +00:00
|
|
|
|
function confirmUserCreate( $u, &$message, &$status = null ) {
|
2014-01-10 23:16:34 +00:00
|
|
|
|
if ( $this->needCreateAccountCaptcha() ) {
|
|
|
|
|
$this->trigger = "new account '" . $u->getName() . "'";
|
2015-01-02 22:56:02 +00:00
|
|
|
|
if ( !$this->passCaptchaLimited() ) {
|
2014-01-17 20:56:56 +00:00
|
|
|
|
// For older MediaWiki
|
2014-01-10 23:16:34 +00:00
|
|
|
|
$message = wfMessage( 'captcha-createaccount-fail' )->text();
|
2014-01-17 20:56:56 +00:00
|
|
|
|
// For MediaWiki 1.23+
|
Cleaner response for captcha-related createaccount API failure
Instead of a generic API error, you get back a non-Success-resulted
creataccount response, with result='NeedCaptcha'. There's also a warning
included with the message key, and of course the captcha key:
array (
'createaccount' =>
array (
'result' => 'NeedCaptcha',
'warnings' =>
array (
0 =>
array (
'type' => 'warning',
'message' => 'captcha-createaccount-fail',
'params' =>
array (
),
),
),
'captcha' =>
array (
'type' => 'simple',
'mime' => 'text/plain',
'id' => '91510936',
'question' => '76−3',
),
),
)
Change-Id: Id1c9e387c592e6d51a5bd58d99ce3d644dfa300b
2014-02-28 22:42:41 +00:00
|
|
|
|
$status = Status::newGood();
|
2014-05-30 14:33:05 +00:00
|
|
|
|
|
Cleaner response for captcha-related createaccount API failure
Instead of a generic API error, you get back a non-Success-resulted
creataccount response, with result='NeedCaptcha'. There's also a warning
included with the message key, and of course the captcha key:
array (
'createaccount' =>
array (
'result' => 'NeedCaptcha',
'warnings' =>
array (
0 =>
array (
'type' => 'warning',
'message' => 'captcha-createaccount-fail',
'params' =>
array (
),
),
),
'captcha' =>
array (
'type' => 'simple',
'mime' => 'text/plain',
'id' => '91510936',
'question' => '76−3',
),
),
)
Change-Id: Id1c9e387c592e6d51a5bd58d99ce3d644dfa300b
2014-02-28 22:42:41 +00:00
|
|
|
|
// Apply a *non*-fatal warning. This will still abort the
|
|
|
|
|
// account creation but returns a "Warning" response to the
|
|
|
|
|
// API or UI.
|
|
|
|
|
$status->warning( 'captcha-createaccount-fail' );
|
2014-01-10 23:16:34 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-05-30 14:33:05 +00:00
|
|
|
|
|
2014-01-10 23:16:34 +00:00
|
|
|
|
/**
|
|
|
|
|
* Logic to check if we need to pass a captcha for the current user
|
|
|
|
|
* to create a new account, or not
|
|
|
|
|
*
|
2014-12-14 21:16:57 +00:00
|
|
|
|
* @param $user User
|
2014-01-10 23:16:34 +00:00
|
|
|
|
* @return bool true to show captcha, false to skip captcha
|
|
|
|
|
*/
|
2014-12-14 21:16:57 +00:00
|
|
|
|
function needCreateAccountCaptcha( $user = null ) {
|
|
|
|
|
global $wgCaptchaTriggers;
|
|
|
|
|
if ( is_null( $user ) ) {
|
|
|
|
|
global $wgUser;
|
|
|
|
|
$user = $wgUser;
|
|
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
|
if ( $wgCaptchaTriggers['createaccount'] ) {
|
2014-12-14 21:16:57 +00:00
|
|
|
|
if ( $user->isAllowed( 'skipcaptcha' ) ) {
|
2008-08-07 17:05:10 +00:00
|
|
|
|
wfDebug( "ConfirmEdit: user group allows skipping captcha on account creation\n" );
|
2014-01-10 23:16:34 +00:00
|
|
|
|
return false;
|
2008-08-07 17:05:10 +00:00
|
|
|
|
}
|
2014-01-10 23:16:34 +00:00
|
|
|
|
if ( $this->isIPWhitelisted() ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-01-10 23:16:34 +00:00
|
|
|
|
return true;
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|
2014-01-10 23:16:34 +00:00
|
|
|
|
return false;
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|
2009-07-19 15:13:01 +00:00
|
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Hook for user login form submissions.
|
2012-08-16 21:21:50 +00:00
|
|
|
|
* @param $u User
|
|
|
|
|
* @param $pass
|
|
|
|
|
* @param $retval
|
2007-11-12 07:42:25 +00:00
|
|
|
|
* @return bool true to continue, false to abort user creation
|
|
|
|
|
*/
|
|
|
|
|
function confirmUserLogin( $u, $pass, &$retval ) {
|
2009-07-19 15:13:01 +00:00
|
|
|
|
if ( $this->isBadLoginTriggered() ) {
|
|
|
|
|
if ( $this->isIPWhitelisted() )
|
2009-05-09 14:00:13 +00:00
|
|
|
|
return true;
|
2009-07-19 15:13:01 +00:00
|
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
|
$this->trigger = "post-badlogin login '" . $u->getName() . "'";
|
2015-01-02 22:56:02 +00:00
|
|
|
|
if ( !$this->passCaptchaLimited() ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
|
// Emulate a bad-password return to confuse the shit out of attackers
|
2009-09-26 00:49:32 +00:00
|
|
|
|
$retval = LoginForm::WRONG_PASS;
|
2007-11-12 07:42:25 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-10 21:26:03 +00:00
|
|
|
|
/**
|
2011-11-23 19:09:57 +00:00
|
|
|
|
* Check the captcha on Special:EmailUser
|
2010-04-10 21:26:03 +00:00
|
|
|
|
* @param $from MailAddress
|
|
|
|
|
* @param $to MailAddress
|
|
|
|
|
* @param $subject String
|
|
|
|
|
* @param $text String
|
|
|
|
|
* @param $error String reference
|
|
|
|
|
* @return Bool true to continue saving, false to abort and show a captcha form
|
|
|
|
|
*/
|
|
|
|
|
function confirmEmailUser( $from, $to, $subject, $text, &$error ) {
|
|
|
|
|
global $wgCaptchaTriggers, $wgUser;
|
|
|
|
|
if ( $wgCaptchaTriggers['sendemail'] ) {
|
|
|
|
|
if ( $wgUser->isAllowed( 'skipcaptcha' ) ) {
|
|
|
|
|
wfDebug( "ConfirmEdit: user group allows skipping captcha on email sending\n" );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if ( $this->isIPWhitelisted() )
|
|
|
|
|
return true;
|
2011-11-23 19:09:57 +00:00
|
|
|
|
|
2010-04-10 21:26:03 +00:00
|
|
|
|
if ( defined( 'MW_API' ) ) {
|
|
|
|
|
# API mode
|
|
|
|
|
# Asking for captchas in the API is really silly
|
2012-08-16 21:21:50 +00:00
|
|
|
|
$error = wfMessage( 'captcha-disabledinapi' )->text();
|
2010-04-10 21:26:03 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$this->trigger = "{$wgUser->getName()} sending email";
|
2015-01-02 22:56:02 +00:00
|
|
|
|
if ( !$this->passCaptchaLimited() ) {
|
2012-08-16 21:21:50 +00:00
|
|
|
|
$error = wfMessage( 'captcha-sendemail-fail' )->text();
|
2010-04-10 21:26:03 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-16 15:42:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* @param $module ApiBase
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
protected function isAPICaptchaModule( $module ) {
|
2014-01-10 23:16:34 +00:00
|
|
|
|
return $module instanceof ApiEditPage || $module instanceof ApiCreateAccount;
|
2013-03-16 15:42:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-23 19:09:57 +00:00
|
|
|
|
/**
|
|
|
|
|
* @param $module ApiBase
|
|
|
|
|
* @param $params array
|
2013-03-16 15:42:51 +00:00
|
|
|
|
* @param $flags int
|
2011-11-23 19:09:57 +00:00
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2013-03-16 15:42:51 +00:00
|
|
|
|
public function APIGetAllowedParams( &$module, &$params, $flags ) {
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
if ( $this->isAPICaptchaModule( $module ) ) {
|
2013-03-16 15:42:51 +00:00
|
|
|
|
$params['captchaword'] = null;
|
|
|
|
|
$params['captchaid'] = null;
|
2011-11-23 19:09:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-09-02 12:26:25 +00:00
|
|
|
|
* @param $module ApiBase
|
2011-11-23 19:09:57 +00:00
|
|
|
|
* @param $desc array
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function APIGetParamDescription( &$module, &$desc ) {
|
2013-03-16 15:42:51 +00:00
|
|
|
|
if ( $this->isAPICaptchaModule( $module ) ) {
|
|
|
|
|
$desc['captchaid'] = 'CAPTCHA ID from previous request';
|
|
|
|
|
$desc['captchaword'] = 'Answer to the CAPTCHA';
|
2011-11-23 19:09:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-02 22:56:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Checks, if the user reached the amount of false CAPTCHAs and give him some vacation
|
|
|
|
|
* or run self::passCaptcha() and clear counter if correct.
|
|
|
|
|
*
|
|
|
|
|
* @see self::passCaptcha()
|
|
|
|
|
*/
|
|
|
|
|
private function passCaptchaLimited() {
|
|
|
|
|
global $wgUser;
|
|
|
|
|
|
|
|
|
|
// don't increase pingLimiter here, just check, if CAPTCHA limit exceeded
|
|
|
|
|
if ( $wgUser->pingLimiter( 'badcaptcha', 0 ) ) {
|
|
|
|
|
// for debugging add an proper error message, the user just see an false captcha error message
|
|
|
|
|
wfDebug( 'ConfirmEdit: User reached RateLimit, preventing action.' );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->passCaptcha() ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// captcha was not solved: increase limit and return false
|
|
|
|
|
$wgUser->pingLimiter( 'badcaptcha' );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* Given a required captcha run, test form input for correct
|
|
|
|
|
* input on the open session.
|
|
|
|
|
* @return bool if passed, false if failed or new session
|
|
|
|
|
*/
|
|
|
|
|
function passCaptcha() {
|
2014-12-14 21:16:57 +00:00
|
|
|
|
global $wgRequest;
|
|
|
|
|
|
|
|
|
|
$info = $this->retrieveCaptcha( $wgRequest );
|
2009-07-19 15:13:01 +00:00
|
|
|
|
if ( $info ) {
|
|
|
|
|
if ( $this->keyMatch( $wgRequest->getVal( 'wpCaptchaWord' ), $info ) ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
|
$this->log( "passed" );
|
|
|
|
|
$this->clearCaptcha( $info );
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
$this->clearCaptcha( $info );
|
|
|
|
|
$this->log( "bad form input" );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->log( "new captcha session" );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Log the status and any triggering info for debugging or statistics
|
|
|
|
|
* @param string $message
|
|
|
|
|
*/
|
|
|
|
|
function log( $message ) {
|
|
|
|
|
wfDebugLog( 'captcha', 'ConfirmEdit: ' . $message . '; ' . $this->trigger );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generate a captcha session ID and save the info in PHP's session storage.
|
|
|
|
|
* (Requires the user to have cookies enabled to get through the captcha.)
|
|
|
|
|
*
|
|
|
|
|
* A random ID is used so legit users can make edits in multiple tabs or
|
|
|
|
|
* windows without being unnecessarily hobbled by a serial order requirement.
|
|
|
|
|
* Pass the returned id value into the edit form as wpCaptchaId.
|
|
|
|
|
*
|
|
|
|
|
* @param array $info data to store
|
|
|
|
|
* @return string captcha ID key
|
|
|
|
|
*/
|
|
|
|
|
function storeCaptcha( $info ) {
|
2009-07-19 15:13:01 +00:00
|
|
|
|
if ( !isset( $info['index'] ) ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
|
// Assign random index if we're not udpating
|
|
|
|
|
$info['index'] = strval( mt_rand() );
|
|
|
|
|
}
|
2011-04-24 17:33:41 +00:00
|
|
|
|
CaptchaStore::get()->store( $info['index'], $info );
|
2007-11-12 07:42:25 +00:00
|
|
|
|
return $info['index'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch this session's captcha info.
|
2014-12-14 21:16:57 +00:00
|
|
|
|
* @param WebRequest
|
2007-11-12 07:42:25 +00:00
|
|
|
|
* @return mixed array of info, or false if missing
|
|
|
|
|
*/
|
2014-12-14 21:16:57 +00:00
|
|
|
|
function retrieveCaptcha( WebRequest $request ) {
|
|
|
|
|
$index = $request->getVal( 'wpCaptchaId' );
|
2011-04-24 17:33:41 +00:00
|
|
|
|
return CaptchaStore::get()->retrieve( $index );
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clear out existing captcha info from the session, to ensure
|
|
|
|
|
* it can't be reused.
|
|
|
|
|
*/
|
|
|
|
|
function clearCaptcha( $info ) {
|
2011-04-24 17:33:41 +00:00
|
|
|
|
CaptchaStore::get()->clear( $info['index'] );
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve the current version of the page or section being edited...
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
* @param Title $title
|
2007-11-12 07:42:25 +00:00
|
|
|
|
* @param string $section
|
|
|
|
|
* @return string
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
function loadText( $title, $section ) {
|
|
|
|
|
$rev = Revision::newFromTitle( $title, false, Revision::READ_LATEST );
|
2009-07-19 15:13:01 +00:00
|
|
|
|
if ( is_null( $rev ) ) {
|
2007-11-12 07:42:25 +00:00
|
|
|
|
return "";
|
|
|
|
|
} else {
|
|
|
|
|
$text = $rev->getText();
|
2009-07-19 15:13:01 +00:00
|
|
|
|
if ( $section != '' ) {
|
2010-07-27 09:00:27 +00:00
|
|
|
|
global $wgParser;
|
|
|
|
|
return $wgParser->getSection( $text, $section );
|
2007-11-12 07:42:25 +00:00
|
|
|
|
} else {
|
|
|
|
|
return $text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extract a list of all recognized HTTP links in the text.
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
* @param $title Title
|
2012-08-16 21:21:50 +00:00
|
|
|
|
* @param $text string
|
2014-12-14 21:16:57 +00:00
|
|
|
|
* @param $user User
|
2007-11-12 07:42:25 +00:00
|
|
|
|
* @return array of strings
|
|
|
|
|
*/
|
2014-12-14 21:16:57 +00:00
|
|
|
|
function findLinks( $title, $text, User $user ) {
|
|
|
|
|
global $wgParser;
|
2007-11-12 07:42:25 +00:00
|
|
|
|
|
|
|
|
|
$options = new ParserOptions();
|
2014-12-14 21:16:57 +00:00
|
|
|
|
$text = $wgParser->preSaveTransform( $text, $title, $user, $options );
|
Use the shared parse on API edit
ConfirmEdit was tripling the API save time, because it was parsing the
entire content twice to evaluate whether the addurl trigger is hit.
While I was here, I stopped using the deprecated non-Content hooks. The
new hook, EditEditFilterMergedContent, does not pass an EditPage object,
which means that Title or WikiPage objects need to be passed around
instead. Also, since EditPage::showEditForm() cannot be called with no
EditPage object, use a EditPage::showEditForm:fields hook instead.
If non-wikitext content is edited, assume that the regex trigger is not
hit.
For further architectural details, see the associated core change:
I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant
introduced to detect the presence of the associated core change.
Also, in APIGetAllowedParams, set the allowed parameters even if we are
not on the help screen. This allows API users to submit their CAPTCHA
answer without it failing with an "unrecognized parameter" error.
Compatibility with MediaWiki 1.21 is retained, compatibility before that
is dropped.
Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
2014-12-05 04:48:13 +00:00
|
|
|
|
$out = $wgParser->parse( $text, $title, $options );
|
2007-11-12 07:42:25 +00:00
|
|
|
|
|
|
|
|
|
return array_keys( $out->getExternalLinks() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show a page explaining what this wacky thing is.
|
2014-12-14 21:16:57 +00:00
|
|
|
|
* @param OutputPage
|
2007-11-12 07:42:25 +00:00
|
|
|
|
*/
|
2014-12-14 21:16:57 +00:00
|
|
|
|
function showHelp( OutputPage $out ) {
|
|
|
|
|
$out->setPageTitle( wfMessage( 'captchahelp-title' )->text() );
|
|
|
|
|
$out->addWikiMsg( 'captchahelp-text' );
|
2011-04-24 17:33:41 +00:00
|
|
|
|
if ( CaptchaStore::get()->cookiesNeeded() ) {
|
2014-12-14 21:16:57 +00:00
|
|
|
|
$out->addWikiMsg( 'captchahelp-cookies-needed' );
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-10 23:16:34 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Pass API captcha parameters on to the login form when using
|
|
|
|
|
* API account creation.
|
|
|
|
|
*
|
|
|
|
|
* @param ApiCreateAccount $apiModule
|
|
|
|
|
* @param LoginForm $loginForm
|
|
|
|
|
* @return hook return value
|
|
|
|
|
*/
|
|
|
|
|
function addNewAccountApiForm( $apiModule, $loginForm ) {
|
2014-12-14 21:16:57 +00:00
|
|
|
|
$request = $loginForm->getContext()->getRequest();
|
2014-01-10 23:16:34 +00:00
|
|
|
|
$main = $apiModule->getMain();
|
|
|
|
|
|
|
|
|
|
$id = $main->getVal( 'captchaid' );
|
|
|
|
|
if ( $id ) {
|
2014-12-14 21:16:57 +00:00
|
|
|
|
$request->setVal( 'wpCaptchaId', $id );
|
2014-01-10 23:16:34 +00:00
|
|
|
|
|
|
|
|
|
// Suppress "unrecognized parameter" warning:
|
|
|
|
|
$main->getVal( 'wpCaptchaId' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$word = $main->getVal( 'captchaword' );
|
|
|
|
|
if ( $word ) {
|
2014-12-14 21:16:57 +00:00
|
|
|
|
$request->setVal( 'wpCaptchaWord', $word );
|
2014-01-10 23:16:34 +00:00
|
|
|
|
|
|
|
|
|
// Suppress "unrecognized parameter" warning:
|
|
|
|
|
$main->getVal( 'wpCaptchaWord' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-03-12 22:37:17 +00:00
|
|
|
|
|
2014-01-10 23:16:34 +00:00
|
|
|
|
/**
|
|
|
|
|
* Pass extra data back in API results for account creation.
|
|
|
|
|
*
|
|
|
|
|
* @param ApiCreateAccount $apiModule
|
2014-03-12 22:37:17 +00:00
|
|
|
|
* @param LoginForm &loginPage
|
|
|
|
|
* @param array &$result
|
|
|
|
|
* @return bool: Hook return value
|
2014-01-10 23:16:34 +00:00
|
|
|
|
*/
|
|
|
|
|
function addNewAccountApiResult( $apiModule, $loginPage, &$result ) {
|
2014-12-14 21:16:57 +00:00
|
|
|
|
$user = $loginPage->getContext()->getUser();
|
|
|
|
|
|
|
|
|
|
if ( $result['result'] !== 'Success' && $this->needCreateAccountCaptcha( $user ) ) {
|
Cleaner response for captcha-related createaccount API failure
Instead of a generic API error, you get back a non-Success-resulted
creataccount response, with result='NeedCaptcha'. There's also a warning
included with the message key, and of course the captcha key:
array (
'createaccount' =>
array (
'result' => 'NeedCaptcha',
'warnings' =>
array (
0 =>
array (
'type' => 'warning',
'message' => 'captcha-createaccount-fail',
'params' =>
array (
),
),
),
'captcha' =>
array (
'type' => 'simple',
'mime' => 'text/plain',
'id' => '91510936',
'question' => '76−3',
),
),
)
Change-Id: Id1c9e387c592e6d51a5bd58d99ce3d644dfa300b
2014-02-28 22:42:41 +00:00
|
|
|
|
|
|
|
|
|
// If we failed a captcha, override the generic 'Warning' result string
|
|
|
|
|
if ( $result['result'] === 'Warning' && isset( $result['warnings'] ) ) {
|
|
|
|
|
foreach ( $result['warnings'] as $warning ) {
|
|
|
|
|
if ( $warning['message'] === 'captcha-createaccount-fail' ) {
|
2014-03-12 22:37:17 +00:00
|
|
|
|
$this->addCaptchaAPI( $result );
|
Cleaner response for captcha-related createaccount API failure
Instead of a generic API error, you get back a non-Success-resulted
creataccount response, with result='NeedCaptcha'. There's also a warning
included with the message key, and of course the captcha key:
array (
'createaccount' =>
array (
'result' => 'NeedCaptcha',
'warnings' =>
array (
0 =>
array (
'type' => 'warning',
'message' => 'captcha-createaccount-fail',
'params' =>
array (
),
),
),
'captcha' =>
array (
'type' => 'simple',
'mime' => 'text/plain',
'id' => '91510936',
'question' => '76−3',
),
),
)
Change-Id: Id1c9e387c592e6d51a5bd58d99ce3d644dfa300b
2014-02-28 22:42:41 +00:00
|
|
|
|
$result['result'] = 'NeedCaptcha';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-10 23:16:34 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2007-11-12 07:42:25 +00:00
|
|
|
|
}
|