MediaWiki  1.32.0
SimpleCaptcha Class Reference

Demo CAPTCHA (not for production usage) and base class for real CAPTCHAs. More...

Inheritance diagram for SimpleCaptcha:
Collaboration diagram for SimpleCaptcha:

Public Member Functions

 addFormInformationToOutput (OutputPage $out, array $formInformation)
 Processes the given $formInformation array and adds the options (see getFormInformation()) to the given OutputPage object. More...
 
 addFormToOutput (OutputPage $out, $tabIndex=1)
 Uses getFormInformation() to get the CAPTCHA form and adds it to the given OutputPage object. More...
 
 apiGetAllowedParams (&$module, &$params, $flags)
 
 canSkipCaptcha ( $user, Config $config)
 Check whether the user provided / IP making the request is allowed to skip captchas. More...
 
 captchaTriggers ( $title, $action)
 
 clearCaptcha ( $index)
 Clear out existing captcha info from the session, to ensure it can't be reused. More...
 
 confirmEditMerged ( $context, $content, $status, $summary, $user, $minorEdit)
 An efficient edit filter callback based on the text after section merging. More...
 
 confirmEmailUser ( $from, $to, $subject, $text, &$error)
 Check the captcha on Special:EmailUser. More...
 
 createAuthenticationRequest ()
 
 describeCaptchaType ()
 Describes the captcha type for API clients. More...
 
 editShowCaptcha ( $editPage)
 Insert the captcha prompt into an edit form. More...
 
 getCaptcha ()
 Returns an array with 'question' and 'answer' keys. More...
 
 getCaptchaInfo ( $captchaData, $id)
 
 getError ()
 Return the error from the last passCaptcha* call. More...
 
 getFormInformation ( $tabIndex=1)
 Insert a captcha prompt into the edit form. More...
 
 getMessage ( $action)
 Show a message asking the user to enter a captcha on edit The result will be treated as wiki text. More...
 
 increaseBadLoginCounter ( $username)
 Increase bad login counter after a failed login. More...
 
 injectEmailUser (&$form)
 Inject whazawhoo @fixme if multiple thingies insert a header, could break. More...
 
 isBadLoginPerUserTriggered ( $u)
 Is the per-user captcha triggered? More...
 
 isBadLoginTriggered ()
 Check if a bad login has already been registered for this IP address. More...
 
 needCreateAccountCaptcha (User $creatingUser=null)
 Logic to check if we need to pass a captcha for the current user to create a new account, or not. More...
 
 onAuthChangeFormFields (array $requests, array $fieldInfo, array &$formDescriptor, $action)
 Modify the appearance of the captcha field. More...
 
 passCaptchaFromRequest (WebRequest $request, User $user)
 Given a required captcha run, test form input for correct input on the open session. More...
 
 passCaptchaLimited ( $index, $word, User $user)
 Checks, if the user reached the amount of false CAPTCHAs and give him some vacation or run self::passCaptcha() and clear counter if correct. More...
 
 passCaptchaLimitedFromRequest (WebRequest $request, User $user)
 Checks, if the user reached the amount of false CAPTCHAs and give him some vacation or run self::passCaptcha() and clear counter if correct. More...
 
 resetBadLoginCounter ( $username)
 Reset bad login counter after a successful login. More...
 
 retrieveCaptcha ( $index)
 Fetch this session's captcha info. More...
 
 setAction ( $action)
 
 setTrigger ( $trigger)
 
 shouldCheck (WikiPage $page, $content, $section, $context, $oldtext=null)
 
 showEditFormFields (&$editPage, &$out)
 Show error message for missing or incorrect captcha on EditPage. More...
 
 showHelp ()
 Show a page explaining what this wacky thing is. More...
 
 storeCaptcha ( $info)
 Generate a captcha session ID and save the info in PHP's session storage. More...
 
 triggersCaptcha ( $action, $title=null)
 Checks, whether the passed action should trigger a CAPTCHA. More...
 

