Jump to content

手册:$wgActions

From mediawiki.org
This page is a translated version of the page Manual:$wgActions and the translation is 41% complete.
操作: $wgActions
正常页面的“action”参数的允许值的数组。正常页面的“action”参数的允许值的数组。
引进版本:1.18.0 (r86041)
移除版本:仍在使用
允许的值:(将字符串映射到布尔值或字符串的数组)
默认值:参见下方

详情

正常页面的“action”参数的允许值的数组。正常页面的“action”参数的允许值的数组。

語法:

  • 'foo' => 'ClassName' - 加载将Action 子类化的指定类
  • 'foo' => true - 加载将Action子类化的类FooAction
  • 'foo' => false - 如果该操作已禁用则显示错误消息

默认值

Since MediaWiki 1.37, core defaults are defined in ActionFactory.php.
MediaWiki版本:
1.37
/**
 * Array of allowed values for the "title=foo&action=<action>" parameter. See
 * ActionFactory for the syntax. Core defaults are in ActionFactory::CORE_ACTIONS,
 * anything here overrides that.
 */
$wgActions = [];
MediaWiki版本:
1.32 – 1.36
/**
 * Array of allowed values for the "title=foo&action=<action>" parameter. Syntax is:
 *     'foo' => 'ClassName'    Load the specified class which subclasses Action
 *     'foo' => true           Load the class FooAction which subclasses Action
 *                             If something is specified in the getActionOverrides()
 *                             of the relevant Page object it will be used
 *                             instead of the default class.
 *     'foo' => false          The action is disabled; show an error message
 * Unsetting core actions will probably cause things to complain loudly.
 */
$wgActions = [
	'credits' => true,
	'delete' => true,
	'edit' => true,
	'editchangetags' => SpecialPageAction::class,
	'history' => true,
	'info' => true,
	'markpatrolled' => true,
	'mcrundo' => McrUndoAction::class,
	'mcrrestore' => McrRestoreAction::class,
	'protect' => true,
	'purge' => true,
	'raw' => true,
	'render' => true,
	'revert' => true,
	'revisiondelete' => SpecialPageAction::class,
	'rollback' => true,
	'submit' => true,
	'unprotect' => true,
	'unwatch' => true,
	'view' => true,
	'watch' => true,
];
MediaWiki版本:
1.31
$wgActions = [
	'credits' => true,
	'delete' => true,
	'edit' => true,
	'editchangetags' => SpecialPageAction::class,
	'history' => true,
	'info' => true,
	'markpatrolled' => true,
	'protect' => true,
	'purge' => true,
	'raw' => true,
	'render' => true,
	'revert' => true,
	'revisiondelete' => SpecialPageAction::class,
	'rollback' => true,
	'submit' => true,
	'unprotect' => true,
	'unwatch' => true,
	'view' => true,
	'watch' => true,
];
MediaWiki版本:
1.25 – 1.30
$wgActions = [
	'credits' => true,
	'delete' => true,
	'edit' => true,
	'editchangetags' => 'SpecialPageAction',
	'history' => true,
	'info' => true,
	'markpatrolled' => true,
	'protect' => true,
	'purge' => true,
	'raw' => true,
	'render' => true,
	'revert' => true,
	'revisiondelete' => 'SpecialPageAction',
	'rollback' => true,
	'submit' => true,
	'unprotect' => true,
	'unwatch' => true,
	'view' => true,
	'watch' => true,
];
MediaWiki版本:
1.19 – 1.24
$wgActions = array(
	'credits' => true,
	'delete' => true,
	'edit' => true,
	'history' => true,
	'info' => true,
	'markpatrolled' => true,
	'protect' => true,
	'purge' => true,
	'raw' => true,
	'render' => true,
	'revert' => true,
	'revisiondelete' => true,
	'rollback' => true,
	'submit' => true,
	'unprotect' => true,
	'unwatch' => true,
	'view' => true,
	'watch' => true,
);
MediaWiki版本:
1.18
$wgActions = array(
	'credits' => true,
	'deletetrackback' => true,
	'info' => true,
	'markpatrolled' => true,
	'purge' => true,
	'revert' => true,
	'revisiondelete' => true,
	'rollback' => true,
	'unwatch' => true,
	'watch' => true,
);

示例

使用自定义操作可以做很多事情,最好的发现方法是浏览核心MediaWiki代码中的Action、FormAction和Formless Action类(因为这些是您将扩展的类),并查看提供与您所需相似功能的页面示例,无论是在核心中还是在稳定且支持良好的扩展中。

下面的示例涵盖了最常见的用例,即为操作生成一个定制页面,可能带有一些额外的URL参数。

class ExampleAction extends Action {

	// This action is called 'example_action'.  This class will only be invoked when the specified
	// action is requested.
	public function getName() {
		// This should be the same name as used when registering the action in $wgActions.
		return 'example_action';
	}

	// This is the function that is called whenever a page is being requested using this action.
	// You should not use globals $wgOut, $wgRequest, etc.  Instead, use the methods provided
	// by the Action class (e.g. $this->getOutput()), instead.
	public function show() {
		// Create local instances of the context variables we need, to simplify later code.
		$out = $this->getOutput();
		$request = $this->getRequest();

		// The view is the same for the main page and the talk page, so if we're on the
		// talk page then we need to change $Title to point to the subject page instead.
		$title = $this->page->getTitle();
		if ( $title->isTalkPage() ) {
			$title = $title->getSubjectPage();
		}

		// Set page title.
		$out->setPageTitle( 'Example Page Title' );

		// Get some parameters from the URL.
		$param = $request->getIntOrNull( 'example_param' );

		// Do some internal stuff to generate the content (placed in $output).

		// Output the results.
		$out->addHTML( $output );
		// or
		$out->addWikiText( $output );
	}
}

在extension.json中注册新操作(请参阅extension.json 架构):

	"Actions": {
		"example_action": "ExampleAction"
	},

禁用一个操作

要禁用某个操作,只需将“原始”操作的以下代码添加到“LocalSettings.php”文件中:

$wgActions['raw'] = false;
扰乱核心行动可能会导致事情大声抱怨。