75 parent::__construct( $article, $context );
76 $this->parser = $parser;
77 $this->permissionManager = $permissionManager;
78 $this->revisionLookup = $revisionLookup;
79 $this->restrictionStore = $restrictionStore;
80 $this->userFactory = $userFactory;
103 $response = $request->response();
104 $config = $this->context->getConfig();
106 if ( $this->
getOutput()->checkLastModified(
115 $maxage = $request->getInt(
'maxage', $config->get( MainConfigNames::CdnMaxAge ) );
116 $smaxage = $request->getIntOrNull(
'smaxage' );
117 if ( $smaxage ===
null ) {
119 $contentType ===
'text/css' ||
120 $contentType ===
'application/json' ||
121 $contentType ===
'text/javascript'
126 $smaxage = intval( $config->get( MainConfigNames::ForcedRawSMaxage ) );
134 $response->header( $this->
getOutput()->getVaryHeader() );
138 $privateCache = !$this->permissionManager->isEveryoneAllowed(
'read' ) &&
139 ( $smaxage === 0 || SessionManager::getGlobalSession()->isPersistent() );
141 $privateCache = $privateCache || $this->
getUser()->isRegistered();
142 $mode = $privateCache ?
'private' :
'public';
144 'Cache-Control: ' . $mode .
', s-maxage=' . $smaxage .
', max-age=' . $maxage
152 if ( $title->isUserConfigPage() && $contentType !==
'text/x-wiki' ) {
155 $rootPage = strtok( $title->getText(),
'/' );
156 $userFromTitle = $this->userFactory->newFromName( $rootPage, UserRigorOptions::RIGOR_USABLE );
157 if ( !$userFromTitle || !$userFromTitle->isRegistered() ) {
158 $elevated = $this->
getAuthority()->isAllowed(
'editinterface' );
159 $elevatedText = $elevated ?
'by elevated ' :
'';
160 $log = LoggerFactory::getInstance(
"security" );
162 "Unsafe JS/CSS/Json {$elevatedText}load - {user} loaded {title} with {ctype}",
165 'title' => $title->getPrefixedDBkey(),
166 'ctype' => $contentType,
167 'elevated' => $elevated
180 $pageRestrictions = $this->restrictionStore->getRestrictions( $title,
'edit' );
182 $contentType ===
'text/javascript' &&
183 !$title->isUserJsConfigPage() &&
185 !in_array(
'sysop', $pageRestrictions ) &&
186 !in_array(
'editprotected', $pageRestrictions )
189 $log = LoggerFactory::getInstance(
"security" );
190 $log->info(
"Blocked loading unprotected JS {title} for {user}",
193 'title' => $title->getPrefixedDBkey(),
199 $response->header(
'Content-type: ' . $contentType .
'; charset=UTF-8' );
207 if ( $text ===
false && $contentType ===
'text/x-wiki' ) {
208 $response->statusHeader( 404 );
211 if ( !$this->
getHookRunner()->onRawPageViewBeforeOutput( $this, $text ) ) {
212 wfDebug( __METHOD__ .
": RawPageViewBeforeOutput hook broke raw page output." );
232 $rev = $this->revisionLookup->getRevisionByTitle( $title, $this->
getOldId() );
234 $lastMod =
wfTimestamp( TS_RFC2822, $rev->getTimestamp() );
235 $request->response()->header(
"Last-modified: $lastMod" );
239 $slot = $this->
getRequest()->getText(
'slot' );
241 if ( $rev->hasSlot( $slot ) ) {
242 $content = $rev->getContent( $slot );
247 $content = $rev->getContent( SlotRecord::MAIN );
250 if ( $content ===
null ) {
252 } elseif ( !$content instanceof
TextContent && !method_exists( $content,
'getText' ) ) {
256 "Unsupported Media Type",
"The requested page uses the content model `"
257 . $content->getModel() .
"` which is not supported via this interface."
262 $section = $request->getIntOrNull(
'section' );
263 if ( $section !==
null ) {
264 $content = $content->getSection( $section );
267 if ( $content !==
null && $content !==
false ) {
269 $text = $content->getText();
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;
338 $gen = $this->
getRequest()->getRawVal(
'gen' );
339 if ( $gen ==
'js' ) {
340 $ctype =
'text/javascript';
341 } elseif ( $gen ==
'css' ) {
346 static $allowedCTypes = [
351 'application/x-zope-edit',
354 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.
getContext()
Get the IContextSource in use here.
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User being used for this instance.
getAuthority()
Shortcut to get the Authority executing 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.
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()
Indicates whether this action page write access to the wiki.
__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.