API:Pageprops
Appearance
This page is part of the MediaWiki Action API documentation. |
MediaWiki version: | ≥ 1.17 |
GET request to get various properties defined in the page content.
API documentation
[edit]
Example
[edit]GET request
[edit]Get various properties defined in the page content.
Response
[edit]{
"batchcomplete": "",
"query": {
"pages": {
"736": {
"pageid": 736,
"ns": 0,
"title": "Albert Einstein",
"pageprops": {
"defaultsort": "Einstein, Albert",
"page_image_free": "Einstein_1921_by_F_Schmutzer_-_restoration.jpg",
"wikibase-badge-Q17437798": "1",
"wikibase_item": "Q937"
}
}
}
}
Sample code
[edit]Python
[edit]#!/usr/bin/python3
"""
pageprops.py
MediaWiki API Demos
Demo of `Pageprops` module: Get various properties defined in the page content
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"titles": "Albert Einstein",
"prop": "pageprops",
"format": "json"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
print(DATA)
PHP
[edit]<?php
/*
pageprops.php
MediaWiki API Demos
Demo of `Pageprops` module: Get various properties defined in the page content
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"titles" => "Albert Einstein",
"prop" => "pageprops",
"format" => "json"
];
$url = $endPoint . "?" . http_build_query( $params );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );
$result = json_decode( $output, true );
var_dump( $result );
JavaScript
[edit]/*
pageprops.js
MediaWiki API Demos
Demo of `Pageprops` module: Get various properties defined in the page content
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
titles: "Albert Einstein",
prop: "pageprops",
format: "json"
};
url = url + "?origin=*";
Object.keys(params).forEach(function(key) { url += "&" + key + "=" + params[key]; });
fetch(url)
.then(function(response) { return response.json(); })
.then(function(response) { console.log(response); })
.catch(function(error) { console.log(error); });
MediaWiki JS
[edit]/*
pageprops.js
MediaWiki API Demos
Demo of `Pageprops` module: Get various properties defined in the page content
MIT License
*/
var params = {
action: 'query',
titles: 'Albert Einstein',
prop: 'pageprops',
format: 'json'
};
var api = new mw.Api();
api.get( params ).then( function ( data ) {
console.log( data );
} );
See also
[edit]- API:Pageswithprop – list all pages using a given page property.
- API:Pagepropnames – list all page property names in use on the wiki.
- API:Properties – get general properties of pages (not necessarily defined in the page content).