66 parent::__construct( $article, $context );
67 $this->parser = $parser;
68 $this->permissionManager = $permissionManager;
69 $this->revisionLookup = $revisionLookup;
70 $this->restrictionStore = $restrictionStore;
92 $response = $request->response();
93 $config = $this->context->getConfig();
95 if ( $this->
getOutput()->checkLastModified(
103 $maxage = $request->getInt(
'maxage', $config->get( MainConfigNames::CdnMaxAge ) );
104 $smaxage = $request->getIntOrNull(
'smaxage' );
105 if ( $smaxage ===
null ) {
107 $contentType ==
'text/css' ||
108 $contentType ==
'application/json' ||
109 $contentType ==
'text/javascript'
114 $smaxage = intval( $config->get( MainConfigNames::ForcedRawSMaxage ) );
122 $response->header( $this->
getOutput()->getVaryHeader() );
126 $privateCache = !$this->permissionManager->isEveryoneAllowed(
'read' ) &&
127 ( $smaxage == 0 || MediaWiki\Session\SessionManager::getGlobalSession()->isPersistent() );
129 $privateCache = $privateCache || $this->
getUser()->isRegistered();
130 $mode = $privateCache ?
'private' :
'public';
132 'Cache-Control: ' . $mode .
', s-maxage=' . $smaxage .
', max-age=' . $maxage
140 if ( $title->isUserConfigPage() && $contentType !==
'text/x-wiki' ) {
143 $rootPage = strtok( $title->getText(),
'/' );
144 $userFromTitle = User::newFromName( $rootPage,
'usable' );
145 if ( !$userFromTitle || !$userFromTitle->isRegistered() ) {
146 $elevated = $this->
getAuthority()->isAllowed(
'editinterface' );
147 $elevatedText = $elevated ?
'by elevated ' :
'';
148 $log = LoggerFactory::getInstance(
"security" );
150 "Unsafe JS/CSS/Json {$elevatedText}load - {user} loaded {title} with {ctype}",
153 'title' => $title->getPrefixedDBkey(),
154 'ctype' => $contentType,
155 'elevated' => $elevated
168 $pageRestrictions = $this->restrictionStore->getRestrictions( $title,
'edit' );
170 $contentType ===
'text/javascript' &&
171 !$title->isUserJsConfigPage() &&
173 !in_array(
'sysop', $pageRestrictions ) &&
174 !in_array(
'editprotected', $pageRestrictions )
177 $log = LoggerFactory::getInstance(
"security" );
178 $log->info(
"Blocked loading unprotected JS {title} for {user}",
181 'title' => $title->getPrefixedDBkey(),
187 $response->header(
'Content-type: ' . $contentType .
'; charset=UTF-8' );
195 if ( $text ===
false && $contentType ==
'text/x-wiki' ) {
196 $response->statusHeader( 404 );
199 if ( !$this->
getHookRunner()->onRawPageViewBeforeOutput( $this, $text ) ) {
200 wfDebug( __METHOD__ .
": RawPageViewBeforeOutput hook broke raw page output." );
220 $rev = $this->revisionLookup->getRevisionByTitle( $title, $this->
getOldId() );
222 $lastmod =
wfTimestamp( TS_RFC2822, $rev->getTimestamp() );
223 $request->response()->header(
"Last-modified: $lastmod" );
227 $slot = $this->
getRequest()->getText(
'slot' );
229 if ( $rev->hasSlot( $slot ) ) {
230 $content = $rev->getContent( $slot );
235 $content = $rev->getContent( SlotRecord::MAIN );
242 wfHttpError( 415,
"Unsupported Media Type",
"The requested page uses the content model `"
243 .
$content->getModel() .
"` which is not supported via this interface." );
247 $section = $request->getIntOrNull(
'section' );
248 if ( $section !==
null ) {
260 if ( $text !==
false && $text !==
'' && $request->getRawVal(
'templates' ) ===
'expand' ) {
261 $text = $this->parser->preprocess(
264 ParserOptions::newFromContext( $this->
getContext() )
277 $oldid = $this->
getRequest()->getInt(
'oldid' );
278 $rl = $this->revisionLookup;
279 switch ( $this->
getRequest()->getText(
'direction' ) ) {
281 # output next revision, or nothing if there isn't one
284 $oldRev = $rl->getRevisionById( $oldid );
286 $nextRev = $rl->getNextRevision( $oldRev );
289 $oldid = $nextRev ? $nextRev->getId() : -1;
292 # output previous revision, or nothing if there isn't one
295 # get the current revision so we can get the penultimate one
298 $oldRev = $rl->getRevisionById( $oldid );
300 $prevRev = $rl->getPreviousRevision( $oldRev );
302 $oldid = $prevRev ? $prevRev->getId() : -1;
320 $ctype = $this->
getRequest()->getRawVal(
'ctype' );
322 if ( $ctype ==
'' ) {
324 $gen = $this->
getRequest()->getRawVal(
'gen' );
325 if ( $gen ==
'js' ) {
326 $ctype =
'text/javascript';
327 } elseif ( $gen ==
'css' ) {
337 'application/x-zope-edit',
340 if ( $ctype ==
'' || !in_array( $ctype, $allowedCTypes ) ) {
341 $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.
Legacy class representing an editable page and handling UI for some page actions.
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.
requiresUnblock()
Whether this action can still be executed by a blocked user.
__construct(Article $article, IContextSource $context, Parser $parser, PermissionManager $permissionManager, RevisionLookup $revisionLookup, RestrictionStore $restrictionStore)
getOldId()
Get the ID of the revision that should used to get the text.
Content object implementation for representing flat text.
Interface for objects which can provide a MediaWiki context on request.