From 8cc0fbb52dc919b3876c9afe6edbd96fad6b0adb Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Fri, 7 Dec 2012 12:52:10 +0530 Subject: [PATCH] Allow preferences that need not be rendered in Special:Preferences 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 | 2 ++ includes/AutoLoader.php | 1 + includes/HTMLForm.php | 19 +++++++++++++++++++ includes/Preferences.php | 7 +++++++ 4 files changed, 29 insertions(+) diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21 index e5e5c6880e..2e33247e37 100644 --- a/RELEASE-NOTES-1.21 +++ b/RELEASE-NOTES-1.21 @@ -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. diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index fd3459063a..5c06a62553 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -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', diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php index ef24b62b26..952022f4bb 100644 --- a/includes/HTMLForm.php +++ b/includes/HTMLForm.php @@ -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 ''; + } +} diff --git a/includes/Preferences.php b/includes/Preferences.php index 96d9e6d15a..e41fbc0392 100644 --- a/includes/Preferences.php +++ b/includes/Preferences.php @@ -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 */ -- 2.20.1