Topic on Project:Support desk

Using flagged revisions with shortened urls

7
Manifestation (talkcontribs)

I installed MediaWiki on my laptop. I also installed the FlaggedRevs extension, which worked. Then I implemented url shortening, and FlaggedRevs didn't like that.

My .htaccess has this:

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d

RewriteRule ^(.*)$ w/index.php?title=$1 [L,QSA]
RewriteRule ^$ w/index.php [L,QSA]

My LocalSettings.php has this:

$wgScriptPath = "/w";
$wgArticlePath = "/$1";
$wgScriptExtension = ".php";
$wgUsePathInfo = true;

$wgServer = "http://localhost";

$wgResourceBasePath = $wgScriptPath;

$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";
}

So, my urls look like this:

http://localhost/Main_Page
http://localhost/edit/Main_Page
http://localhost/history/Talk:Main_Page
etc.

All works fine, but when I try to approve a pending revision, it fails. My browser's console shows a 404 on this url: http://localhost/w/rest.php/flaggedrevs/internal/review/Main_Page

As it turns out, my wiki literally tries to load an article named "W/rest.php/flaggedrevs/internal/review/Main Page". In other words, FlaggedRevs does not load rest.php, and instead tries loading an unexisting wiki article. This of course causes FlaggedRevs to fail.

I tried hardcoding rest.php into .htaccess, explicitly instructing the server to access rest.php when asked, not a wiki page. Emphasis added:

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d

RewriteRule ^w/rest.php/(.*)$ w/rest.php/$1 [L,QSA]
RewriteRule ^(.*)$ w/index.php?title=$1 [L,QSA]
RewriteRule ^$ w/index.php [L,QSA]

This does not work. What am I doing wrong?

Jonathan3 (talkcontribs)
Manifestation (talkcontribs)

@Jonathan3: If I change $wgScriptPath to "", it breaks my wiki.

I installed MediaWiki in the "/w" directory.

Manifestation (talkcontribs)

I just discovered something. Inserting "/wiki/" into the url fixes the problem! 😲

.htaccess:

(...)
RewriteRule ^wiki/(.*)$ w/index.php?title=$1 [L,QSA]
RewriteRule ^wiki$ w/index.php [L,QSA]
RewriteRule ^$ w/index.php [L,QSA]

LocalSettings.php:

$wgArticlePath = "/wiki/$1";

(...)

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

Is this why all Wikimedia wikis have this stupid "wiki/" bit in their urls???

Why would you want the word "wiki" in the url of a wiki?!

Manifestation (talkcontribs)

A small addition:

As you can read above, I kind of 'fixed' the problem by making the URLs less pretty. But then I ran into another problem: FlaggedRevs did not work on subpages. For example: "Main_Page/test". If I choose "Accept revision" on that page, it failed. The browser's console showed a 404 when rest.php was called.

The reason: Apache *by default* does not accept encoded forward slashes ("/"), probably due to some security reason. The titles of subpages have encoded forward slashes when sent to the rest api, so Apache refused them.

The solution: add AllowEncodedSlashes NoDecode to httpd.conf. You should put it in the <VirtualHost>. If your Apache server does not have any, you can add this at the end of the file:

<VirtualHost *:80>
    AllowEncodedSlashes NoDecode
</VirtualHost>

Don't forget to reboot.

I have left a note about this at Extension talk:FlaggedRevs.

Manifestation (talkcontribs)

Ok, thanks to Stack Overflow, I have now definitely fixed this issue. The solution is this (emphasis added):

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/w/rest\.php
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d

RewriteRule ^(.*)$ w/index.php?title=$1 [L,QSA]
RewriteRule ^$ w/index.php [L,QSA]

Combined, of course, with the "AllowEncodedSlashes NoDecode" directive described above, plus the appropriate lines in LocalSettings.

Jonathan3 (talkcontribs)

There is no very good reason to have the "wiki" part - see Manual:Wiki in site root directory.

I think you solved the problem by matching $wgArticlePath with your URL structure, i.e. now you are using "wiki" in the URL and have "wiki" in $wgArticlePath. I think you could remove "wiki" from both.

Reply to "Using flagged revisions with shortened urls"