72 parent::__construct( $page, $context );
73 $this->hookRunner =
new HookRunner( $hookContainer );
74 $this->parser = $parser;
75 $this->permissionManager = $permissionManager;
76 $this->revisionLookup = $revisionLookup;
98 $response = $request->response();
99 $config = $this->context->getConfig();
101 if ( $this->
getOutput()->checkLastModified(
109 $maxage = $request->getInt(
'maxage', $config->get(
'CdnMaxAge' ) );
110 $smaxage = $request->getIntOrNull(
'smaxage' );
111 if ( $smaxage ===
null ) {
113 $contentType ==
'text/css' ||
114 $contentType ==
'application/json' ||
115 $contentType ==
'text/javascript'
120 $smaxage = intval( $config->get(
'ForcedRawSMaxage' ) );
128 $response->header( $this->
getOutput()->getVaryHeader() );
132 $privateCache = !$this->permissionManager->isEveryoneAllowed(
'read' ) &&
133 ( $smaxage == 0 || MediaWiki\Session\SessionManager::getGlobalSession()->isPersistent() );
135 $privateCache = $privateCache || $this->
getUser()->isRegistered();
136 $mode = $privateCache ?
'private' :
'public';
138 'Cache-Control: ' . $mode .
', s-maxage=' . $smaxage .
', max-age=' . $maxage
146 if (
$title->isUserConfigPage() && $contentType !==
'text/x-wiki' ) {
149 $rootPage = strtok(
$title->getText(),
'/' );
151 if ( !$userFromTitle || $userFromTitle->getId() === 0 ) {
152 $elevated = $this->
getContext()->getAuthority()->isAllowed(
'editinterface' );
153 $elevatedText = $elevated ?
'by elevated ' :
'';
154 $log = LoggerFactory::getInstance(
"security" );
156 "Unsafe JS/CSS/Json {$elevatedText}load - {user} loaded {title} with {ctype}",
159 'title' =>
$title->getPrefixedDBkey(),
160 'ctype' => $contentType,
161 'elevated' => $elevated
175 $contentType ===
'text/javascript' &&
176 !
$title->isUserJsConfigPage() &&
178 !in_array(
'sysop',
$title->getRestrictions(
'edit' ) ) &&
179 !in_array(
'editprotected',
$title->getRestrictions(
'edit' ) )
182 $log = LoggerFactory::getInstance(
"security" );
183 $log->info(
"Blocked loading unprotected JS {title} for {user}",
186 'title' =>
$title->getPrefixedDBkey(),
192 $response->header(
'Content-type: ' . $contentType .
'; charset=UTF-8' );
200 if ( $text ===
false && $contentType ==
'text/x-wiki' ) {
201 $response->statusHeader( 404 );
204 if ( !$this->hookRunner->onRawPageViewBeforeOutput( $this, $text ) ) {
205 wfDebug( __METHOD__ .
": RawPageViewBeforeOutput hook broke raw page output." );
225 $rev = $this->revisionLookup->getRevisionByTitle(
$title, $this->
getOldId() );
227 $lastmod =
wfTimestamp( TS_RFC2822, $rev->getTimestamp() );
228 $request->response()->header(
"Last-modified: $lastmod" );
231 $content = $rev->getContent( SlotRecord::MAIN );
237 wfHttpError( 415,
"Unsupported Media Type",
"The requested page uses the content model `"
238 .
$content->getModel() .
"` which is not supported via this interface." );
242 $section = $request->getIntOrNull(
'section' );
243 if ( $section !==
null ) {
255 if ( $text !==
false && $text !==
'' && $request->getRawVal(
'templates' ) ===
'expand' ) {
256 $text = $this->parser->preprocess(
259 ParserOptions::newFromContext( $this->
getContext() )
272 $oldid = $this->
getRequest()->getInt(
'oldid' );
273 $rl = $this->revisionLookup;
274 switch ( $this->
getRequest()->getText(
'direction' ) ) {
276 # output next revision, or nothing if there isn't one
279 $oldRev = $rl->getRevisionById( $oldid );
281 $nextRev = $rl->getNextRevision( $oldRev );
284 $oldid = $nextRev ? $nextRev->getId() : -1;
287 # output previous revision, or nothing if there isn't one
290 # get the current revision so we can get the penultimate one
293 $oldRev = $rl->getRevisionById( $oldid );
295 $prevRev = $rl->getPreviousRevision( $oldRev );
297 $oldid = $prevRev ? $prevRev->getId() : -1;
314 $ctype = $this->
getRequest()->getRawVal(
'ctype' );
316 if ( $ctype ==
'' ) {
318 $gen = $this->
getRequest()->getRawVal(
'gen' );
319 if ( $gen ==
'js' ) {
320 $ctype =
'text/javascript';
321 } elseif ( $gen ==
'css' ) {
331 'application/x-zope-edit',
334 if ( $ctype ==
'' || !in_array( $ctype, $allowedCTypes ) ) {
335 $ctype =
'text/x-wiki';
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfHttpError( $code, $label, $desc)
Provide a simple HTTP error.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
getWikiPage()
Get a WikiPage object.
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User being used for this instance.
getRequest()
Get the WebRequest being used for this instance.
Show an error that looks like an HTTP server error.
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
A simple method to retrieve the plain source of an article, using "action=raw" in the GET request str...
getContentType()
Get the content type to use for the response.
__construct(Page $page, IContextSource $context, HookContainer $hookContainer, Parser $parser, PermissionManager $permissionManager, RevisionLookup $revisionLookup)
getRawText()
Get the text that should be returned, or false if the page or revision was not found.
getName()
Return the name of the action this object responds to.
requiresWrite()
Whether this action requires the wiki not to be locked.
PermissionManager $permissionManager
RevisionLookup $revisionLookup
requiresUnblock()
Whether this action can still be executed by a blocked user.
getOldId()
Get the ID of the revision that should used to get the text.
Content object implementation for representing flat text.
static newFromName( $name, $validate='valid')
Interface for objects which can provide a MediaWiki context on request.
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)