Protected Member Functions

 addCaptchaAPI (&$resultArr)
 
 getCaptchaParamsFromRequest (WebRequest $request)
 
 isAPICaptchaModule ( $module)
 
 keyMatch ( $answer, $info)
 Check if the submitted form matches the captcha session data provided by the plugin when the form was generated. More...
 
 log ( $message)
 Log the status and any triggering info for debugging or statistics. More...
 
 passCaptcha ( $index, $word)
 Given a required captcha run, test form input for correct input on the open session. More...
 

Protected Attributes

string $action
 Used to select the right message. More...
 
string $trigger
 Used in log messages. More...
 

Static Protected Attributes

static $messagePrefix = 'captcha-'
 

Private Member Functions

 badLoginKey ()
 Internal cache key for badlogin checks. More...
 
 badLoginPerUserKey ( $username)
 Cache key for badloginPerUser checks. More...
 
 buildRegexes ( $lines)
 Build regex from whitelist. More...
 
 buildValidIPs (array $input)
 From a list of unvalidated input, get all the valid IP addresses and IP ranges from it. More...
 
 doConfirmEdit (WikiPage $page, $newtext, $section, IContextSource $context)
 Backend function for confirmEditMerged() More...
 
 filterLink ( $url)
 Filter callback function for URL whitelisting. More...
 
 findLinks ( $title, $text)
 Extract a list of all recognized HTTP links in the text. More...
 
 getLinksFromTracker ( $title)
 Load external links from the externallinks table. More...
 
 getWikiIPWhitelist (Message $msg)
 Get the on-wiki IP whitelist stored in [[MediaWiki:Captcha-ip-whitelist]] page from cache if possible. More...
 
 isIPWhitelisted ()
 Check if the current IP is allowed to skip captchas. More...
 
 loadText ( $title, $section, $flags=Revision::READ_LATEST)
 Retrieve the current version of the page or section being edited... More...
 

Private Attributes

boolean null $captchaSolved = null
 Was the CAPTCHA already passed and if yes, with which result? More...
 

Detailed Description

Demo CAPTCHA (not for production usage) and base class for real CAPTCHAs.

Definition at line 8 of file SimpleCaptcha.php.

Member Function Documentation

◆ addCaptchaAPI()

SimpleCaptcha::addCaptchaAPI ( $resultArr)
protected
Parameters
array&$resultArr

Reimplemented in FancyCaptcha, ReCaptcha, QuestyCaptcha, and MathCaptcha.

Definition at line 71 of file SimpleCaptcha.php.

References describeCaptchaType(), getCaptcha(), and storeCaptcha().

Referenced by confirmEditMerged().

◆ addFormInformationToOutput()

SimpleCaptcha::addFormInformationToOutput ( OutputPage  $out,
array  $formInformation 
)

Processes the given $formInformation array and adds the options (see getFormInformation()) to the given OutputPage object.

Parameters
OutputPage$outThe OutputPage object to which the form should be added
array$formInformation

Definition at line 161 of file SimpleCaptcha.php.

References $out.

Referenced by addFormToOutput(), and injectEmailUser().

◆ addFormToOutput()

SimpleCaptcha::addFormToOutput ( OutputPage  $out,
  $tabIndex = 1 
)

Uses getFormInformation() to get the CAPTCHA form and adds it to the given OutputPage object.

Parameters
OutputPage$outThe OutputPage object to which the form should be added
int$tabIndexSee self::getFormInformation

Definition at line 150 of file SimpleCaptcha.php.

References addFormInformationToOutput(), and getFormInformation().

Referenced by editShowCaptcha(), and showEditFormFields().

◆ apiGetAllowedParams()

SimpleCaptcha::apiGetAllowedParams ( $module,
$params,
  $flags 
)
Parameters
ApiBase&$module
array&$params
int$flags
Returns
bool

Reimplemented in ReCaptcha.

