Florianschmidtwelzow has uploaded a new change for review.

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

Change subject: Replace the edit preview with a validation of whitelisted ip 
addresses
......................................................................

Replace the edit preview with a validation of whitelisted ip addresses

The user now can press the preview button to bring up an interpreted list
of the lines of the interface message MediaWiki:Captcha-ip-whitelist to check
if the added/remained data is (still) a valid list of (whitelisted) ip 
addresses.

Bug: T129757
Change-Id: Ic61f00e7f88c9290ae6e11f7258c11a730ac98c8
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/ConfirmEditHooks.php
A resources/ext.confirmEdit.editPreview.ipwhitelist.styles.css
5 files changed, 98 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ConfirmEdit 
refs/changes/51/277051/1

diff --git a/extension.json b/extension.json
index 89db1b0..e942950 100644
--- a/extension.json
+++ b/extension.json
@@ -54,6 +54,16 @@
                "CaptchaCacheStore": "includes/CaptchaStore.php",
                "CaptchaSpecialPage": "includes/specials/SpecialCaptcha.php"
        },
+       "ResourceModules": {
+               "ext.confirmEdit.editPreview.ipwhitelist.styles": {
+                       "position": "top",
+                       "styles": 
"ext.confirmEdit.editPreview.ipwhitelist.styles.css"
+               }
+       },
+       "ResourceFileModulePaths": {
+               "localBasePath": "resources",
+               "remoteExtPath": "ConfirmEdit/resources"
+       },
        "Hooks": {
                "EditPageBeforeEditButtons": [
                        "ConfirmEditHooks::confirmEditPage"
@@ -105,6 +115,9 @@
                ],
                "UnitTestsList": [
                        "ConfirmEditHooks::onUnitTestsList"
+               ],
+               "AlternateEditPreview": [
+                       "ConfirmEditHooks::onAlternateEditPreview"
                ]
        },
        "config": {
diff --git a/i18n/en.json b/i18n/en.json
index 84d27ab..9e47864 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -21,5 +21,9 @@
        "captcha-addurl-whitelist": " #<!-- leave this line exactly as it is 
--> <pre>\n# Syntax is as follows:\n#   * Everything from a \"#\" character to 
the end of the line is a comment\n#   * Every non-blank line is a regex 
fragment which will only match hosts inside URLs\n #</pre> <!-- leave this line 
exactly as it is -->",
        "right-skipcaptcha": "Perform CAPTCHA-triggering actions without having 
to go through the CAPTCHA",
        "captcha-apihelp-param-captchaword": "Answer to the CAPTCHA",
-       "captcha-apihelp-param-captchaid": "CAPTCHA ID from previous request"
+       "captcha-apihelp-param-captchaid": "CAPTCHA ID from previous request",
+       "confirmedit-preview-line": "Line",
+       "confirmedit-preview-content": "Content",
+       "confirmedit-preview-validity": "Validity",
+       "confirmedit-preview-description": "In the following table you see a 
list of all lines of the text with the indication if the content of the line is 
a valid IP address or not. If not and you save this page, the line will not be 
used to whitelist a user (so that he doesn't see a CAPTCHA)."
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 1b6c757..07d71c0 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -33,5 +33,8 @@
        "captcha-addurl-whitelist": "See also: [[MediaWiki:Spam-blacklist]] and 
[[MediaWiki:Spam-whitelist]].\n\nLeave all the wiki markup, including the 
spaces, as is.\nYou can translate the text, including 'Leave this line exactly 
as it is'.\nThe first line of this messages has one (1) leading 
space.\n\n\"regex\" stands for \"regular expression\".",
        "right-skipcaptcha": "{{doc-right|skipcaptcha}}",
        "captcha-apihelp-param-captchaword": 
"{{doc-apihelp-param|description=the \"captchaword\" parameter added by 
[[mw:Extension:ConfirmEdit]]|noseealso=1}}\nSee also 
{{msg-mw|captcha-apihelp-param-captchaid}}",
-       "captcha-apihelp-param-captchaid": "{{doc-apihelp-param|description=the 
\"captchaid\" parameter added by 
[[mw:Extension:ConfirmEdit]]|noseealso=1}}\nSee also 
{{msg-mw|captcha-apihelp-param-captchaword}}"
+       "captcha-apihelp-param-captchaid": "{{doc-apihelp-param|description=the 
\"captchaid\" parameter added by 
[[mw:Extension:ConfirmEdit]]|noseealso=1}}\nSee also 
{{msg-mw|captcha-apihelp-param-captchaword}}",
+       "confirmedit-preview-line": "Used as a table heading for the edit 
preview of [[MediaWiki:Captcha-ip-whitelist]] to indicate the line number (L1, 
L2, L3, ...).",
+       "confirmedit-preview-content": "Used as a table heading for the edit 
preview of [[MediaWiki:Captcha-ip-whitelist]] to indicate the content of a 
line.",
+       "confirmedit-preview-validity": "Used as a table heading for the edit 
preview of [[MediaWiki:Captcha-ip-whitelist]] to indicate the validity of a 
content of a line (if it's an IP address or not)."
 }
