MediaWiki master
MediaWiki\MediaWikiEntryPoint Class Reference

Base class for entry point handlers. More...

Inherited by MediaWiki, MediaWiki\Actions\ActionEntryPoint, MediaWiki\Api\ApiEntryPoint, MediaWiki\FileRepo\ThumbnailEntryPoint, MediaWiki\ResourceLoader\ResourceLoaderEntryPoint, and MediaWiki\Rest\EntryPoint.

Collaboration diagram for MediaWiki\MediaWikiEntryPoint:

Public Member Functions

 __construct (IContextSource $context, EntryPointEnvironment $environment, MediaWikiServices $mediaWikiServices)
 
 enableOutputCapture ()
 Enable capturing of the current output buffer.
 
 getCapturedOutput ()
 Stop capturing and return all output.
 
 getRequestPathSuffix ( $basePath)
 If the request URL matches a given base path, extract the path part of the request URL after that base, and decode escape sequences in it.
 
 run ()
 Main app life cycle: Calls doSetup(), execute(), prepareForOutput(), and postOutputShutdown().
 

Static Public Member Functions

static emitBufferedStatsdData (IBufferingStatsdDataFactory $stats, Config $config)
 Send out any buffered statsd data according to sampling rules.
 

Protected Member Functions

 commitMainTransaction ()
 This function commits all DB and session changes as needed before the client can receive a response (in case DB commit fails) and thus also before the response can trigger a subsequent related request by the client.
 
 commitOutputBuffer ()
 Ends the current output buffer, appending its content to the parent buffer.
 
 disableModDeflate ()
 
 discardAllOutput ()
 Discards all buffered output, down to the capture buffer level.
 
 discardOutputBuffer ()
 
 doPostOutputShutdown ()
 Forces the response to be sent to the client and then does work that can be done after the user gets the HTTP response, so they don't block on it.
 
 doPrepareForOutput ()
 Prepare for sending the output.
 
 doSetup ()
 Perform any setup needed before execute() is called.
 
 drainOutputBuffer ()
 Returns the content of the current output buffer and clears it.
 
 enterPostSendMode ()
 Disables all output to the client.
 
 execute ()
 Subclasses implement the entry point's functionality by overriding this method.
 
 exit (int $code=0)
 
 fastCgiFinishRequest ()
 Calls fastcgi_finish_request if possible.
 
 flushOutputBuffer ()
 Flush buffered output to the client.
 
 getBlockManager ()
 
 getConfig (string $key)
 
 getContext ()
 
 getDBLoadBalancerFactory ()
 
 getEnv (string $name)
 Returns the value of an environment variable.
 
 getIni (string $name)
 Returns the value of an ini option.
 
 getJobQueueGroupFactory ()
 
 getJobRunner ()
 
 getMessageCache ()
 
 getOutputBufferLength ()
 
 getOutputBufferLevel ()
 Returns the output buffer level.
 
 getOutputBufferStatus ()
 
 getReadOnlyMode ()
 
 getRequest ()
 
 getRequestURL ()
 Returns the current request's path and query string (not a full URL), like PHP's built-in $_SERVER['REQUEST_URI'].
 
 getResponse ()
 
 getServerInfo (string $key, $default=null)
 
 getServiceContainer ()
 Returns the main service container.
 
 getSpecialPageFactory ()
 
 getStatsdDataFactory ()
 
 getStatsFactory ()
 
 getStatusCode ()
 
 getUrlUtils ()
 
 handleTopLevelError (Throwable $e)
 Report a top level error.
 
 hasFastCgi ()
 
 header (string $header, bool $replace=true, int $status=0)
 
 inPostSendMode ()
 Whether enterPostSendMode() has been called.
 
 isCli ()
 
 outputResponsePayload ( $content)
 Print a response body to the current buffer (if there is one) or the server (otherwise)
 
 postOutputShutdown ()
 Forces the response to be sent to the client and then does work that can be done after the user gets the HTTP response, so they don't block on it.
 
 prepareForOutput ()
 Prepare for sending the output.
 
 print ( $data)
 
 restInPeace ()
 Ends this task peacefully.
 
 schedulePostSendJobs ()
 If enabled, after everything specific to this request is done, occasionally run jobs.
 
 setIniOption (string $name, $value)
 
 setup ()
 Perform any setup needed before execute() is called.
 
 shouldDoHttpRedirect ()
 Check if an HTTP->HTTPS redirect should be done.
 
 startOutputBuffer (?callable $callback=null)
 Adds a new output buffer level.
 
 status (int $code)
 
 triggerAsyncJobs ( $n, LoggerInterface $runJobsLogger)
 
 triggerError (string $message, int $level=E_USER_NOTICE)
 Triggers a PHP runtime error.
 
 triggerSyncJobs ( $n)
 

