* License: GPL (http://www.gnu.org/copyleft/gpl.html)
*
* @author Gabriel Wicke <wicke@wikidev.net>
- * @package MediaWiki
*/
/**
- * @todo document
- * @package MediaWiki
+ * A simple method to retrieve the plain source of an article,
+ * using "action=raw" in the GET request string.
*/
class RawPage {
var $mArticle, $mTitle, $mRequest;
var $mSmaxage, $mMaxage;
var $mContentType, $mExpandTemplates;
- function RawPage( &$article, $request = false ) {
+ function __construct( &$article, $request = false ) {
global $wgRequest, $wgInputEncoding, $wgSquidMaxage, $wgJsMimeType;
$allowedCTypes = array('text/x-wiki', $wgJsMimeType, 'text/css', 'application/x-zope-edit');
$maxage = $this->mRequest->getInt( 'maxage', $wgSquidMaxage );
$this->mExpandTemplates = $this->mRequest->getVal( 'templates' ) === 'expand';
$this->mUseMessageCache = $this->mRequest->getBool( 'usemsgcache' );
-
+
$oldid = $this->mRequest->getInt( 'oldid' );
switch ( $wgRequest->getText( 'direction' ) ) {
case 'next':
$this->mCharset = $wgInputEncoding;
$this->mSmaxage = intval( $smaxage );
$this->mMaxage = $maxage;
+
+ // Output may contain user-specific data; vary for open sessions
+ $this->mPrivateCache = ( $this->mSmaxage == 0 ) ||
+ ( session_id() != '' );
+
if ( $ctype == '' or ! in_array( $ctype, $allowedCTypes ) ) {
$this->mContentType = 'text/x-wiki';
} else {
header( "Content-type: ".$this->mContentType.'; charset='.$this->mCharset );
# allow the client to cache this for 24 hours
- header( 'Cache-Control: s-maxage='.$this->mSmaxage.', max-age='.$this->mMaxage );
- echo $this->getRawText();
+ $mode = $this->mPrivateCache ? 'private' : 'public';
+ header( 'Cache-Control: '.$mode.', s-maxage='.$this->mSmaxage.', max-age='.$this->mMaxage );
+ $text = $this->getRawText();
+
+ if( !wfRunHooks( 'RawPageViewBeforeOutput', array( &$this, &$text ) ) ) {
+ wfDebug( __METHOD__ . ': RawPageViewBeforeOutput hook broke raw page output.' );
+ }
+
+ echo $text;
$wgOut->disable();
}
function getRawText() {
- global $wgUser, $wgOut;
+ global $wgUser, $wgOut, $wgRequest;
if($this->mGen) {
$sk = $wgUser->getSkin();
$sk->initPage($wgOut);
$key = $this->mTitle->getDBkey();
$text = wfMsgForContentNoTrans( $key );
# If the message doesn't exist, return a blank
- if( $text == '<' . $key . '>' )
+ if( wfEmptyMsg( $key, $text ) )
$text = '';
$found = true;
} else {
header( "HTTP/1.0 404 Not Found" );
}
+ // Special-case for empty CSS/JS
+ //
+ // Internet Explorer for Mac handles empty files badly;
+ // particularly so when keep-alive is active. It can lead
+ // to long timeouts as it seems to sit there waiting for
+ // more data that never comes.
+ //
+ // Give it a comment...
+ if( strlen( $text ) == 0 &&
+ ($this->mContentType == 'text/css' ||
+ $this->mContentType == 'text/javascript' ) ) {
+ return "/* Empty */";
+ }
+
return $this->parseArticleText( $text );
}
return '';
else
if ( $this->mExpandTemplates ) {
- global $wgTitle;
-
- $parser = new Parser();
- $parser->Options( new ParserOptions() ); // We don't want this to be user-specific
- $parser->Title( $wgTitle );
- $parser->OutputType( OT_HTML );
-
- return $parser->replaceVariables( $text );
+ global $wgParser;
+ return $wgParser->preprocess( $text, $this->mTitle, new ParserOptions() );
} else
return $text;
}