API talk:Block

Latest comment: 1 year ago by Ponor in topic Blocking a number of users

What's mean "Invalid IP address specified"? I specified some Open Proxy for block but give me this error. How can I fix it?Ladsgroup 01:37, 16 November 2011 (UTC)Reply

It means the IP address isn't valid. It doesn't exist, can't edit your wiki, and can't be blocked. What IP address did you attempt to block? Reach Out to the Truth 03:28, 16 November 2011 (UTC)Reply

The "block" option doesn't seem to be available in my wikimedia version. What version is required? The only available "action" commands I have are: login, logout, query, expandtemplates, parse, opensearch, feedwatchlist, help, paraminfo. Block is not one of them.

Hide

edit

Is there an option to hide API blocks from the RC list (marking them as bot)? When done from the normal webpage the block is marked as bot edit. --Kevin 12:04, 21 August 2013 (UTC)

Can't block users with Internal API Call

edit

Hello, I am trying to customize the UserMerge extension for our wiki's purposes by adding a block to the user that is being merged (if not deleted). To do so, I need to call the Block API internally. This is my code:

            $params = new FauxRequest( array(
			'action'=>'query',
			'meta'=>'tokens',
		));
		$enableWrite = true; // This is set to false by default, in the ApiMain constructor
		$api = new ApiMain( $params, $enableWrite );
		$api->execute();
		$data = & $api->getResult()->getResultData();
		
		//Blocco l'utente
		//global $wgUser;
		//$token = $wgUser->getEditToken();
		$token = $data['query']['tokens']['csrftoken'];
		error_log($token);

		$params = new FauxRequest( array(
			'action'=>'block',
			'user'=>$oldUser,
			'token'=>$token,
		), true);
		$enableWrite = true; // This is set to false by default, in the ApiMain constructor
		$api = new ApiMain( $params, $enableWrite );
		$api->execute();
		//error_log( $data = & $api->getResult()->getResultData() );

Whether I use the first API call (that works), or $wgUser->getEditToken(); I still get an Invalid Token when the second API is called (and its resulting Usage Exception). I also tried to rawurlencode or urlencode the token even if this is not done in the tutorials, same error. $oldUser is the username of the person being blocked and is correct.

I'm not familiar with the PHP side of things, but the two most common causes of a valid token being rejected are that you're not preserving and sending coookies, or that you're sending a GET request instead of a POST request. Robin Hood  (talk) 18:53, 12 July 2016 (UTC)Reply
Thanks for the info, it turns out the original syntax was correct, I just had to use a DerivativeRequest with a default context instead of the FauxRequest, probably this lets PHP keep session cookies automatically in the request context. It was already a POST because of the ", true);" before $enableWrite definition.
Glad you figured it out! Robin Hood  (talk) 18:31, 22 July 2016 (UTC)Reply

Blocking a number of users

edit

This one is hard to practice, for obvious reasons, but how would one block a number of users (20ish), given user names in a list, using the MediaWiki JS example? Make as many new mw.Api() as there are users and use them inside list.forEach()? Got a bit rusty on all this, wondering what the best practice would be. ponor (talk) 20:53, 22 June 2023 (UTC)Reply

Return to "Block" page.