Definition at line 915 of file SimpleCaptcha.php.

References $params, isAPICaptchaModule(), and ApiBase\PARAM_HELP_MSG.

◆ badLoginKey()

SimpleCaptcha::badLoginKey ( )
private

Internal cache key for badlogin checks.

Returns
string

Definition at line 431 of file SimpleCaptcha.php.

References $wgRequest, and wfGlobalCacheKey().

Referenced by increaseBadLoginCounter().

◆ badLoginPerUserKey()

SimpleCaptcha::badLoginPerUserKey (   $username)
private

Cache key for badloginPerUser checks.

Parameters
string$username
Returns
string

Definition at line 442 of file SimpleCaptcha.php.

References $username, User\getCanonicalName(), and wfGlobalCacheKey().

Referenced by increaseBadLoginCounter(), and resetBadLoginCounter().

◆ buildRegexes()

SimpleCaptcha::buildRegexes (   $lines)
private

Build regex from whitelist.

Parameters
string$linesstring from [[MediaWiki:Captcha-addurl-whitelist]]
Returns
array Regexes
Access:\n private

Definition at line 679 of file SimpleCaptcha.php.

References $line, $lines, $matches, $opt, $options, $value, as, captcha-old\count, and wfDebug().

Referenced by filterLink().

◆ buildValidIPs()

SimpleCaptcha::buildValidIPs ( array  $input)
private

From a list of unvalidated input, get all the valid IP addresses and IP ranges from it.

Note that only lines with just the IP address or IP range is considered as valid. Whitespace is allowed but if there is any other character on the line, it's not considered as a valid entry.

Parameters
string[]$input
Returns
string[] of valid IP addresses and IP ranges

Definition at line 412 of file SimpleCaptcha.php.

References $input, as, and IP\isIPAddress().

Referenced by getWikiIPWhitelist().

◆ canSkipCaptcha()

SimpleCaptcha::canSkipCaptcha (   $user,
Config  $config 
)

Check whether the user provided / IP making the request is allowed to skip captchas.

Parameters
User$user
Config$config
Returns
bool
Exceptions
ConfigException

Definition at line 1162 of file SimpleCaptcha.php.

References $user, Config\get(), isIPWhitelisted(), and wfDebug().

Referenced by confirmEmailUser(), injectEmailUser(), needCreateAccountCaptcha(), and shouldCheck().

◆ captchaTriggers()

SimpleCaptcha::captchaTriggers (   $title,
  $action 
)
Parameters
Title$title
string$action(edit/create/addurl...)
Returns
bool true if action triggers captcha on $title's namespace
Deprecated:
since 1.5.1 Use triggersCaptcha instead

Definition at line 469 of file SimpleCaptcha.php.

References $title, and triggersCaptcha().

◆ clearCaptcha()

SimpleCaptcha::clearCaptcha (   $index)

Clear out existing captcha info from the session, to ensure it can't be reused.

Parameters
string$index

Definition at line 1065 of file SimpleCaptcha.php.

References CaptchaStore\get().

Referenced by passCaptcha().

◆ confirmEditMerged()

SimpleCaptcha::confirmEditMerged (   $context,
  $content,
  $status,
  $summary,
  $user,
  $minorEdit 
)

An efficient edit filter callback based on the text after section merging.

Parameters
RequestContext$context
Content$content
Status$status
string$summary
User$user
bool$minorEdit
Returns
bool

Definition at line 805 of file SimpleCaptcha.php.

References $content, $context, $title, captcha-old\action, addCaptchaAPI(), EditPage\AS_HOOK_ERROR_EXPECTED, doConfirmEdit(), Html\element(), MediaWiki\getTitle(), and wfDebug().

◆ confirmEmailUser()

SimpleCaptcha::confirmEmailUser (   $from,
  $to,
  $subject,
  $text,
$error 
)

Check the captcha on Special:EmailUser.

Parameters
MailAddress$from
MailAddress$to
string$subject
string$text
string&$error
Returns
bool true to continue saving, false to abort and show a captcha form

