Merge "Simplify HTMLTitleTextField::validate"
[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 }
206
207 /**
208 * @param User $user
209 * @param IContextSource $context
210 * @return array Text/links to display as key; $skinkey as value
211 */
212 public static function generateSkinOptions( $user, IContextSource $context ) {
213 wfDeprecated( __METHOD__, '1.31' );
214 return self::getPreferences( $user, $context );
215 }
216
217 /**
218 * @param IContextSource $context
219 * @return array
220 */
221 static function getDateOptions( IContextSource $context ) {
222 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
223 }
224
225 /**
226 * @param IContextSource $context
227 * @return array
228 */
229 public static function getImageSizes( IContextSource $context ) {
230 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
231 }
232
233 /**
234 * @param IContextSource $context
235 * @return array
236 */
237 public static function getThumbSizes( IContextSource $context ) {
238 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
239 }
240
241 /**
242 * @param string $signature
243 * @param array $alldata
244 * @param HTMLForm $form
245 * @return bool|string
246 */
247 public static function validateSignature( $signature, $alldata, $form ) {
248 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
249 }
250
251 /**
252 * @param string $signature
253 * @param array $alldata
254 * @param HTMLForm $form
255 * @return string
256 */
257 public static function cleanSignature( $signature, $alldata, $form ) {
258 throw new Exception( __METHOD__ . '() is deprecated and does nothing now' );
259 }
260
261 /**
262 * @param User $user
263 * @param IContextSource $context
264 * @param string $formClass
265 * @param array $remove Array of items to remove
266 * @return PreferencesFormLegacy|HTMLForm
267 */
268 public static function getFormObject(
269 $user,
270 IContextSource $context,
271 $formClass = PreferencesFormLegacy::class,
272 array $remove = []
273 ) {
274 $preferencesFactory = self::getDefaultPreferencesFactory();
275 return $preferencesFactory->getForm( $user, $context, $formClass, $remove );
276 }
277
278 /**
279 * @param IContextSource $context
280 * @return array
281 */
282 public static function getTimezoneOptions( IContextSource $context ) {
283 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
284 }
285
286 /**
287 * @param string $value
288 * @param array $alldata
289 * @return int
290 */
291 public static function filterIntval( $value, $alldata ) {
292 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
293 }
294
295 /**
296 * @param string $tz
297 * @param array $alldata
298 * @return string
299 */
300 public static function filterTimezoneInput( $tz, $alldata ) {
301 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
302 }
303
304 /**
305 * Get a list of all time zones
306 * @param Language $language Language used for the localized names
307 * @return array A list of all time zones. The system name of the time zone is used as key and
308 * the value is an array which contains localized name, the timecorrection value used for
309 * preferences and the region
310 * @since 1.26
311 */
312 public static function getTimeZoneList( Language $language ) {
313 throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
314 }
315 }