Page MenuHomeWickedGov Phorge

ChannelFeed.php
No OneTemporary

Size
3 KB
Referenced Files
None
Subscribers
None

ChannelFeed.php

<?php
/**
* Copyright © 2004 Brooke Vibber <bvibber@wikimedia.org>
* https://www.mediawiki.org/
*
* @license GPL-2.0-or-later
* @file
*/
namespace MediaWiki\Feed;
use MediaWiki\Html\TemplateParser;
use MediaWiki\MainConfigNames;
use MediaWiki\MediaWikiServices;
/**
* Class to support the outputting of syndication feeds in Atom and RSS format.
*
* @stable to extend
* @ingroup Feed
*/
abstract class ChannelFeed extends FeedItem {
/** @var TemplateParser */
protected $templateParser;
/**
* @stable to call
*
* @param string $title Feed's title
* @param string $description
* @param string $url URL uniquely designating the feed.
* @param string $date Feed's date
* @param string $author Author's user name
* @param string $comments
*/
public function __construct(
$title, $description, $url, $date = '', $author = '', $comments = ''
) {
parent::__construct( $title, $description, $url, $date, $author, $comments );
$this->templateParser = new TemplateParser();
}
/**
* Generate Header of the feed
* @par Example:
* @code
* print "<feed>";
* @endcode
*/
abstract public function outHeader();
/**
* Generate an item
* @par Example:
* @code
* print "<item>...</item>";
* @endcode
* @param FeedItem $item
*/
abstract public function outItem( $item );
/**
* Generate Footer of the feed
* @par Example:
* @code
* print "</feed>";
* @endcode
*/
abstract public function outFooter();
/**
* Setup and send HTTP headers. Don't send any content;
* content might end up being cached and re-sent with
* these same headers later.
*
* This should be called from the outHeader() method,
* but can also be called separately.
*/
public function httpHeaders() {
global $wgOut;
$varyOnXFP = MediaWikiServices::getInstance()->getMainConfig()
->get( MainConfigNames::VaryOnXFP );
# We take over from $wgOut, excepting its cache header info
$wgOut->disable();
$mimetype = $this->contentType();
header( "Content-type: $mimetype; charset=UTF-8" );
// @todo Maybe set a CSP header here at some point as defense in depth.
// need to figure out how that interacts with browser display of article
// snippets.
// Set a sensible filename
$mimeAnalyzer = MediaWikiServices::getInstance()->getMimeAnalyzer();
$ext = $mimeAnalyzer->getExtensionFromMimeTypeOrNull( $mimetype ) ?? 'xml';
header( "Content-Disposition: inline; filename=\"feed.{$ext}\"" );
if ( $varyOnXFP ) {
$wgOut->addVaryHeader( 'X-Forwarded-Proto' );
}
$wgOut->sendCacheControl();
}
/**
* Return an internet media type to be sent in the headers.
*
* @stable to override
*
* @return string
*/
private function contentType() {
global $wgRequest;
$ctype = $wgRequest->getVal( 'ctype', 'application/xml' );
$allowedctypes = [
'application/xml',
'text/xml',
'application/rss+xml',
'application/atom+xml'
];
return ( in_array( $ctype, $allowedctypes ) ? $ctype : 'application/xml' );
}
/**
* Output the initial XML headers.
*/
protected function outXmlHeader() {
$this->httpHeaders();
echo '<?xml version="1.0"?>' . "\n";
}
}

File Metadata

Mime Type
text/x-php
Expires
Sat, Oct 3, 04:52 (3 w, 5 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
b0/83/176922aa79cf88d7d630b38fa029
Default Alt Text
ChannelFeed.php (3 KB)

Event Timeline