Definition at line 877 of file SimpleCaptcha.php.

References $wgRequest, canSkipCaptcha(), StatusValue\newFatal(), passCaptchaLimitedFromRequest(), CaptchaTriggers\SENDEMAIL, and triggersCaptcha().

◆ createAuthenticationRequest()

SimpleCaptcha::createAuthenticationRequest ( )
Returns
CaptchaAuthenticationRequest

Reimplemented in ReCaptcha.

Definition at line 1125 of file SimpleCaptcha.php.

References getCaptcha(), and storeCaptcha().

◆ describeCaptchaType()

SimpleCaptcha::describeCaptchaType ( )

Describes the captcha type for API clients.

Returns
array An array with keys 'type' and 'mime', and possibly other implementation-specific

Reimplemented in FancyCaptcha, ReCaptcha, QuestyCaptcha, and MathCaptcha.

Definition at line 84 of file SimpleCaptcha.php.

Referenced by addCaptchaAPI().

◆ doConfirmEdit()

SimpleCaptcha::doConfirmEdit ( WikiPage  $page,
  $newtext,
  $section,
IContextSource  $context 
)
private

Backend function for confirmEditMerged()

Parameters
WikiPage$page
string$newtext
string$section
IContextSource$context
Returns
bool false if the CAPTCHA is rejected, true otherwise

Definition at line 773 of file SimpleCaptcha.php.

References $context, $request, $section, $wgRequest, passCaptchaLimitedFromRequest(), shouldCheck(), and wfDebug().

Referenced by confirmEditMerged().

◆ editShowCaptcha()

SimpleCaptcha::editShowCaptcha (   $editPage)

Insert the captcha prompt into an edit form.

Parameters
EditPage$editPage

Definition at line 210 of file SimpleCaptcha.php.

References $context, $out, captcha-old\action, addFormToOutput(), and getMessage().

◆ filterLink()

SimpleCaptcha::filterLink (   $url)
private

Filter callback function for URL whitelisting.

Parameters
string$urlstring to check
Returns
bool true if unknown, false if whitelisted

Definition at line 648 of file SimpleCaptcha.php.

References $source, as, buildRegexes(), and wfMessage().

◆ findLinks()

SimpleCaptcha::findLinks (   $title,
  $text 
)
private

Extract a list of all recognized HTTP links in the text.

Parameters
Title$title
string$text
Returns
array of strings

Definition at line 1100 of file SimpleCaptcha.php.

References $options, $out, $title, and $wgParser.

Referenced by shouldCheck().

◆ getCaptcha()

SimpleCaptcha::getCaptcha ( )

Returns an array with 'question' and 'answer' keys.

Subclasses might use different structure. Since MW 1.27 all subclasses must implement this method.

Returns
array

Reimplemented in FancyCaptcha, ReCaptcha, MathCaptcha, and QuestyCaptcha.

Definition at line 53 of file SimpleCaptcha.php.

Referenced by addCaptchaAPI(), createAuthenticationRequest(), and getFormInformation().

◆ getCaptchaInfo()

SimpleCaptcha::getCaptchaInfo (   $captchaData,
  $id 
)
Parameters
array$captchaDataData given by getCaptcha
string$idID given by storeCaptcha
Returns
string Description of the captcha. Format is not specified; could be text, HTML, URL...

Reimplemented in FancyCaptcha, ReCaptcha, QuestyCaptcha, and MathCaptcha.

Definition at line 184 of file SimpleCaptcha.php.

◆ getCaptchaParamsFromRequest()

SimpleCaptcha::getCaptchaParamsFromRequest ( WebRequest  $request)
protected
Parameters
WebRequest$request
Returns
array [ captcha ID, captcha solution ]

Reimplemented in ReCaptcha.

Definition at line 945 of file SimpleCaptcha.php.

References $request.

