Jack Phoenix has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/366300 )
Change subject: [WIP] Fix the US state selector on
Special:EditProfile/Special:UpdateProfile
......................................................................
[WIP] Fix the US state selector on Special:EditProfile/Special:UpdateProfile
Also adds search subpage suggestions support for Special:EditProfile, e.g.
searching for "Special:EditProfile/J" suggests
Special:EditProfile/JackTest, Special:EditProfile/Jack Phoenix, etc.
Change-Id: I0888a32c0de7ca2698d3d36b8b67690f077e239d
---
M UserProfile/SpecialEditProfile.php
M UserProfile/SpecialUpdateProfile.php
M UserProfile/UpdateProfile.js
M UserProfile/UserProfile.php
4 files changed, 53 insertions(+), 28 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SocialProfile
refs/changes/00/366300/1
diff --git a/UserProfile/SpecialEditProfile.php
b/UserProfile/SpecialEditProfile.php
index 4a8489e..326778f 100644
--- a/UserProfile/SpecialEditProfile.php
+++ b/UserProfile/SpecialEditProfile.php
@@ -252,11 +252,10 @@
<p class="profile-update-unit-left"
id="location_state_label">' . $this->msg( 'user-profile-personal-country'
)->plain() . '</p>';
$form .= '<p class="profile-update-unit">';
$form .= '<span id="location_state_form">';
- $form .= "</span>
- <script type=\"text/javascript\">
- displaySection(\"location_state\",\"" .
$location_country . "\",\"" . ( isset( $location_state ) ? $location_state : ''
) . "\");
- </script>";
- $form .= "<select name=\"location_country\"
id=\"location_country\"
onchange=\"displaySection('location_state',this.value,'')\"><option></option>";
+ $form .= '</span>';
+ // Hidden helper for UpdateProfile.js since JS cannot directly
access PHP variables
+ $form .= '<input type="hidden" id="location_state_current"
value="' . ( isset( $location_state ) ? $location_state : '' ) . '" />';
+ $form .= '<select name="location_country"
id="location_country"><option></option>';
foreach ( $countries as $country ) {
$form .= "<option value=\"{$country}\"" . ( ( $country
== $location_country ) ? ' selected="selected"' : '' ) . ">";
@@ -277,11 +276,10 @@
<p class="profile-update-unit-left"
id="hometown_state_label">' . $this->msg( 'user-profile-personal-country'
)->plain() . '</p>
<p class="profile-update-unit">';
$form .= '<span id="hometown_state_form">';
- $form .= "</span>
- <script type=\"text/javascript\">
- displaySection(\"hometown_state\",\"" .
$hometown_country . "\",\"" . ( isset( $hometown_state ) ? $hometown_state : ''
) . "\");
- </script>";
- $form .= "<select name=\"hometown_country\"
id=\"hometown_country\"
onchange=\"displaySection('hometown_state',this.value,'')\"><option></option>";
+ $form .= '</span>';
+ // Hidden helper for UpdateProfile.js since JS cannot directly
access PHP variables
+ $form .= '<input type="hidden" id="hometown_state_current"
value="' . ( isset( $hometown_state ) ? $hometown_state : '' ) . '" />';
+ $form .= '<select name="hometown_country"
id="hometown_country"><option></option>';
foreach ( $countries as $country ) {
$form .= "<option value=\"{$country}\"" . ( ( $country
== $hometown_country ) ? ' selected="selected"' : '' ) . ">";
@@ -505,4 +503,23 @@
return $form;
}
+
+ /**
+ * Return an array of subpages beginning with $search that this special
page will accept.
+ *
+ * @param string $search Prefix to search for
+ * @param int $limit Maximum number of results to return (usually 10)
+ * @param int $offset Number of results to skip (usually 0)
+ * @return string[] Matching subpages
+ */
+ public function prefixSearchSubpages( $search, $limit, $offset ) {
+ $user = User::newFromName( $search );
+ if ( !$user ) {
+ // No prefix suggestion for invalid user
+ return [];
+ }
+ // Autocomplete subpage as user list - public to allow caching
+ return UserNamePrefixSearch::search( 'public', $search, $limit,
$offset );
+ }
+
}
diff --git a/UserProfile/SpecialUpdateProfile.php
b/UserProfile/SpecialUpdateProfile.php
index 4379ceb..428e3d9 100644
--- a/UserProfile/SpecialUpdateProfile.php
+++ b/UserProfile/SpecialUpdateProfile.php
@@ -546,12 +546,11 @@
<div class="visualClear">' . $this->renderEye(
'up_location_city' ) . '</div>
<p class="profile-update-unit-left"
id="location_state_label">' . $this->msg( 'user-profile-personal-country'
)->plain() . '</p>';
$form .= '<p class="profile-update-unit">';
+ // Hidden helper for UpdateProfile.js since JS cannot directly
access PHP variables
+ $form .= '<input type="hidden" id="location_state_current"
value="' . ( isset( $location_state ) ? $location_state : '' ) . '" />';
$form .= '<span id="location_state_form">';
- $form .= "</span>
- <script type=\"text/javascript\">
- displaySection(\"location_state\",\"" .
$location_country . "\",\"" . ( isset( $location_state ) ? $location_state : ''
) . "\");
- </script>";
- $form .= "<select name=\"location_country\"
id=\"location_country\"
onchange=\"displaySection('location_state',this.value,'')\"><option></option>";
+ $form .= '</span>';
+ $form .= '<select name="location_country"
id="location_country"><option></option>';
foreach ( $countries as $country ) {
$form .= "<option value=\"{$country}\"" . ( ( $country
== $location_country ) ? ' selected="selected"' : '' ) . ">";
@@ -572,11 +571,10 @@
<p class="profile-update-unit-left"
id="hometown_state_label">' . $this->msg( 'user-profile-personal-country'
)->plain() . '</p>
<p class="profile-update-unit">';
$form .= '<span id="hometown_state_form">';
- $form .= "</span>
- <script type=\"text/javascript\">
- displaySection(\"hometown_state\",\"" .
$hometown_country . "\",\"" . ( isset( $hometown_state ) ? $hometown_state : ''
) . "\");
- </script>";
- $form .= "<select name=\"hometown_country\"
id=\"hometown_country\"
onchange=\"displaySection('hometown_state',this.value,'')\"><option></option>";
+ $form .= '</span>';
+ // Hidden helper for UpdateProfile.js since JS cannot directly
access PHP variables
+ $form .= '<input type="hidden" id="hometown_state_current"
value="' . ( isset( $hometown_state ) ? $hometown_state : '' ) . '" />';
+ $form .= '<select name="hometown_country"
id="hometown_country"><option></option>';
foreach ( $countries as $country ) {
$form .= "<option value=\"{$country}\"" . ( ( $country
== $hometown_country ) ? ' selected="selected"' : '' ) . ">";
diff --git a/UserProfile/UpdateProfile.js b/UserProfile/UpdateProfile.js
index e58762c..27aedb4 100644
--- a/UserProfile/UpdateProfile.js
+++ b/UserProfile/UpdateProfile.js
@@ -43,17 +43,27 @@
document.getElementById( id + '_form' ).innerHTML = section_select;
}
-mediaWiki.loader.using( 'jquery.ui.datepicker', function() {
- jQuery( function( jQuery ) {
- jQuery( '#birthday' ).datepicker( {
- changeYear: true,
- yearRange: '1930:c',
- dateFormat: jQuery( '#birthday' ).hasClass(
'long-birthday' ) ? 'mm/dd/yy' : 'mm/dd'
- } );
+jQuery( function( jQuery ) {
+ jQuery( '#birthday' ).datepicker( {
+ changeYear: true,
+ yearRange: '1930:c',
+ dateFormat: jQuery( '#birthday' ).hasClass( 'long-birthday' ) ?
'mm/dd/yy' : 'mm/dd'
} );
} );
$( function() {
+ // US state selector
+ displaySection( 'location_state', $( '#location_country' ).val(), $(
'#location_state_current' ).val() );
+ $( '#location_country' ).on( 'change', function () {
+ displaySection( 'location_state', this.value, '' );
+ } );
+
+ displaySection( 'hometown_state', $( '#hometown_country' ).val(), $(
'#hometown_state_current' ).val() );
+ $( '#hometown_state' ).on( 'change', function () {
+ displaySection( 'hometown_state', this.value, '' );
+ } );
+
+ // Profile visibility stuff
$( '.eye-container' ).on( {
'mouseenter': function() {
if ( $( this ).css( 'position' ) !== 'absolute' ) {
diff --git a/UserProfile/UserProfile.php b/UserProfile/UserProfile.php
index 506b322..a6dc033 100644
--- a/UserProfile/UserProfile.php
+++ b/UserProfile/UserProfile.php
@@ -89,7 +89,7 @@
// Modules for Special:EditProfile/Special:UpdateProfile
$wgResourceModules['ext.userProfile.updateProfile'] = array(
'scripts' => 'UpdateProfile.js',
- 'dependencies' => 'mediawiki.util',
+ 'dependencies' => array( 'mediawiki.util', 'jquery.ui.datepicker' ),
'localBasePath' => __DIR__,
'remoteExtPath' => 'SocialProfile/UserProfile',
'position' => 'top'
--
To view, visit https://gerrit.wikimedia.org/r/366300
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0888a32c0de7ca2698d3d36b8b67690f077e239d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SocialProfile
Gerrit-Branch: master
Gerrit-Owner: Jack Phoenix <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits