SpecialPreferences.php 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  1. <?php
  2. /**
  3. * Hold things related to displaying and saving user preferences.
  4. * @file
  5. * @ingroup SpecialPage
  6. */
  7. /**
  8. * Entry point that create the "Preferences" object
  9. */
  10. function wfSpecialPreferences() {
  11. global $wgRequest;
  12. $form = new PreferencesForm( $wgRequest );
  13. $form->execute();
  14. }
  15. /**
  16. * Preferences form handling
  17. * This object will show the preferences form and can save it as well.
  18. * @ingroup SpecialPage
  19. */
  20. class PreferencesForm {
  21. var $mQuickbar, $mStubs;
  22. var $mRows, $mCols, $mSkin, $mMath, $mDate, $mUserEmail, $mEmailFlag, $mNick;
  23. var $mUserLanguage, $mUserVariant;
  24. var $mSearch, $mRecent, $mRecentDays, $mTimeZone, $mHourDiff, $mSearchLines, $mSearchChars, $mAction;
  25. var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName, $mImageSize;
  26. var $mUnderline, $mWatchlistEdits, $mGender;
  27. /**
  28. * Constructor
  29. * Load some values
  30. */
  31. function __construct( &$request ) {
  32. global $wgContLang, $wgUser, $wgAllowRealName;
  33. $this->mQuickbar = $request->getVal( 'wpQuickbar' );
  34. $this->mStubs = $request->getVal( 'wpStubs' );
  35. $this->mRows = $request->getVal( 'wpRows' );
  36. $this->mCols = $request->getVal( 'wpCols' );
  37. $this->mSkin = Skin::normalizeKey( $request->getVal( 'wpSkin' ) );
  38. $this->mMath = $request->getVal( 'wpMath' );
  39. $this->mDate = $request->getVal( 'wpDate' );
  40. $this->mUserEmail = $request->getVal( 'wpUserEmail' );
  41. $this->mRealName = $wgAllowRealName ? $request->getVal( 'wpRealName' ) : '';
  42. $this->mEmailFlag = $request->getCheck( 'wpEmailFlag' ) ? 0 : 1;
  43. $this->mNick = $request->getVal( 'wpNick' );
  44. $this->mUserLanguage = $request->getVal( 'wpUserLanguage' );
  45. $this->mUserVariant = $request->getVal( 'wpUserVariant' );
  46. $this->mSearch = $request->getVal( 'wpSearch' );
  47. $this->mRecent = $request->getVal( 'wpRecent' );
  48. $this->mRecentDays = $request->getVal( 'wpRecentDays' );
  49. $this->mTimeZone = $request->getVal( 'wpTimeZone' );
  50. $this->mHourDiff = $request->getVal( 'wpHourDiff' );
  51. $this->mSearchLines = $request->getVal( 'wpSearchLines' );
  52. $this->mSearchChars = $request->getVal( 'wpSearchChars' );
  53. $this->mImageSize = $request->getVal( 'wpImageSize' );
  54. $this->mThumbSize = $request->getInt( 'wpThumbSize' );
  55. $this->mUnderline = $request->getInt( 'wpOpunderline' );
  56. $this->mAction = $request->getVal( 'action' );
  57. $this->mReset = $request->getCheck( 'wpReset' );
  58. $this->mRestoreprefs = $request->getCheck( 'wpRestore' );
  59. $this->mPosted = $request->wasPosted();
  60. $this->mSuccess = $request->getCheck( 'success' );
  61. $this->mWatchlistDays = $request->getVal( 'wpWatchlistDays' );
  62. $this->mWatchlistEdits = $request->getVal( 'wpWatchlistEdits' );
  63. $this->mDisableMWSuggest = $request->getCheck( 'wpDisableMWSuggest' );
  64. $this->mGender = $request->getVal( 'wpGender' );
  65. $this->mSaveprefs = $request->getCheck( 'wpSaveprefs' ) &&
  66. $this->mPosted &&
  67. $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
  68. # User toggles (the big ugly unsorted list of checkboxes)
  69. $this->mToggles = array();
  70. if ( $this->mPosted ) {
  71. $togs = User::getToggles();
  72. foreach ( $togs as $tname ) {
  73. $this->mToggles[$tname] = $request->getCheck( "wpOp$tname" ) ? 1 : 0;
  74. }
  75. }
  76. $this->mUsedToggles = array();
  77. # Search namespace options
  78. # Note: namespaces don't necessarily have consecutive keys
  79. $this->mSearchNs = array();
  80. if ( $this->mPosted ) {
  81. $namespaces = $wgContLang->getNamespaces();
  82. foreach ( $namespaces as $i => $namespace ) {
  83. if ( $i >= 0 ) {
  84. $this->mSearchNs[$i] = $request->getCheck( "wpNs$i" ) ? 1 : 0;
  85. }
  86. }
  87. }
  88. # Validate language
  89. if ( !preg_match( '/^[a-z\-]*$/', $this->mUserLanguage ) ) {
  90. $this->mUserLanguage = 'nolanguage';
  91. }
  92. wfRunHooks( 'InitPreferencesForm', array( $this, $request ) );
  93. }
  94. function execute() {
  95. global $wgUser, $wgOut, $wgTitle;
  96. if ( $wgUser->isAnon() ) {
  97. $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext', array($wgTitle->getPrefixedDBkey()) );
  98. return;
  99. }
  100. if ( wfReadOnly() ) {
  101. $wgOut->readOnlyPage();
  102. return;
  103. }
  104. if ( $this->mReset ) {
  105. $this->resetPrefs();
  106. $this->mainPrefsForm( 'reset', wfMsg( 'prefsreset' ) );
  107. } else if ( $this->mSaveprefs ) {
  108. $this->savePreferences();
  109. } else if ( $this->mRestoreprefs ) {
  110. $this->restorePreferences();
  111. } else {
  112. $this->resetPrefs();
  113. $this->mainPrefsForm( '' );
  114. }
  115. }
  116. /**
  117. * @access private
  118. */
  119. function validateInt( &$val, $min=0, $max=0x7fffffff ) {
  120. $val = intval($val);
  121. $val = min($val, $max);
  122. $val = max($val, $min);
  123. return $val;
  124. }
  125. /**
  126. * @access private
  127. */
  128. function validateFloat( &$val, $min, $max=0x7fffffff ) {
  129. $val = floatval( $val );
  130. $val = min( $val, $max );
  131. $val = max( $val, $min );
  132. return( $val );
  133. }
  134. /**
  135. * @access private
  136. */
  137. function validateIntOrNull( &$val, $min=0, $max=0x7fffffff ) {
  138. $val = trim($val);
  139. if($val === '') {
  140. return null;
  141. } else {
  142. return $this->validateInt( $val, $min, $max );
  143. }
  144. }
  145. /**
  146. * @access private
  147. */
  148. function validateDate( $val ) {
  149. global $wgLang, $wgContLang;
  150. if ( $val !== false && (
  151. in_array( $val, (array)$wgLang->getDatePreferences() ) ||
  152. in_array( $val, (array)$wgContLang->getDatePreferences() ) ) )
  153. {
  154. return $val;
  155. } else {
  156. return $wgLang->getDefaultDateFormat();
  157. }
  158. }
  159. /**
  160. * Used to validate the user inputed timezone before saving it as
  161. * 'timecorrection', will return 'System' if fed bogus data.
  162. * @access private
  163. * @param string $tz the user input Zoneinfo timezone
  164. * @param string $s the user input offset string
  165. * @return string
  166. */
  167. function validateTimeZone( $tz, $s ) {
  168. $data = explode( '|', $tz, 3 );
  169. switch ( $data[0] ) {
  170. case 'ZoneInfo':
  171. case 'System':
  172. return $tz;
  173. case 'Offset':
  174. default:
  175. $data = explode( ':', $s, 2 );
  176. $minDiff = 0;
  177. if( count( $data ) == 2 ) {
  178. $data[0] = intval( $data[0] );
  179. $data[1] = intval( $data[1] );
  180. $minDiff = abs( $data[0] ) * 60 + $data[1];
  181. if ( $data[0] < 0 ) $minDiff = -$minDiff;
  182. } else {
  183. $minDiff = intval( $data[0] ) * 60;
  184. }
  185. # Max is +14:00 and min is -12:00, see:
  186. # http://en.wikipedia.org/wiki/Timezone
  187. $minDiff = min( $minDiff, 840 ); # 14:00
  188. $minDiff = max( $minDiff, -720 ); # -12:00
  189. return 'Offset|'.$minDiff;
  190. }
  191. }
  192. function validateGender( $val ) {
  193. $valid = array( 'male', 'female', 'unknown' );
  194. if ( in_array($val, $valid) ) {
  195. return $val;
  196. } else {
  197. return User::getDefaultOption( 'gender' );
  198. }
  199. }
  200. /**
  201. * @access private
  202. */
  203. function savePreferences() {
  204. global $wgUser, $wgOut, $wgParser;
  205. global $wgEnableUserEmail, $wgEnableEmail;
  206. global $wgEmailAuthentication, $wgRCMaxAge;
  207. global $wgAuth, $wgEmailConfirmToEdit;
  208. $wgUser->setRealName( $this->mRealName );
  209. $oldOptions = $wgUser->mOptions;
  210. if( $wgUser->getOption( 'language' ) !== $this->mUserLanguage ) {
  211. $needRedirect = true;
  212. } else {
  213. $needRedirect = false;
  214. }
  215. # Validate the signature and clean it up as needed
  216. global $wgMaxSigChars;
  217. if( mb_strlen( $this->mNick ) > $wgMaxSigChars ) {
  218. global $wgLang;
  219. $this->mainPrefsForm( 'error',
  220. wfMsgExt( 'badsiglength', 'parsemag', $wgLang->formatNum( $wgMaxSigChars ) ) );
  221. return;
  222. } elseif( $this->mToggles['fancysig'] ) {
  223. if( $wgParser->validateSig( $this->mNick ) !== false ) {
  224. $this->mNick = $wgParser->cleanSig( $this->mNick );
  225. } else {
  226. $this->mainPrefsForm( 'error', wfMsg( 'badsig' ) );
  227. return;
  228. }
  229. } else {
  230. // When no fancy sig used, make sure ~{3,5} get removed.
  231. $this->mNick = $wgParser->cleanSigInSig( $this->mNick );
  232. }
  233. $wgUser->setOption( 'language', $this->mUserLanguage );
  234. $wgUser->setOption( 'variant', $this->mUserVariant );
  235. $wgUser->setOption( 'nickname', $this->mNick );
  236. $wgUser->setOption( 'quickbar', $this->mQuickbar );
  237. global $wgAllowUserSkin;
  238. if( $wgAllowUserSkin ) {
  239. $wgUser->setOption( 'skin', $this->mSkin );
  240. }
  241. global $wgUseTeX;
  242. if( $wgUseTeX ) {
  243. $wgUser->setOption( 'math', $this->mMath );
  244. }
  245. $wgUser->setOption( 'date', $this->validateDate( $this->mDate ) );
  246. $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch ) );
  247. $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines ) );
  248. $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars ) );
  249. $wgUser->setOption( 'rclimit', $this->validateIntOrNull( $this->mRecent ) );
  250. $wgUser->setOption( 'rcdays', $this->validateInt($this->mRecentDays, 1, ceil($wgRCMaxAge / (3600*24))));
  251. $wgUser->setOption( 'wllimit', $this->validateIntOrNull( $this->mWatchlistEdits, 0, 1000 ) );
  252. $wgUser->setOption( 'rows', $this->validateInt( $this->mRows, 4, 1000 ) );
  253. $wgUser->setOption( 'cols', $this->validateInt( $this->mCols, 4, 1000 ) );
  254. $wgUser->setOption( 'stubthreshold', $this->validateIntOrNull( $this->mStubs ) );
  255. $wgUser->setOption( 'timecorrection', $this->validateTimeZone( $this->mTimeZone, $this->mHourDiff ) );
  256. $wgUser->setOption( 'imagesize', $this->mImageSize );
  257. $wgUser->setOption( 'thumbsize', $this->mThumbSize );
  258. $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline, 0, 2) );
  259. $wgUser->setOption( 'watchlistdays', $this->validateFloat( $this->mWatchlistDays, 0, 7 ) );
  260. $wgUser->setOption( 'disablesuggest', $this->mDisableMWSuggest );
  261. $wgUser->setOption( 'gender', $this->validateGender( $this->mGender ) );
  262. # Set search namespace options
  263. foreach( $this->mSearchNs as $i => $value ) {
  264. $wgUser->setOption( "searchNs{$i}", $value );
  265. }
  266. if( $wgEnableEmail && $wgEnableUserEmail ) {
  267. $wgUser->setOption( 'disablemail', $this->mEmailFlag );
  268. }
  269. # Set user toggles
  270. foreach ( $this->mToggles as $tname => $tvalue ) {
  271. $wgUser->setOption( $tname, $tvalue );
  272. }
  273. $error = false;
  274. if( $wgEnableEmail ) {
  275. $newadr = $this->mUserEmail;
  276. $oldadr = $wgUser->getEmail();
  277. if( ($newadr != '') && ($newadr != $oldadr) ) {
  278. # the user has supplied a new email address on the login page
  279. if( $wgUser->isValidEmailAddr( $newadr ) ) {
  280. # new behaviour: set this new emailaddr from login-page into user database record
  281. $wgUser->setEmail( $newadr );
  282. # but flag as "dirty" = unauthenticated
  283. $wgUser->invalidateEmail();
  284. if ($wgEmailAuthentication) {
  285. # Mail a temporary password to the dirty address.
  286. # User can come back through the confirmation URL to re-enable email.
  287. $result = $wgUser->sendConfirmationMail();
  288. if( WikiError::isError( $result ) ) {
  289. $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
  290. } else {
  291. $error = wfMsg( 'eauthentsent', $wgUser->getName() );
  292. }
  293. }
  294. } else {
  295. $error = wfMsg( 'invalidemailaddress' );
  296. }
  297. } else {
  298. if( $wgEmailConfirmToEdit && empty( $newadr ) ) {
  299. $this->mainPrefsForm( 'error', wfMsg( 'noemailtitle' ) );
  300. return;
  301. }
  302. $wgUser->setEmail( $this->mUserEmail );
  303. }
  304. if( $oldadr != $newadr ) {
  305. wfRunHooks( 'PrefsEmailAudit', array( $wgUser, $oldadr, $newadr ) );
  306. }
  307. }
  308. if( !$wgAuth->updateExternalDB( $wgUser ) ){
  309. $this->mainPrefsForm( 'error', wfMsg( 'externaldberror' ) );
  310. return;
  311. }
  312. $msg = '';
  313. if ( !wfRunHooks( 'SavePreferences', array( $this, $wgUser, &$msg, $oldOptions ) ) ) {
  314. $this->mainPrefsForm( 'error', $msg );
  315. return;
  316. }
  317. $wgUser->setCookies();
  318. $wgUser->saveSettings();
  319. if( $needRedirect && $error === false ) {
  320. $title = SpecialPage::getTitleFor( 'Preferences' );
  321. $wgOut->redirect( $title->getFullURL( 'success' ) );
  322. return;
  323. }
  324. $wgOut->parserOptions( ParserOptions::newFromUser( $wgUser ) );
  325. $this->mainPrefsForm( $error === false ? 'success' : 'error', $error);
  326. }
  327. /**
  328. * @access private
  329. */
  330. function resetPrefs() {
  331. global $wgUser, $wgLang, $wgContLang, $wgContLanguageCode, $wgAllowRealName, $wgLocalTZoffset;
  332. $this->mUserEmail = $wgUser->getEmail();
  333. $this->mUserEmailAuthenticationtimestamp = $wgUser->getEmailAuthenticationtimestamp();
  334. $this->mRealName = ($wgAllowRealName) ? $wgUser->getRealName() : '';
  335. # language value might be blank, default to content language
  336. $this->mUserLanguage = $wgUser->getOption( 'language', $wgContLanguageCode );
  337. $this->mUserVariant = $wgUser->getOption( 'variant');
  338. $this->mEmailFlag = $wgUser->getOption( 'disablemail' ) == 1 ? 1 : 0;
  339. $this->mNick = $wgUser->getOption( 'nickname' );
  340. $this->mQuickbar = $wgUser->getOption( 'quickbar' );
  341. $this->mSkin = Skin::normalizeKey( $wgUser->getOption( 'skin' ) );
  342. $this->mMath = $wgUser->getOption( 'math' );
  343. $this->mDate = $wgUser->getDatePreference();
  344. $this->mRows = $wgUser->getOption( 'rows' );
  345. $this->mCols = $wgUser->getOption( 'cols' );
  346. $this->mStubs = $wgUser->getOption( 'stubthreshold' );
  347. $tz = $wgUser->getOption( 'timecorrection' );
  348. $data = explode( '|', $tz, 3 );
  349. $minDiff = null;
  350. switch ( $data[0] ) {
  351. case 'ZoneInfo':
  352. $this->mTimeZone = $tz;
  353. # Check if the specified TZ exists, and change to 'Offset' if
  354. # not.
  355. if ( !function_exists('timezone_open') || @timezone_open( $data[2] ) === false ) {
  356. $this->mTimeZone = 'Offset';
  357. $minDiff = intval( $data[1] );
  358. }
  359. break;
  360. case '':
  361. case 'System':
  362. $this->mTimeZone = 'System|'.$wgLocalTZoffset;
  363. break;
  364. case 'Offset':
  365. $this->mTimeZone = 'Offset';
  366. $minDiff = intval( $data[1] );
  367. break;
  368. default:
  369. $this->mTimeZone = 'Offset';
  370. $data = explode( ':', $tz, 2 );
  371. if( count( $data ) == 2 ) {
  372. $data[0] = intval( $data[0] );
  373. $data[1] = intval( $data[1] );
  374. $minDiff = abs( $data[0] ) * 60 + $data[1];
  375. if ( $data[0] < 0 ) $minDiff = -$minDiff;
  376. } else {
  377. $minDiff = intval( $data[0] ) * 60;
  378. }
  379. break;
  380. }
  381. if ( is_null( $minDiff ) ) {
  382. $this->mHourDiff = '';
  383. } else {
  384. $this->mHourDiff = sprintf( '%+03d:%02d', floor($minDiff/60), abs($minDiff)%60 );
  385. }
  386. $this->mSearch = $wgUser->getOption( 'searchlimit' );
  387. $this->mSearchLines = $wgUser->getOption( 'contextlines' );
  388. $this->mSearchChars = $wgUser->getOption( 'contextchars' );
  389. $this->mImageSize = $wgUser->getOption( 'imagesize' );
  390. $this->mThumbSize = $wgUser->getOption( 'thumbsize' );
  391. $this->mRecent = $wgUser->getOption( 'rclimit' );
  392. $this->mRecentDays = $wgUser->getOption( 'rcdays' );
  393. $this->mWatchlistEdits = $wgUser->getOption( 'wllimit' );
  394. $this->mUnderline = $wgUser->getOption( 'underline' );
  395. $this->mWatchlistDays = $wgUser->getOption( 'watchlistdays' );
  396. $this->mDisableMWSuggest = $wgUser->getBoolOption( 'disablesuggest' );
  397. $this->mGender = $wgUser->getOption( 'gender' );
  398. $togs = User::getToggles();
  399. foreach ( $togs as $tname ) {
  400. $this->mToggles[$tname] = $wgUser->getOption( $tname );
  401. }
  402. $namespaces = $wgContLang->getNamespaces();
  403. foreach ( $namespaces as $i => $namespace ) {
  404. if ( $i >= NS_MAIN ) {
  405. $this->mSearchNs[$i] = $wgUser->getOption( 'searchNs'.$i );
  406. }
  407. }
  408. wfRunHooks( 'ResetPreferences', array( $this, $wgUser ) );
  409. }
  410. /**
  411. * @access private
  412. */
  413. function restorePreferences() {
  414. global $wgUser, $wgOut;
  415. $wgUser->restoreOptions();
  416. $wgUser->setCookies();
  417. $wgUser->saveSettings();
  418. $title = SpecialPage::getTitleFor( 'Preferences' );
  419. $wgOut->redirect( $title->getFullURL( 'success' ) );
  420. }
  421. /**
  422. * @access private
  423. */
  424. function namespacesCheckboxes() {
  425. global $wgContLang;
  426. # Determine namespace checkboxes
  427. $namespaces = $wgContLang->getNamespaces();
  428. $r1 = null;
  429. foreach ( $namespaces as $i => $name ) {
  430. if ($i < 0)
  431. continue;
  432. $checked = $this->mSearchNs[$i] ? "checked='checked'" : '';
  433. $name = str_replace( '_', ' ', $namespaces[$i] );
  434. if ( empty($name) )
  435. $name = wfMsg( 'blanknamespace' );
  436. $r1 .= "<input type='checkbox' value='1' name='wpNs$i' id='wpNs$i' {$checked}/> <label for='wpNs$i'>{$name}</label><br />\n";
  437. }
  438. return $r1;
  439. }
  440. function getToggle( $tname, $trailer = false, $disabled = false ) {
  441. global $wgUser, $wgLang;
  442. $this->mUsedToggles[$tname] = true;
  443. $ttext = $wgLang->getUserToggle( $tname );
  444. $checked = $wgUser->getOption( $tname ) == 1 ? ' checked="checked"' : '';
  445. $disabled = $disabled ? ' disabled="disabled"' : '';
  446. $trailer = $trailer ? $trailer : '';
  447. return "<div class='toggle'><input type='checkbox' value='1' id=\"$tname\" name=\"wpOp$tname\"$checked$disabled />" .
  448. " <span class='toggletext'><label for=\"$tname\">$ttext</label>$trailer</span></div>\n";
  449. }
  450. function getToggles( $items ) {
  451. $out = "";
  452. foreach( $items as $item ) {
  453. if( $item === false )
  454. continue;
  455. if( is_array( $item ) ) {
  456. list( $key, $trailer ) = $item;
  457. } else {
  458. $key = $item;
  459. $trailer = false;
  460. }
  461. $out .= $this->getToggle( $key, $trailer );
  462. }
  463. return $out;
  464. }
  465. function addRow($td1, $td2) {
  466. return "<tr><td class='mw-label'>$td1</td><td class='mw-input'>$td2</td></tr>";
  467. }
  468. /**
  469. * Helper function for user information panel
  470. * @param $td1 label for an item
  471. * @param $td2 item or null
  472. * @param $td3 optional help or null
  473. * @return xhtml block
  474. */
  475. function tableRow( $td1, $td2 = null, $td3 = null ) {
  476. if ( is_null( $td3 ) ) {
  477. $td3 = '';
  478. } else {
  479. $td3 = Xml::tags( 'tr', null,
  480. Xml::tags( 'td', array( 'class' => 'pref-label', 'colspan' => '2' ), $td3 )
  481. );
  482. }
  483. if ( is_null( $td2 ) ) {
  484. $td1 = Xml::tags( 'td', array( 'class' => 'pref-label', 'colspan' => '2' ), $td1 );
  485. $td2 = '';
  486. } else {
  487. $td1 = Xml::tags( 'td', array( 'class' => 'pref-label' ), $td1 );
  488. $td2 = Xml::tags( 'td', array( 'class' => 'pref-input' ), $td2 );
  489. }
  490. return Xml::tags( 'tr', null, $td1 . $td2 ). $td3 . "\n";
  491. }
  492. /**
  493. * @access private
  494. */
  495. function mainPrefsForm( $status , $message = '' ) {
  496. global $wgUser, $wgOut, $wgLang, $wgContLang, $wgAuth;
  497. global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
  498. global $wgDisableLangConversion, $wgDisableTitleConversion;
  499. global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits;
  500. global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
  501. global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
  502. global $wgContLanguageCode, $wgDefaultSkin, $wgCookieExpiration;
  503. global $wgEmailConfirmToEdit, $wgEnableMWSuggest, $wgLocalTZoffset;
  504. $wgOut->setPageTitle( wfMsg( 'preferences' ) );
  505. $wgOut->setArticleRelated( false );
  506. $wgOut->setRobotPolicy( 'noindex,nofollow' );
  507. $wgOut->addScriptFile( 'prefs.js' );
  508. $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
  509. if ( $this->mSuccess || 'success' == $status ) {
  510. $wgOut->wrapWikiMsg( '<div class="successbox"><strong>$1</strong></div>', 'savedprefs' );
  511. } else if ( 'error' == $status ) {
  512. $wgOut->addWikiText( '<div class="errorbox"><strong>' . $message . '</strong></div>' );
  513. } else if ( '' != $status ) {
  514. $wgOut->addWikiText( $message . "\n----" );
  515. }
  516. $qbs = $wgLang->getQuickbarSettings();
  517. $mathopts = $wgLang->getMathNames();
  518. $dateopts = $wgLang->getDatePreferences();
  519. $togs = User::getToggles();
  520. $titleObj = SpecialPage::getTitleFor( 'Preferences' );
  521. # Pre-expire some toggles so they won't show if disabled
  522. $this->mUsedToggles[ 'shownumberswatching' ] = true;
  523. $this->mUsedToggles[ 'showupdated' ] = true;
  524. $this->mUsedToggles[ 'enotifwatchlistpages' ] = true;
  525. $this->mUsedToggles[ 'enotifusertalkpages' ] = true;
  526. $this->mUsedToggles[ 'enotifminoredits' ] = true;
  527. $this->mUsedToggles[ 'enotifrevealaddr' ] = true;
  528. $this->mUsedToggles[ 'ccmeonemails' ] = true;
  529. $this->mUsedToggles[ 'uselivepreview' ] = true;
  530. $this->mUsedToggles[ 'noconvertlink' ] = true;
  531. if ( !$this->mEmailFlag ) { $emfc = 'checked="checked"'; }
  532. else { $emfc = ''; }
  533. if ($wgEmailAuthentication && ($this->mUserEmail != '') ) {
  534. if( $wgUser->getEmailAuthenticationTimestamp() ) {
  535. // date and time are separate parameters to facilitate localisation.
  536. // $time is kept for backward compat reasons.
  537. // 'emailauthenticated' is also used in SpecialConfirmemail.php
  538. $time = $wgLang->timeAndDate( $wgUser->getEmailAuthenticationTimestamp(), true );
  539. $d = $wgLang->date( $wgUser->getEmailAuthenticationTimestamp(), true );
  540. $t = $wgLang->time( $wgUser->getEmailAuthenticationTimestamp(), true );
  541. $emailauthenticated = wfMsg('emailauthenticated', $time, $d, $t ).'<br />';
  542. $disableEmailPrefs = false;
  543. } else {
  544. $disableEmailPrefs = true;
  545. $skin = $wgUser->getSkin();
  546. $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
  547. $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Confirmemail' ),
  548. wfMsg( 'emailconfirmlink' ) ) . '<br />';
  549. }
  550. } else {
  551. $emailauthenticated = '';
  552. $disableEmailPrefs = false;
  553. }
  554. if ($this->mUserEmail == '') {
  555. $emailauthenticated = wfMsg( 'noemailprefs' ) . '<br />';
  556. }
  557. $ps = $this->namespacesCheckboxes();
  558. $enotifwatchlistpages = ($wgEnotifWatchlist) ? $this->getToggle( 'enotifwatchlistpages', false, $disableEmailPrefs ) : '';
  559. $enotifusertalkpages = ($wgEnotifUserTalk) ? $this->getToggle( 'enotifusertalkpages', false, $disableEmailPrefs ) : '';
  560. $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ? $this->getToggle( 'enotifminoredits', false, $disableEmailPrefs ) : '';
  561. $enotifrevealaddr = (($wgEnotifWatchlist || $wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ? $this->getToggle( 'enotifrevealaddr', false, $disableEmailPrefs ) : '';
  562. # </FIXME>
  563. $wgOut->addHTML(
  564. Xml::openElement( 'form', array(
  565. 'action' => $titleObj->getLocalUrl(),
  566. 'method' => 'post',
  567. 'id' => 'mw-preferences-form',
  568. ) ) .
  569. Xml::openElement( 'div', array( 'id' => 'preferences' ) )
  570. );
  571. # User data
  572. $wgOut->addHTML(
  573. Xml::fieldset( wfMsg('prefs-personal') ) .
  574. Xml::openElement( 'table' ) .
  575. $this->tableRow( Xml::element( 'h2', null, wfMsg( 'prefs-personal' ) ) )
  576. );
  577. # Get groups to which the user belongs
  578. $userEffectiveGroups = $wgUser->getEffectiveGroups();
  579. $userEffectiveGroupsArray = array();
  580. foreach( $userEffectiveGroups as $ueg ) {
  581. if( $ueg == '*' ) {
  582. // Skip the default * group, seems useless here
  583. continue;
  584. }
  585. $userEffectiveGroupsArray[] = User::makeGroupLinkHTML( $ueg );
  586. }
  587. asort( $userEffectiveGroupsArray );
  588. $sk = $wgUser->getSkin();
  589. $toolLinks = array();
  590. $toolLinks[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'ListGroupRights' ), wfMsg( 'listgrouprights' ) );
  591. # At the moment one tool link only but be prepared for the future...
  592. # FIXME: Add a link to Special:Userrights for users who are allowed to use it.
  593. # $wgUser->isAllowed( 'userrights' ) seems to strict in some cases
  594. $userInformationHtml =
  595. $this->tableRow( wfMsgHtml( 'username' ), htmlspecialchars( $wgUser->getName() ) ) .
  596. $this->tableRow( wfMsgHtml( 'uid' ), htmlspecialchars( $wgUser->getId() ) ) .
  597. $this->tableRow(
  598. wfMsgExt( 'prefs-memberingroups', array( 'parseinline' ), count( $userEffectiveGroupsArray ) ),
  599. $wgLang->commaList( $userEffectiveGroupsArray ) .
  600. '<br />(' . $wgLang->pipeList( $toolLinks ) . ')'
  601. ) .
  602. $this->tableRow(
  603. wfMsgHtml( 'prefs-edits' ),
  604. $wgLang->formatNum( $wgUser->getEditCount() )
  605. );
  606. if( wfRunHooks( 'PreferencesUserInformationPanel', array( $this, &$userInformationHtml ) ) ) {
  607. $wgOut->addHTML( $userInformationHtml );
  608. }
  609. if ( $wgAllowRealName ) {
  610. $wgOut->addHTML(
  611. $this->tableRow(
  612. Xml::label( wfMsg('yourrealname'), 'wpRealName' ),
  613. Xml::input( 'wpRealName', 25, $this->mRealName, array( 'id' => 'wpRealName' ) ),
  614. Xml::tags('div', array( 'class' => 'prefsectiontip' ),
  615. wfMsgExt( 'prefs-help-realname', 'parseinline' )
  616. )
  617. )
  618. );
  619. }
  620. if ( $wgEnableEmail ) {
  621. $wgOut->addHTML(
  622. $this->tableRow(
  623. Xml::label( wfMsg('youremail'), 'wpUserEmail' ),
  624. Xml::input( 'wpUserEmail', 25, $this->mUserEmail, array( 'id' => 'wpUserEmail' ) ),
  625. Xml::tags('div', array( 'class' => 'prefsectiontip' ),
  626. wfMsgExt( $wgEmailConfirmToEdit ? 'prefs-help-email-required' : 'prefs-help-email', 'parseinline' )
  627. )
  628. )
  629. );
  630. }
  631. global $wgParser, $wgMaxSigChars;
  632. if( mb_strlen( $this->mNick ) > $wgMaxSigChars ) {
  633. $invalidSig = $this->tableRow(
  634. '&nbsp;',
  635. Xml::element( 'span', array( 'class' => 'error' ),
  636. wfMsgExt( 'badsiglength', 'parsemag', $wgLang->formatNum( $wgMaxSigChars ) ) )
  637. );
  638. } elseif( !empty( $this->mToggles['fancysig'] ) &&
  639. false === $wgParser->validateSig( $this->mNick ) ) {
  640. $invalidSig = $this->tableRow(
  641. '&nbsp;',
  642. Xml::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) )
  643. );
  644. } else {
  645. $invalidSig = '';
  646. }
  647. $wgOut->addHTML(
  648. $this->tableRow(
  649. Xml::label( wfMsg( 'yournick' ), 'wpNick' ),
  650. Xml::input( 'wpNick', 25, $this->mNick,
  651. array(
  652. 'id' => 'wpNick',
  653. // Note: $wgMaxSigChars is enforced in Unicode characters,
  654. // both on the backend and now in the browser.
  655. // Badly-behaved requests may still try to submit
  656. // an overlong string, however.
  657. 'maxlength' => $wgMaxSigChars ) )
  658. ) .
  659. $invalidSig .
  660. $this->tableRow( '&nbsp;', $this->getToggle( 'fancysig' ) )
  661. );
  662. $gender = new XMLSelect( 'wpGender', 'wpGender', $this->mGender );
  663. $gender->addOption( wfMsg( 'gender-unknown' ), 'unknown' );
  664. $gender->addOption( wfMsg( 'gender-male' ), 'male' );
  665. $gender->addOption( wfMsg( 'gender-female' ), 'female' );
  666. $wgOut->addHTML(
  667. $this->tableRow(
  668. Xml::label( wfMsg( 'yourgender' ), 'wpGender' ),
  669. $gender->getHTML(),
  670. Xml::tags( 'div', array( 'class' => 'prefsectiontip' ),
  671. wfMsgExt( 'prefs-help-gender', 'parseinline' )
  672. )
  673. )
  674. );
  675. list( $lsLabel, $lsSelect) = Xml::languageSelector( $this->mUserLanguage, false );
  676. $wgOut->addHTML(
  677. $this->tableRow( $lsLabel, $lsSelect )
  678. );
  679. /* see if there are multiple language variants to choose from*/
  680. if(!$wgDisableLangConversion) {
  681. $variants = $wgContLang->getVariants();
  682. $variantArray = array();
  683. $languages = Language::getLanguageNames( true );
  684. foreach($variants as $v) {
  685. $v = str_replace( '_', '-', strtolower($v));
  686. if( array_key_exists( $v, $languages ) ) {
  687. // If it doesn't have a name, we'll pretend it doesn't exist
  688. $variantArray[$v] = $languages[$v];
  689. }
  690. }
  691. $options = "\n";
  692. foreach( $variantArray as $code => $name ) {
  693. $selected = ($code == $this->mUserVariant);
  694. $options .= Xml::option( "$code - $name", $code, $selected ) . "\n";
  695. }
  696. if(count($variantArray) > 1) {
  697. $wgOut->addHTML(
  698. $this->tableRow(
  699. Xml::label( wfMsg( 'yourvariant' ), 'wpUserVariant' ),
  700. Xml::tags( 'select',
  701. array( 'name' => 'wpUserVariant', 'id' => 'wpUserVariant' ),
  702. $options
  703. )
  704. )
  705. );
  706. }
  707. if(count($variantArray) > 1 && !$wgDisableLangConversion && !$wgDisableTitleConversion) {
  708. $wgOut->addHTML(
  709. Xml::tags( 'tr', null,
  710. Xml::tags( 'td', array( 'colspan' => '2' ),
  711. $this->getToggle( "noconvertlink" )
  712. )
  713. )
  714. );
  715. }
  716. }
  717. # Password
  718. if( $wgAuth->allowPasswordChange() ) {
  719. $link = $wgUser->getSkin()->link( SpecialPage::getTitleFor( 'ResetPass' ), wfMsgHtml( 'prefs-resetpass' ),
  720. array() , array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' )->getPrefixedText() ) );
  721. $wgOut->addHTML(
  722. $this->tableRow( Xml::element( 'h2', null, wfMsg( 'changepassword' ) ) ) .
  723. $this->tableRow( '<ul><li>' . $link . '</li></ul>' ) );
  724. }
  725. # <FIXME>
  726. # Enotif
  727. if ( $wgEnableEmail ) {
  728. $moreEmail = '';
  729. if ($wgEnableUserEmail) {
  730. // fixme -- the "allowemail" pseudotoggle is a hacked-together
  731. // inversion for the "disableemail" preference.
  732. $emf = wfMsg( 'allowemail' );
  733. $disabled = $disableEmailPrefs ? ' disabled="disabled"' : '';
  734. $moreEmail =
  735. "<input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label>" .
  736. $this->getToggle( 'ccmeonemails', '', $disableEmailPrefs );
  737. }
  738. $wgOut->addHTML(
  739. $this->tableRow( Xml::element( 'h2', null, wfMsg( 'email' ) ) ) .
  740. $this->tableRow(
  741. $emailauthenticated.
  742. $enotifrevealaddr.
  743. $enotifwatchlistpages.
  744. $enotifusertalkpages.
  745. $enotifminoredits.
  746. $moreEmail
  747. )
  748. );
  749. }
  750. # </FIXME>
  751. $wgOut->addHTML(
  752. Xml::closeElement( 'table' ) .
  753. Xml::closeElement( 'fieldset' )
  754. );
  755. # Quickbar
  756. #
  757. if ($this->mSkin == 'cologneblue' || $this->mSkin == 'standard') {
  758. $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
  759. for ( $i = 0; $i < count( $qbs ); ++$i ) {
  760. if ( $i == $this->mQuickbar ) { $checked = ' checked="checked"'; }
  761. else { $checked = ""; }
  762. $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
  763. }
  764. $wgOut->addHTML( "</fieldset>\n\n" );
  765. } else {
  766. # Need to output a hidden option even if the relevant skin is not in use,
  767. # otherwise the preference will get reset to 0 on submit
  768. $wgOut->addHTML( Xml::hidden( 'wpQuickbar', $this->mQuickbar ) );
  769. }
  770. # Skin
  771. #
  772. global $wgAllowUserSkin;
  773. if( $wgAllowUserSkin ) {
  774. $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg( 'skin' ) . "</legend>\n" );
  775. $mptitle = Title::newMainPage();
  776. $previewtext = wfMsg( 'skin-preview' );
  777. # Only show members of Skin::getSkinNames() rather than
  778. # $skinNames (skins is all skin names from Language.php)
  779. $validSkinNames = Skin::getUsableSkins();
  780. # Sort by UI skin name. First though need to update validSkinNames as sometimes
  781. # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
  782. foreach ( $validSkinNames as $skinkey => &$skinname ) {
  783. $msgName = "skinname-{$skinkey}";
  784. $localisedSkinName = wfMsg( $msgName );
  785. if ( !wfEmptyMsg( $msgName, $localisedSkinName ) ) {
  786. $skinname = $localisedSkinName;
  787. }
  788. }
  789. asort($validSkinNames);
  790. foreach( $validSkinNames as $skinkey => $sn ) {
  791. $checked = $skinkey == $this->mSkin ? ' checked="checked"' : '';
  792. $mplink = htmlspecialchars( $mptitle->getLocalURL( "useskin=$skinkey" ) );
  793. $previewlink = "(<a target='_blank' href=\"$mplink\">$previewtext</a>)";
  794. $extraLinks = '';
  795. global $wgAllowUserCss, $wgAllowUserJs;
  796. if( $wgAllowUserCss ) {
  797. $cssPage = Title::makeTitleSafe( NS_USER, $wgUser->getName().'/'.$skinkey.'.css' );
  798. $customCSS = $sk->makeLinkObj( $cssPage, wfMsgExt('prefs-custom-css', array() ) );
  799. $extraLinks .= " ($customCSS)";
  800. }
  801. if( $wgAllowUserJs ) {
  802. $jsPage = Title::makeTitleSafe( NS_USER, $wgUser->getName().'/'.$skinkey.'.js' );
  803. $customJS = $sk->makeLinkObj( $jsPage, wfMsgHtml('prefs-custom-js') );
  804. $extraLinks .= " ($customJS)";
  805. }
  806. if( $skinkey == $wgDefaultSkin )
  807. $sn .= ' (' . wfMsg( 'default' ) . ')';
  808. $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked />
  809. <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink{$extraLinks}<br />\n" );
  810. }
  811. $wgOut->addHTML( "</fieldset>\n\n" );
  812. }
  813. # Math
  814. #
  815. global $wgUseTeX;
  816. if( $wgUseTeX ) {
  817. $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
  818. foreach ( $mathopts as $k => $v ) {
  819. $checked = ($k == $this->mMath);
  820. $wgOut->addHTML(
  821. Xml::openElement( 'div' ) .
  822. Xml::radioLabel( wfMsg( $v ), 'wpMath', $k, "mw-sp-math-$k", $checked ) .
  823. Xml::closeElement( 'div' ) . "\n"
  824. );
  825. }
  826. $wgOut->addHTML( "</fieldset>\n\n" );
  827. }
  828. # Files
  829. #
  830. $imageLimitOptions = null;
  831. foreach ( $wgImageLimits as $index => $limits ) {
  832. $selected = ($index == $this->mImageSize);
  833. $imageLimitOptions .= Xml::option( "{$limits[0]}×{$limits[1]}" .
  834. wfMsg('unit-pixel'), $index, $selected );
  835. }
  836. $imageThumbOptions = null;
  837. foreach ( $wgThumbLimits as $index => $size ) {
  838. $selected = ($index == $this->mThumbSize);
  839. $imageThumbOptions .= Xml::option($size . wfMsg('unit-pixel'), $index,
  840. $selected);
  841. }
  842. $imageSizeId = 'wpImageSize';
  843. $thumbSizeId = 'wpThumbSize';
  844. $wgOut->addHTML(
  845. Xml::fieldset( wfMsg( 'files' ) ) . "\n" .
  846. Xml::openElement( 'table' ) .
  847. '<tr>
  848. <td class="mw-label">' .
  849. Xml::label( wfMsg( 'imagemaxsize' ), $imageSizeId ) .
  850. '</td>
  851. <td class="mw-input">' .
  852. Xml::openElement( 'select', array( 'name' => $imageSizeId, 'id' => $imageSizeId ) ) .
  853. $imageLimitOptions .
  854. Xml::closeElement( 'select' ) .
  855. '</td>
  856. </tr><tr>
  857. <td class="mw-label">' .
  858. Xml::label( wfMsg( 'thumbsize' ), $thumbSizeId ) .
  859. '</td>
  860. <td class="mw-input">' .
  861. Xml::openElement( 'select', array( 'name' => $thumbSizeId, 'id' => $thumbSizeId ) ) .
  862. $imageThumbOptions .
  863. Xml::closeElement( 'select' ) .
  864. '</td>
  865. </tr>' .
  866. Xml::closeElement( 'table' ) .
  867. Xml::closeElement( 'fieldset' )
  868. );
  869. # Date format
  870. #
  871. # Date/Time
  872. #
  873. $wgOut->addHTML(
  874. Xml::openElement( 'fieldset' ) .
  875. Xml::element( 'legend', null, wfMsg( 'datetime' ) ) . "\n"
  876. );
  877. if ($dateopts) {
  878. $wgOut->addHTML(
  879. Xml::openElement( 'fieldset' ) .
  880. Xml::element( 'legend', null, wfMsg( 'dateformat' ) ) . "\n"
  881. );
  882. $idCnt = 0;
  883. $epoch = '20010115161234'; # Wikipedia day
  884. foreach( $dateopts as $key ) {
  885. if( $key == 'default' ) {
  886. $formatted = wfMsg( 'datedefault' );
  887. } else {
  888. $formatted = $wgLang->timeanddate( $epoch, false, $key );
  889. }
  890. $wgOut->addHTML(
  891. Xml::tags( 'div', null,
  892. Xml::radioLabel( $formatted, 'wpDate', $key, "wpDate$idCnt", $key == $this->mDate )
  893. ) . "\n"
  894. );
  895. $idCnt++;
  896. }
  897. $wgOut->addHTML( Xml::closeElement( 'fieldset' ) . "\n" );
  898. }
  899. $nowlocal = Xml::openElement( 'span', array( 'id' => 'wpLocalTime' ) ) .
  900. $wgLang->time( $now = wfTimestampNow(), true ) .
  901. Xml::closeElement( 'span' );
  902. $nowserver = $wgLang->time( $now, false ) .
  903. Xml::hidden( 'wpServerTime', substr( $now, 8, 2 ) * 60 + substr( $now, 10, 2 ) );
  904. $wgOut->addHTML(
  905. Xml::openElement( 'fieldset' ) .
  906. Xml::element( 'legend', null, wfMsg( 'timezonelegend' ) ) .
  907. Xml::openElement( 'table' ) .
  908. $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
  909. $this->addRow( wfMsg( 'localtime' ), $nowlocal )
  910. );
  911. $opt = Xml::openElement( 'select', array(
  912. 'name' => 'wpTimeZone',
  913. 'id' => 'wpTimeZone',
  914. 'onchange' => 'javascript:updateTimezoneSelection(false)' ) );
  915. $opt .= Xml::option( wfMsg( 'timezoneuseserverdefault' ), "System|$wgLocalTZoffset", $this->mTimeZone === "System|$wgLocalTZoffset" );
  916. $opt .= Xml::option( wfMsg( 'timezoneuseoffset' ), 'Offset', $this->mTimeZone === 'Offset' );
  917. if ( function_exists( 'timezone_identifiers_list' ) ) {
  918. # Read timezone list
  919. $tzs = timezone_identifiers_list();
  920. sort( $tzs );
  921. # Precache localized region names
  922. $tzRegions = array();
  923. $tzRegions['Africa'] = wfMsg( 'timezoneregion-africa' );
  924. $tzRegions['America'] = wfMsg( 'timezoneregion-america' );
  925. $tzRegions['Antarctica'] = wfMsg( 'timezoneregion-antarctica' );
  926. $tzRegions['Arctic'] = wfMsg( 'timezoneregion-arctic' );
  927. $tzRegions['Asia'] = wfMsg( 'timezoneregion-asia' );
  928. $tzRegions['Atlantic'] = wfMsg( 'timezoneregion-atlantic' );
  929. $tzRegions['Australia'] = wfMsg( 'timezoneregion-australia' );
  930. $tzRegions['Europe'] = wfMsg( 'timezoneregion-europe' );
  931. $tzRegions['Indian'] = wfMsg( 'timezoneregion-indian' );
  932. $tzRegions['Pacific'] = wfMsg( 'timezoneregion-pacific' );
  933. asort( $tzRegions );
  934. $selZone = explode( '|', $this->mTimeZone, 3 );
  935. $selZone = ( $selZone[0] == 'ZoneInfo' ) ? $selZone[2] : null;
  936. $now = date_create( 'now' );
  937. $optgroup = '';
  938. foreach ( $tzs as $tz ) {
  939. $z = explode( '/', $tz, 2 );
  940. # timezone_identifiers_list() returns a number of
  941. # backwards-compatibility entries. This filters them out of the
  942. # list presented to the user.
  943. if ( count( $z ) != 2 || !array_key_exists( $z[0], $tzRegions ) )
  944. continue;
  945. # Localize region
  946. $z[0] = $tzRegions[$z[0]];
  947. # Create region groups
  948. if ( $optgroup != $z[0] ) {
  949. if ( $optgroup !== '' ) {
  950. $opt .= Xml::closeElement( 'optgroup' );
  951. }
  952. $optgroup = $z[0];
  953. $opt .= Xml::openElement( 'optgroup', array( 'label' => $z[0] ) ) . "\n";
  954. }
  955. $minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );
  956. $opt .= Xml::option( str_replace( '_', ' ', $z[0] . '/' . $z[1] ), "ZoneInfo|$minDiff|$tz", $selZone === $tz, array( 'label' => $z[1] ) ) . "\n";
  957. }
  958. if ( $optgroup !== '' ) $opt .= Xml::closeElement( 'optgroup' );
  959. }
  960. $opt .= Xml::closeElement( 'select' );
  961. $wgOut->addHTML(
  962. $this->addRow(
  963. Xml::label( wfMsg( 'timezoneselect' ), 'wpTimeZone' ),
  964. $opt )
  965. );
  966. $wgOut->addHTML(
  967. $this->addRow(
  968. Xml::label( wfMsg( 'timezoneoffset' ), 'wpHourDiff' ),
  969. Xml::input( 'wpHourDiff', 6, $this->mHourDiff, array(
  970. 'id' => 'wpHourDiff',
  971. 'onfocus' => 'javascript:updateTimezoneSelection(true)',
  972. 'onblur' => 'javascript:updateTimezoneSelection(false)' ) ) ) .
  973. "<tr>
  974. <td></td>
  975. <td class='mw-submit'>" .
  976. Xml::element( 'input',
  977. array( 'type' => 'button',
  978. 'value' => wfMsg( 'guesstimezone' ),
  979. 'onclick' => 'javascript:guessTimezone()',
  980. 'id' => 'guesstimezonebutton',
  981. 'style' => 'display:none;' ) ) .
  982. "</td>
  983. </tr>" .
  984. Xml::closeElement( 'table' ) .
  985. Xml::tags( 'div', array( 'class' => 'prefsectiontip' ), wfMsgExt( 'timezonetext', 'parseinline' ) ).
  986. Xml::closeElement( 'fieldset' ) .
  987. Xml::closeElement( 'fieldset' ) . "\n\n"
  988. );
  989. # Editing
  990. #
  991. global $wgLivePreview;
  992. $wgOut->addHTML(
  993. Xml::fieldset( wfMsg( 'textboxsize' ) ) .
  994. wfMsgHTML( 'prefs-edit-boxsize' ) . ' ' .
  995. Xml::inputLabel( wfMsg( 'rows' ), 'wpRows', 'wpRows', 3, $this->mRows ) . ' ' .
  996. Xml::inputLabel( wfMsg( 'columns' ), 'wpCols', 'wpCols', 3, $this->mCols ) .
  997. $this->getToggles( array(
  998. 'editsection',
  999. 'editsectiononrightclick',
  1000. 'editondblclick',
  1001. 'editwidth',
  1002. 'showtoolbar',
  1003. 'previewonfirst',
  1004. 'previewontop',
  1005. 'minordefault',
  1006. 'externaleditor',
  1007. 'externaldiff',
  1008. $wgLivePreview ? 'uselivepreview' : false,
  1009. 'forceeditsummary',
  1010. ) )
  1011. );
  1012. $wgOut->addHTML( Xml::closeElement( 'fieldset' ) );
  1013. # Recent changes
  1014. global $wgRCMaxAge, $wgUseRCPatrol;
  1015. $wgOut->addHTML(
  1016. Xml::fieldset( wfMsg( 'prefs-rc' ) ) .
  1017. Xml::openElement( 'table' ) .
  1018. '<tr>
  1019. <td class="mw-label">' .
  1020. Xml::label( wfMsg( 'recentchangesdays' ), 'wpRecentDays' ) .
  1021. '</td>
  1022. <td class="mw-input">' .
  1023. Xml::input( 'wpRecentDays', 3, $this->mRecentDays, array( 'id' => 'wpRecentDays' ) ) . ' ' .
  1024. wfMsgExt( 'recentchangesdays-max', 'parsemag',
  1025. $wgLang->formatNum( ceil( $wgRCMaxAge / ( 3600 * 24 ) ) ) ) .
  1026. '</td>
  1027. </tr><tr>
  1028. <td class="mw-label">' .
  1029. Xml::label( wfMsg( 'recentchangescount' ), 'wpRecent' ) .
  1030. '</td>
  1031. <td class="mw-input">' .
  1032. Xml::input( 'wpRecent', 3, $this->mRecent, array( 'id' => 'wpRecent' ) ) .
  1033. '</td>
  1034. </tr>' .
  1035. Xml::closeElement( 'table' ) .
  1036. '<br />'
  1037. );
  1038. $toggles[] = 'hideminor';
  1039. if( $wgUseRCPatrol ) {
  1040. $toggles[] = 'hidepatrolled';
  1041. $toggles[] = 'newpageshidepatrolled';
  1042. }
  1043. if( $wgRCShowWatchingUsers ) $toggles[] = 'shownumberswatching';
  1044. $toggles[] = 'usenewrc';
  1045. $wgOut->addHTML(
  1046. $this->getToggles( $toggles ) .
  1047. Xml::closeElement( 'fieldset' )
  1048. );
  1049. # Watchlist
  1050. $watchlistToggles = array( 'watchlisthideminor', 'watchlisthidebots', 'watchlisthideown',
  1051. 'watchlisthideanons', 'watchlisthideliu' );
  1052. if( $wgUseRCPatrol ) $watchlistToggles[] = 'watchlisthidepatrolled';
  1053. $wgOut->addHTML(
  1054. Xml::fieldset( wfMsg( 'prefs-watchlist' ) ) .
  1055. Xml::inputLabel( wfMsg( 'prefs-watchlist-days' ), 'wpWatchlistDays', 'wpWatchlistDays', 3, $this->mWatchlistDays ) . ' ' .
  1056. wfMsgHTML( 'prefs-watchlist-days-max' ) .
  1057. '<br /><br />' .
  1058. $this->getToggle( 'extendwatchlist' ) .
  1059. Xml::inputLabel( wfMsg( 'prefs-watchlist-edits' ), 'wpWatchlistEdits', 'wpWatchlistEdits', 3, $this->mWatchlistEdits ) . ' ' .
  1060. wfMsgHTML( 'prefs-watchlist-edits-max' ) .
  1061. '<br /><br />' .
  1062. $this->getToggles( $watchlistToggles )
  1063. );
  1064. if( $wgUser->isAllowed( 'createpage' ) || $wgUser->isAllowed( 'createtalk' ) ) {
  1065. $wgOut->addHTML( $this->getToggle( 'watchcreations' ) );
  1066. }
  1067. foreach( array( 'edit' => 'watchdefault', 'move' => 'watchmoves', 'delete' => 'watchdeletion' ) as $action => $toggle ) {
  1068. if( $wgUser->isAllowed( $action ) )
  1069. $wgOut->addHTML( $this->getToggle( $toggle ) );
  1070. }
  1071. $this->mUsedToggles['watchcreations'] = true;
  1072. $this->mUsedToggles['watchdefault'] = true;
  1073. $this->mUsedToggles['watchmoves'] = true;
  1074. $this->mUsedToggles['watchdeletion'] = true;
  1075. $wgOut->addHTML( Xml::closeElement( 'fieldset' ) );
  1076. # Search
  1077. $mwsuggest = $wgEnableMWSuggest ?
  1078. $this->addRow(
  1079. Xml::label( wfMsg( 'mwsuggest-disable' ), 'wpDisableMWSuggest' ),
  1080. Xml::check( 'wpDisableMWSuggest', $this->mDisableMWSuggest, array( 'id' => 'wpDisableMWSuggest' ) )
  1081. ) : '';
  1082. $wgOut->addHTML(
  1083. // Elements for the search tab itself
  1084. Xml::openElement( 'fieldset' ) .
  1085. Xml::element( 'legend', null, wfMsg( 'searchresultshead' ) ) .
  1086. // Elements for the search options in the search tab
  1087. Xml::openElement( 'fieldset' ) .
  1088. Xml::element( 'legend', null, wfMsg( 'prefs-searchoptions' ) ) .
  1089. Xml::openElement( 'table' ) .
  1090. $this->addRow(
  1091. Xml::label( wfMsg( 'resultsperpage' ), 'wpSearch' ),
  1092. Xml::input( 'wpSearch', 4, $this->mSearch, array( 'id' => 'wpSearch' ) )
  1093. ) .
  1094. $this->addRow(
  1095. Xml::label( wfMsg( 'contextlines' ), 'wpSearchLines' ),
  1096. Xml::input( 'wpSearchLines', 4, $this->mSearchLines, array( 'id' => 'wpSearchLines' ) )
  1097. ) .
  1098. $this->addRow(
  1099. Xml::label( wfMsg( 'contextchars' ), 'wpSearchChars' ),
  1100. Xml::input( 'wpSearchChars', 4, $this->mSearchChars, array( 'id' => 'wpSearchChars' ) )
  1101. ) .
  1102. $mwsuggest .
  1103. Xml::closeElement( 'table' ) .
  1104. Xml::closeElement( 'fieldset' ) .
  1105. // Elements for the namespace options in the search tab
  1106. Xml::openElement( 'fieldset' ) .
  1107. Xml::element( 'legend', null, wfMsg( 'prefs-namespaces' ) ) .
  1108. wfMsgExt( 'defaultns', array( 'parse' ) ) .
  1109. $ps .
  1110. Xml::closeElement( 'fieldset' ) .
  1111. // End of the search tab
  1112. Xml::closeElement( 'fieldset' )
  1113. );
  1114. # Misc
  1115. #
  1116. $uopt = $wgUser->getOption( 'underline' );
  1117. $wgOut->addHTML(
  1118. Xml::fieldset( wfMsg( 'prefs-misc' ) ) .
  1119. Xml::openElement( 'table' ) .
  1120. '<tr>
  1121. <td class="mw-label">' .
  1122. // Xml::label() cannot be used because 'stub-threshold' contains plain HTML
  1123. Xml::tags( 'label', array( 'for' => 'wpStubs' ), wfMsg( 'stub-threshold' ) ) .
  1124. '</td>
  1125. <td class="mw-input">' .
  1126. Xml::input( 'wpStubs', 6, $this->mStubs, array( 'id' => 'wpStubs' ) ) .
  1127. '</td>
  1128. </tr><tr>
  1129. <td class="mw-label">' .
  1130. Xml::label( wfMsg( 'tog-underline' ), 'wpOpunderline' ) .
  1131. '</td>
  1132. <td class="mw-input">' .
  1133. Xml::openElement( 'select', array( 'id' => 'wpOpunderline', 'name' => 'wpOpunderline' ) ) .
  1134. Xml::option( wfMsg ( 'underline-never' ), '0', $uopt == 0 ) .
  1135. Xml::option( wfMsg ( 'underline-always' ), '1', $uopt == 1 ) .
  1136. Xml::option( wfMsg ( 'underline-default' ), '2', $uopt == 2 ) .
  1137. Xml::closeElement( 'select' ) .
  1138. '</td>
  1139. </tr>' .
  1140. Xml::closeElement( 'table' )
  1141. );
  1142. # And now the rest = Misc.
  1143. foreach ( $togs as $tname ) {
  1144. if( !array_key_exists( $tname, $this->mUsedToggles ) ) {
  1145. if( $tname == 'norollbackdiff' && $wgUser->isAllowed( 'rollback' ) )
  1146. $wgOut->addHTML( $this->getToggle( $tname ) );
  1147. else
  1148. $wgOut->addHTML( $this->getToggle( $tname ) );
  1149. }
  1150. }
  1151. $wgOut->addHTML( '</fieldset>' );
  1152. wfRunHooks( 'RenderPreferencesForm', array( $this, $wgOut ) );
  1153. $token = htmlspecialchars( $wgUser->editToken() );
  1154. $skin = $wgUser->getSkin();
  1155. $rtl = $wgContLang->isRTL() ? 'left' : 'right';
  1156. $wgOut->addHTML( "
  1157. <table id='prefsubmit' cellpadding='0' width='100%' style='background:none;'><tr>
  1158. <td><input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) .
  1159. '"'.$skin->tooltipAndAccesskey('save')." />
  1160. <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" /></td>
  1161. <td align='$rtl'><input type='submit' name='wpRestore' value=\"" . wfMsgHtml( 'restoreprefs' ) . "\" /></td>
  1162. </tr></table>
  1163. <input type='hidden' name='wpEditToken' value=\"{$token}\" />
  1164. </div></form>\n" );
  1165. $wgOut->addHTML( Xml::tags( 'div', array( 'class' => "prefcache" ),
  1166. wfMsgExt( 'clearyourcache', 'parseinline' ) )
  1167. );
  1168. }
  1169. }