jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/326071 )

Change subject: Display search suggestions for special pages which take a user 
name as the parameter
......................................................................


Display search suggestions for special pages which take a user name as the 
parameter

And also for Special:TopUsersRecent.

Code sporked from core /includes/specials/SpecialUserrights.php for all
the other special pages but Special:TopUsersRecent.

A patch for Special:RemoveRelationship will be made as a follow-up,
to address potential performance concerns.

Change-Id: I3c6b56b0c263327181258bdadaff728161bf7863
---
M UserGifts/SpecialGiveGift.php
M UserProfile/SpecialRemoveAvatar.php
M UserRelationship/SpecialAddRelationship.php
M UserStats/TopFansRecent.php
4 files changed, 77 insertions(+), 8 deletions(-)

Approvals:
  Jack Phoenix: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/UserGifts/SpecialGiveGift.php b/UserGifts/SpecialGiveGift.php
index 57c6b2a..e7677bc 100644
--- a/UserGifts/SpecialGiveGift.php
+++ b/UserGifts/SpecialGiveGift.php
@@ -40,7 +40,7 @@
        /**
         * Show the special page
         *
-        * @param $par Mixed: parameter passed to the page or null
+        * @param string|null $par Name of the user whom to give a gift
         */
        public function execute( $par ) {
                global $wgMemc, $wgUploadPath;
@@ -61,13 +61,12 @@
                ] );
                $out->addModules( 'ext.socialprofile.usergifts.js' );
 
-               $userTitle = Title::newFromDBkey( $request->getVal( 'user' ) );
+               $userTitle = Title::makeTitle( NS_USER, $request->getVal( 
'user', $par ) );
                if ( !$userTitle ) {
                        $out->addHTML( $this->displayFormNoUser() );
                        return false;
                }
 
-               $user_title = Title::makeTitle( NS_USER, $request->getVal( 
'user' ) );
                $this->user_name_to = $userTitle->getText();
                $this->user_id_to = User::idFromName( $this->user_name_to );
                $giftId = $request->getInt( 'gift_id' );
@@ -139,7 +138,7 @@
                                $out->setPageTitle( $this->msg( 'g-sent-title', 
$this->user_name_to )->parse() );
 
                                $output .= '<div class="back-links">
-                                       <a href="' . htmlspecialchars( 
$user_title->getFullURL() ) . '">' .
+                                       <a href="' . htmlspecialchars( 
$userTitle->getFullURL() ) . '">' .
                                                $this->msg( 'g-back-link', 
$this->user_name_to )->parse() .
                                        '</a>
                                </div>
@@ -175,6 +174,24 @@
        }
 
        /**
+        * 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 );
+       }
+
+       /**
         * Display the form for sending out a single gift.
         * Relies on the gift_id URL parameter and bails out if it's not there.
         *
diff --git a/UserProfile/SpecialRemoveAvatar.php 
b/UserProfile/SpecialRemoveAvatar.php
index 7768e8c..36a8f07 100644
--- a/UserProfile/SpecialRemoveAvatar.php
+++ b/UserProfile/SpecialRemoveAvatar.php
@@ -46,7 +46,7 @@
        /**
         * Show the special page
         *
-        * @param $user Mixed: parameter passed to the page or null
+        * @param string|null $par Name of the user whose avatar we're removing
         */
        public function execute( $par ) {
                $out = $this->getOutput();
@@ -150,6 +150,28 @@
        }
 
        /**
+        * 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 [];
+               }
+               if ( $this->getUser()->isAllowed( 'avatarremove' ) ) {
+                       // Autocomplete subpage as user list - public to allow 
caching
+                       return UserNamePrefixSearch::search( 'public', $search, 
$limit, $offset );
+               } else {
+                       return [ $this->getUser()->getName() ];
+               }
+       }
+
+       /**
         * Show the form for retrieving a user's current avatar
         * @return HTML
         */
diff --git a/UserRelationship/SpecialAddRelationship.php 
b/UserRelationship/SpecialAddRelationship.php
index 96e5183..4125472 100644
--- a/UserRelationship/SpecialAddRelationship.php
+++ b/UserRelationship/SpecialAddRelationship.php
@@ -33,9 +33,9 @@
        /**
         * Show the special page
         *
-        * @param $params Mixed: parameter(s) passed to the page or null
+        * @param string|null $par Name of the user whom to remove as a 
friend/foe
         */
-       public function execute( $params ) {
+       public function execute( $par ) {
                $out = $this->getOutput();
                $request = $this->getRequest();
                $currentUser = $this->getUser();
@@ -49,7 +49,7 @@
                // Add CSS
                $out->addModuleStyles( 'ext.socialprofile.userrelationship.css' 
);
 
-               $userTitle = Title::newFromDBkey( $request->getVal( 'user' ) );
+               $userTitle = Title::newFromDBkey( $request->getVal( 'user', 
$par ) );
 
                if ( !$userTitle ) {
                        $out->setPageTitle( $this->msg( 'ur-error-title' ) );
@@ -225,6 +225,24 @@
        }
 
        /**
+        * 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 );
+       }
+
+       /**
         * Displays the form for adding a friend or a foe
         *
         * @return $form Mixed: HTML code for the form
diff --git a/UserStats/TopFansRecent.php b/UserStats/TopFansRecent.php
index 2d202c3..0d3d114 100644
--- a/UserStats/TopFansRecent.php
+++ b/UserStats/TopFansRecent.php
@@ -10,6 +10,18 @@
        }
 
        /**
+        * 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 ) {
+               return [ 'weekly', 'monthly' ];
+       }
+
+       /**
         * Show the special page
         *
         * @param string|null $par Period name, i.e. weekly or monthly (or null)

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I3c6b56b0c263327181258bdadaff728161bf7863
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/SocialProfile
Gerrit-Branch: master
Gerrit-Owner: Jack Phoenix <ash...@uncyclomedia.co>
Gerrit-Reviewer: Jack Phoenix <ash...@uncyclomedia.co>
Gerrit-Reviewer: Lewis Cawte <le...@lewiscawte.me>
Gerrit-Reviewer: SamanthaNguyen <samanthanguyen1...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to