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',
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;
60 * List of IP ranges to allow to skip the captcha, similar to the group setting:
61 * "$wgGroupPermission[...]['skipcaptcha'] = true"
63 * Specific IP addresses or CIDR-style ranges may be used,
65 * $wgCaptchaWhitelistIP = array('192.168.1.0/24', '10.1.0.0/16');
67 $wgCaptchaWhitelistIP = false;
69 global $wgCaptcha, $wgCaptchaClass, $wgCaptchaTriggers;
71 $wgCaptchaClass = 'SimpleCaptcha';
74 * Actions which can trigger a captcha
76 * If the 'edit' trigger is on, *every* edit will trigger the captcha.
77 * This may be useful for protecting against vandalbot attacks.
79 * If using the default 'addurl' trigger, the captcha will trigger on
80 * edits that include URLs that aren't in the current version of the page.
81 * This should catch automated linkspammers without annoying people when
82 * they make more typical edits.
84 * The captcha code should not use $wgCaptchaTriggers, but CaptchaTriggers()
85 * which also takes into account per namespace triggering.
87 $wgCaptchaTriggers = array();
88 $wgCaptchaTriggers['edit'] = false; // Would check on every edit
89 $wgCaptchaTriggers['create'] = false; // Check on page creation.
90 $wgCaptchaTriggers['addurl'] = true; // Check on edits that add URLs
91 $wgCaptchaTriggers['createaccount'] = true; // Special:Userlogin&type=signup
92 $wgCaptchaTriggers['badlogin'] = true; // Special:Userlogin after failure
95 * You may wish to apply special rules for captcha triggering on some namespaces.
96 * $wgCaptchaTriggersOnNamespace[<namespace id>][<trigger>] forces an always on /
97 * always off configuration with that trigger for the given namespace.
98 * Leave unset to use the global options ($wgCaptchaTriggers).
100 * Shall not be used with 'createaccount' (it is not checked).
102 $wgCaptchaTriggersOnNamespace = array();
105 #$wgCaptchaTriggersOnNamespace[NS_TALK]['create'] = false; //Allow creation of talk pages without captchas.
106 #$wgCaptchaTriggersOnNamespace[NS_PROJECT]['edit'] = true; //Show captcha whenever editing Project pages.
109 * Indicate how to store per-session data required to match up the
110 * internal captcha data with the editor.
112 * 'CaptchaSessionStore' uses PHP's session storage, which is cookie-based
113 * and may fail for anons with cookies disabled.
115 * 'CaptchaCacheStore' uses $wgMemc, which avoids the cookie dependency
116 * but may be fragile depending on cache configuration.
118 global $wgCaptchaStorageClass;
119 $wgCaptchaStorageClass = 'CaptchaSessionStore';
122 * Number of seconds a captcha session should last in the data cache
123 * before expiring when managing through CaptchaCacheStore class.
125 * Default is a half hour.
127 global $wgCaptchaSessionExpiration;
128 $wgCaptchaSessionExpiration = 30 * 60;
131 * Number of seconds after a bad login that a captcha will be shown to
132 * that client on the login form to slow down password-guessing bots.
134 * Has no effect if 'badlogin' is disabled in $wgCaptchaTriggers or
135 * if there is not a caching engine enabled.
137 * Default is five minutes.
139 global $wgCaptchaBadLoginExpiration;
140 $wgCaptchaBadLoginExpiration = 5 * 60;
143 * Allow users who have confirmed their e-mail addresses to post
144 * URL links without being harassed by the captcha.
146 global $ceAllowConfirmedEmail;
147 $ceAllowConfirmedEmail = false;
150 * Regex to whitelist URLs to known-good sites...
152 * $wgCaptchaWhitelist = '#^https?://([a-z0-9-]+\\.)?(wikimedia|wikipedia)\.org/#i';
153 * Local admins can define a whitelist under [[MediaWiki:captcha-addurl-whitelist]]
155 $wgCaptchaWhitelist = false;
158 * Additional regexes to check for. Use full regexes; can match things
159 * other than URLs such as junk edits.
161 * If the new version matches one and the old version doesn't,
162 * toss up the captcha screen.
164 * @fixme Add a message for local admins to add items as well.
166 $wgCaptchaRegexes = array();
168 /** Register special page */
169 global $wgSpecialPages;
170 $wgSpecialPages['Captcha'] = array( /*class*/'CaptchaSpecialPage', /*name*/'Captcha' );
172 $wgConfirmEditIP = dirname( __FILE__ );
173 $wgExtensionMessagesFiles['ConfirmEdit'] = "$wgConfirmEditIP/ConfirmEdit.i18n.php";
175 if ( defined( 'MW_SUPPORTS_EDITFILTERMERGED' ) ) {
176 $wgHooks['EditFilterMerged'][] = 'ConfirmEditHooks::confirmEditMerged';
178 $wgHooks['EditFilter'][] = 'ConfirmEditHooks::confirmEdit';
180 $wgHooks['UserCreateForm'][] = 'ConfirmEditHooks::injectUserCreate';
181 $wgHooks['AbortNewAccount'][] = 'ConfirmEditHooks::confirmUserCreate';
182 $wgHooks['LoginAuthenticateAudit'][] = 'ConfirmEditHooks::triggerUserLogin';
183 $wgHooks['UserLoginForm'][] = 'ConfirmEditHooks::injectUserLogin';
184 $wgHooks['AbortLogin'][] = 'ConfirmEditHooks::confirmUserLogin';
186 $wgAutoloadClasses['ConfirmEditHooks']
187 = $wgAutoloadClasses['SimpleCaptcha']
188 = $wgAutoloadClasses['CaptchaSessionStore']
189 = $wgAutoloadClasses['CaptchaCacheStore']
190 = $wgAutoloadClasses['CaptchaSpecialPage']
191 = "$wgConfirmEditIP/ConfirmEdit_body.php";
194 * Set up $wgWhitelistRead
196 function confirmEditSetup() {
197 global $wgGroupPermissions, $wgCaptchaTriggers;
198 if( !$wgGroupPermissions['*']['read'] && $wgCaptchaTriggers['badlogin'] ) {
199 // We need to ensure that the captcha interface is accessible
200 // so that unauthenticated users can actually get in after a
201 // mistaken password typing.
202 global $wgWhitelistRead;
203 $image = Title::makeTitle( NS_SPECIAL, 'Captcha/image' );
204 $help = Title::makeTitle( NS_SPECIAL, 'Captcha/help' );
205 $wgWhitelistRead[] = $image->getPrefixedText();
206 $wgWhitelistRead[] = $help->getPrefixedText();