Referenced by passCaptchaFromRequest(), and passCaptchaLimitedFromRequest().

◆ getError()

SimpleCaptcha::getError ( )

Return the error from the last passCaptcha* call.

Not implemented but needed by some child classes.

Returns
mixed

Reimplemented in ReCaptcha.

Definition at line 43 of file SimpleCaptcha.php.

Referenced by CaptchaPreAuthenticationProvider\makeError().

◆ getFormInformation()

SimpleCaptcha::getFormInformation (   $tabIndex = 1)

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!

It is not guaranteed that the CAPTCHA will load synchronously with the main page content. So you can not rely on registering handlers before page load. E.g.:

NOT SAFE: $( window ).on( 'load', handler ) SAFE: $( handler )

However, if the HTML is loaded dynamically via AJAX, the following order will be used.

headitems => modulestyles + modules => add main HTML to DOM when modulestyles + modules are ready.

Parameters
int$tabIndexTab index to start from
Returns
array Associative array with the following keys: string html - Main HTML array modules (optional) - Array of ResourceLoader module names array modulestyles (optional) - Array of ResourceLoader module names to be included as style-only modules. array headitems (optional) - Head items (see OutputPage::addHeadItems), as a numeric array of raw HTML strings. Do not use unless no other option is feasible.

Reimplemented in FancyCaptcha, QuestyCaptcha, MathCaptcha, and ReCaptcha.

Definition at line 120 of file SimpleCaptcha.php.

References Xml\element(), getCaptcha(), and storeCaptcha().

Referenced by addFormToOutput(), and injectEmailUser().

◆ getLinksFromTracker()

SimpleCaptcha::getLinksFromTracker (   $title)
private

Load external links from the externallinks table.

Parameters
Title$title
Returns
array

Definition at line 752 of file SimpleCaptcha.php.

References $dbr, $res, $title, as, DB_REPLICA, and wfGetDB().

Referenced by shouldCheck().

◆ getMessage()

SimpleCaptcha::getMessage (   $action)

Show a message asking the user to enter a captcha on edit The result will be treated as wiki text.

Parameters
string$actionAction being performed
Returns
Message

Definition at line 230 of file SimpleCaptcha.php.

References $action, $name, and wfMessage().

Referenced by editShowCaptcha(), FancyCaptcha\onAuthChangeFormFields(), and showEditFormFields().

◆ getWikiIPWhitelist()

SimpleCaptcha::getWikiIPWhitelist ( Message  $msg)
private

Get the on-wiki IP whitelist stored in [[MediaWiki:Captcha-ip-whitelist]] page from cache if possible.

Parameters
Message$msgwhitelist Message on wiki
Returns
array whitelisted IP addresses or IP ranges, empty array if no whitelist

Definition at line 378 of file SimpleCaptcha.php.

References $cache, buildValidIPs(), and ObjectCache\getMainWANInstance().

Referenced by isIPWhitelisted().

◆ increaseBadLoginCounter()

SimpleCaptcha::increaseBadLoginCounter (   $username)

Increase bad login counter after a failed login.

The user might be required to solve a captcha if the count is high.

Parameters
string$usernameTODO use Throttler

Definition at line 273 of file SimpleCaptcha.php.

References $cache, $username, CaptchaTriggers\BAD_LOGIN, CaptchaTriggers\BAD_LOGIN_PER_USER, badLoginKey(), badLoginPerUserKey(), ObjectCache\getLocalClusterInstance(), and triggersCaptcha().

◆ injectEmailUser()

SimpleCaptcha::injectEmailUser ( $form)

Inject whazawhoo @fixme if multiple thingies insert a header, could break.

Parameters
HTMLForm&$form
Returns
bool true to keep running callbacks

Definition at line 246 of file SimpleCaptcha.php.

References $out, $user, captcha-old\action, addFormInformationToOutput(), canSkipCaptcha(), getFormInformation(), CaptchaTriggers\SENDEMAIL, and triggersCaptcha().

