34 private static $mainRequest;
45 private static function createRouter(
58 ->addAuthorizer( $cors );
61 $restValidator =
new Validator( $objectFactory,
69 self::getRouteFiles( $conf ),
70 ExtensionRegistry::getInstance()->getAttribute(
'RestRoutes' ),
90 if ( self::$mainRequest === null ) {
96 return self::$mainRequest;
99 public static function main() {
103 $context = RequestContext::getMain();
113 $responseFactory =
new ResponseFactory( self::getTextFormatters( $services ) );
114 $responseFactory->setShowExceptionDetails( MWExceptionRenderer::shouldShowExceptionDetails() );
118 CorsUtils::CONSTRUCTOR_OPTIONS, $conf
124 $request = self::getMainRequest();
126 $router = self::createRouter( $services, $context, $request, $responseFactory, $cors );
128 $entryPoint =
new self(
135 $entryPoint->execute();
146 $langs = array_unique( [ $code,
'en' ] );
147 $textFormatters = [];
150 foreach ( $langs as
$lang ) {
151 $textFormatters[] = $factory->getTextFormatter(
$lang );
153 return $textFormatters;
160 private static function getRouteFiles( $conf ) {
164 $routeFiles = array_merge(
165 [
'includes/Rest/coreRoutes.json' ],
168 foreach ( $routeFiles as &
$file ) {
169 if ( str_starts_with(
$file,
'/' ) ) {
171 } elseif ( str_starts_with(
$file,
'extensions/' ) ) {
173 $file = substr_replace(
$file, $extensionsDir, 0, strlen(
'extensions' ) );
184 $this->context = $context;
185 $this->request = $request;
186 $this->webResponse = $webResponse;
187 $this->router = $router;
193 $response = $this->cors->modifyResponse(
195 $this->router->execute( $this->request )
198 $this->webResponse->header(
199 'HTTP/' . $response->getProtocolVersion() .
' ' .
200 $response->getStatusCode() .
' ' .
201 $response->getReasonPhrase() );
203 foreach ( $response->getRawHeaderLines() as $line ) {
204 $this->webResponse->header( $line );
207 foreach ( $response->getCookies() as $cookie ) {
208 $this->webResponse->setCookie(
212 $cookie[
'options'] );
218 $stream = $response->getBody();
221 MediaWiki::preOutputCommit( $this->context );
224 $stream->copyToStream( fopen(
'php://output',
'w' ) );
227 $buffer = $stream->read( 65536 );
228 if ( $buffer ===
'' ) {
236 $mw->doPostOutputShutdown();
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode $wgTitle
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
The Registry loads JSON files, and uses a Processor to extract information from them.
Class to expose exceptions to the client (API bots, users, admins using CLI scripts)
A class containing constants representing the names of configuration variables.
const ExtensionDirectory
Name constant for the ExtensionDirectory setting, for use with Config::get()
const CookiePrefix
Name constant for the CookiePrefix setting, for use with Config::get()
const RestAPIAdditionalRouteFiles
Name constant for the RestAPIAdditionalRouteFiles setting, for use with Config::get()
__construct(RequestContext $context, RequestInterface $request, WebResponse $webResponse, Router $router, CorsUtils $cors)
Group all the pieces relevant to the context of a request into one instance.
Interface for configuration instances.
Interface for objects which can provide a MediaWiki context on request.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
if(!isset( $args[0])) $lang