{"id":15134576,"url":"https://github.com/wiki-connect/parsewiki","last_synced_at":"2026-02-04T07:36:37.936Z","repository":{"id":203126168,"uuid":"708885254","full_name":"wiki-connect/ParseWiki","owner":"wiki-connect","description":"A library that helps parse wikitext data","archived":false,"fork":false,"pushed_at":"2023-12-18T23:06:47.000Z","size":29,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-05T22:45:01.733Z","etag":null,"topics":["mediawiki","parser","wikipedia","wikitext","wikitext-parser"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wiki-connect.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-23T15:23:10.000Z","updated_at":"2023-12-22T19:35:42.000Z","dependencies_parsed_at":"2023-12-19T01:47:06.793Z","dependency_job_id":"c20bb8bf-aaff-48c1-8d23-8ad6922ce3da","html_url":"https://github.com/wiki-connect/ParseWiki","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"94a48e5e249ef0c6e7c7e38684239b9b964f1000"},"previous_names":["gergesshamon/parsewiki","wiki-connect/parsewiki"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiki-connect%2FParseWiki","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiki-connect%2FParseWiki/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiki-connect%2FParseWiki/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiki-connect%2FParseWiki/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wiki-connect","download_url":"https://codeload.github.com/wiki-connect/ParseWiki/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247411194,"owners_count":20934650,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mediawiki","parser","wikipedia","wikitext","wikitext-parser"],"created_at":"2024-09-26T05:23:04.177Z","updated_at":"2026-02-04T07:36:37.909Z","avatar_url":"https://github.com/wiki-connect.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WikiConnect ParseWiki\n\nA powerful PHP library for parsing MediaWiki-style content from raw wiki text.\n\n---\n\n## 📚 Overview\n\nThis library allows you to extract:\n- Templates (single, multiple, nested)\n- Internal wiki links\n- External links\n- Citations (references)\n- Categories (with or without display text)\nPerfect for handling wiki-formatted text in PHP projects.\n\n---\n\n## 🗂️ Project Structure\n\n- `ParserTemplates`: Parses multiple templates.\n- `ParserTemplate`: Parses a single template.\n- `ParserInternalLinks`: Parses internal wiki links.\n- `ParserExternalLinks`: Parses external links.\n- `ParserCitations`: Parses citations and references.\n- `ParserCategories`: Parses categories from wiki text.\n- `DataModel` classes:\n  - `Attribute`\n  - `Citation`\n  - `ExternalLink`\n  - `InternalLink`\n  - `Parameters`\n  - `Template`\n- `tests/`: Contains PHPUnit test files:\n  - `ParserCategoriesTest`\n  - `ParserCitationsTest`\n  - `ParserExternalLinksTest`\n  - `ParserInternalLinksTest`\n  - `ParserTemplatesTest`\n  - `ParserTemplateTest`\n  - `DataModel` tests:\n    - `AttributeTest`\n    - `ParametersTest`\n    - `TemplateTest`\n---\n\n## 🚀 Features\n\n- ✅ Parse single and multiple templates.\n- ✅ Support nested templates.\n- ✅ Handle named and unnamed template parameters.\n- ✅ Extract internal links with or without display text.\n- ✅ Extract external links with or without labels.\n- ✅ Parse citations including attributes and special characters.\n- ✅ Parse categories, support custom namespaces, handle whitespaces and special characters.\n- ✅ Full PHPUnit test coverage.\n\n---\n## 🧩 Wikitext Features Support\n\n| Feature                    | Read ✅ | Modify ✏️ | Replace 🔄 |\n|--------------------------- |---------|------------|------------|\n| **Templates**              | ✅ Yes  | ✅ Yes    | ✅ Yes     |\n| **Parameters**             | ✅ Yes  | ✅ Yes    | ✅ Yes     |\n| **Citations**              | ✅ Yes  | ✅ Yes    | ✅ Yes     |\n| **Citations\u003eAttributes**   | ✅ Yes  | ✅ Yes    | ✅ Yes     |\n| **Internal Links**         | ✅ Yes  |     |      |\n| **External Links**         | ✅ Yes  |     |      |\n| **Categories**             | ✅ Yes  |      |       |\n| **HTML Tags**              |   |     |      |\n| **Parser Functions**       |   |   |       |\n| **Tables**                 |   |      |       |\n| **Sections**               |   |      |       |\n| **Magic Words**            |   |      |       |\n\n\u003e 🟡 **Note:** Some features are partially supported or under development. Contributions are welcome!\n\n---\n\n## ⚙️ Requirements\n\n- PHP 8.0 or higher\n- PHPUnit 9 or higher\n\n---\n\n## 💻 Installation\n\n```bash\ncomposer require wiki-connect/parsewiki\n```\n\nMake sure you have proper PSR-4 autoloading for the `WikiConnect\\ParseWiki` namespace.\n\n---\n\n## 🧪 Running Tests\n\n```bash\nvendor/bin/phpunit tests\n```\n\n### Test Coverage:\n- **Templates:** Single, multiple, nested, named/unnamed parameters.\n- **Internal Links:** Simple, with display text, special characters.\n- **External Links:** With/without labels, multiple links, whitespace handling.\n- **Citations:** With/without attributes, special characters.\n- **Categories:** Simple, with display text, custom namespaces, whitespaces, special characters.\n\n---\n\n## ✨ Example Usage\n\n### Parsing Templates\n\n```php\nuse WikiConnect\\ParseWiki\\ParserTemplates;\n\n$text = '{{Infobox person|name=John Doe|birth_date=1990-01-01}}';\n\n$parser = new ParserTemplates($text);\n$templates = $parser-\u003egetTemplates();\n\nforeach ($templates as $template) {\n    echo $template-\u003egetName();\n    print_r($template-\u003egetParameters());\n}\n```\n### Parsing and Editing a single Template\n\n```php\nuse WikiConnect\\ParseWiki\\ParserTemplate;\n\n$text = '{{Infobox_Person|name=John Doe|birth_date=1990-01-01}}';\n\n$parser = new ParserTemplate($text);\n$template = $parser-\u003egetTemplate();\n\n// Edit the template\n$template-\u003esetName('Infobox person');\n$template-\u003eparameters-\u003eset('birth_place', '[[New York City|New York]]');\n\n$new_template = $template-\u003etoString();\necho $new_template; // {{Infobox person|name=John Doe|birth_date=1990-01-01|birth_place=[[New York City|New York]]}\n\n```\n\n### Parsing Internal Links\n\n```php\nuse WikiConnect\\ParseWiki\\ParserInternalLinks;\n\n$text = 'See [[Main Page|the main page]] and [[Help]].';\n\n$parser = new ParserInternalLinks($text);\n$links = $parser-\u003egetTargets();\n\nforeach ($links as $link) {\n    echo 'Target: ' . $link-\u003egetTarget() . PHP_EOL;\n    echo 'Text: ' . ($link-\u003egetText() ?? $link-\u003egetTarget()) . PHP_EOL;\n}\n```\n\n### Parsing External Links\n\n```php\nuse WikiConnect\\ParseWiki\\ParserExternalLinks;\n\n$text = 'Visit [https://example.com Example Site] and [https://nolabel.com].';\n\n$parser = new ParserExternalLinks($text);\n$links = $parser-\u003egetLinks();\n\nforeach ($links as $link) {\n    echo 'URL: ' . $link-\u003egetLink() . PHP_EOL;\n    echo 'Label: ' . ($link-\u003egetText() ?: 'No label') . PHP_EOL;\n}\n```\n\n### Parsing Citations\n\n```php\nuse WikiConnect\\ParseWiki\\ParserCitations;\n\n$text = 'Some text with a citation.\u003cref name=\"source\"\u003eThis is a citation\u003c/ref\u003e';\n\n$parser = new ParserCitations($text);\n$citations = $parser-\u003egetCitations();\n\nforeach ($citations as $citation) {\n    echo 'Content: ' . $citation-\u003egetContent() . PHP_EOL;\n    echo 'Attributes: ' . $citation-\u003egetAttributes() . PHP_EOL;\n}\n```\n\n### Parsing Categories\n\n```php\nuse WikiConnect\\ParseWiki\\ParserCategories;\n\n$text = 'Some text [[Category:Science]] and [[Category:Math|Displayed]].';\n\n$parser = new ParserCategories($text);\n$categories = $parser-\u003egetCategories();\n\nforeach ($categories as $category) {\n    echo 'Category: ' . $category . PHP_EOL;\n}\n```\n\n---\n\n## 🙌 Author\n\nDeveloped with ❤️ by Gerges.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiki-connect%2Fparsewiki","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwiki-connect%2Fparsewiki","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiki-connect%2Fparsewiki/lists"}