Příručka:$wgActions

From mediawiki.org
This page is a translated version of the page Manual:$wgActions and the translation is 41% complete.
Akce: $wgActions
Pole povolených hodnot pro parametr "action" pro normální stránky.
Zavedeno od verze:1.18.0 (r86041)
Odstraněno od verze:stále se používá
Povolené hodnoty:(pole mapující řetězce na boolean nebo řetězec)
Výchozí hodnota:viz níže

Podrobnosti

Pole povolených hodnot pro parametr "action" pro normální stránky.

Syntaxe je:

  • 'foo' => 'ClassName' - Načte zadanou třídu, která má podtřídy Action
  • 'foo' => true - Načte třídu FooAction, která podtřídu Action
  • 'foo' => false - Akce je zakázána. Zobrazí chybovou zprávu

Výchozí hodnota

Since MediaWiki 1.37, core defaults are defined in ActionFactory.php.
Verze 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 = [];
Verze 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,
];
Verze 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,
];
Verze 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,
];
Verze 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,
);
Verze 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,
);

Příklad

S vlastní akcí můžete dělat hodně a nejlepší metodou, jak to zjistit, je procházet třídy Action, FormAction a FormlessAction v základním kódu MediaWiki (protože to jsou třídy, které budete rozšiřovat) a podívat se na příklady stránky, které poskytují podobnou funkci, jakou požadujete, buď v jádru, nebo ve stabilních a dobře podporovaných rozšířeních.

Následující příklad popisuje nejběžnější případ použití, jmenovitě vygenerování vlastní stránky pro akci, případně s některými dalšími argumenty adresy 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 );
	}
}

Zaregistrujte novou akci v extension.json (viz schéma extension.json ):

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

Zakázat akci

Chcete-li akci zakázat, stačí přidat následující, např. pro akci "raw" do vašeho souboru "LocalSettings.php":

$wgActions['raw'] = false;
Zrušení základních akcí pravděpodobně způsobí, že si věci budou hlasitě stěžovat.