Page MenuHomePhabricator

core Page.templates has incompatible API change from compat
Closed, ResolvedPublic

Description

COMPAT:

def templates(self, get_redirect=False):
    """Return a list of titles (unicode) of templates used on this Page.

    Template parameters are ignored.
    """

CORE:

def templates(self, content=False):
    """Return a list of Page objects for templates used on this Page.                                                                                               
    Template parameters are ignored.  This method only returns embedded
    templates, not template pages that happen to be referenced through
    a normal link.
    @param content: if True, retrieve the content of the current version
    of each template (default False)
    """

See Also:
T57256: Page.templates() cache does not respect get_redirect

Event Timeline

bzimport raised the priority of this task from to High.Nov 22 2014, 2:37 AM
bzimport set Reference to bz56188.
bzimport added a subscriber: Unknown Object (????).

Blocker is not really the right term for this ('should be fixed before release'), and calling it 'blocker' will probably screw up WMF's weekly report...

Xqt lowered the priority of this task from High to Low.Jun 4 2018, 4:21 AM
Xqt subscribed.

The only thing here to do is a hint in README-conversion and a warning through compat2core script. Degrease prio after this long time.

In T58188#4252573, @Xqt wrote:

The only thing here to do is a hint in README-conversion and a warning through compat2core script. Degrease prio after this long time.

I don't think so. How to do templates(get_redirect=True) in core easily?

I don't think so. How to do templates(get_redirect=True) in core easily?

t = page.templates()

but for get_redirect=False is is:

t = [] if page.isRedirectPage() else page.templates()

which doesn’t make a lot of sense

In T58188#4253449, @Xqt wrote:

I don't think so. How to do templates(get_redirect=True) in core easily?

t = page.templates()

but for get_redirect=False is is:

t = [] if page.isRedirectPage() else page.templates()

which doesn’t make a lot of sense

I mean what if the template is redirect. Do we have something like: page.templates(redirects_only=True) or opposite page.templates(redirect_targets_only=True)?

Ah, I see, perhaps we could do something like: redirects = [(t if t.isRedirectPage()) for t in page.templates()] or nonredirects = [(t if not t.isRedirectPage()) for t in page.templates()] as currently:

>>> page.templates()
[Page('Template:Template'), Page('Template:TemplateRedirect'), Page('Template:SubTemplate')]
>>> page.templatesWithParams()
[(Page('Template:TemplateRedirect'), ['param1', 'param2'])]
>>> page.raw_extracted_templates
[('TemplateRedirect', OrderedDict([('1', 'param1'), ('2', 'param2')]))]

...and a bunch of extract_templates_and_params methods from textlib

for page.text like: {{TemplateRedirect|param1|param2}}

This seems to me too complicated. I would expect something like:

def templates(self, content=False, params=False, expanded=False,
              template_redirect_targets=False, template_pages=False)
    templates = textlib.extract_templates_and_params(self.text)
    # do some magic
    return templates

@deprecated(Page.templates())
def templatesWithParams()

@deprecated(Page.templates())
def raw_extracted_templates()

or some better defined methods. Who likes to search all the time, what templates are returned by which function and what templates do I need to get:

>>> raw_templates(page)
['A', 'B']
>>> raw_templates_with_params(page)
[('A', [('param1', 'value')]), ('B', [])]
>>> templates(page)
[Page('A'), Page('B')]
>>> templates_with_params(page)
[(Page('A'), [('param1', 'value')]), (Page('B'), [])]
>>> expand_raw_templates(page)
['Ab', 'B', 'B/core']
...
>>> expand_redirected_templates(page)
['Ab', 'B']
...

Change 463660 had a related patch set uploaded (by Dvorapa; owner: Dvorapa):
[pywikibot/core@master] [compat2core] Fix regressions of multiple Page methods

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

Dvorapa raised the priority of this task from Low to Medium.

Change 463660 merged by jenkins-bot:
[pywikibot/core@master] [compat2core] Fix regressions of multiple Page methods

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