74 parent::__construct( $article, $context );
75 $this->parser = $parser;
76 $this->permissionManager = $permissionManager;
77 $this->revisionLookup = $revisionLookup;
78 $this->restrictionStore = $restrictionStore;
79 $this->userFactory = $userFactory;
102 $response = $request->response();
103 $config = $this->context->getConfig();
105 if ( $this->
getOutput()->checkLastModified(
114 $maxage = $request->getInt(
'maxage', $config->get( MainConfigNames::CdnMaxAge ) );
115 $smaxage = $request->getIntOrNull(
'smaxage' );
116 if ( $smaxage ===
null ) {
118 $contentType ===
'text/css' ||
119 $contentType ===
'application/json' ||
120 $contentType ===
'text/javascript'
125 $smaxage = intval( $config->get( MainConfigNames::ForcedRawSMaxage ) );
133 $response->header( $this->
getOutput()->getVaryHeader() );
137 $privateCache = !$this->permissionManager->isEveryoneAllowed(
'read' ) &&
138 ( $smaxage === 0 || SessionManager::getGlobalSession()->isPersistent() );
140 $privateCache = $privateCache || $this->
getUser()->isRegistered();
141 $mode = $privateCache ?
'private' :
'public';
143 'Cache-Control: ' . $mode .
', s-maxage=' . $smaxage .
', max-age=' . $maxage
151 if ( $title->isUserConfigPage() && $contentType !==
'text/x-wiki' ) {
154 $rootPage = strtok( $title->getText(),
'/' );
155 $userFromTitle = $this->userFactory->newFromName( $rootPage, UserRigorOptions::RIGOR_USABLE );
156 if ( !$userFromTitle || !$userFromTitle->isRegistered() ) {
157 $elevated = $this->
getAuthority()->isAllowed(
'editinterface' );
158 $elevatedText = $elevated ?
'by elevated ' :
'';
159 $log = LoggerFactory::getInstance(
"security" );
161 "Unsafe JS/CSS/Json {$elevatedText}load - {user} loaded {title} with {ctype}",
164 'title' => $title->getPrefixedDBkey(),
165 'ctype' => $contentType,
166 'elevated' => $elevated
179 $pageRestrictions = $this->restrictionStore->getRestrictions( $title,
'edit' );
181 $contentType ===
'text/javascript' &&
182 !$title->isUserJsConfigPage() &&
184 !in_array(
'sysop', $pageRestrictions ) &&
185 !in_array(
'editprotected', $pageRestrictions )
188 $log = LoggerFactory::getInstance(
"security" );
189 $log->info(
"Blocked loading unprotected JS {title} for {user}",
192 'title' => $title->getPrefixedDBkey(),
198 $response->header(
'Content-type: ' . $contentType .
'; charset=UTF-8' );
206 if ( $text ===
false && $contentType ===
'text/x-wiki' ) {
207 $response->statusHeader( 404 );
210 if ( !$this->
getHookRunner()->onRawPageViewBeforeOutput( $this, $text ) ) {
211 wfDebug( __METHOD__ .
": RawPageViewBeforeOutput hook broke raw page output." );
231 $rev = $this->revisionLookup->getRevisionByTitle( $title, $this->
getOldId() );
233 $lastMod =
wfTimestamp( TS_RFC2822, $rev->getTimestamp() );
234 $request->response()->header(
"Last-modified: $lastMod" );
238 $slot = $this->
getRequest()->getText(
'slot' );
240 if ( $rev->hasSlot( $slot ) ) {
241 $content = $rev->getContent( $slot );
246 $content = $rev->getContent( SlotRecord::MAIN );
249 if ( $content ===
null ) {
251 } elseif ( !$content instanceof
TextContent && !method_exists( $content,
'getText' ) ) {
255 "Unsupported Media Type",
"The requested page uses the content model `"
256 . $content->getModel() .
"` which is not supported via this interface."
261 $section = $request->getIntOrNull(
'section' );
262 if ( $section !==
null ) {
263 $content = $content->getSection( $section );
266 if ( $content !==
null && $content !==
false ) {
268 $text = $content->getText();
273 if ( $text !==
false && $text !==
'' && $request->getRawVal(
'templates' ) ===
'expand' ) {
274 $text = $this->parser->preprocess(
277 ParserOptions::newFromContext( $this->
getContext() )
290 $oldId = $this->
getRequest()->getInt(
'oldid' );
291 $rl = $this->revisionLookup;
292 switch ( $this->
getRequest()->getText(
'direction' ) ) {
294 # output next revision, or nothing if there isn't one
297 $oldRev = $rl->getRevisionById( $oldId );
299 $nextRev = $rl->getNextRevision( $oldRev );
302 $oldId = $nextRev ? $nextRev->getId() : -1;
305 # output previous revision, or nothing if there isn't one
308 # get the current revision so we can get the penultimate one
311 $oldRev = $rl->getRevisionById( $oldId );
313 $prevRev = $rl->getPreviousRevision( $oldRev );
315 $oldId = $prevRev ? $prevRev->getId() : -1;
337 $gen = $this->
getRequest()->getRawVal(
'gen' );
338 if ( $gen ==
'js' ) {
339 $ctype =
'text/javascript';
340 } elseif ( $gen ==
'css' ) {
345 static $allowedCTypes = [
350 'application/x-zope-edit',
353 if (
$ctype ==
'' || !in_array(
$ctype, $allowedCTypes ) ) {
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.
Content object implementation for representing flat text.
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 be used 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.1.17string Lowercase name
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 be used to get the text.
Interface for objects which can provide a MediaWiki context on request.