API:Restricting API usage/hi
![]() | यह पृष्ठ मीडियाविकि प्रतिक्रिया API प्रलेख का हिस्सा है। |
API (के कुछ हिस्सों) के उपयोग को सीमित करने के या फिर इसे पूरी तरह से अक्षम कर देने के कई तरीके हैं। इनमें से कुछ के लिए सदस्य समूह बदलने की ज़रूरत पड़ सकती है।
Disabling general access
There is no dedicated user permission for accessing the API. To disable API access for a specific user group, you can disable read
permissions for that group. For instance, to disallow anonymous requests,
$wgGroupPermissions['*']['read'] = false;
Note that some API modules may be available regardless. If access is successfully prevented, the API output will usually show the error code 'readapidenied'.
मोडल अक्षम करना
आप LocalSettings.php
पर एक पंक्ति जोड़कर विशिष्ट मोडलों को सभी सदस्यों के लिए अक्षम कर सकते हैं।
जोड़ना क्या है, यह उस मोडल के प्रकार पर निर्भर है जिसे आप अक्षम करना चाहते हैं:
action=
मोडलों के लिए$wgAPIModules ['modulename'] = 'ApiDisabled';
का इस्तेमाल करेंprop=
मोडलों के लिए$wgAPIPropModules ['modulename'] = 'ApiQueryDisabled';
का इस्तेमाल करेंlist=
मोडलों के लिए$wgAPIListModules ['modulename'] = 'ApiQueryDisabled';
का इस्तेमाल करेंmeta=
मोडलों के लिए$wgAPIMetaModules ['modulename'] = 'ApiQueryDisabled';
का इस्तेमाल करें
उदाहरण
बिना sysop अधिकार के सदस्यों के लिए action=edit
का उपयोग अक्षम करना:
$wgAPIModules['edit'] = 'ApiDisabled';
API ऐक्शन को सीमित करने के लिए ApiCheckCanExecute के लिए यह हुक जोड़ें:
static function onApiCheckCanExecute( $module, $user, &$message ) {
$moduleName = $module->getModuleName();
if (
$moduleName == 'action' &&
!in_array( 'right', $user->getRights() )
) {
$message = 'apierror-action-notallowed';
return false;
}
return true;
}
'action'
, 'right'
और 'apierror-action-notallowed'
को उनके वैल्यूओं से बदल दें।