Metadata-Version: 2.1
Name: mwtp
Version: 2.3.2
Summary: A parser for MediaWiki titles
Author-email: NDKDD <adhominem259@gmail.com>
License: GPL-3.0-only
Project-URL: Homepage, https://github.com/NguoiDungKhongDinhDanh/mwtp
Project-URL: Bug tracker, https://github.com/NguoiDungKhongDinhDanh/mwtp/issues
Project-URL: Documentation, https://mwtp.readthedocs.io/
Keywords: mediawiki,title,page name,parser
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Operating System :: Microsoft :: Windows
Classifier: Topic :: Software Development :: Build Tools
Classifier: License :: OSI Approved :: GNU General Public License (GPL)
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: build ~=1.0.3 ; extra == 'dev'
Requires-Dist: mypy ~=1.4.1 ; extra == 'dev'
Requires-Dist: pytest ~=7.4.0 ; extra == 'dev'
Requires-Dist: pytest-cov ~=4.1.0 ; extra == 'dev'
Requires-Dist: setuptools ~=67.6.1 ; extra == 'dev'
Requires-Dist: tox ~=4.6.4 ; extra == 'dev'

# MediaWikiTitleParser

![Documentation status](https://readthedocs.org/projects/mwtp/badge/?version=latest)
![Tests](https://github.com/NguoiDungKhongDinhDanh/mwtp/actions/workflows/tests.yaml/badge.svg)
![License](https://img.shields.io/pypi/l/mwtp.svg)
![Supported versions](https://img.shields.io/pypi/pyversions/mwtp.svg)

MWTP is a parser for MediaWiki titles. Its logic is partly derived from
[mediawiki.Title][1], and hence is licensed under GNU GPL.

It works as simple as follows:

```python
from mwtp import TitleParser as Parser


parser = Parser(namespaces_data, namespace_aliases)
title = parser.parse(' _ FoO: this/is A__/talk page _ ')

print(repr(title))
# Title('Thảo luận:This/is A /talk page')
```

`namespaces_data` and `namespace_aliases` can be obtained by
making a query to [a wiki's API][2] with
`action=query&meta=siteinfo&siprop=namespaces|namespacealiases`:

```python
namespaces_data = {
  '0': { 'id': 0, 'case': 'first-letter', 'name': '',          ...: ... },
  '1': { 'id': 1, 'case': 'first-letter', 'name': 'Thảo luận', ...: ... },
  ...: ...
}
```

```python
namespace_aliases = [
  { 'id': 1, 'alias': 'Foo' },
  ...
]
```

Note that the following format (`&formatversion=1`) is not supported.
Always use `&formatversion=2` or `&formatversion=latest`.

```python
namespaces_data = {
  '0': { 'id': 0, 'case': 'first-letter', '*': '',          ...: ... },
  '1': { 'id': 1, 'case': 'first-letter', '*': 'Thảo luận', ...: ... },
  ...: ...
}
namespace_aliases = [
  { 'id': 1, '*': 'Foo' },
  ...
]
```

For more information, see [the documentation][3].


[1]: https://github.com/wikimedia/mediawiki/tree/c237f0548845662759bfcc6419cec9ca02d03c18/resources/src/mediawiki.Title
[2]: https://www.mediawiki.org/wiki/Special:ApiSandbox#action=query&meta=siteinfo&siprop=namespaces%7Cnamespacealiases
[3]: https://mwtp.readthedocs.io/
