Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/159514

Change subject: WIP: Preference search
......................................................................

WIP: Preference search

TODO:
* Bug 70670
* Search section headings as well when looking for preferences
* Give indication of whether preference saved successfully or not.

Change-Id: Ic0c463b51d3dcc6b7e58448c911b12d1caf05ead
---
M MobileFrontend.php
M includes/MobileFrontend.hooks.php
M includes/Resources.php
A includes/specials/SpecialMobilePreferences.php
M javascripts/specials/preferences.js
5 files changed, 82 insertions(+), 50 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/14/159514/1

diff --git a/MobileFrontend.php b/MobileFrontend.php
index 825737b..3eeac16 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -63,6 +63,7 @@
 
        'MobileSiteModule' => 'modules/MobileSiteModule',
 
+       'SpecialMobilePreferences' => 'specials/SpecialMobilePreferences',
        'SpecialMobileWebApp' => 'specials/SpecialMobileWebApp',
        'SpecialUploads' => 'specials/SpecialUploads',
        'SpecialUserProfile' => 'specials/SpecialUserProfile',
diff --git a/includes/MobileFrontend.hooks.php 
b/includes/MobileFrontend.hooks.php
index 4f942c3..922efed 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -328,6 +328,7 @@
                if ( $ctx->shouldDisplayMobileView() ) {
                        // Replace the standard watchlist view with our custom 
one
                        $list['Watchlist'] = 'SpecialMobileWatchlist';
+                       $list['Preferences'] = 'SpecialMobilePreferences';
 
                        /* Special:MobileContributions redefines 
Special:History in
                         * such a way that for Special:Contributions/Foo, Foo 
is a
diff --git a/includes/Resources.php b/includes/Resources.php
index b575ad1..f090d29 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -1139,9 +1139,13 @@
        ),
 
        'skins.minerva.special.preferences.scripts' => 
$wgMFMobileSpecialPageResourceBoilerplate + array(
+               'dependencies' => array(
+                       'mediawiki.api',
+               ),
                'scripts' => array(
                        'javascripts/specials/preferences.js',
                ),
+               'position' => 'top',
        ),
 
        'skins.minerva.special.search.styles' => 
$wgMFMobileSpecialPageResourceBoilerplate + array(
diff --git a/includes/specials/SpecialMobilePreferences.php 
b/includes/specials/SpecialMobilePreferences.php
new file mode 100644
index 0000000..c824695
--- /dev/null
+++ b/includes/specials/SpecialMobilePreferences.php
@@ -0,0 +1,15 @@
+<?php
+/**
+ * MobileSpecialPageFeed.php
+ */
+
+/**
+ * This is an abstract class intended for use by special pages that consist 
primarily of
+ * a list of pages, for example, Special:Watchlist or Special:History.
+ */
+class SpecialMobilePreferences extends SpecialPreferences {
+       /**  @var boolean $showUsername Whether to show the username in results 
or not */
+       public function execute( $par ) {
+               parent::execute( $par );
+       }
+}
diff --git a/javascripts/specials/preferences.js 
b/javascripts/specials/preferences.js
index fe69f21..4f765d6 100644
--- a/javascripts/specials/preferences.js
+++ b/javascripts/specials/preferences.js
@@ -1,55 +1,66 @@
 jQuery( function( $ ) {
-var $header, $tabHeadings, $tabs, $activeBtn, val,
-       $form = $( '#mw-prefs-form' ),
-       action = $form.attr( 'action' ),
-       // Load from user preference if available
-       hash = window.location.hash;
+       var
+               api = new mw.Api(),
+               $form = $( '#content form' ),
+               query,
+               $input = $( '<input type="search" class="mw-ui-input">' ),
+               selector = [
+                       '.mw-htmlform-field-HTMLTextField',
+                       '.mw-htmlform-field-HTMLInfoField',
+                       '.mw-htmlform-field-HTMLSelectField',
+                       '.mw-htmlform-field-HTMLRadioField',
+                       '.mw-htmlform-field-HTMLCheckField',
+                       '.mw-htmlform-field-HTMLCheckMatrix',
+                       '.mw-htmlform-field-HTMLIntField',
+                       '.mw-htmlform-field-HTMLFloatField',
+                       '.mw-htmlform-field-HTMLSelectOrOtherField'
+               ].join( ',' );
 
-$header = $( '<div class="content-header">' ).insertBefore( '#content' );
-$tabHeadings = $( '<ul class="button-bar">' ).appendTo( $header );
-$tabs = $( '#preferences > fieldset' );
-
-function handler( ev ) {
-       var $this = $( this ),
-               hash = $this.attr( 'href' );
-       // Ensure that the browser does not jump to the section in the DOM
-       ev.preventDefault();
-       // However make sure the address bar changes
-       window.location.hash = hash;
-       $tabs.hide();
-       $tabHeadings.find( '.active' ).removeClass( 'active' );
-       $this.parent().addClass( 'active' );
-       $this.data( 'tab' ).show();
-       // Ensure on a save the hash is passed.
-       $form.attr( 'action', action + hash );
-}
-
-$tabs.each( function() {
-       var $this = $( this ),
-               legend = $this.find( 'legend' ).eq( 0 ),
-               $li = $( '<li>' ).appendTo( $tabHeadings ),
-               id = $this.attr( 'id' );
-
-       $( '<a class="button">' ).attr( 'href', '#' + id ).
-               data( 'tab', $this ).text( legend.text() ).
-               on( 'click', handler ).appendTo( $li );
-} );
-$tabs.hide();
-
-// Preserve active tab when switching from another skin to Minerva
-// FIXME: [Core] this is a terrible abuse of the web.
-if ( !hash && window.sessionStorage ) {
-       val = window.sessionStorage.getItem( 'mediawikiPreferencesTab' );
-       if ( val ) {
-               hash = '#mw-prefsection-' + val;
+       function hideFields( $el ) {
+               $el.hide();
+               $el.parents( 'fieldset' ).hide();
        }
-}
 
-$activeBtn = $tabHeadings.find( '[href="' + hash + '"]' );
-if ( $activeBtn.length === 0 ) {
-       // click the first tab button
-       $tabHeadings.find( '.button' ).eq( 0 ).trigger( 'click' );
-} else {
-       $activeBtn.trigger( 'click' );
-}
+       function showFields( $el ) {
+               $el.show();
+               $el.parents( 'fieldset' ).show();
+       }
+
+       function searchPreferences() {
+               window.clearTimeout( query );
+               window.setTimeout( function() {
+                       var val = $input.val().toLowerCase(),
+                               $fields = $( selector );
+                       hideFields( $fields );
+
+                       if ( val ) {
+                               $fields.each( function() {
+                                       var $this = $( this ),
+                                               label = $this.find( '.mw-label' 
).text().toLowerCase();
+
+                                       if ( label.indexOf( val ) > -1 ) {
+                                               showFields( $this );
+                                       }
+                               } );
+                       }
+               }, 100 );
+       }
+
+       $input.
+               on( 'keypress', searchPreferences ).
+               attr( 'placeholder', 'Search for a preference' ).
+               insertBefore( $form );
+
+       $form.find( 'fieldset' ).hide();
+       $form.find( selector ).hide();
+       // Remove things that do not make sense in this interface.
+       $form.find( 
'.htmlform-tip,.mw-prefs-buttons,.mw-htmlform-field-HTMLInfoField' ).remove();
+       $form.find( 'input,select' ).on( 'change', function() {
+               var $this = $( this );
+               api.postWithToken( 'options', {
+                       action: 'options',
+                       optionname: $this.attr( 'name' ).substr( 2 ),
+                       optionvalue: $this.val()
+               } );
+       } );
 } );

-- 
To view, visit https://gerrit.wikimedia.org/r/159514
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic0c463b51d3dcc6b7e58448c911b12d1caf05ead
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to