3 namespace MediaWiki\Rest
;
6 use MediaWiki\MediaWikiServices
;
12 /** @var RequestInterface */
14 /** @var WebResponse */
19 public static function main() {
22 if ( !$wgRequest->checkUrlExtension() ) {
26 // Set $wgTitle and the title in RequestContext, as in api.php
28 $wgTitle = Title
::makeTitle( NS_SPECIAL
, 'Badtitle/rest.php' );
29 RequestContext
::getMain()->setTitle( $wgTitle );
31 $services = MediaWikiServices
::getInstance();
32 $conf = $services->getMainConfig();
34 $request = new RequestFromGlobals( [
35 'cookiePrefix' => $conf->get( 'CookiePrefix' )
40 [ "$IP/includes/Rest/coreRoutes.json" ],
41 ExtensionRegistry
::getInstance()->getAttribute( 'RestRoutes' ),
42 $conf->get( 'RestPath' ),
43 $services->getLocalServerObjectCache(),
47 $entryPoint = new self(
49 $wgRequest->response(),
51 $entryPoint->execute();
54 public function __construct( RequestInterface
$request, WebResponse
$webResponse,
57 $this->request
= $request;
58 $this->webResponse
= $webResponse;
59 $this->router
= $router;
62 public function execute() {
63 $response = $this->router
->execute( $this->request
);
65 $this->webResponse
->header(
66 'HTTP/' . $response->getProtocolVersion() . ' ' .
67 $response->getStatusCode() . ' ' .
68 $response->getReasonPhrase() );
70 foreach ( $response->getRawHeaderLines() as $line ) {
71 $this->webResponse
->header( $line );
74 foreach ( $response->getCookies() as $cookie ) {
75 $this->webResponse
->setCookie(
82 $stream = $response->getBody();
84 if ( $stream instanceof CopyableStreamInterface
) {
85 $stream->copyToStream( fopen( 'php://output', 'w' ) );
88 $buffer = $stream->read( 65536 );
89 if ( $buffer === '' ) {