Movatterモバイル変換


[0]ホーム

URL:


Jump to content
MediaWiki
Search

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

From mediawiki.org
This page is atranslated version of the pageAPI:Parsing wikitext and the translation is 100% complete.
Languages:
هذه الصفحة جزء من توثيقواجهة برمجة تطبيقات ميدياويكي التي تحمل اسم Action.
واجهة برمجة التطبيقات لتطبيق Action على ميدياويكي
الأساسيات
التصديق
الحسابات والمستخدمين
عمليات الصفحات
البحث
أدوات المطورين
برامج تعليمية
ع · ن · ت

طلب POST/GET الغرض منه إعراب محتوى صفحة برمجيًا والحصول على الناتج.

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

أعمال التوثيق التالية هي نتاج صفحةSpecial:ApiHelp/parse، التي ولّدتها آليا نسخة سابقة للإصدار من برمجيات ميدياويكي تعمل على هذا الموقع الشبكي (MediaWiki.org).

action=parse

(main |parse)

Parses content and returns parser output.

See the various prop-modules ofaction=query to get information from the current version of a page.

There are several ways to specify the text to parse:

  1. Specify a page or revision, usingpage,pageid, oroldid.
  2. Specify content explicitly, usingtext,title,revid, andcontentmodel.
  3. Specify only a summary to parse.prop should be given an empty value.
Specific parameters:
Other general parameters are available.
title

Title of page the text belongs to. If omitted,contentmodel must be specified, andAPI will be used as the title.

text

Text to parse. Usetitle orcontentmodel to control the content model.

revid

Revision ID, for{{REVISIONID}} and similar variables.

Type: integer
summary

Summary to parse.

page

Parse the content of this page. Cannot be used together withtext andtitle.

pageid

Parse the content of this page. Overridespage.

Type: integer
redirects

Ifpage orpageid is set to a redirect, resolve it.

Type: boolean (details)
oldid

Parse the content of this revision. Overridespage andpageid.

Type: integer
prop

Which pieces of information to get:

text
Gives the parsed text of the wikitext.
langlinks
Gives the language links in the parsed wikitext.
categories
Gives the categories in the parsed wikitext.
categorieshtml
Gives the HTML version of the categories.
links
Gives the internal links in the parsed wikitext.
templates
Gives the templates in the parsed wikitext.
images
Gives the images in the parsed wikitext.
externallinks
Gives the external links in the parsed wikitext.
sections
Deprecated. Gives the sections in the parsed wikitext.
tocdata
Gives the table of contents information in the parsed wikitext.
revid
Adds the revision ID of the parsed page.
displaytitle
Adds the title of the parsed wikitext.
subtitle
Adds the page subtitle for the parsed page.
headhtml
Gives parsed doctype, opening<html>,<head> element and opening<body> of the page.
modules
Gives the ResourceLoader modules used on the page. To load, usemw.loader.using(). Eitherjsconfigvars orencodedjsconfigvars must be requested jointly withmodules.
jsconfigvars
Gives the JavaScript configuration variables specific to the page. To apply, usemw.config.set().
encodedjsconfigvars
Gives the JavaScript configuration variables specific to the page as a JSON string.
indicators
Gives the HTML of page status indicators used on the page.
iwlinks
Gives interwiki links in the parsed wikitext.
wikitext
Gives the original wikitext that was parsed.
properties
Gives various properties defined in the parsed wikitext.
limitreportdata
Gives the limit report in a structured way. Gives no data, whendisablelimitreport is set.
limitreporthtml
Gives the HTML version of the limit report. Gives no data, whendisablelimitreport is set.
parsetree
The XML parse tree of revision content (requires content modelwikitext)
parsewarnings
Gives the warnings that occurred while parsing content (as wikitext).
parsewarningshtml
Gives the warnings that occurred while parsing content (as HTML).
headitems
Deprecated. Gives items to put in the<head> of the page.
Values (separate with| oralternative): categories, categorieshtml, displaytitle, encodedjsconfigvars, externallinks, headhtml, images, indicators, iwlinks, jsconfigvars, langlinks, limitreportdata, limitreporthtml, links, modules, parsetree, parsewarnings, parsewarningshtml, properties, revid, subtitle, templates, text, tocdata, wikitext, headitems, sections
Default: text|langlinks|categories|links|templates|images|externallinks|sections|tocdata|revid|displaytitle|iwlinks|properties|parsewarnings
wrapoutputclass

CSS class to use to wrap the parser output.

Default: mw-parser-output
usearticle

Use the ArticleParserOptions hook to ensure the options used match those used for article page views

Type: boolean (details)
parsoid
Deprecated.

