واجهة برمجة التطبيقات:Allcategories

This page is a translated version of the page API:Allcategories and the translation is 100% complete.
إصدار ميدياويكي:
1.12

طلب GET الغرض منه سرد كافة التصنيفات التي ينطبق عليها معايير محددة تتعلق بعناوينها.

يمكن استخدام هذه الوحدة البرمجية بصفة مولّد .

توثيق واجهة برمجة التطبيقات


list=allcategories (ac)

(main | query | allcategories)
  • This module requires read rights.
  • This module can be used as a generator.
  • Source: MediaWiki
  • License: GPL-2.0-or-later

Enumerate all categories.

Specific parameters:
Other general parameters are available.
acfrom

The category to start enumerating from.

accontinue

When more results are available, use this to continue. More detailed information on how to continue queries can be found on mediawiki.org.

acto

The category to stop enumerating at.

acprefix

Search for all category titles that begin with this value.

acdir

Direction to sort in.

One of the following values: ascending, descending
Default: ascending
acmin

Only return categories with at least this many members.

Type: integer
acmax

Only return categories with at most this many members.

Type: integer
aclimit

How many categories to return.

Type: integer or max
The value must be between 1 and 500.
Default: 10
acprop

Which properties to get:

size
Adds number of pages in the category.
hidden
Tags categories that are hidden with __HIDDENCAT__.
Values (separate with | or alternative): hidden, size
Default: (empty)
Examples:
List categories with information on the number of pages in each.
api.php?action=query&list=allcategories&acprop=size [open in sandbox]
Retrieve info about the category page itself for categories beginning List.
api.php?action=query&generator=allcategories&gacprefix=List&prop=info [open in sandbox]

مثال

طلب GET

الحصول على قائمة بكافة التصنيفات التي تبدأ بالعبارة «15th-century caliphs».


النتيجة

{
    {
    "batchcomplete": "",
    "continue": {
        "accontinue": "15th-century_churches_in_Denmark",
        "continue": "-||"
    },
    "query": {
        "allcategories": [
            {
                "*": "15th-century caliphs"
            },
            {
                "*": "15th-century calligraphers"
            },
            {
                "*": "15th-century card games"
            },
            ...
        ]
    }
}

عينة من الكود البرمجي

Python

#!/usr/bin/python3

"""
    get_allcategories.py

    MediaWiki API Demos
    Demo of `Allcategories` module: Get all categories, starting from a
    certain point, as ordered by category title.

    MIT License
"""

import requests

S = requests.Session()

URL = "https://en.wikipedia.org/w/api.php"

PARAMS = {
    "action": "query",
    "format": "json",
    "list": "allcategories",
    "acfrom": "15th-century caliphs"
}

R = S.get(url=URL, params=PARAMS)
DATA = R.json()

CATEGORIES = DATA["query"]["allcategories"]

for cat in CATEGORIES:
    print(cat["*"])

PHP

<?php
/*
    get_allcategories.php

    MediaWiki API Demos
    Demo of `Allcategories` module: Get all categories, starting from a certian point, as ordered by category title.

    MIT License
*/

$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
    "action" => "query",
    "format" => "json",
    "list" => "allcategories",
    "acfrom" => "15th-century caliphs"
];

$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"]["allcategories"] as $k => $v ) {
    echo( $v["*"] . "\n" );
}

JavaScript

/*
    get_allcategories.js

    MediaWiki API Demos
    Demo of `Allcategories` module: Get all categories, starting from a certain point, as ordered by category title.

    MIT License
*/

var url = "https://en.wikipedia.org/w/api.php"; 

var params = {
    action: "query",
    format: "json",
    list: "allcategories",
    acfrom: "15th-century caliphs"
};

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 categories = response.query.allcategories;
        for (var cat in categories) {
            console.log(categories[cat]["*"]);
        }
    })
    .catch(function(error){console.log(error);});

MediaWiki JS

/*
	get_allcategories.js

	MediaWiki API Demos
	Demo of `Allcategories` module: Get all categories,
	starting from a certian point, as ordered by category title.

	MIT License
*/

var params = {
		action: 'query',
		format: 'json',
		list: 'allcategories',
		acfrom: '15th-century caliphs'
	},
	api = new mw.Api();

api.get( params ).done( function ( data ) {
	var categories = data.query.allcategories,
		cat;
	for ( cat in categories ) {
		console.log( categories[ cat ][ '*' ] );
	}
} );

ملاحظات إضافية

  • تختلف هذه الوحدة البرمجية عن list=allpages&alnamespace=14 من ناحية أن التصنيفات التي لا يوجد لها وصف سوف تضاف تسرد أيضا، بينما لن تسرد صفحات إعادة التوجيه والصفحات التي لم يستخدم فيها التصنيف على الإطلاق.
  • ربما تضم النتيجة تصنيفات استخدمت من قبل إلا أنها أزيلت منذ ذلك الحين.
  • منذ أن النتيجة قد تشتمل على تصنيفات أزيلت أو فارغة، نحبذ ترشيح القائمة مستخدما acmin=1، حتى تحصل فقط على تصنيفات تحتوي على عضو واحد أو أكثر من واحد.

انظر أيضا