UltrasonicNXT has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/185633

Change subject: Add CAPTCHAs
......................................................................

Add CAPTCHAs

Also some other cleanup. Before https://gerrit.wikimedia.org/r/#/c/185544/,
is merged, WikiForum will have to be required after ConfirmEdit in localsettings

Change-Id: Iccf2bd9930ebf6460a5c9e73c7c5866324d1b3c4
---
M Reply.php
M Thread.php
M WikiForum.php
M WikiForumClass.php
M WikiForumGui.php
M i18n/en.json
M i18n/qqq.json
7 files changed, 81 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikiForum 
refs/changes/33/185633/1

diff --git a/Reply.php b/Reply.php
index 43b9bfe..c86ba1e 100644
--- a/Reply.php
+++ b/Reply.php
@@ -341,6 +341,17 @@
                        return WikiForumClass::showErrorMessage( 
'wikiforum-error-add', 'wikiforum-error-thread-closed' );
                }
 
+               if ( WikiForumClass::useCaptcha() ) {
+                       $captcha = ConfirmEditHooks::getInstance();
+                       $captcha->trigger = 'wikiforum'; // doesn't make sense, 
but otherwise we get errors
+                       if ( !ConfirmEditHooks::getInstance()->passCaptcha() ) {
+                               $output = 
WikiForumClass::showErrorMessage('wikiforum-error-add', 
'wikiforum-error-captcha');
+                               $thread->preloadText = $text;
+                               $output .= $thread->show();
+                               return $output;
+                       }
+               }
+
                $dbr = wfGetDB( DB_SLAVE );
                $doublepost = $dbr->selectRow(
                        'wikiforum_replies',
diff --git a/Thread.php b/Thread.php
index 4f1bf83..18c20f3 100644
--- a/Thread.php
+++ b/Thread.php
@@ -5,6 +5,7 @@
        private $data;
        public $forum;
        private $replies;
+       public $preloadText;
 
        private function __construct( $sql ) {
                $this->data = $sql;
@@ -322,7 +323,7 @@
                }
 
                $dbw = wfGetDB( DB_MASTER );
-               $result = $dbw->delete(
+               $dbw->delete(
                        'wikiforum_threads',
                        array( 'wft_thread' => $this->getId() ),
                        __METHOD__
@@ -342,8 +343,7 @@
                        __METHOD__,
                        array( 'LIMIT' => 1 )
                );
-               // Update the forum table so that the data shown on
-               // Special:WikiForum is up to date
+               // Update the forum table so that the data shown on 
Special:WikiForum is up to date
                $dbw->update(
                        'wikiforum_forums',
                        array(
@@ -798,6 +798,24 @@
                        return WikiForumClass::showErrorMessage( 
'wikiforum-error-add', 'wikiforum-error-no-rights' );
                }
 
+               if ( WikiForumClass::useCaptcha() ) {
+                       $captcha = ConfirmEditHooks::getInstance();
+                       $captcha->trigger = 'wikiforum'; // doesn't make sense, 
but otherwise we get errors
+                       if ( !ConfirmEditHooks::getInstance()->passCaptcha() ) {
+                               $output = 
WikiForumClass::showErrorMessage('wikiforum-error-add', 
'wikiforum-error-captcha');
+                               $output .= WFThread::showGeneralEditor(
+                                       $title,
+                                       '',
+                                       $text,
+                                       array(
+                                               'wfaction' => 'savenewthread',
+                                               'forum' => $forum->getId()
+                                       )
+                               );
+                               return $output;
+                       }
+               }
+
                $dbw = wfGetDB( DB_MASTER );
                $timestamp = wfTimestampNow();
 
@@ -961,6 +979,8 @@
                } elseif ( $quoteThread ) {
                        $posted = $this->showPlainPostedInfo();
                        $textValue = '[quote=' . $posted . ']' . 
$this->getText() . '[/quote]';
+               } elseif ( $this->preloadText ) {
+                       $textValue = $this->preloadText;
                }
 
                return WFReply::showGeneralEditor(
diff --git a/WikiForum.php b/WikiForum.php
index 5917f4d..784a3aa 100644
--- a/WikiForum.php
+++ b/WikiForum.php
@@ -35,7 +35,7 @@
        'path' => __FILE__,
        'name' => 'WikiForum',
        'author' => array( 'Michael Chlebek', 'Jack Phoenix', 'Adam Carter 
(UltrasonicNXT)' ),
-       'version' => '2.0.7',
+       'version' => '2.1.0',
        'url' => 'https://www.mediawiki.org/wiki/Extension:WikiForum',
        'descriptionmsg' => 'wikiforum-desc'
 );
@@ -104,3 +104,6 @@
 $wgAutoloadClasses['WikiForumLogFormatter'] = $dir . 
'WikiForumLogFormatter.php';
 $wgLogTypes[] = 'forum';
 $wgLogActionsHandlers['forum/*'] = 'WikiForumLogFormatter';
+
+// ConfirmEdit/CAPTCHAs
+$wgCaptchaTriggers['wikiforum'] = true; // CAPTCHA on by default
\ No newline at end of file
diff --git a/WikiForumClass.php b/WikiForumClass.php
index 9b3acdb..695a1cf 100644
--- a/WikiForumClass.php
+++ b/WikiForumClass.php
@@ -172,7 +172,7 @@
                                        User::makeGroupLinkHTML( 'sysop', 
User::getGroupMember( 'sysop', $username ) )
                                )->text();
 
-               } elseif ( in_array( 'forumadmin', $groups ) && !$isStaff ) {
+               } elseif ( in_array( 'forumadmin', $groups ) ) {
                        $groupText .= wfMessage( 'word-separator' )->plain() .
                                wfMessage(
                                        'parentheses',
@@ -332,4 +332,33 @@
                return $text;
        }
 
+       /**
+        * Should we require the user to pass a captcha?
+        *
+        * @return bool
+        */
+       public static function useCaptcha() {
+               global $wgCaptchaClass, $wgCaptchaTriggers, $wgUser;
+               return $wgCaptchaClass &&
+                       isset( $wgCaptchaTriggers['wikiforum'] ) &&
+                       $wgCaptchaTriggers['wikiforum'] &&
+                       !$wgUser->isAllowed( 'skipcaptcha' );
+       }
+
+       /**
+        * Return the HTML for the captcha
+        *
+        * @return string
+        */
+       public static function getCaptcha() {
+               wfSetupSession(); // NOTE: make sure we have a session. May be 
required for CAPTCHAs to work.
+               $output = wfMessage( "captcha-sendemail" )->parseAsBlock();
+
+               $captcha = ConfirmEditHooks::getInstance();
+               $captcha->trigger = 'wikiforum';
+               $captcha->action = 'post';
+               $output .= $captcha->getForm();
+
+               return $output;
+       }
 }
\ No newline at end of file
diff --git a/WikiForumGui.php b/WikiForumGui.php
index 6c01732..23056dc 100644
--- a/WikiForumGui.php
+++ b/WikiForumGui.php
@@ -75,7 +75,7 @@
         * @param $maxissues Integer: amount of replies, fetched from the DB
         * @param $limit Integer: limit; this is also used for the SQL query
         * @param $params array: URL params to be passed, should have a thread 
or forum number
-        * @return HTML
+        * @return string HTML
         */
        static function showFooterRow( $page, $maxissues, $limit, $params ) {
                $output = '';
@@ -242,8 +242,11 @@
                                </tr>
                                <tr>
                                        <td><textarea name="text" 
id="wpTextbox1" style="height: ' . $height . ';">' . $text_prev . 
'</textarea></td>
-                               </tr>
-                               <tr>
+                               </tr>';
+                       if ( WikiForumClass::useCaptcha() ) {
+                               $output .= '<tr><td>' . 
WikiForumClass::getCaptcha() . '</td></tr>';
+                       }
+                       $output .= '<tr>
                                        <td>
                                                <input type="submit" value="' . 
$saveButton . '" accesskey="s" title="' . $saveButton . ' [s]" />';
                        if ( $showCancel ) {
diff --git a/i18n/en.json b/i18n/en.json
index 638df35..e978ef9 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -122,5 +122,8 @@
 
     "wikiforum-forum-preload": "Title of your forum",
     "wikiforum-category-preload": "Title of your category",
-    "wikiforum-must-supply-thread": "You must supply a thread ID."
+    "wikiforum-must-supply-thread": "You must supply a thread ID.",
+
+    "wikiforum-captcha": "To protect the wiki against automated spamming, we 
kindly ask you to solve the simple question below and enter the answer in the 
box ([[Special:Captcha/help|more info]]):",
+    "wikiforum-error-captcha": "Error - incorrect or missing CAPTCHA"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 2c612d4..8e3653d 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -115,5 +115,7 @@
        "logentry-forum-add-thread": "Shown when the user $1 created a new 
thread, $4.\n\n{{logentry}}\nAdditional parameters:\n* $4 - thread 
title\n{{Related|Logentry-forum}}",
        "logentry-forum-add-reply": "Shown when the user $1 replied on the 
thread $4.\n\n{{logentry}}\nAdditional parameters:\n* $4 - thread 
title\n{{Related|Logentry-forum}}",
        "wikiforum-forum-preload": "Used as placeholder for title.\n\nSee 
also:\n* {{msg-mw|Wikiforum-category-preload}}",
-       "wikiforum-category-preload": "Used as placeholder for title.\n\nSee 
also:\n* {{msg-mw|Wikiforum-forum-preload}}"
+       "wikiforum-category-preload": "Used as placeholder for title.\n\nSee 
also:\n* {{msg-mw|Wikiforum-forum-preload}}",
+       "wikiforum-captcha": "Label for the CAPTCHA",
+       "wikiforum-error-captcha": "Error message shown when the CAPTCHA is 
failed."
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/185633
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iccf2bd9930ebf6460a5c9e73c7c5866324d1b3c4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikiForum
Gerrit-Branch: master
Gerrit-Owner: UltrasonicNXT <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to