outputpage.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 1,079 行 · 第 1/3 页
PHP
1,079 行
<?phpif ( ! defined( 'MEDIAWIKI' ) ) die( 1 );/** * @package MediaWiki *//** * @todo document * @package MediaWiki */class OutputPage { var $mMetatags, $mKeywords; var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext; var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable; var $mSubtitle, $mRedirect, $mStatusCode; var $mLastModified, $mETag, $mCategoryLinks; var $mScripts, $mLinkColours, $mPageLinkTitle; var $mSuppressQuickbar; var $mOnloadHandler; var $mDoNothing; var $mContainsOldMagic, $mContainsNewMagic; var $mIsArticleRelated; var $mParserOptions; var $mShowFeedLinks = false; var $mEnableClientCache = true; var $mArticleBodyOnly = false; var $mNewSectionLink = false; var $mNoGallery = false; /** * Constructor * Initialise private variables */ function OutputPage() { $this->mMetatags = $this->mKeywords = $this->mLinktags = array(); $this->mHTMLtitle = $this->mPagetitle = $this->mBodytext = $this->mRedirect = $this->mLastModified = $this->mSubtitle = $this->mDebugtext = $this->mRobotpolicy = $this->mOnloadHandler = $this->mPageLinkTitle = ''; $this->mIsArticleRelated = $this->mIsarticle = $this->mPrintable = true; $this->mSuppressQuickbar = $this->mPrintable = false; $this->mLanguageLinks = array(); $this->mCategoryLinks = array(); $this->mDoNothing = false; $this->mContainsOldMagic = $this->mContainsNewMagic = 0; $this->mParserOptions = ParserOptions::newFromUser( $temp = NULL ); $this->mSquidMaxage = 0; $this->mScripts = ''; $this->mETag = false; $this->mRevisionId = null; $this->mNewSectionLink = false; } function redirect( $url, $responsecode = '302' ) { # Strip newlines as a paranoia check for header injection in PHP<5.1.2 $this->mRedirect = str_replace( "\n", '', $url ); $this->mRedirectCode = $responsecode; } function setStatusCode( $statusCode ) { $this->mStatusCode = $statusCode; } # To add an http-equiv meta tag, precede the name with "http:" function addMeta( $name, $val ) { array_push( $this->mMetatags, array( $name, $val ) ); } function addKeyword( $text ) { array_push( $this->mKeywords, $text ); } function addScript( $script ) { $this->mScripts .= $script; } function getScript() { return $this->mScripts; } function setETag($tag) { $this->mETag = $tag; } function setArticleBodyOnly($only) { $this->mArticleBodyOnly = $only; } function getArticleBodyOnly($only) { return $this->mArticleBodyOnly; } function addLink( $linkarr ) { # $linkarr should be an associative array of attributes. We'll escape on output. array_push( $this->mLinktags, $linkarr ); } function addMetadataLink( $linkarr ) { # note: buggy CC software only reads first "meta" link static $haveMeta = false; $linkarr['rel'] = ($haveMeta) ? 'alternate meta' : 'meta'; $this->addLink( $linkarr ); $haveMeta = true; } /** * checkLastModified tells the client to use the client-cached page if * possible. If sucessful, the OutputPage is disabled so that * any future call to OutputPage->output() have no effect. The method * returns true iff cache-ok headers was sent. */ function checkLastModified ( $timestamp ) { global $wgCachePages, $wgCacheEpoch, $wgUser; $fname = 'OutputPage::checkLastModified'; if ( !$timestamp || $timestamp == '19700101000000' ) { wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" ); return; } if( !$wgCachePages ) { wfDebug( "$fname: CACHE DISABLED\n", false ); return; } if( $wgUser->getOption( 'nocache' ) ) { wfDebug( "$fname: USER DISABLED CACHE\n", false ); return; } $timestamp=wfTimestamp(TS_MW,$timestamp); $lastmod = wfTimestamp( TS_RFC2822, max( $timestamp, $wgUser->mTouched, $wgCacheEpoch ) ); if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) { # IE sends sizes after the date like this: # Wed, 20 Aug 2003 06:51:19 GMT; length=5202 # this breaks strtotime(). $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] ); $modsinceTime = strtotime( $modsince ); $ismodsince = wfTimestamp( TS_MW, $modsinceTime ? $modsinceTime : 1 ); wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false ); wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false ); if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) { # Make sure you're in a place you can leave when you call us! header( "HTTP/1.0 304 Not Modified" ); $this->mLastModified = $lastmod; $this->sendCacheControl(); wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false ); $this->disable(); @ob_end_clean(); // Don't output compressed blob return true; } else { wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false ); $this->mLastModified = $lastmod; } } else { wfDebug( "$fname: client did not send If-Modified-Since header\n", false ); $this->mLastModified = $lastmod; } } function getPageTitleActionText () { global $action; switch($action) { case 'edit': case 'delete': case 'protect': case 'unprotect': case 'watch': case 'unwatch': // Display title is already customized return ''; case 'history': return wfMsg('history_short'); case 'submit': // FIXME: bug 2735; not correct for special pages etc return wfMsg('preview'); case 'info': return wfMsg('info_short'); default: return ''; } } function setRobotpolicy( $str ) { $this->mRobotpolicy = $str; } function setHTMLTitle( $name ) {$this->mHTMLtitle = $name; } function setPageTitle( $name ) { global $action, $wgContLang; $name = $wgContLang->convert($name, true); $this->mPagetitle = $name; if(!empty($action)) { $taction = $this->getPageTitleActionText(); if( !empty( $taction ) ) { $name .= ' - '.$taction; } } $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) ); } function getHTMLTitle() { return $this->mHTMLtitle; } function getPageTitle() { return $this->mPagetitle; } function setSubtitle( $str ) { $this->mSubtitle = /*$this->parse(*/$str/*)*/; } // @bug 2514 function getSubtitle() { return $this->mSubtitle; } function isArticle() { return $this->mIsarticle; } function setPrintable() { $this->mPrintable = true; } function isPrintable() { return $this->mPrintable; } function setSyndicated( $show = true ) { $this->mShowFeedLinks = $show; } function isSyndicated() { return $this->mShowFeedLinks; } function setOnloadHandler( $js ) { $this->mOnloadHandler = $js; } function getOnloadHandler() { return $this->mOnloadHandler; } function disable() { $this->mDoNothing = true; } function setArticleRelated( $v ) { $this->mIsArticleRelated = $v; if ( !$v ) { $this->mIsarticle = false; } } function setArticleFlag( $v ) { $this->mIsarticle = $v; if ( $v ) { $this->mIsArticleRelated = $v; } } function isArticleRelated() { return $this->mIsArticleRelated; } function getLanguageLinks() { return $this->mLanguageLinks; } function addLanguageLinks($newLinkArray) { $this->mLanguageLinks += $newLinkArray; } function setLanguageLinks($newLinkArray) { $this->mLanguageLinks = $newLinkArray; } function getCategoryLinks() { return $this->mCategoryLinks; } /** * Add an array of categories, with names in the keys */ function addCategoryLinks($categories) { global $wgUser, $wgContLang; if ( !is_array( $categories ) ) { return; } # Add the links to the link cache in a batch $arr = array( NS_CATEGORY => $categories ); $lb = new LinkBatch; $lb->setArray( $arr ); $lb->execute(); $sk =& $wgUser->getSkin(); foreach ( $categories as $category => $arbitrary ) { $title = Title::makeTitleSafe( NS_CATEGORY, $category ); $text = $wgContLang->convertHtml( $title->getText() ); $this->mCategoryLinks[] = $sk->makeLinkObj( $title, $text ); } } function setCategoryLinks($categories) { $this->mCategoryLinks = array(); $this->addCategoryLinks($categories); } function suppressQuickbar() { $this->mSuppressQuickbar = true; } function isQuickbarSuppressed() { return $this->mSuppressQuickbar; } function addHTML( $text ) { $this->mBodytext .= $text; } function clearHTML() { $this->mBodytext = ''; } function getHTML() { return $this->mBodytext; } function debug( $text ) { $this->mDebugtext .= $text; } /* @deprecated */ function setParserOptions( $options ) { return $this->ParserOptions( $options ); } function ParserOptions( $options = null ) { return wfSetVar( $this->mParserOptions, $options ); } /** * Set the revision ID which will be seen by the wiki text parser * for things such as embedded {{REVISIONID}} variable use. * @param mixed $revid an integer, or NULL * @return mixed previous value */ function setRevisionId( $revid ) { $val = is_null( $revid ) ? null : intval( $revid ); return wfSetVar( $this->mRevisionId, $val ); } /** * Convert wikitext to HTML and add it to the buffer * Default assumes that the current page title will * be used. */ function addWikiText( $text, $linestart = true ) { global $wgTitle; $this->addWikiTextTitle($text, $wgTitle, $linestart); } function addWikiTextWithTitle($text, &$title, $linestart = true) { $this->addWikiTextTitle($text, $title, $linestart); } function addWikiTextTitle($text, &$title, $linestart) { global $wgParser; $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions, $linestart, true, $this->mRevisionId ); $this->addParserOutput( $parserOutput ); } function addParserOutputNoText( &$parserOutput ) { $this->mLanguageLinks += $parserOutput->getLanguageLinks(); $this->addCategoryLinks( $parserOutput->getCategories() ); $this->mNewSectionLink = $parserOutput->getNewSection(); $this->addKeywords( $parserOutput ); if ( $parserOutput->getCacheTime() == -1 ) { $this->enableClientCache( false ); } if ( $parserOutput->mHTMLtitle != "" ) { $this->mPagetitle = $parserOutput->mHTMLtitle ; $this->mSubtitle .= $parserOutput->mSubtitle ; } } function addParserOutput( &$parserOutput ) { $this->addParserOutputNoText( $parserOutput ); $this->addHTML( $parserOutput->getText() ); } /** * Add wikitext to the buffer, assuming that this is the primary text for a page view * Saves the text into the parser cache if possible */ function addPrimaryWikiText( $text, $article, $cache = true ) { global $wgParser, $wgUser; $this->mParserOptions->setTidy(true); $parserOutput = $wgParser->parse( $text, $article->mTitle, $this->mParserOptions, true, true, $this->mRevisionId ); $this->mParserOptions->setTidy(false); if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) { $parserCache =& ParserCache::singleton(); $parserCache->save( $parserOutput, $article, $wgUser ); } $this->addParserOutputNoText( $parserOutput ); $text = $parserOutput->getText(); $this->mNoGallery = $parserOutput->getNoGallery(); wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) ); $parserOutput->setText( $text ); $this->addHTML( $parserOutput->getText() ); } /** * For anything that isn't primary text or interface message */ function addSecondaryWikiText( $text, $linestart = true ) { global $wgTitle; $this->mParserOptions->setTidy(true); $this->addWikiTextTitle($text, $wgTitle, $linestart); $this->mParserOptions->setTidy(false); } /** * Add the output of a QuickTemplate to the output buffer * @param QuickTemplate $template */ function addTemplate( &$template ) { ob_start(); $template->execute(); $this->addHTML( ob_get_contents() ); ob_end_clean(); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?