Merge "Use MediaWiki\SuppressWarnings around trigger_error('') instead @"
[lhc/web/wiklou.git] / includes / Preferences.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 use MediaWiki\Auth\AuthManager;
22 use MediaWiki\MediaWikiServices;
23 use MediaWiki\Preferences\DefaultPreferencesFactory;
24
25 /**
26 * This class has been replaced by the PreferencesFactory service.
27 *
28 * @deprecated since 1.31 use the PreferencesFactory service instead.
29 */
30 class Preferences {
31
32 /**
33 * A shim to maintain backwards-compatibility of this class, basically replicating the
34 * default behaviour of the PreferencesFactory service but not permitting overriding.
35 * @return DefaultPreferencesFactory
36 */
37 protected static function getDefaultPreferencesFactory() {
38 $services = MediaWikiServices::getInstance();
39 $authManager = AuthManager::singleton();
40 $linkRenderer = $services->getLinkRenderer();
41 $config = $services->getMainConfig();
42 $preferencesFactory = new DefaultPreferencesFactory(
43 $config, $services->getContentLanguage(), $authManager,
44 $linkRenderer
45 );
46 return $preferencesFactory;
47 }
48
49 /**
50 * @throws MWException
51 * @param User $user
52 * @param IContextSource $context
53 * @return array|null
54 */
55 public static function getPreferences( $user, IContextSource $context ) {
56 wfDeprecated( __METHOD__, '1.31' );
57 $preferencesFactory = self::getDefaultPreferencesFactory();
58 return $preferencesFactory->getFormDescriptor( $user, $context );
59 }
60
61 /**
62 * Loads existing values for a given array of preferences
63 * @throws MWException
64 * @param User $user
65 * @param IContextSource $context
66 * @param array &$defaultPreferences Array to load values for
67 * @return array|null
68 */
69 public static function loadPreferenceValues( $user, $context, &$defaultPreferences ) {
70 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
71 }
72
73 /**
74 * Pull option from a user account. Handles stuff like array-type preferences.
75 *
76 * @param string $name
77 * @param array $info
78 * @param User $user
79 * @return array|string
80 */
81 public static function getOptionFromUser( $name, $info, $user ) {
82 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
83 }
84
85 /**
86 * @param User $user
87 * @param IContextSource $context
88 * @param array &$defaultPreferences
89 * @return void
90 */
91 public static function profilePreferences(
92 $user, IContextSource $context, &$defaultPreferences
93 ) {
94 wfDeprecated( __METHOD__, '1.31' );
95 $defaultPreferences = self::getPreferences( $user, $context );
96 }
97
98 /**
99 * @param User $user
100 * @param IContextSource $context
101 * @param array &$defaultPreferences
102 * @return void
103 */
104 public static function skinPreferences( $user, IContextSource $context, &$defaultPreferences ) {
105 wfDeprecated( __METHOD__, '1.31' );
106 $defaultPreferences = self::getPreferences( $user, $context );
107 }
108
109 /**
110 * @param User $user
111 * @param IContextSource $context
112 * @param array &$defaultPreferences
113 */
114 public static function filesPreferences(
115 $user, IContextSource $context, &$defaultPreferences
116 ) {
117 wfDeprecated( __METHOD__, '1.31' );
118 $defaultPreferences = self::getPreferences( $user, $context );
119 }
120
121 /**
122 * @param User $user
123 * @param IContextSource $context
124 * @param array &$defaultPreferences
125 * @return void
126 */
127 public static function datetimePreferences(
128 $user, IContextSource $context, &$defaultPreferences
129 ) {
130 wfDeprecated( __METHOD__, '1.31' );
131 $defaultPreferences = self::getPreferences( $user, $context );
132 }
133
134 /**
135 * @param User $user
136 * @param IContextSource $context
137 * @param array &$defaultPreferences
138 */
139 public static function renderingPreferences(
140 $user, IContextSource $context, &$defaultPreferences
141 ) {
142 wfDeprecated( __METHOD__, '1.31' );
143 $defaultPreferences = self::getPreferences( $user, $context );
144 }
145
146 /**
147 * @param User $user
148 * @param IContextSource $context
149 * @param array &$defaultPreferences
150 */
151 public static function editingPreferences(
152 $user, IContextSource $context, &$defaultPreferences
153 ) {
154 wfDeprecated( __METHOD__, '1.31' );
155 $defaultPreferences = self::getPreferences( $user, $context );
156 }
157
158 /**
159 * @param User $user
160 * @param IContextSource $context
161 * @param array &$defaultPreferences
162 */
163 public static function rcPreferences( $user, IContextSource $context, &$defaultPreferences ) {
164 wfDeprecated( __METHOD__, '1.31' );
165 $defaultPreferences = self::getPreferences( $user, $context );
166 }
167
168 /**
169 * @param User $user
170 * @param IContextSource $context
171 * @param array &$defaultPreferences
172 */
173 public static function watchlistPreferences(
174 $user, IContextSource $context, &$defaultPreferences
175 ) {
176 wfDeprecated( __METHOD__, '1.31' );
177 $defaultPreferences = self::getPreferences( $user, $context );
178 }
179
180 /**
181 * @param User $user
182 * @param IContextSource $context
183 * @param array &$defaultPreferences
184 */
185 public static function searchPreferences(
186 $user, IContextSource $context, &$defaultPreferences
187 ) {
188 wfDeprecated( __METHOD__, '1.31' );
189 $defaultPreferences = self::getPreferences( $user, $context );
190 }
191
192 /**
193 * Dummy, kept for backwards-compatibility.
194 * @param User $user
195 * @param IContextSource $context
196 * @param array &$defaultPreferences
197 */
198 public static function miscPreferences( $user, IContextSource $context, &$defaultPreferences ) {
199 wfDeprecated( __METHOD__, '1.31' );
200 }
201
202 /**
203 * @param User $user
204 * @param IContextSource $context
205 * @return array Text/links to display as key; $skinkey as value
206 */
207 public static function generateSkinOptions( $user, IContextSource $context ) {
208 wfDeprecated( __METHOD__, '1.31' );
209 return self::getPreferences( $user, $context );
210 }
211
212 /**
213 * @param IContextSource $context
214 * @return array
215 */
216 static function getDateOptions( IContextSource $context ) {
217 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
218 }
219
220 /**
221 * @param IContextSource $context
222 * @return array
223 */
224 public static function getImageSizes( IContextSource $context ) {
225 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
226 }
227
228 /**
229 * @param IContextSource $context
230 * @return array
231 */
232 public static function getThumbSizes( IContextSource $context ) {
233 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
234 }
235
236 /**
237 * @param string $signature
238 * @param array $alldata
239 * @param HTMLForm $form
240 * @return bool|string
241 */
242 public static function validateSignature( $signature, $alldata, $form ) {
243 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
244 }
245
246 /**
247 * @param string $signature
248 * @param array $alldata
249 * @param HTMLForm $form
250 * @return string
251 */
252 public static function cleanSignature( $signature, $alldata, $form ) {
253 throw new Exception( __METHOD__ . '() is deprecated and does nothing now' );
254 }
255
256 /**
257 * @param User $user
258 * @param IContextSource $context
259 * @param string $formClass
260 * @param array $remove Array of items to remove
261 * @return PreferencesFormLegacy|HTMLForm
262 */
263 public static function getFormObject(
264 $user,
265 IContextSource $context,
266 $formClass = PreferencesFormLegacy::class,
267 array $remove = []
268 ) {
269 wfDeprecated( __METHOD__, '1.31' );
270 $preferencesFactory = self::getDefaultPreferencesFactory();
271 return $preferencesFactory->getForm( $user, $context, $formClass, $remove );
272 }
273 }