Руководство:$wgActionPaths
| URL-адреса серверов и пути к файлам: $wgActionPaths | |
|---|---|
| Пути для разного рода пользовательских действий. Позволяют сокращать URL. |
|
| Введено в версии: | 1.5.0 (r7538) |
| Удалено в версии: | всё ещё используется |
| Допустимые значения: | не определено |
| Значение по умолчанию: | [] |
| Другие настройки: По алфавиту | По функциональности | |
Подробности
Чтобы использовать «красивые» пути URL вместо обычных просмотров страниц, добавляйте элементы в этот массив.
Например:
$wgActionPaths['edit'] = "$wgScriptPath/edit/1ドル";
В дополнение к задании этой переменной вам нужно внедрить соответствующий сценарий или серверное правило, чтобы обрабатывать эти URL.
Пример настроек
Эти примеры включают демонстрационные файлы .htaccess для серверов Apache с использованием mod_rewrite.
У другого серверного ПО должны быть другие способы задания переписывания (rewrite) URL.
Пути действия из корневого каталога
Здесь задаются пути действия, например http://mywiki.example.com/edit/Cucumber и прочие.
- LocalSettings.php
$actions = [ 'view', 'edit', 'watch', 'unwatch', 'delete', 'revert', 'rollback', 'protect', 'unprotect', 'markpatrolled', 'render', 'submit', 'history', 'purge', 'info', ]; foreach ( $actions as $action ) { $wgActionPaths[$action] = "/$action/1ドル"; } $wgArticlePath = $wgActionPaths['view'];
Дополнительные htaccess правила
- .htaccess
- Не забудьте изменить «/w/index.php» на ваш путь установки MediaWiki
RewriteRule^/([a-z]*)/(.*)$%{DOCUMENT_ROOT}/w/index.php[L,QSA]
Действие в конце ссылки
This sets up action paths of the form http://mywiki.example.com/Cucumber/edit etc.
$actions = [ 'edit', 'watch', 'unwatch', 'delete', 'revert', 'rollback', 'protect', 'unprotect', 'markpatrolled', 'render', 'submit', 'history', 'purge', 'info', ]; foreach ( $actions as $action ) { $wgActionPaths[$action] = "/1ドル/$action"; } $wgActionPaths['view'] = "/1ドル"; $wgArticlePath = $wgActionPaths['view'];
Некорневые пути действия
Для переписывания стандартного пути example.com/wiki/Main_Page на example.com/wiki/view/Main_Page используйте вышеприведённый файл конфигурации и измените эту строку, добавив в неё «/wiki»:
foreach ( $actions as $action ) { $wgActionPaths[$action] = "/wiki/$action/1ドル"; }
Для использования стандартных URL просмотра example.com/wiki/Main_Page и переписывания URL редактирования на example.com/wiki/edit/Main_Page
$actions = [ 'edit', 'watch', 'unwatch', 'delete', 'revert', 'rollback', 'protect', 'unprotect', 'markpatrolled', 'render', 'submit', 'history', 'purge', 'info', ]; foreach ( $actions as $action ) { $wgActionPaths[$action] = "/wiki/$action/1ドル"; } $wgActionPaths['view'] = "/wiki/1ドル"; $wgArticlePath = $wgActionPaths['view'];
action at the end
For standard example.com/wiki/Main_Page view urls, and rewrites to example.com/wiki/Main_Page/edit
$actions = [ 'view', 'edit', 'watch', 'unwatch', 'delete', 'revert', 'rollback', 'protect', 'unprotect', 'markpatrolled', 'render', 'submit', 'history', 'purge', 'info', ]; foreach ( $actions as $action ) { $wgActionPaths[$action] = "/wiki/1ドル/$action"; } $wgActionPaths['view'] = "/wiki/1ドル"; $wgArticlePath = $wgActionPaths['view'];
Virtual action / directories
This sets up URLs such as http://mywiki.example.com/wiki/action/edit/Cucumber etc.
To rewrite most[1] actions to a specific path, one could make the following changes to LocalSettings.php :
$actions = [ 'view', 'edit', 'watch', 'unwatch', 'delete', 'revert', 'rollback', 'protect', 'unprotect', 'markpatrolled', 'render', 'submit', 'history', 'purge', 'info', ]; 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]. См. также bugzilla:21617.
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.
- ↑ It is currently not possible to have a $wgActionPath for the 'raw' action.