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