Generate HTML conforming to theMediaWiki DOM spec usingParsoid. Replaced byparser=parsoid.

Type: boolean (details)
parser

Which wikitext parser to use:

parsoid
Generate HTML conforming to theMediaWiki DOM spec usingParsoid.
default
Generate HTML using this wiki's default parser.
legacy
Generate HTML using the legacy parser.
One of the following values: default, legacy, parsoid
Default: default
pst

Do a pre-save transform on the input before parsing it. Only valid when used with text.

Type: boolean (details)
onlypst

Do a pre-save transform (PST) on the input, but don't parse it. Returns the same wikitext, after a PST has been applied. Only valid when used withtext.

Type: boolean (details)
effectivelanglinks
Deprecated.

Includes language links supplied by extensions (for use withprop=langlinks).

Type: boolean (details)
section

Only parse the content of the section with this identifier.

Whennew, parsetext andsectiontitle as if adding a new section to the page.

new is allowed only when specifyingtext.

sectiontitle

New section title whensection isnew.

Unlike page editing, this does not fall back tosummary when omitted or empty.

disablepp
Deprecated.

Usedisablelimitreport instead.

Type: boolean (details)
disablelimitreport

Omit the limit report ("NewPP limit report") from the parser output.

Type: boolean (details)
disableeditsection

Omit edit section links from the parser output.

Type: boolean (details)
disablestylededuplication

Do not deduplicate inline stylesheets in the parser output.

Type: boolean (details)
showstrategykeys

Whether to include internal merge strategy information in jsconfigvars.

Type: boolean (details)
generatexml
Deprecated.

Generate XML parse tree (requires content modelwikitext; replaced byprop=parsetree).

Type: boolean (details)
preview

Parse in preview mode.

Type: boolean (details)
sectionpreview

Parse in section preview mode (enables preview mode too).

Type: boolean (details)
disabletoc

Omit table of contents in output.

Type: boolean (details)
useskin

Apply the selected skin to the parser output. May affect the following properties:text,langlinks,headitems,modules,jsconfigvars,indicators.

One of the following values: apioutput, authentication-popup, cologneblue, fallback, json, minerva, modern, monobook, timeless, vector, vector-2022
contentformat

Content serialization format used for the input text. Only valid when used with text.

One of the following values: application/json, application/octet-stream, application/unknown, application/vue+xml, application/x-binary, text/css, text/javascript, text/plain, text/unknown, text/x-wiki, unknown/unknown
contentmodel

Content model of the input text. If omitted, title must be specified, and default will be the model of the specified title. Only valid when used with text.

One of the following values: GadgetDefinition, Graph.JsonConfig, Json.JsonConfig, JsonSchema, MassMessageListContent, NewsletterContent, Scribunto, SecurePoll, css, flow-board, javascript, json, sanitized-css, text, translate-messagebundle, unknown, vue, wikitext
mobileformat

Return parse output in a format suitable for mobile devices.

Type: boolean (details)
templatesandboxprefix

Template sandbox prefix, as withSpecial:TemplateSandbox.

Separate values with| oralternative.
Maximum number of values is 50 (500 for clients that are allowed higher limits).
templatesandboxtitle

Parse the page usingtemplatesandboxtext in place of the contents of the page named here.

templatesandboxtext

Parse the page using this page content in place of the page named bytemplatesandboxtitle.

templatesandboxcontentmodel

Content model oftemplatesandboxtext.

One of the following values: GadgetDefinition, Graph.JsonConfig, Json.JsonConfig, JsonSchema, MassMessageListContent, NewsletterContent, Scribunto, SecurePoll, css, flow-board, javascript, json, sanitized-css, text, translate-messagebundle, unknown, vue, wikitext
templatesandboxcontentformat

Content format oftemplatesandboxtext.

One of the following values: application/json, application/octet-stream, application/unknown, application/vue+xml, application/x-binary, text/css, text/javascript, text/plain, text/unknown, text/x-wiki, unknown/unknown

مثال 1: إعراب محتوى صفحة برمجيًا

طلب GET

api.php?action=parse&page=Pet_door&format=json [جربها في ApiSandbox]

النتيجة

