示例#1
0
/**
 * Entry point that create the "Preferences" object
 */
function wfSpecialPreferences()
{
    global $wgRequest, $wgHooks;
    $wgHooks["pageTabs"][] = array("wfPreferencesTabs");
    $form = new PreferencesForm($wgRequest);
    $form->execute();
}
 /**
  * @param {String} $key valid key as specified in validTabs
  * @return {HtmlForm}
  */
 public function getPreferencesForm($key)
 {
     $prefs = array();
     $user = $this->getUser();
     $ctx = $this->getContext();
     switch ($key) {
         case 'personal':
             Preferences::profilePreferences($user, $ctx, $prefs);
             break;
         case 'skin':
             Preferences::skinPreferences($user, $ctx, $prefs);
             break;
         case 'dateformat':
             Preferences::datetimePreferences($user, $ctx, $prefs);
             break;
         case 'files':
             Preferences::filesPreferences($user, $ctx, $prefs);
             break;
         case 'rc':
             Preferences::rcPreferences($user, $ctx, $prefs);
             break;
     }
     Preferences::loadPreferenceValues($user, $ctx, $prefs);
     $htmlForm = new PreferencesForm($prefs, $ctx, 'prefs');
     $htmlForm->suppressReset();
     $htmlForm->setModifiedUser($user);
     $htmlForm->setId('mw-prefs-form');
     $htmlForm->setSubmitText($ctx->msg('saveprefs')->text());
     $htmlForm->setSubmitCallback(array('Preferences', 'tryUISubmit'));
     $htmlForm->setAction(SpecialPage::getTitleFor($this->getName(), $key)->getLocalUrl());
     return $htmlForm;
 }
示例#3
0
/**
 * Entry point that create the "Preferences" object
 */
function wfSpecialPreferences()
{
    global $wgRequest;
    $form = new PreferencesForm($wgRequest);
    $form->execute();
}
示例#4
0
 /**
  * Handle the form submission if everything validated properly
  *
  * @param array $formData
  * @param PreferencesForm $form
  * @return bool|Status|string
  */
 static function tryFormSubmit($formData, $form)
 {
     global $wgAuth;
     $user = $form->getModifiedUser();
     $hiddenPrefs = $form->getConfig()->get('HiddenPrefs');
     $result = true;
     if (!$user->isAllowedAny('editmyprivateinfo', 'editmyoptions')) {
         return Status::newFatal('mypreferencesprotected');
     }
     // Filter input
     foreach (array_keys($formData) as $name) {
         if (isset(self::$saveFilters[$name])) {
             $formData[$name] = call_user_func(self::$saveFilters[$name], $formData[$name], $formData);
         }
     }
     // Fortunately, the realname field is MUCH simpler
     // (not really "private", but still shouldn't be edited without permission)
     if (!in_array('realname', $hiddenPrefs) && $user->isAllowed('editmyprivateinfo') && array_key_exists('realname', $formData)) {
         $realName = $formData['realname'];
         $user->setRealName($realName);
     }
     if ($user->isAllowed('editmyoptions')) {
         foreach (self::$saveBlacklist as $b) {
             unset($formData[$b]);
         }
         # If users have saved a value for a preference which has subsequently been disabled
         # via $wgHiddenPrefs, we don't want to destroy that setting in case the preference
         # is subsequently re-enabled
         foreach ($hiddenPrefs 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);
         }
         // 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);
         }
         Hooks::run('PreferencesFormPreSave', array($formData, $form, $user, &$result));
     }
     $wgAuth->updateExternalDB($user);
     $user->saveSettings();
     return $result;
 }
