شعار Wikimedia Wikitext

Wikimedia Wikitext

المجتمع
fuzheado
wikimedia-wikitext

Parse, extract, and manipulate Wikipedia and MediaWiki wikitext (wiki markup, templates, infoboxes, citations, links) using proper AST-based tooling instead of fragile regex patterns

نظرة عامة

الناشرfuzheado
المستودعWikipedia-AI-Skills
اسم المهارةwikimedia-wikitext
النجوم
27
التفريعات
10
الملفات المرفقة
8
الترخيصMIT
الروابط
  • تعليمات بصيغة Markdown

    ملف SKILL.md يُحمّله النموذج عند الحاجة، فلا يستهلك توكنات إلا عندما يَرِد طلب ذو صلة فعلًا.

  • تعمل مع أي نموذج لغوي كبير

    مهارات الذكاء الاصطناعي مكتوبة بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا تعمل مع GPT أو Claude أو Gemini أو Grok أو نموذج محلي.

  • الملفات المرفقة: 8

    نصوص برمجية وقوالب ومراجع يمكن للنموذج قراءتها أثناء عمله. الملفات للقراءة فقط ولا تُنفّذ أبدًا.

  • مفتوحة المصدر

    نشرها fuzheado على GitHub. اطّلع على المصدر قبل تثبيتها.

التثبيت

ثبّت مهارة الذكاء الاصطناعي Wikimedia Wikitext في TypingMind لاستخدامها مع أي نموذج لغوي كبير، أو أضفها إلى وكيل ذكاء اصطناعي آخر يقرأ SKILL.md.

1

التثبيت في TypingMind

يُثبّت TypingMind المهارة مباشرةً من مجلدها على GitHub — فيقرأ SKILL.md، ويجمع ملفات الموارد في حزمة، ويحفظ النتيجة محليًا.

  1. افتح التطبيق وانتقل إلى «الإضافات» ثم «المهارات».
  2. اختر «تثبيت من GitHub».
  3. الصق رابط مجلد المهارة الموضّح أدناه وأكّد التثبيت.
    https://github.com/fuzheado/Wikipedia-AI-Skills/tree/main/.claude/skills/wikimedia-wikitext
  4. فعّل المهارة في كل محادثة تريد إتاحتها فيها.
الإضافات ← المهارات ← إضافة مهارة ← من رابط GitHub، ثم الصق رابط المجلد واضغط على «متابعة».
2

التثبيت في وكيل ذكاء اصطناعي آخر

يمكن لأي وكيل ذكاء اصطناعي يقرأ تنسيق Agent Skills استخدام هذه المهارة — انسخ المجلد إلى مجلد المهارات الخاص بذلك الوكيل.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/fuzheado/Wikipedia-AI-Skills.git /tmp/Wikipedia-AI-Skills
mkdir -p .claude/skills
cp -r /tmp/Wikipedia-AI-Skills/.claude/skills/wikimedia-wikitext .claude/skills/wikimedia-wikitext
أعد تشغيل Claude Code بعد النسخ ليتعرّف على المهارة الجديدة.

استخدمها في TypingMind

فعّل Wikimedia Wikitext في أي محادثة على TypingMind وسيتولى النموذج الباقي. تتضمن مطالبة النظام اسمها ووصفها، وبمجرد ورود طلب ذي صلة، يُحمّل النموذج التعليمات الكاملة تلقائيًا — فلا تحتاج إلى استدعائها يدويًا، ولا تستهلك أي توكنات حتى تُستخدم فعليًا.

يُحمّل النموذج مهارة Wikimedia Wikitext تلقائيًا بمجرد ورود طلب ذي صلة بها.

تعمل مع أي نموذج ذكاء اصطناعي

مهارات الذكاء الاصطناعي هي تعليمات بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا لا ترتبط Wikimedia Wikitext بالنموذج الذي كُتبت له. ثبّتها مرة واحدة في TypingMind واستخدمها مع GPT-5 أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو نموذج محلي تشغّله بنفسك — كل ذلك باستخدام مفاتيح API الخاصة بك.

  • تُحمَّل عند الحاجة فقط

    تتضمن مطالبة النظام الاسم والوصف فقط. وتُجلب التعليمات عند أول طلب ذي صلة، لذا لا تستهلك تعليمات المهارة أي توكنات ما دامت المهارة غير مستخدمة.

  • بدّل النماذج أثناء المحادثة

    لأن المهارة تعليمات وليست شيفرة، فإن تغيير النموذج لا يعطّلها — فالنموذج التالي يقرأ ملف SKILL.md نفسه.

