Manual:$wgActionPaths

From MediaWiki.org
Jump to: navigation, search
Paths: $wgActionPaths
Paths for various user actions. Used to 'pretty' URLs.
Introduced in version: 1.5.0 (r7538)
Removed in version: still in use
Allowed values:
Default value: array()

Other settings: Alphabetical | By Function


Contents

[edit] Details

To set 'pretty' URL paths for actions other than plain page views, add to this array. For instance:

 'edit' => "$wgScriptPath/edit/$1"

There must be an appropriate script or rewrite rule in place to handle these URLs.

[edit] Rewrite rules

This option needs an appropriate rewrite rule to work.

To rewrite most[1] actions to a specific path, one could make the following changes to LocalSettings.php:

$actions = array( 'view', 'edit', 'watch', 'unwatch', 'delete','revert', 'rollback',
  'protect', 'unprotect', 'markpatrolled', 'render', 'submit', 'history', 'purge' );
 
foreach ( $actions as $action ) {
  $wgActionPaths[$action] = "$wgScriptPath/action/$action/$1";
}
$wgArticlePath = $wgActionPaths['view'];

In Apache, code a rewrite rule similar to the following:

RewriteRule ^/action/([a-z]*)/(.*)$ /index.php [L,QSA]

This will forward all requests to /action/actionword/title to MediaWiki's index.php which will parse the action and title according to your $wgActionPaths settings.

When configuring Apache mod_negotation to execute PHP scripts when using this method care should be taken not to cause 406 Not Acceptable errors that might in some cases expose a directory listing, see [1], [2]. See also bugzilla:21617.

[edit] Clean action paths from root

LocalSettings.php
$actions = array( 'view', 'edit', 'watch', 'unwatch', 'delete','revert', 'rollback',
  'protect', 'unprotect', 'markpatrolled', 'render', 'submit', 'history', 'purge' );
 
foreach ( $actions as $action ) {
  $wgActionPaths[$action] = "/$action/$1";
}
$wgArticlePath = $wgActionPaths['view'];
.htaccess
Be sure to modify "/mediawiki/index.php" to where you have MediaWiki installed
RewriteRule ^/([a-z]*)/(.*)$ /mediawiki/index.php [L,QSA]

[edit] Spam prevention

Using $wgActionPaths, especially for the edit action seems to reduce the number of spam bots attempting article edits. It is suspected that bots are programmed to look for action=edit to identify a MediaWiki installation and act appropriately. With this in mind, it would be beneficial to name your action prefix something non-apparent so bots can't find your site when they start looking for action/edit.

  1. It is currently not possible to have a $wgActionPath for the 'raw' action.
Language: English  • Français • 日本語
Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox