Jdlrobson has uploaded a new change for review.

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

Change subject: Allow rendering of each individual preference section
......................................................................

Allow rendering of each individual preference section

The entire preferences section is difficult to display in one go
on a mobile device. As a result our mobile users miss out on useful
features such as BetaFeatures and the ability to customise notifications
on Echo.

This change surfaces subsections of preferences.
e.g. http://localhost:8888/w/index.php/Special:Preferences/skin
http://localhost:8888/w/index.php/Special:Preferences/echo

Most importantly it makes it possible for the mobile skin to introduce
beta features.

Bug: T78186
Change-Id: I43885b1744809b798cf2f94caa1bd5ccfc20cf7c
---
M includes/specials/SpecialPreferences.php
1 file changed, 87 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/94/236194/1

diff --git a/includes/specials/SpecialPreferences.php 
b/includes/specials/SpecialPreferences.php
index f2a315e..a0f1a9a 100644
--- a/includes/specials/SpecialPreferences.php
+++ b/includes/specials/SpecialPreferences.php
@@ -29,6 +29,85 @@
 class SpecialPreferences extends SpecialPage {
        function __construct() {
                parent::__construct( 'Preferences' );
+               $this->validTabs = array(
+                       'profile',
+                       'rendering',
+                       'skin',
+                       'dateformat',
+                       'files',
+                       'editing',
+                       'rc',
+                       'personal',
+                       'misc',
+               );
+               $this->externalPrefs = array();
+       }
+
+       /**
+        * @param {String} $key valid key as specified in validTabs private 
property
+        * @return {HtmlForm}
+        */
+       public function getSectionPreferencesForm( $key ) {
+               $prefs = array();
+               $user = $this->getUser();
+               $ctx = $this->getContext();
+               switch ( $key ) {
+                       case 'rendering':
+                               Preferences::renderingPreferences( $user, $ctx, 
$prefs );
+                               break;
+                       case 'profile':
+                               Preferences::profilePreferences( $user, $ctx, 
$prefs );
+                               break;
+                       case 'skin':
+                               Preferences::skinPreferences( $user, $ctx, 
$prefs );
+                               break;
+                       case 'dateformat':
+                               Preferences::datetimePreferences( $user, $ctx, 
$prefs );
+                               break;
+                       case 'editing':
+                               Preferences::editingPreferences( $user, $ctx, 
$prefs );
+                               break;
+                       case 'personal':
+                               Preferences::profilePreferences( $user, $ctx, 
$prefs );
+                               break;
+                       case 'files':
+                               Preferences::filesPreferences( $user, $ctx, 
$prefs );
+                               break;
+                       case 'rc':
+                               Preferences::rcPreferences( $user, $ctx, $prefs 
);
+                               break;
+                       default:
+                               $prefs = $this->externalPrefs[$key];
+                               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->setAction( SpecialPage::getTitleFor( 
$this->getName(), $key )->getLocalUrl() );
+               return $htmlForm;
+       }
+
+       /**
+        * Runs GetPreferences hook and constructs a mechanism for rendering 
preferences from other extensions as a
+        * separate preference pane.
+        */
+       public function loadExternalPreferences() {
+               $defaults = array();
+               Hooks::run( 'GetPreferences', array( $this->getUser(), 
&$defaults ) );
+               $this->externalPrefs = $defaults;
+               foreach( $defaults as $key => $row ) {
+                       if ( isset( $row["section"] ) ) {
+                               $section = explode( '/', $row["section"] )[0];
+                               if ( !in_array( $section, $this->validTabs ) ) {
+                                       $this->validTabs[]  = $section;
+                                       $this->externalPrefs[$section] = 
array();
+                               }
+                               $this->externalPrefs[$section][$key] = $row;
+                       }
+               }
        }
 
        public function execute( $par ) {
@@ -61,12 +140,18 @@
 
                $this->addHelpLink( 'Help:Preferences' );
 
-               $htmlForm = Preferences::getFormObject( $this->getUser(), 
$this->getContext() );
+               $this->loadExternalPreferences();
+
+               if ( $par && in_array( $par, $this->validTabs ) ) {
+                       $htmlForm = $this->getSectionPreferencesForm( $par );
+               } else {
+                       $htmlForm = Preferences::getFormObject( 
$this->getUser(), $this->getContext() );
+               }
                $htmlForm->setSubmitCallback( array( 'Preferences', 
'tryUISubmit' ) );
 
                $htmlForm->show();
        }
-
+       
        private function showResetForm() {
                if ( !$this->getUser()->isAllowed( 'editmyoptions' ) ) {
                        throw new PermissionsError( 'editmyoptions' );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I43885b1744809b798cf2f94caa1bd5ccfc20cf7c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
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