Gerrit Patch Uploader has uploaded a new change for review.

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

Change subject: Preferences: Add autocomplete="off" to preferences form
......................................................................

Preferences: Add autocomplete="off" to preferences form

This change adds a new method setAutocomplete to the class HTMLForm.
This method allows to set the HTML attribute autocomplete for the form.
This change uses this method to set autocomplete="off" for the preferences form.

Without autocomplete="off" the selections in the preferences get cached in
the browser. This can lead to wrong selected options when the settings get
changed on an other way, for example via API.

Bug: T131047
Change-Id: I2920383b5b8cfca3f1d546315f202985edf417d8
---
M includes/Preferences.php
M includes/htmlform/HTMLForm.php
2 files changed, 27 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/54/280154/1

diff --git a/includes/Preferences.php b/includes/Preferences.php
index 54176a6..66a8152 100644
--- a/includes/Preferences.php
+++ b/includes/Preferences.php
@@ -1301,6 +1301,7 @@
 
                $htmlForm->setModifiedUser( $user );
                $htmlForm->setId( 'mw-prefs-form' );
+               $htmlForm->setAutocomplete( 'off' );
                $htmlForm->setSubmitText( $context->msg( 'saveprefs' )->text() 
);
                # Used message keys: 'accesskey-preferences-save', 
'tooltip-preferences-save'
                $htmlForm->setSubmitTooltip( 'preferences-save' );
diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php
index ba43244..bf46e55 100644
--- a/includes/htmlform/HTMLForm.php
+++ b/includes/htmlform/HTMLForm.php
@@ -198,6 +198,13 @@
         */
        protected $mAction = false;
 
+       /**
+        * Form attribute autocomplete. false does not set the attribute
+        * @since 1.27
+        * @var bool|string
+        */
+       protected $mAutocomplete = false;
+
        protected $mUseMultipart = false;
        protected $mHiddenFields = [];
        protected $mButtons = [];
@@ -996,6 +1003,9 @@
                if ( !empty( $this->mId ) ) {
                        $attribs['id'] = $this->mId;
                }
+               if ( !empty( $this->mAutocomplete ) ) {
+                       $attribs['autocomplete'] = $this->mAutocomplete;
+               }
                return $attribs;
        }
 
@@ -1677,4 +1687,20 @@
 
                return $this->getTitle()->getLocalURL();
        }
+
+       /**
+        * Set the value for the autocomplete attribute of the form.
+        * When set to false (which is the default state), the attribute get 
not set.
+        *
+        * @since 1.27
+        *
+        * @param string|bool $autocomplete
+        *
+        * @return HTMLForm $this for chaining calls
+        */
+       public function setAutocomplete( $autocomplete ) {
+               $this->mAutocomplete = $autocomplete;
+
+               return $this;
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2920383b5b8cfca3f1d546315f202985edf417d8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Gerrit Patch Uploader <gerritpatchuploa...@gmail.com>

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

Reply via email to