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(
38 'name' => 'ConfirmEdit',
39 'author' => 'Brion Vibber',
40 'url' => 'http://www.mediawiki.org/wiki/Extension:ConfirmEdit',
41 'description' => 'Simple captcha implementation',
45 * The 'skipcaptcha' permission key can be given out to
46 * let known-good users perform triggering actions without
47 * having to go through the captcha.
49 * By default, sysops and registered bot accounts will be
50 * able to skip, while others have to go through it.
52 $wgGroupPermissions['*' ]['skipcaptcha'] = false;
53 $wgGroupPermissions['user' ]['skipcaptcha'] = false;
54 $wgGroupPermissions['autoconfirmed']['skipcaptcha'] = false;
55 $wgGroupPermissions['bot' ]['skipcaptcha'] = true; // registered bots
56 $wgGroupPermissions['sysop' ]['skipcaptcha'] = true;
59 * List of IP ranges to allow to skip the captcha, similar to the group setting:
60 * "$wgGroupPermission[...]['skipcaptcha'] = true"
62 * Specific IP addresses or CIDR-style ranges may be used,
64 * $wgCaptchaWhitelistIP = array('192.168.1.0/24', '10.1.0.0/16');
66 $wgCaptchaWhitelistIP = false;
68 global $wgCaptcha, $wgCaptchaClass, $wgCaptchaTriggers;
70 $wgCaptchaClass = 'SimpleCaptcha';
73 * Actions which can trigger a captcha
75 * If the 'edit' trigger is on, *every* edit will trigger the captcha.
76 * This may be useful for protecting against vandalbot attacks.
78 * If using the default 'addurl' trigger, the captcha will trigger on
79 * edits that include URLs that aren't in the current version of the page.
80 * This should catch automated linkspammers without annoying people when
81 * they make more typical edits.
83 * The captcha code should not use $wgCaptchaTriggers, but CaptchaTriggers()
84 * which also takes into account per namespace triggering.
86 $wgCaptchaTriggers = array();
87 $wgCaptchaTriggers['edit'] = false; // Would check on every edit
88 $wgCaptchaTriggers['create'] = false; // Check on page creation.
89 $wgCaptchaTriggers['addurl'] = true; // Check on edits that add URLs
90 $wgCaptchaTriggers['createaccount'] = true; // Special:Userlogin&type=signup
91 $wgCaptchaTriggers['badlogin'] = true; // Special:Userlogin after failure
94 * You may wish to apply special rules for captcha triggering on some namespaces.
95 * $wgCaptchaTriggersOnNamespace[<namespace id>][<trigger>] forces an always on /
96 * always off configuration with that trigger for the given namespace.
97 * Leave unset to use the global options ($wgCaptchaTriggers).
99 * Shall not be used with 'createaccount' (it is not checked).
101 $wgCaptchaTriggersOnNamespace = array();
104 #$wgCaptchaTriggersOnNamespace[NS_TALK]['create'] = false; //Allow creation of talk pages without captchas.
105 #$wgCaptchaTriggersOnNamespace[NS_PROJECT]['edit'] = true; //Show captcha whenever editing Project pages.
108 * Indicate how to store per-session data required to match up the
109 * internal captcha data with the editor.
111 * 'CaptchaSessionStore' uses PHP's session storage, which is cookie-based
112 * and may fail for anons with cookies disabled.
114 * 'CaptchaCacheStore' uses $wgMemc, which avoids the cookie dependency
115 * but may be fragile depending on cache configuration.
117 global $wgCaptchaStorageClass;
118 $wgCaptchaStorageClass = 'CaptchaSessionStore';
121 * Number of seconds a captcha session should last in the data cache
122 * before expiring when managing through CaptchaCacheStore class.
124 * Default is a half hour.
126 global $wgCaptchaSessionExpiration;
127 $wgCaptchaSessionExpiration = 30 * 60;
130 * Number of seconds after a bad login that a captcha will be shown to
131 * that client on the login form to slow down password-guessing bots.
133 * Has no effect if 'badlogin' is disabled in $wgCaptchaTriggers or
134 * if there is not a caching engine enabled.
136 * Default is five minutes.
138 global $wgCaptchaBadLoginExpiration;
139 $wgCaptchaBadLoginExpiration = 5 * 60;
142 * Allow users who have confirmed their e-mail addresses to post
143 * URL links without being harassed by the captcha.
145 global $ceAllowConfirmedEmail;
146 $ceAllowConfirmedEmail = false;
149 * Regex to whitelist URLs to known-good sites...
151 * $wgCaptchaWhitelist = '#^https?://([a-z0-9-]+\\.)?(wikimedia|wikipedia)\.org/#i';
152 * Local admins can define a whitelist under [[MediaWiki:captcha-addurl-whitelist]]
154 $wgCaptchaWhitelist = false;
157 * Additional regexes to check for. Use full regexes; can match things
158 * other than URLs such as junk edits.
160 * If the new version matches one and the old version doesn't,
161 * toss up the captcha screen.
163 * @fixme Add a message for local admins to add items as well.
165 $wgCaptchaRegexes = array();
167 /** Register special page */
168 global $wgSpecialPages;
169 $wgSpecialPages['Captcha'] = array( /*class*/'CaptchaSpecialPage', /*name*/'Captcha' );
171 $wgConfirmEditIP = dirname( __FILE__ );
172 $wgExtensionMessagesFiles['ConfirmEdit'] = "$wgConfirmEditIP/ConfirmEdit.i18n.php";
174 if ( defined( 'MW_SUPPORTS_EDITFILTERMERGED' ) ) {
175 $wgHooks['EditFilterMerged'][] = 'ConfirmEditHooks::confirmEditMerged';
177 $wgHooks['EditFilter'][] = 'ConfirmEditHooks::confirmEdit';
179 $wgHooks['UserCreateForm'][] = 'ConfirmEditHooks::injectUserCreate';
180 $wgHooks['AbortNewAccount'][] = 'ConfirmEditHooks::confirmUserCreate';
181 $wgHooks['LoginAuthenticateAudit'][] = 'ConfirmEditHooks::triggerUserLogin';
182 $wgHooks['UserLoginForm'][] = 'ConfirmEditHooks::injectUserLogin';
183 $wgHooks['AbortLogin'][] = 'ConfirmEditHooks::confirmUserLogin';
185 $wgAutoloadClasses['ConfirmEditHooks']
186 = $wgAutoloadClasses['SimpleCaptcha']
187 = $wgAutoloadClasses['CaptchaSessionStore']
188 = $wgAutoloadClasses['CaptchaCacheStore']
189 = $wgAutoloadClasses['CaptchaSpecialPage']
190 = "$wgConfirmEditIP/ConfirmEdit_body.php";
193 * Set up $wgWhitelistRead
195 function confirmEditSetup() {
196 global $wgGroupPermissions, $wgCaptchaTriggers;
197 if( !$wgGroupPermissions['*']['read'] && $wgCaptchaTriggers['badlogin'] ) {
198 // We need to ensure that the captcha interface is accessible
199 // so that unauthenticated users can actually get in after a
200 // mistaken password typing.
201 global $wgWhitelistRead;
202 $image = Title::makeTitle( NS_SPECIAL, 'Captcha/image' );
203 $help = Title::makeTitle( NS_SPECIAL, 'Captcha/help' );
204 $wgWhitelistRead[] = $image->getPrefixedText();
205 $wgWhitelistRead[] = $help->getPrefixedText();