Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to fetch data from Special:Ask via cURL? #3168

Closed
mwjames opened this Issue May 13, 2018 · 2 comments

Comments

2 participants
@mwjames
Copy link
Contributor

mwjames commented May 13, 2018

refs https://sourceforge.net/p/semediawiki/mailman/message/36312276/

Essentially, I'd like the results of a query such as:
{{#ask: [[Category:Foo]] [[MyParam::Bar]] |format=csv }}
How does one write a cURL statement so as to querry the wiki from a php script and save the data into a veriable?

// Wiki url
$url = 'http://127.0.0.1:8080/wiki/index.php';

// Query parameters
$params = [
	'title' => 'Special:Ask',
	// Query conditions
	'q'     => '[[Has number::+]]',
	// Printouts
	'po'    => 'Has number',
	// Parameters
	'p'     => 'format=csv',
	// since 3.0+
	'request_type' => 'raw'
];

$options = array(
	CURLOPT_URL => $url,
	CURLOPT_POST => true,
	CURLOPT_POSTFIELDS => http_build_query( $params ),
	CURLOPT_RETURNTRANSFER => 1
);

// Create curl resource
$ch = curl_init();

// Set options
curl_setopt_array( $ch, $options );

// Fetch output string
$output = curl_exec( $ch );

// Close curl resource
curl_close( $ch );

The $output contains the content as string from the predefined format. The above example uses a similar approach as implemented by #3167.

@mwjames

This comment has been minimized.

Copy link
Contributor Author

mwjames commented May 13, 2018

@kghbln FYI

@kghbln

This comment has been minimized.

Copy link
Member

kghbln commented May 13, 2018

@kghbln kghbln closed this May 13, 2018

@kghbln kghbln added this to Documentation in Documentation May 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.