outputpage.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 1,079 行 · 第 1/3 页
PHP
1,079 行
/** * Parse wikitext and return the HTML. */ function parse( $text, $linestart = true, $interface = false ) { global $wgParser, $wgTitle; if ( $interface) { $this->mParserOptions->setInterfaceMessage(true); } $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, $linestart, true, $this->mRevisionId ); if ( $interface) { $this->mParserOptions->setInterfaceMessage(false); } return $parserOutput->getText(); } /** * @param $article * @param $user * * @return bool */ function tryParserCache( &$article, $user ) { $parserCache =& ParserCache::singleton(); $parserOutput = $parserCache->get( $article, $user ); if ( $parserOutput !== false ) { $this->mLanguageLinks += $parserOutput->getLanguageLinks(); $this->addCategoryLinks( $parserOutput->getCategories() ); $this->addKeywords( $parserOutput ); $this->mNewSectionLink = $parserOutput->getNewSection(); $this->mNoGallery = $parserOutput->getNoGallery(); $text = $parserOutput->getText(); wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) ); $this->addHTML( $text ); $t = $parserOutput->getTitleText(); if( !empty( $t ) ) { $this->setPageTitle( $t ); } return true; } else { return false; } } /** * Set the maximum cache time on the Squid in seconds * @param $maxage */ function setSquidMaxage( $maxage ) { $this->mSquidMaxage = $maxage; } /** * Use enableClientCache(false) to force it to send nocache headers * @param $state */ function enableClientCache( $state ) { return wfSetVar( $this->mEnableClientCache, $state ); } function uncacheableBecauseRequestvars() { global $wgRequest; return $wgRequest->getText('useskin', false) === false && $wgRequest->getText('uselang', false) === false; } function sendCacheControl() { global $wgUseSquid, $wgUseESI, $wgSquidMaxage; $fname = 'OutputPage::sendCacheControl'; if ($this->mETag) header("ETag: $this->mETag"); # don't serve compressed data to clients who can't handle it # maintain different caches for logged-in users and non-logged in ones header( 'Vary: Accept-Encoding, Cookie' ); if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache ) { if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) && ! $this->isPrintable() && $this->mSquidMaxage != 0 ) { if ( $wgUseESI ) { # We'll purge the proxy cache explicitly, but require end user agents # to revalidate against the proxy on each visit. # Surrogate-Control controls our Squid, Cache-Control downstream caches wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false ); # start with a shorter timeout for initial testing # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"'); header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage.', content="ESI/1.0"'); header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' ); } else { # We'll purge the proxy cache for anons explicitly, but require end user agents # to revalidate against the proxy on each visit. # IMPORTANT! The Squid needs to replace the Cache-Control header with # Cache-Control: s-maxage=0, must-revalidate, max-age=0 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false ); # start with a shorter timeout for initial testing # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" ); header( 'Cache-Control: s-maxage='.$this->mSquidMaxage.', must-revalidate, max-age=0' ); } } else { # We do want clients to cache if they can, but they *must* check for updates # on revisiting the page. wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false ); header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' ); header( "Cache-Control: private, must-revalidate, max-age=0" ); } if($this->mLastModified) header( "Last-modified: {$this->mLastModified}" ); } else { wfDebug( "$fname: no caching **\n", false ); # In general, the absence of a last modified header should be enough to prevent # the client from using its cache. We send a few other things just to make sure. header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' ); header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' ); header( 'Pragma: no-cache' ); } } /** * Finally, all the text has been munged and accumulated into * the object, let's actually output it: */ function output() { global $wgUser, $wgOutputEncoding; global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType; global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgScriptPath, $wgServer; if( $this->mDoNothing ){ return; } $fname = 'OutputPage::output'; wfProfileIn( $fname ); $sk = $wgUser->getSkin(); if ( $wgUseAjax ) { $this->addScript( "<script type=\"{$wgJsMimeType}\"> var wgScriptPath=\"{$wgScriptPath}\"; var wgServer=\"{$wgServer}\"; </script>" ); $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js\"></script>\n" ); } if ( '' != $this->mRedirect ) { if( substr( $this->mRedirect, 0, 4 ) != 'http' ) { # Standards require redirect URLs to be absolute global $wgServer; $this->mRedirect = $wgServer . $this->mRedirect; } if( $this->mRedirectCode == '301') { if( !$wgDebugRedirects ) { header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently"); } $this->mLastModified = wfTimestamp( TS_RFC2822 ); } $this->sendCacheControl(); if( $wgDebugRedirects ) { $url = htmlspecialchars( $this->mRedirect ); print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n"; print "<p>Location: <a href=\"$url\">$url</a></p>\n"; print "</body>\n</html>\n"; } else { header( 'Location: '.$this->mRedirect ); } wfProfileOut( $fname ); return; } elseif ( $this->mStatusCode ) { $statusMessage = array( 100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-Status', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Request Range Not Satisfiable', 417 => 'Expectation Failed', 422 => 'Unprocessable Entity', 423 => 'Locked', 424 => 'Failed Dependency', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported', 507 => 'Insufficient Storage' ); if ( $statusMessage[$this->mStatusCode] ) header( 'HTTP/1.1 ' . $this->mStatusCode . ' ' . $statusMessage[$this->mStatusCode] ); } # Buffer output; final headers may depend on later processing ob_start(); # Disable temporary placeholders, so that the skin produces HTML $sk->postParseLinkColour( false ); header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" ); header( 'Content-language: '.$wgContLanguageCode ); if ($this->mArticleBodyOnly) { $this->out($this->mBodytext); } else { wfProfileIn( 'Output-skin' ); $sk->outputPage( $this ); wfProfileOut( 'Output-skin' ); } $this->sendCacheControl(); ob_end_flush(); wfProfileOut( $fname ); } function out( $ins ) { global $wgInputEncoding, $wgOutputEncoding, $wgContLang; if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) { $outs = $ins; } else { $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins ); if ( false === $outs ) { $outs = $ins; } } print $outs; } function setEncodings() { global $wgInputEncoding, $wgOutputEncoding; global $wgUser, $wgContLang; $wgInputEncoding = strtolower( $wgInputEncoding ); if( $wgUser->getOption( 'altencoding' ) ) { $wgContLang->setAltEncoding(); return; } if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) { $wgOutputEncoding = strtolower( $wgOutputEncoding ); return; } $wgOutputEncoding = $wgInputEncoding; } /** * Returns a HTML comment with the elapsed time since request. * This method has no side effects. * Use wfReportTime() instead. * @return string * @deprecated */ function reportTime() { $time = wfReportTime(); return $time; } /** * Produce a "user is blocked" page */ function blockedPage( $return = true ) { global $wgUser, $wgContLang, $wgTitle; $this->setPageTitle( wfMsg( 'blockedtitle' ) ); $this->setRobotpolicy( 'noindex,nofollow' ); $this->setArticleRelated( false ); $id = $wgUser->blockedBy(); $reason = $wgUser->blockedFor(); $ip = wfGetIP(); if ( is_numeric( $id ) ) { $name = User::whoIs( $id ); } else { $name = $id; } $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]"; $this->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) ); # Don't auto-return to special pages if( $return ) { $return = $wgTitle->getNamespace() > -1 ? $wgTitle->getPrefixedText() : NULL; $this->returnToMain( false, $return ); } } /** * Note: these arguments are keys into wfMsg(), not text! */ function showErrorPage( $title, $msg ) { global $wgTitle; $this->mDebugtext .= 'Original title: ' . $wgTitle->getPrefixedText() . "\n"; $this->setPageTitle( wfMsg( $title ) ); $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) ); $this->setRobotpolicy( 'noindex,nofollow' ); $this->setArticleRelated( false ); $this->enableClientCache( false ); $this->mRedirect = ''; $this->mBodytext = ''; $this->addWikiText( wfMsg( $msg ) ); $this->returnToMain( false ); } /** @obsolete */ function errorpage( $title, $msg ) { throw new ErrorPageError( $title, $msg ); } /** * Display an error page indicating that a given version of MediaWiki is * required to use it * * @param mixed $version The version of MediaWiki needed to use the page */ function versionRequired( $version ) { $this->setPageTitle( wfMsg( 'versionrequired', $version ) ); $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) ); $this->setRobotpolicy( 'noindex,nofollow' ); $this->setArticleRelated( false ); $this->mBodytext = ''; $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) ); $this->returnToMain(); } /** * Display an error page noting that a given permission bit is required. * This should generally replace the sysopRequired, developerRequired etc. * @param string $permission key required */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?