◆ isAPICaptchaModule()

SimpleCaptcha::isAPICaptchaModule (   $module)
protected
Parameters
ApiBase$module
Returns
bool

Definition at line 905 of file SimpleCaptcha.php.

Referenced by ReCaptcha\apiGetAllowedParams(), and apiGetAllowedParams().

◆ isBadLoginPerUserTriggered()

SimpleCaptcha::isBadLoginPerUserTriggered (   $u)

Is the per-user captcha triggered?

Parameters
User | string$uUser object, or name
Returns
bool|null False: no, null: no, but it will be triggered next time

Definition at line 330 of file SimpleCaptcha.php.

References $cache, CaptchaTriggers\BAD_LOGIN_PER_USER, ObjectCache\getLocalClusterInstance(), and triggersCaptcha().

◆ isBadLoginTriggered()

SimpleCaptcha::isBadLoginTriggered ( )

Check if a bad login has already been registered for this IP address.

If so, require a captcha.

Returns
bool
Access:\n private

Definition at line 316 of file SimpleCaptcha.php.

References $cache, CaptchaTriggers\BAD_LOGIN, ObjectCache\getLocalClusterInstance(), and triggersCaptcha().

◆ isIPWhitelisted()

SimpleCaptcha::isIPWhitelisted ( )
private

Check if the current IP is allowed to skip captchas.

This checks the whitelist from two sources. 1) From the server-side config array $wgCaptchaWhitelistIP 2) From the local [[MediaWiki:Captcha-ip-whitelist]] message

Returns
bool true if whitelisted, false if not

Definition at line 350 of file SimpleCaptcha.php.

References $wgRequest, getWikiIPWhitelist(), IP\isInRanges(), and wfMessage().

Referenced by canSkipCaptcha().

◆ keyMatch()

SimpleCaptcha::keyMatch (   $answer,
  $info 
)
protected

Check if the submitted form matches the captcha session data provided by the plugin when the form was generated.

Override this!

Parameters
string$answer
array$info
Returns
bool

Reimplemented in FancyCaptcha, QuestyCaptcha, and MathCaptcha.

Definition at line 457 of file SimpleCaptcha.php.

Referenced by passCaptcha().

◆ loadText()

SimpleCaptcha::loadText (   $title,
  $section,
  $flags = Revision::READ_LATEST 
)
private

Retrieve the current version of the page or section being edited...

Parameters
Title$title
string$section
int$flagsFlags for Revision loading methods
Returns
string
Access:\n private

Definition at line 1077 of file SimpleCaptcha.php.

References $content, $rev, $section, $title, $wgParser, ContentHandler\getContentText(), and Revision\newFromTitle().

Referenced by shouldCheck().

◆ log()

SimpleCaptcha::log (   $message)
protected

Log the status and any triggering info for debugging or statistics.

Parameters
string$message

Definition at line 1027 of file SimpleCaptcha.php.

References wfDebugLog().

Referenced by passCaptcha(), and passCaptchaLimited().

◆ needCreateAccountCaptcha()

SimpleCaptcha::needCreateAccountCaptcha ( User  $creatingUser = null)

Logic to check if we need to pass a captcha for the current user to create a new account, or not.

Parameters
User | null$creatingUser
Returns
bool true to show captcha, false to skip captcha

Definition at line 854 of file SimpleCaptcha.php.

References canSkipCaptcha(), CaptchaTriggers\CREATE_ACCOUNT, and triggersCaptcha().

◆ onAuthChangeFormFields()

SimpleCaptcha::onAuthChangeFormFields ( array  $requests,
array  $fieldInfo,
array $formDescriptor,
  $action 
)

Modify the appearance of the captcha field.

Parameters
AuthenticationRequest[]$requests
array$fieldInfoField description as given by AuthenticationRequest::mergeFieldInfo
array&$formDescriptorA form descriptor suitable for the HTMLForm constructor
string$actionOne of the AuthManager::ACTION_* constants

