Last modified: 2011-04-30 01:21:46 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T21677, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 19677 - Stack dump with errors when trying to create pages through the API
Stack dump with errors when trying to create pages through the API
Status: RESOLVED INVALID
Product: MediaWiki
Classification: Unclassified
API (Other open bugs)
1.15.x
All All
: Normal major (vote)
: ---
Assigned To: Roan Kattouw
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-07-12 18:45 UTC by Lisa Ridley
Modified: 2011-04-30 01:21 UTC (History)
4 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Lisa Ridley 2009-07-12 18:45:47 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();
Comment 1 Bryan Tong Minh 2009-07-12 19:12:19 UTC
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?
Comment 2 Lisa Ridley 2009-07-12 19:14:37 UTC
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;
Comment 3 Lisa Ridley 2009-07-12 19:17:49 UTC
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.  
Comment 4 Bryan Tong Minh 2009-07-12 19:22:03 UTC
(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.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links