summaryrefslogtreecommitdiff
path: root/includes/Preferences.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2013-08-12 09:28:15 +0200
committerPierre Schmitz <pierre@archlinux.de>2013-08-12 09:28:15 +0200
commit08aa4418c30cfc18ccc69a0f0f9cb9e17be6c196 (patch)
tree577a29fb579188d16003a209ce2a2e9c5b0aa2bd /includes/Preferences.php
parentcacc939b34e315b85e2d72997811eb6677996cc1 (diff)
Update to MediaWiki 1.21.1
Diffstat (limited to 'includes/Preferences.php')
-rw-r--r--includes/Preferences.php113
1 files changed, 70 insertions, 43 deletions
diff --git a/includes/Preferences.php b/includes/Preferences.php
index db231573..56dba05e 100644
--- a/includes/Preferences.php
+++ b/includes/Preferences.php
@@ -1,6 +1,6 @@
<?php
/**
- * Form to edit user perferences.
+ * Form to edit user preferences.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -129,7 +129,7 @@ class Preferences {
static function getOptionFromUser( $name, $info, $user ) {
$val = $user->getOption( $name );
- // Handling for array-type preferences
+ // Handling for multiselect preferences
if ( ( isset( $info['type'] ) && $info['type'] == 'multiselect' ) ||
( isset( $info['class'] ) && $info['class'] == 'HTMLMultiSelectField' ) ) {
$options = HTMLFormField::flattenOptions( $info['options'] );
@@ -143,6 +143,23 @@ class Preferences {
}
}
+ // Handling for checkmatrix preferences
+ if ( ( isset( $info['type'] ) && $info['type'] == 'checkmatrix' ) ||
+ ( isset( $info['class'] ) && $info['class'] == 'HTMLCheckMatrix' ) ) {
+ $columns = HTMLFormField::flattenOptions( $info['columns'] );
+ $rows = HTMLFormField::flattenOptions( $info['rows'] );
+ $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $name;
+ $val = array();
+
+ foreach ( $columns as $column ) {
+ foreach ( $rows as $row ) {
+ if ( $user->getOption( "$prefix-$column-$row" ) ) {
+ $val[] = "$column-$row";
+ }
+ }
+ }
+ }
+
return $val;
}
@@ -158,18 +175,21 @@ class Preferences {
$wgEnableEmail, $wgEmailConfirmToEdit, $wgEnableUserEmail, $wgEmailAuthentication,
$wgEnotifWatchlist, $wgEnotifUserTalk, $wgEnotifRevealEditorAddress;
+ // retrieving user name for GENDER and misc.
+ $userName = $user->getName();
+
## User info #####################################
// Information panel
$defaultPreferences['username'] = array(
'type' => 'info',
- 'label-message' => 'username',
- 'default' => $user->getName(),
+ 'label-message' => array( 'username', $userName ),
+ 'default' => $userName,
'section' => 'personal/info',
);
$defaultPreferences['userid'] = array(
'type' => 'info',
- 'label-message' => 'uid',
+ 'label-message' => array( 'uid', $userName ),
'default' => $user->getId(),
'section' => 'personal/info',
);
@@ -182,10 +202,10 @@ class Preferences {
// Skip the default * group, seems useless here
continue;
}
- $groupName = User::getGroupName( $ueg );
+ $groupName = User::getGroupName( $ueg );
$userGroups[] = User::makeGroupLinkHTML( $ueg, $groupName );
- $memberName = User::getGroupMember( $ueg, $user->getName() );
+ $memberName = User::getGroupMember( $ueg, $userName );
$userMembers[] = User::makeGroupLinkHTML( $ueg, $memberName );
}
asort( $userGroups );
@@ -196,7 +216,7 @@ class Preferences {
$defaultPreferences['usergroups'] = array(
'type' => 'info',
'label' => $context->msg( 'prefs-memberingroups' )->numParams(
- count( $userGroups ) )->parse(),
+ count( $userGroups ) )->params( $userName )->parse(),
'default' => $context->msg( 'prefs-memberingroups-type',
$lang->commaList( $userGroups ),
$lang->commaList( $userMembers )
@@ -252,7 +272,7 @@ class Preferences {
if ( $wgAuth->allowPasswordChange() ) {
$link = Linker::link( SpecialPage::getTitleFor( 'ChangePassword' ),
$context->msg( 'prefs-resetpass' )->escaped(), array(),
- array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' ) ) );
+ array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' )->getPrefixedText() ) );
$defaultPreferences['password'] = array(
'type' => 'info',
@@ -356,7 +376,7 @@ class Preferences {
if ( $wgEnableEmail ) {
$helpMessages[] = $wgEmailConfirmToEdit
? 'prefs-help-email-required'
- : 'prefs-help-email' ;
+ : 'prefs-help-email';
if( $wgEnableUserEmail ) {
// additional messages when users can send email to each other
@@ -367,7 +387,7 @@ class Preferences {
SpecialPage::getTitleFor( 'ChangeEmail' ),
$context->msg( $user->getEmail() ? 'prefs-changeemail' : 'prefs-setemail' )->escaped(),
array(),
- array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' ) ) );
+ array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' )->getPrefixedText() ) );
$emailAddress = $user->getEmail() ? htmlspecialchars( $user->getEmail() ) : '';
if ( $wgAuth->allowPropChange( 'emailaddress' ) ) {
@@ -377,7 +397,6 @@ class Preferences {
);
}
-
$defaultPreferences['emailaddress'] = array(
'type' => 'info',
'raw' => true,
@@ -507,14 +526,15 @@ class Preferences {
# be nice to somehow merge this back in there to avoid redundancy.
if ( $wgAllowUserCss || $wgAllowUserJs ) {
$linkTools = array();
+ $userName = $user->getName();
if ( $wgAllowUserCss ) {
- $cssPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/common.css' );
+ $cssPage = Title::makeTitleSafe( NS_USER, $userName . '/common.css' );
$linkTools[] = Linker::link( $cssPage, $context->msg( 'prefs-custom-css' )->escaped() );
}
if ( $wgAllowUserJs ) {
- $jsPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/common.js' );
+ $jsPage = Title::makeTitleSafe( NS_USER, $userName . '/common.js' );
$linkTools[] = Linker::link( $jsPage, $context->msg( 'prefs-custom-js' )->escaped() );
}
@@ -805,7 +825,6 @@ class Preferences {
'label-message' => 'tog-forceeditsummary',
);
-
$defaultPreferences['uselivepreview'] = array(
'type' => 'toggle',
'section' => 'editing/advancedediting',
@@ -879,7 +898,7 @@ class Preferences {
global $wgUseRCPatrol, $wgEnableAPI, $wgRCMaxAge;
$watchlistdaysMax = ceil( $wgRCMaxAge / ( 3600 * 24 ) );
-
+
## Watchlist #####################################
$defaultPreferences['watchlistdays'] = array(
'type' => 'float',
@@ -887,7 +906,7 @@ class Preferences {
'max' => $watchlistdaysMax,
'section' => 'watchlist/displaywatchlist',
'help' => $context->msg( 'prefs-watchlist-days-max' )->numParams(
- $watchlistdaysMax )->text(),
+ $watchlistdaysMax )->text(),
'label-message' => 'prefs-watchlist-days',
);
$defaultPreferences['wllimit'] = array(
@@ -988,7 +1007,6 @@ class Preferences {
'min' => 0,
);
-
if ( $wgVectorUseSimpleSearch ) {
$defaultPreferences['vector-simplesearch'] = array(
'type' => 'toggle',
@@ -1009,27 +1027,17 @@ class Preferences {
'section' => 'searchoptions/advancedsearchoptions',
);
- $nsOptions = array();
-
- foreach ( $wgContLang->getNamespaces() as $ns => $name ) {
- if ( $ns < 0 ) {
- continue;
- }
-
- $displayNs = str_replace( '_', ' ', $name );
-
- if ( !$displayNs ) {
- $displayNs = $context->msg( 'blanknamespace' )->text();
- }
-
- $displayNs = htmlspecialchars( $displayNs );
- $nsOptions[$displayNs] = $ns;
+ $nsOptions = $wgContLang->getFormattedNamespaces();
+ $nsOptions[0] = $context->msg( 'blanknamespace' )->text();
+ foreach ( $nsOptions as $ns => $name ) {
+ if ( $ns < 0 )
+ unset( $nsOptions[$ns] );
}
$defaultPreferences['searchnamespaces'] = array(
'type' => 'multiselect',
'label-message' => 'defaultns',
- 'options' => $nsOptions,
+ 'options' => array_flip( $nsOptions ),
'section' => 'searchoptions/advancedsearchoptions',
'prefix' => 'searchNs',
);
@@ -1236,7 +1244,7 @@ class Preferences {
* @param $user User
* @param $context IContextSource
* @param $formClass string
- * @param $remove Array: array of items to remove
+ * @param array $remove array of items to remove
* @return HtmlForm
*/
static function getFormObject( $user, IContextSource $context, $formClass = 'PreferencesForm', array $remove = array() ) {
@@ -1339,7 +1347,7 @@ class Preferences {
* @param $alldata
* @return int
*/
- static function filterIntval( $value, $alldata ){
+ static function filterIntval( $value, $alldata ) {
return intval( $value );
}
@@ -1380,7 +1388,7 @@ class Preferences {
* @return bool|Status|string
*/
static function tryFormSubmit( $formData, $form, $entryPoint = 'internal' ) {
- global $wgHiddenPrefs;
+ global $wgHiddenPrefs, $wgAuth;
$user = $form->getModifiedUser();
$result = true;
@@ -1413,15 +1421,14 @@ class Preferences {
# via $wgHiddenPrefs, we don't want to destroy that setting in case the preference
# is subsequently re-enabled
# TODO: maintenance script to actually delete these
- foreach( $wgHiddenPrefs as $pref ){
+ foreach( $wgHiddenPrefs as $pref ) {
# If the user has not set a non-default value here, the default will be returned
# and subsequently discarded
$formData[$pref] = $user->getOption( $pref, null, true );
}
- // Keeps old preferences from interfering due to back-compat
- // code, etc.
- $user->resetOptions();
+ // Keep old preferences from interfering due to back-compat code, etc.
+ $user->resetOptions( 'unused', $form->getContext() );
foreach ( $formData as $key => $value ) {
$user->setOption( $key, $value );
@@ -1429,6 +1436,8 @@ class Preferences {
$user->saveSettings();
+ $wgAuth->updateExternalDB( $user );
+
return $result;
}
@@ -1464,7 +1473,7 @@ class Preferences {
*
* @deprecated in 1.20; use User::setEmailWithConfirmation() instead.
* @param $user User
- * @param $newaddr string New email address
+ * @param string $newaddr New email address
* @return Array (true on success or Status on failure, info string)
*/
public static function trySetUserEmail( User $user, $newaddr ) {
@@ -1565,10 +1574,11 @@ class PreferencesForm extends HTMLForm {
* @return array
*/
function filterDataForSubmit( $data ) {
- // Support for separating MultiSelect preferences into multiple preferences
+ // Support for separating multi-option preferences into multiple preferences
// Due to lack of array support.
foreach ( $this->mFlatFields as $fieldname => $field ) {
$info = $field->mParams;
+
if ( $field instanceof HTMLMultiSelectField ) {
$options = HTMLFormField::flattenOptions( $info['options'] );
$prefix = isset( $info['prefix'] ) ? $info['prefix'] : $fieldname;
@@ -1578,6 +1588,23 @@ class PreferencesForm extends HTMLForm {
}
unset( $data[$fieldname] );
+
+ } elseif ( $field instanceof HTMLCheckMatrix ) {
+ $columns = HTMLFormField::flattenOptions( $info['columns'] );
+ $rows = HTMLFormField::flattenOptions( $info['rows'] );
+ $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $fieldname;
+ foreach ( $columns as $column ) {
+ foreach ( $rows as $row ) {
+ // Make sure option hasn't been removed
+ if ( !isset( $info['remove-options'] )
+ || !in_array( "$column-$row", $info['remove-options'] ) )
+ {
+ $data["$prefix-$column-$row"] = in_array( "$column-$row", $data[$fieldname] );
+ }
+ }
+ }
+
+ unset( $data[$fieldname] );
}
}