28 private ?
Router $router =
null;
49 $conf = $services->getMainConfig();
55 ->addAuthorizer( $cors );
58 $restValidator =
new Validator( $objectFactory,
66 self::getRouteFiles( $conf ),
67 ExtensionRegistry::getInstance()->getAttribute(
'RestRoutes' ),
88 static $mainRequest = null;
90 if ( $mainRequest ===
null ) {
103 $context = RequestContext::getMain();
115 MWExceptionRenderer::shouldShowExceptionDetails()
120 CorsUtils::CONSTRUCTOR_OPTIONS,
121 $this->getServiceContainer()->getMainConfig()
127 if ( !$this->router ) {
128 $this->router = $this->createRouter(
129 $this->getServiceContainer(),
143 private function getTextFormatters() {
144 $services = $this->getServiceContainer();
147 $langs = array_unique( [ $code,
'en' ] );
148 $textFormatters = [];
151 foreach ( $langs as $lang ) {
152 $textFormatters[] = $factory->getTextFormatter( $lang );
155 return $textFormatters;
163 private static function getRouteFiles( $conf ) {
165 $extensionsDir = $conf->get( MainConfigNames::ExtensionDirectory );
167 $routeFiles = array_merge(
168 [
'includes/Rest/coreRoutes.json' ],
169 $conf->get( MainConfigNames::RestAPIAdditionalRouteFiles )
171 foreach ( $routeFiles as &$file ) {
173 str_starts_with( $file,
'/' )
177 str_starts_with( $file,
'extensions/' )
180 $file = substr_replace( $file, $extensionsDir,
181 0, strlen(
'extensions' ) );
196 parent::__construct( $context, $environment, $mediaWikiServices );
198 $this->request = $request;
208 $this->router = $router;
212 $this->startOutputBuffer();
216 $response = $this->cors->modifyResponse(
218 $this->router->execute( $this->request )
221 $webResponse = $this->getResponse();
223 $webResponse->header(
224 'HTTP/' . $response->getProtocolVersion() .
' ' . $response->getStatusCode() .
' ' .
225 $response->getReasonPhrase()
228 foreach ( $response->getRawHeaderLines() as $line ) {
229 $webResponse->header( $line );
232 foreach ( $response->getCookies() as $cookie ) {
233 $webResponse->setCookie(
242 $this->discardOutputBuffer();
244 $stream = $response->getBody();
247 $this->prepareForOutput();
250 $stream->copyToStream( fopen(
'php://output',
'w' ) );
253 $buffer = $stream->read( 65536 );
254 if ( $buffer ===
'' ) {
257 $this->print( $buffer );
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgTitle
Load JSON files, and uses a Processor to extract information.
Class to expose exceptions to the client (API bots, users, admins using CLI scripts)
Group all the pieces relevant to the context of a request into one instance.
Utility class wrapping PHP runtime state.
A class containing constants representing the names of configuration variables.
const CookiePrefix
Name constant for the CookiePrefix setting, for use with Config::get()
Base class for entry point handlers.
doSetup()
Perform any setup needed before execute() is called.
setRouter(Router $router)
Sets the router to use.
__construct(RequestInterface $request, RequestContext $context, EntryPointEnvironment $environment, MediaWikiServices $mediaWikiServices)
execute()
Subclasses implement the entry point's functionality by overriding this method.
static createRouter(MediaWikiServices $services, IContextSource $context, RequestInterface $request, ResponseFactory $responseFactory, CorsUtils $cors)
Interface for objects which can provide a MediaWiki context on request.