Protected Attributes

EntryPointEnvironment $environment
 

Detailed Description

Base class for entry point handlers.

Note
: This is not stable to extend by extensions, because MediaWiki does not allow extensions to define new entry points.
Since
1.42, factored out of the previously existing MediaWiki class.

Definition at line 77 of file MediaWikiEntryPoint.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\MediaWikiEntryPoint::__construct ( IContextSource $context,
EntryPointEnvironment $environment,
MediaWikiServices $mediaWikiServices )
Parameters
IContextSource$context
EntryPointEnvironment$environment
MediaWikiServices$mediaWikiServices

Definition at line 109 of file MediaWikiEntryPoint.php.

References MediaWiki\Context\IContextSource\getConfig(), MediaWiki\EntryPointEnvironment\hasFastCgi(), and MediaWiki\EntryPointEnvironment\isCli().

Member Function Documentation

◆ commitMainTransaction()

MediaWiki\MediaWikiEntryPoint::commitMainTransaction ( )
protected

This function commits all DB and session changes as needed before the client can receive a response (in case DB commit fails) and thus also before the response can trigger a subsequent related request by the client.

Definition at line 281 of file MediaWikiEntryPoint.php.

References MediaWiki\Config\Config\get(), MediaWiki\Context\IContextSource\getConfig(), MediaWiki\Context\IContextSource\getOutput(), MediaWiki\Context\IContextSource\getRequest(), MediaWiki\Context\IContextSource\getUser(), wfDebug(), and wfDebugLog().

◆ commitOutputBuffer()

MediaWiki\MediaWikiEntryPoint::commitOutputBuffer ( )
protected

Ends the current output buffer, appending its content to the parent buffer.

See also
ob_end_flush

Definition at line 994 of file MediaWikiEntryPoint.php.

◆ disableModDeflate()

MediaWiki\MediaWikiEntryPoint::disableModDeflate ( )
protected

Definition at line 1128 of file MediaWikiEntryPoint.php.

◆ discardAllOutput()

MediaWiki\MediaWikiEntryPoint::discardAllOutput ( )
protected

Discards all buffered output, down to the capture buffer level.

Definition at line 1096 of file MediaWikiEntryPoint.php.

◆ discardOutputBuffer()

MediaWiki\MediaWikiEntryPoint::discardOutputBuffer ( )
protected
See also
ob_end_clean

Definition at line 1124 of file MediaWikiEntryPoint.php.

◆ doPostOutputShutdown()

MediaWiki\MediaWikiEntryPoint::doPostOutputShutdown ( )
protected

Forces the response to be sent to the client and then does work that can be done after the user gets the HTTP response, so they don't block on it.

Since
1.26 (formerly on the MediaWiki class)
Note
arc-lamp profiling relies on the name of this method, it's hard coded in the arclamp-generate-svgs script!

Reimplemented in MediaWiki.

Definition at line 472 of file MediaWikiEntryPoint.php.

◆ doPrepareForOutput()

MediaWiki\MediaWikiEntryPoint::doPrepareForOutput ( )
protected

Prepare for sending the output.

Should be called by entry points before sending the response. Will be called automatically by run() via prepareForOutput(). Subclasses may override this method, but should not call it directly.

Note
arc-lamp profiling relies on the name of this method, it's hard coded in the arclamp-generate-svgs script!

Reimplemented in MediaWiki\Actions\ActionEntryPoint, MediaWiki\FileRepo\ThumbnailEntryPoint, and MediaWiki\ResourceLoader\ResourceLoaderEntryPoint.

