Jump to content

Extension:ConfirmEdit

本頁使用了標題或全文手工轉換
From mediawiki.org
This page is a translated version of the page Extension:ConfirmEdit and the translation is 59% complete.
MediaWiki扩展手册
ConfirmEdit
发行状态: 稳定版
实现 页面操作
描述 为页面保存和其他用户操作添加验证码
作者
  • Brooke Vibber
  • Florian Schmidt
  • Sam Reed
最新版本 1.6.0 (持續更新)
兼容性政策 快照跟随MediaWiki发布。 master分支不向后兼容。
  • $wgCaptchaBadLoginPerUserAttempts
  • $wgConfirmEditLoadedCaptchas
  • $wgCaptchaRegexes
  • $wgCaptchaBypassIPs
  • $wgHCaptchaDeveloperMode
  • $wgHCaptchaUseRiskScore
  • $wgHCaptchaProxy
  • $wgHCaptchaSiteKey
  • $wgCaptchaTriggersOnNamespace
  • $wgHCaptchaApiUrlIntegrityHash
  • $wgHCaptchaVerifyUrl
  • $wgHCaptchaEnterpriseHealthCheckApiUrlRetryCount
  • $wgHCaptchaApiUrl
  • $wgCaptchaBadLoginAttempts
  • $wgHCaptchaEnabledInMobileFrontend
  • $wgCaptchaStorageClass
  • $wgCaptchaSessionExpiration
  • $wgHCaptchaEnterpriseHealthCheckSiteVerifyErrorThreshold
  • $wgHCaptchaSecureEnclave
  • $wgHCaptchaSendRemoteIP
  • $wgCaptchaTriggers
  • $wgHCaptchaInvisibleMode
  • $wgHCaptchaEnterpriseHealthCheckApiUrlErrorThreshold
  • $wgConfirmEditEnabledAbuseFilterCustomActions
  • $wgCaptchaBadLoginPerUserExpiration
  • $wgCaptchaAbuseFilterCaptchaConsequenceTTL
  • $wgHCaptchaEnterpriseHealthCheckApiUrlRetryDelayMs
  • $wgCaptchaBadLoginExpiration
  • $wgHCaptchaSecretKey
  • $wgCaptchaClass
  • $wgHCaptchaEnterpriseHealthCheckFailoverDuration
  • $wgHCaptchaEnterprise
  • $wgHCaptchaCSPRules
  • $wgHCaptchaVisualEditorOnLoadIntegrationEnabled
  • $wgCaptchaIgnoredUrls
  • skipcaptcha
许可证 GNU General Public License 2.0 or later
下載
前往translatewiki.net翻譯ConfirmEdit扩展
Vagrant角色 confirmedit
問題 开启的任务 · 报告错误

通过ConfirmEdit扩展,您可以使用各种的验证码技术,尝试去阻止那些垃圾訊息機器人和其他自动化工具去编辑您的wiki,以及去挫败那些试图猜测密码的自动登录。

ConfirmEdit配备了多种生成验证码的技术/模块。

模块 描述 阻止垃圾邮件的效果
SimpleCaptcha 用户必须解决一道简单的数学题。
FancyCaptcha 用户必须识别以风格化方式显示的一系列字符。
QuestyCaptcha 用户必须从管理员定义的一系列问题中回答一个问题。 非常高,直至被破解
ReCaptchaNoCaptcha 用户将看到一个基于JavaScript的人性检查。如果检查失败,就会出现一个谜题。 中-低
hCaptcha 与reCAPTCHA类似,但可以说比reCAPTCHA更有效,因为它采用其不一樣的可訪問性友善的验证码方法
Turnstile Cloudflare公司的一款取代CAPTCHA的驗證工具Turnstile。 人类无操作(或点击方框)的机器人检测器。 基於工作量證明的機制。 非常高

其中一些模块需要额外的设置工作:

  • FancyCaptcha需要在Python中运行一个初步设置脚本。

弊端

验证码降低了網站的可访问性并给真人用户带来不便。

