49 ->addAuthorizer(
$cors );
51 $objectFactory = $services->getObjectFactory();
52 $restValidator =
new Validator( $objectFactory,
58 $routeFiles = array_merge(
59 [
'includes/Rest/coreRoutes.json' ],
60 $conf->get(
'RestAPIAdditionalRouteFiles' )
62 array_walk( $routeFiles,
static function ( &$val, $key ) {
69 ExtensionRegistry::getInstance()->getAttribute(
'RestRoutes' ),
70 $conf->get(
'CanonicalServer' ),
71 $conf->get(
'RestPath' ),
72 $services->getLocalServerObjectCache(),
78 $services->getHookContainer()
79 ) )->setCors(
$cors );
86 if ( self::$mainRequest === null ) {
89 'cookiePrefix' => $conf->get(
'CookiePrefix' )
92 return self::$mainRequest;
95 public static function main() {
99 $context = RequestContext::getMain();
106 $services = MediaWikiServices::getInstance();
107 $conf = $services->getMainConfig();
109 $responseFactory =
new ResponseFactory( self::getTextFormatters( $services ) );
113 CorsUtils::CONSTRUCTOR_OPTIONS, $services->getMainConfig()
119 $request = self::getMainRequest();
121 $router = self::createRouter( $context, $request, $responseFactory, $cors );
123 $entryPoint =
new self(
130 $entryPoint->execute();
141 $langs = array_unique( [ $code,
'en' ] );
142 $textFormatters = [];
145 foreach ( $langs as
$lang ) {
146 $textFormatters[] = $factory->getTextFormatter(
$lang );
148 return $textFormatters;
154 $this->context = $context;
155 $this->request = $request;
156 $this->webResponse = $webResponse;
157 $this->router = $router;
163 $response = $this->cors->modifyResponse(
165 $this->router->execute( $this->request )
168 $this->webResponse->header(
169 'HTTP/' . $response->getProtocolVersion() .
' ' .
170 $response->getStatusCode() .
' ' .
171 $response->getReasonPhrase() );
173 foreach ( $response->getRawHeaderLines() as
$line ) {
174 $this->webResponse->header(
$line );
177 foreach ( $response->getCookies() as $cookie ) {
178 $this->webResponse->setCookie(
182 $cookie[
'options'] );
188 $stream = $response->getBody();
191 MediaWiki::preOutputCommit( $this->context );
194 $stream->copyToStream( fopen(
'php://output',
'w' ) );
197 $buffer = $stream->read( 65536 );
198 if ( $buffer ===
'' ) {
206 $mw->doPostOutputShutdown();
if(ini_get('mbstring.func_overload')) if(!defined('MW_ENTRY_POINT'))
Pre-config setup: Before loading LocalSettings.php.
The Registry loads JSON files, and uses a Processor to extract information from them.
static RequestInterface $mainRequest
RequestInterface $request
static createRouter(IContextSource $context, RequestInterface $request, ResponseFactory $responseFactory, CorsUtils $cors)
static getTextFormatters(MediaWikiServices $services)
Get a TextFormatter array from MediaWikiServices.
__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 @newable.
Represents a title within MediaWiki.
Allow programs to request this object from WebRequest::response() and handle all outputting (or lack ...
Interface for objects which can provide a MediaWiki context on request.
if(!isset( $args[0])) $lang