Manual:OutputPage.php

From MediaWiki.org
Jump to: navigation, search


The OutputPage object takes care of generating HTML and other things related to creating a HTML-view of a page. It will also generate the <head> element for non-SkinTemplate skins or part of it for SkinTemplate based skins.

An instance of this class is located in $wgOut.

Methods[edit | edit source]

Output HTML[edit | edit source]

  • output(): called from function finalCleanup() in Wiki.php. It calls function outputPage() in Skin.php.
  • out($string): called from function outputPage() in Skin.php a number of times to send the HTML to the user: $mBodytext and HTML before and after it.

Generate HTML[edit | edit source]

  • addWikiText($txt): parses wikitext and adds it to the HTML stored in that object. There are also variants of this function to choose the Title used to parse the wikitext or to choose whether the html should be parsed with HTML tidy.
  • addWikiMsg($name, [$arg1, ...]) (since 1.12.0): adds the content of the message to the HTML after parsing it.
  • prependHTML($text): prepends $text (HTML) to the body HTML.
  • addPrimaryWikiText($text) (deprecated, use Article::outputWikitext()) which:
    • applies function parse() in Parser.php to the wikitext $text, resulting in the HTML text $text
    • applies function addParserOutput() to the HTML text $text, which:
    • applies function addHTML() to $text, which appends $text to $mBodytext.

JavaScript and CSS[edit | edit source]

  • addJsConfigVars($keys,[$value]): adds one or more variables to be set in mw.config in JavaScript. $keys can be an array of key/value pairs. If $keys is a string it is used as key and $value must be set. Using this method is ideal if you have a direct correlation between a module added to the page and information the module needs (e.g. an OutputPage::addModules call and OutputPage::addJsConfigVars go well together). However if you're exporting generic information for a lot (if not, all) pages (in which case you likely don't have a reference to an OutputPage instance) then you should use the MakeGlobalVariablesScript hook instead. To add mw.config variables that are site-wide and do not depend on page or user, then use the ResourceLoaderGetConfigVars hook instead. Though use the latter sparingly as it adds weight to the startup module. Also beware of caching since this (depending on the wiki's cache configuration) this may be only refreshed when the wiki page associated with the OutputPage is modified.
  • addInlineScript($script): add a self-contained script tag with the given contents.
  • addInlineStyle($style_css, [$flip]): adds inline CSS styles. Set $flip to 'flip' to flip the CSS if needed (for RTL support). Defaults to 'noflip'.
  • addModules($modules): Add one or more modules recognized by the Resource Loader. Module CSS and JavaScript added through this function will be loaded by the resource loader when the page loads as a combined JavaScript and CSS package, thus the user's browser must enable JavaScript. $modules can be a module name (string) or an array of module names.
  • addModuleScripts($modules): Add only JavaScript of one or more modules recognized by the Resource Loader. Module scripts added through this function will be loaded by the resource loader when the page loads. $modules can be a module name (string) or an array of module names.
  • addModuleStyles($modules): Add only CSS of one or more modules recognized by the Resource Loader. Module styles added through this function will be added using standard link CSS tags, rather than as a combined Javascript and CSS package. Thus, they will load even if the user's browser disables JavaScript (unless the browser also disables CSS). $modules can be a module name (string) or an array of module names.
  • disallowUserJs(): do not allow scripts which can be modified by wiki users to load on this page: only allow scripts bundled with, or generated by, the software. For security reasons scripts which can be modified by users should not be loaded on some pages, for example a login page.

Other functions[edit | edit source]

  • setTitle($title): set the title to use to the Title object $title.
  • setPageTitle($name): sets the contents of <h1> and <title> to $name. $name can either be a String or a Message object. When $name is a Message object, the text of this message is used.
  • getPageTitle(): gets the page title (the contents of <h1> and <title>) as string.
  • setHTMLTitle($name): set the contents of <title>. It is stored as plain, unescaped text and will be run through htmlspecialchars in the skin file.
  • setRobotPolicy($policy): sets the robot policy for the page. See http://www.robotstxt.org/meta.html.
  • redirect($url, [$responsecode]): redirect to $url rather than displaying the normal page. $responsecode defaults to 302.
  • getRedirect(): get the URL to redirect to, or an empty string if not redirect URL set.
  • addHeadItem($name, $value): sets a HEAD item.
  • addReturnTo($title, [$query, $text]): adds a "return to" link pointing to a specified title. $title is the Title object to link to. $query is an optional query string and $text the text of the link (input is not escaped).
  • addTemplate($template): adds the output of a QuickTemplate to the output buffer.
  • allowClickjacking(): turn off frame-breaking. See Clickjacking.
  • debug($text): Adds $text to the debug output.
  • getCategories(): get the list of category names this page belongs to.
  • isArticle(): is the content of the displayed page related to the source of the corresponding article on the wiki?
  • isArticleRelated(): is this page related to an article on the wiki?
  • setSquidMaxage($maxage): set the value of the "s-maxage" part of the "Cache-control" HTTP header. $maxages is the maximum cache time on the Squid, in seconds.
Language: English  • português do Brasil