MediaWiki
1.30.0
|
Demo CAPTCHA (not for production usage) and base class for real CAPTCHAs. More...
Public Member Functions | |
addCaptchaAPI (&$resultArr) | |
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) | |
buildRegexes ( $lines) | |
Build regex from whitelist. 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... | |
filterLink ( $url) | |
Filter callback function for URL whitelisting. More... | |
findLinks ( $title, $text) | |
Extract a list of all recognized HTTP links in the text. 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... | |
getLinksFromTracker ( $title) | |
Load external links from the externallinks table. 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... | |
isIPWhitelisted () | |
Check if the current IP is allowed to skip captchas. More... | |
keyMatch ( $answer, $info) | |
Check if the submitted form matches the captcha session data provided by the plugin when the form was generated. More... | |
loadText ( $title, $section, $flags=Revision::READ_LATEST) | |
Retrieve the current version of the page or section being edited... More... | |
log ( $message) | |
Log the status and any triggering info for debugging or statistics. 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 apprearance 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... | |
Protected Member Functions | |
getCaptchaParamsFromRequest (WebRequest $request) | |
isAPICaptchaModule ( $module) | |
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... | |
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... | |
getWikiIPWhitelist (Message $msg) | |
Get the on-wiki IP whitelist stored in [[MediaWiki:Captcha-ip-whitelist]] page from cache if possible. More... | |
Private Attributes | |
boolean null | $captchaSolved = null |
Was the CAPTCHA already passed and if yes, with which result? More... | |
Demo CAPTCHA (not for production usage) and base class for real CAPTCHAs.
Definition at line 9 of file Captcha.php.
SimpleCaptcha::addCaptchaAPI | ( | & | $resultArr | ) |
array | $resultArr |
Reimplemented in FancyCaptcha, ReCaptcha, QuestyCaptcha, and MathCaptcha.
Definition at line 72 of file Captcha.php.
References describeCaptchaType(), getCaptcha(), and storeCaptcha().
Referenced by confirmEditMerged().
SimpleCaptcha::addFormInformationToOutput | ( | OutputPage | $out, |
array | $formInformation | ||
) |
Processes the given $formInformation array and adds the options (see getFormInformation()) to the given OutputPage object.
OutputPage | $out | The OutputPage object to which the form should be added |
array | $formInformation |
Definition at line 161 of file Captcha.php.
References $out.
Referenced by addFormToOutput(), and injectEmailUser().
SimpleCaptcha::addFormToOutput | ( | OutputPage | $out, |
$tabIndex = 1 |
|||
) |
Uses getFormInformation() to get the CAPTCHA form and adds it to the given OutputPage object.
OutputPage | $out | The OutputPage object to which the form should be added |
int | $tabIndex | See self::getFormInformation |
Definition at line 150 of file Captcha.php.
References addFormInformationToOutput(), and getFormInformation().
Referenced by editShowCaptcha(), and showEditFormFields().
SimpleCaptcha::APIGetAllowedParams | ( | & | $module, |
& | $params, | ||
$flags | |||
) |
$module | ApiBase |
$params | array |
$flags | int |
Reimplemented in ReCaptcha.
Definition at line 903 of file Captcha.php.
References $params, isAPICaptchaModule(), and ApiBase\PARAM_HELP_MSG.
|
private |
Internal cache key for badlogin checks.
Definition at line 433 of file Captcha.php.
References $wgRequest, global, and wfGlobalCacheKey().
Referenced by increaseBadLoginCounter().
|
private |
Cache key for badloginPerUser checks.
string | $username |
Definition at line 444 of file Captcha.php.
References $username, User\getCanonicalName(), and wfGlobalCacheKey().
Referenced by increaseBadLoginCounter(), and resetBadLoginCounter().
SimpleCaptcha::buildRegexes | ( | $lines | ) |
Build regex from whitelist.
$lines | string from [[MediaWiki:Captcha-addurl-whitelist]] |
Definition at line 662 of file Captcha.php.
References $line, $lines, $matches, $opt, $options, $regexes, $value, as, captcha-old\count, and wfDebug().
Referenced by filterLink().
|
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.
string[] | $input |
Definition at line 414 of file Captcha.php.
References $input, as, and IP\isIPAddress().
Referenced by getWikiIPWhitelist().
SimpleCaptcha::captchaTriggers | ( | $title, | |
$action | |||
) |
Title | $title | |
string | $action | (edit/create/addurl...) |
Definition at line 470 of file Captcha.php.
References $action, $title, and global.
Referenced by shouldCheck().
SimpleCaptcha::clearCaptcha | ( | $index | ) |
Clear out existing captcha info from the session, to ensure it can't be reused.
Definition at line 1052 of file Captcha.php.
References CaptchaStore\get().
Referenced by passCaptcha().
SimpleCaptcha::confirmEditMerged | ( | $context, | |
$content, | |||
$status, | |||
$summary, | |||
$user, | |||
$minorEdit | |||
) |
An efficient edit filter callback based on the text after section merging.
RequestContext | $context | |
Content | $content | |
Status | $status | |
$summary | ||
$user | ||
$minorEdit |
Definition at line 787 of file Captcha.php.
References $context, $title, captcha-old\action, addCaptchaAPI(), EditPage\AS_HOOK_ERROR_EXPECTED, doConfirmEdit(), Html\element(), MediaWiki\getTitle(), and wfDebug().
SimpleCaptcha::confirmEmailUser | ( | $from, | |
$to, | |||
$subject, | |||
$text, | |||
& | $error | ||
) |
Check the captcha on Special:EmailUser.
$from | MailAddress |
$to | MailAddress |
$subject | String |
$text | String |
$error | String reference |
Definition at line 862 of file Captcha.php.
References $wgRequest, $wgUser, global, isIPWhitelisted(), StatusValue\newFatal(), passCaptchaLimitedFromRequest(), and wfDebug().
SimpleCaptcha::createAuthenticationRequest | ( | ) |
Reimplemented in ReCaptcha.
Definition at line 1112 of file Captcha.php.
References getCaptcha(), and storeCaptcha().
SimpleCaptcha::describeCaptchaType | ( | ) |
Describes the captcha type for API clients.
Reimplemented in FancyCaptcha, ReCaptcha, QuestyCaptcha, and MathCaptcha.
Definition at line 85 of file Captcha.php.
Referenced by addCaptchaAPI().
|
private |
Backend function for confirmEditMerged()
WikiPage | $page | |
$newtext | string | |
$section | ||
IContextSource | $context |
Definition at line 755 of file Captcha.php.
References $context, $request, $section, $wgRequest, $wgUser, global, passCaptchaLimitedFromRequest(), shouldCheck(), and wfDebug().
Referenced by confirmEditMerged().
SimpleCaptcha::editShowCaptcha | ( | $editPage | ) |
Insert the captcha prompt into an edit form.
EditPage | $editPage |
Definition at line 210 of file Captcha.php.
References $context, $out, captcha-old\action, addFormToOutput(), getMessage(), and text.
SimpleCaptcha::filterLink | ( | $url | ) |
Filter callback function for URL whitelisting.
$url | string to check |
Definition at line 631 of file Captcha.php.
References $regexes, $source, as, buildRegexes(), global, and wfMessage().
SimpleCaptcha::findLinks | ( | $title, | |
$text | |||
) |
Extract a list of all recognized HTTP links in the text.
$title | Title |
$text | string |
Definition at line 1087 of file Captcha.php.
References $options, $out, $title, $wgParser, $wgUser, and global.
Referenced by shouldCheck().
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.
Reimplemented in FancyCaptcha, ReCaptcha, MathCaptcha, and QuestyCaptcha.
Definition at line 54 of file Captcha.php.
Referenced by addCaptchaAPI(), createAuthenticationRequest(), and getFormInformation().
SimpleCaptcha::getCaptchaInfo | ( | $captchaData, | |
$id | |||
) |
array | $captchaData | Data given by getCaptcha |
string | $id | ID given by storeCaptcha |
Reimplemented in FancyCaptcha, ReCaptcha, QuestyCaptcha, and MathCaptcha.
Definition at line 184 of file Captcha.php.
|
protected |
WebRequest | $request |
Reimplemented in ReCaptcha.
Definition at line 933 of file Captcha.php.
References $request.
Referenced by passCaptchaFromRequest(), and passCaptchaLimitedFromRequest().
SimpleCaptcha::getError | ( | ) |
Return the error from the last passCaptcha* call.
Not implemented but needed by some child classes.
Reimplemented in ReCaptcha.
Definition at line 44 of file Captcha.php.
Referenced by CaptchaPreAuthenticationProvider\makeError().
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.
int | $tabIndex | Tab index to start from |
Reimplemented in FancyCaptcha, QuestyCaptcha, MathCaptcha, and ReCaptcha.
Definition at line 121 of file Captcha.php.
References Xml\element(), getCaptcha(), and storeCaptcha().
Referenced by addFormToOutput(), and injectEmailUser().
SimpleCaptcha::getLinksFromTracker | ( | $title | ) |
Load external links from the externallinks table.
$title | Title |
Definition at line 735 of file Captcha.php.
References $dbr, $res, $title, as, DB_SLAVE, and wfGetDB().
Referenced by shouldCheck().
SimpleCaptcha::getMessage | ( | $action | ) |
Show a message asking the user to enter a captcha on edit The result will be treated as wiki text.
$action | string Action being performed |
Definition at line 230 of file Captcha.php.
References $action, $name, and wfMessage().
Referenced by editShowCaptcha(), FancyCaptcha\onAuthChangeFormFields(), and showEditFormFields().
|
private |
Get the on-wiki IP whitelist stored in [[MediaWiki:Captcha-ip-whitelist]] page from cache if possible.
Message | $msg | whitelist Message on wiki |
Definition at line 380 of file Captcha.php.
References $cache, buildValidIPs(), and ObjectCache\getMainWANInstance().
Referenced by isIPWhitelisted().
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.
string | $username | TODO use Throttler |
Definition at line 275 of file Captcha.php.
References $cache, $username, badLoginKey(), badLoginPerUserKey(), ObjectCache\getLocalClusterInstance(), and global.
SimpleCaptcha::injectEmailUser | ( | & | $form | ) |
Inject whazawhoo @fixme if multiple thingies insert a header, could break.
$form | HTMLForm |
Definition at line 246 of file Captcha.php.
References $out, $user, captcha-old\action, addFormInformationToOutput(), getFormInformation(), global, and wfDebug().
|
protected |
$module | ApiBase |
Definition at line 893 of file Captcha.php.
Referenced by ReCaptcha\APIGetAllowedParams(), and APIGetAllowedParams().
SimpleCaptcha::isBadLoginPerUserTriggered | ( | $u | ) |
Is the per-user captcha triggered?
$u | User|String User object, or name |
Definition at line 333 of file Captcha.php.
References $cache, ObjectCache\getLocalClusterInstance(), and global.
SimpleCaptcha::isBadLoginTriggered | ( | ) |
Check if a bad login has already been registered for this IP address.
If so, require a captcha.
Definition at line 320 of file Captcha.php.
References $cache, ObjectCache\getLocalClusterInstance(), and global.
SimpleCaptcha::isIPWhitelisted | ( | ) |
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
Definition at line 352 of file Captcha.php.
References $wgRequest, getWikiIPWhitelist(), global, IP\isInRanges(), and wfMessage().
Referenced by confirmEmailUser(), needCreateAccountCaptcha(), and shouldCheck().
SimpleCaptcha::keyMatch | ( | $answer, | |
$info | |||
) |
Check if the submitted form matches the captcha session data provided by the plugin when the form was generated.
Override this!
string | $answer | |
array | $info |
Reimplemented in FancyCaptcha, QuestyCaptcha, and MathCaptcha.
Definition at line 459 of file Captcha.php.
Referenced by passCaptcha().
SimpleCaptcha::loadText | ( | $title, | |
$section, | |||
$flags = Revision::READ_LATEST |
|||
) |
Retrieve the current version of the page or section being edited...
Definition at line 1064 of file Captcha.php.
References $flags, $rev, $section, $title, $wgParser, ContentHandler\getContentText(), global, and Revision\newFromTitle().
Referenced by shouldCheck().
SimpleCaptcha::log | ( | $message | ) |
Log the status and any triggering info for debugging or statistics.
string | $message |
Definition at line 1015 of file Captcha.php.
References wfDebugLog().
Referenced by passCaptcha(), and passCaptchaLimited().
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.
User | $creatingUser |
Definition at line 836 of file Captcha.php.
References $wgUser, global, isIPWhitelisted(), and wfDebug().
SimpleCaptcha::onAuthChangeFormFields | ( | array | $requests, |
array | $fieldInfo, | ||
array & | $formDescriptor, | ||
$action | |||
) |
Modify the apprearance of the captcha field.
AuthenticationRequest[] | $requests | |
array | $fieldInfo | Field description as given by AuthenticationRequest::mergeFieldInfo |
array | $formDescriptor | A form descriptor suitable for the HTMLForm constructor |
string | $action | One of the AuthManager::ACTION_* constants |
Reimplemented in FancyCaptcha, ReCaptcha, QuestyCaptcha, and MathCaptcha.
Definition at line 1125 of file Captcha.php.
|
protected |
Given a required captcha run, test form input for correct input on the open session.
string | $index | Captcha idenitifier |
string | $word | Captcha solution |
Reimplemented in FancyCaptcha, and ReCaptcha.
Definition at line 985 of file Captcha.php.
References $captchaSolved, clearCaptcha(), keyMatch(), log(), and retrieveCaptcha().
Referenced by passCaptchaFromRequest(), and passCaptchaLimited().
SimpleCaptcha::passCaptchaFromRequest | ( | WebRequest | $request, |
User | $user | ||
) |
Given a required captcha run, test form input for correct input on the open session.
WebRequest | $request | |
User | $user |
Definition at line 973 of file Captcha.php.
References getCaptchaParamsFromRequest(), list, and passCaptcha().
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.
string | $index | Captcha idenitifier |
string | $word | Captcha solution |
User | $user | User for throttling captcha solving attempts |
Definition at line 949 of file Captcha.php.
References $user, log(), and passCaptcha().
Referenced by passCaptchaLimitedFromRequest(), and CaptchaPreAuthenticationProvider\verifyCaptcha().
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.
WebRequest | $request | |
User | $user |
Definition at line 924 of file Captcha.php.
References $user, getCaptchaParamsFromRequest(), list, and passCaptchaLimited().
Referenced by confirmEmailUser(), and doConfirmEdit().
SimpleCaptcha::resetBadLoginCounter | ( | $username | ) |
Reset bad login counter after a successful login.
string | $username |
Definition at line 305 of file Captcha.php.
References $cache, $username, badLoginPerUserKey(), ObjectCache\getLocalClusterInstance(), and global.
SimpleCaptcha::retrieveCaptcha | ( | $index | ) |
Fetch this session's captcha info.
string | $index |
Reimplemented in ReCaptcha.
Definition at line 1044 of file Captcha.php.
References CaptchaStore\get().
Referenced by FancyCaptcha\passCaptcha(), passCaptcha(), and FancyCaptcha\showImage().
SimpleCaptcha::setAction | ( | $action | ) |
string | $action |
Definition at line 28 of file Captcha.php.
References $action, and captcha-old\action.
SimpleCaptcha::setTrigger | ( | $trigger | ) |
SimpleCaptcha::shouldCheck | ( | WikiPage | $page, |
$content, | |||
$section, | |||
$context, | |||
$oldtext = null |
|||
) |
WikiPage | $page | |
$content | Content|string | |
$section | string | |
IContextSource | $context | |
oldtext | string The content of the revision prior to $content When null this will be loaded from the database. |
Definition at line 489 of file Captcha.php.
References $context, $request, $section, $title, $user, captcha-old\action, as, captchaTriggers(), CONTENT_MODEL_WIKITEXT, captcha-old\count, findLinks(), getLinksFromTracker(), RequestContext\getMain(), WikiPage\getTitle(), global, isIPWhitelisted(), loadText(), WikiPage\prepareContentForEdit(), and wfDebug().
Referenced by doConfirmEdit().
SimpleCaptcha::showEditFormFields | ( | & | $editPage, |
& | $out | ||
) |
Show error message for missing or incorrect captcha on EditPage.
EditPage | $editPage | |
OutputPage | $out |
Definition at line 193 of file Captcha.php.
References $out, captcha-old\action, addFormToOutput(), getMessage(), and text.
SimpleCaptcha::showHelp | ( | ) |
Show a page explaining what this wacky thing is.
Reimplemented in QuestyCaptcha.
Definition at line 1100 of file Captcha.php.
References $wgOut, CaptchaStore\get(), global, text, and wfMessage().
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.
array | $info | data to store |
Reimplemented in ReCaptcha.
Definition at line 1030 of file Captcha.php.
References CaptchaStore\get().
Referenced by MathCaptcha\addCaptchaAPI(), QuestyCaptcha\addCaptchaAPI(), addCaptchaAPI(), FancyCaptcha\addCaptchaAPI(), createAuthenticationRequest(), MathCaptcha\getFormInformation(), QuestyCaptcha\getFormInformation(), FancyCaptcha\getFormInformation(), getFormInformation(), and FancyCaptcha\showImage().
|
protected |
Used to select the right message.
One of sendmail, createaccount, badlogin, edit, create, addurl.
Definition at line 20 of file Captcha.php.
Referenced by captchaTriggers(), getMessage(), FancyCaptcha\onAuthChangeFormFields(), and setAction().
|
private |
Was the CAPTCHA already passed and if yes, with which result?
Definition at line 13 of file Captcha.php.
Referenced by passCaptcha().
|
staticprotected |
Definition at line 10 of file Captcha.php.
|
protected |