diff --git a/includes/ConfirmEditHooks.php b/includes/ConfirmEditHooks.php
index 30585ca..182f552 100644
--- a/includes/ConfirmEditHooks.php
+++ b/includes/ConfirmEditHooks.php
@@ -204,4 +204,73 @@
                                htmlentities( recaptcha_get_signup_url( 
$wgServerName, "mediawiki" ) ) . "'>here</a>." );
                }
        }
+
+       /**
+        * AlternateEditPreview hook handler.
+        *
+        * Replaces the preview with a check of all lines for the 
[[MediaWiki:Captcha-ip-whitelist]] interface
+        * message, if it validates as an IP address.
+        *
+        * @param EditPage $editor
+        * @param $content Content
+        * @param String $html
+        * @param ParserOutput $po
+        */
+       public static function onAlternateEditPreview( EditPage $editor, 
&$content, &$html, &$po ) {
+               $title = $editor->getTitle();
+               $ctx = $editor->getArticle()->getContext();
+               $out = $ctx->getOutput();
+
+               if ( $title->getPrefixedText() === 
'MediaWiki:Captcha-ip-whitelist' ) {
+                       $proposedIPAddresses = explode( 
"\n",$content->getNativeData() );
+                       $html .= Html::element(
+                                       'div', 
+                                       array( 'class' => 'warningbox' ),
+                                       $ctx->msg( 
'confirmedit-preview-description' )->text()
+                               ) .
+                               Html::openElement(
+                                       'table',
+                                       array( 'class' => 'wikitable sortable' )
+                               ) .
+                               Html::openElement( 'thead' ) .
+                               Html::element( 'th', array(), $ctx->msg( 
'confirmedit-preview-line' )->text() ) .
+                               Html::element( 'th', array(), $ctx->msg( 
'confirmedit-preview-content' )->text() ) .
+                               Html::element( 'th', array(), $ctx->msg( 
'confirmedit-preview-validity' )->text() ) .
+                               Html::closeElement( 'thead' );
+
+                       foreach ( $proposedIPAddresses as $count => $ip ) {
+                               if ( IP::isIPAddress( $ip ) ) {
+                                       $validity = 'valid';
+                                       $css = 'valid';
+                               } else {
+                                       $validity = 'not valid';
+                                       $css = 'notvalid';
+                               }
+                               $html .= Html::openElement( 'tr' ) .
+                                       Html::element(
+                                               'td',
+                                               array(),
+                                               'L' . $count
+                                       ) .
+                                       Html::element(
+                                               'td',
+                                               array(),
+                                               $ip
+                                       ) .
+                                       Html::rawElement(
+                                               'td',
+                                               // possible values:
+                                               // mw-confirmedit-ip-valid
+                                               // mw-confirmedit-ip-notvalid
+                                               array( 'class' => 
'mw-confirmedit-ip-' . $css ),
+                                               $validity
+                                       ) .
+                                       Html::closeElement( 'tr' );
+                       }
+                       $html .= Html::closeElement( 'table' );
+                       $out->addModuleStyles( 
'ext.confirmEdit.editPreview.ipwhitelist.styles' );
+
+                       return false;
+               }
+       }
 }
diff --git a/resources/ext.confirmEdit.editPreview.ipwhitelist.styles.css 
b/resources/ext.confirmEdit.editPreview.ipwhitelist.styles.css
new file mode 100644
index 0000000..62dd86d
--- /dev/null
+++ b/resources/ext.confirmEdit.editPreview.ipwhitelist.styles.css
@@ -0,0 +1,7 @@
+.mw-confirmedit-ip-notvalid {
+       background-color: rgb(255, 108, 108) !important;
+}
+
+.mw-confirmedit-ip-valid {
+       background-color: lightgreen !important;
+}
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic61f00e7f88c9290ae6e11f7258c11a730ac98c8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ConfirmEdit
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to