它们并非百分之百有效对抗机器人程序,且无法保护您的维基免受那些愿意且能够通过人工方式绕过验证码的垃圾信息发送者的侵扰。 您可以将ConfirmEdit与其他反垃圾功能结合使用。 无论采用何种解决方案,只要您使用的是公开可编辑的维基,就必须持续关注“最近更改”页面。

安裝

此扩展随附于MediaWiki 1.18及更新版本,因此您無需下載它。 但其余的配置的指示仍须依循執行。
若使用的MediaWiki版本与通过“扩展分发器”下载时指定的版本不同,ConfirmEdit可能无法正常工作。
  • 下载文件,并解压ConfirmEdit文件夹到extensions/目录中。
    开发者和代码贡献人员应改从Git安装此扩展,输入:
    cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
    
  • 請新增下列代码到您的LocalSettings.php 文件的底部:
    wfLoadExtension( 'ConfirmEdit' );
    
  • 明确启用应使用的验证码类型(设置$wgCaptchaClass
  • 按需求配置
  • Yes 完成 – 請导航至您的wiki上的Special:Version,以验证此扩展已成功安装。


使用Vagrant安装:

  • 如果你有使用Vagrant ,请通过vagrant roles enable confirmedit --provision安装

验证码类型

ConfirmEdit 包含多种不同类型的验证码。请注意,MathCaptcha 已于 2024 年移除(变更 1015991)。

QuestyCaptcha

本模块提出问题、用户提供答案。 您在配置中提供各個问题。 该模块已被证实能有效抵御垃圾机器人;同时,它还具有提升可访问性的优势——文本形式的问题可通过语音软件朗读,使视障用户(非机器人)能够正确作答。

請将以下内容添加到LocalSettings.php以启用此验证码,以编辑问答环节:

wfLoadExtensions([ 'ConfirmEdit', 'ConfirmEdit/QuestyCaptcha' ]);
$wgCaptchaClass = 'QuestyCaptcha';

// 請使用此格式在LocalSettings.php中加入您的問題:
$wgCaptchaQuestions = [
	'What is the capital of France?' => 'Paris',
	'What is the capital of Spain' => 'MADRID', // 答案不區分大小寫
	'What is the name of this wiki?' => $wgSitename, // 您可以使用變數
	'How many fingers does a hand have?' => [ 5, 'five' ], // 一個問題可能有多種答案
];

它將從提供的問題中隨機選擇一個。

最低限度是一個。

  • QuestyCaptcha不區分大小寫。 若答案為「Paris」而使用者輸入「paris」,或答案為「paris」而使用者輸入「Paris」,它會正常動作。
  • 若答案中包含某個像是「ó」的特殊字元,您可分別撰寫兩個答案:一個是包含「ó」,另一個則替換為「o」(即「o」取代「ó」),以防萬一。 例如,若答案為「canción」,則可使用 [ 'cancion', 'canción' ] 以防使用者輸入「cancion」。
  • 這個答案對於那些感興趣的人類使用者而言,必須易於猜出;但對於自動程式而言則不然。 理想情況下,答案不應包含在問題的文字內容中;您可以嘗試編輯驗證碼說明訊息,並在該處提供驗證碼的解決方案。[1]
  • 當問題開始被證實是無效時,請馬上改變問題;若您的維基並沒有被特別盯上,這種情況可能永遠不會發生。
  • 切勿重複使用你或他人過去曾使用過的問題:眾所周知,垃圾訊息機器人一旦破解了某個問題及其答案,它們便會永遠記住這個問題與答案。
  • 您甚至可以動態生成questy captchas,其是在組態中的。 『切勿』直接複製連結中的動態問題。垃圾郵件發送者已破解這些問題。 然而,其他的動態問題在呈現方式上同樣極具成效。
  • ConfirmEdit 擁有一個獨立的擴充功能 QuestyCaptchaEditor,該功能提供維基內建的特殊頁面,用於管理 QuestyCaptcha 的問題與答案配對組合。 若您希望減少系統管理員在管理驗證碼問題及其答案時所需的介入,建議您考慮安裝此套件。

ReCaptcha (NoCaptcha)

警告 警告: ReCaptcha已被多數針對維基網站的垃圾郵件機器人破解,主要原因在於其可供存取的驗證碼替代方案。

新一代名為「NoCaptcha」的ReCaptcha系統由Google於2014年12月推出,大幅減少人類解決驗證碼的需求。[2] 基於用戶端的 JavaScript(此程式碼無法由用戶或管理員「控制」),reCaptcha透過分析用戶在頁面上的瀏覽行為,試圖判斷該網站使用者是否為真人。 用戶接著必須點擊「我不是機器人」的核取方塊,而在最佳情況下,無需再執行任何操作即可證明自己是真人。 在一些情況下,使用者仍需要去解開某個驗證碼圖片。

ReCaptcha無法與手持的來源編輯器及部份的擴充功能配合使用。

此模組在 ConfirmEdit 中實作了新的 ReCaptcha NoCaptcha 解決方案。

您仍需準備一組公鑰與私鑰(可從ReCaptcha管理面板取得——請改用v2版本,v3是無法運作的),並透過以下指令安裝外掛程式:

wfLoadExtensions([ 'ConfirmEdit', 'ConfirmEdit/ReCaptchaNoCaptcha' ]);
$wgCaptchaClass = 'ReCaptchaNoCaptcha';
$wgReCaptchaSiteKey = '您的公開金鑰/網站金鑰在此';
$wgReCaptchaSecretKey = '您的私鑰在此';

此模組提供額外的組態選項 $wgReCaptchaSendRemoteIP(預設值:false),若將其設為 true,則在驗證 CAPTCHA 時會將當前使用者的 IP 位址傳送至 Google 伺服器。 若將此設定維持為 false,您便能為使用者提升隱私保護。 『可是』,請注意此模組會新增一段客戶端 JavaScript 程式碼,該程式碼直接從 Google 伺服器載入,其本身即可收集用戶的 IP 位址(亦可能與其他資料結合),且此行為『無法』透過組態選項加以限制。 此功能僅適用於標準 MediaWiki 編輯器。

reCAPTCHA v3

目前尚無官方途徑可實作 Google reCAPTCHA 第 3 版。

簡易驗證碼(計算題)

警告 警告: 此類型極少被維基採用,甚至可能根本無人使用,原因很可能是其效果甚微。
一道簡單的數學題

這是預設的驗證碼。

此模組為使用者提供簡單的加減法題目。

請在 MediaWiki 根目錄的 LocalSettings.php 檔案中加入以下行以啟用此驗證碼:

wfLoadExtension( 'ConfirmEdit' );
$wgCaptchaClass = 'SimpleCaptcha';

请注意,像这样把简单数学问题显示成明文将可以通过自动化程序轻松解决;截至2012年,使用SimpleCaptcha的网站正在收到大量垃圾邮件和许多虚假帐户的自动注册。因此,当前使用此作为默认设置的Wiki应使用其他验证码。 目前將此設為預設選項的維基網站,應遷移至其他驗證碼方案之一。

FancyCaptcha

警告 警告: 此類格式在維基媒體基金會以外的維基網站中極少使用(若有亦寥寥可數),原因很可能是其效果有限。

此模組顯示一組字符的風格化圖像。

初始建立圖像集時必須安裝 Pillow,但後續不再需要(多數環境下可透過 pip install Pillow 安裝)。

  1. 請將以下內容新增至 MediaWiki 安裝根目錄下的 LocalSettings.php 檔案中:
    wfLoadExtensions([ 'ConfirmEdit', 'ConfirmEdit/FancyCaptcha' ]);
    $wgCaptchaClass = 'FancyCaptcha';
  2. LocalSettings.php 中,設定變數 $wgCaptchaDirectory 為儲存驗證碼圖片的目錄。『注意:』請使用絕對目錄路徑、或相對於您的維基安裝目錄的相對路徑。 下方將您的通行密碼設定為 $wgCaptchaSecret
  3. 執行以下指令以建立圖像:
    python /path/to/captcha.py --font=<font> --wordlist=<wordlist> --key=<key> --output=<output> --count=<count>
    • 其中 font 是某種字體的路徑,例如 AriBlk.TTF。
    • wordlist 是通往某個詞彙列表的路徑,例如 /usr/share/dict/words。 (註:在 Debian/Ubuntu 系統上,'wbritish' 和 'wamerican' 套件有提供這樣的清單。 在 Fedora 上,請使用 'words' 套件)
    • key 即是您設定為 $wgCaptchaSecret 的精確密碼短語。 必要時請使用引號。
    • output 是圖片應儲存的路徑(定義於 $wgCaptchaDirectory)。
    • count 代表要生成多少張圖片。
    • 舉例來說,假設您位於 extensions/ConfirmEdit 目錄(此為 Ubuntu 6.06 的字型位置,其他作業系統可能不同):
    python captcha.py --font=/usr/share/fonts/truetype/freefont/FreeSans.ttf --wordlist=/usr/share/dict/words --key=FOO --output=../../../captcha --count=100
    • 若您對生成的文字結果不滿意,可移除圖片並建立一組新的。 Comic_Sans_MS_Bold.ttf 似乎能產生相對清晰可辨的文字,您亦可編輯 captcha.py 的最後一行,將預設的 40 點字型大小調高。
  4. 將取得的圖片存放至安裝目錄下的 captcha 目錄中。
  5. 編輯您的維基 LocalSettings.php :請在 $wgCaptchaDirectory 中指定驗證碼目錄的完整路徑,並在 $wgCaptchaSecret 中填入生成驗證碼時使用的私密金鑰。
$wgCaptchaDirectory = "/.php-data/my-wiki.org/wiki/captcha";
$wgCaptchaDirectoryLevels = 0; // 將此值設定為大於零,即可將圖片分割至子目錄中
$wgCaptchaSecret = "FOO"; // 與您在 captcha.py 中使用的 --key 選項相同值

另請參閱 wikitech:Generating CAPTCHAs 以了解維基媒體基金會的操作方式。

How to avoid common problems running Python on Windows
  1. Install the most recent version of Pillow.
  2. Make the installation of Python on a short folder name, like C:\Python\
  3. Create a folder like C:\Ex and place files CAPTCHA.py / FONT.ttf / LIST.txt into the folder.
  4. To execute easily, run the following example as a batch file:
C:\python\python.exe C:\Ex\CAPTCHA.py --font C:\Ex\FONT.ttf --wordlist C:\Ex\LIST.txt --key=YOURPASSWORD --output C:\Ex\ --count=20

hCaptcha

MediaWiki版本:
1.35

The configuration is similar to ReCaptcha:

wfLoadExtensions([ 'ConfirmEdit', 'ConfirmEdit/hCaptcha' ]);
$wgCaptchaClass = MediaWiki\Extension\ConfirmEdit\hCaptcha\HCaptcha::class;

$wgHCaptchaSiteKey = 'your public/site key here';
$wgHCaptchaSecretKey = 'your private key here';

Other configuration is available, depending on requirements of the setup of the wiki.

Configuration

hCaptcha brings in various configuration variables, some of which are considered enterprise features.

You will be required to create an account with hCaptcha to use this extension.

Configuration Flag Default Value Description
$wgHCaptchaProxy false Proxy to use for outbound PHP web requests to hCaptcha servers (HCaptchaVerifyUrl)
$wgHCaptchaSiteKey "" Sitekey from hCaptcha (requires creating an account)
$wgHCaptchaSecretKey "" Secret key from hCaptcha (requires creating an account)
$wgHCaptchaSendRemoteIP false Whether to send the client's IP address to hCaptcha
$wgHCaptchaApiUrl "https://js.hcaptcha.com/1/api.js" Url that the hCaptcha JS is loaded from; may want to use https://cn1.hcaptcha.com/1/api.js?endpoint=https://cn1.hcaptcha.com&assethost=https://assets-cn1.hcaptcha.com&imghost=https://imgs-cn1.hcaptcha.com&reportapi=https://reportapi-cn1.hcaptcha.com for Chinese visitors
$wgHCaptchaVerifyUrl "https://api.hcaptcha.com/siteverify" Url that the hCaptcha requested is verified against; may want to use https://cn1.hcaptcha.com/siteverify if server is in China
$wgHCaptchaEnterprise false Whether the provided sitekey is for hCaptcha Enterprise features. See https://www.hcaptcha.com/#enterprise-features
$wgHCaptchaInvisibleMode false Enable this to make the hCaptcha checkbox invisible and only show a challenge if hCaptcha determines it is needed. This forces the inclusion of a message with the hCaptcha Privacy Policy and Terms of Service
$wgHCaptchaCSPRules [ "https://hcaptcha.com", "https://*.hcaptcha.com" ] Urls to add to the Content Security Policies (CSP) for hcaptcha.com and *.hcaptcha.com to a page when loading a hCaptcha
$wgHCaptchaSecureEnclave false Whether to use hCaptcha's Secure Enclave mode. If enabled, then $wgHCaptchaEnterprise must be true (because it is an Enterprise feature). You will need to modify $wgHCaptchaApiUrl as appropriate, such as to use https://js.hcaptcha.com/1/secure-api.js and make rendering explicitSee https://docs.hcaptcha.com/enterprise/secure_enclave
$wgHCaptchaDeveloperMode false Whether to place hCaptcha integration in developer mode. When in developer mode, potentially sensitive information is logged to debug logs. Do not enable on production wikis.
$wgHCaptchaUseRiskScore false Whether to use captcha risk signal. Unless specifically enabled or in developer mode, we do not want that sensitive information to be stored.

Turnstile

MediaWiki版本:
1.42

The configuration is similar to #ReCaptcha or #hCaptcha:

wfLoadExtensions([ 'ConfirmEdit', 'ConfirmEdit/Turnstile' ]);
$wgCaptchaClass = MediaWiki\Extension\ConfirmEdit\Turnstile\Turnstile::class;

$wgTurnstileSiteKey= 'your public/site key here';
$wgTurnstileSecretKey= 'your private key here';

$wgTurnstileSendRemoteIP is also available.

配置

Integration with Extension:AbuseFilter

If ConfirmEdit and Extension:AbuseFilter(滥用过滤器) are installed, then an AbuseFilter can be configured to show a CAPTCHA as a consequence for matching against a filter. It is recommended to load the ConfirmEdit extension before the AbuseFilter extension to ensure that this consequence functions correctly.

Don't require CAPTCHA from some users

ConfirmEdit introduces a 'skipcaptcha' permission type to wgGroupPermissions . This lets you set certain groups never to see CAPTCHAs. All of the following can be added to LocalSettings.php.

Defaults from ConfirmEdit.php:

$wgGroupPermissions['*']['skipcaptcha'] = false;
$wgGroupPermissions['user']['skipcaptcha'] = false;
$wgGroupPermissions['autoconfirmed']['skipcaptcha'] = false;
$wgGroupPermissions['bot']['skipcaptcha'] = true; // registered bots
$wgGroupPermissions['sysop']['skipcaptcha'] = true;

To skip captchas for users who confirmed their email, you need to set both:

$wgGroupPermissions['emailconfirmed']['skipcaptcha'] = true;
$wgAllowConfirmedEmail = true;

Set actions that require CAPTCHA

The following conditions can trigger a CAPTCHA to be displayed:

  • 'edit' – triggered on every attempted page save
  • 'create' – triggered on page creation
  • 'sendemail' – triggered when using Special:Emailuser
  • 'addurl' – triggered on a page save that would add one or more URLs to the page
  • 'createaccount' – triggered on creation of a new account
  • 'badlogin' – triggered after several failed login attempts from the same IP address
  • 'badloginperuser' – triggered after several failed login attempts using the same username

The default values for these are:

$wgCaptchaTriggers['edit'] = false;
$wgCaptchaTriggers['create'] = false;
$wgCaptchaTriggers['sendemail'] = false;
$wgCaptchaTriggers['addurl'] = true;
$wgCaptchaTriggers['createaccount'] = true;
$wgCaptchaTriggers['badlogin'] = true;
$wgCaptchaTriggers['badloginperuser'] = true;

The triggers edit, create and addurl can be configured per namespace using the $wgCaptchaTriggersOnNamespace setting. If there is no $wgCaptchaTriggersOnNamespace for the current namespace, the normal $wgCaptchaTriggers apply. So suppose that in addition to the above $wgCaptchaTriggers defaults we configure the following:

$wgCaptchaTriggersOnNamespace[NS_TALK]['addurl'] = false;
$wgCaptchaTriggersOnNamespace[NS_PROJECT]['edit'] = true;

Then the CAPTCHA will not trigger when adding URLs to a talk page, but on the other hand user will need to solve a CAPTCHA any time they try to edit a page in the project namespace, even if they aren't adding a link.

URL和IP允許清單

可以定義一個已知安全網站的允許清單,當這些網站的'addurl'動作被觸發時,驗證碼機制不應該作動。

具有系統管理員的使用者們可編輯名為 MediaWiki:Captcha-addurl-whitelist 的系統訊息頁面。

預期格式是一組正規表達式,每行一個。

可在評論前添加 # 前置詞。

您可以在開放街道地圖看到此用法範例。

這組正規表達式亦可透過在 LocalSettings.php 中使用環境變數$wgCaptchaIgnoredUrls來定義,以保持值的機密性。

您還可以加入其他變量到LocalSettings.php之中:

  • $wgCaptchaBypassIPs – List of IP ranges to allow to skip the CAPTCHA (you can also use MediaWiki:Captcha-ip-whitelist; see below for details).
  • $wgAllowConfirmedEmail – Allow users who have confirmed their e-mail addresses to post URL links.

These are described more thoroughly in the code comments

MediaWiki:Captcha-ip-whitelist can change the allowed IP addresses and IP ranges on the wiki.

They should be separated by newlines.

If any other character (apart from a valid IP address or range) is found on a line, it will be ignored, but leading and trailing whitespace characters are allowed.

For example, a line with only 127.0.0.1 is considered valid but #127.0.0.1 will be ignored.

正则表达式

The global variable wgCaptchaRegexes accepts an array of regexes to be tested against the page text and triggers the CAPTCHA if a match is found.

Failed login attempts

When using the badlogin or badloginperuser triggers, the following configuration variables control how many failed login attempts per-IP and per-user are allowed before a CAPTCHA is required, and how long it takes until the CAPTCHA requirement expires:

$wgCaptchaBadLoginAttempts = 3;
$wgCaptchaBadLoginExpiration = 300; // 300 seconds = 5 minutes
$wgCaptchaBadLoginPerUserAttempts = 20;
$wgCaptchaBadLoginPerUserExpiration = 600; // 600 seconds = 10 minutes

The triggers require $wgMainCacheType to be set to something other than CACHE_NONE in your LocalSettings.php, if in doubt the following will always work.

$wgMainCacheType = CACHE_ANYTHING;

Note that these triggers do not trigger CAPTCHAs on API login but block them outright until the CAPTCHA requirement expires.

Wikimedia configuration

For example, Wikimedia Foundation wikis use FancyCaptcha with a custom set of images and the default configuration, modified by what follows.

$wgGroupPermissions['autoconfirmed']['skipcaptcha'] = true;

This means only unregistered and newly registered users have to pass the CAPTCHA.

EmergencyCaptcha mode

Additionally, the shortcut named $wmgEmergencyCaptcha is designed for use in a limited number of emergencies, for instance, in case of massive vandalism or spam attacks: it changes the default trigger values (see above) into the following:

$wgCaptchaTriggers['edit'] = true; 
$wgCaptchaTriggers['create'] = true;

So, in addition to the normal situation, all anonymous and new users have to solve a CAPTCHA before being able to save an edit or create a new page.

速率限制

ConfirmEdit supports rate limiting for false CAPTCHA.

For more information about $wgRateLimits and how to set it up, read Manual:$wgRateLimits , the action key is badcaptcha.

作者

The basic framework was primarily designed by Brooke Vibber, who also wrote the SimpleCaptcha and FancyCaptcha modules.

The QuestyCaptcha module was written by Benjamin Lees.

Additional maintenance work was done by Yaron Koren.

参见

参考资料

  1. MediaWiki:Questycaptchahelp-text, MediaWiki:Questycaptcha-edit, MediaWiki:Questycaptcha-addurl, MediaWiki:Questycaptcha-create, MediaWiki:Questycaptcha-createaccount
  2. Google Blog Are you a robot? Introducing “No CAPTCHA reCAPTCHA” ()