示例#5
0
 static function getFormObject($user)
 {
     $formDescriptor = Preferences::getPreferences($user);
     $htmlForm = new PreferencesForm($formDescriptor, 'prefs');
     $htmlForm->setSubmitText(wfMsg('saveprefs'));
     $htmlForm->setTitle(SpecialPage::getTitleFor('Preferences'));
     $htmlForm->setSubmitID('prefsubmit');
     $htmlForm->setSubmitCallback(array('Preferences', 'tryFormSubmit'));
     return $htmlForm;
 }
 function mainPrefsForm($status, $message = '')
 {
     global $wgOut, $wgUser, $wgExtensionPreferences;
     wfProfileIn(__METHOD__);
     // first get original form, then hack into it new options
     parent::mainPrefsForm($status, $message);
     $html = $wgOut->getHTML();
     $wgOut->clearHTML();
     $sections = array();
     foreach ($wgExtensionPreferences as $p) {
         if (!isset($p['section']) || !$p['section']) {
             continue;
         }
         $section = $p['section'];
         $name = isset($p['name']) ? $p['name'] : '';
         $value = '';
         if ($name) {
             if (isset($p['load'])) {
                 $value = $p['load']($name);
             } else {
                 $value = $wgUser->getOption($name);
             }
         }
         if ($value === '' && isset($p['default'])) {
             $value = $p['default'];
         }
         $sectext = htmlspecialchars(wfMsg($section));
         $regex = "/(<fieldset>\\s*<legend>\\s*" . preg_quote($sectext) . "\\s*<\\/legend>.*?)(<\\/fieldset>)/s";
         // check if $section exists in prefs yet
         // cache the existence of sections
         if (!isset($sections[$section])) {
             $sections[$section] = true;
             if (!preg_match($regex, $html, $m)) {
                 // doesn't exist so add an empty section to end
                 $addhtml = "<fieldset><legend>{$sectext}</legend></fieldset>\n";
                 $html = preg_replace("/(<(div|table) id='prefsubmit'.*)/s", "{$addhtml} \$1", $html);
             }
         }
         $type = isset($p['type']) ? $p['type'] : PREF_USER_T;
         if (!empty($p['int-type'])) {
             $type = $p['int-type'];
         }
         $pos = isset($p['pos']) ? $p['pos'] : '';
         switch ($type) {
             case PREF_CUSTOM_HTML_T:
                 $addhtml = $p['html'];
                 break;
             case PREF_TOGGLE_T:
                 $addhtml = $this->getToggle($name);
                 break;
             case PREF_INT_T:
             case PREF_TEXT_T:
             case PREF_PASSWORD_T:
                 $size = isset($p['size']) && $p['size'] ? "size=\"{$p['size']}\"" : '';
                 $caption = isset($p['caption']) && $p['caption'] ? $p['caption'] : wfMsg($name);
                 if ($type == PREF_PASSWORD_T) {
                     $type = 'password';
                 } else {
                     $type = 'text';
                 }
                 if ($pos == 'first' || $pos == '') {
                     $addhtml = "\n<table>\n";
                 } else {
                     $addhtml = '';
                 }
                 $addhtml .= $this->addRow("<label for=\"{$name}\">{$caption}</label>", "<input type=\"{$type}\" id=\"{$name}\" name=\"{$name}\" value=\"{$value}\" {$size} />") . "\n";
                 if ($pos == 'last' || $pos == '') {
                     $addhtml .= "</table>\n";
                 }
                 break;
             case PREF_DROPDOWN_T:
                 $caption = isset($p['caption']) && $p['caption'] ? $p['caption'] : wfMsg($name);
                 $onchange = isset($p['onchange']) && $p['onchange'] ? " onchange='" . $p['onchange'] . "'" : '';
                 $row = "\n\t  <select id=\"{$name}\"{$onchange} name=\"{$name}\">\n";
                 $options = is_array($p['options']) ? $p['options'] : array();
                 foreach ($options as $option) {
                     $row .= "\t\t<option>{$option}</option>\n";
                 }
                 $row .= "\t  </select>";
                 if ($pos == 'first' || $pos == '') {
                     $addhtml = "\n<table>\n";
                 } else {
                     $addhtml = '';
                 }
                 $addhtml .= $this->addRow("<label for=\"{$name}\">{$caption}</label>", $row) . "\n";
                 if ($pos == 'last' || $pos == '') {
                     $addhtml .= "</table>\n";
                 }
                 break;
             case PREF_USER_T:
             default:
                 $addhtml = preg_replace("/@VALUE@/", $value, isset($p['html']) ? $p['html'] : '');
                 break;
         }
         // the section exists
         $html = preg_replace($regex, "\$1 {$addhtml} \$2", $html);
     }
     $wgOut->addHTML($html);
     // debugging
     //$wgOut->addHTML( $wgUser->encodeOptions() );
     wfProfileOut(__METHOD__);
 }