Reimplemented in FancyCaptcha, ReCaptcha, QuestyCaptcha, and MathCaptcha.

Definition at line 1138 of file SimpleCaptcha.php.

References $formDescriptor, $req, $requests, and class.

◆ passCaptcha()

SimpleCaptcha::passCaptcha (   $index,
  $word 
)
protected

Given a required captcha run, test form input for correct input on the open session.

Parameters
string$indexCaptcha idenitifier
string$wordCaptcha solution
Returns
bool if passed, false if failed or new session

Reimplemented in FancyCaptcha, and ReCaptcha.

Definition at line 997 of file SimpleCaptcha.php.

References $captchaSolved, clearCaptcha(), keyMatch(), log(), and retrieveCaptcha().

Referenced by passCaptchaFromRequest(), and passCaptchaLimited().

◆ passCaptchaFromRequest()

SimpleCaptcha::passCaptchaFromRequest ( WebRequest  $request,
User  $user 
)

Given a required captcha run, test form input for correct input on the open session.

Parameters
WebRequest$request
User$user
Returns
bool if passed, false if failed or new session

Definition at line 985 of file SimpleCaptcha.php.

References getCaptchaParamsFromRequest(), list, and passCaptcha().

◆ passCaptchaLimited()

SimpleCaptcha::passCaptchaLimited (   $index,
  $word,
User  $user 
)

Checks, if the user reached the amount of false CAPTCHAs and give him some vacation or run self::passCaptcha() and clear counter if correct.

Parameters
string$indexCaptcha idenitifier
string$wordCaptcha solution
User$userUser for throttling captcha solving attempts
Returns
bool
See also
self::passCaptcha()

Definition at line 961 of file SimpleCaptcha.php.

References $user, log(), and passCaptcha().

Referenced by passCaptchaLimitedFromRequest(), and CaptchaPreAuthenticationProvider\verifyCaptcha().

◆ passCaptchaLimitedFromRequest()

SimpleCaptcha::passCaptchaLimitedFromRequest ( WebRequest  $request,
User  $user 
)

Checks, if the user reached the amount of false CAPTCHAs and give him some vacation or run self::passCaptcha() and clear counter if correct.

Parameters
WebRequest$request
User$user
Returns
bool

Definition at line 936 of file SimpleCaptcha.php.

References $user, getCaptchaParamsFromRequest(), list, and passCaptchaLimited().

Referenced by confirmEmailUser(), and doConfirmEdit().

◆ resetBadLoginCounter()

SimpleCaptcha::resetBadLoginCounter (   $username)

Reset bad login counter after a successful login.

Parameters
string$username

Definition at line 303 of file SimpleCaptcha.php.

References $cache, $username, CaptchaTriggers\BAD_LOGIN_PER_USER, badLoginPerUserKey(), ObjectCache\getLocalClusterInstance(), and triggersCaptcha().

◆ retrieveCaptcha()

SimpleCaptcha::retrieveCaptcha (   $index)

Fetch this session's captcha info.

Parameters
string$index
Returns
array|false array of info, or false if missing

Reimplemented in ReCaptcha.

Definition at line 1056 of file SimpleCaptcha.php.

References CaptchaStore\get().

Referenced by FancyCaptcha\passCaptcha(), passCaptcha(), and FancyCaptcha\showImage().

◆ setAction()

SimpleCaptcha::setAction (   $action)
Parameters
string$action

Definition at line 27 of file SimpleCaptcha.php.

References $action, and captcha-old\action.

◆ setTrigger()

SimpleCaptcha::setTrigger (   $trigger)
Parameters
string$trigger

Definition at line 34 of file SimpleCaptcha.php.

References $trigger.

◆ shouldCheck()

SimpleCaptcha::shouldCheck ( WikiPage  $page,
  $content,
  $section,
  $context,
  $oldtext = null 
)
Parameters
WikiPage$page
Content | string$content
string$section
IContextSource$context
string | null$oldtextThe content of the revision prior to $content When null this will be loaded from the database.
Returns
bool true if the captcha should run