تعليمات المهارة

هذا هو محتوى SKILL.md الذي يُحمّله النموذج. اقرأه قبل التثبيت — فالمهارة عبارة عن تعليمات سيتبعها نموذجك.

⚠️ User-Agent required: The API examples below use the Action API and REST API. All requests must include a descriptive User-Agent header or they will be blocked. See the wikimedia-api-access skill for the correct format.

SOP: The Two Strategies

There are two fundamentally different approaches to reading and extracting data from MediaWiki wikitext. Choose based on whether you need to write back wikitext changes.

StrategyWhen to useTool
AST ParsingYou need to modify wikitext or extract structured data from raw markupmwparserfromhell
Parsoid HTMLYou only need to read page content as structured text/dataMediaWiki REST API (/html endpoint) + BeautifulSoup/lxml

Never mix the two — do not parse Parsoid HTML to reconstruct wikitext, and do not use regex on raw wikitext to extract data.


SOP: AST Parsing with mwparserfromhell

Wikitext is non-regular, context-dependent, and recursive (templates inside templates inside image captions). Never use regex to parse wikitext structures like templates, tables, or links. Always use mwparserfromhell, an LL(1)-based parser that builds a proper Abstract Syntax Tree (AST).

Installation

bash
pip install mwparserfromhell

Safe Template Extraction

python
import mwparserfromhell

wikitext = "[[File:Example.jpg|thumb|{{Location|40|-74}}]] Text with {{Template|param=value|nested={{Value}}}}."
code = mwparserfromhell.parse(wikitext)

for template in code.filter_templates():
    if template.name.matches("Template"):
        param = template.get("param").value
        print(f"Found param: {param}")

Mutating Wikitext

python
import mwparserfromhell

code = mwparserfromhell.parse(wikitext)
for template in code.filter_templates():
    if template.name.matches("Infobox"):
        template.add("image", "new_image.jpg")

updated_wikitext = str(code)

Stripping Markup to Plain Text

python
code = mwparserfromhell.parse(wikitext)
plain_text = code.strip_code()  # Removes templates, comments, wikilinks, etc.

⚠️ strip_code() removes:

  • HTML comments (<!-- ... -->)
  • Templates (replaced with their rendered output if available, else stripped)
  • Wiki markup formatting

strip_code() preserves:

  • Plain text content
  • External URLs

⚠️ Template payloads are the trap (verified 2026-10-09). Text wrapped for language or formatting — {{en|1=Text}}, {{Langswitch|en=…}}, {{nowrap|…}} — is not "plain content" to a stripper: a pass that drops everything between {{ and }} blanks the text entirely and leaves an empty string, which then reads like a page with nothing to say rather than a parser failure. Resolve the payload of language/formatting templates ({{en|1=X}} → X), and fall back to the labels of any wikilinks when a payload cannot be read.

Measured on a 30,032-note corpus: fixing this moved an agreement rate from 4.1% → 4.2% and resolved links from 2,879 → 2,990. Small corrections to an aggregate — but the same bug emptied individual notes, and an empty note counts as "no evidence" in every downstream number, so the error is silent by construction.

Use str(code) when you need the raw wikitext with all markup intact.

Filtering Specific Node Types

python
# All templates
code.filter_templates()

# All wikilinks ([[...]])
code.filter_wikilinks()

# All external links ([...])
code.filter_external_links()

# All tags (<ref>, <nowiki>, etc.)
code.filter_tags()

# All headings
code.filter_headings()

# Filter by name pattern
code.filter_templates(matches=lambda name: name.startswith("Infobox"))

Parameter Access Patterns

python
template = code.filter_templates(matches="Infobox person")[0]

# Safe access with default
name = template.get("name").value
# raises ValueError if param doesn't exist

# Check existence first
if template.has("birth_date"):
    bd = template.get("birth_date").value

# Get all parameters
for param in template.params:
    print(f"{param.name}: {param.value}")

# Add or update a parameter
template.add("new_param", "value")
template.add("existing_param", "new_value")  # Replaces if exists

SOP: Parsoid HTML Strategy (Read-Only)

If you do not need to write back wikitext changes, do not parse wikitext at all. Use the MediaWiki Core REST API's /html endpoint, which returns clean, semantic HTML5/RDFa generated by Parsoid (natively embedded in MediaWiki — the standalone JS version is obsolete).

