wiki.techinc.nl/includes/OutputPage.php

1078 lines
33 KiB
PHP
Raw Normal View History

<?php
if ( ! defined( 'MEDIAWIKI' ) )
die( 1 );
/**
* @package MediaWiki
*/
2004-08-12 06:54:58 +00:00
/**
* @todo document
* @package MediaWiki
*/
2003-04-14 23:10:40 +00:00
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;
Merged localisation-work branch: * Made lines from initialiseMessages() appear as list items during installation * Moved the bulk of the localisation data from the Language*.php files to the Messages*.php files. Deleted most of the Languages*.php files. * Introduced "stub global" framework to provide deferred initialisation of core modules. * Removed placeholder values for $wgTitle and $wgArticle, these variables will now be null during the initialisation process, until they are set by index.php or another entry point. * Added DBA cache type, for BDB-style caches. * Removed custom date format functions, replacing them with a format string in the style of PHP's date(). Used string identifiers instead of integer identifiers, in both the language files and user preferences. Migration should be transparent in most cases. * Simplified the initialisation API for LoadBalancer objects. * Removed the broken altencoding feature. * Moved default user options and toggles from Language to User. Language objects are still able to define default preference overrides and extra user toggles, via a slightly different interface. * Don't include the date option in the parser cache rendering hash unless $wgUseDynamicDates is enabled. * Merged LanguageUtf8 with Language. Removed LanguageUtf8.php. * Removed inclusion of language files from the bottom of Language.php. This is now consistently done from Language::factory(). * Add the name of the executing maintenance script to the debug log. Start the profiler during maintenance scripts. * Added "serialized" directory, for storing precompiled data in serialized form.
2006-07-26 07:15:39 +00:00
protected $mParserOptions; // lazy initialised, use parserOptions()
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();
2003-04-14 23:10:40 +00:00
$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;
2003-04-14 23:10:40 +00:00
$this->mLanguageLinks = array();
$this->mCategoryLinks = array();
$this->mDoNothing = false;
$this->mContainsOldMagic = $this->mContainsNewMagic = 0;
Merged localisation-work branch: * Made lines from initialiseMessages() appear as list items during installation * Moved the bulk of the localisation data from the Language*.php files to the Messages*.php files. Deleted most of the Languages*.php files. * Introduced "stub global" framework to provide deferred initialisation of core modules. * Removed placeholder values for $wgTitle and $wgArticle, these variables will now be null during the initialisation process, until they are set by index.php or another entry point. * Added DBA cache type, for BDB-style caches. * Removed custom date format functions, replacing them with a format string in the style of PHP's date(). Used string identifiers instead of integer identifiers, in both the language files and user preferences. Migration should be transparent in most cases. * Simplified the initialisation API for LoadBalancer objects. * Removed the broken altencoding feature. * Moved default user options and toggles from Language to User. Language objects are still able to define default preference overrides and extra user toggles, via a slightly different interface. * Don't include the date option in the parser cache rendering hash unless $wgUseDynamicDates is enabled. * Merged LanguageUtf8 with Language. Removed LanguageUtf8.php. * Removed inclusion of language files from the bottom of Language.php. This is now consistently done from Language::factory(). * Add the name of the executing maintenance script to the debug log. Start the profiler during maintenance scripts. * Added "serialized" directory, for storing precompiled data in serialized form.
2006-07-26 07:15:39 +00:00
$this->mParserOptions = null;
$this->mSquidMaxage = 0;
$this->mScripts = '';
$this->mETag = false;
$this->mRevisionId = null;
$this->mNewSectionLink = false;
2003-04-14 23:10:40 +00:00
}
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;
}
2003-04-14 23:10:40 +00:00
function setStatusCode( $statusCode ) { $this->mStatusCode = $statusCode; }
2006-01-07 13:31:29 +00:00
2003-04-14 23:10:40 +00:00
# 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; }
2005-07-03 04:00:33 +00:00
function setArticleBodyOnly($only) { $this->mArticleBodyOnly = $only; }
2005-07-03 04:56:53 +00:00
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 );
}
2003-04-14 23:10:40 +00:00
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;
}
2003-07-10 04:55:41 +00:00
if( !$wgCachePages ) {
wfDebug( "$fname: CACHE DISABLED\n", false );
2003-07-10 04:55:41 +00:00
return;
}
if( $wgUser->getOption( 'nocache' ) ) {
wfDebug( "$fname: USER DISABLED CACHE\n", false );
2003-04-14 23:10:40 +00:00
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 ) {
2003-04-14 23:10:40 +00:00
# Make sure you're in a place you can leave when you call us!
header( "HTTP/1.0 304 Not Modified" );
2004-02-02 04:33:48 +00:00
$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;
2003-04-14 23:10:40 +00:00
} else {
wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
2003-04-14 23:10:40 +00:00
$this->mLastModified = $lastmod;
}
2003-07-10 04:55:41 +00:00
} else {
wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
2003-07-10 04:55:41 +00:00
$this->mLastModified = $lastmod;
2003-04-14 23:10:40 +00:00
}
}
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 '';
}
}
2003-04-14 23:10:40 +00:00
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;
}
}
2006-01-07 13:31:29 +00:00
$this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
}
function getHTMLTitle() { return $this->mHTMLtitle; }
2003-04-14 23:10:40 +00:00
function getPageTitle() { return $this->mPagetitle; }
function setSubtitle( $str ) { $this->mSubtitle = /*$this->parse(*/$str/*)*/; } // @bug 2514
2003-04-14 23:10:40 +00:00
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; }
2003-04-14 23:10:40 +00:00
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; }
2004-06-01 18:29:31 +00:00
function addLanguageLinks($newLinkArray) {
$this->mLanguageLinks += $newLinkArray;
}
function setLanguageLinks($newLinkArray) {
$this->mLanguageLinks = $newLinkArray;
}
2004-06-19 06:46:54 +00:00
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 );
}
2004-06-19 06:46:54 +00:00
}
function setCategoryLinks($categories) {
$this->mCategoryLinks = array();
$this->addCategoryLinks($categories);
2004-06-19 06:46:54 +00:00
}
function suppressQuickbar() { $this->mSuppressQuickbar = true; }
function isQuickbarSuppressed() { return $this->mSuppressQuickbar; }
2003-04-14 23:10:40 +00:00
function addHTML( $text ) { $this->mBodytext .= $text; }
function clearHTML() { $this->mBodytext = ''; }
function getHTML() { return $this->mBodytext; }
2003-04-14 23:10:40 +00:00
function debug( $text ) { $this->mDebugtext .= $text; }
/* @deprecated */
function setParserOptions( $options ) {
Merged localisation-work branch: * Made lines from initialiseMessages() appear as list items during installation * Moved the bulk of the localisation data from the Language*.php files to the Messages*.php files. Deleted most of the Languages*.php files. * Introduced "stub global" framework to provide deferred initialisation of core modules. * Removed placeholder values for $wgTitle and $wgArticle, these variables will now be null during the initialisation process, until they are set by index.php or another entry point. * Added DBA cache type, for BDB-style caches. * Removed custom date format functions, replacing them with a format string in the style of PHP's date(). Used string identifiers instead of integer identifiers, in both the language files and user preferences. Migration should be transparent in most cases. * Simplified the initialisation API for LoadBalancer objects. * Removed the broken altencoding feature. * Moved default user options and toggles from Language to User. Language objects are still able to define default preference overrides and extra user toggles, via a slightly different interface. * Don't include the date option in the parser cache rendering hash unless $wgUseDynamicDates is enabled. * Merged LanguageUtf8 with Language. Removed LanguageUtf8.php. * Removed inclusion of language files from the bottom of Language.php. This is now consistently done from Language::factory(). * Add the name of the executing maintenance script to the debug log. Start the profiler during maintenance scripts. * Added "serialized" directory, for storing precompiled data in serialized form.
2006-07-26 07:15:39 +00:00
return $this->parserOptions( $options );
}
Merged localisation-work branch: * Made lines from initialiseMessages() appear as list items during installation * Moved the bulk of the localisation data from the Language*.php files to the Messages*.php files. Deleted most of the Languages*.php files. * Introduced "stub global" framework to provide deferred initialisation of core modules. * Removed placeholder values for $wgTitle and $wgArticle, these variables will now be null during the initialisation process, until they are set by index.php or another entry point. * Added DBA cache type, for BDB-style caches. * Removed custom date format functions, replacing them with a format string in the style of PHP's date(). Used string identifiers instead of integer identifiers, in both the language files and user preferences. Migration should be transparent in most cases. * Simplified the initialisation API for LoadBalancer objects. * Removed the broken altencoding feature. * Moved default user options and toggles from Language to User. Language objects are still able to define default preference overrides and extra user toggles, via a slightly different interface. * Don't include the date option in the parser cache rendering hash unless $wgUseDynamicDates is enabled. * Merged LanguageUtf8 with Language. Removed LanguageUtf8.php. * Removed inclusion of language files from the bottom of Language.php. This is now consistently done from Language::factory(). * Add the name of the executing maintenance script to the debug log. Start the profiler during maintenance scripts. * Added "serialized" directory, for storing precompiled data in serialized form.
2006-07-26 07:15:39 +00:00
function parserOptions( $options = null ) {
if ( !$this->mParserOptions ) {
$this->mParserOptions = new ParserOptions;
}
return wfSetVar( $this->mParserOptions, $options );
}
2006-01-07 13:31:29 +00:00
/**
* 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) {
2005-12-04 18:27:59 +00:00
global $wgParser;
$fname = 'OutputPage:addWikiTextTitle';
wfProfileIn($fname);
wfIncrStats('pcache_not_possible');
Merged localisation-work branch: * Made lines from initialiseMessages() appear as list items during installation * Moved the bulk of the localisation data from the Language*.php files to the Messages*.php files. Deleted most of the Languages*.php files. * Introduced "stub global" framework to provide deferred initialisation of core modules. * Removed placeholder values for $wgTitle and $wgArticle, these variables will now be null during the initialisation process, until they are set by index.php or another entry point. * Added DBA cache type, for BDB-style caches. * Removed custom date format functions, replacing them with a format string in the style of PHP's date(). Used string identifiers instead of integer identifiers, in both the language files and user preferences. Migration should be transparent in most cases. * Simplified the initialisation API for LoadBalancer objects. * Removed the broken altencoding feature. * Moved default user options and toggles from Language to User. Language objects are still able to define default preference overrides and extra user toggles, via a slightly different interface. * Don't include the date option in the parser cache rendering hash unless $wgUseDynamicDates is enabled. * Merged LanguageUtf8 with Language. Removed LanguageUtf8.php. * Removed inclusion of language files from the bottom of Language.php. This is now consistently done from Language::factory(). * Add the name of the executing maintenance script to the debug log. Start the profiler during maintenance scripts. * Added "serialized" directory, for storing precompiled data in serialized form.
2006-07-26 07:15:39 +00:00
$parserOutput = $wgParser->parse( $text, $title, $this->parserOptions(),
$linestart, true, $this->mRevisionId );
2006-01-01 20:08:08 +00:00
$this->addParserOutput( $parserOutput );
wfProfileOut($fname);
2006-01-01 20:08:08 +00:00
}
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 ;
}
if ( $parserOutput->mSubtitle != '' ) {
$this->mSubtitle .= $parserOutput->mSubtitle ;
}
2006-01-01 20:08:08 +00:00
}
2006-01-07 13:31:29 +00:00
2006-01-01 20:08:08 +00:00
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;
Merged localisation-work branch: * Made lines from initialiseMessages() appear as list items during installation * Moved the bulk of the localisation data from the Language*.php files to the Messages*.php files. Deleted most of the Languages*.php files. * Introduced "stub global" framework to provide deferred initialisation of core modules. * Removed placeholder values for $wgTitle and $wgArticle, these variables will now be null during the initialisation process, until they are set by index.php or another entry point. * Added DBA cache type, for BDB-style caches. * Removed custom date format functions, replacing them with a format string in the style of PHP's date(). Used string identifiers instead of integer identifiers, in both the language files and user preferences. Migration should be transparent in most cases. * Simplified the initialisation API for LoadBalancer objects. * Removed the broken altencoding feature. * Moved default user options and toggles from Language to User. Language objects are still able to define default preference overrides and extra user toggles, via a slightly different interface. * Don't include the date option in the parser cache rendering hash unless $wgUseDynamicDates is enabled. * Merged LanguageUtf8 with Language. Removed LanguageUtf8.php. * Removed inclusion of language files from the bottom of Language.php. This is now consistently done from Language::factory(). * Add the name of the executing maintenance script to the debug log. Start the profiler during maintenance scripts. * Added "serialized" directory, for storing precompiled data in serialized form.
2006-07-26 07:15:39 +00:00
$popts = $this->parserOptions();
$popts->setTidy(true);
$parserOutput = $wgParser->parse( $text, $article->mTitle,
Merged localisation-work branch: * Made lines from initialiseMessages() appear as list items during installation * Moved the bulk of the localisation data from the Language*.php files to the Messages*.php files. Deleted most of the Languages*.php files. * Introduced "stub global" framework to provide deferred initialisation of core modules. * Removed placeholder values for $wgTitle and $wgArticle, these variables will now be null during the initialisation process, until they are set by index.php or another entry point. * Added DBA cache type, for BDB-style caches. * Removed custom date format functions, replacing them with a format string in the style of PHP's date(). Used string identifiers instead of integer identifiers, in both the language files and user preferences. Migration should be transparent in most cases. * Simplified the initialisation API for LoadBalancer objects. * Removed the broken altencoding feature. * Moved default user options and toggles from Language to User. Language objects are still able to define default preference overrides and extra user toggles, via a slightly different interface. * Don't include the date option in the parser cache rendering hash unless $wgUseDynamicDates is enabled. * Merged LanguageUtf8 with Language. Removed LanguageUtf8.php. * Removed inclusion of language files from the bottom of Language.php. This is now consistently done from Language::factory(). * Add the name of the executing maintenance script to the debug log. Start the profiler during maintenance scripts. * Added "serialized" directory, for storing precompiled data in serialized form.
2006-07-26 07:15:39 +00:00
$popts, true, true, $this->mRevisionId );
$popts->setTidy(false);
if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
$parserCache =& ParserCache::singleton();
$parserCache->save( $parserOutput, $article, $wgUser );
2003-04-14 23:10:40 +00:00
}
$this->addParserOutputNoText( $parserOutput );
$text = $parserOutput->getText();
$this->mNoGallery = $parserOutput->getNoGallery();
wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
$parserOutput->setText( $text );
$this->addHTML( $parserOutput->getText() );
2003-04-14 23:10:40 +00:00
}
/**
* For anything that isn't primary text or interface message
*/
function addSecondaryWikiText( $text, $linestart = true ) {
global $wgTitle;
Merged localisation-work branch: * Made lines from initialiseMessages() appear as list items during installation * Moved the bulk of the localisation data from the Language*.php files to the Messages*.php files. Deleted most of the Languages*.php files. * Introduced "stub global" framework to provide deferred initialisation of core modules. * Removed placeholder values for $wgTitle and $wgArticle, these variables will now be null during the initialisation process, until they are set by index.php or another entry point. * Added DBA cache type, for BDB-style caches. * Removed custom date format functions, replacing them with a format string in the style of PHP's date(). Used string identifiers instead of integer identifiers, in both the language files and user preferences. Migration should be transparent in most cases. * Simplified the initialisation API for LoadBalancer objects. * Removed the broken altencoding feature. * Moved default user options and toggles from Language to User. Language objects are still able to define default preference overrides and extra user toggles, via a slightly different interface. * Don't include the date option in the parser cache rendering hash unless $wgUseDynamicDates is enabled. * Merged LanguageUtf8 with Language. Removed LanguageUtf8.php. * Removed inclusion of language files from the bottom of Language.php. This is now consistently done from Language::factory(). * Add the name of the executing maintenance script to the debug log. Start the profiler during maintenance scripts. * Added "serialized" directory, for storing precompiled data in serialized form.
2006-07-26 07:15:39 +00:00
$popts = $this->parserOptions();
$popts->setTidy(true);
$this->addWikiTextTitle($text, $wgTitle, $linestart);
Merged localisation-work branch: * Made lines from initialiseMessages() appear as list items during installation * Moved the bulk of the localisation data from the Language*.php files to the Messages*.php files. Deleted most of the Languages*.php files. * Introduced "stub global" framework to provide deferred initialisation of core modules. * Removed placeholder values for $wgTitle and $wgArticle, these variables will now be null during the initialisation process, until they are set by index.php or another entry point. * Added DBA cache type, for BDB-style caches. * Removed custom date format functions, replacing them with a format string in the style of PHP's date(). Used string identifiers instead of integer identifiers, in both the language files and user preferences. Migration should be transparent in most cases. * Simplified the initialisation API for LoadBalancer objects. * Removed the broken altencoding feature. * Moved default user options and toggles from Language to User. Language objects are still able to define default preference overrides and extra user toggles, via a slightly different interface. * Don't include the date option in the parser cache rendering hash unless $wgUseDynamicDates is enabled. * Merged LanguageUtf8 with Language. Removed LanguageUtf8.php. * Removed inclusion of language files from the bottom of Language.php. This is now consistently done from Language::factory(). * Add the name of the executing maintenance script to the debug log. Start the profiler during maintenance scripts. * Added "serialized" directory, for storing precompiled data in serialized form.
2006-07-26 07:15:39 +00:00
$popts->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();
}
/**
* Parse wikitext and return the HTML.
*/
function parse( $text, $linestart = true, $interface = false ) {
global $wgParser, $wgTitle;
Merged localisation-work branch: * Made lines from initialiseMessages() appear as list items during installation * Moved the bulk of the localisation data from the Language*.php files to the Messages*.php files. Deleted most of the Languages*.php files. * Introduced "stub global" framework to provide deferred initialisation of core modules. * Removed placeholder values for $wgTitle and $wgArticle, these variables will now be null during the initialisation process, until they are set by index.php or another entry point. * Added DBA cache type, for BDB-style caches. * Removed custom date format functions, replacing them with a format string in the style of PHP's date(). Used string identifiers instead of integer identifiers, in both the language files and user preferences. Migration should be transparent in most cases. * Simplified the initialisation API for LoadBalancer objects. * Removed the broken altencoding feature. * Moved default user options and toggles from Language to User. Language objects are still able to define default preference overrides and extra user toggles, via a slightly different interface. * Don't include the date option in the parser cache rendering hash unless $wgUseDynamicDates is enabled. * Merged LanguageUtf8 with Language. Removed LanguageUtf8.php. * Removed inclusion of language files from the bottom of Language.php. This is now consistently done from Language::factory(). * Add the name of the executing maintenance script to the debug log. Start the profiler during maintenance scripts. * Added "serialized" directory, for storing precompiled data in serialized form.
2006-07-26 07:15:39 +00:00
$popts = $this->parserOptions();
if ( $interface) { $popts->setInterfaceMessage(true); }
$parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
2005-12-01 08:24:49 +00:00
$linestart, true, $this->mRevisionId );
Merged localisation-work branch: * Made lines from initialiseMessages() appear as list items during installation * Moved the bulk of the localisation data from the Language*.php files to the Messages*.php files. Deleted most of the Languages*.php files. * Introduced "stub global" framework to provide deferred initialisation of core modules. * Removed placeholder values for $wgTitle and $wgArticle, these variables will now be null during the initialisation process, until they are set by index.php or another entry point. * Added DBA cache type, for BDB-style caches. * Removed custom date format functions, replacing them with a format string in the style of PHP's date(). Used string identifiers instead of integer identifiers, in both the language files and user preferences. Migration should be transparent in most cases. * Simplified the initialisation API for LoadBalancer objects. * Removed the broken altencoding feature. * Moved default user options and toggles from Language to User. Language objects are still able to define default preference overrides and extra user toggles, via a slightly different interface. * Don't include the date option in the parser cache rendering hash unless $wgUseDynamicDates is enabled. * Merged LanguageUtf8 with Language. Removed LanguageUtf8.php. * Removed inclusion of language files from the bottom of Language.php. This is now consistently done from Language::factory(). * Add the name of the executing maintenance script to the debug log. Start the profiler during maintenance scripts. * Added "serialized" directory, for storing precompiled data in serialized form.
2006-07-26 07:15:39 +00:00
if ( $interface) { $popts->setInterfaceMessage(false); }
return $parserOutput->getText();
}
/**
* @param $article
* @param $user
2005-04-15 18:37:39 +00:00
*
* @return bool
*/
function tryParserCache( &$article, $user ) {
$parserCache =& ParserCache::singleton();
$parserOutput = $parserCache->get( $article, $user );
if ( $parserOutput !== false ) {
$this->addParserOutputNoText( $parserOutput );
$text = $parserOutput->getText();
wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
$this->addHTML( $text );
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
*/
2004-03-23 10:19:31 +00:00
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() {
2006-01-10 18:44:39 +00:00
global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
2006-05-12 22:45:52 +00:00
$fname = 'OutputPage::sendCacheControl';
if ($this->mETag)
header("ETag: $this->mETag");
2005-03-08 02:58:43 +00:00
# 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
2006-05-12 22:45:52 +00:00
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
2006-05-12 22:45:52 +00:00
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.
2006-05-12 22:45:52 +00:00
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 {
2006-05-12 22:45:52 +00:00
wfDebug( "$fname: no caching **\n", false );
2004-03-23 10:19:31 +00:00
# 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;
2006-03-28 05:15:10 +00:00
global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgScriptPath, $wgServer;
if( $this->mDoNothing ){
return;
}
$fname = 'OutputPage::output';
wfProfileIn( $fname );
2003-04-14 23:10:40 +00:00
$sk = $wgUser->getSkin();
if ( $wgUseAjax ) {
$this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js\"></script>\n" );
}
if ( $wgUseAjax && $wgAjaxSearch ) {
$this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js\"></script>\n" );
$this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</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 );
2004-03-01 22:16:39 +00:00
}
2004-03-01 22:16:39 +00:00
$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 );
}
2005-07-25 07:00:20 +00:00
wfProfileOut( $fname );
2003-04-14 23:10:40 +00:00
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 );
2003-04-14 23:10:40 +00:00
2005-07-03 04:00:33 +00:00
if ($this->mArticleBodyOnly) {
$this->out($this->mBodytext);
} else {
wfProfileIn( 'Output-skin' );
$sk->outputPage( $this );
wfProfileOut( 'Output-skin' );
}
$this->sendCacheControl();
ob_end_flush();
2005-07-25 07:00:20 +00:00
wfProfileOut( $fname );
2003-04-14 23:10:40 +00:00
}
function out( $ins ) {
global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
2003-04-14 23:10:40 +00:00
if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
$outs = $ins;
} else {
$outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
2003-04-14 23:10:40 +00:00
if ( false === $outs ) { $outs = $ins; }
}
print $outs;
}
function setEncodings() {
global $wgInputEncoding, $wgOutputEncoding;
global $wgUser, $wgContLang;
2003-04-14 23:10:40 +00:00
$wgInputEncoding = strtolower( $wgInputEncoding );
if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
2003-04-14 23:10:40 +00:00
$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.
2005-04-04 19:31:58 +00:00
* @return string
* @deprecated
*/
function reportTime() {
$time = wfReportTime();
return $time;
2003-04-14 23:10:40 +00:00
}
2006-01-07 13:31:29 +00:00
/**
* 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 );
}
}
2003-04-14 23:10:40 +00:00
/**
* Note: these arguments are keys into wfMsg(), not text!
*/
function showErrorPage( $title, $msg ) {
2003-04-14 23:10:40 +00:00
global $wgTitle;
$this->mDebugtext .= 'Original title: ' .
2003-04-14 23:10:40 +00:00
$wgTitle->getPrefixedText() . "\n";
$this->setPageTitle( wfMsg( $title ) );
$this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
$this->setRobotpolicy( 'noindex,nofollow' );
$this->setArticleRelated( false );
2004-03-23 10:19:31 +00:00
$this->enableClientCache( false );
$this->mRedirect = '';
2003-04-14 23:10:40 +00:00
$this->mBodytext = '';
$this->addWikiText( wfMsg( $msg ) );
2003-04-14 23:10:40 +00:00
$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.
* @param string $permission key required
*/
function permissionRequired( $permission ) {
global $wgGroupPermissions, $wgUser;
$this->setPageTitle( wfMsg( 'badaccess' ) );
$this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
$this->setRobotpolicy( 'noindex,nofollow' );
$this->setArticleRelated( false );
$this->mBodytext = '';
$groups = array();
foreach( $wgGroupPermissions as $key => $value ) {
if( isset( $value[$permission] ) && $value[$permission] == true ) {
$groupName = User::getGroupName( $key );
$groupPage = User::getGroupPage( $key );
if( $groupPage ) {
$skin =& $wgUser->getSkin();
$groups[] = '"'.$skin->makeLinkObj( $groupPage, $groupName ).'"';
} else {
$groups[] = '"'.$groupName.'"';
}
}
}
$n = count( $groups );
$groups = implode( ', ', $groups );
switch( $n ) {
case 0:
case 1:
case 2:
$message = wfMsgHtml( "badaccess-group$n", $groups );
break;
default:
$message = wfMsgHtml( 'badaccess-groups', $groups );
}
$this->addHtml( $message );
$this->returnToMain( false );
}
/**
* @deprecated
*/
function sysopRequired() {
throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
2003-04-14 23:10:40 +00:00
}
/**
* @deprecated
*/
function developerRequired() {
throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
2003-04-14 23:10:40 +00:00
}
/**
* Produce the stock "please login to use the wiki" page
*/
function loginToUse() {
global $wgUser, $wgTitle, $wgContLang;
$skin = $wgUser->getSkin();
$this->setPageTitle( wfMsg( 'loginreqtitle' ) );
$this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
$this->setRobotPolicy( 'noindex,nofollow' );
$this->setArticleFlag( false );
$loginTitle = Title::makeTitle( NS_SPECIAL, 'Userlogin' );
$loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
$this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
$this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
$this->returnToMain();
}
/** @obsolete */
function databaseError( $fname, $sql, $error, $errno ) {
throw new MWException( "OutputPage::databaseError is obsolete\n" );
2003-04-14 23:10:40 +00:00
}
function readOnlyPage( $source = null, $protected = false ) {
global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
2003-04-14 23:10:40 +00:00
$this->setRobotpolicy( 'noindex,nofollow' );
$this->setArticleRelated( false );
2003-04-14 23:10:40 +00:00
if( $protected ) {
$skin = $wgUser->getSkin();
$this->setPageTitle( wfMsg( 'viewsource' ) );
$this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
# Determine if protection is due to the page being a system message
# and show an appropriate explanation
if( $wgTitle->getNamespace() == NS_MEDIAWIKI && !$wgUser->isAllowed( 'editinterface' ) ) {
$this->addWikiText( wfMsg( 'protectedinterface' ) );
} else {
$this->addWikiText( wfMsg( 'protectedtext' ) );
}
} else {
$this->setPageTitle( wfMsg( 'readonly' ) );
2005-06-01 06:18:49 +00:00
if ( $wgReadOnly ) {
$reason = $wgReadOnly;
} else {
$reason = file_get_contents( $wgReadOnlyFile );
}
$this->addWikiText( wfMsg( 'readonlytext', $reason ) );
}
if( is_string( $source ) ) {
if( strcmp( $source, '' ) == 0 ) {
global $wgTitle;
if ( $wgTitle->getNamespace() == NS_MEDIAWIKI ) {
$source = wfMsgWeirdKey ( $wgTitle->getText() );
} else {
$source = '';
}
}
$rows = $wgUser->getIntOption( 'rows' );
$cols = $wgUser->getIntOption( 'cols' );
$text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
2004-04-29 12:17:33 +00:00
htmlspecialchars( $source ) . "\n</textarea>";
$this->addHTML( $text );
}
2003-04-14 23:10:40 +00:00
$this->returnToMain( false );
}
/** @obsolete */
function fatalError( $message ) {
throw new FatalError( $message );
}
/** @obsolete */
function unexpectedValueError( $name, $val ) {
throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
}
/** @obsolete */
function fileCopyError( $old, $new ) {
throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
}
/** @obsolete */
function fileRenameError( $old, $new ) {
throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
}
/** @obsolete */
function fileDeleteError( $name ) {
throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
}
/** @obsolete */
function fileNotFoundError( $name ) {
throw new FatalError( wfMsg( 'filenotfound', $name ) );
}
function showFatalError( $message ) {
2003-04-14 23:10:40 +00:00
$this->setPageTitle( wfMsg( "internalerror" ) );
$this->setRobotpolicy( "noindex,nofollow" );
$this->setArticleRelated( false );
2004-03-23 10:19:31 +00:00
$this->enableClientCache( false );
$this->mRedirect = '';
2003-04-14 23:10:40 +00:00
$this->mBodytext = $message;
}
function showUnexpectedValueError( $name, $val ) {
$this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
2003-04-14 23:10:40 +00:00
}
function showFileCopyError( $old, $new ) {
$this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
2003-04-14 23:10:40 +00:00
}
function showFileRenameError( $old, $new ) {
$this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
2003-04-14 23:10:40 +00:00
}
function showFileDeleteError( $name ) {
$this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
2003-04-14 23:10:40 +00:00
}
function showFileNotFoundError( $name ) {
$this->showFatalError( wfMsg( 'filenotfound', $name ) );
2003-04-14 23:10:40 +00:00
}
/**
* return from error messages or notes
* @param $auto automatically redirect the user after 10 seconds
* @param $returnto page title to return to. Default is Main Page.
*/
function returnToMain( $auto = true, $returnto = NULL ) {
global $wgUser, $wgOut, $wgRequest;
if ( $returnto == NULL ) {
$returnto = $wgRequest->getText( 'returnto' );
}
if ( '' === $returnto ) {
$returnto = wfMsgForContent( 'mainpage' );
2003-04-14 23:10:40 +00:00
}
if ( is_object( $returnto ) ) {
$titleObj = $returnto;
} else {
$titleObj = Title::newFromText( $returnto );
}
2006-06-23 06:53:05 +00:00
if ( !is_object( $titleObj ) ) {
$titleObj = Title::newMainPage();
}
$sk = $wgUser->getSkin();
$link = $sk->makeLinkObj( $titleObj, '' );
2003-04-14 23:10:40 +00:00
$r = wfMsg( 'returnto', $link );
2003-04-14 23:10:40 +00:00
if ( $auto ) {
$wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
2003-04-14 23:10:40 +00:00
}
2004-04-03 10:59:26 +00:00
$wgOut->addHTML( "\n<p>$r</p>\n" );
2003-04-14 23:10:40 +00:00
}
/**
2005-07-12 21:23:28 +00:00
* This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
* and uses the first 10 of them for META keywords
*/
function addKeywords( &$parserOutput ) {
global $wgTitle;
$this->addKeyword( $wgTitle->getPrefixedText() );
$count = 1;
$links2d =& $parserOutput->getLinks();
if ( !is_array( $links2d ) ) {
return;
}
foreach ( $links2d as $ns => $dbkeys ) {
foreach( $dbkeys as $dbkey => $id ) {
$this->addKeyword( $dbkey );
if ( ++$count > 10 ) {
break 2;
}
}
}
2004-03-20 13:27:08 +00:00
}
/**
* @access private
2005-04-04 19:31:58 +00:00
* @return string
*/
function headElement() {
global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle;
2003-04-14 23:10:40 +00:00
if( $wgMimeType == 'text/xml' || $wgMimeType == 'application/xhtml+xml' || $wgMimeType == 'application/xml' ) {
2005-04-15 18:37:39 +00:00
$ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
} else {
$ret = '';
}
2004-04-09 10:15:08 +00:00
$ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
2003-04-14 23:10:40 +00:00
if ( '' == $this->getHTMLTitle() ) {
$this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
2003-04-14 23:10:40 +00:00
}
$rtl = $wgContLang->isRTL() ? " dir='RTL'" : '';
$ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
$ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
$ret .= $this->getHeadLinks();
global $wgStylePath;
if( $this->isPrintable() ) {
$media = '';
} else {
$media = "media='print'";
}
2004-09-05 03:25:58 +00:00
$printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
$ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
$sk = $wgUser->getSkin();
$ret .= $sk->getHeadScripts();
$ret .= $this->mScripts;
$ret .= $sk->getUserStyles();
2005-07-23 05:47:25 +00:00
if ($wgUseTrackbacks && $this->isArticleRelated())
$ret .= $wgTitle->trackbackRDF();
$ret .= "</head>\n";
return $ret;
}
function getHeadLinks() {
global $wgRequest;
$ret = '';
2003-04-14 23:10:40 +00:00
foreach ( $this->mMetatags as $tag ) {
if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
$a = 'http-equiv';
2003-04-14 23:10:40 +00:00
$tag[0] = substr( $tag[0], 5 );
} else {
$a = 'name';
2003-04-14 23:10:40 +00:00
}
$ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
2003-04-14 23:10:40 +00:00
}
2006-01-07 13:31:29 +00:00
2003-04-14 23:10:40 +00:00
$p = $this->mRobotpolicy;
if( $p !== '' && $p != 'index,follow' ) {
// http://www.robotstxt.org/wc/meta-user.html
// Only show if it's different from the default robots policy
$ret .= "<meta name=\"robots\" content=\"$p\" />\n";
}
2003-04-14 23:10:40 +00:00
if ( count( $this->mKeywords ) > 0 ) {
2004-04-15 12:27:31 +00:00
$strip = array(
"/<.*?>/" => '',
"/_/" => ' '
2004-04-15 12:27:31 +00:00
);
2003-04-14 23:10:40 +00:00
$ret .= "<meta name=\"keywords\" content=\"" .
2004-04-15 12:27:31 +00:00
htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ))) . "\" />\n";
2003-04-14 23:10:40 +00:00
}
foreach ( $this->mLinktags as $tag ) {
$ret .= '<link';
foreach( $tag as $attr => $val ) {
$ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
}
$ret .= " />\n";
2003-04-14 23:10:40 +00:00
}
if( $this->isSyndicated() ) {
# FIXME: centralize the mime-type and name information in Feed.php
$link = $wgRequest->escapeAppendQuery( 'feed=rss' );
$ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
$link = $wgRequest->escapeAppendQuery( 'feed=atom' );
$ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
}
2003-04-14 23:10:40 +00:00
return $ret;
}
/**
* Turn off regular page output and return an error reponse
* for when rate limiting has triggered.
2005-07-05 21:22:25 +00:00
* @todo i18n
* @access public
*/
function rateLimited() {
global $wgOut;
$wgOut->disable();
wfHttpError( 500, 'Internal Server Error',
'Sorry, the server has encountered an internal error. ' .
'Please wait a moment and hit "refresh" to submit the request again.' );
}
/**
* Show an "add new section" link?
*
* @return bool True if the parser output instructs us to add one
*/
function showNewSectionLink() {
return $this->mNewSectionLink;
}
2003-04-14 23:10:40 +00:00
}
?>