Page MenuHomePhabricator

Add documentation to textlib.replace_links
Open, LowPublic

Description

Documentation of textlib.replace_links is insufficient. The behaviour depends in on type (which is not really helpful imho).
e.g.:

>>> import pwb, pywikibot as py
>>> from pywikibot.textlib import replace_links as rl
>>> t = '[[Foo#bar|baz]]'
>>> s = py.Site()
>>> rl(t, ('foo', 'Bar'), s)
u'[[Bar#bar|baz]]'
>>> rl(t, ('foo', py.Page(s, 'Bar')), s)
u'[[Bar#bar|baz]]'
>>> rl(t, ('foo', py.Link('Bar', s)), s)
u'[[Bar]]'

Please provide some samples how to replace links.

Event Timeline

Xqt raised the priority of this task from to Medium.
Xqt updated the task description. (Show Details)
Xqt added a subscriber: Xqt.

Change 491673 had a related patch set uploaded (by Dvorapa; owner: Dvorapa):
[pywikibot/core@master] [IMPR] Fix weirdly broken replace_links

https://gerrit.wikimedia.org/r/491673

Dvorapa lowered the priority of this task from Medium to Low.Feb 20 2019, 3:02 AM
Dvorapa added a subscriber: Dvorapa.

This is normal, but stupid. For Link it gets the data from the Link, for Page and string it gets the data from the old link text. Weird, but fully described in the docs. I will try to find a better way in my patch.

I made Link, Page and also a callback function behave exactly the same, only string gets the data from the old link. I also made docs 100 % clear about this. I will slice the large patch into small portions

Not actively working on it