Definition at line 183 of file MediaWikiEntryPoint.php.

◆ doSetup()

MediaWiki\MediaWikiEntryPoint::doSetup ( )
protected

Perform any setup needed before execute() is called.

Called by doRun() via doSetup().

Reimplemented in MediaWiki\Rest\EntryPoint.

Definition at line 147 of file MediaWikiEntryPoint.php.

◆ drainOutputBuffer()

MediaWiki\MediaWikiEntryPoint::drainOutputBuffer ( )
protected

Returns the content of the current output buffer and clears it.

See also
ob_get_clean
Returns
false|string

Definition at line 938 of file MediaWikiEntryPoint.php.

◆ emitBufferedStatsdData()

static MediaWiki\MediaWikiEntryPoint::emitBufferedStatsdData ( IBufferingStatsdDataFactory $stats,
Config $config )
static

Send out any buffered statsd data according to sampling rules.

For web requests, this is called once by MediaWiki::restInPeace(), which is post-send (after the response is sent to the client).

For maintenance scripts, especially long-running CLI scripts, it is called more often, to avoid OOM, since we buffer stats (T181385), based on the following heuristics:

  • Long-running scripts that involve database writes often use transactions to commit chunks of work. We flush from IDatabase::setTransactionListener, as wired up by MWLBFactory::applyGlobalState.
  • Long-running scripts that involve database writes but don't need any transactions will still periodically wait for replication to be graceful to the databases. We flush from ILBFactory::setWaitForReplicationListener as wired up by MWLBFactory::applyGlobalState.
  • Any other long-running scripts will probably report progress to stdout in some way. We also flush from Maintenance::output().
Parameters
IBufferingStatsdDataFactory$stats
Config$config
Exceptions
ConfigException
Since
1.31 (formerly one the MediaWiki class)

Definition at line 720 of file MediaWikiEntryPoint.php.

References IBufferingStatsdDataFactory\clearData(), MediaWiki\Config\Config\get(), IBufferingStatsdDataFactory\getData(), IBufferingStatsdDataFactory\getDataCount(), and IBufferingStatsdDataFactory\hasData().

◆ enableOutputCapture()

MediaWiki\MediaWikiEntryPoint::enableOutputCapture ( )

Enable capturing of the current output buffer.

There may be mutiple levels of output buffering. The level we are currently at, at the time of calling this method, is the level that will be captured to later retrieve via getCapturedOutput().

When capturing is active, flushOutputBuffer() will not actually write to the real STDOUT, but instead write only to the capture.

This exists to ease testing.

Access: internal
For use in PHPUnit tests
See also
ob_start()
getCapturedOutput();

Definition at line 964 of file MediaWikiEntryPoint.php.

◆ enterPostSendMode()

MediaWiki\MediaWikiEntryPoint::enterPostSendMode ( )
protected

Disables all output to the client.

After this, calling any output methods on this object will fail.

Definition at line 1251 of file MediaWikiEntryPoint.php.

◆ execute()

MediaWiki\MediaWikiEntryPoint::execute ( )
abstractprotected

Subclasses implement the entry point's functionality by overriding this method.

This method is not safe to override for extensions.

Reimplemented in MediaWiki\Actions\ActionEntryPoint, MediaWiki\Api\ApiEntryPoint, MediaWiki\FileRepo\ThumbnailEntryPoint, MediaWiki, MediaWiki\ResourceLoader\ResourceLoaderEntryPoint, and MediaWiki\Rest\EntryPoint.

◆ exit()

MediaWiki\MediaWikiEntryPoint::exit ( int $code = 0)
protected
Parameters
int$code
Returns
never

Definition at line 917 of file MediaWikiEntryPoint.php.

◆ fastCgiFinishRequest()

MediaWiki\MediaWikiEntryPoint::fastCgiFinishRequest ( )
protected

Calls fastcgi_finish_request if possible.

Reasons for not calling fastcgi_finish_request include the fastcgi extension not being loaded and the capture buffer level being different from 0.

See also
fastcgi_finish_request
Returns
bool true if fastcgi_finish_request was called and successful.

