Allow preferences that need not be rendered in Special:Preferences
authorSanthosh Thottingal <santhosh.thottingal@gmail.com>
Fri, 7 Dec 2012 07:22:10 +0000 (12:52 +0530)
committerSiebrand Mazeland <s.mazeland@xs4all.nl>
Mon, 7 Jan 2013 13:07:43 +0000 (14:07 +0100)
Extensions can use their own interface for user preferences, with the
help of the action=options API.

For example, Universal Language Selector has a different UI to
allow anonymous and logged in users to set language related preferences.

Validation for the preference values is up to the extensions.

Change-Id: I18a5ffb5cc202c59ba76b86cfb63e49010cc1881

RELEASE-NOTES-1.21
includes/AutoLoader.php
includes/HTMLForm.php
includes/Preferences.php

index e5e5c68..2e33247 100644 (file)
@@ -71,6 +71,8 @@ production.
 * Added GetDoubleUnderscoreIDs hook, for modifying the list of magic words.
 * DatabaseUpdater class has two new methods to ease extensions schema changes:
   dropExtensionIndex and renameExtensionIndex.
+* New preference type - 'api'. Preferences of this type are not shown on
+  Special:Preferences, but are still available via the action=options API.
 
 === Bug fixes in 1.21 ===
 * (bug 40353) SpecialDoubleRedirect should support interwiki redirects.
index fd34590..5c06a62 100644 (file)
@@ -115,6 +115,7 @@ $wgAutoloadLocalClasses = array(
        'HistoryBlobStub' => 'includes/HistoryBlob.php',
        'Hooks' => 'includes/Hooks.php',
        'Html' => 'includes/Html.php',
+       'HTMLApiField' => 'includes/HTMLForm.php',
        'HTMLCheckField' => 'includes/HTMLForm.php',
        'HTMLEditTools' => 'includes/HTMLForm.php',
        'HTMLFloatField' => 'includes/HTMLForm.php',
index ef24b62..952022f 100644 (file)
@@ -96,6 +96,7 @@ class HTMLForm extends ContextSource {
 
        // A mapping of 'type' inputs onto standard HTMLFormField subclasses
        static $typeMappings = array(
+               'api' => 'HTMLApiField',
                'text' => 'HTMLTextField',
                'textarea' => 'HTMLTextAreaField',
                'select' => 'HTMLSelectField',
@@ -2429,3 +2430,21 @@ class HTMLEditTools extends HTMLFormField {
                return $msg;
        }
 }
+
+class HTMLApiField extends HTMLFormField {
+       public function getTableRow( $value ) {
+               return '';
+       }
+
+       public function getDiv( $value ) {
+               return $this->getTableRow( $value );
+       }
+
+       public function getRaw( $value ) {
+               return $this->getTableRow( $value );
+       }
+
+       public function getInputHTML( $value ) {
+               return '';
+       }
+}
index 96d9e6d..e41fbc0 100644 (file)
@@ -1240,6 +1240,13 @@ class Preferences {
                        $formDescriptor = array_diff_key( $formDescriptor, $removeKeys );
                }
 
+               // Remove type=api preferences. They are not intended for rendering in the form.
+               foreach ( $formDescriptor as $name => $info ) {
+                       if ( isset( $info['type'] ) && $info['type'] === 'api' ) {
+                               unset( $formDescriptor[$name] );
+                       }
+               }
+
                /**
                 * @var $htmlForm PreferencesForm
                 */