34 private static $mainRequest;
43 private static function createRouter(
53 ->addAuthorizer( $cors );
56 $restValidator =
new Validator( $objectFactory,
62 self::getRouteFiles( $conf ),
63 ExtensionRegistry::getInstance()->getAttribute(
'RestRoutes' ),
74 ) )->setCors( $cors );
81 if ( self::$mainRequest === null ) {
87 return self::$mainRequest;
90 public static function main() {
94 $context = RequestContext::getMain();
104 $responseFactory =
new ResponseFactory( self::getTextFormatters( $services ) );
105 $responseFactory->setShowExceptionDetails( MWExceptionRenderer::shouldShowExceptionDetails() );
109 CorsUtils::CONSTRUCTOR_OPTIONS, $conf
115 $request = self::getMainRequest();
117 $router = self::createRouter( $context, $request, $responseFactory, $cors );
119 $entryPoint =
new self(
126 $entryPoint->execute();
137 $langs = array_unique( [ $code,
'en' ] );
138 $textFormatters = [];
141 foreach ( $langs as
$lang ) {
142 $textFormatters[] = $factory->getTextFormatter(
$lang );
144 return $textFormatters;
151 private static function getRouteFiles( $conf ) {
155 $routeFiles = array_merge(
156 [
'includes/Rest/coreRoutes.json' ],
159 foreach ( $routeFiles as &
$file ) {
160 if ( str_starts_with(
$file,
'/' ) ) {
162 } elseif ( str_starts_with(
$file,
'extensions/' ) ) {
164 $file = substr_replace(
$file, $extensionsDir, 0, strlen(
'extensions' ) );
175 $this->context = $context;
176 $this->request = $request;
177 $this->webResponse = $webResponse;
178 $this->router = $router;
184 $response = $this->cors->modifyResponse(
186 $this->router->execute( $this->request )
189 $this->webResponse->header(
190 'HTTP/' . $response->getProtocolVersion() .
' ' .
191 $response->getStatusCode() .
' ' .
192 $response->getReasonPhrase() );
194 foreach ( $response->getRawHeaderLines() as
$line ) {
195 $this->webResponse->header(
$line );
198 foreach ( $response->getCookies() as $cookie ) {
199 $this->webResponse->setCookie(
203 $cookie[
'options'] );
209 $stream = $response->getBody();
212 MediaWiki::preOutputCommit( $this->context );
215 $stream->copyToStream( fopen(
'php://output',
'w' ) );
218 $buffer = $stream->read( 65536 );
219 if ( $buffer ===
'' ) {
227 $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.
Represents a title within MediaWiki.
Allow programs to request this object from WebRequest::response() and handle all outputting (or lack ...
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