Merge "StringUtils: Add a utility for checking if a string is a valid regex"
[lhc/web/wiklou.git] / includes / specials / forms / PreferencesFormOOUI.php
index 5dae156..36e14f0 100644 (file)
@@ -27,8 +27,15 @@ class PreferencesFormOOUI extends OOUIHTMLForm {
        // Override default value from HTMLForm
        protected $mSubSectionBeforeFields = false;
 
+       /** @var User|null */
        private $modifiedUser;
 
+       /** @var bool */
+       private $privateInfoEditable = true;
+
+       /** @var bool */
+       private $optionsEditable = true;
+
        /**
         * @param User $user
         */
@@ -47,6 +54,35 @@ class PreferencesFormOOUI extends OOUIHTMLForm {
                }
        }
 
+       /**
+        * @return bool
+        */
+       public function isPrivateInfoEditable() {
+               return $this->privateInfoEditable;
+       }
+
+       /**
+        * Whether the
+        * @param bool $editable
+        */
+       public function setPrivateInfoEditable( $editable ) {
+               $this->privateInfoEditable = $editable;
+       }
+
+       /**
+        * @return bool
+        */
+       public function areOptionsEditable() {
+               return $this->optionsEditable;
+       }
+
+       /**
+        * @param bool $optionsEditable
+        */
+       public function setOptionsEditable( $optionsEditable ) {
+               $this->optionsEditable = $optionsEditable;
+       }
+
        /**
         * Get extra parameters for the query string when redirecting after
         * successful save.
@@ -71,13 +107,13 @@ class PreferencesFormOOUI extends OOUIHTMLForm {
         * @return string
         */
        function getButtons() {
-               if ( !$this->getModifiedUser()->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
+               if ( !$this->areOptionsEditable() && !$this->isPrivateInfoEditable() ) {
                        return '';
                }
 
                $html = parent::getButtons();
 
-               if ( $this->getModifiedUser()->isAllowed( 'editmyoptions' ) ) {
+               if ( $this->areOptionsEditable() ) {
                        $t = $this->getTitle()->getSubpage( 'reset' );
 
                        $html .= new OOUI\ButtonWidget( [
@@ -104,6 +140,8 @@ class PreferencesFormOOUI extends OOUIHTMLForm {
        function filterDataForSubmit( $data ) {
                foreach ( $this->mFlatFields as $fieldname => $field ) {
                        if ( $field instanceof HTMLNestedFilterable ) {
+                               // @phan-suppress-next-next-line PhanUndeclaredProperty All HTMLForm fields have mParams,
+                               // but the instanceof confuses phan, which doesn't support intersections
                                $info = $field->mParams;
                                $prefix = $info['prefix'] ?? $fieldname;
                                foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {