27 private ?
Router $router =
null;
48 $conf = $services->getMainConfig();
54 ->addAuthorizer( $cors );
57 $restValidator =
new Validator( $objectFactory,
65 self::getRouteFiles( $conf ),
66 ExtensionRegistry::getInstance()->getAttribute(
'RestRoutes' ),
87 static $mainRequest = null;
89 if ( $mainRequest ===
null ) {
102 $context = RequestContext::getMain();
106 MWExceptionRenderer::shouldShowExceptionDetails()
111 CorsUtils::CONSTRUCTOR_OPTIONS,
112 $this->getServiceContainer()->getMainConfig()
118 if ( !$this->router ) {
119 $this->router = $this->createRouter(
120 $this->getServiceContainer(),
134 private function getTextFormatters() {
135 $services = $this->getServiceContainer();
138 $langs = array_unique( [ $code,
'en' ] );
139 $textFormatters = [];
142 foreach ( $langs as $lang ) {
143 $textFormatters[] = $factory->getTextFormatter( $lang );
146 return $textFormatters;
154 private static function getRouteFiles( $conf ) {
156 $extensionsDir = $conf->get( MainConfigNames::ExtensionDirectory );
158 $routeFiles = array_merge(
160 'includes/Rest/coreRoutes.json',
162 $conf->get( MainConfigNames::RestAPIAdditionalRouteFiles )
164 foreach ( $routeFiles as &$file ) {
166 str_starts_with( $file,
'/' )
170 str_starts_with( $file,
'extensions/' )
173 $file = substr_replace( $file, $extensionsDir,
174 0, strlen(
'extensions' ) );
189 parent::__construct( $context, $environment, $mediaWikiServices );
191 $this->request = $request;
201 $this->router = $router;
205 $this->startOutputBuffer();
209 $response = $this->cors->modifyResponse(
211 $this->router->execute( $this->request )
214 $webResponse = $this->getResponse();
216 $webResponse->header(
217 'HTTP/' . $response->getProtocolVersion() .
' ' . $response->getStatusCode() .
' ' .
218 $response->getReasonPhrase()
221 foreach ( $response->getRawHeaderLines() as $line ) {
222 $webResponse->header( $line );
225 foreach ( $response->getCookies() as $cookie ) {
226 $webResponse->setCookie(
235 $this->discardOutputBuffer();
237 $stream = $response->getBody();
240 $this->prepareForOutput();
243 $stream->copyToStream( fopen(
'php://output',
'w' ) );
246 $buffer = $stream->read( 65536 );
247 if ( $buffer ===
'' ) {
250 $this->print( $buffer );
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
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.