Definition at line 517 of file SimpleCaptcha.php.

References $content, $context, $request, $section, $title, $user, captcha-old\action, as, canSkipCaptcha(), CONTENT_MODEL_WIKITEXT, captcha-old\count, findLinks(), getLinksFromTracker(), RequestContext\getMain(), WikiPage\getTitle(), loadText(), WikiPage\prepareContentForEdit(), triggersCaptcha(), and wfDebug().

Referenced by doConfirmEdit().

◆ showEditFormFields()

SimpleCaptcha::showEditFormFields ( $editPage,
$out 
)

Show error message for missing or incorrect captcha on EditPage.

Parameters
EditPage&$editPage
OutputPage&$out

Definition at line 193 of file SimpleCaptcha.php.

References $out, captcha-old\action, addFormToOutput(), and getMessage().

◆ showHelp()

SimpleCaptcha::showHelp ( )

Show a page explaining what this wacky thing is.

Reimplemented in QuestyCaptcha.

Definition at line 1113 of file SimpleCaptcha.php.

References $wgOut, CaptchaStore\get(), text, and wfMessage().

◆ storeCaptcha()

SimpleCaptcha::storeCaptcha (   $info)

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.

Parameters
array$infodata to store
Returns
string captcha ID key

Reimplemented in ReCaptcha.

Definition at line 1042 of file SimpleCaptcha.php.

References CaptchaStore\get().

Referenced by MathCaptcha\addCaptchaAPI(), QuestyCaptcha\addCaptchaAPI(), addCaptchaAPI(), FancyCaptcha\addCaptchaAPI(), createAuthenticationRequest(), MathCaptcha\getFormInformation(), QuestyCaptcha\getFormInformation(), FancyCaptcha\getFormInformation(), getFormInformation(), and FancyCaptcha\showImage().

◆ triggersCaptcha()

SimpleCaptcha::triggersCaptcha (   $action,
  $title = null 
)

Checks, whether the passed action should trigger a CAPTCHA.

The optional $title parameter will be used to check namespace specific CAPTCHA triggers.

Parameters
string$actionThe CAPTCHA trigger to check (see CaptchaTriggers for ConfirmEdit built-in triggers)
Title | null$titleAn optional Title object, if the namespace specific triggers should be checked, too.
Returns
bool True, if the action should trigger a CAPTCHA, false otherwise

Definition at line 483 of file SimpleCaptcha.php.

References $action, $title, CaptchaTriggers\EXT_REG_ATTRIBUTE_NAME, and ExtensionRegistry\getInstance().

Referenced by captchaTriggers(), confirmEmailUser(), increaseBadLoginCounter(), injectEmailUser(), isBadLoginPerUserTriggered(), isBadLoginTriggered(), needCreateAccountCaptcha(), resetBadLoginCounter(), and shouldCheck().

Member Data Documentation

◆ $action

string SimpleCaptcha::$action
protected

Used to select the right message.

One of sendmail, createaccount, badlogin, edit, create, addurl.

Definition at line 19 of file SimpleCaptcha.php.

Referenced by getMessage(), FancyCaptcha\onAuthChangeFormFields(), setAction(), and triggersCaptcha().

◆ $captchaSolved

boolean null SimpleCaptcha::$captchaSolved = null
private

Was the CAPTCHA already passed and if yes, with which result?

Definition at line 12 of file SimpleCaptcha.php.

Referenced by passCaptcha().

◆ $messagePrefix

SimpleCaptcha::$messagePrefix = 'captcha-'
staticprotected

Definition at line 9 of file SimpleCaptcha.php.

◆ $trigger

string SimpleCaptcha::$trigger
protected

Used in log messages.

Definition at line 22 of file SimpleCaptcha.php.

Referenced by setTrigger().


The documentation for this class was generated from the following file: