Esempio n. 1
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 (!$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;
 }
Esempio n. 2
0
 /**
  * @param $main ApiMain
  * @param $action string
  */
 public function __construct($main, $action)
 {
     parent::__construct($main, $action);
     // Allow custom modules to be added in LocalSettings.php
     global $wgAPIPropModules, $wgAPIListModules, $wgAPIMetaModules, $wgMemc, $wgAPICacheHelpTimeout;
     self::appendUserModules($this->mQueryPropModules, $wgAPIPropModules);
     self::appendUserModules($this->mQueryListModules, $wgAPIListModules);
     self::appendUserModules($this->mQueryMetaModules, $wgAPIMetaModules);
     $this->mPropModuleNames = array_keys($this->mQueryPropModules);
     $this->mListModuleNames = array_keys($this->mQueryListModules);
     $this->mMetaModuleNames = array_keys($this->mQueryMetaModules);
     // Get array of query generators from cache if present
     $key = wfMemcKey('apiquerygenerators', SpecialVersion::getVersion('nodb'));
     if ($wgAPICacheHelpTimeout > 0) {
         $cached = $wgMemc->get($key);
         if ($cached) {
             $this->mAllowedGenerators = $cached;
             return;
         }
     }
     $this->makeGeneratorList($this->mQueryPropModules);
     $this->makeGeneratorList($this->mQueryListModules);
     if ($wgAPICacheHelpTimeout > 0) {
         $wgMemc->set($key, $this->mAllowedGenerators, $wgAPICacheHelpTimeout);
     }
 }
Esempio n. 3
0
 public function __construct(ApiMain $main, $name, Config $config)
 {
     parent::__construct($main, $name);
     $this->veConfig = $config;
     $this->serviceClient = new VirtualRESTServiceClient(new MultiHttpClient(array()));
     $this->serviceClient->mount('/restbase/', $this->getVRSObject());
 }
Esempio n. 4
0
 /**
  * @param ApiMain $main
  */
 public function __construct(ApiMain $main)
 {
     parent::__construct($main, 'result');
     $this->mIsRawMode = false;
     $this->mCheckingSize = true;
     $this->reset();
 }
Esempio n. 5
0
 /**
  * Constructs an instance of ApiMain that utilizes the module and format specified by $request.
  *
  * @param $request WebRequest - 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();
         }
     }
     global $wgAPIModules;
     // extension modules
     $this->mModules = $wgAPIModules + self::$Modules;
     $this->mModuleNames = array_keys($this->mModules);
     $this->mFormats = self::$Formats;
     $this->mFormatNames = array_keys($this->mFormats);
     $this->mResult = new ApiResult($this);
     $this->mShowVersions = false;
     $this->mEnableWrite = $enableWrite;
     $this->mRequest =& $request;
     $this->mSquidMaxage = -1;
     // flag for executeActionWithErrorHandling()
     $this->mCommit = false;
 }
Esempio n. 6
0
 public function __construct(ApiBase $query, $moduleName, $paramPrefix = '')
 {
     parent::__construct($query->getMain(), $moduleName, $paramPrefix);
     $this->mQueryModule = $query;
     $this->mDb = null;
     $this->resetQueryParams();
 }
 public function __construct(ApiMain $main, $name)
 {
     global $wgContentTranslationParsoid;
     parent::__construct($main, $name);
     $this->serviceClient = new VirtualRESTServiceClient(new MultiHttpClient(array()));
     $parsoidConfig = $wgContentTranslationParsoid;
     $this->serviceClient->mount('/parsoid/', new ParsoidVirtualRESTService(array('URL' => $parsoidConfig['url'], 'prefix' => $parsoidConfig['prefix'], 'timeout' => $parsoidConfig['timeout'])));
 }
Esempio n. 8
0
 public function __construct($main, $action)
 {
     parent::__construct($main, $action);
     $this->mPropModuleNames = array_keys($this->mQueryPropModules);
     $this->mListModuleNames = array_keys($this->mQueryListModules);
     $this->mMetaModuleNames = array_keys($this->mQueryMetaModules);
     // Allow the entire list of modules at first,
     // but during module instantiation check if it can be used as a generator.
     $this->mAllowedGenerators = array_merge($this->mListModuleNames, $this->mPropModuleNames);
 }
Esempio n. 9
0
	/**
	 * Constructor
	 * @param $dbSource ApiBase Module implementing getDB().
	 *        Allows PageSet to reuse existing db connection from the shared state like ApiQuery.
	 * @param int $flags Zero or more flags like DISABLE_GENERATORS
	 * @param int $defaultNamespace the namespace to use if none is specified by a prefix.
	 * @since 1.21 accepts $flags instead of two boolean values
	 */
	public function __construct( ApiBase $dbSource, $flags = 0, $defaultNamespace = NS_MAIN ) {
		parent::__construct( $dbSource->getMain(), $dbSource->getModuleName() );
		$this->mDbSource = $dbSource;
		$this->mAllowGenerator = ( $flags & ApiPageSet::DISABLE_GENERATORS ) == 0;
		$this->mDefaultNamespace = $defaultNamespace;

		$this->profileIn();
		$this->mParams = $this->extractRequestParams();
		$this->mResolveRedirects = $this->mParams['redirects'];
		$this->mConvertTitles = $this->mParams['converttitles'];
		$this->profileOut();
	}
Esempio n. 10
0
	/**
	 * Constructor
	 * If $format ends with 'fm', pretty-print the output in HTML.
	 * @param $main ApiMain
	 * @param string $format Format name
	 */
	public function __construct( $main, $format ) {
		parent::__construct( $main, $format );

		$this->mIsHtml = ( substr( $format, - 2, 2 ) === 'fm' ); // ends with 'fm'
		if ( $this->mIsHtml ) {
			$this->mFormat = substr( $format, 0, - 2 ); // remove ending 'fm'
		} else {
			$this->mFormat = $format;
		}
		$this->mFormat = strtoupper( $this->mFormat );
		$this->mCleared = false;
	}
Esempio n. 11
0
 /**
  * Constructor
  */
 public function __construct($main, $format)
 {
     parent::__construct($main, $format);
     $this->mIsHtml = substr($format, -2, 2) === 'fm';
     // ends with 'fm'
     if ($this->mIsHtml) {
         $this->mFormat = substr($format, 0, -2);
     } else {
         $this->mFormat = $format;
     }
     $this->mFormat = strtoupper($this->mFormat);
 }
Esempio n. 12
0
 /**
  * Constructor
  * $apiStartTime - time of the originating call for profiling purposes
  * $modules - an array of actions (keys) and classes that handle them (values) 
  */
 public function __construct($apiStartTime, $modules, $formats, $enableWrite)
 {
     // Special handling for the main module: $parent === $this
     parent::__construct($this, 'main');
     $this->mModules = $modules;
     $this->mModuleNames = array_keys($modules);
     $this->mFormats = $formats;
     $this->mFormatNames = array_keys($formats);
     $this->mApiStartTime = $apiStartTime;
     $this->mResult = new ApiResult($this);
     $this->mShowVersions = false;
     $this->mEnableWrite = $enableWrite;
 }
Esempio n. 13
0
 public function __construct($main, $action)
 {
     parent::__construct($main, $action);
     // Allow custom modules to be added in LocalSettings.php
     global $wgAPIPropModules, $wgAPIListModules, $wgAPIMetaModules;
     self::appendUserModules($this->mQueryPropModules, $wgAPIPropModules);
     self::appendUserModules($this->mQueryListModules, $wgAPIListModules);
     self::appendUserModules($this->mQueryMetaModules, $wgAPIMetaModules);
     $this->mPropModuleNames = array_keys($this->mQueryPropModules);
     $this->mListModuleNames = array_keys($this->mQueryListModules);
     $this->mMetaModuleNames = array_keys($this->mQueryMetaModules);
     $this->makeHelpMsgHelper($this->mQueryPropModules, 'prop');
     $this->makeHelpMsgHelper($this->mQueryListModules, 'list');
 }
Esempio n. 14
0
 /**
  * @param $main ApiMain
  * @param $action string
  */
 public function __construct($main, $action)
 {
     parent::__construct($main, $action);
     // Allow custom modules to be added in LocalSettings.php
     global $wgAPIPropModules, $wgAPIListModules, $wgAPIMetaModules, $wgAPIGeneratorModules;
     self::appendUserModules($this->mQueryPropModules, $wgAPIPropModules);
     self::appendUserModules($this->mQueryListModules, $wgAPIListModules);
     self::appendUserModules($this->mQueryMetaModules, $wgAPIMetaModules);
     self::appendUserModules($this->mQueryGenerators, $wgAPIGeneratorModules);
     $this->mPropModuleNames = array_keys($this->mQueryPropModules);
     $this->mListModuleNames = array_keys($this->mQueryListModules);
     $this->mMetaModuleNames = array_keys($this->mQueryMetaModules);
     $this->mAllowedGenerators = array_keys($this->mQueryGenerators);
 }
