[Mediawiki-l] Creating a custom Preferences tab (UserToggles hook)?

Daniel Barrett danb at VistaPrint.com
Wed Nov 14 20:20:20 UTC 2007


I am creating a custom Preferences tab with a checkbox, and it's ALMOST
working.  I'm sure I'm missing something simple... any guidance?

The behavior is:

*	The new tab appears
*	It contains a checkbox, "Test checkbox"
*	When I click "Save" for the first time, the value gets properly
saved in the database, with a value of zero
*	When I toggle the checkbox and Save again, the value "1" is
properly written to the database
*	BUT..... the value remains "1" in the database, no matter what
else I do: toggling, saving, etc.

Here is the very short code:

$wgMyFunkyPreferences = new MyFunkyPreferences();

class MyFunkyPreferences {
  public function __construct() {
    global $wgHooks;
    $wgHooks['RenderPreferencesForm'][] = array($this, 'render');
    $wgHooks['UserToggles'][] = array($this, 'toggle');
  }

  function render($form, $out) {
    $out->addHTML('<fieldset><legend>My Tab</legend>');
    $out->addHTML($form->getToggle('mytoggle'));
    $out->addHTML('</fieldset>');
    return true;
  }

  function toggle($extraToggles) {
    global $wgMessageCache;
    $extraToggles[] = 'mytoggle';
    $wgMessageCache->addMessage('tog-mytoggle', 'Test checkbox');
    return true;
  }
}

Thank you,
DanB



More information about the MediaWiki-l mailing list