Definition at line 1217 of file MediaWikiEntryPoint.php.

◆ flushOutputBuffer()

MediaWiki\MediaWikiEntryPoint::flushOutputBuffer ( )
protected

Flush buffered output to the client.

If enableOutputCapture() was called, buffered output is committed to the capture buffer instead.

If enterPostSendMode() was called before this method, a warning is triggered and any buffered output is discarded.

See also
ob_end_flush
flush

Definition at line 1044 of file MediaWikiEntryPoint.php.

◆ getBlockManager()

MediaWiki\MediaWikiEntryPoint::getBlockManager ( )
protected

Definition at line 856 of file MediaWikiEntryPoint.php.

◆ getCapturedOutput()

MediaWiki\MediaWikiEntryPoint::getCapturedOutput ( )

Stop capturing and return all output.

It flushes and drains all output buffers, but lets it go to a return value instead of the real STDOUT.

You must call enableOutputCapture() and run() before getCapturedOutput().

Access: internal
For use in PHPUnit tests
See also
enableOutputCapture();
ob_end_clean
Returns
string HTTP response body

Definition at line 1021 of file MediaWikiEntryPoint.php.

◆ getConfig()

◆ getContext()

MediaWiki\MediaWikiEntryPoint::getContext ( )
protected

◆ getDBLoadBalancerFactory()

MediaWiki\MediaWikiEntryPoint::getDBLoadBalancerFactory ( )
protected

Definition at line 848 of file MediaWikiEntryPoint.php.

◆ getEnv()

MediaWiki\MediaWikiEntryPoint::getEnv ( string $name)
protected

Returns the value of an environment variable.

See also
getenv
Parameters
string$name
Returns
array|false|string

Definition at line 1168 of file MediaWikiEntryPoint.php.

◆ getIni()

MediaWiki\MediaWikiEntryPoint::getIni ( string $name)
protected

Returns the value of an ini option.

See also
ini_get
Parameters
string$name
Returns
false|string

Definition at line 1181 of file MediaWikiEntryPoint.php.

◆ getJobQueueGroupFactory()

MediaWiki\MediaWikiEntryPoint::getJobQueueGroupFactory ( )
protected

Definition at line 868 of file MediaWikiEntryPoint.php.

◆ getJobRunner()

MediaWiki\MediaWikiEntryPoint::getJobRunner ( )
protected

Definition at line 844 of file MediaWikiEntryPoint.php.

◆ getMessageCache()

MediaWiki\MediaWikiEntryPoint::getMessageCache ( )
protected

Definition at line 852 of file MediaWikiEntryPoint.php.

◆ getOutputBufferLength()

MediaWiki\MediaWikiEntryPoint::getOutputBufferLength ( )
protected
See also
ob_get_length
Returns
false|int

Definition at line 1110 of file MediaWikiEntryPoint.php.

◆ getOutputBufferLevel()

MediaWiki\MediaWikiEntryPoint::getOutputBufferLevel ( )
protected

Returns the output buffer level.

If enableOutputCapture() has been called, the capture buffer level is taking into account by subtracting it from the actual buffer level.

See also
ob_get_level

Definition at line 985 of file MediaWikiEntryPoint.php.

◆ getOutputBufferStatus()

MediaWiki\MediaWikiEntryPoint::getOutputBufferStatus ( )
protected
See also
ob_get_status

Definition at line 1117 of file MediaWikiEntryPoint.php.

◆ getReadOnlyMode()

MediaWiki\MediaWikiEntryPoint::getReadOnlyMode ( )
protected

Definition at line 840 of file MediaWikiEntryPoint.php.

◆ getRequest()

MediaWiki\MediaWikiEntryPoint::getRequest ( )
protected

◆ getRequestPathSuffix()

MediaWiki\MediaWikiEntryPoint::getRequestPathSuffix ( $basePath)

If the request URL matches a given base path, extract the path part of the request URL after that base, and decode escape sequences in it.

If the request URL does not match, false is returned.

Access: internal
Should be protected, made public for backwards compatibility code in WebRequest.
Parameters
string$basePath
Returns
false|string

