Manual:$wgRequest

From MediaWiki.org
Jump to navigation Jump to search

Other languages:
Deutsch • ‎English • ‎dansk • ‎español • ‎français • ‎italiano • ‎polski • ‎português • ‎português do Brasil • ‎日本語

Overview[edit]

$wgRequest is used as a global singleton that contains an instance of the WebRequest class. The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form, handling removal of "magic quotes" slashes, stripping illegal input characters and normalizing Unicode sequences. See the WebRequest class documentation and Manual:WebRequest.php for more details.

Examples[edit]

This code can be useful within hook functions when you want to return without executing additional function code if the user is editing, rather than viewing, the current page.

global $wgRequest;
if ( $wgRequest->getText( 'action' ) == 'edit'  ) {
	return true;
}

Deprecation[edit]

As with other globals, the use of $wgRequest should be avoided when alternative methods are available. For example, when writing a special page, use the getRequest() method provided by the SpecialPage class, e.g.:

$request = $this->getRequest();

Accessing[edit]

Hook functions[edit]

When you work with various hooks you can usually get the WebRequest object from the context, for example:

$output->getRequest(); // here $output is an object of OutputPage class
$article->getContext()->getRequest(); // getting WebRequest from the Article object
$editpage->getArticle()->getContext()->getRequest(); // getting WebRequest from the EditPage object

Special pages[edit]

In a special page context, one can use $this->getRequest().

API modules[edit]

In an API module context, one can use $this->getMain()->getRequest().

See also[edit]