{"parse":{"title":"Pet door","pageid":3276454,"revid":852892138,"text":{"*":"<div class=\"mw-parser-output\"><div class=\"thumb tright\"><div class=\"thumbinner\" style=\"width:222px;\"><a href=\"/wiki/File:Doggy_door_exit.JPG\" class=\"image\"><img alt=\"\" src=\"//upload.wikimedia.org/wikipedia/commons/thumb/7/71/Doggy_door_exit.JPG/220px-Doggy_door_exit.JPG\" width=\"220\" height=\"165\" class=\"thumbimage\" srcset=\"//upload.wikimedia.org/wikipedia/commons/thumb/7/71/Doggy_door_exit.JPG/330px-Doggy_door_exit.JPG 1.5x,            ...        }    }}

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

Python

#!/usr/bin/python3"""    parse.py    MediaWiki API Demos    Demo of `Parse` module: Parse content of a page    MIT License"""importrequestsS=requests.Session()URL="https://en.wikipedia.org/w/api.php"PARAMS={"action":"parse","page":"Pet door","format":"json"}R=S.get(url=URL,params=PARAMS)DATA=R.json()print(DATA["parse"]["text"]["*"])

PHP

<?php/*    parse.php    MediaWiki API Demos    Demo of `Parse` module: Parse content of a page    MIT License*/$endPoint="https://en.wikipedia.org/w/api.php";$params=["action"=>"parse","page"=>"Pet door","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);echo($result["parse"]["text"]["*"]);

JavaScript

/** * parse.js * * MediaWiki API Demos * Demo of `Parse` module: Parse content of a page * * MIT License */consturl="https://en.wikipedia.org/w/api.php?"+newURLSearchParams({origin:"*",action:"parse",page:"Pet door",format:"json",});try{constreq=awaitfetch(url);constjson=awaitreq.json();console.log(json.parse.text["*"]);}catch(e){console.error(e);}

MediaWiki JS

/** * parse.js * * MediaWiki API Demos * Demo of `Parse` module: Parse content of a page * MIT License */constparams={action:'parse',page:'Pet door',format:'json'};constapi=newmw.Api();api.get(params).done(data=>{console.log(data.parse.text['*']);});

مثال 2: إعراب فقرة من صفحة برمجيًا وجلب بيانات جدولها

طلب GET

api.php?action=parse&page=Wikipedia:Unusual_articles/Places_and_infrastructure&prop=wikitext&section=5&format=json [جربها في ApiSandbox]

النتيجة

النتيجة
{"parse":{"title":"Wikipedia:Unusual articles/Places and infrastructure","pageid":38664530,"wikitext":{"*":"===Antarctica===\n<!--[[File:Grytviken church.jpg|thumb|150px|right|A little church in [[Grytviken]] in the [[Religion in Antarctica|Antarctic]].]]-->\n{| class=\"wikitable\"\n|-\n| '''[[Emilio Palma]]'''\n| An Argentine national who is the first person known to be born on the continent of Antarctica.\n|-\n| '''[[Scouting in the Antarctic]]'''\n| Always be prepared for glaciers and penguins.\n|}"}}}

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

parse_wikitable.py
#!/usr/bin/python3"""    parse_wikitable.py    MediaWiki Action API Code Samples    Demo of `Parse` module: Parse a section of a page, fetch its table data and save    it to a CSV file    MIT license"""importcsvimportrequestsS=requests.Session()URL="https://en.wikipedia.org/w/api.php"TITLE="Wikipedia:Unusual_articles/Places_and_infrastructure"PARAMS={'action':"parse",'page':TITLE,'prop':'wikitext','section':5,'format':"json"}defget_table():""" Parse a section of a page, fetch its table data and save it to a CSV file    """res=S.get(url=URL,params=PARAMS)data=res.json()wikitext=data['parse']['wikitext']['*']lines=wikitext.split('|-')entries=[]forlineinlines:line=line.strip()ifline.startswith("|"):table=line[2:].split('||')entry=table[0].split("|")[0].strip("'''[[]]\n"),table[0].split("|")[1].strip("\n")entries.append(entry)file=open("places_and_infrastructure.csv","w")writer=csv.writer(file)writer.writerows(entries)file.close()if__name__=='__main__':get_table()

الأخطاء المحتملة

الكودمعلومات
missingtitleالصفحة التي حددتها غير موجودة.
nosuchsectionلا يوجد قسمقسم/فقرة فيصفحة.
pagecannotexistالنطاق لا يسمح بالصفحات الفعلية.
invalidparammix
  • لا يمكن استخدام الوسائطpage,pageid,oldid,text معا.
  • لا يمكن استخدام الوسائطpage,pageid,oldid,title معا.
  • لا يمكن استخدام الوسائطpage,pageid,oldid,revid معا.


تاريخ المعاملات

  • v1.38: إضافةshowstrategykeys
  • v1.32: ‏disabletidy متقادم
  • v1.31: إضافةdisablestylededuplication
  • v1.30: إضافةrevid,useskin,wrapoutputclass

انظر أيضا

Retrieved from "https://www.mediawiki.org/w/index.php?title=API:Parsing_wikitext/ar&oldid=6735699"
Category:

[8]ページ先頭

©2009-2025 Movatter.jp