Manuel:$wgActions

From MediaWiki.org
Jump to navigation Jump to search
This page is a translated version of the page Manual:$wgActions and the translation is 75% complete.

Other languages:
Deutsch • ‎English • ‎español • ‎français • ‎italiano • ‎magyar • ‎polski • ‎português • ‎português do Brasil • ‎русский • ‎العربية • ‎中文 • ‎日本語
Accès: $wgActions
Tableau des valeurs permises pour le paramètre "action" des pages normales.
Introduit dans la version :1.18.0 (r86041)
Retiré dans la version :Encore utilisé
Valeurs autorisées :(tableau de correspondance chaînes vers booléen ou chaîne)
Valeur par défaut :voir ci-dessous
Autres paramètres : Alphabétique | Par Fonction

Détails

Tableau des valeurs permises pour le paramètre "action" des pages normales.

This method of defining custom actions replaces the deprecated UnknownAction hook. For details about how to migrate existing hook code to the class-based approach, see the migration section of the hook page .

La syntaxe est:

  • 'foo' => 'ClassName' - Charge la classe spécifiée qui sous-classe Action
  • 'foo' => true - Charge la classe FooAction qui sous-classe Action
  • 'foo' => false - L'action est désactivée; affiche un message d'erreur

Valeur par défaut

Version de MediaWiki : 1.19
$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,
);
Version de 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,
);

Example

There is a lot you can do with a custom action, and the best method of discovery is to browse the Action, FormAction and FormlessAction classes in the core MediaWiki code (as these are the classes you will be extending) and to look at examples of pages that provide similar function to what you require, either in the core or in stable and well-supported extensions.

The following example covers the most common use-case, namely generating a custom page for the action, possibly with some extra URL arguments.

// Register the action in the array of available actions.
// If you only need to support more recent versions of MediaWiki, register the action using
// extension.json, instead.
$wgActions['example_action'] = 'ExampleAction';

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 );
	}
}

Disable an action

To disable an action just add the following e.g. for the "raw" action to your "LocalSettings.php" file:

$wgActions['raw'] = false;
Les actions cœur non fixées provoqueront certainement des plaintes importantes.