Page MenuHomePhabricator

Using go button to go to empty userpage for existing user goes to search screen
Closed, ResolvedPublic

Description

Author: thuejk

Description:
Sometimes I will type fx "User:Thue" into the search/go box on the left hand
side, and in that case when I press the "go" button I expect to be taken to that
users userpage, whether it is blank or not. Especially I don't want to be taken
to the search screen if the user exists, which mediawiki currently does if the
userpage is blank.

Attached (hopefully...) is a patch that fixes this. It also fixes
-recognize IP numbers as "User:127.0.0.1" instead of just "127.0.0.1".
-recognize IP adresses and usernames even if they contain leading blankspace


Version: 1.4.x
Severity: normal
URL: N/A

Details

Reference
bz1398
TitleReferenceAuthorSource BranchDest Branch
envvars-api: fix bug in openapi schema pattern regexrepos/cloud/toolforge/envvars-api!9raymond-ndibeimprove_envvars_name_pattern_checkmain
Customize query in GitLab

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 8:09 PM
bzimport added a project: MediaWiki-Search.
bzimport set Reference to bz1398.
bzimport added a subscriber: Unknown Object (MLST).

thuejk wrote:

Patch to fix "go"-ing to a blank userpage

attachment userpage.diff ignored as obsolete

Commited to REL1_4 and HEAD and will be available in beta6.
Thanks for the patch !

I've reverted the patch for the moment as there are a number of problems with it.

  • It hard-codes the English string "user", and doesn't allow localized user namespaces.
  • Title::makeTitle doesn't perform validity checks as it's meant mainly for data pulled from the database which has been

previously screened. Use Title::makeTitleSafe().

  • The ereg_replace is a bit odd. Trimming of stray whitespace from the search term should be done at the top end in

SpecialSearch.php, not down there.

thuejk wrote:

Fix issues raised by Brion Vibber

*User namespace name internationalized.

*Actually I didn't insert the Title::makeTitle call; it was already there, but
this patch fixes it. It is guarded by a regexp comparison that ensured it could
only be an IP address, so it was probably safe anyway.

*Moved removal of leading blankspace all the way up to top of searchengine.php.
I looked down in the search code if there were any case where that might be a
problem because leading blankspace was really part of the search term, but that
doesn't seem to be the case. (it wouldn't make much sense either as far as I
can see)

attachment userpage_v2.diff ignored as obsolete

thuejk wrote:

Comment on attachment 255
Fix issues raised by Brion Vibber

diff -ur /home/thue/mediawiki/mediawiki-1.4beta5/includes/SearchEngine.php
wiki/includes/SearchEngine.php

  • /home/thue/mediawiki/mediawiki-1.4beta5/includes/SearchEngine.php

2004-12-26 06:03:48.000000000 +0100
+++ wiki/includes/SearchEngine.php 2005-02-03 17:35:57.000000000 +0100
@@ -45,6 +45,8 @@

  • @access private
	 */

function getNearMatch( $term ) {
+ global $wgContLang;
+

  1. Exact match? No need to look further.
		$title = Title::newFromText( $term );
		if (is_null($title))

@@ -75,11 +77,21 @@

			return $title;
		}

+

    1. Entering an IP address goes to the contributions page
  • if ( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/',

$term ) ) {

  • $title = Title::makeTitle( NS_SPECIAL, "Contributions/"

. $term );
+ $userprefixtext = $wgContLang->getNsText( NS_USER);
+ if ( preg_match(
"/^(${userprefixtext}:)?".'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/i', $term ) ) {
+ $title = Title::makeTitleSafe( NS_SPECIAL,
"Contributions/" . $term );

			return $title;
		}

+
+ # Entering a user goes to the user page whether it's there or
not
+ if ( preg_match( "/^${userprefixtext}:/i", $term ) ) {
+ if (User::idFromName($term)) {
+ $title = Title::newFromURL( $term );
+ return $title;
+ }
+ }

		return NULL;

}
diff -ur /home/thue/mediawiki/mediawiki-1.4beta5/includes/SpecialSearch.php
wiki/includes/SpecialSearch.php

  • /home/thue/mediawiki/mediawiki-1.4beta5/includes/SpecialSearch.php

2005-01-07 04:17:26.000000000 +0100
+++ wiki/includes/SpecialSearch.php 2005-02-03 17:47:04.000000000 +0100
@@ -29,6 +29,7 @@
global $wgRequest, $wgUser;

$search = $wgRequest->getText( 'search', $par );
+ $search = ereg_replace('[[:blank:]]*', '', $search);
$searchPage = new SpecialSearch( $wgRequest, $wgUser );
if( $wgRequest->getVal( 'fulltext' ) ||

		!is_null( $wgRequest->getVal( 'offset' ) ) ||

Please don't paste the code into the comment field; it clutters up the page.

As I understand it, this new code will accept _only_ the canonical localized form of the namespace. The
standard English names are always accepted in titles as alternates, and some languages may provide
alternates for some namespaces as well (for instance, with or without accept marks). It would be better to
simply make a title object and check if its namespace is NS_USER; this will allow the standard namespace
parsing code to do its thing.

As for the whitespace trimming; I would simply use the trim() function rather than the ereg_replace.

thuejk wrote:

Implement comments

Ok - now I am using all the right functions that already existed elsewhere. I
even tidied up the preexisting code by finding User::isIP().

I changed it back to using makeTitle() instead of makeTitleSafe() as I am now
using Title->getText() as input, which I assume is safe enough.

I did not mean to paste the previous patch into bugzilla - I had made an error
in the attached patch, and thought I could edit it in place, but bugzilla
surpriced me by creating it as a new comment.

Attached:

avarab wrote:

Applied to HEAD and REL1_4, thanks for the patch.