From c37da687548589fa9222d968d495dcee02f5a524 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 23 May 2011 19:03:17 +0000 Subject: [PATCH] Revert r87964: destroyed standard segregation of non-view action links outside of $wgArticlePath, which would have created huge extra search spider traffic to sites and put more bogus URLs into indexes. This also reverts some convenience functions that were being added at the same time (??) to attempt to parse local links from JS. --- includes/Setup.php | 6 + includes/Title.php | 59 ++--- .../mediawiki.action.watch.ajax.js | 4 +- resources/mediawiki.util/mediawiki.util.js | 68 +---- tests/parser/parserTests.txt | 250 +++++++++--------- 5 files changed, 151 insertions(+), 236 deletions(-) diff --git a/includes/Setup.php b/includes/Setup.php index 2ae28adbf0..f343c49765 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -47,6 +47,12 @@ if ( !empty($wgActionPaths) && !isset($wgActionPaths['view']) ) { $wgActionPaths['view'] = $wgArticlePath; } +if ( !empty($wgActionPaths) && !isset($wgActionPaths['view']) ) { + # 'view' is assumed the default action path everywhere in the code + # but is rarely filled in $wgActionPaths + $wgActionPaths['view'] = $wgArticlePath ; +} + if ( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins"; if ( $wgLocalStylePath === false ) $wgLocalStylePath = "$wgScriptPath/skins"; if ( $wgStyleDirectory === false ) $wgStyleDirectory = "$IP/skins"; diff --git a/includes/Title.php b/includes/Title.php index 919cda27fd..b352169615 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -877,23 +877,30 @@ class Title { $url = str_replace( '$1', $dbkey, $wgArticlePath ); } } else { - $url = false; - global $wgActionPaths; - if( !empty( $wgActionPaths ) ) { - $url = Title::resolveActionPath( $dbkey, $query ); + $url = false; + $matches = array(); + if ( !empty( $wgActionPaths ) && + preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches ) ) + { + $action = urldecode( $matches[2] ); + if ( isset( $wgActionPaths[$action] ) ) { + $query = $matches[1]; + if ( isset( $matches[4] ) ) { + $query .= $matches[4]; + } + $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] ); + if ( $query != '' ) { + $url = wfAppendQuery( $url, $query ); + } + } } if ( $url === false ) { if ( $query == '-' ) { $query = ''; } - #$url = "{$wgScript}?title={$dbkey}&{$query}"; - # forge a nice URL (ex: /wiki/Special:Foo?q=1&r=2 ) - // @todo FIXME: This causes a 403 error for action=raw - // which disallows wgArticlePath access (bug 29088) - $baseurl = str_replace( '$1', $dbkey, $wgArticlePath ); - $url = wfAppendQuery( $baseurl, $query ); + $url = "{$wgScript}?title={$dbkey}&{$query}"; } } @@ -907,38 +914,6 @@ class Title { return $url; } - /** - * Helper for getLocalUrl() to handles $wgActionPaths - * - * @param $dbkey string Title in database key format - * @param $query string request parameters in CGI format (p=1&q=2&..) - * @return Url resolved or boolean false - */ - private static function resolveActionPath( $dbkey, $query ) { - $url = ''; - - # query parameters are easier to handle using an array: - $queryArray = wfCGIToArray( $query ); - - global $wgActionPaths; - if( !array_key_exists( 'action', $queryArray ) ) { - // Makes the default action 'view' and points to $wgArticlePath - // @todo FIXME: This should be handled in Setup or Wiki! - global $wgArticlePath; - $url = str_replace( '$1', $dbkey, $wgArticlePath ); - } elseif( isset( $wgActionPaths[$queryArray['action']] ) ) { - $url = str_replace( '$1', $dbkey, $wgActionPaths[$queryArray['action']] ); - } else { - # No path found - return false; - } - - # No need to append the action since we have embed it in the path - unset( $queryArray['action'] ); - $url = wfAppendQuery( $url, wfArrayToCGI( $queryArray ) ); - return $url; - } - /** * Get a URL that's the simplest URL that will be valid to link, locally, * to the current Title. It includes the fragment, but does not include diff --git a/resources/mediawiki.action/mediawiki.action.watch.ajax.js b/resources/mediawiki.action/mediawiki.action.watch.ajax.js index 19e6d1e6f1..93aa29c908 100644 --- a/resources/mediawiki.action/mediawiki.action.watch.ajax.js +++ b/resources/mediawiki.action/mediawiki.action.watch.ajax.js @@ -96,8 +96,8 @@ $( document ).ready( function() { var link = this; $link .data( 'icon', $link.closest( 'li' ).hasClass( 'icon' ) ) - .data( 'action', mw.util.getActionFrom( link.href ) == 'unwatch' ? 'unwatch' : 'watch' ); - var title = mw.util.getTitleFrom( link.href ); + .data( 'action', mw.util.getParamValue( 'action', link.href ) == 'unwatch' ? 'unwatch' : 'watch' ); + var title = mw.util.getParamValue( 'title', link.href ); $link.data( 'target', title.replace( /_/g, ' ' ) ); }); diff --git a/resources/mediawiki.util/mediawiki.util.js b/resources/mediawiki.util/mediawiki.util.js index a23af62c17..4917856569 100644 --- a/resources/mediawiki.util/mediawiki.util.js +++ b/resources/mediawiki.util/mediawiki.util.js @@ -215,12 +215,6 @@ /** * Grab the URL parameter value for the given parameter. * Returns null if not found. - * Beware! When action paths are enabled (wgActionPaths) using this function - * to retrieve the 'action' or 'title' parameter will probably fail since - * those parameters are hidden in the path. - * To safely query for: - * 'action' use getActionFrom( url ) - * 'title' use getTitleFrom( url ) * * @param param The parameter name * @param url URL to search through (optional) @@ -236,66 +230,6 @@ return null; }, - /** - * Try to find the wiki action for a given URL with actions paths support. - * Defaults to 'view'. - * - * @param url URL to search for a wiki action - * @return Action - */ - 'getActionFrom' : function( url ) { - // attempt to get the action from the parameter [&?]action= - var action = mw.util.getParamValue( 'action', url ); - if ( action !== null ) { - return action; - } - - // now from the action paths - var actionPaths = mw.config.get( 'wgActionPaths' ); - if ( actionPaths.length === 0 ) { - actionPaths.view = mw.config.get( 'wgArticlePath' ); - } - var actionRe; - for ( action in actionPaths ) { - actionRe = new RegExp( actionPaths[action].replace( '$1', '.*?' ) ); - if ( url.match( actionRe ) ) { - return action; - } - } - - return 'view'; - }, - - /** - * Try to find the wiki title for a given URL with actions paths support - * - * @param url URL to search for a title - * @return Title or null. - */ - 'getTitleFrom' : function( url ) { - // attempt to get the title from the parameter [&?]title= - var title = mw.util.getParamValue( 'title', url ); - if ( title !== null ) { - return title; - } - - // now from the action paths - var actionPaths = mw.config.get( 'wgActionPaths' ); - if ( actionPaths.length === 0 ) { - actionPaths.view = mw.config.get( 'wgArticlePath' ); - } - var action, actionRe; - for ( action in actionPaths ) { - actionRe = new RegExp( '.*' + actionPaths[action].replace( '$1', '([^&?#]+)' ) ); - title = url.match( actionRe ); - if ( title !== null ) { - return title[1]; - } - } - - return null; - }, - // Access key prefix. // Will be re-defined based on browser/operating system detection in // mw.util.init(). @@ -622,4 +556,4 @@ mw.util.init(); -} )( jQuery, mediaWiki ); +} )( jQuery, mediaWiki ); \ No newline at end of file diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index cdde746a0d..fc05d5b148 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -538,7 +538,7 @@ Definition list with wikilink containing colon !! input ; [[Help:FAQ]]: The least-read page on Wikipedia !! result -
Help:FAQ
The least-read page on Wikipedia +
Help:FAQ
The least-read page on Wikipedia
!! end @@ -971,7 +971,7 @@ External links: wiki links within external link (Bug 3695) !! input [http://example.com [[wikilink]] embedded in ext link] !! result -

wikilink embedded in ext link +

wikilink embedded in ext link

!! end @@ -1138,7 +1138,7 @@ External link containing double-single-quotes with no space separating the url f !! input [http://www.musee-picasso.fr/pages/page_id18528_u1l2.htm''La muerte de Casagemas'' (1901) en el sitio de [[Museo Picasso (París)|Museo Picasso]].] !! result -

La muerte de Casagemas (1901) en el sitio de Museo Picasso. +

La muerte de Casagemas (1901) en el sitio de Museo Picasso.

!! end @@ -1147,7 +1147,7 @@ URL-encoding in URL functions (single parameter) !! input {{localurl:Some page|amp=&}} !! result -

/wiki/Some_page?amp=& +

/index.php?title=Some_page&amp=&

!! end @@ -1156,7 +1156,7 @@ URL-encoding in URL functions (multiple parameters) !! input {{localurl:Some page|q=?&=&}} !! result -

/wiki/Some_page?q=?&amp=& +

/index.php?title=Some_page&q=?&amp=&

!! end @@ -1757,7 +1757,7 @@ Heading inside table (affected by r85922)
-

[edit] Heading

+

[edit] Heading

@@ -1938,7 +1938,7 @@ Broken link !! input [[Zigzagzogzagzig]] !! result -

Zigzagzogzagzig +

Zigzagzogzagzig

!! end @@ -1947,7 +1947,7 @@ Broken link with fragment !! input [[Zigzagzogzagzig#zug]] !! result -

Zigzagzogzagzig#zug +

Zigzagzogzagzig#zug

!! end @@ -2019,7 +2019,7 @@ Link to namespaces !! input [[Talk:Parser testing]], [[Meta:Disclaimers]] !! result -

Talk:Parser testing, Meta:Disclaimers +

Talk:Parser testing, Meta:Disclaimers

!! end @@ -2028,7 +2028,7 @@ Piped link to namespace !! input [[Meta:Disclaimers|The disclaimers]] !! result -

The disclaimers +

The disclaimers

!! end @@ -2046,7 +2046,7 @@ Link containing % (not as a hex sequence) !! input [[7% Solution]] !! result -

7% Solution +

7% Solution

!! end @@ -2055,7 +2055,7 @@ Link containing % as a single hex sequence interpreted to char !! input [[7%25 Solution]] !! result -

7% Solution +

7% Solution

!!end @@ -2092,7 +2092,7 @@ Link containing double-single-quotes '' (bug 4598) !! input [[Lista d''e paise d''o munno]] !! result -

Lista d''e paise d''o munno +

Lista d''e paise d''o munno

!! end @@ -2101,7 +2101,7 @@ Link containing double-single-quotes '' in text (bug 4598 sanity check) !! input Some [[Link|pretty ''italics'' and stuff]]! !! result -

Some pretty italics and stuff! +

Some pretty italics and stuff!

!! end @@ -2110,7 +2110,7 @@ Link containing double-single-quotes '' in text embedded in italics (bug 4598 sa !! input ''Some [[Link|pretty ''italics'' and stuff]]! !! result -

Some pretty italics and stuff! +

Some pretty italics and stuff!

!! end @@ -2125,10 +2125,10 @@ Link with double quotes in title part (literal) and alternate part (interpreted) [[''Pentecoste''|''Pentecoste'']] !! result -

File:Denys Savchenko Pentecoste.jpg -

''Pentecoste'' -

Pentecoste -

Pentecoste +

File:Denys Savchenko Pentecoste.jpg +

''Pentecoste'' +

Pentecoste +

Pentecoste

!! end @@ -2148,7 +2148,7 @@ Plain link to URL # ---- # I'm changing it to match the current output--it arguably makes more # sense in the light of the test above. Old expected result was: -#

Piped link to URL: an example URL +#

Piped link to URL: an example URL #

# But I think this test is bordering on "garbage in, garbage out" anyway. # -- wtm @@ -2267,7 +2267,7 @@ language=en !! input [[Something]]'nice !! result -

Something'nice +

Something'nice

!! end @@ -2278,7 +2278,7 @@ language=ca !! input [[Something]]'nice !! result -

Something'nice +

Something'nice

!! end @@ -2289,7 +2289,7 @@ language=kaa !! input [[Something]]'nice !! result -

Something'nice +

Something'nice

!! end @@ -2909,7 +2909,7 @@ Magic links: internal link to RFC (bug 479) !! input [[RFC 123]] !! result -

RFC 123 +

RFC 123

!! end @@ -2949,7 +2949,7 @@ Nonexistent template !! input {{thistemplatedoesnotexist}} !! result -

Template:Thistemplatedoesnotexist +

Template:Thistemplatedoesnotexist

!! end @@ -3131,7 +3131,7 @@ Template with thumb image (with link in description) {{paramtest| param =[[Image:noimage.png|thumb|[[no link|link]] [[no link|caption]]]]}} !! result -This is a test template with parameter +This is a test template with parameter !! end @@ -3435,8 +3435,8 @@ Bug 6563: Edit link generation for section shown by !! input {{includeonly section}} !! result -

[edit] Includeonly section

-

[edit] Section T-1

+

[edit] Includeonly section

+

[edit] Section T-1

!! end @@ -3462,7 +3462,7 @@ Bug 6563: Edit link generation for section suppressed by ==Section 1== !! result -

[edit] Section 1

+

[edit] Section 1

!! end @@ -4103,7 +4103,7 @@ Add test with existing image page !! input [[:Image:test]] !! result -

Image:test +

Image:test

!! end @@ -4112,7 +4112,7 @@ bug 18784 Link to non-existent image page with caption should use caption as li !! input [[:Image:test|caption]] !! result -

caption +

caption

!! end @@ -4239,7 +4239,7 @@ Image caption containing another image !! input [[Image:Foobar.jpg|thumb|This is a caption with another [[Image:icon.png|image]] inside it!]] !! result -
This is a caption with another image inside it!
+
This is a caption with another image inside it!
!! end @@ -4326,7 +4326,7 @@ Disabled subpages !! input [[/subpage]] !! result -

/subpage +

/subpage

!! end @@ -4337,7 +4337,7 @@ subpage title=[[Page]] !! input {{/Subpage}} !! result -

Page/Subpage +

Page/Subpage

!! end @@ -4407,13 +4407,13 @@ More ===Smaller headline=== Blah blah !! result -

[edit] Headline 1

+

[edit] Headline 1

Some text

-

[edit] Headline 2

+

[edit] Headline 2

More

-

[edit] Smaller headline

+

[edit] Smaller headline

Blah blah

!! end @@ -4452,14 +4452,14 @@ Some text -

[edit] Headline 1

-

[edit] Subheadline 1

-
[edit] Skipping a level
-
[edit] Skipping a level
-

[edit] Headline 2

+

[edit] Headline 1

+

[edit] Subheadline 1

+
[edit] Skipping a level
+
[edit] Skipping a level
+

[edit] Headline 2

Some text

-

[edit] Another headline

+

[edit] Another headline

!! end @@ -4507,16 +4507,16 @@ Handling of sections up to level 6 and beyond -

[edit] Level 1 Heading

-

[edit] Level 2 Heading

-

[edit] Level 3 Heading

-

[edit] Level 4 Heading

-
[edit] Level 5 Heading
-
[edit] Level 6 Heading
-
[edit] = Level 7 Heading=
-
[edit] == Level 8 Heading==
-
[edit] === Level 9 Heading===
-
[edit] ==== Level 10 Heading====
+

[edit] Level 1 Heading

+

[edit] Level 2 Heading

+

[edit] Level 3 Heading

+

[edit] Level 4 Heading

+
[edit] Level 5 Heading
+
[edit] Level 6 Heading
+
[edit] = Level 7 Heading=
+
[edit] == Level 8 Heading==
+
[edit] === Level 9 Heading===
+
[edit] ==== Level 10 Heading====
!! end @@ -4549,12 +4549,12 @@ TOC regression (bug 9764) -

[edit] title 1

-

[edit] title 1.1

-

[edit] title 1.1.1

-

[edit] title 1.2

-

[edit] title 2

-

[edit] title 2.1

+

[edit] title 1

+

[edit] title 1.1

+

[edit] title 1.1.1

+

[edit] title 1.2

+

[edit] title 2

+

[edit] title 2.1

!! end @@ -4585,12 +4585,12 @@ wgMaxTocLevel=3 -

[edit] title 1

-

[edit] title 1.1

-

[edit] title 1.1.1

-

[edit] title 1.2

-

[edit] title 2

-

[edit] title 2.1

+

[edit] title 1

+

[edit] title 1.1

+

[edit] title 1.1.1

+

[edit] title 1.2

+

[edit] title 2

+

[edit] title 2.1

!! end @@ -4615,11 +4615,11 @@ wgMaxTocLevel=3
  • 2 Section 2
  • -

    [edit] Section 1

    -

    [edit] Section 1.1

    -

    [edit] Section 1.1.1

    -

    [edit] Section 1.1.1.1

    -

    [edit] Section 2

    +

    [edit] Section 1

    +

    [edit] Section 1.1

    +

    [edit] Section 1.1.1

    +

    [edit] Section 1.1.1.1

    +

    [edit] Section 2

    !! end @@ -4630,8 +4630,8 @@ Resolving duplicate section names == Foo bar == == Foo bar == !! result -

    [edit] Foo bar

    -

    [edit] Foo bar

    +

    [edit] Foo bar

    +

    [edit] Foo bar

    !! end @@ -4641,8 +4641,8 @@ Resolving duplicate section names with differing case (bug 10721) == Foo bar == == Foo Bar == !! result -

    [edit] Foo bar

    -

    [edit] Foo Bar

    +

    [edit] Foo bar

    +

    [edit] Foo Bar

    !! end @@ -4661,10 +4661,10 @@ __NOTOC__ {{sections}} ==Section 4== !! result -

    [edit] Section 0

    -

    [edit] Section 1

    -

    [edit] Section 2

    -

    [edit] Section 4

    +

    [edit] Section 0

    +

    [edit] Section 1

    +

    [edit] Section 2

    +

    [edit] Section 4

    !! end @@ -4685,7 +4685,7 @@ Link inside a section heading !! input ==Section with a [[Main Page|link]] in it== !! result -

    [edit] Section with a link in it

    +

    [edit] Section with a link in it

    !! end @@ -4707,9 +4707,9 @@ __TOC__
  • 2 title 2
  • -

    [edit] title 1

    -

    [edit] title 1.1

    -

    [edit] title 2

    +

    [edit] title 1

    +

    [edit] title 1.1

    +

    [edit] title 2

    !! end @@ -4731,10 +4731,10 @@ The line above must have a trailing space! --> But just in case it doesn't... !! result -

    [edit] =

    +

    [edit] =

    The line above must have a trailing space!

    -

    [edit] =

    +

    [edit] =

    But just in case it doesn't...

    !! end @@ -4770,19 +4770,19 @@ section 5
  • 5 text " text
  • -

    [edit] text > text

    +

    [edit] text > text

    section 1

    -

    [edit] text < text

    +

    [edit] text < text

    section 2

    -

    [edit] text & text

    +

    [edit] text & text

    section 3

    -

    [edit] text ' text

    +

    [edit] text ' text

    section 4

    -

    [edit] text " text

    +

    [edit] text " text

    section 5

    !! end @@ -4971,7 +4971,7 @@ Media link to nonexistent file (bug 1702) !! input [[Media:No such.jpg]] !! result -

    Media:No such.jpg +

    Media:No such.jpg

    !! end @@ -4980,7 +4980,7 @@ Image link to nonexistent file (bug 1850 - good) !! input [[Image:No such.jpg]] !! result -

    File:No such.jpg +

    File:No such.jpg

    !! end @@ -4989,7 +4989,7 @@ Image link to nonexistent file (bug 1850 - good) !! input [[:Image:No such.jpg]] !! result -

    Image:No such.jpg +

    Image:No such.jpg

    !! end @@ -5988,7 +5988,7 @@ Fuzz testing: Parser14 == onmouseover= == http://__TOC__ !! result -

    [edit] onmouseover=

    +

    [edit] onmouseover=

    http://

    Contents