Merge "Add tablesUsed to RevisionStoreDbTest"
[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 global $wgContLang;
39 $authManager = AuthManager::singleton();
40 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
41 $config = MediaWikiServices::getInstance()->getMainConfig();
42 $preferencesFactory = new DefaultPreferencesFactory(
43 $config, $wgContLang, $authManager, $linkRenderer
44 );
45 return $preferencesFactory;
46 }
47
48 /**
49 * @return array
50 */
51 public static function getSaveBlacklist() {
52 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
53 }
54
55 /**
56 * @throws MWException
57 * @param User $user
58 * @param IContextSource $context
59 * @return array|null
60 */
61 public static function getPreferences( $user, IContextSource $context ) {
62 $preferencesFactory = self::getDefaultPreferencesFactory();
63 return $preferencesFactory->getFormDescriptor( $user, $context );
64 }
65
66 /**
67 * Loads existing values for a given array of preferences
68 * @throws MWException
69 * @param User $user
70 * @param IContextSource $context
71 * @param array &$defaultPreferences Array to load values for
72 * @return array|null
73 */
74 public static function loadPreferenceValues( $user, $context, &$defaultPreferences ) {
75 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
76 }
77
78 /**
79 * Pull option from a user account. Handles stuff like array-type preferences.
80 *
81 * @param string $name
82 * @param array $info
83 * @param User $user
84 * @return array|string
85 */
86 public static function getOptionFromUser( $name, $info, $user ) {
87 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
88 }
89
90 /**
91 * @param User $user
92 * @param IContextSource $context
93 * @param array &$defaultPreferences
94 * @return void
95 */
96 public static function profilePreferences(
97 $user, IContextSource $context, &$defaultPreferences
98 ) {
99 wfDeprecated( __METHOD__, '1.31' );
100 $defaultPreferences = self::getPreferences( $user, $context );
101 }
102
103 /**
104 * @param User $user
105 * @param IContextSource $context
106 * @param array &$defaultPreferences
107 * @return void
108 */
109 public static function skinPreferences( $user, IContextSource $context, &$defaultPreferences ) {
110 wfDeprecated( __METHOD__, '1.31' );
111 $defaultPreferences = self::getPreferences( $user, $context );
112 }
113
114 /**
115 * @param User $user
116 * @param IContextSource $context
117 * @param array &$defaultPreferences
118 */
119 public static function filesPreferences(
120 $user, IContextSource $context, &$defaultPreferences
121 ) {
122 wfDeprecated( __METHOD__, '1.31' );
123 $defaultPreferences = self::getPreferences( $user, $context );
124 }
125
126 /**
127 * @param User $user
128 * @param IContextSource $context
129 * @param array &$defaultPreferences
130 * @return void
131 */
132 public static function datetimePreferences(
133 $user, IContextSource $context, &$defaultPreferences
134 ) {
135 wfDeprecated( __METHOD__, '1.31' );
136 $defaultPreferences = self::getPreferences( $user, $context );
137 }
138
139 /**
140 * @param User $user
141 * @param IContextSource $context
142 * @param array &$defaultPreferences
143 */
144 public static function renderingPreferences(
145 $user, IContextSource $context, &$defaultPreferences
146 ) {
147 wfDeprecated( __METHOD__, '1.31' );
148 $defaultPreferences = self::getPreferences( $user, $context );
149 }
150
151 /**
152 * @param User $user
153 * @param IContextSource $context
154 * @param array &$defaultPreferences
155 */
156 public static function editingPreferences(
157 $user, IContextSource $context, &$defaultPreferences
158 ) {
159 wfDeprecated( __METHOD__, '1.31' );
160 $defaultPreferences = self::getPreferences( $user, $context );
161 }
162
163 /**
164 * @param User $user
165 * @param IContextSource $context
166 * @param array &$defaultPreferences
167 */
168 public static function rcPreferences( $user, IContextSource $context, &$defaultPreferences ) {
169 wfDeprecated( __METHOD__, '1.31' );
170 $defaultPreferences = self::getPreferences( $user, $context );
171 }
172
173 /**
174 * @param User $user
175 * @param IContextSource $context
176 * @param array &$defaultPreferences
177 */
178 public static function watchlistPreferences(
179 $user, IContextSource $context, &$defaultPreferences
180 ) {
181 wfDeprecated( __METHOD__, '1.31' );
182 $defaultPreferences = self::getPreferences( $user, $context );
183 }
184
185 /**
186 * @param User $user
187 * @param IContextSource $context
188 * @param array &$defaultPreferences
189 */
190 public static function searchPreferences(
191 $user, IContextSource $context, &$defaultPreferences
192 ) {
193 wfDeprecated( __METHOD__, '1.31' );
194 $defaultPreferences = self::getPreferences( $user, $context );
195 }
196
197 /**
198 * Dummy, kept for backwards-compatibility.
199 * @param User $user
200 * @param IContextSource $context
201 * @param array &$defaultPreferences
202 */
203 public static function miscPreferences( $user, IContextSource $context, &$defaultPreferences ) {
204 }
205
206 /**
207 * @param User $user
208 * @param IContextSource $context
209 * @return array Text/links to display as key; $skinkey as value
210 */
211 public static function generateSkinOptions( $user, IContextSource $context ) {
212 wfDeprecated( __METHOD__, '1.31' );
213 return self::getPreferences( $user, $context );
214 }
215
216 /**
217 * @param IContextSource $context
218 * @return array
219 */
220 static function getDateOptions( IContextSource $context ) {
221 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
222 }
223
224 /**
225 * @param IContextSource $context
226 * @return array
227 */
228 public static function getImageSizes( IContextSource $context ) {
229 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
230 }
231
232 /**
233 * @param IContextSource $context
234 * @return array
235 */
236 public static function getThumbSizes( IContextSource $context ) {
237 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
238 }
239
240 /**
241 * @param string $signature
242 * @param array $alldata
243 * @param HTMLForm $form
244 * @return bool|string
245 */
246 public static function validateSignature( $signature, $alldata, $form ) {
247 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
248 }
249
250 /**
251 * @param string $signature
252 * @param array $alldata
253 * @param HTMLForm $form
254 * @return string
255 */
256 public static function cleanSignature( $signature, $alldata, $form ) {
257 throw new Exception( __METHOD__ . '() is deprecated and does nothing now' );
258 }
259
260 /**
261 * @param User $user
262 * @param IContextSource $context
263 * @param string $formClass
264 * @param array $remove Array of items to remove
265 * @return PreferencesForm|HTMLForm
266 */
267 public static function getFormObject(
268 $user,
269 IContextSource $context,
270 $formClass = PreferencesForm::class,
271 array $remove = []
272 ) {
273 $preferencesFactory = self::getDefaultPreferencesFactory();
274 return $preferencesFactory->getForm( $user, $context, $formClass, $remove );
275 }
276
277 /**
278 * @param IContextSource $context
279 * @return array
280 */
281 public static function getTimezoneOptions( IContextSource $context ) {
282 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
283 }
284
285 /**
286 * @param string $value
287 * @param array $alldata
288 * @return int
289 */
290 public static function filterIntval( $value, $alldata ) {
291 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
292 }
293
294 /**
295 * @param string $tz
296 * @param array $alldata
297 * @return string
298 */
299 public static function filterTimezoneInput( $tz, $alldata ) {
300 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
301 }
302
303 /**
304 * Handle the form submission if everything validated properly
305 *
306 * @deprecated since 1.31, use PreferencesFactory
307 *
308 * @param array $formData
309 * @param PreferencesForm $form
310 * @return bool|Status|string
311 */
312 public static function tryFormSubmit( $formData, $form ) {
313 $preferencesFactory = self::getDefaultPreferencesFactory();
314 return $preferencesFactory->legacySaveFormData( $formData, $form );
315 }
316
317 /**
318 * @param array $formData
319 * @param PreferencesForm $form
320 * @return Status
321 */
322 public static function tryUISubmit( $formData, $form ) {
323 $preferencesFactory = self::getDefaultPreferencesFactory();
324 return $preferencesFactory->legacySubmitForm( $formData, $form );
325 }
326
327 /**
328 * Get a list of all time zones
329 * @param Language $language Language used for the localized names
330 * @return array A list of all time zones. The system name of the time zone is used as key and
331 * the value is an array which contains localized name, the timecorrection value used for
332 * preferences and the region
333 * @since 1.26
334 */
335 public static function getTimeZoneList( Language $language ) {
336 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
337 }
338 }