Esempio n. 15
0
 /**
  * If $format ends with 'fm', pretty-print the output in HTML.
  * @param ApiMain $main
  * @param string $format Format name
  */
 public function __construct(ApiMain $main, $format)
 {
     parent::__construct($main, $format);
     $this->mIsHtml = substr($format, -2, 2) === 'fm';
     // ends with 'fm'
     if ($this->mIsHtml) {
         $this->mFormat = substr($format, 0, -2);
         // remove ending 'fm'
         $this->mIsWrappedHtml = $this->getMain()->getCheck('wrappedhtml');
     } else {
         $this->mFormat = $format;
     }
     $this->mFormat = strtoupper($this->mFormat);
 }
Esempio n. 16
0
 /**
  * @param $main ApiMain
  * @param $action string
  */
 public function __construct($main, $action)
 {
     parent::__construct($main, $action);
     $this->mModuleMgr = new ApiModuleManager($this);
     // Allow custom modules to be added in LocalSettings.php
     global $wgAPIPropModules, $wgAPIListModules, $wgAPIMetaModules;
     $this->mModuleMgr->addModules(self::$QueryPropModules, 'prop');
     $this->mModuleMgr->addModules($wgAPIPropModules, 'prop');
     $this->mModuleMgr->addModules(self::$QueryListModules, 'list');
     $this->mModuleMgr->addModules($wgAPIListModules, 'list');
     $this->mModuleMgr->addModules(self::$QueryMetaModules, 'meta');
     $this->mModuleMgr->addModules($wgAPIMetaModules, 'meta');
     // Create PageSet that will process titles/pageids/revids/generator
     $this->mPageSet = new ApiPageSet($this);
 }
Esempio n. 17
0
 public function __construct($main, $action)
 {
     parent::__construct($main, $action);
     // Allow custom modules to be added in LocalSettings.php
     global $wgAPIPropModules, $wgAPIListModules, $wgAPIMetaModules;
     self::appendUserModules($this->mQueryPropModules, $wgAPIPropModules);
     self::appendUserModules($this->mQueryListModules, $wgAPIListModules);
     self::appendUserModules($this->mQueryMetaModules, $wgAPIMetaModules);
     $this->mPropModuleNames = array_keys($this->mQueryPropModules);
     $this->mListModuleNames = array_keys($this->mQueryListModules);
     $this->mMetaModuleNames = array_keys($this->mQueryMetaModules);
     // Allow the entire list of modules at first,
     // but during module instantiation check if it can be used as a generator.
     $this->mAllowedGenerators = array_merge($this->mListModuleNames, $this->mPropModuleNames);
 }
Esempio n. 18
0
 /**
  * @param ApiMain $main
  * @param string $action
  */
 public function __construct(ApiMain $main, $action)
 {
     parent::__construct($main, $action);
     $this->mModuleMgr = new ApiModuleManager($this);
     // Allow custom modules to be added in LocalSettings.php
     $config = $this->getConfig();
     $this->mModuleMgr->addModules(self::$QueryPropModules, 'prop');
     $this->mModuleMgr->addModules($config->get('APIPropModules'), 'prop');
     $this->mModuleMgr->addModules(self::$QueryListModules, 'list');
     $this->mModuleMgr->addModules($config->get('APIListModules'), 'list');
     $this->mModuleMgr->addModules(self::$QueryMetaModules, 'meta');
     $this->mModuleMgr->addModules($config->get('APIMetaModules'), 'meta');
     Hooks::run('ApiQuery::moduleManager', array($this->mModuleMgr));
     // Create PageSet that will process titles/pageids/revids/generator
     $this->mPageSet = new ApiPageSet($this);
 }
Esempio n. 19
0
 /**
  * Constructor
  * @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');
     $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;
 }
Esempio n. 20
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;
 }
 /**
  * constructor
  */
 public function __construct($query, $moduleName)
 {
     parent::__construct($query, $moduleName);
 }
