73 parent::__construct( $article, $context );
74 $this->parser = $parser;
75 $this->permissionManager = $permissionManager;
76 $this->revisionLookup = $revisionLookup;
77 $this->restrictionStore = $restrictionStore;
78 $this->userFactory = $userFactory;
101 $response = $request->response();
102 $config = $this->context->getConfig();
104 if ( $this->
getOutput()->checkLastModified(
113 $maxage = $request->getInt(
'maxage', $config->get( MainConfigNames::CdnMaxAge ) );
114 $smaxage = $request->getIntOrNull(
'smaxage' );
115 if ( $smaxage ===
null ) {
117 $contentType ===
'text/css' ||
118 $contentType ===
'application/json' ||
119 $contentType ===
'text/javascript'
124 $smaxage = intval( $config->get( MainConfigNames::ForcedRawSMaxage ) );
132 $response->header( $this->
getOutput()->getVaryHeader() );
136 $privateCache = !$this->permissionManager->isEveryoneAllowed(
'read' ) &&
137 ( $smaxage === 0 || SessionManager::getGlobalSession()->isPersistent() );
139 $privateCache = $privateCache || $this->
getUser()->isRegistered();
140 $mode = $privateCache ?
'private' :
'public';
142 'Cache-Control: ' . $mode .
', s-maxage=' . $smaxage .
', max-age=' . $maxage
150 if ( $title->isUserConfigPage() && $contentType !==
'text/x-wiki' ) {
153 $rootPage = strtok( $title->getText(),
'/' );
154 $userFromTitle = $this->userFactory->newFromName( $rootPage, UserRigorOptions::RIGOR_USABLE );
155 if ( !$userFromTitle || !$userFromTitle->isRegistered() ) {
156 $elevated = $this->
getAuthority()->isAllowed(
'editinterface' );
157 $elevatedText = $elevated ?
'by elevated ' :
'';
158 $log = LoggerFactory::getInstance(
"security" );
160 "Unsafe JS/CSS/Json {$elevatedText}load - {user} loaded {title} with {ctype}",
163 'title' => $title->getPrefixedDBkey(),
164 'ctype' => $contentType,
165 'elevated' => $elevated
178 $pageRestrictions = $this->restrictionStore->getRestrictions( $title,
'edit' );
180 $contentType ===
'text/javascript' &&
181 !$title->isUserJsConfigPage() &&
183 !in_array(
'sysop', $pageRestrictions ) &&
184 !in_array(
'editprotected', $pageRestrictions )
187 $log = LoggerFactory::getInstance(
"security" );
188 $log->info(
"Blocked loading unprotected JS {title} for {user}",
191 'title' => $title->getPrefixedDBkey(),
197 $response->header(
'Content-type: ' . $contentType .
'; charset=UTF-8' );
205 if ( $text ===
false && $contentType ===
'text/x-wiki' ) {
206 $response->statusHeader( 404 );
209 if ( !$this->
getHookRunner()->onRawPageViewBeforeOutput( $this, $text ) ) {
210 wfDebug( __METHOD__ .
": RawPageViewBeforeOutput hook broke raw page output." );
230 $rev = $this->revisionLookup->getRevisionByTitle( $title, $this->
getOldId() );
232 $lastMod =
wfTimestamp( TS_RFC2822, $rev->getTimestamp() );
233 $request->response()->header(
"Last-modified: $lastMod" );
237 $slot = $this->
getRequest()->getText(
'slot' );
239 if ( $rev->hasSlot( $slot ) ) {
240 $content = $rev->getContent( $slot );
245 $content = $rev->getContent( SlotRecord::MAIN );
248 if ( $content ===
null ) {
250 } elseif ( !$content instanceof
TextContent && !method_exists( $content,
'getText' ) ) {
254 "Unsupported Media Type",
"The requested page uses the content model `"
255 . $content->getModel() .
"` which is not supported via this interface."
260 $section = $request->getIntOrNull(
'section' );
261 if ( $section !==
null ) {
262 $content = $content->getSection( $section );
265 if ( $content !==
null && $content !==
false ) {
267 $text = $content->getText();
272 if ( $text !==
false && $text !==
'' && $request->getRawVal(
'templates' ) ===
'expand' ) {
273 $text = $this->parser->preprocess(
276 ParserOptions::newFromContext( $this->
getContext() )
289 $oldId = $this->
getRequest()->getInt(
'oldid' );
290 $rl = $this->revisionLookup;
291 switch ( $this->
getRequest()->getText(
'direction' ) ) {
293 # output next revision, or nothing if there isn't one
296 $oldRev = $rl->getRevisionById( $oldId );
298 $nextRev = $rl->getNextRevision( $oldRev );
301 $oldId = $nextRev ? $nextRev->getId() : -1;
304 # output previous revision, or nothing if there isn't one
307 # get the current revision so we can get the penultimate one
310 $oldRev = $rl->getRevisionById( $oldId );
312 $prevRev = $rl->getPreviousRevision( $oldRev );
314 $oldId = $prevRev ? $prevRev->getId() : -1;
332 $ctype = $this->
getRequest()->getRawVal(
'ctype' );
334 if ( $ctype ==
'' ) {
336 $gen = $this->
getRequest()->getRawVal(
'gen' );
337 if ( $gen ==
'js' ) {
338 $ctype =
'text/javascript';
339 } elseif ( $gen ==
'css' ) {
344 static $allowedCTypes = [
349 'application/x-zope-edit',
352 if ( $ctype ==
'' || !in_array( $ctype, $allowedCTypes ) ) {
353 $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 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.
Content object implementation for representing flat text.
Interface for objects which can provide a MediaWiki context on request.