/** * Constructs an instance of ApiMain that utilizes the module and format specified by $request. * * @param $request object - if this is an instance of FauxRequest, errors are thrown and no printing occurs * @param $enableWrite bool should be set to true if the api may modify data */ public function __construct($request, $enableWrite = false) { $this->mInternalMode = $request instanceof FauxRequest; // Special handling for the main module: $parent === $this parent::__construct($this, $this->mInternalMode ? 'main_int' : 'main'); if (!$this->mInternalMode) { // Impose module restrictions. // If the current user cannot read, // Remove all modules other than login global $wgUser; if (!$wgUser->isAllowed('read')) { self::$Modules = array('login' => self::$Modules['login'], 'help' => self::$Modules['help']); } } $this->mModules = self::$Modules; $this->mModuleNames = array_keys($this->mModules); // todo: optimize $this->mFormats = self::$Formats; $this->mFormatNames = array_keys($this->mFormats); // todo: optimize $this->mResult = new ApiResult($this); $this->mShowVersions = false; $this->mEnableWrite = $enableWrite; $this->mRequest =& $request; $this->mSquidMaxage = 0; }
/** * Constructs an instance of ApiMain that utilizes the module and format specified by $request. * * @param $request object - if this is an instance of FauxRequest, errors are thrown and no printing occurs * @param $enableWrite bool should be set to true if the api may modify data */ public function __construct($request, $enableWrite = false) { $this->mInternalMode = $request instanceof FauxRequest; // Special handling for the main module: $parent === $this parent::__construct($this, $this->mInternalMode ? 'main_int' : 'main'); if (!$this->mInternalMode) { // Impose module restrictions. // If the current user cannot read, // Remove all modules other than login global $wgUser; if ($request->getVal('callback') !== null) { // JSON callback allows cross-site reads. // For safety, strip user credentials. wfDebug("API: stripping user credentials for JSON callback\n"); $wgUser = new User(); } if (!$wgUser->isAllowed('read')) { self::$Modules = array('login' => self::$Modules['login'], 'logout' => self::$Modules['logout'], 'help' => self::$Modules['help']); } } global $wgAPIModules, $wgEnableWriteAPI; // extension modules $this->mModules = $wgAPIModules + self::$Modules; if ($wgEnableWriteAPI) { $this->mModules += self::$WriteModules; } $this->mModuleNames = array_keys($this->mModules); // todo: optimize $this->mFormats = self::$Formats; $this->mFormatNames = array_keys($this->mFormats); // todo: optimize $this->mResult = new ApiResult($this); $this->mShowVersions = false; $this->mEnableWrite = $enableWrite; $this->mRequest =& $request; $this->mSquidMaxage = 0; }