本文整理汇总了PHP中HTMLForm::loadInputFromParameters方法的典型用法代码示例。如果您正苦于以下问题:PHP HTMLForm::loadInputFromParameters方法的具体用法?PHP HTMLForm::loadInputFromParameters怎么用?PHP HTMLForm::loadInputFromParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTMLForm
的用法示例。
在下文中一共展示了HTMLForm::loadInputFromParameters方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Changes preferences of the current user.
*/
public function execute()
{
$user = $this->getUser();
if ($user->isAnon()) {
$this->dieUsage('Anonymous users cannot change preferences', 'notloggedin');
}
if (!$user->isAllowed('editmyoptions')) {
$this->dieUsage('You don\'t have permission to edit your options', 'permissiondenied');
}
$params = $this->extractRequestParams();
$changed = false;
if (isset($params['optionvalue']) && !isset($params['optionname'])) {
$this->dieUsageMsg(array('missingparam', 'optionname'));
}
if ($params['reset']) {
$user->resetOptions();
$changed = true;
}
$changes = array();
if (count($params['change'])) {
foreach ($params['change'] as $entry) {
$array = explode('=', $entry, 2);
$changes[$array[0]] = isset($array[1]) ? $array[1] : null;
}
}
if (isset($params['optionname'])) {
$newValue = isset($params['optionvalue']) ? $params['optionvalue'] : null;
$changes[$params['optionname']] = $newValue;
}
if (!$changed && !count($changes)) {
$this->dieUsage('No changes were requested', 'nochanges');
}
$prefs = Preferences::getPreferences($user, $this->getContext());
foreach ($changes as $key => $value) {
if (empty($prefs[$key])) {
// This is not a default preference and cannot be modified by this API
$validation = 'not a valid preference';
} else {
$field = HTMLForm::loadInputFromParameters($key, $prefs[$key]);
$validation = $field->validate($value, $user->getOptions());
}
if ($validation === true) {
$user->setGlobalPreference($key, $value);
$changed = true;
} else {
$this->setWarning("Validation error for '{$key}': {$validation}");
}
}
if ($changed) {
// Commit changes
$user->saveSettings();
}
$this->getResult()->addValue(null, $this->getModuleName(), 'success');
}
示例2: getPreferences
static function getPreferences($user)
{
if (self::$defaultPreferences) {
return self::$defaultPreferences;
}
global $wgRCMaxAge;
$defaultPreferences = array();
self::profilePreferences($user, $defaultPreferences);
self::skinPreferences($user, $defaultPreferences);
self::filesPreferences($user, $defaultPreferences);
self::mathPreferences($user, $defaultPreferences);
self::datetimePreferences($user, $defaultPreferences);
self::renderingPreferences($user, $defaultPreferences);
self::editingPreferences($user, $defaultPreferences);
self::rcPreferences($user, $defaultPreferences);
self::watchlistPreferences($user, $defaultPreferences);
self::searchPreferences($user, $defaultPreferences);
self::miscPreferences($user, $defaultPreferences);
wfRunHooks('GetPreferences', array($user, &$defaultPreferences));
## Remove preferences that wikis don't want to use
global $wgHiddenPrefs;
foreach ($wgHiddenPrefs as $pref) {
if (isset($defaultPreferences[$pref])) {
unset($defaultPreferences[$pref]);
}
}
## Prod in defaults from the user
global $wgDefaultUserOptions;
foreach ($defaultPreferences as $name => &$info) {
$prefFromUser = self::getOptionFromUser($name, $info, $user);
$field = HTMLForm::loadInputFromParameters($info);
// For validation
$defaultOptions = User::getDefaultOptions();
$globalDefault = isset($defaultOptions[$name]) ? $defaultOptions[$name] : null;
// If it validates, set it as the default
if (isset($info['default'])) {
// Already set, no problem
continue;
} elseif (!is_null($prefFromUser) && $field->validate($prefFromUser, $user->mOptions) === true) {
$info['default'] = $prefFromUser;
} elseif ($field->validate($globalDefault, $user->mOptions) === true) {
$info['default'] = $globalDefault;
} else {
throw new MWException("Global default '{$globalDefault}' is invalid for field {$name}");
}
}
self::$defaultPreferences = $defaultPreferences;
return $defaultPreferences;
}
示例3: getPreferences
/**
* @throws MWException
* @param $user User
* @param $context IContextSource
* @return array|null
*/
static function getPreferences( $user, IContextSource $context ) {
if ( self::$defaultPreferences ) {
return self::$defaultPreferences;
}
$defaultPreferences = array();
self::profilePreferences( $user, $context, $defaultPreferences );
self::skinPreferences( $user, $context, $defaultPreferences );
self::filesPreferences( $user, $context, $defaultPreferences );
self::datetimePreferences( $user, $context, $defaultPreferences );
self::renderingPreferences( $user, $context, $defaultPreferences );
self::editingPreferences( $user, $context, $defaultPreferences );
self::rcPreferences( $user, $context, $defaultPreferences );
self::watchlistPreferences( $user, $context, $defaultPreferences );
self::searchPreferences( $user, $context, $defaultPreferences );
self::miscPreferences( $user, $context, $defaultPreferences );
wfRunHooks( 'GetPreferences', array( $user, &$defaultPreferences ) );
## Remove preferences that wikis don't want to use
global $wgHiddenPrefs;
foreach ( $wgHiddenPrefs as $pref ) {
if ( isset( $defaultPreferences[$pref] ) ) {
unset( $defaultPreferences[$pref] );
}
}
## Make sure that form fields have their parent set. See bug 41337.
$dummyForm = new HTMLForm( array(), $context );
$disable = !$user->isAllowed( 'editmyoptions' );
## Prod in defaults from the user
foreach ( $defaultPreferences as $name => &$info ) {
$prefFromUser = self::getOptionFromUser( $name, $info, $user );
if ( $disable && !in_array( $name, self::$saveBlacklist ) ) {
$info['disabled'] = 'disabled';
}
$field = HTMLForm::loadInputFromParameters( $name, $info ); // For validation
$field->mParent = $dummyForm;
$defaultOptions = User::getDefaultOptions();
$globalDefault = isset( $defaultOptions[$name] )
? $defaultOptions[$name]
: null;
// If it validates, set it as the default
if ( isset( $info['default'] ) ) {
// Already set, no problem
continue;
} elseif ( !is_null( $prefFromUser ) && // Make sure we're not just pulling nothing
$field->validate( $prefFromUser, $user->getOptions() ) === true ) {
$info['default'] = $prefFromUser;
} elseif ( $field->validate( $globalDefault, $user->getOptions() ) === true ) {
$info['default'] = $globalDefault;
} else {
throw new MWException( "Global default '$globalDefault' is invalid for field $name" );
}
}
self::$defaultPreferences = $defaultPreferences;
return $defaultPreferences;
}
示例4: getInputHTML
public function getInputHTML($values)
{
$html = '';
foreach ((array) $values as $key => $value) {
if ($key === 'nonjs') {
continue;
}
$html .= Html::rawElement('li', ['class' => 'mw-htmlform-cloner-li'], $this->getInputHTMLForKey($key, $value));
}
$template = $this->getInputHTMLForKey($this->uniqueId, null);
$html = Html::rawElement('ul', ['id' => "mw-htmlform-cloner-list-{$this->mID}", 'class' => 'mw-htmlform-cloner-ul', 'data-template' => $template, 'data-unique-id' => $this->uniqueId], $html);
$name = "{$this->mName}[create]";
$label = isset($this->mParams['create-button-message']) ? $this->mParams['create-button-message'] : 'htmlform-cloner-create';
$field = HTMLForm::loadInputFromParameters($name, ['type' => 'submit', 'name' => $name, 'id' => Sanitizer::escapeId("{$this->mID}--create"), 'cssclass' => 'mw-htmlform-cloner-create-button', 'default' => $this->getMessage($label)->text()], $this->mParent);
$html .= $field->getInputHTML($field->getDefault());
return $html;
}
示例5: loadInputFromParameters
public static function loadInputFromParameters($fieldname, $descriptor, HTMLForm $parent = null)
{
$field = parent::loadInputFromParameters($fieldname, $descriptor, $parent);
$field->setShowEmptyLabel(false);
return $field;
}
示例6: loadPreferenceValues
/**
* Loads existing values for a given array of preferences
* @throws MWException
* @param User $user
* @param IContextSource $context
* @param array $defaultPreferences Array to load values for
* @return array|null
*/
static function loadPreferenceValues($user, $context, &$defaultPreferences)
{
# # Remove preferences that wikis don't want to use
foreach ($context->getConfig()->get('HiddenPrefs') as $pref) {
if (isset($defaultPreferences[$pref])) {
unset($defaultPreferences[$pref]);
}
}
# # Make sure that form fields have their parent set. See bug 41337.
$dummyForm = new HTMLForm(array(), $context);
$disable = !$user->isAllowed('editmyoptions');
$defaultOptions = User::getDefaultOptions();
# # Prod in defaults from the user
foreach ($defaultPreferences as $name => &$info) {
$prefFromUser = self::getOptionFromUser($name, $info, $user);
if ($disable && !in_array($name, self::$saveBlacklist)) {
$info['disabled'] = 'disabled';
}
$field = HTMLForm::loadInputFromParameters($name, $info, $dummyForm);
// For validation
$globalDefault = isset($defaultOptions[$name]) ? $defaultOptions[$name] : null;
// If it validates, set it as the default
if (isset($info['default'])) {
// Already set, no problem
continue;
} elseif (!is_null($prefFromUser) && $field->validate($prefFromUser, $user->getOptions()) === true) {
$info['default'] = $prefFromUser;
} elseif ($field->validate($globalDefault, $user->getOptions()) === true) {
$info['default'] = $globalDefault;
} else {
throw new MWException("Global default '{$globalDefault}' is invalid for field {$name}");
}
}
return $defaultPreferences;
}
示例7: execute
/**
* Changes preferences of the current user.
*/
public function execute()
{
$user = $this->getUser();
if ($user->isAnon()) {
$this->dieUsage('Anonymous users cannot change preferences', 'notloggedin');
}
if (!$user->isAllowed('editmyoptions')) {
$this->dieUsage('You don\'t have permission to edit your options', 'permissiondenied');
}
$params = $this->extractRequestParams();
$changed = false;
if (isset($params['optionvalue']) && !isset($params['optionname'])) {
$this->dieUsageMsg(array('missingparam', 'optionname'));
}
// Load the user from the master to reduce CAS errors on double post (T95839)
if (wfGetLB()->getServerCount() > 1) {
$user = User::newFromId($user->getId());
if (!$user->loadFromId(User::READ_EXCLUSIVE)) {
$this->dieUsage('Anonymous users cannot change preferences', 'notloggedin');
}
}
if ($params['reset']) {
$user->resetOptions($params['resetkinds'], $this->getContext());
$changed = true;
}
$changes = array();
if (count($params['change'])) {
foreach ($params['change'] as $entry) {
$array = explode('=', $entry, 2);
$changes[$array[0]] = isset($array[1]) ? $array[1] : null;
}
}
if (isset($params['optionname'])) {
$newValue = isset($params['optionvalue']) ? $params['optionvalue'] : null;
$changes[$params['optionname']] = $newValue;
}
if (!$changed && !count($changes)) {
$this->dieUsage('No changes were requested', 'nochanges');
}
$prefs = Preferences::getPreferences($user, $this->getContext());
$prefsKinds = $user->getOptionKinds($this->getContext(), $changes);
$htmlForm = null;
foreach ($changes as $key => $value) {
switch ($prefsKinds[$key]) {
case 'registered':
// Regular option.
if ($htmlForm === null) {
// We need a dummy HTMLForm for the validate callback...
$htmlForm = new HTMLForm(array(), $this);
}
$field = HTMLForm::loadInputFromParameters($key, $prefs[$key]);
$field->mParent = $htmlForm;
$validation = $field->validate($value, $user->getOptions());
break;
case 'registered-multiselect':
case 'registered-checkmatrix':
// A key for a multiselect or checkmatrix option.
$validation = true;
$value = $value !== null ? (bool) $value : null;
break;
case 'userjs':
// Allow non-default preferences prefixed with 'userjs-', to be set by user scripts
if (strlen($key) > 255) {
$validation = "key too long (no more than 255 bytes allowed)";
} elseif (preg_match("/[^a-zA-Z0-9_-]/", $key) !== 0) {
$validation = "invalid key (only a-z, A-Z, 0-9, _, - allowed)";
} else {
$validation = true;
}
break;
case 'special':
$validation = "cannot be set by this module";
break;
case 'unused':
default:
$validation = "not a valid preference";
break;
}
if ($validation === true) {
$user->setOption($key, $value);
$changed = true;
} else {
$this->setWarning("Validation error for '{$key}': {$validation}");
}
}
if ($changed) {
// Commit changes
$user->saveSettings();
}
$this->getResult()->addValue(null, $this->getModuleName(), 'success');
}
示例8: execute
/**
* Changes preferences of the current user.
*/
public function execute()
{
$user = $this->getUser();
if ($user->isAnon()) {
$this->dieUsage('Anonymous users cannot change preferences', 'notloggedin');
}
$params = $this->extractRequestParams();
$changed = false;
if (isset($params['optionvalue']) && !isset($params['optionname'])) {
$this->dieUsageMsg(array('missingparam', 'optionname'));
}
if ($params['reset']) {
$user->resetOptions($params['resetkinds']);
$changed = true;
}
$changes = array();
if (count($params['change'])) {
foreach ($params['change'] as $entry) {
$array = explode('=', $entry, 2);
$changes[$array[0]] = isset($array[1]) ? $array[1] : null;
}
}
if (isset($params['optionname'])) {
$newValue = isset($params['optionvalue']) ? $params['optionvalue'] : null;
$changes[$params['optionname']] = $newValue;
}
if (!$changed && !count($changes)) {
$this->dieUsage('No changes were requested', 'nochanges');
}
$prefs = Preferences::getPreferences($user, $this->getContext());
$prefsKinds = $user->getOptionKinds($this->getContext(), $changes);
foreach ($changes as $key => $value) {
switch ($prefsKinds[$key]) {
case 'registered':
// Regular option.
$field = HTMLForm::loadInputFromParameters($key, $prefs[$key]);
$validation = $field->validate($value, $user->getOptions());
break;
case 'registered-multiselect':
case 'registered-checkmatrix':
// A key for a multiselect or checkmatrix option.
$validation = true;
$value = $value !== null ? (bool) $value : null;
break;
case 'userjs':
// Allow non-default preferences prefixed with 'userjs-', to be set by user scripts
if (strlen($key) > 255) {
$validation = "key too long (no more than 255 bytes allowed)";
} elseif (preg_match("/[^a-zA-Z0-9_-]/", $key) !== 0) {
$validation = "invalid key (only a-z, A-Z, 0-9, _, - allowed)";
} else {
$validation = true;
}
break;
case 'unused':
default:
$validation = "not a valid preference";
break;
}
if ($validation === true) {
$user->setOption($key, $value);
$changed = true;
} else {
$this->setWarning("Validation error for '{$key}': {$validation}");
}
}
if ($changed) {
// Commit changes
$user->saveSettings();
}
$this->getResult()->addValue(null, $this->getModuleName(), 'success');
}