722a3c7ed5ddb6f7e1fbcd79f72533c90afce9ee
[toast/cookiecaptcha.git] / ConfirmEdit.php
1 <?php
2
3 /**
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.
8  *
9  * Copyright (C) 2005-2007 Brion Vibber <brion@wikimedia.org>
10  * http://www.mediawiki.org/
11  *
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.
16  *
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.
21  *
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
26  *
27  * @addtogroup Extensions
28  */
29
30 if ( !defined( 'MEDIAWIKI' ) ) {
31         exit;
32 }
33
34 global $wgExtensionFunctions, $wgGroupPermissions;
35
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',
43 );
44
45 /**
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.
49  *
50  * By default, sysops and registered bot accounts will be
51  * able to skip, while others have to go through it.
52  */
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
59 /**
60  * List of IP ranges to allow to skip the captcha, similar to the group setting:
61  * "$wgGroupPermission[...]['skipcaptcha'] = true"
62  *
63  * Specific IP addresses or CIDR-style ranges may be used,
64  * for instance:
65  * $wgCaptchaWhitelistIP = array('192.168.1.0/24', '10.1.0.0/16');
66  */
67 $wgCaptchaWhitelistIP = false;
68
69 global $wgCaptcha, $wgCaptchaClass, $wgCaptchaTriggers;
70 $wgCaptcha = null;
71 $wgCaptchaClass = 'SimpleCaptcha';
72
73 /**
74  * Actions which can trigger a captcha
75  *
76  * If the 'edit' trigger is on, *every* edit will trigger the captcha.
77  * This may be useful for protecting against vandalbot attacks.
78  *
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.
83  *
84  * The captcha code should not use $wgCaptchaTriggers, but CaptchaTriggers()
85  * which also takes into account per namespace triggering.
86  */
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
93
94 /**
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).
99  *
100  * Shall not be used with 'createaccount' (it is not checked).
101  */
102 $wgCaptchaTriggersOnNamespace = array();
103
104 #Example:
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.
107
108 /**
109  * Indicate how to store per-session data required to match up the
110  * internal captcha data with the editor.
111  *
112  * 'CaptchaSessionStore' uses PHP's session storage, which is cookie-based
113  * and may fail for anons with cookies disabled.
114  *
115  * 'CaptchaCacheStore' uses $wgMemc, which avoids the cookie dependency
116  * but may be fragile depending on cache configuration.
117  */
118 global $wgCaptchaStorageClass;
119 $wgCaptchaStorageClass = 'CaptchaSessionStore';
120
121 /**
122  * Number of seconds a captcha session should last in the data cache
123  * before expiring when managing through CaptchaCacheStore class.
124  *
125  * Default is a half hour.
126  */
127 global $wgCaptchaSessionExpiration;
128 $wgCaptchaSessionExpiration = 30 * 60;
129
130 /**
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.
133  *
134  * Has no effect if 'badlogin' is disabled in $wgCaptchaTriggers or
135  * if there is not a caching engine enabled.
136  *
137  * Default is five minutes.
138  */
139 global $wgCaptchaBadLoginExpiration;
140 $wgCaptchaBadLoginExpiration = 5 * 60;
141
142 /**
143  * Allow users who have confirmed their e-mail addresses to post
144  * URL links without being harassed by the captcha.
145  */
146 global $ceAllowConfirmedEmail;
147 $ceAllowConfirmedEmail = false;
148
149 /**
150  * Regex to whitelist URLs to known-good sites...
151  * For instance:
152  * $wgCaptchaWhitelist = '#^https?://([a-z0-9-]+\\.)?(wikimedia|wikipedia)\.org/#i';
153  * Local admins can define a whitelist under [[MediaWiki:captcha-addurl-whitelist]]
154  */
155 $wgCaptchaWhitelist = false;
156
157 /**
158  * Additional regexes to check for. Use full regexes; can match things
159  * other than URLs such as junk edits.
160  *
161  * If the new version matches one and the old version doesn't,
162  * toss up the captcha screen.
163  *
164  * @fixme Add a message for local admins to add items as well.
165  */
166 $wgCaptchaRegexes = array();
167
168 /** Register special page */
169 global $wgSpecialPages;
170 $wgSpecialPages['Captcha'] = array( /*class*/'CaptchaSpecialPage', /*name*/'Captcha' );
171
172 $wgConfirmEditIP = dirname( __FILE__ );
173 $wgExtensionMessagesFiles['ConfirmEdit'] = "$wgConfirmEditIP/ConfirmEdit.i18n.php";
174
175 if ( defined( 'MW_SUPPORTS_EDITFILTERMERGED' ) ) {
176         $wgHooks['EditFilterMerged'][] = 'ConfirmEditHooks::confirmEditMerged';
177 } else {
178         $wgHooks['EditFilter'][] = 'ConfirmEditHooks::confirmEdit';
179 }
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';
185
186 $wgAutoloadClasses['ConfirmEditHooks'] 
187         = $wgAutoloadClasses['SimpleCaptcha'] 
188         = $wgAutoloadClasses['CaptchaSessionStore']
189         = $wgAutoloadClasses['CaptchaCacheStore']
190         = $wgAutoloadClasses['CaptchaSpecialPage']
191         = "$wgConfirmEditIP/ConfirmEdit_body.php";
192
193 /**
194  * Set up $wgWhitelistRead
195  */
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();
207         }
208 }
209
210