wiki-connect / parsewiki
A library that helps parse wikitext template data
2.0
2025-07-18 22:35 UTC
Requires
- php: >=8.1.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10
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.DataModelclasses:AttributeCitationExternalLinkInternalLinkParametersTemplate
tests/: Contains PHPUnit test files:ParserCategoriesTestParserCitationsTestParserExternalLinksTestParserInternalLinksTestParserTemplatesTestParserTemplateTestDataModeltests:AttributeTestParametersTestTemplateTest
๐ 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
| Feature | Read โ | 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