2005-09-30 09:21:02 +00:00
|
|
|
<?php
|
2007-04-09 16:42:18 +00:00
|
|
|
|
2006-01-27 08:00:32 +00:00
|
|
|
/**
|
|
|
|
* Experimental captcha plugin framework.
|
|
|
|
* Not intended as a real production captcha system; derived classes
|
|
|
|
* can extend the base to produce their fancy images in place of the
|
|
|
|
* text-based test output here.
|
|
|
|
*
|
2007-06-14 16:41:57 +00:00
|
|
|
* Copyright (C) 2005-2007 Brion Vibber <brion@wikimedia.org>
|
2006-01-27 08:00:32 +00:00
|
|
|
* http://www.mediawiki.org/
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2010-06-21 13:45:17 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2006-01-27 08:00:32 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
2010-06-06 15:12:22 +00:00
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
2006-01-27 08:00:32 +00:00
|
|
|
*/
|
2005-09-30 09:21:02 +00:00
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
2005-09-30 09:21:02 +00:00
|
|
|
|
2005-10-14 05:07:24 +00:00
|
|
|
global $wgExtensionFunctions, $wgGroupPermissions;
|
2005-09-30 09:21:02 +00:00
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
$wgExtensionFunctions[] = 'confirmEditSetup';
|
2007-01-11 05:36:48 +00:00
|
|
|
$wgExtensionCredits['other'][] = array(
|
2009-04-27 03:15:19 +00:00
|
|
|
'path' => __FILE__,
|
2007-01-11 05:36:48 +00:00
|
|
|
'name' => 'ConfirmEdit',
|
|
|
|
'author' => 'Brion Vibber',
|
2007-04-25 16:52:57 +00:00
|
|
|
'url' => 'http://www.mediawiki.org/wiki/Extension:ConfirmEdit',
|
2008-02-04 15:04:47 +00:00
|
|
|
'descriptionmsg' => 'captcha-desc',
|
2007-01-11 05:36:48 +00:00
|
|
|
);
|
2005-09-30 09:21:02 +00:00
|
|
|
|
2006-01-27 08:00:32 +00:00
|
|
|
/**
|
|
|
|
* The 'skipcaptcha' permission key can be given out to
|
|
|
|
* let known-good users perform triggering actions without
|
|
|
|
* having to go through the captcha.
|
|
|
|
*
|
|
|
|
* By default, sysops and registered bot accounts will be
|
|
|
|
* able to skip, while others have to go through it.
|
|
|
|
*/
|
2005-12-29 17:19:28 +00:00
|
|
|
$wgGroupPermissions['*' ]['skipcaptcha'] = false;
|
|
|
|
$wgGroupPermissions['user' ]['skipcaptcha'] = false;
|
|
|
|
$wgGroupPermissions['autoconfirmed']['skipcaptcha'] = false;
|
|
|
|
$wgGroupPermissions['bot' ]['skipcaptcha'] = true; // registered bots
|
|
|
|
$wgGroupPermissions['sysop' ]['skipcaptcha'] = true;
|
2008-05-14 00:38:28 +00:00
|
|
|
$wgAvailableRights[] = 'skipcaptcha';
|
2005-09-30 09:21:02 +00:00
|
|
|
|
2007-07-05 19:48:53 +00:00
|
|
|
/**
|
|
|
|
* List of IP ranges to allow to skip the captcha, similar to the group setting:
|
|
|
|
* "$wgGroupPermission[...]['skipcaptcha'] = true"
|
|
|
|
*
|
|
|
|
* Specific IP addresses or CIDR-style ranges may be used,
|
|
|
|
* for instance:
|
|
|
|
* $wgCaptchaWhitelistIP = array('192.168.1.0/24', '10.1.0.0/16');
|
|
|
|
*/
|
|
|
|
$wgCaptchaWhitelistIP = false;
|
|
|
|
|
2005-10-14 05:07:24 +00:00
|
|
|
global $wgCaptcha, $wgCaptchaClass, $wgCaptchaTriggers;
|
|
|
|
$wgCaptcha = null;
|
|
|
|
$wgCaptchaClass = 'SimpleCaptcha';
|
|
|
|
|
2006-01-27 08:00:32 +00:00
|
|
|
/**
|
2007-04-09 16:42:18 +00:00
|
|
|
* Actions which can trigger a captcha
|
2006-01-27 08:00:32 +00:00
|
|
|
*
|
|
|
|
* If the 'edit' trigger is on, *every* edit will trigger the captcha.
|
|
|
|
* This may be useful for protecting against vandalbot attacks.
|
|
|
|
*
|
|
|
|
* If using the default 'addurl' trigger, the captcha will trigger on
|
|
|
|
* edits that include URLs that aren't in the current version of the page.
|
|
|
|
* This should catch automated linkspammers without annoying people when
|
|
|
|
* they make more typical edits.
|
2007-03-29 02:13:34 +00:00
|
|
|
*
|
|
|
|
* The captcha code should not use $wgCaptchaTriggers, but CaptchaTriggers()
|
|
|
|
* which also takes into account per namespace triggering.
|
2006-01-27 08:00:32 +00:00
|
|
|
*/
|
2005-10-14 05:07:24 +00:00
|
|
|
$wgCaptchaTriggers = array();
|
2006-01-29 07:37:33 +00:00
|
|
|
$wgCaptchaTriggers['edit'] = false; // Would check on every edit
|
2007-03-29 02:13:34 +00:00
|
|
|
$wgCaptchaTriggers['create'] = false; // Check on page creation.
|
2010-04-10 21:26:03 +00:00
|
|
|
$wgCaptchaTriggers['sendemail'] = false; // Special:Emailuser
|
2006-01-29 07:37:33 +00:00
|
|
|
$wgCaptchaTriggers['addurl'] = true; // Check on edits that add URLs
|
|
|
|
$wgCaptchaTriggers['createaccount'] = true; // Special:Userlogin&type=signup
|
2007-05-07 21:54:06 +00:00
|
|
|
$wgCaptchaTriggers['badlogin'] = true; // Special:Userlogin after failure
|
2006-01-29 07:37:33 +00:00
|
|
|
|
2007-03-29 02:13:34 +00:00
|
|
|
/**
|
|
|
|
* You may wish to apply special rules for captcha triggering on some namespaces.
|
2009-07-19 15:13:01 +00:00
|
|
|
* $wgCaptchaTriggersOnNamespace[<namespace id>][<trigger>] forces an always on /
|
2007-03-29 02:13:34 +00:00
|
|
|
* always off configuration with that trigger for the given namespace.
|
|
|
|
* Leave unset to use the global options ($wgCaptchaTriggers).
|
|
|
|
*
|
|
|
|
* Shall not be used with 'createaccount' (it is not checked).
|
|
|
|
*/
|
|
|
|
$wgCaptchaTriggersOnNamespace = array();
|
|
|
|
|
2009-07-19 15:13:01 +00:00
|
|
|
# Example:
|
|
|
|
# $wgCaptchaTriggersOnNamespace[NS_TALK]['create'] = false; //Allow creation of talk pages without captchas.
|
|
|
|
# $wgCaptchaTriggersOnNamespace[NS_PROJECT]['edit'] = true; //Show captcha whenever editing Project pages.
|
2007-03-29 02:13:34 +00:00
|
|
|
|
2007-02-19 21:32:16 +00:00
|
|
|
/**
|
|
|
|
* Indicate how to store per-session data required to match up the
|
|
|
|
* internal captcha data with the editor.
|
|
|
|
*
|
|
|
|
* 'CaptchaSessionStore' uses PHP's session storage, which is cookie-based
|
|
|
|
* and may fail for anons with cookies disabled.
|
|
|
|
*
|
|
|
|
* 'CaptchaCacheStore' uses $wgMemc, which avoids the cookie dependency
|
|
|
|
* but may be fragile depending on cache configuration.
|
|
|
|
*/
|
|
|
|
global $wgCaptchaStorageClass;
|
|
|
|
$wgCaptchaStorageClass = 'CaptchaSessionStore';
|
|
|
|
|
|
|
|
/**
|
2007-05-07 21:54:06 +00:00
|
|
|
* Number of seconds a captcha session should last in the data cache
|
2007-02-19 21:32:16 +00:00
|
|
|
* before expiring when managing through CaptchaCacheStore class.
|
|
|
|
*
|
|
|
|
* Default is a half hour.
|
|
|
|
*/
|
|
|
|
global $wgCaptchaSessionExpiration;
|
|
|
|
$wgCaptchaSessionExpiration = 30 * 60;
|
2005-10-14 05:07:24 +00:00
|
|
|
|
2007-05-07 21:54:06 +00:00
|
|
|
/**
|
|
|
|
* Number of seconds after a bad login that a captcha will be shown to
|
|
|
|
* that client on the login form to slow down password-guessing bots.
|
|
|
|
*
|
|
|
|
* Has no effect if 'badlogin' is disabled in $wgCaptchaTriggers or
|
|
|
|
* if there is not a caching engine enabled.
|
|
|
|
*
|
|
|
|
* Default is five minutes.
|
|
|
|
*/
|
|
|
|
global $wgCaptchaBadLoginExpiration;
|
|
|
|
$wgCaptchaBadLoginExpiration = 5 * 60;
|
|
|
|
|
2005-09-30 09:21:02 +00:00
|
|
|
/**
|
|
|
|
* Allow users who have confirmed their e-mail addresses to post
|
|
|
|
* URL links without being harassed by the captcha.
|
|
|
|
*/
|
|
|
|
global $ceAllowConfirmedEmail;
|
|
|
|
$ceAllowConfirmedEmail = false;
|
|
|
|
|
2009-07-19 15:13:01 +00:00
|
|
|
/**
|
2008-07-02 23:09:26 +00:00
|
|
|
* Number of bad login attempts before triggering the captcha. 0 means the
|
|
|
|
* captcha is presented on the first login.
|
2008-07-02 15:00:30 +00:00
|
|
|
*/
|
|
|
|
global $wgCaptchaBadLoginAttempts;
|
2008-07-02 23:09:26 +00:00
|
|
|
$wgCaptchaBadLoginAttempts = 3;
|
2008-07-02 15:00:30 +00:00
|
|
|
|
2006-01-27 11:05:50 +00:00
|
|
|
/**
|
|
|
|
* Regex to whitelist URLs to known-good sites...
|
|
|
|
* For instance:
|
|
|
|
* $wgCaptchaWhitelist = '#^https?://([a-z0-9-]+\\.)?(wikimedia|wikipedia)\.org/#i';
|
2007-06-20 10:00:47 +00:00
|
|
|
* Local admins can define a whitelist under [[MediaWiki:captcha-addurl-whitelist]]
|
2006-01-27 11:05:50 +00:00
|
|
|
*/
|
|
|
|
$wgCaptchaWhitelist = false;
|
|
|
|
|
2006-06-24 21:26:48 +00:00
|
|
|
/**
|
|
|
|
* Additional regexes to check for. Use full regexes; can match things
|
|
|
|
* other than URLs such as junk edits.
|
|
|
|
*
|
|
|
|
* If the new version matches one and the old version doesn't,
|
|
|
|
* toss up the captcha screen.
|
|
|
|
*
|
|
|
|
* @fixme Add a message for local admins to add items as well.
|
|
|
|
*/
|
|
|
|
$wgCaptchaRegexes = array();
|
|
|
|
|
2006-07-03 15:56:15 +00:00
|
|
|
/** Register special page */
|
2007-11-12 07:42:25 +00:00
|
|
|
$wgSpecialPages['Captcha'] = array( /*class*/'CaptchaSpecialPage', /*name*/'Captcha' );
|
2006-07-03 15:56:15 +00:00
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
$wgConfirmEditIP = dirname( __FILE__ );
|
|
|
|
$wgExtensionMessagesFiles['ConfirmEdit'] = "$wgConfirmEditIP/ConfirmEdit.i18n.php";
|
2009-05-24 09:20:04 +00:00
|
|
|
$wgExtensionAliasesFiles['ConfirmEdit'] = "$wgConfirmEditIP/ConfirmEdit.alias.php";
|
2007-01-11 05:36:48 +00:00
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
if ( defined( 'MW_SUPPORTS_EDITFILTERMERGED' ) ) {
|
|
|
|
$wgHooks['EditFilterMerged'][] = 'ConfirmEditHooks::confirmEditMerged';
|
|
|
|
} else {
|
|
|
|
$wgHooks['EditFilter'][] = 'ConfirmEditHooks::confirmEdit';
|
|
|
|
}
|
|
|
|
$wgHooks['UserCreateForm'][] = 'ConfirmEditHooks::injectUserCreate';
|
|
|
|
$wgHooks['AbortNewAccount'][] = 'ConfirmEditHooks::confirmUserCreate';
|
|
|
|
$wgHooks['LoginAuthenticateAudit'][] = 'ConfirmEditHooks::triggerUserLogin';
|
|
|
|
$wgHooks['UserLoginForm'][] = 'ConfirmEditHooks::injectUserLogin';
|
|
|
|
$wgHooks['AbortLogin'][] = 'ConfirmEditHooks::confirmUserLogin';
|
2010-04-10 21:26:03 +00:00
|
|
|
$wgHooks['EmailUserForm'][] = 'ConfirmEditHooks::injectEmailUser';
|
|
|
|
$wgHooks['EmailUser'][] = 'ConfirmEditHooks::confirmEmailUser';
|
2008-02-28 17:42:23 +00:00
|
|
|
# Register API hook
|
|
|
|
$wgHooks['APIEditBeforeSave'][] = 'ConfirmEditHooks::confirmEditAPI';
|
2007-11-12 07:42:25 +00:00
|
|
|
|
2009-07-19 15:13:01 +00:00
|
|
|
$wgAutoloadClasses['ConfirmEditHooks']
|
|
|
|
= $wgAutoloadClasses['SimpleCaptcha']
|
2007-11-12 07:42:25 +00:00
|
|
|
= $wgAutoloadClasses['CaptchaSessionStore']
|
|
|
|
= $wgAutoloadClasses['CaptchaCacheStore']
|
|
|
|
= $wgAutoloadClasses['CaptchaSpecialPage']
|
|
|
|
= "$wgConfirmEditIP/ConfirmEdit_body.php";
|
2007-01-11 05:36:48 +00:00
|
|
|
|
2007-11-12 07:42:25 +00:00
|
|
|
/**
|
|
|
|
* Set up $wgWhitelistRead
|
|
|
|
*/
|
|
|
|
function confirmEditSetup() {
|
2007-05-14 14:23:25 +00:00
|
|
|
global $wgGroupPermissions, $wgCaptchaTriggers;
|
2009-07-19 15:13:01 +00:00
|
|
|
if ( !$wgGroupPermissions['*']['read'] && $wgCaptchaTriggers['badlogin'] ) {
|
2007-05-14 14:23:25 +00:00
|
|
|
// We need to ensure that the captcha interface is accessible
|
|
|
|
// so that unauthenticated users can actually get in after a
|
|
|
|
// mistaken password typing.
|
|
|
|
global $wgWhitelistRead;
|
2010-06-08 19:30:48 +00:00
|
|
|
$image = SpecialPage::getTitleFor( 'Captcha', 'image' );
|
|
|
|
$help = SpecialPage::getTitleFor( 'Captcha', 'help' );
|
2007-05-14 14:23:25 +00:00
|
|
|
$wgWhitelistRead[] = $image->getPrefixedText();
|
|
|
|
$wgWhitelistRead[] = $help->getPrefixedText();
|
|
|
|
}
|
2005-09-30 09:21:02 +00:00
|
|
|
}
|