Fetching Page HTML

python
import requests

url = "https://en.wikipedia.org/w/rest.php/v1/page/Python_(programming_language)/html"
headers = {"User-Agent": "MyTool/1.0 (user@example.com)"}

response = requests.get(url, headers=headers, timeout=30)
if response.status_code == 200:
    html = response.text
    # Parse with BeautifulSoup or lxml

Extracting Tables as DataFrames

Wikitext tables ({| ... |}) contain deep edge cases (implicit row spans, embedded CSS). Never parse them manually.

python
import pandas as pd
from bs4 import BeautifulSoup

soup = BeautifulSoup(html, "html.parser")
tables = pd.read_html(str(soup))  # pandas handles HTML tables natively

for i, df in enumerate(tables):
    print(f"Table {i}: {df.shape[0]} rows × {df.shape[1]} columns")

Extracting Section Content

python
soup = BeautifulSoup(html, "html.parser")
for section in soup.find_all(["h1", "h2", "h3", "h4", "h5", "h6"]):
    heading = section.get_text(strip=True)
    # Next siblings until the next heading are this section's content

SOP: Anti-Patterns to Avoid

❌ Anti-PatternWhy It Breaks✅ Correct Approach
r'\{\{Infobox(.*?)\}\}' for template paramsBreaks on nested templates, multi-line params, pipes in wikilinksmwparserfromhell.filter_templates()
Splitting on `` to get table cellsPipes inside wikilinks `[[a
r'\[\[(.*?)\]\]' for wikilinksMisses piped links, interwiki links, category links, file linksmwparserfromhell.filter_wikilinks()
r'<ref>(.*?)</ref>' for referencesMisses self-closing <ref name="x" />, multi-line refs, nested refsmwparserfromhell.filter_tags()
Manually stripping HTML from Parsoid outputFragile — Parsoid's HTML structure may change across MediaWiki versionsBeautifulSoup/lxml with semantic selectors
Dropping every {{…}} to "remove templates"Blanks `{{en1=Text}}, {{Langswitch

SOP: Troubleshooting Edge Cases

Complex Tables

Fetch via /html endpoint and pass to pandas.read_html(). Do not manually chunk {| and |} tokens.

Invisible/Stripped Content

mwparserfromhell.strip_code() removes HTML comments and template markup. Use code.get_sections() if you need to preserve section structure, or str(code) for raw wikitext.

Nested Templates

mwparserfromhell handles arbitrary nesting depth — let the parser do the work:

python
code = mwparserfromhell.parse("{{Outer|{{Inner|param={{Deepest|value}}}}}}")
for t in code.filter_templates():
    print(t.name)  # Correctly identifies all three templates

Unicode and Special Characters

Wikitext may contain non-ASCII characters, HTML entities (&amp;, &lt;), and magic words. mwparserfromhell handles these correctly; regex approaches will not.

⚠️ Gallery images are NOT wikilinks (verified 2026-08-18)

Inside {{gallery|File:X.jpg|caption|File:Y.jpg|caption}} templates, file names are plain-text template parameters, not [[File:...]] wikilinks. mwparserfromhell correctly reports them as Text nodes — so code.filter_wikilinks() will NOT find gallery images. If you need the set of images actually rendered in an article, use the Parsoid REST endpoint (GET /w/rest.php/v1/page/<title>/html) and select semantic elements: <figure> + <figcaption> for standard thumbnails, <li class="gallerybox"> + <div class="gallerytext"> for <gallery> items. This also excludes navbox icons and other template chrome that prop=images would include. Chapters can be assigned in the same walk: each figure/gallerybox belongs to the nearest preceding <h2> (Parsoid emits plain <h2> elements in document order).

⚠️ Parsoid hrefs are relative (verified 2026-08-18)

The Parsoid REST /html endpoint emits relative file links: <a href="./File:Name.jpg"> (not /wiki/File:Name.jpg), and the <img> resource attribute also uses ./File:. Handle all three forms: re.search(r"(?:\./|/wiki/)?(File|Image):(.*)$", href).


Tooling

This skill includes helper scripts, reference docs, and templates:

🔧 Wikitext Inspector (scripts/test-mwparser.sh)

Inspect any wikitext file and get a structured overview of what's in it — templates, wikilinks, tags, headings, sections, and potential issues. It also doubles as an installation smoke test when called with --smoke.

bash
# Smoke test (--smoke) — verify installation
./scripts/test-mwparser.sh --smoke

# Inspect a wikitext file
./scripts/test-mwparser.sh page.wikitext

# Pipe mode — inspect wikitext from stdin
curl -s "https://en.wikipedia.org/w/index.php?title=Python_(programming_language)&action=raw" \
  | ./test-mwparser.sh -

# Usage: ./test-mwparser.sh [--smoke | file.wikitext | -]
#   --smoke        — run installation smoke test
#   file.wikitext  — parse file and report structure
#   -              — read wikitext from stdin (pipe mode)
#   (no args)      — print usage and exit 2

Reports: total AST nodes, templates with parameter previews, wikilinks with display text, tags, headings (section outline), plain text length, and potential issues (e.g., empty file, very large pages).

🔧 Parsoid HTML Fetcher (scripts/fetch-parsoid-html.sh)

Fetch a Wikipedia page as clean Parsoid HTML and save to a file.

bash
# Fetch page HTML
./scripts/fetch-parsoid-html.sh "Python (programming language)"

# Fetch into a specific output file
./scripts/fetch-parsoid-html.sh "Albert Einstein" albert.html

📚 mwparserfromhell Reference (references/mwparserfromhell-guide.md)

Complete reference covering:

  • All node types and filter methods
  • Template parameter manipulation
  • Section and heading handling
  • Tag and comment handling
  • Common patterns for infoboxes, citations, lists
  • Performance considerations for large pages

📚 Parsoid HTML API Reference (references/parsoid-html-api.md)

Complete guide to the MediaWiki REST API /html endpoint:

  • Endpoint structure and parameters
  • Content negotiation (JSON vs HTML)
  • If-None-Match / ETag caching
  • Section-only retrieval
  • Handling revisions vs latest
  • Error response guide

📚 Wikitext Pitfalls (references/wikitext-pitfalls.md)

Deep reference of documented edge cases:

  • Table syntax gotchas (implicit row/colspan, multi-line cells)
  • Template argument separation (pipes in different contexts)
  • Comment placement affecting template parsing
  • Tag extension boundaries (, , )
  • Unicode normalization issues
  • Parser function intricacies
  • Behavior of strip_code() with various markup types

🐍 Wikitext Parser Template (assets/parse-wikitext.py)

Ready-to-use Python script with:

  • Template extraction and parameter manipulation
  • Wikilink and external link extraction
  • Section splitting and plain-text conversion
  • Infobox data extraction
  • Citation list extraction
  • Multi-file batch processing
bash
# Extract all templates from a wikitext file
python3 assets/parse-wikitext.py page.wikitext --templates

# Extract all internal links
python3 assets/parse-wikitext.py page.wikitext --links

# Convert to plain text
python3 assets/parse-wikitext.py page.wikitext --plaintext

🐍 Parsoid Extractor Template (assets/parsoid-extractor.py)

Ready-to-use Python script for the HTML DOM strategy:

bash
# Fetch a page and extract tables as CSV
python3 assets/parsoid-extractor.py "Python (programming language)" --tables

# Extract section text
python3 assets/parsoid-extractor.py "Albert Einstein" --sections

# Extract infobox data from rendered HTML
python3 assets/parsoid-extractor.py "Berlin" --infobox

🧩 Table to DataFrame Template (assets/table-extractor.py)

Example script for converting wikitext tables to pandas DataFrames via the Parsoid HTML pipeline, with CSV/JSON export.


Cross-References

Related SkillWhy
wikimedia-api-accessUser-Agent and API patterns — the foundation all API calls build on
wikimedia-api-strategyChoosing how to read a page: REST /page/summary vs TextExtracts vs Parsoid HTML — decision matrix + fidelity-test pattern in references/lead-text-extraction.md
wikipedia-templatesTemplate syntax — mwparserfromhell is the primary parsing tool
wikipedia-wikitablesTable parsing — always use Parsoid HTML + pandas.read_html(), never regex
wikipedia-citationsCitation/reference extraction from wikitext
wikipedia-page-anatomyPage structure — sections, infoboxes, navboxes parsed from wikitext
pywikibotBot framework — uses mwparserfromhell for template manipulation
wiktionaryDictionary entry structure and AST-based parsing of translation tables
wikisourceProofread page text extraction, Page:/Index: namespaces, transclusion
wikivoyageWikivoyage listing templates ({{see}}, {{eat}}, etc.) are structured wikitext templates parsed with mwparserfromhell

الملفات المرفقة

يقرأ النموذج هذه الملفات عند الحاجة ما دامت المهارة محمّلة. وهي متاحة للقراءة ولا تُنفّذ أبدًا.

الأسئلة الشائعة

ماذا تفعل مهارة الذكاء الاصطناعي Wikimedia Wikitext؟

Parse, extract, and manipulate Wikipedia and MediaWiki wikitext (wiki markup, templates, infoboxes, citations, links) using proper AST-based tooling instead of fragile regex patterns

لماذا تستخدم Wikimedia Wikitext على TypingMind؟

لأنك تثبّتها مرة واحدة وتستخدمها مع أي نموذج. مهارة Wikimedia Wikitext عبارة عن نص Markdown وليست شيفرة خاصة بمزود بعينه، لذا تعمل المهارة نفسها مع GPT-5 أو Claude أو Gemini أو Grok أو نموذج محلي، ويمكنك تبديل النموذج أثناء المحادثة دون تعطّل المهارة. يعمل TypingMind بمفاتيح API الخاصة بك، فتدفع للمزودين مباشرةً بدلًا من اشتراك لكل مقعد، وتبقى مهاراتك ومحادثاتك في مساحة التخزين الخاصة بك.

كيف أثبّت Wikimedia Wikitext في TypingMind؟

في TypingMind، افتح «الإضافات»، ثم «المهارات»، ثم اختر «التثبيت من GitHub» والصق https://github.com/fuzheado/Wikipedia-AI-Skills/tree/main/.claude/skills/wikimedia-wikitext. يقرأ TypingMind ملف SKILL.md الخاص بالمهارة، ويجمع ملفاتها ويثبّتها كمهارة يمكنك تفعيلها لكل محادثة على حدة.

ما نماذج الذكاء الاصطناعي التي يمكنها استخدام Wikimedia Wikitext؟

أي نموذج تربطه في TypingMind. مهارات الذكاء الاصطناعي عبارة عن تعليمات Markdown وليست شيفرة خاصة بمزود بعينه، لذا يمكن لكل من GPT وClaude وGemini وGrok والنماذج المحلية تحميل هذه المهارة عندما يتوافق الطلب معها.

كم نموذج ذكاء اصطناعي يمكنني استخدامه مع Wikimedia Wikitext؟

أي عدد تريده. ما دام النموذج يدعم المهارات، يمكنك استخدام Wikimedia Wikitext معه، سواء كان GPT أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو غيرها، وكل ذلك على TypingMind باستخدام مفاتيح API الخاصة بك.

هل مهارة الذكاء الاصطناعي Wikimedia Wikitext مجانية؟

نعم. نشرها fuzheado على GitHub بموجب ترخيص MIT. لا تدفع إلا لمزود الذكاء الاصطناعي الخاص بك مقابل التوكنات التي تستخدمها.

ما هي مهارات الذكاء الاصطناعي؟

مهارة الذكاء الاصطناعي حزمة تعليمات قابلة لإعادة الاستخدام تعلّم نموذج الذكاء الاصطناعي كيفية تنفيذ مهمة محددة. وتتبع تنسيق Agent Skills المفتوح: ملف SKILL.md يتضمن اسمًا ووصفًا، إلى جانب أي نصوص برمجية أو قوالب أو ملفات مرجعية قد يحتاج إليها النموذج. لا يقرأ النموذج التعليمات إلا عندما يتوافق طلبك مع المهارة، لذا لا تترتب على المهارة المثبتة أي تكلفة حتى تُستخدم.

كيف تختلف مهارات الذكاء الاصطناعي عن الإضافات أو موصلات MCP؟

تمنح الإضافة أو موصل MCP النموذج أدوات جديدة يمكنه استدعاؤها، وهي شيفرة تُنفَّذ في مكان ما وتُرجع نتيجة. أما مهارة الذكاء الاصطناعي فتزوّد النموذج بالمعرفة ومنهجية العمل: كيفية التعامل مع مهمة، والخطوات التي ينبغي اتباعها، وما ينبغي أن تكون عليه المخرجات الجيدة. المهارات عبارة عن نصوص Markdown، لذا لا تحتاج إلى خادم أو مفتاح API أو بيئة تشغيل، وتعمل مع أي نموذج.

عرض الكل

أنشئ مساحة عملك للذكاء الاصطناعي الآن

اشترك في نشرتنا الإخبارية لتصلك أخبار الميزات الجديدة والهدايا القادمة 👇