jenkins-bot has submitted this change and it was merged.

Change subject: Improve wiki selection
......................................................................


Improve wiki selection

* Accept domain names in wiki form
* Add a dropdown for "All wikis", "Current wiki", or "Specific wiki",
and add autocomplete of domain names in 'other' text box

Bug: 55703
Change-Id: I417490107414a8f2f310ab612e65da7c8f547b09
---
M backend/MWOAuthUtils.php
M control/MWOAuthConsumerSubmitControl.php
M frontend/MWOAuthUI.setup.php
M frontend/language/MWOAuth.i18n.php
A frontend/modules/ext.MWOAuth.WikiSelect.js
M frontend/specialpages/SpecialMWOAuthConsumerRegistration.php
6 files changed, 59 insertions(+), 2 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/backend/MWOAuthUtils.php b/backend/MWOAuthUtils.php
index 000a572..35dc53d 100644
--- a/backend/MWOAuthUtils.php
+++ b/backend/MWOAuthUtils.php
@@ -280,6 +280,23 @@
        }
 
        /**
+        * Get the pretty names of all local wikis
+        *
+        * @return associative array of local wiki names indexed by wiki ID
+        */
+       public static function getAllWikiNames() {
+               global $wgConf;
+               $wikiNames = array();
+               foreach ( $wgConf->getLocalDatabases() as $dbname ) {
+                       $name = self::getWikiIdName( $dbname );
+                       if ( $name != $dbname ) {
+                               $wikiNames[$dbname] = $name;
+                       }
+               }
+               return $wikiNames;
+       }
+
+       /**
         * Quickly get a new server with all the default configurations
         *
         * @return MWOAuthServer with default configurations
diff --git a/control/MWOAuthConsumerSubmitControl.php 
b/control/MWOAuthConsumerSubmitControl.php
index d49e550..9f9b222 100644
--- a/control/MWOAuthConsumerSubmitControl.php
+++ b/control/MWOAuthConsumerSubmitControl.php
@@ -68,7 +68,10 @@
                                        return Sanitizer::validateEmail( $s ); 
},
                                'wiki'         => function( $s ) {
                                        global $wgConf;
-                                       return in_array( $s, 
$wgConf->getLocalDatabases() ) || $s === '*'; },
+                                       return ( $s === '*'
+                                               || in_array( $s, 
$wgConf->getLocalDatabases() )
+                                               || array_search( $s, 
MWOAuthUtils::getAllWikiNames() ) !== false
+                                       ); },
                                'grants'       => function( $s ) {
                                        $grants = FormatJSON::decode( $s, true 
);
                                        return is_array( $grants ) && 
MWOAuthUtils::grantsAreValid( $grants );
@@ -158,6 +161,12 @@
                                return $this->failure( 'consumer_exists', 
'mwoauth-consumer-alreadyexists' );
                        }
 
+                       $wikiNames = MWOAuthUtils::getAllWikiNames();
+                       $dbKey = array_search( $this->vals['wiki'], $wikiNames 
);
+                       if ( $dbKey !== false ) {
+                               $this->vals['wiki'] = $dbKey;
+                       }
+
                        $curVer = $dbw->selectField( 
'oauth_registered_consumer',
                                'oarc_version',
                                array( 'oarc_name' => $this->vals['name'], 
'oarc_user_id' => $centralUserId ),
diff --git a/frontend/MWOAuthUI.setup.php b/frontend/MWOAuthUI.setup.php
index 63ca406..03907e8 100644
--- a/frontend/MWOAuthUI.setup.php
+++ b/frontend/MWOAuthUI.setup.php
@@ -37,6 +37,13 @@
                        'remoteExtPath' => 'OAuth/frontend/modules',
                        'messages'      => array( 'mwoauth-desc' )
                );
+               $wgResourceModules['ext.MWOAuth.WikiSelect'] = array(
+                       'scripts'       => array( 'ext.MWOAuth.WikiSelect.js' ),
+                       'dependencies'  => array( 'jquery.ui.autocomplete' ),
+                       'localBasePath' => dirname( __FILE__ ) . '/modules',
+                       'remoteExtPath' => 'OAuth/frontend/modules',
+                       'messages'      => array( 'mwoauth-desc' )
+               );
        }
 
        /**
diff --git a/frontend/language/MWOAuth.i18n.php 
b/frontend/language/MWOAuth.i18n.php
index 6211086..620d41d 100644
--- a/frontend/language/MWOAuth.i18n.php
+++ b/frontend/language/MWOAuth.i18n.php
@@ -39,6 +39,8 @@
        'mwoauth-consumer-grantsneeded' => 'Applicable grants:',
        'mwoauth-consumer-required-grant' => 'Applicable to consumer',
        'mwoauth-consumer-wiki' => 'Applicable wiki:',
+       'mwoauth-consumer-wiki-thiswiki' => 'Current wiki ($1)',
+       'mwoauth-consumer-wiki-other' => 'Specific wiki',
        'mwoauth-consumer-restrictions' => 'Usage restrictions:',
        'mwoauth-consumer-restrictions-json' => 'Usage restrictions (JSON):',
        'mwoauth-consumer-rsakey' => 'Public RSA key:',
@@ -414,6 +416,8 @@
        'mwoauth-consumer-required-grant' => 'Used as table column header.',
        'mwoauth-consumer-wiki' => 'Used as label for the input box. The 
default value for the input box is "*".
 {{Identical|Applicable wiki}}',
+       'mwoauth-consumer-wiki-thiswiki' => 'Label for selection-list option, 
indicating the wiki this user is currently visiting',
+       'mwoauth-consumer-wiki-other' => 'Label for selection-list option, 
indicating the user wants to type in another wiki\'s name',
        'mwoauth-consumer-restrictions' => 'Used as label for the textarea. 
(The value is written in JSON format.)
 
 Followed by the textarea or the message 
{{msg-mw|Mwoauthmanageconsumers-field-hidden}}.
diff --git a/frontend/modules/ext.MWOAuth.WikiSelect.js 
b/frontend/modules/ext.MWOAuth.WikiSelect.js
new file mode 100644
index 0000000..316c8b2
--- /dev/null
+++ b/frontend/modules/ext.MWOAuth.WikiSelect.js
@@ -0,0 +1,13 @@
+/**
+ * OAuth JavaScript
+ * @author Chris Steipp 2013
+ */
+( function( mw, $ ) {
+       $( document ).ready( function () {
+               if(window.mw){
+                       $( '#mw-input-wpwiki-other' ).autocomplete({
+                               source: mw.config.get( 'wgOAuthWikiList' )
+                       });
+               }
+       } );
+})( mediaWiki, jQuery );
diff --git a/frontend/specialpages/SpecialMWOAuthConsumerRegistration.php 
b/frontend/specialpages/SpecialMWOAuthConsumerRegistration.php
index 1453e93..8aa13ea 100644
--- a/frontend/specialpages/SpecialMWOAuthConsumerRegistration.php
+++ b/frontend/specialpages/SpecialMWOAuthConsumerRegistration.php
@@ -56,6 +56,8 @@
 
                $this->setHeaders();
                $this->getOutput()->disallowUserJs();
+               $this->getOutput()->addModules( 'ext.MWOAuth.WikiSelect' );
+               $this->getOutput()->addJsConfigVars( 'wgOAuthWikiList', 
array_values( MWOAuthUtils::getAllWikiNames() ) );
 
                $block = $user->getBlock();
                if ( $block ) {
@@ -111,7 +113,12 @@
                                                'required' => true
                                        ),
                                        'wiki' => array(
-                                               'type' => 'text',
+                                               'type' => 'selectorother',
+                                               'options' => array(
+                                                       wfMessage( 
'mwoauth-consumer-allwikis' )->escaped() => '*',
+                                                       wfMessage( 
'mwoauth-consumer-wiki-thiswiki', wfWikiID() )->escaped() => wfWikiID()
+                                               ),
+                                               'other' => wfMessage( 
'mwoauth-consumer-wiki-other' )->escaped(),
                                                'label-message' => 
'mwoauth-consumer-wiki',
                                                'required' => true,
                                                'default' => '*'

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I417490107414a8f2f310ab612e65da7c8f547b09
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/OAuth
Gerrit-Branch: master
Gerrit-Owner: CSteipp <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: CSteipp <[email protected]>
Gerrit-Reviewer: MZMcBride <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to