Definition at line 440 of file MediaWikiEntryPoint.php.

Referenced by MediaWiki\FileRepo\Thumbnail404EntryPoint\handleRequest().

◆ getRequestURL()

MediaWiki\MediaWikiEntryPoint::getRequestURL ( )
protected

Returns the current request's path and query string (not a full URL), like PHP's built-in $_SERVER['REQUEST_URI'].

See also
WebRequest::getRequestURL()
WebRequest::getGlobalRequestURL()

Definition at line 1242 of file MediaWikiEntryPoint.php.

◆ getResponse()

MediaWiki\MediaWikiEntryPoint::getResponse ( )
protected

◆ getServerInfo()

MediaWiki\MediaWikiEntryPoint::getServerInfo ( string $key,
$default = null )
protected

◆ getServiceContainer()

MediaWiki\MediaWikiEntryPoint::getServiceContainer ( )
protected

Returns the main service container.

This is intended as a stepping stone for migration. Ideally, individual service objects should be injected via the constructor.

Returns
MediaWikiServices

Definition at line 832 of file MediaWikiEntryPoint.php.

Referenced by MediaWiki\ResourceLoader\ResourceLoaderEntryPoint\execute(), MediaWiki\FileRepo\Thumbnail404EntryPoint\extractThumbRequestInfo(), and MediaWiki\FileRepo\Thumbnail404EntryPoint\handleRequest().

◆ getSpecialPageFactory()

MediaWiki\MediaWikiEntryPoint::getSpecialPageFactory ( )
protected

Definition at line 872 of file MediaWikiEntryPoint.php.

◆ getStatsdDataFactory()

MediaWiki\MediaWikiEntryPoint::getStatsdDataFactory ( )
protected

Definition at line 864 of file MediaWikiEntryPoint.php.

◆ getStatsFactory()

MediaWiki\MediaWikiEntryPoint::getStatsFactory ( )
protected

Definition at line 860 of file MediaWikiEntryPoint.php.

◆ getStatusCode()

MediaWiki\MediaWikiEntryPoint::getStatusCode ( )
protected
See also
http_response_code
Returns
int|bool

Definition at line 1136 of file MediaWikiEntryPoint.php.

◆ getUrlUtils()

MediaWiki\MediaWikiEntryPoint::getUrlUtils ( )
protected

Definition at line 836 of file MediaWikiEntryPoint.php.

◆ handleTopLevelError()

MediaWiki\MediaWikiEntryPoint::handleTopLevelError ( Throwable $e)
protected

Report a top level error.

Subclasses in core may override this to handle errors according to the expected output format. This method is not safe to override for extensions.

Parameters
Throwable$e

Reimplemented in MediaWiki\Actions\ActionEntryPoint.

Definition at line 219 of file MediaWikiEntryPoint.php.

◆ hasFastCgi()

MediaWiki\MediaWikiEntryPoint::hasFastCgi ( )
protected

Definition at line 896 of file MediaWikiEntryPoint.php.

◆ header()

MediaWiki\MediaWikiEntryPoint::header ( string $header,
bool $replace = true,
int $status = 0 )
protected

◆ inPostSendMode()

MediaWiki\MediaWikiEntryPoint::inPostSendMode ( )
protected

Whether enterPostSendMode() has been called.

Indicates whether more data can be sent to the client. To determine whether more headers can be sent, use $this->getResponse()->headersSent().

Definition at line 1146 of file MediaWikiEntryPoint.php.

◆ isCli()

MediaWiki\MediaWikiEntryPoint::isCli ( )
protected

Definition at line 892 of file MediaWikiEntryPoint.php.

◆ outputResponsePayload()

MediaWiki\MediaWikiEntryPoint::outputResponsePayload ( $content)
protected

Print a response body to the current buffer (if there is one) or the server (otherwise)

This method should be called after commitMainTransaction() and before doPostOutputShutdown()

Any accompanying Content-Type header is assumed to have already been set

Parameters
string$contentResponse content, usually from OutputPage::output()

Definition at line 566 of file MediaWikiEntryPoint.php.

References Profiler\instance().

◆ postOutputShutdown()