Esempio n. 22
0
 /**
  * Constructs an instance of ApiMain that utilizes the module and format specified by $request.
  *
  * @param IContextSource|WebRequest $context If this is an instance of
  *    FauxRequest, errors are thrown and no printing occurs
  * @param bool $enableWrite Should be set to true if the api may modify data
  */
 public function __construct($context = null, $enableWrite = false)
 {
     if ($context === null) {
         $context = RequestContext::getMain();
     } elseif ($context instanceof WebRequest) {
         // BC for pre-1.19
         $request = $context;
         $context = RequestContext::getMain();
     }
     // We set a derivative context so we can change stuff later
     $this->setContext(new DerivativeContext($context));
     if (isset($request)) {
         $this->getContext()->setRequest($request);
     }
     $this->mInternalMode = $this->getRequest() 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 ($this->lacksSameOriginSecurity()) {
             // If we're in a mode that breaks the same-origin policy, strip
             // user credentials for security.
             wfDebug("API: stripping user credentials when the same-origin policy is not applied\n");
             $wgUser = new User();
             $this->getContext()->setUser($wgUser);
         }
     }
     $uselang = $this->getParameter('uselang');
     if ($uselang === 'user') {
         // Assume the parent context is going to return the user language
         // for uselang=user (see T85635).
     } else {
         if ($uselang === 'content') {
             global $wgContLang;
             $uselang = $wgContLang->getCode();
         }
         $code = RequestContext::sanitizeLangCode($uselang);
         $this->getContext()->setLanguage($code);
         if (!$this->mInternalMode) {
             global $wgLang;
             $wgLang = $this->getContext()->getLanguage();
             RequestContext::getMain()->setLanguage($wgLang);
         }
     }
     $config = $this->getConfig();
     $this->mModuleMgr = new ApiModuleManager($this);
     $this->mModuleMgr->addModules(self::$Modules, 'action');
     $this->mModuleMgr->addModules($config->get('APIModules'), 'action');
     $this->mModuleMgr->addModules(self::$Formats, 'format');
     $this->mModuleMgr->addModules($config->get('APIFormatModules'), 'format');
     Hooks::run('ApiMain::moduleManager', array($this->mModuleMgr));
     $this->mResult = new ApiResult($this->getConfig()->get('APIMaxResultSize'));
     $this->mErrorFormatter = new ApiErrorFormatter_BackCompat($this->mResult);
     $this->mResult->setErrorFormatter($this->mErrorFormatter);
     $this->mResult->setMainForContinuation($this);
     $this->mContinuationManager = null;
     $this->mEnableWrite = $enableWrite;
     $this->mSquidMaxage = -1;
     // flag for executeActionWithErrorHandling()
     $this->mCommit = false;
 }
Esempio n. 23
0
 /**
  * Constructs an instance of ApiMain that utilizes the module and format specified by $request.
  *
  * @param $context IContextSource|WebRequest - 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($context = null, $enableWrite = false)
 {
     if ($context === null) {
         $context = RequestContext::getMain();
     } elseif ($context instanceof WebRequest) {
         // BC for pre-1.19
         $request = $context;
         $context = RequestContext::getMain();
     }
     // We set a derivative context so we can change stuff later
     $this->setContext(new DerivativeContext($context));
     if (isset($request)) {
         $this->getContext()->setRequest($request);
     }
     $this->mInternalMode = $this->getRequest() 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 ($this->getRequest()->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();
             $this->getContext()->setUser($wgUser);
         }
     }
     global $wgAPIModules;
     // extension modules
     $this->mModules = $wgAPIModules + self::$Modules;
     $this->mModuleNames = array_keys($this->mModules);
     $this->mFormats = self::$Formats;
     $this->mFormatNames = array_keys($this->mFormats);
     $this->mResult = new ApiResult($this);
     $this->mShowVersions = false;
     $this->mEnableWrite = $enableWrite;
     $this->mSquidMaxage = -1;
     // flag for executeActionWithErrorHandling()
     $this->mCommit = false;
 }
Esempio n. 24
0
 public function __construct(ApiMain $main, $action)
 {
     parent::__construct($main, $action, 'lg');
 }
 public function __construct(ApiMain $main, $moduleName)
 {
     parent::__construct($main, $moduleName);
 }
Esempio n. 26
0
 public function __construct($main, $action)
 {
     parent::__construct($main, $action);
     $this->queryObj = new ApiQuery($this->getMain(), 'query');
 }
 public function __construct(ApiMain $mainModule, $moduleName, $modulePrefix = '')
 {
     parent::__construct($mainModule, $moduleName, $modulePrefix);
     $this->logger = new MRLogging(__FILE__);
 }
Esempio n. 28
0
 /**
  * @access public
  */
 public function __construct($main, $action)
 {
     self::$messageMap["cantrunjobs"] = array("code" => "cantrunjobs", 'info' => "You don't have permission to run jobs");
     parent::__construct($main, $action);
 }
Esempio n. 29
0
 public function __construct($main, $action)
 {
     parent::__construct($main, $action);
 }
Esempio n. 30
0
 /**
  * Constructor
  */
 public function __construct($main)
 {
     parent::__construct($main, 'result');
     $this->mIsRawMode = false;
     $this->reset();
 }