4 * Experimental captcha plugin framework.
5 * Not intended as a real production captcha system; derived classes
6 * can extend the base to produce their fancy images in place of the
7 * text-based test output here.
9 * Copyright (C) 2005-2007 Brion Vibber <brion@wikimedia.org>
10 * http://www.mediawiki.org/
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * http://www.gnu.org/copyleft/gpl.html
27 * @addtogroup Extensions
30 if ( !defined( 'MEDIAWIKI' ) ) {
34 global $wgExtensionFunctions, $wgGroupPermissions;
36 $wgExtensionFunctions[] = 'confirmEditSetup';
37 $wgExtensionCredits['other'][] = array(
39 'name' => 'ConfirmEdit',
40 'author' => 'Brion Vibber',
41 'url' => 'http://www.mediawiki.org/wiki/Extension:ConfirmEdit',
42 'descriptionmsg' => 'captcha-desc',
46 * The 'skipcaptcha' permission key can be given out to
47 * let known-good users perform triggering actions without
48 * having to go through the captcha.
50 * By default, sysops and registered bot accounts will be
51 * able to skip, while others have to go through it.
53 $wgGroupPermissions['*' ]['skipcaptcha'] = false;
54 $wgGroupPermissions['user' ]['skipcaptcha'] = false;
55 $wgGroupPermissions['autoconfirmed']['skipcaptcha'] = false;
56 $wgGroupPermissions['bot' ]['skipcaptcha'] = true; // registered bots
57 $wgGroupPermissions['sysop' ]['skipcaptcha'] = true;
58 $wgAvailableRights[] = 'skipcaptcha';
61 * List of IP ranges to allow to skip the captcha, similar to the group setting:
62 * "$wgGroupPermission[...]['skipcaptcha'] = true"
64 * Specific IP addresses or CIDR-style ranges may be used,
66 * $wgCaptchaWhitelistIP = array('192.168.1.0/24', '10.1.0.0/16');
68 $wgCaptchaWhitelistIP = false;
70 global $wgCaptcha, $wgCaptchaClass, $wgCaptchaTriggers;
72 $wgCaptchaClass = 'SimpleCaptcha';
75 * Actions which can trigger a captcha
77 * If the 'edit' trigger is on, *every* edit will trigger the captcha.
78 * This may be useful for protecting against vandalbot attacks.
80 * If using the default 'addurl' trigger, the captcha will trigger on
81 * edits that include URLs that aren't in the current version of the page.
82 * This should catch automated linkspammers without annoying people when
83 * they make more typical edits.
85 * The captcha code should not use $wgCaptchaTriggers, but CaptchaTriggers()
86 * which also takes into account per namespace triggering.
88 $wgCaptchaTriggers = array();
89 $wgCaptchaTriggers['edit'] = false; // Would check on every edit
90 $wgCaptchaTriggers['create'] = false; // Check on page creation.
91 $wgCaptchaTriggers['sendemail'] = false; // Special:Emailuser
92 $wgCaptchaTriggers['addurl'] = true; // Check on edits that add URLs
93 $wgCaptchaTriggers['createaccount'] = true; // Special:Userlogin&type=signup
94 $wgCaptchaTriggers['badlogin'] = true; // Special:Userlogin after failure
97 * You may wish to apply special rules for captcha triggering on some namespaces.
98 * $wgCaptchaTriggersOnNamespace[<namespace id>][<trigger>] forces an always on /
99 * always off configuration with that trigger for the given namespace.
100 * Leave unset to use the global options ($wgCaptchaTriggers).
102 * Shall not be used with 'createaccount' (it is not checked).
104 $wgCaptchaTriggersOnNamespace = array();
107 # $wgCaptchaTriggersOnNamespace[NS_TALK]['create'] = false; //Allow creation of talk pages without captchas.
108 # $wgCaptchaTriggersOnNamespace[NS_PROJECT]['edit'] = true; //Show captcha whenever editing Project pages.
111 * Indicate how to store per-session data required to match up the
112 * internal captcha data with the editor.
114 * 'CaptchaSessionStore' uses PHP's session storage, which is cookie-based
115 * and may fail for anons with cookies disabled.
117 * 'CaptchaCacheStore' uses $wgMemc, which avoids the cookie dependency
118 * but may be fragile depending on cache configuration.
120 global $wgCaptchaStorageClass;
121 $wgCaptchaStorageClass = 'CaptchaSessionStore';
124 * Number of seconds a captcha session should last in the data cache
125 * before expiring when managing through CaptchaCacheStore class.
127 * Default is a half hour.
129 global $wgCaptchaSessionExpiration;
130 $wgCaptchaSessionExpiration = 30 * 60;
133 * Number of seconds after a bad login that a captcha will be shown to
134 * that client on the login form to slow down password-guessing bots.
136 * Has no effect if 'badlogin' is disabled in $wgCaptchaTriggers or
137 * if there is not a caching engine enabled.
139 * Default is five minutes.
141 global $wgCaptchaBadLoginExpiration;
142 $wgCaptchaBadLoginExpiration = 5 * 60;
145 * Allow users who have confirmed their e-mail addresses to post
146 * URL links without being harassed by the captcha.
148 global $ceAllowConfirmedEmail;
149 $ceAllowConfirmedEmail = false;
152 * Number of bad login attempts before triggering the captcha. 0 means the
153 * captcha is presented on the first login.
155 global $wgCaptchaBadLoginAttempts;
156 $wgCaptchaBadLoginAttempts = 3;
159 * Regex to whitelist URLs to known-good sites...
161 * $wgCaptchaWhitelist = '#^https?://([a-z0-9-]+\\.)?(wikimedia|wikipedia)\.org/#i';
162 * Local admins can define a whitelist under [[MediaWiki:captcha-addurl-whitelist]]
164 $wgCaptchaWhitelist = false;
167 * Additional regexes to check for. Use full regexes; can match things
168 * other than URLs such as junk edits.
170 * If the new version matches one and the old version doesn't,
171 * toss up the captcha screen.
173 * @fixme Add a message for local admins to add items as well.
175 $wgCaptchaRegexes = array();
177 /** Register special page */
178 $wgSpecialPages['Captcha'] = array( /*class*/'CaptchaSpecialPage', /*name*/'Captcha' );
180 $wgConfirmEditIP = dirname( __FILE__ );
181 $wgExtensionMessagesFiles['ConfirmEdit'] = "$wgConfirmEditIP/ConfirmEdit.i18n.php";
182 $wgExtensionAliasesFiles['ConfirmEdit'] = "$wgConfirmEditIP/ConfirmEdit.alias.php";
184 if ( defined( 'MW_SUPPORTS_EDITFILTERMERGED' ) ) {
185 $wgHooks['EditFilterMerged'][] = 'ConfirmEditHooks::confirmEditMerged';
187 $wgHooks['EditFilter'][] = 'ConfirmEditHooks::confirmEdit';
189 $wgHooks['UserCreateForm'][] = 'ConfirmEditHooks::injectUserCreate';
190 $wgHooks['AbortNewAccount'][] = 'ConfirmEditHooks::confirmUserCreate';
191 $wgHooks['LoginAuthenticateAudit'][] = 'ConfirmEditHooks::triggerUserLogin';
192 $wgHooks['UserLoginForm'][] = 'ConfirmEditHooks::injectUserLogin';
193 $wgHooks['AbortLogin'][] = 'ConfirmEditHooks::confirmUserLogin';
194 $wgHooks['EmailUserForm'][] = 'ConfirmEditHooks::injectEmailUser';
195 $wgHooks['EmailUser'][] = 'ConfirmEditHooks::confirmEmailUser';
197 $wgHooks['APIEditBeforeSave'][] = 'ConfirmEditHooks::confirmEditAPI';
199 $wgAutoloadClasses['ConfirmEditHooks']
200 = $wgAutoloadClasses['SimpleCaptcha']
201 = $wgAutoloadClasses['CaptchaSessionStore']
202 = $wgAutoloadClasses['CaptchaCacheStore']
203 = $wgAutoloadClasses['CaptchaSpecialPage']
204 = "$wgConfirmEditIP/ConfirmEdit_body.php";
207 * Set up $wgWhitelistRead
209 function confirmEditSetup() {
210 global $wgGroupPermissions, $wgCaptchaTriggers;
211 if ( !$wgGroupPermissions['*']['read'] && $wgCaptchaTriggers['badlogin'] ) {
212 // We need to ensure that the captcha interface is accessible
213 // so that unauthenticated users can actually get in after a
214 // mistaken password typing.
215 global $wgWhitelistRead;
216 $image = Title::makeTitle( NS_SPECIAL, 'Captcha/image' );
217 $help = Title::makeTitle( NS_SPECIAL, 'Captcha/help' );
218 $wgWhitelistRead[] = $image->getPrefixedText();
219 $wgWhitelistRead[] = $help->getPrefixedText();