wiki-connect/parsewiki

A library that helps parse wikitext template data

2.0 2025-07-18 22:35 UTC

This package is auto-updated.

Last update: 2025-07-18 22:46:01 UTC


README

A powerful PHP library for parsing MediaWiki-style content from raw wiki text.

๐Ÿ“š Overview

This library allows you to extract:

  • Templates (single, multiple, nested)
  • Internal wiki links
  • External links
  • Citations (references)
  • Categories (with or without display text) Perfect for handling wiki-formatted text in PHP projects.

๐Ÿ—‚๏ธ Project Structure

  • ParserTemplates: Parses multiple templates.
  • ParserTemplate: Parses a single template.
  • ParserInternalLinks: Parses internal wiki links.
  • ParserExternalLinks: Parses external links.
  • ParserCitations: Parses citations and references.
  • ParserCategories: Parses categories from wiki text.
  • DataModel classes:
    • Attribute
    • Citation
    • ExternalLink
    • InternalLink
    • Parameters
    • Template
  • tests/: Contains PHPUnit test files:
    • ParserCategoriesTest
    • ParserCitationsTest
    • ParserExternalLinksTest
    • ParserInternalLinksTest
    • ParserTemplatesTest
    • ParserTemplateTest
    • DataModel tests:
      • AttributeTest
      • ParametersTest
      • TemplateTest

๐Ÿš€ Features

  • โœ… Parse single and multiple templates.
  • โœ… Support nested templates.
  • โœ… Handle named and unnamed template parameters.
  • โœ… Extract internal links with or without display text.
  • โœ… Extract external links with or without labels.
  • โœ… Parse citations including attributes and special characters.
  • โœ… Parse categories, support custom namespaces, handle whitespaces and special characters.
  • โœ… Full PHPUnit test coverage.

๐Ÿงฉ Wikitext Features Support

FeatureRead โœ…Modify โœ๏ธReplace ๐Ÿ”„
Templatesโœ… Yesโœ… Yesโœ… Yes
Parametersโœ… Yesโœ… Yesโœ… Yes
Citationsโœ… Yesโœ… Yesโœ… Yes
Citations>Attributesโœ… Yesโœ… Yesโœ… Yes
Internal Linksโœ… Yes
External Linksโœ… Yes
Categoriesโœ… Yes
HTML Tags
Parser Functions
Tables
Sections
Magic Words

๐ŸŸก Note: Some features are partially supported or under development. Contributions are welcome!

โš™๏ธ Requirements

  • PHP 8.0 or higher
  • PHPUnit 9 or higher

๐Ÿ’ป Installation

composer require wiki-connect/parsewiki

Make sure you have proper PSR-4 autoloading for the WikiConnect\ParseWiki namespace.

๐Ÿงช Running Tests

vendor/bin/phpunit tests