Thanks I was just about to reply to you and say that I got it working
with cookies. Interesting that I can't get it to work with the tokens.
It must believe the session is ended when doing it without cookies.
---Working PHP Edit Code---
echo "<pre>";
print_r($_POST);
$apiURL = "http://".$_SERVER['HTTP_HOST']."/phpapps/wiki/api.php";
$loginURL =
array("action"=>"login","lgname"=>"jkuter","lgpassword"=>"","lgdomain"=>
"ad.mathworks.com","format"=>"php");
$getLoginResponse = unserialize(getURL($apiURL,$loginURL));
print_r($getLoginResponse);
$titleURLParams =
array("action"=>"query","prop"=>"info","titles"=>"BatPresubmitTest","int
oken"=>"edit","format"=>"php");
print_r($titleURLParams);
$getTitleResponse = unserialize(getURL($apiURL,$titleURLParams));
print_r($getTitleResponse);
//$newPageURLParams =
array("action"=>"query","prop"=>"info","titles"=>"BatPresubmitTest","int
oken"=>"edit",
//
"lgtoken"=>$getLoginResponse['login']['lgtoken'],"lgusername"=>$getLogin
Response['login']['lgusername'],
//
"lguserid"=>$getLoginResponse['login']['lguserid'],"format"=>"php");
//$makeNewPage = unserialize(getURL($apiURL,$newPageURLParams));
//print_r($makeNewPage);
echo "</pre>";
function getURL($url,$vars){
include "Snoopy.class.php";
$snoopy = new Snoopy;
$snoopy->cookies["inside_wikiToken"] =
$_COOKIE["inside_wikiToken"];
$snoopy->cookies["inside_wikiUserID"] =
$_COOKIE["inside_wikiUserID"];
$snoopy->cookies["inside_wikiUserName"] =
$_COOKIE["inside_wikiUserName"];
$snoopy->cookies["inside_wiki_session"] =
$_COOKIE["inside_wiki_session"];
$snoopy->submit($url,$vars);
$snoopy->setcookies();
return $snoopy->results;
}
---End Working PHP Code---
-----Original Message-----
From: Roan Kattouw [mailto:roan.kattouw@home.nl]
Sent: Tuesday, November 13, 2007 12:23 PM
To: Jason Kuter
Subject: Re: [Mediawiki-api] FW: Problems Using API Via PHP
Jason Kuter schreef:
> Understood, I just wish it worked without an additional class. Using
> Snoopy works but my user is not being authenticated. It must be
another
> issue.
>
> Thanks for the reply,
>
> jason
Use $snoopy->setCookies(); after doing action=login to force Snoopy to
remember the authentication cookies.
Roan Kattouw (Catrope)
I understand that this part of the API is not implemented fully etc,
etc. However I am having an issue I can't get around which is the
following:
&prop is converted by php to the "proportional" char when sending via
post, get, using curl, fopen, file_get_contents. This whole process
works just fine if I execute via the URL in the browser, so I know it
can happen. Is there a way around using &prop=info to get a token to
complete the page creation process? Why is &prop being used when it's a
reserved html special char? It seems silly to be blocked by such a
little thing but I can't seem to get around it and would rather not do
this whole thing is javascript since this script will have a lot of work
to do when its complete. My assumption is that many people will run
into this when the api becomes more popular, because who doesn't love
php?
Thanks,
jason
--Info---
* MediaWiki: 1.12alpha
* PHP: 5.1.2 (apache2handler)
* MySQL: 5.0.18-log
---Begin PHP Code---
echo "<pre>";
print_r($_POST);
$apiURL = "http://".$_SERVER['HTTP_HOST']."/phpapps/wiki/api.php";
$loginURL =
"action=login&lgname=jkuter&lgpassword=&lgdomain=ad.mathworks.com&format
=php";
$getLoginResponse = unserialize(getURL($apiURL,$loginURL));
print_r($getLoginResponse);
$titleURL =
"action=query&prop=info&titles=BatPresubmitTest&intoken=edit&lgtoken=".
$getLoginResponse['login']['lgtoken']."&lgusername=".
$getLoginResponse['login']['lgusername']."&lguserid=".
$getLoginResponse['login']['lguserid'].
"&format=php";
$getTitleResponse = unserialize(getURL($apiURL,$titleURL));
print_r($getTitleResponse);
$newPageURL =
"action=query&prop=info&titles=BatPresubmitTest&intoken=edit&lgtoken=".
$getLoginResponse['login']['lgtoken']."&lgusername=".
$getLoginResponse['login']['lgusername']."&lguserid=".
$getLoginResponse['login']['lguserid'].
"&format=php";
//$makeNewPage = unserialize(getURL($apiURL,$newPageURL));
//print_r($makeNewPage);
echo "</pre>";
function getURL($url,$vars){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch,CURLOPT_POSTFIELDS,$vars);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
---End PHP Code---
---Begin output with &prop---
Array
(
[RCAlink] => Insert link here
[ReqDesRevDoclink] => Insert link here
[LEGORevlink] => Insert link here
[APIClasslink] => Insert link here
[CRChecklistLink] => Insert link here
[CRList] => Insert list here
[TestsAddedDescription] => Insert description here
[RunSuiteList] => Insert list here
[InteractiveBashingList] => Insert list here
[BaTStages] => Insert list here
[ForeignFilesMissing] => Insert link here
[BuildPlatformsList] => Insert list here
[TestPlatformsList] => Insert list here
[TestingBottleneck] => YNTestingBottleneck
[FinalMergeCheck] => YNFinalMergeCheck
[SubmitJob] => YNSubmitJob
[JobNo] => dsfdsf
[Submit_Checklist] => Submit
)
Array
(
[login] => Array
(
[result] => Success
[lguserid] => 1004
[lgusername] => Jkuter
[lgtoken] => 4ee852dbbe6ad67022af0873aaa21098
[cookieprefix] => inside_wiki
[sessionid] =>
)
)
Array
(
[error] => Array
(
[code] => inpermissiondenied
[info] => Action 'edit' is not allowed for the current user
)
)
--End Output With &prop---
---Begin Output Without &prop---
Array
(
[RCAlink] => Insert link here
[ReqDesRevDoclink] => Insert link here
[LEGORevlink] => Insert link here
[APIClasslink] => Insert link here
[CRChecklistLink] => Insert link here
[CRList] => Insert list here
[TestsAddedDescription] => Insert description here
[RunSuiteList] => Insert list here
[InteractiveBashingList] => Insert list here
[BaTStages] => Insert list here
[ForeignFilesMissing] => Insert link here
[BuildPlatformsList] => Insert list here
[TestPlatformsList] => Insert list here
[TestingBottleneck] => YNTestingBottleneck
[FinalMergeCheck] => YNFinalMergeCheck
[SubmitJob] => YNSubmitJob
[JobNo] => dsfdsf
[Submit_Checklist] => Submit
)
Array
(
[login] => Array
(
[result] => Success
[lguserid] => 1004
[lgusername] => Jkuter
[lgtoken] => 4ee852dbbe6ad67022af0873aaa21098
[cookieprefix] => inside_wiki
[sessionid] =>
)
)
Array
(
[query] => Array
(
[pages] => Array
(
[-1] => Array
(
[ns] => 0
[title] => BatPresubmitTest
[missing] =>
)
)
)
)
--End Output Without &prop---
Searching the list and I figure that the search API is currently broke? If
so I guess I can / should use the "list=allpages" API for a temporary hack.
Any god-beings out there that can advise?
Ben Srour wrote:
> >* I'm sorry, I don't know what that means. :)
> *>*
> *>* What action should I take as a consumer of the API?
> *>*
> *>* Thanks
> *>* Ben
> *
> As a consumer? Wait for the god-beings to fix it.
> Or you may become a developer and fix it ;)
>
>
Hi All:
I have blown 8 hrs over 2 days trying to figure out what is wrong with my PHP program to try to do a query.
I am trying to build a simple PHP program to get the contents of recent changes on a wiki I admin.
Here is the code, with a couple of things "anonymized" (surrounded by << >>):
========= begin code ===========
<?php
//login and get the correct security values to pass in on subsequent queries
$wikiURL = "<<mydomain>>/mediawiki";
$logincmd = $wikiURL."/api.php?action=login&lgname=Sgg&lgpassword=<<mypwd>>&format=json";
$handle = fopen($logincmd,"rb");
$contents = stream_get_contents($handle);
fclose($handle);
$loginVals = json_decode($contents, true);
if($loginVals["login"]["result"] != "Success"){
echo"Failed to login, result returned ", $loginVals["login"]["result"];
exit(-1);
}
//set up the security parm values and create query
$userid = $loginVals["login"]["lguserid"];
$username = $loginVals["login"]["lgusername"];
$token = $loginVals["login"]["lgtoken"];
$query = $wikiURL."/api.php?action=query&list=recentchanges&format=xml&lgtoken=$token&lgusername=$username&lguserid=$userid";
echo"
Query",$query,"
";
//execute the get and print the results
$handle = fopen($query,"rb");
$contents = stream_get_contents($handle);
fclose($handle);
print_r("
Query results");
print_r($contents);
print_r("
end query results
");
?>
===============end code ================
The login works fine, returns reasonable looking tokens. The Query results, however are empty.
When I copy the query that was produced (note the echo statement), and paste that into a browser (that I have previously used to login to the wiki, I get some query results back. When I paste that query into a browser I rarely use (ie haven't logged into the wiki), I get empty result set.
So, am I misusing the login parms somehow on the query url? Are the login parms not working? Should I use cookie manipulation instead?
Please help
sgg
Hello,
whats the current state of the edit API functionality? Does it work?
Bye
Christian
===========================
Freiberuflicher Softwareentwickler
Christian Thiele
August-Bebel-Straße 48
04275 Leipzig
Tel. 0178 4860018
I see that this branch is a little out of date, and didn't get any
word from anyone maintaining it on the discussion page (thanks to Roan
for the reply and info), and I wasn't sure where to ask other than
here. Is there any change we can get it synced? I'd be willing to
volunteer to help maintain and develop on it as I have some interest
in getting editing working as well. Thanks guys and gals!
Eddie
Hi.
I am watching this list for a couple of months now, and this is the answer every time.
Does anyone know an estimate on when this will work? I see it as a pretty important feature, which should be taken into consideration... :)
Thanks!
>
> Wikimedia uses Lucene as search backend, which is currently not
> supported by the API.
>
> Bryan
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
I've been tinkering with pieces of ApiMain to attack the login through
POST variables issue, and I think I have a patch for it. But, being
new to shared development like this, I've never submitted anything
before. How can I submit a patch? I'm sure just committing the new
files is a bad idea, and I probably don't have permission to do that
anyway. Is anyone willing to do a code test on their part to make sure
it works? Of course I tested it on my end, but the more eyes, the
better. Please let me know how I should submit. Thanks.
Eddie
On IRC, Carl Fürstenberg (AzaTht) pointed out that for cmcategory, the
Category: namespace prefix is implicit (i.e. for [[Category:People]],
you'd use cmcategory=People), while this is not the case for imageinfo
and imageusage the Image: namespace is not implied
(iutitle=Image:Dog.jpg). For consistency's sake (and to make copying
titles from other request easier), Carl suggested categorymembers be
changed to explicitly require the Category: namespace prefix. Since this
would be a breaking change, however, I'm suggesting this here first and
asking for your input on whether we should do this.
Roan Kattouw