MediaWiki\MediaWikiEntryPoint::postOutputShutdown ( )
finalprotected

Forces the response to be sent to the client and then does work that can be done after the user gets the HTTP response, so they don't block on it.

Definition at line 452 of file MediaWikiEntryPoint.php.

◆ prepareForOutput()

MediaWiki\MediaWikiEntryPoint::prepareForOutput ( )
finalprotected

Prepare for sending the output.

Should be called by entry points before sending the response. Final wrapper function for doPrepareForOutput(). Will be called automatically at the end of doRun(), but will do nothing if it was already called from execute().

Definition at line 163 of file MediaWikiEntryPoint.php.

Referenced by MediaWiki\FileRepo\ThumbnailEntryPoint\streamThumb().

◆ print()

MediaWiki\MediaWikiEntryPoint::print ( $data)
protected

◆ restInPeace()

MediaWiki\MediaWikiEntryPoint::restInPeace ( )
protected

Ends this task peacefully.

Called after the response has been sent to the client. Subclasses in core may override this to add end-of-request code, but should always call the parent method. This method is not safe to override by extensions.

Reimplemented in MediaWiki.

Definition at line 652 of file MediaWikiEntryPoint.php.

References Profiler\instance(), and wfDebug().

◆ run()

MediaWiki\MediaWikiEntryPoint::run ( )
final

Main app life cycle: Calls doSetup(), execute(), prepareForOutput(), and postOutputShutdown().

Definition at line 195 of file MediaWikiEntryPoint.php.

◆ schedulePostSendJobs()

MediaWiki\MediaWikiEntryPoint::schedulePostSendJobs ( )
protected

If enabled, after everything specific to this request is done, occasionally run jobs.

Reimplemented in MediaWiki\Actions\ActionEntryPoint.

Definition at line 233 of file MediaWikiEntryPoint.php.

◆ setIniOption()

MediaWiki\MediaWikiEntryPoint::setIniOption ( string $name,
$value )
protected
Parameters
string$name
mixed$value
Returns
false|string

Definition at line 1191 of file MediaWikiEntryPoint.php.

◆ setup()

MediaWiki\MediaWikiEntryPoint::setup ( )
finalprotected

Perform any setup needed before execute() is called.

Final wrapper function for setup(). Will be called by doRun().

Definition at line 133 of file MediaWikiEntryPoint.php.

◆ shouldDoHttpRedirect()

MediaWiki\MediaWikiEntryPoint::shouldDoHttpRedirect ( )
protected

Check if an HTTP->HTTPS redirect should be done.

It may still be aborted by a hook, so this is not the final word.

Returns
bool

Definition at line 518 of file MediaWikiEntryPoint.php.

References PROTO_HTTPS.

◆ startOutputBuffer()

MediaWiki\MediaWikiEntryPoint::startOutputBuffer ( ?callable $callback = null)
protected

Adds a new output buffer level.

Parameters
?callable$callback
See also
ob_start

Definition at line 928 of file MediaWikiEntryPoint.php.

◆ status()

MediaWiki\MediaWikiEntryPoint::status ( int $code)
protected

◆ triggerAsyncJobs()

MediaWiki\MediaWikiEntryPoint::triggerAsyncJobs ( $n,
LoggerInterface $runJobsLogger )
protected
Parameters
int$nNumber of jobs to try to run
LoggerInterface$runJobsLogger
Returns
bool Success

Definition at line 755 of file MediaWikiEntryPoint.php.

◆ triggerError()

MediaWiki\MediaWikiEntryPoint::triggerError ( string $message,
int $level = E_USER_NOTICE )
protected

Triggers a PHP runtime error.

See also
trigger_error

Definition at line 1155 of file MediaWikiEntryPoint.php.

◆ triggerSyncJobs()

MediaWiki\MediaWikiEntryPoint::triggerSyncJobs ( $n)
protected
Parameters
int$nNumber of jobs to try to run

Definition at line 744 of file MediaWikiEntryPoint.php.

References Profiler\instance().

Member Data Documentation

◆ $environment

EntryPointEnvironment MediaWiki\MediaWikiEntryPoint::$environment
protected

The documentation for this class was generated from the following file: