MediaWiki REL1_37
MediaWiki Class Reference

The MediaWiki class is the helper class for the index.php entry point. More...

Collaboration diagram for MediaWiki:

Public Member Functions

 __construct (IContextSource $context=null)
 
 doPostOutputShutdown ()
 This function does work that can be done after the user gets the HTTP response so they don't block on it.
 
 doPreOutputCommit (callable $postCommitWork=null)
 
 getAction ()
 Returns the name of the action that will be executed.
 
 getTitle ()
 Get the Title object that we'll be acting on, as specified in the WebRequest.
 
 restInPeace ()
 Ends this task peacefully.
 
 run ()
 Run the current MediaWiki instance; index.php just calls this.
 

Static Public Member Functions

static emitBufferedStatsdData (IBufferingStatsdDataFactory $stats, Config $config)
 Send out any buffered statsd data according to sampling rules.
 
static preOutputCommit (IContextSource $context, callable $postCommitWork=null)
 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.
 

Private Member Functions

 initializeArticle ()
 Initialize the main Article object for "standard" actions (view, etc) Create an Article object for the page, following redirects if needed.
 
 main ()
 Determine and send the response headers and body for this web request.
 
 maybeDoHttpsRedirect ()
 If the stars are suitably aligned, do an HTTP->HTTPS redirect.
 
 outputResponsePayload ( $content)
 Print a response body to the current buffer (if there is one) or the server (otherwise)
 
 parseTitle ()
 Parse the request to get the Title object.
 
 performAction (Article $article, Title $requestTitle)
 Perform one of the "standard" actions.
 
 performRequest ()
 Performs the request.
 
 schedulePostSendJobs ()
 If enabled, after everything specific to this request is done, occasionally run jobs.
 
 setDBProfilingAgent ()
 Add a comment to future SQL queries for easy SHOW PROCESSLIST interpretation.
 
 shouldDoHttpRedirect ()
 Check if an HTTP->HTTPS redirect should be done.
 
 triggerAsyncJobs ( $n, LoggerInterface $runJobsLogger)
 
 triggerSyncJobs ( $n)
 
 tryNormaliseRedirect (Title $title)
 Handle redirects for uncanonical title requests.
 

Static Private Member Functions

static getUrlDomainDistance ( $url)
 

Private Attributes

string $action
 Cache what action this request is.
 
Config $config
 
IContextSource $context
 
int $postSendStrategy
 Class DEFER_* constant; how non-blocking post-response tasks should run.
 
const DEFER_CLI_MODE = 3
 Do not try to make post-send updates async (e.g.
 
const DEFER_FASTCGI_FINISH_REQUEST = 1
 Call fastcgi_finish_request() to make post-send updates async.
 
const DEFER_SET_LENGTH_AND_FLUSH = 2
 Set Content-Length and call ob_end_flush()/flush() to make post-send updates async.
 

Detailed Description

The MediaWiki class is the helper class for the index.php entry point.

Definition at line 36 of file MediaWiki.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki::__construct ( IContextSource  $context = null)
Parameters
IContextSource | null$context

Definition at line 59 of file MediaWiki.php.

Member Function Documentation

◆ doPostOutputShutdown()

MediaWiki::doPostOutputShutdown ( )

This function does work that can be done after the user gets the HTTP response so they don't block on it.

This manages deferred updates, job insertion, final commit, and the logging of profiling data

Since
1.26

Definition at line 822 of file MediaWiki.php.

◆ doPreOutputCommit()

MediaWiki::doPreOutputCommit ( callable  $postCommitWork = null)
See also
MediaWiki::preOutputCommit()
Parameters
callable | null$postCommitWork[default: null]
Since
1.26

Definition at line 657 of file MediaWiki.php.

◆ emitBufferedStatsdData()

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

Send out any buffered statsd data according to sampling rules.

Parameters
IBufferingStatsdDataFactory$stats
Config$config
Exceptions
ConfigException
Since
1.31

Definition at line 1163 of file MediaWiki.php.

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

◆ getAction()

MediaWiki::getAction ( )

Returns the name of the action that will be executed.

Returns
string Action

Definition at line 174 of file MediaWiki.php.

◆ getTitle()

MediaWiki::getTitle ( )

Get the Title object that we'll be acting on, as specified in the WebRequest.

Returns
Title

Definition at line 158 of file MediaWiki.php.

References SpecialPage\getTitleFor(), and parseTitle().

◆ getUrlDomainDistance()

static MediaWiki::getUrlDomainDistance (   $url)
staticprivate
Parameters
string$url
Returns
string Either "local", "remote" if in the farm, "external" otherwise

Definition at line 801 of file MediaWiki.php.

◆ initializeArticle()

MediaWiki::initializeArticle ( )
private

Initialize the main Article object for "standard" actions (view, etc) Create an Article object for the page, following redirects if needed.

Returns
Article|string An Article, or a string to redirect to another URL

Definition at line 414 of file MediaWiki.php.

References $file, $title, and wfWarn().

◆ main()

MediaWiki::main ( )
private

Determine and send the response headers and body for this web request.

Definition at line 867 of file MediaWiki.php.

References $cache, $title, $wgTitle, getTitle(), NS_SPECIAL, ErrorPageError\report(), ErrorPageError\STAGE_OUTPUT, and HTMLFileCache\useFileCache().

◆ maybeDoHttpsRedirect()

MediaWiki::maybeDoHttpsRedirect ( )
private

If the stars are suitably aligned, do an HTTP->HTTPS redirect.

Note: Do this after $wgTitle is setup, otherwise the hooks run from isRegistered() will do all sorts of weird stuff.

Returns
bool True if the redirect was done. Handling of the request should be aborted. False if no redirect was done.

Definition at line 1012 of file MediaWiki.php.

References $title, NS_MAIN, and wfDebugLog().

◆ outputResponsePayload()

MediaWiki::outputResponsePayload (   $content)
private

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

This method should be called after doPreOutputCommit() 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 1053 of file MediaWiki.php.

References $content, and print.

◆ parseTitle()

MediaWiki::parseTitle ( )
private

Parse the request to get the Title object.

Exceptions
MalformedTitleExceptionIf a title has been provided by the user, but is invalid.
Returns
Title Title object to be $wgTitle

Definition at line 78 of file MediaWiki.php.

References $title, MediaWiki\MediaWikiServices\getInstance(), SpecialPage\getTitleFor(), NS_FILE, and NS_MEDIA.

Referenced by getTitle().

◆ performAction()

MediaWiki::performAction ( Article  $article,
Title  $requestTitle 
)
private

Perform one of the "standard" actions.

Parameters
Article$article
Title$requestTitleThe original title, before any redirects were applied

Definition at line 498 of file MediaWiki.php.

References $t, $title, PROTO_INTERNAL, and wfExpandUrl().

◆ performRequest()

MediaWiki::performRequest ( )
private

Performs the request.

  • bad titles
  • read restriction
  • local interwiki redirects
  • redirect loop
  • special pages
  • normal pages
Exceptions
MWException|PermissionsError|BadTitleError|HttpError
Returns
void

Definition at line 194 of file MediaWiki.php.

References $title, $wgTitle, and SpecialPage\getTitleFor().

◆ preOutputCommit()

static MediaWiki::preOutputCommit ( IContextSource  $context,
callable  $postCommitWork = null 
)
static

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.

If there is a significant amount of content to flush, it can be done in $postCommitWork

Parameters
IContextSource$context
callable | null$postCommitWork[default: null]
Since
1.27

Definition at line 672 of file MediaWiki.php.

References IContextSource\getConfig(), IContextSource\getOutput(), IContextSource\getRequest(), IContextSource\getUser(), wfDebug(), and wfDebugLog().

◆ restInPeace()

MediaWiki::restInPeace ( )

Ends this task peacefully.

Definition at line 1124 of file MediaWiki.php.

References wfDebug(), and wfLogProfilingData().

◆ run()

MediaWiki::run ( )

Run the current MediaWiki instance; index.php just calls this.

Definition at line 560 of file MediaWiki.php.

References $cache, MWExceptionRenderer\getHTML(), HTMLFileCache\MODE_OUTAGE, print, and HTMLFileCache\useFileCache().

◆ schedulePostSendJobs()

MediaWiki::schedulePostSendJobs ( )
private

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

Definition at line 605 of file MediaWiki.php.

References getTitle(), and wfReadOnly().

◆ setDBProfilingAgent()

MediaWiki::setDBProfilingAgent ( )
private

Add a comment to future SQL queries for easy SHOW PROCESSLIST interpretation.

Definition at line 594 of file MediaWiki.php.

◆ shouldDoHttpRedirect()

MediaWiki::shouldDoHttpRedirect ( )
private

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 968 of file MediaWiki.php.

References PROTO_HTTPS, and wfExpandUrl().

◆ triggerAsyncJobs()

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

Definition at line 1198 of file MediaWiki.php.

References SpecialRunJobs\getQuerySignature(), and wfParseUrl().

◆ triggerSyncJobs()

MediaWiki::triggerSyncJobs (   $n)
private
Parameters
int$nNumber of jobs to try to run

Definition at line 1186 of file MediaWiki.php.

◆ tryNormaliseRedirect()

MediaWiki::tryNormaliseRedirect ( Title  $title)
private

Handle redirects for uncanonical title requests.

Handles:

  • Redirect loops.
  • No title in URL.
  • $wgUsePathInfo URLs.
  • URLs with a variant.
  • Other non-standard URLs (as long as they have no extra query parameters).

Behaviour:

  • Normalise title values: /wiki/Foo%20Bar -> /wiki/Foo_Bar
  • Normalise empty title: /wiki/ -> /wiki/Main /w/index.php?title= -> /wiki/Main
  • Don't redirect anything with query parameters other than 'title' or 'action=view'.
Parameters
Title$title
Returns
bool True if a redirect was set.
Exceptions
HttpError

Definition at line 354 of file MediaWiki.php.

References $title, SpecialPage\getTitleFor(), PROTO_CURRENT, and wfExpandUrl().

Member Data Documentation

◆ $action

string MediaWiki::$action
private

Cache what action this request is.

Definition at line 45 of file MediaWiki.php.

◆ $config

Config MediaWiki::$config
private

Definition at line 42 of file MediaWiki.php.

◆ $context

IContextSource MediaWiki::$context
private

Definition at line 40 of file MediaWiki.php.

◆ $postSendStrategy

int MediaWiki::$postSendStrategy
private

Class DEFER_* constant; how non-blocking post-response tasks should run.

Definition at line 47 of file MediaWiki.php.

◆ DEFER_CLI_MODE

const MediaWiki::DEFER_CLI_MODE = 3
private

Do not try to make post-send updates async (e.g.

for CLI mode)

Definition at line 54 of file MediaWiki.php.

◆ DEFER_FASTCGI_FINISH_REQUEST

const MediaWiki::DEFER_FASTCGI_FINISH_REQUEST = 1
private

Call fastcgi_finish_request() to make post-send updates async.

Definition at line 50 of file MediaWiki.php.

◆ DEFER_SET_LENGTH_AND_FLUSH

const MediaWiki::DEFER_SET_LENGTH_AND_FLUSH = 2
private

Set Content-Length and call ob_end_flush()/flush() to make post-send updates async.

Definition at line 52 of file MediaWiki.php.


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