Last modified: 2010-05-15 15:33:53 UTC
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
Created attachment 217 [details] Patch to fix "go"-ing to a blank userpage
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.
Created attachment 255 [details] 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)
Comment on attachment 255 [details] 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; + # Exact match? No need to look further. $title = Title::newFromText( $term ); if (is_null($title)) @@ -75,11 +77,21 @@ return $title; } + # 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.
Created attachment 256 [details] 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.
Applied to HEAD and REL1_4, thanks for the patch.