Manual:$wgOut

From MediaWiki.org
Jump to: navigation, search

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

Details[edit | edit source]

The OutputPage object is output variable that can be modified to change rendering of the page. It encapsulates the entire HTML page that will be sent in response to any server request.

The OutputPage object is used by calling its functions to add text, headers, etc., in any order, and then calling output() to send it all. The OutputPage object also conducts the output encoding.

Examples[edit | edit source]

For example, you can add debug information.

global $wgOut;
$wgOut->mDebugtext .= "This is debug text";

(If using the default MonoBook skin, you will need to uncomment the line "$this->text( 'debug' );" in MonoBook.php)

Other examples of using $wgOut:

$wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
$wgOut->setRobotpolicy( 'noindex,nofollow' );
$wgOut->setArticleRelated( false );
$wgOut->addWikiText( $msg );
$wgOut->addWikiMsg( 'descriptionpage' );
$wgOut->addHTML( '<script src="/w/index.php?title=User:Example&amp;action=raw"></script>' );
$wgOut->getPageTitle();
 
// Get all categories of the current page: 
$title = Title::newFromText( $wgOut->getPageTitle() );
$title->getParentCategories();
 
// Perform a 302 redirect to the same page with a parameter added to the query string:
$wgOut->redirect( $this->getTitle()->getLocalUrl( "foo=$bar" ) );

Deprecation[edit | edit source]

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

$output = $this->getOutput();
$output->addWikiText ( 'Hello world!' );

See also[edit | edit source]