Open samwilson opened 1 week ago
Hi, Sam To solve this issue;
Locate line 54 in the addwiki/packages/mediawiki-api-base/src/Client/Auth/UserAndPassword.php file. Change the line $request->setParam( 'assert', 'user' ); to $request->setParam( 'assert', 'bot' );
That's true, but it wouldn't fix the issue for anyone else.
I think it probably needs to do something similar to how addwiki-api does it, although I'm not quite sure what the best way is to pass an is-bot flag is. Perhaps the addition of AuthMethod::isBot(): bool
and AuthMethod::setBot( bool $bot )
?
To conditionally set the assert parameter in the preRequestAuth function, you can modify the function to accept an additional parameter that indicates whether the request is from a bot or a user. Here’s an example of how to implement this.
function preRequestAuth($request, $isBot = false) { if ($isBot) { $request->setParam('assert', 'bot'); } else { $request->setParam('assert', 'user'); } }
This way, you can call preRequestAuth with the $isBot parameter set to true for bots and false for users, allowing the assert parameter to be set dynamically.
(Just out of interest, are you using an AI tool to create that code?)
The preRequstAuth()
method isn't usually called by the consuming code, it's called from ActionApi::request()
, so it's not super convenient to change it there I think.
Since I'm interested in similar technologies, I wanted to help balance the problem. In general, I get analysis done with AI, educate myself and try to help solve problems. I hope I didn't offend you.
Oh no, don't worry I'm not offended! :-) Just interested, because it's becoming more common to see generated code. It's often not quite the right code though!
Have you used the AddWiki package much?
After more investigating, it appears that this isn't the root cause of my problems today. I do still think it'd be good to be able to customize this, but it turns out there was a session problem on my wiki (session being killed at some random point, resulting in an assert error). I removed the above assert parameter, and that resulted in the actual error being exposed so I could debug.
UserAndPassword::preRequestAuth()
currently addsassert=user
, but it should be possible to have this beassert=bot
when required.https://github.com/addwiki/addwiki/blob/e3615e9eb829bc8fe917bb6bfb33e827a8c50327/packages/mediawiki-api-base/src/Client/Auth/UserAndPassword.php#L54
https://www.mediawiki.org/wiki/API:Assert