Preferences.php 9.6 KB

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