4 * ConfirmEdit MediaWiki extension.
6 * This is a framework that holds a variety of CAPTCHA tools. The
7 * default one, 'SimpleCaptcha', is not intended as a production-
8 * level CAPTCHA system, and another one of the options provided
9 * should be used in its place for any real usages.
11 * Copyright (C) 2005-2007 Brion Vibber <brion@wikimedia.org>
12 * http://www.mediawiki.org/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 * http://www.gnu.org/copyleft/gpl.html
33 if ( !defined( 'MEDIAWIKI' ) ) {
37 global $wgExtensionFunctions, $wgGroupPermissions;
39 $wgExtensionFunctions[] = 'confirmEditSetup';
40 $wgExtensionCredits['other'][] = array(
42 'name' => 'ConfirmEdit',
43 'author' => array( 'Brion Vibber', '...' ),
44 'url' => 'http://www.mediawiki.org/wiki/Extension:ConfirmEdit',
46 'descriptionmsg' => 'captcha-desc',
50 * The 'skipcaptcha' permission key can be given out to
51 * let known-good users perform triggering actions without
52 * having to go through the captcha.
54 * By default, sysops and registered bot accounts will be
55 * able to skip, while others have to go through it.
57 $wgGroupPermissions['*' ]['skipcaptcha'] = false;
58 $wgGroupPermissions['user' ]['skipcaptcha'] = false;
59 $wgGroupPermissions['autoconfirmed']['skipcaptcha'] = false;
60 $wgGroupPermissions['bot' ]['skipcaptcha'] = true; // registered bots
61 $wgGroupPermissions['sysop' ]['skipcaptcha'] = true;
62 $wgAvailableRights[] = 'skipcaptcha';
65 * List of IP ranges to allow to skip the captcha, similar to the group setting:
66 * "$wgGroupPermission[...]['skipcaptcha'] = true"
68 * Specific IP addresses or CIDR-style ranges may be used,
70 * $wgCaptchaWhitelistIP = array('192.168.1.0/24', '10.1.0.0/16');
72 $wgCaptchaWhitelistIP = false;
74 global $wgCaptcha, $wgCaptchaClass, $wgCaptchaTriggers;
76 $wgCaptchaClass = 'SimpleCaptcha';
79 * Actions which can trigger a captcha
81 * If the 'edit' trigger is on, *every* edit will trigger the captcha.
82 * This may be useful for protecting against vandalbot attacks.
84 * If using the default 'addurl' trigger, the captcha will trigger on
85 * edits that include URLs that aren't in the current version of the page.
86 * This should catch automated linkspammers without annoying people when
87 * they make more typical edits.
89 * The captcha code should not use $wgCaptchaTriggers, but CaptchaTriggers()
90 * which also takes into account per namespace triggering.
92 $wgCaptchaTriggers = array();
93 $wgCaptchaTriggers['edit'] = false; // Would check on every edit
94 $wgCaptchaTriggers['create'] = false; // Check on page creation.
95 $wgCaptchaTriggers['sendemail'] = false; // Special:Emailuser
96 $wgCaptchaTriggers['addurl'] = true; // Check on edits that add URLs
97 $wgCaptchaTriggers['createaccount'] = true; // Special:Userlogin&type=signup
98 $wgCaptchaTriggers['badlogin'] = true; // Special:Userlogin after failure
101 * You may wish to apply special rules for captcha triggering on some namespaces.
102 * $wgCaptchaTriggersOnNamespace[<namespace id>][<trigger>] forces an always on /
103 * always off configuration with that trigger for the given namespace.
104 * Leave unset to use the global options ($wgCaptchaTriggers).
106 * Shall not be used with 'createaccount' (it is not checked).
108 $wgCaptchaTriggersOnNamespace = array();
111 # $wgCaptchaTriggersOnNamespace[NS_TALK]['create'] = false; //Allow creation of talk pages without captchas.
112 # $wgCaptchaTriggersOnNamespace[NS_PROJECT]['edit'] = true; //Show captcha whenever editing Project pages.
115 * Indicate how to store per-session data required to match up the
116 * internal captcha data with the editor.
118 * 'CaptchaSessionStore' uses PHP's session storage, which is cookie-based
119 * and may fail for anons with cookies disabled.
121 * 'CaptchaCacheStore' uses $wgMemc, which avoids the cookie dependency
122 * but may be fragile depending on cache configuration.
124 global $wgCaptchaStorageClass;
125 $wgCaptchaStorageClass = 'CaptchaSessionStore';
128 * Number of seconds a captcha session should last in the data cache
129 * before expiring when managing through CaptchaCacheStore class.
131 * Default is a half hour.
133 global $wgCaptchaSessionExpiration;
134 $wgCaptchaSessionExpiration = 30 * 60;
137 * Number of seconds after a bad login that a captcha will be shown to
138 * that client on the login form to slow down password-guessing bots.
140 * Has no effect if 'badlogin' is disabled in $wgCaptchaTriggers or
141 * if there is not a caching engine enabled.
143 * Default is five minutes.
145 global $wgCaptchaBadLoginExpiration;
146 $wgCaptchaBadLoginExpiration = 5 * 60;
149 * Allow users who have confirmed their e-mail addresses to post
150 * URL links without being harassed by the captcha.
152 global $ceAllowConfirmedEmail;
153 $ceAllowConfirmedEmail = false;
156 * Number of bad login attempts before triggering the captcha. 0 means the
157 * captcha is presented on the first login.
159 global $wgCaptchaBadLoginAttempts;
160 $wgCaptchaBadLoginAttempts = 3;
163 * Regex to whitelist URLs to known-good sites...
165 * $wgCaptchaWhitelist = '#^https?://([a-z0-9-]+\\.)?(wikimedia|wikipedia)\.org/#i';
166 * Local admins can define a whitelist under [[MediaWiki:captcha-addurl-whitelist]]
168 $wgCaptchaWhitelist = false;
171 * Additional regexes to check for. Use full regexes; can match things
172 * other than URLs such as junk edits.
174 * If the new version matches one and the old version doesn't,
175 * toss up the captcha screen.
177 * @fixme Add a message for local admins to add items as well.
179 $wgCaptchaRegexes = array();
181 /** Register special page */
182 $wgSpecialPages['Captcha'] = 'CaptchaSpecialPage';
184 $wgConfirmEditIP = dirname( __FILE__ );
185 $wgExtensionMessagesFiles['ConfirmEdit'] = "$wgConfirmEditIP/ConfirmEdit.i18n.php";
186 $wgExtensionAliasesFiles['ConfirmEdit'] = "$wgConfirmEditIP/ConfirmEdit.alias.php";
188 if ( defined( 'MW_SUPPORTS_EDITFILTERMERGED' ) ) {
189 $wgHooks['EditFilterMerged'][] = 'ConfirmEditHooks::confirmEditMerged';
191 $wgHooks['EditFilter'][] = 'ConfirmEditHooks::confirmEdit';
193 $wgHooks['UserCreateForm'][] = 'ConfirmEditHooks::injectUserCreate';
194 $wgHooks['AbortNewAccount'][] = 'ConfirmEditHooks::confirmUserCreate';
195 $wgHooks['LoginAuthenticateAudit'][] = 'ConfirmEditHooks::triggerUserLogin';
196 $wgHooks['UserLoginForm'][] = 'ConfirmEditHooks::injectUserLogin';
197 $wgHooks['AbortLogin'][] = 'ConfirmEditHooks::confirmUserLogin';
198 $wgHooks['EmailUserForm'][] = 'ConfirmEditHooks::injectEmailUser';
199 $wgHooks['EmailUser'][] = 'ConfirmEditHooks::confirmEmailUser';
201 $wgHooks['APIEditBeforeSave'][] = 'ConfirmEditHooks::confirmEditAPI';
203 $wgAutoloadClasses['ConfirmEditHooks']
204 = $wgAutoloadClasses['SimpleCaptcha']
205 = $wgAutoloadClasses['CaptchaSessionStore']
206 = $wgAutoloadClasses['CaptchaCacheStore']
207 = $wgAutoloadClasses['CaptchaSpecialPage']
208 = "$wgConfirmEditIP/ConfirmEdit_body.php";
211 * Set up $wgWhitelistRead
213 function confirmEditSetup() {
214 global $wgGroupPermissions, $wgCaptchaTriggers;
215 if ( !$wgGroupPermissions['*']['read'] && $wgCaptchaTriggers['badlogin'] ) {
216 // We need to ensure that the captcha interface is accessible
217 // so that unauthenticated users can actually get in after a
218 // mistaken password typing.
219 global $wgWhitelistRead;
220 $image = SpecialPage::getTitleFor( 'Captcha', 'image' );
221 $help = SpecialPage::getTitleFor( 'Captcha', 'help' );
222 $wgWhitelistRead[] = $image->getPrefixedText();
223 $wgWhitelistRead[] = $help->getPrefixedText();