53 private $permissionManager;
56 private $revisionLookup;
59 private $restrictionStore;
79 parent::__construct( $page, $context );
80 $this->hookRunner =
new HookRunner( $hookContainer );
81 $this->parser = $parser;
82 $this->permissionManager = $permissionManager;
83 $this->revisionLookup = $revisionLookup;
84 $this->restrictionStore = $restrictionStore;
106 $response = $request->response();
107 $config = $this->context->getConfig();
109 if ( $this->
getOutput()->checkLastModified(
117 $maxage = $request->getInt(
'maxage', $config->get( MainConfigNames::CdnMaxAge ) );
118 $smaxage = $request->getIntOrNull(
'smaxage' );
119 if ( $smaxage ===
null ) {
121 $contentType ==
'text/css' ||
122 $contentType ==
'application/json' ||
123 $contentType ==
'text/javascript'
128 $smaxage = intval( $config->get( MainConfigNames::ForcedRawSMaxage ) );
136 $response->header( $this->
getOutput()->getVaryHeader() );
140 $privateCache = !$this->permissionManager->isEveryoneAllowed(
'read' ) &&
141 ( $smaxage == 0 || MediaWiki\Session\SessionManager::getGlobalSession()->isPersistent() );
143 $privateCache = $privateCache || $this->
getUser()->isRegistered();
144 $mode = $privateCache ?
'private' :
'public';
146 'Cache-Control: ' . $mode .
', s-maxage=' . $smaxage .
', max-age=' . $maxage
154 if (
$title->isUserConfigPage() && $contentType !==
'text/x-wiki' ) {
157 $rootPage = strtok(
$title->getText(),
'/' );
159 if ( !$userFromTitle || !$userFromTitle->isRegistered() ) {
160 $elevated = $this->
getAuthority()->isAllowed(
'editinterface' );
161 $elevatedText = $elevated ?
'by elevated ' :
'';
162 $log = LoggerFactory::getInstance(
"security" );
164 "Unsafe JS/CSS/Json {$elevatedText}load - {user} loaded {title} with {ctype}",
167 'title' =>
$title->getPrefixedDBkey(),
168 'ctype' => $contentType,
169 'elevated' => $elevated
182 $pageRestrictions = $this->restrictionStore->getRestrictions(
$title,
'edit' );
184 $contentType ===
'text/javascript' &&
185 !
$title->isUserJsConfigPage() &&
187 !in_array(
'sysop', $pageRestrictions ) &&
188 !in_array(
'editprotected', $pageRestrictions )
191 $log = LoggerFactory::getInstance(
"security" );
192 $log->info(
"Blocked loading unprotected JS {title} for {user}",
195 'title' =>
$title->getPrefixedDBkey(),
201 $response->header(
'Content-type: ' . $contentType .
'; charset=UTF-8' );
209 if ( $text ===
false && $contentType ==
'text/x-wiki' ) {
210 $response->statusHeader( 404 );
213 if ( !$this->hookRunner->onRawPageViewBeforeOutput( $this, $text ) ) {
214 wfDebug( __METHOD__ .
": RawPageViewBeforeOutput hook broke raw page output." );
234 $rev = $this->revisionLookup->getRevisionByTitle(
$title, $this->
getOldId() );
236 $lastmod =
wfTimestamp( TS_RFC2822, $rev->getTimestamp() );
237 $request->response()->header(
"Last-modified: $lastmod" );
241 $slot = $this->
getRequest()->getText(
'slot' );
243 if ( $rev->hasSlot( $slot ) ) {
244 $content = $rev->getContent( $slot );
249 $content = $rev->getContent( SlotRecord::MAIN );
256 wfHttpError( 415,
"Unsupported Media Type",
"The requested page uses the content model `"
257 .
$content->getModel() .
"` which is not supported via this interface." );
261 $section = $request->getIntOrNull(
'section' );
262 if ( $section !==
null ) {
274 if ( $text !==
false && $text !==
'' && $request->getRawVal(
'templates' ) ===
'expand' ) {
275 $text = $this->parser->preprocess(
278 ParserOptions::newFromContext( $this->
getContext() )
291 $oldid = $this->
getRequest()->getInt(
'oldid' );
292 $rl = $this->revisionLookup;
293 switch ( $this->
getRequest()->getText(
'direction' ) ) {
295 # output next revision, or nothing if there isn't one
298 $oldRev = $rl->getRevisionById( $oldid );
300 $nextRev = $rl->getNextRevision( $oldRev );
303 $oldid = $nextRev ? $nextRev->getId() : -1;
306 # output previous revision, or nothing if there isn't one
309 # get the current revision so we can get the penultimate one
312 $oldRev = $rl->getRevisionById( $oldid );
314 $prevRev = $rl->getPreviousRevision( $oldRev );
316 $oldid = $prevRev ? $prevRev->getId() : -1;
334 $ctype = $this->
getRequest()->getRawVal(
'ctype' );
336 if ( $ctype ==
'' ) {
338 $gen = $this->
getRequest()->getRawVal(
'gen' );
339 if ( $gen ==
'js' ) {
340 $ctype =
'text/javascript';
341 } elseif ( $gen ==
'css' ) {
351 'application/x-zope-edit',
354 if ( $ctype ==
'' || !in_array( $ctype, $allowedCTypes ) ) {
355 $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.
getRequest()
Get the WebRequest being used for this instance.
Show an error that looks like an HTTP server error.
A class containing constants representing the names of configuration variables.
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.
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.
__construct(Page $page, IContextSource $context, HookContainer $hookContainer, Parser $parser, PermissionManager $permissionManager, RevisionLookup $revisionLookup, RestrictionStore $restrictionStore)
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)