Page MenuHomePhabricator

relative links on Page
Closed, ResolvedPublic

Description

Originally from: http://sourceforge.net/p/pywikipediabot/feature-requests/75/
Reported by: Anonymous user
Created on: 2007-01-28 21:44:27
Subject: category.py add blind with contextual links
Original description:

When using category.py add and giving a page where wikilinks are in this form [[/foo]] or [[/foo/]] (http://en.wikibooks.org/w/index.php?title=C%2B%2B\_Programming&action=edit for example) or included in a template, the robot will parse pages named literally [[/foo]] instead of [[{{PAGENAME}}/foo]]. And if the link is included in a template, the robot will see anything (but for the template, it's often more convenient and not so problematic).


Version: core-(2.0)
Severity: normal
See Also:
https://sourceforge.net/p/pywikipediabot/feature-requests/75

Event Timeline

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

Compat has completely no support for relative links in the API. Core does, but the support is non-functional:

pywikibot.Page(pywikibot.Page(pywikibot.Site('nl'), 'Gebruiker:Valhallasw'), '/test')

Page(/test)

Marking 'easy' for core implementation

I cant see any tests for subpages, so even if it works in core, we still need tests created for this.

happy5214 set Security to None.

I'll try this one. It'll be a good first step in learning the Pywikibot codebase and the testing framework.

Change 200328 had a related patch set uploaded (by Happy5214):
Enabling the creation of Pages using links relative to another Page

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

Yikes! I forgot to branch! Ugh.

@valhallasw: I'm not sure it's that simple. The current implementation has already a meaning for Page(page, title) and title could be “/foo” and then is the question is it's a subpage or not? Afaik it's only a subpage when it's a link on a page (I'm not sure if the namespace has to be a subpages namespace).

I think the correct interpretation of Page(page, title) is 'the page a Link with /title/ links to from Page /page/'. Is there another interpretation that also makes sense? Why would you pass a Page object if it's not where you found the link?

Unfortunately yes, copied from the documentation:

If the first argument is a Page, create a copy of that object.                    
This can be used to convert an existing Page into a subclass                  
object, such as Category or FilePage.  (If the title is also                  
given as the second argument, creates a copy with that title;                     
this is used when pages are moved.)

Doh. You're right. That means we have to pass through a Link object, then? I.e. the method would then be

targetpage = Page(Link('/b', oldpage))

which currently doesn't work, as Link requires a Site object (?!):

>>> pywikibot.Link("/b", p)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/valhallasw/src/pywikibot-core/pywikibot/page.py", line 4369, in __init__
    "source parameter should be a Site object"
AssertionError: source parameter should be a Site object

That seems sensible. Allow the Site to be a Page as it also stores a Site. If it's a page it could be page relative and otherwise it's always absolute.

Change 200328 abandoned by Happy5214:
Enabling the creation of Pages using links relative to another Page

Reason:
Forgot to branch; new fix probably won't need this code.

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

I will work on this as time allows.

Change 213816 had a related patch set uploaded (by Happy5214):
Allow relative links to be handled in Link constructor

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

Change 213816 merged by jenkins-bot:
Allow relative links to be handled in Link constructor

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