User:Prisicilavilemen/Sandbox/API:Pageswithprop
Appearance
This page is part of the MediaWiki Action API documentation. |
MediaWiki version: | ≥ 1.21 |
GET request List all pages using a given page property.
API documentation
[edit]
list=pageswithprop (pwp)
List all pages using a given page property. Specific parameters: Other general parameters are available.
Examples:
|
Example
[edit]GET request
[edit]Response
[edit]{
"batchcomplete": "",
"continue": {
"ppncontinue": "kartographer_frames",
"continue": "-||"
},
"query": {
"pageswithprop": [
{
"pwppropname": "defaultsort"
},
{
"pwppropname": "disambiguation"
},
{
"pwppropname": "displaytitle"
}
...
]
}
}
Sample code
[edit]Python
[edit]#!/usr/bin/python3
"""
get_pageswithprop.py
MediaWiki API Demos
Demo of `Pageswithprop` module: List all pages using a given page property.
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"list": "pageswithprop",
"pwppropname": "displaytitle",
"format": "json"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
PAGESWITHPROP = DATA["query"]["pageswithprop"]
for p in PAGESWITHPROP:
print(p["title"])
PHP
[edit]<?php
/*
get_pageswithprop.php
MediaWiki API Demos
Demo of `Pageswithprop` module: List all pages using a given page property.
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"list" => "pageswithprop",
"pwppropname" => "displaytitle",
"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 );
foreach( $result["query"]["pageswithprop"] as $k => $v ) {
echo( $v["title"] . "\n" );
}
JavaScript
[edit]/*
get_pageswithprops.js
MediaWiki API Demos
Demo of `Pageswithprop` module: List all pages using a given page property.
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
list: "pageswithprop",
pwppropname: "displaytitle",
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) {
var pageswithprop = response.query.pageswithprop;
for (var p in pageswithprop) {
console.log(pageswithprop[p].title);
}
})
.catch(function(error){console.log(error);});
MediaWiki JS
[edit]/*
get_pageswithprop.js
MediaWiki API Demos
Demo of `Pageswithprop` module: List all pages using a given page property.
MIT License
*/
var params = {
action: 'query',
list: 'pageswithprop',
pwppropname: "displaytitle",
format: 'json'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var pageswithprops = data.query.pageswithprop,
p;
for ( p in pageswithprops ) {
console.log( pageswithprops[ p ].title );
}
} );
See also
[edit]- API:Allpages - List all pages fitting certain criteria, within a given namespace.
- API:Pagepropnames - List all page properties in use on the wiki.
- API:Categorymembers - lists all pages within a category