手册:OutputPage.php
Appearance
此頁面已过时。 |
MediaWiki文件: OutputPage.php | |
---|---|
位置: | includes/Output/ |
源代码: | master • 1.42.3 • 1.41.4 • 1.39.10 |
类: | OutputPage |
1.40 and earlier:
MediaWiki文件: OutputPage.php | |
---|---|
位置: | includes/ |
源代码: | master • 1.42.3 • 1.41.4 • 1.39.10 |
类: | OutputPage |
OutputPage
对象负责生成HTML和其他与创建页面的HTML视图相关的内容。
它还将为非SkinTemplate皮肤生成<head>
元素,或为基于SkinTemplate的皮肤生成部分元素。
此类的一个实例位于$wgOut 中。
可用请求方法
输出HTML
output()
- called from functionfinalCleanup()
in MediaWiki.php . It calls functionoutputPage()
in Skin.php.out($string)
- called from functionoutputPage()
in Skin.php a number of times to send the HTML to the user: $mBodytext and HTML before and after it.
生成HTML
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, useArticle::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.
- applies function
JavaScript CSS/LESS
addJsConfigVars($keys,[$value])
- adds one or more variables to be set inmw.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. anOutputPage::addModules
call andOutputPage::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 addmw.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.addScriptFile($url)
- add a script tag that references a URL. URL should be absolute, protocol-relative or relative to root path.addInlineStyle($style_css, [$flip])
- adds inline CSS styles. Set $flip to 'flip' to flip the CSS if needed (for RTL support). Defaults to 'noflip'.addStyle($style, $media, $condition, $dir)
- add a local or specified stylesheet, with the given media options.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.addModuleStyles($modules)
- Add only CSS or LESS 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.
其他函数
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.
- Example:
<meta ... />
tags (See:$wgBrowserFormatDetection
)
- Example:
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.setPreventClickjacking()
- set the 'prevent-clickjacking' flag to turn off frame-breaking. ReplacesallowClickjacking()
since 1.38. 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.