72 parent::__construct( $article, $context );
73 $this->parser = $parser;
74 $this->permissionManager = $permissionManager;
75 $this->revisionLookup = $revisionLookup;
76 $this->restrictionStore = $restrictionStore;
77 $this->userFactory = $userFactory;
99 $response = $request->response();
100 $config = $this->context->getConfig();
102 if ( $this->
getOutput()->checkLastModified(
110 $maxage = $request->getInt(
'maxage', $config->get( MainConfigNames::CdnMaxAge ) );
111 $smaxage = $request->getIntOrNull(
'smaxage' );
112 if ( $smaxage ===
null ) {
114 $contentType ==
'text/css' ||
115 $contentType ==
'application/json' ||
116 $contentType ==
'text/javascript'
121 $smaxage = intval( $config->get( MainConfigNames::ForcedRawSMaxage ) );
129 $response->header( $this->
getOutput()->getVaryHeader() );
133 $privateCache = !$this->permissionManager->isEveryoneAllowed(
'read' ) &&
134 ( $smaxage == 0 || MediaWiki\Session\SessionManager::getGlobalSession()->isPersistent() );
136 $privateCache = $privateCache || $this->
getUser()->isRegistered();
137 $mode = $privateCache ?
'private' :
'public';
139 'Cache-Control: ' . $mode .
', s-maxage=' . $smaxage .
', max-age=' . $maxage
147 if ( $title->isUserConfigPage() && $contentType !==
'text/x-wiki' ) {
150 $rootPage = strtok( $title->getText(),
'/' );
151 $userFromTitle = $this->userFactory->newFromName( $rootPage, UserRigorOptions::RIGOR_USABLE );
152 if ( !$userFromTitle || !$userFromTitle->isRegistered() ) {
153 $elevated = $this->
getAuthority()->isAllowed(
'editinterface' );
154 $elevatedText = $elevated ?
'by elevated ' :
'';
155 $log = LoggerFactory::getInstance(
"security" );
157 "Unsafe JS/CSS/Json {$elevatedText}load - {user} loaded {title} with {ctype}",
160 'title' => $title->getPrefixedDBkey(),
161 'ctype' => $contentType,
162 'elevated' => $elevated
175 $pageRestrictions = $this->restrictionStore->getRestrictions( $title,
'edit' );
177 $contentType ===
'text/javascript' &&
178 !$title->isUserJsConfigPage() &&
180 !in_array(
'sysop', $pageRestrictions ) &&
181 !in_array(
'editprotected', $pageRestrictions )
184 $log = LoggerFactory::getInstance(
"security" );
185 $log->info(
"Blocked loading unprotected JS {title} for {user}",
188 'title' => $title->getPrefixedDBkey(),
194 $response->header(
'Content-type: ' . $contentType .
'; charset=UTF-8' );
202 if ( $text ===
false && $contentType ==
'text/x-wiki' ) {
203 $response->statusHeader( 404 );
206 if ( !$this->
getHookRunner()->onRawPageViewBeforeOutput( $this, $text ) ) {
207 wfDebug( __METHOD__ .
": RawPageViewBeforeOutput hook broke raw page output." );
227 $rev = $this->revisionLookup->getRevisionByTitle( $title, $this->
getOldId() );
229 $lastmod =
wfTimestamp( TS_RFC2822, $rev->getTimestamp() );
230 $request->response()->header(
"Last-modified: $lastmod" );
234 $slot = $this->
getRequest()->getText(
'slot' );
236 if ( $rev->hasSlot( $slot ) ) {
237 $content = $rev->getContent( $slot );
242 $content = $rev->getContent( SlotRecord::MAIN );
245 if ( $content ===
null ) {
247 } elseif ( !$content instanceof
TextContent && !method_exists( $content,
'getText' ) ) {
249 wfHttpError( 415,
"Unsupported Media Type",
"The requested page uses the content model `"
250 . $content->getModel() .
"` which is not supported via this interface." );
254 $section = $request->getIntOrNull(
'section' );
255 if ( $section !==
null ) {
256 $content = $content->getSection( $section );
259 if ( $content ===
null || $content ===
false ) {
262 $text = $content->getText();
267 if ( $text !==
false && $text !==
'' && $request->getRawVal(
'templates' ) ===
'expand' ) {
268 $text = $this->parser->preprocess(
271 ParserOptions::newFromContext( $this->
getContext() )
284 $oldid = $this->
getRequest()->getInt(
'oldid' );
285 $rl = $this->revisionLookup;
286 switch ( $this->
getRequest()->getText(
'direction' ) ) {
288 # output next revision, or nothing if there isn't one
291 $oldRev = $rl->getRevisionById( $oldid );
293 $nextRev = $rl->getNextRevision( $oldRev );
296 $oldid = $nextRev ? $nextRev->getId() : -1;
299 # output previous revision, or nothing if there isn't one
302 # get the current revision so we can get the penultimate one
305 $oldRev = $rl->getRevisionById( $oldid );
307 $prevRev = $rl->getPreviousRevision( $oldRev );
309 $oldid = $prevRev ? $prevRev->getId() : -1;
327 $ctype = $this->
getRequest()->getRawVal(
'ctype' );
329 if ( $ctype ==
'' ) {
331 $gen = $this->
getRequest()->getRawVal(
'gen' );
332 if ( $gen ==
'js' ) {
333 $ctype =
'text/javascript';
334 } elseif ( $gen ==
'css' ) {
344 'application/x-zope-edit',
347 if ( $ctype ==
'' || !in_array( $ctype, $allowedCTypes ) ) {
348 $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.
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.
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(Article $article, IContextSource $context, Parser $parser, PermissionManager $permissionManager, RevisionLookup $revisionLookup, RestrictionStore $restrictionStore, UserFactory $userFactory)
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.
Interface for objects which can provide a MediaWiki context on request.