Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
[lhc/web/wiklou.git] / includes / api / ApiOptions.php
index 14bd089..f30b44c 100644 (file)
@@ -1,9 +1,5 @@
 <?php
 /**
- *
- *
- * Created on Apr 15, 2012
- *
  * Copyright © 2012 Szymon Świerkosz beau@adres.pl
  *
  * This program is free software; you can redistribute it and/or modify
@@ -24,6 +20,8 @@
  * @file
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * API module that facilitates the changing of user's preferences.
  * Requires API write mode to be enabled.
@@ -67,18 +65,19 @@ class ApiOptions extends ApiBase {
                if ( $params['change'] ) {
                        foreach ( $params['change'] as $entry ) {
                                $array = explode( '=', $entry, 2 );
-                               $changes[$array[0]] = isset( $array[1] ) ? $array[1] : null;
+                               $changes[$array[0]] = $array[1] ?? null;
                        }
                }
                if ( isset( $params['optionname'] ) ) {
-                       $newValue = isset( $params['optionvalue'] ) ? $params['optionvalue'] : null;
+                       $newValue = $params['optionvalue'] ?? null;
                        $changes[$params['optionname']] = $newValue;
                }
                if ( !$changed && !count( $changes ) ) {
                        $this->dieWithError( 'apierror-nochanges' );
                }
 
-               $prefs = Preferences::getPreferences( $user, $this->getContext() );
+               $preferencesFactory = MediaWikiServices::getInstance()->getPreferencesFactory();
+               $prefs = $preferencesFactory->getFormDescriptor( $user, $this->getContext() );
                $prefsKinds = $user->getOptionKinds( $this->getContext(), $changes );
 
                $htmlForm = null;
@@ -121,7 +120,7 @@ class ApiOptions extends ApiBase {
                                $user->setOption( $key, $value );
                                $changed = true;
                        } else {
-                               $this->addWarning( [ 'apiwarn-validationfailed', wfEscapeWikitext( $key ), $validation ] );
+                               $this->addWarning( [ 'apiwarn-validationfailed', wfEscapeWikiText( $key ), $validation ] );
                        }
                }