Page MenuHomePhabricator

Root /Foo style article paths and action paths conflict
Open, MediumPublic

Description

It seams that root urls and action paths can have a bit of a conflict:

Under this setup:
$wgArticlePath = "/$1";
$wgActionPaths['edit'] = "/edit/$1";

Our code inside WebRequest.php parses the article path first, as a result the edit url /edit/Foo is interpreted as the article [[Edit/Foo]].

We may want to re-order the way we parse paths inside WebRequest.

Or perhaps we should replace the way we parse WebRequest sequentially with a system that will give more specific paths dominance.

ie: If we have /* and /edit/* then /edit/* will win out over /* because it's more dominant. An unlikely circumstance like $wgActionPath = "/wiki/*" and $wgArticlePath['render'] = "/*"; would work if we went based on specificity instead of sequential parsing order.


Version: unspecified
Severity: normal

Details

Reference
bz32621

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:58 PM
bzimport set Reference to bz32621.
bzimport added a subscriber: Unknown Object (MLST).

"edit/Foo" is a legitimate page name (especially if $wgCapitalLinks is disabled)... this sort of thing is one of the reasons we recommend against putting your article and other spaces in the same place. :)

But if folks do do this, swapping the order to recognize action paths first is probably better behavior for most cases.

MediaWiki wrote:

As of r104385 action paths defined in $wgActionPaths are still being intercepted as article titles.

Setting $wgActionPaths['edit'] = "/edit/$1": Page is treated as if the title is "Edit/$1", and displayed (though non-existent).

Setting above plus $wgActionPaths['view'] = "/view/$1": Redirect loop to "/view/View/View/View/View/View/View/View/View/View/View/View/View/View/View/View/View/View/View/View/View/View/$1"

I might not be setting the options correctly; my article-path-related LocalSettings.php code is below. Leaving as Resolved Fixed for now.

  1. The URL base path to the directory containing the wiki;
  2. defaults for all runtime URL paths are based off of this.
  3. For more information on customizing the URLs please see:
  4. http://www.mediawiki.org/wiki/Manual:Short_URL

$wgScriptPath = "";
$wgScriptExtension = ".php";
$wgScript = "$wgScriptPath/index.php";
$wgArticlePath = "/$1";

Action paths

$actions = array( /*'view', causes redirect loop*/ 'edit', 'watch', 'unwatch', 'delete','revert', 'rollback',

'protect', 'unprotect', 'markpatrolled', 'render', 'submit', 'history', 'purge' );

foreach ( $actions as $action ) {

$wgActionPaths[$action] = "/$action/$1";

}
// $wgArticlePath = $wgActionPaths['view']; # causes redirect loop

r104274 is breaking all non-English languages and may need to be reverted.

There were talks to replace actions with special pages at some point, am I mistaken? is it planned? it sounds like a way to fix this issue.

Sorry for resurrecting this. I was reading https://www.mediawiki.org/wiki/Manual:Wiki_in_site_root_directory which advises against short URLs like example.com/pagename and which mentions this Phabricator task.

This intrigued me so I tried it out. I was able to set up action paths on my wiki without any problems at all. I've confirmed that /watch/Test_page, /unwatch/Test_page, /edit/Test_page and /view/Test_page work as expected. So does /Test_page as usual.

As advised in https://www.mediawiki.org/wiki/Manual:$wgActionPaths I added the following to LocalSettings.php:

$actions = array( 'view', 'edit', 'watch', 'unwatch', 'delete','revert', 'rollback',
  'protect', 'unprotect', 'markpatrolled', 'render', 'submit', 'history', 'purge', 'info' );

foreach ( $actions as $action ) {
  $wgActionPaths[$action] = "/$action/$1";
}

Neither of the following steps (which are mentioned on the manual page) were necessary:

  • $wgArticlePath = $wgActionPaths['view']; in LocalSettings.php.
  • RewriteRule ^/([a-z]*)/(.*)$ %{DOCUMENT_ROOT}/w/index.php [L,QSA] in .htaccess.

In case it helps, here are extracts from my LocalSettings.php:

$wgScriptPath ="";
$wgArticlePath = "/$1";

And from .htaccess:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/index.php [L]