Last modified: 2011-04-30 01:21:46 UTC
I'm writing an extension that will create pages through the API based on user input. When the code that creates the page is executed, I'm getting a stack dump: Unexpected non-MediaWiki exception encountered, of type "UsageException" noapiwrite: Editing of this wiki through the API is disabled. Make sure the $wgEnableWriteAPI=true; statement is included in the wiki's LocalSettings.php file #0 /Users/lhridley/MediaWiki1_15/phase3/includes/api/ApiBase.php(830): ApiBase->dieUsage('Editing of this...', 'noapiwrite') #1 /Users/lhridley/MediaWiki1_15/phase3/includes/api/ApiMain.php(395): ApiBase->dieUsageMsg(Array) #2 /Users/lhridley/MediaWiki1_15/phase3/includes/api/ApiMain.php(220): ApiMain->executeAction() #3 /Users/lhridley/MediaWiki1_15/phase3/extensions/ProjectWiki/ProjectWiki.php(231): ApiMain->execute() #4 /Users/lhridley/MediaWiki1_15/phase3/extensions/ProjectWiki/ProjectWiki.php(117): ProjectSetup::createPage('Test Project', 'category', Array) #5 [internal function]: ProjectSetup::attemptSave(Object(EditPage)) #6 /Users/lhridley/MediaWiki1_15/phase3/includes/Hooks.php(117): call_user_func_array(Array, Array) #7 /Users/lhridley/MediaWiki1_15/phase3/includes/EditPage.php(749): wfRunHooks('EditPage::attem...', Array) #8 /Users/lhridley/MediaWiki1_15/phase3/includes/EditPage.php(2483): EditPage->internalAttemptSave(false, false) #9 /Users/lhridley/MediaWiki1_15/phase3/includes/EditPage.php(449): EditPage->attemptSave() #10 /Users/lhridley/MediaWiki1_15/phase3/includes/EditPage.php(340): EditPage->edit() #11 /Users/lhridley/MediaWiki1_15/phase3/includes/Wiki.php(510): EditPage->submit() #12 /Users/lhridley/MediaWiki1_15/phase3/includes/Wiki.php(63): MediaWiki->performAction(Object(OutputPage), Object(Article), Object(Title), Object(User), Object(WebRequest)) #13 /Users/lhridley/MediaWiki1_15/phase3/index.php(116): MediaWiki->initialize(Object(Title), Object(Article), Object(OutputPage), Object(User), Object(WebRequest)) #14 {main} The problem is that $wgEnableAPI is set to true, $wgEnableWriteAPI is set to true, and the user groups all have the writeapi permission. It appears that the $wgEnableWriteAPI flag is being ignored when the APIMain object is created. The code in the extension that attempts to create the object is as follows: $pageparams = array( 'action' => 'edit', 'section' => 0, 'token' => $pageinfo['edittoken'], 'summary' => 'Project Setup: Creating New Project pages for ' . $projectName, 'starttimestamp' => $pageinfo['starttimestamp'], 'title' => $pageinfo['title'] ); if($pagetype == 'category') { $pageparams['text'] = 'Listed below are all pages that are part of the ' . $projectName . ' project. '; } if($pagetype == 'issuetracker') { $pageparams['text'] = '<issues project="'.$projectName.'" /> [[Category:'.$projectName.' Project|{{BASEPAGENAME}}]] '; } $params = new FauxRequest($pageparams); $api = new ApiMain($params); $api->execute(); The error is occurring upon $api->execute();
The following line evaluates false: $wgUser->isAllowed('writeapi') Are you sure that 1) $wgUser is set up and that 2) the user has the writeapi permission?
Yes, the user is me currently, I am logged in and have sysop permissions. The following flags are set when the extension is loaded, and these are global in scope: $wgEnableWriteAPI = true; $wgEnableAPI = true; ## sets up a new group permission for project setup, and establishes a new group called "projectlead" $wgGroupPermissions['projectlead']['projectsetup'] = true; $wgGrouppermissions['projectlead']['writeapi'] = true; $wgGroupPermissions['sysop']['projectsetup'] = true; $wgGroupPermissions['sysop']['writeapi'] = true;
Additional information: When I change my code as follows, the page gets created successfully: 1. Add "global $wgEnableWriteAPI;" to the beginning of the method that creates the pages 2. Create the ApiMain object as follows: $api = new ApiMain($params, $wgEnableWriteAPI); But, that's not my understanding of how the API is supposed to work.
(In reply to comment #3) > Additional information: When I change my code as follows, the page gets > created successfully: > > 1. Add "global $wgEnableWriteAPI;" to the beginning of the method that creates > the pages > > 2. Create the ApiMain object as follows: > > $api = new ApiMain($params, $wgEnableWriteAPI); > > But, that's not my understanding of how the API is supposed to work. > That is how its supposed to work. The main use for the api is via its entry point in api.php, which does work that way. The use of the API in extensions is only of secondary importance.