mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-11-23 15:56:50 +00:00
Improved the QuestyCaptcha syntax for setting questions and answers
Simple change to one method, QuestyCaptcha::getCaptcha, that allows to set questions and answers like so: $wgCaptchaQuestions = array( 'The capital of England?' => 'London', 'The capital of France?' => 'Paris', 'The capital of Spain?' => 'Madrid', ); Backwards compatibility with the previous syntax has been preserved. Change-Id: Ife16bfb4c63864f8bc9117dad15136288564e2b0
This commit is contained in:
parent
afcbcbb92c
commit
614c626964
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@
|
|||
*.kate-swp
|
||||
.*.swp
|
||||
.idea
|
||||
.DS_Store
|
|
@ -30,7 +30,15 @@ class QuestyCaptcha extends SimpleCaptcha {
|
|||
|
||||
function getCaptcha() {
|
||||
global $wgCaptchaQuestions;
|
||||
return $wgCaptchaQuestions[mt_rand( 0, count( $wgCaptchaQuestions ) - 1 )]; // pick a question, any question
|
||||
|
||||
//Backwards compatibility
|
||||
if ( $wgCaptchaQuestions === array_values( $wgCaptchaQuestions ) ) {
|
||||
return $wgCaptchaQuestions[ mt_rand( 0, count( $wgCaptchaQuestions ) - 1 ) ];
|
||||
}
|
||||
|
||||
$question = array_rand( $wgCaptchaQuestions, 1 );
|
||||
$answer = $wgCaptchaQuestions[ $question ];
|
||||
return array( 'question' => $question, 'answer' => $answer );
|
||||
}
|
||||
|
||||
function getForm() {
|
||||
|
|
|
@ -35,12 +35,14 @@ $wgCaptchaClass = 'QuestyCaptcha';
|
|||
global $wgCaptchaQuestions;
|
||||
$wgCaptchaQuestions = array();
|
||||
|
||||
// Add your questions in LocalSettings.php using this format
|
||||
// $wgCaptchaQuestions[] = array( 'question' => "A question?", 'answer' => "An answer!" );
|
||||
// $wgCaptchaQuestions[] = array( 'question' => 'How much wood would a woodchuck chuck if a woodchuck could chuck wood?', 'answer' => 'as much wood as...' );
|
||||
// $wgCaptchaQuestions[] = array( 'question' => "What is this wiki's name?", 'answer' => "$wgSitename" );
|
||||
// You can also provide several acceptable answers to a given question (the answers shall be in lowercase):
|
||||
// $wgCaptchaQuestions[] = array( 'question' => "2 + 2 ?", 'answer' => array( '4', 'four' ) );
|
||||
/* Add your questions in LocalSettings.php using this format
|
||||
$wgCaptchaQuestions = array(
|
||||
'A question?' => 'An answer!',
|
||||
'What is the capital of France?' => 'Paris', //Answers are normalized to lowercase: Paris and paris are the same
|
||||
'What is this wiki's name?' => $wgSitename,
|
||||
'2 + 2 ?' => array( '4', 'four' ), //Questions may have many answers
|
||||
);
|
||||
*/
|
||||
|
||||
$wgMessagesDirs['QuestyCaptcha'] = __DIR__ . '/i18n/questy';
|
||||
$wgExtensionMessagesFiles['QuestyCaptcha'] = $dir . '/QuestyCaptcha.i18n.php';
|
||||
|
|
Loading…
Reference in a new issue