<?php
+if ( ! defined( 'MEDIAWIKI' ) )
+ die( -1 );
/**
* @package MediaWiki
*/
-/**
- * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
- */
-if( defined( 'MEDIAWIKI' ) ) {
-
-# See design.txt
-
-if($wgUseTeX) require_once( 'Math.php' );
+if ( $wgUseTeX )
+ require_once 'Math.php';
/**
* @todo document
function addHeader( $name, $val ) { array_push( $this->mHeaders, $name.': '.$val ) ; }
function redirect( $url, $responsecode = '302' ) { $this->mRedirect = $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 ); }
$name .= ' - '.$taction;
}
}
-
+
$this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
}
function getHTMLTitle() { return $this->mHTMLtitle; }
function getCategoryLinks() {
return $this->mCategoryLinks;
}
- function addCategoryLinks($newLinkArray) {
- $this->mCategoryLinks += $newLinkArray;
+
+ /**
+ * Add an array of categories, with names in the keys
+ */
+ function addCategoryLinks($categories) {
+ global $wgUser, $wgContLang;
+
+ # 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($newLinkArray) {
- $this->mCategoryLinks += $newLinkArray;
+
+ function setCategoryLinks($categories) {
+ $this->mCategoryLinks = array();
+ $this->addCategoryLinks($categories);
}
function suppressQuickbar() { $this->mSuppressQuickbar = true; }
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.
global $wgParser;
$parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions,
$linestart, true, $this->mRevisionId );
+ $this->addParserOutput( $parserOutput );
+ }
+
+ function addParserOutputNoText( &$parserOutput ) {
$this->mLanguageLinks += $parserOutput->getLanguageLinks();
- $this->mCategoryLinks += $parserOutput->getCategoryLinks();
+ $this->addCategoryLinks( $parserOutput->getCategories() );
+ $this->addKeywords( $parserOutput );
if ( $parserOutput->getCacheTime() == -1 ) {
$this->enableClientCache( false );
}
+ }
+
+ 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, $cacheArticle ) {
- global $wgParser, $wgParserCache, $wgUser;
+ function addPrimaryWikiText( $text, $article, $cache = true ) {
+ global $wgParser, $wgUser;
- $parserOutput = $wgParser->parse( $text, $cacheArticle->mTitle,
+ $parserOutput = $wgParser->parse( $text, $article->mTitle,
$this->mParserOptions, true, true, $this->mRevisionId );
- $text = $parserOutput->getText();
-
- if ( $cacheArticle && $parserOutput->getCacheTime() != -1 ) {
- $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
+ if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
+ $parserCache =& ParserCache::singleton();
+ $parserCache->save( $parserOutput, $article, $wgUser );
}
- $this->mLanguageLinks += $parserOutput->getLanguageLinks();
- $this->mCategoryLinks += $parserOutput->getCategoryLinks();
- if ( $parserOutput->getCacheTime() == -1 ) {
- $this->enableClientCache( false );
- }
- $this->addHTML( $text );
+ $this->addParserOutputNoText( $parserOutput );
+ $text = $parserOutput->getText();
+ wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
+ $parserOutput->setText( $text );
+ $this->addHTML( $parserOutput->getText() );
}
/**
function addTemplate( &$template ) {
ob_start();
$template->execute();
- $this->addHtml( ob_get_contents() );
+ $this->addHTML( ob_get_contents() );
ob_end_clean();
}
* @return bool
*/
function tryParserCache( $article, $user ) {
- global $wgParserCache;
- $parserOutput = $wgParserCache->get( $article, $user );
+ $parserCache =& ParserCache::singleton();
+ $parserOutput = $parserCache->get( $article, $user );
if ( $parserOutput !== false ) {
$this->mLanguageLinks += $parserOutput->getLanguageLinks();
- $this->mCategoryLinks += $parserOutput->getCategoryLinks();
- $this->addHTML( $parserOutput->getText() );
+ $this->addCategoryLinks( $parserOutput->getCategories() );
+ $this->addKeywords( $parserOutput );
+ $text = $parserOutput->getText();
+ wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
+ $this->addHTML( $text );
$t = $parserOutput->getTitleText();
if( !empty( $t ) ) {
$this->setPageTitle( $t );
}
function sendCacheControl() {
- global $wgUseSquid, $wgUseESI;
+ global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
if ($this->mETag)
header("ETag: $this->mETag");
return $time;
}
+ /**
+ * Produce a "user is blocked" page
+ */
+ function blockedPage() {
+ global $wgUser, $wgContLang;
+
+ $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 ) );
+ $this->returnToMain( false );
+ }
+
/**
* Note: these arguments are keys into wfMsg(), not text!
*/
$this->mBodytext = '';
$loginpage = Title::makeTitle(NS_SPECIAL, 'Userlogin');
$sk = $wgUser->getSkin();
- $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
+ $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
'returnto=' . htmlspecialchars($wgTitle->getPrefixedDBkey()));
$this->addHTML( wfMsgHtml( 'loginreqpagetext', $loginlink ) );
if( is_string( $source ) ) {
if( strcmp( $source, '' ) == 0 ) {
- $source = wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' );
+ global $wgTitle ;
+ if ( $wgTitle->getNamespace() == NS_MEDIAWIKI ) {
+ $source = wfMsgWeirdKey ( $wgTitle->getText() ) ;
+ } else {
+ $source = wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' );
+ }
}
$rows = $wgUser->getOption( 'rows' );
$cols = $wgUser->getOption( 'cols' );
* 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 addMetaTags () {
- global $wgLinkCache , $wgOut ;
- $categories = array_keys ( $wgLinkCache->mCategoryLinks ) ;
- $good = array_keys ( $wgLinkCache->mGoodLinks ) ;
- $bad = array_keys ( $wgLinkCache->mBadLinks ) ;
- $a = array_merge ( array_slice ( $good , 0 , 1 ), $categories, array_slice ( $good , 1 , 9 ) , $bad ) ;
- $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
- $a = implode ( ',' , $a ) ;
- $strip = array(
- "/<.*?>/" => '',
- "/_/" => ' '
- );
- $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
-
- $wgOut->addMeta( 'keywords' , $a ) ;
+ function addKeywords( &$parserOutput ) {
+ global $wgTitle;
+ $this->addKeyword( $wgTitle->getPrefixedText() );
+ $count = 1;
+ $links2d =& $parserOutput->getLinks();
+ foreach ( $links2d as $ns => $dbkeys ) {
+ foreach( $dbkeys as $dbkey => $id ) {
+ $this->addKeyword( $dbkey );
+ if ( ++$count > 10 ) {
+ break 2;
+ }
+ }
+ }
}
/**
- * @private
+ * @access private
* @return string
*/
function headElement() {
}
$ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
}
-
+
$p = $this->mRobotpolicy;
if( $p !== '' && $p != 'index,follow' ) {
// http://www.robotstxt.org/wc/meta-user.html
}
}
-
-} // MediaWiki
-
?>