Page MenuHomePhabricator

Interwiki link with p.title(asLink=True)
Open, LowPublic

Description

Hello, about this edit :

>>> p = pywikibot.Page(pywikibot.Site('fr', 'wikipedia'), 'Test')
>>> t = pywikibot.Page(pywikibot.Site('test', 'wikipedia'), 'user:Framawiki/Brouillon')
>>> t.text += p.title(asLink=True, forceInterwiki=True)
>>> t.save()
Page [[test:User:Framawiki/Brouillon]] saved

And I obtain just [[Test]] and not [[:fr:Test]].

.title(asLink=True) should give a way to return an interwiki / absolute link.

Related Objects

StatusSubtypeAssignedTask
OpenNone
OpenNone

Event Timeline

Framawiki renamed this task from Correct p.title(asLink=True) when not use same wiki to Interwiki link with p.title(asLink=True).Nov 8 2016, 9:45 PM
Framawiki updated the task description. (Show Details)

You can use forceInterwiki=True or insite

Edit: Never mind. Both are missing the first colon.

Why do you need the first column?

The first colon is the difference between linking to fr:Test ([[:fr:Test]]) and creating a local interlanguage link corresponding to fr:Test ([[fr:Test]]).

OK, so what you are after is actually a Inline link, right?

BTW, is this still a valid interwiki link?

>>> t = pywikibot.Page(pywikibot.Site('test', 'wikipedia'), 'user:Framawiki/Brouillon')
>>> t.text = p.title(asLink=True, forceInterwiki=True)
>>> t.text
>>> u'[[wikipedia:fr:Test]]'

Yes, an inline interwiki link is what I would want a way to get (not sure about the OP).

[[wikipedia:fr:Test]] creates a local link to Wikipedia:fr:Test (test:Wikipedia:fr:Test) since testwiki has a 'Wikipedia' namespace.

The result with forceInterwiki=True depends on the site the user is logged into (or set in user-config.py, not sure which). When I set different sites in my user-config.py and run the below code, it results in different prefixes: [[Test]], [[fr:Test]], or [[wikipedia:fr:test]].

>>> p = pywikibot.Page(pywikibot.Site('fr', 'wikipedia'), 'Test')
>>> t = pywikibot.Page(pywikibot.Site('test', 'wikipedia'), 'user:Framawiki/Brouillon')
>>> t.text = p.title(asLink=True, forceInterwiki=True)
>>> print(t.text)
Xqt subscribed.

looks like a textlink outside category an image namespace for sites outside the current page.site.

There is a rewite for page.title() but I am unsure whether is has such a feature.

Hi,
I am Mayank Jindal from India. I am preparing for GSoC 2017. I have seen some projects related to pywikibot in possible tech projects list - https://phabricator.wikimedia.org/project/view/1042/
I think there is good chance for selecting in GSoC if I get some experience related to pywikibot. So I am starting by resolving easy tasks. That's why I have reached here.
I would love to start working on this task as it will help me in getting started.
Please guide me as I am new to pywikibot.

Hi @Mayank.jindal5, nice to see You here. Have fun trying to solve this issue, and if You would have any specific question, don't hesitate to ask.

I have cloned pywikibot with following command - git clone --recursive ssh://USERNAME@gerrit.wikimedia.org:29418/pywikibot/core.git
Now a repo named "core" has been created in my PC
But according to task description when I try to run the command -
p = pywikibot.Page(pywikibot.Site('fr', 'wikipedia'), 'Test')
It gives me error that NameError: name 'pywikibot' is not defined.
Please guide me as I am very new to wikimedia and pywikibot. However, I have tried to read all the development pages related to pywikibot.
Also I have joined # pywikibot channel on IRC. I am using riot for IRC.

@Mayank.jindal5 for your comfort it would be great if You could install virtualenv and create one for pywikibot (see: 1).

Get comfortible with it, activate one, after that it should be enough if You will run (in virtualenv activated) python setup.py install.

Hello @Mayank.jindal5 .
Common usage is python pwb.py nameofthefile.py for lunch python file directly with pywikibot loaded.
But because you use python in command line (shell), you have to manually import the library : import pywikibot should do this. Because you have downloaded the repo by git, you have to navigate to parent-folder of your downloaded git repo before lunch pythonin your command line (and then import pywikibot).
PWB should ask you to create a config file : try to run python pwb.py login (in PWB folder) or python pwb.py generate_user_files.pysee https://www.mediawiki.org/wiki/Manual:Pywikibot/generate_user_files.py)
For basic PWB use : https://www.mediawiki.org/wiki/Manual:Pywikibot/Create_your_own_script

thanks @Magul and @Framawiki My problem has been resolved.
I have some queries-

  1. When I am executing t.save() command, I am getting error - pywikibot.exceptions.OtherPageSaveError: Edit to page [[test:User:Mayank.jindal5]] failed:

ERROR: Username for wikipedia:test is undefined.
If you have an account for that site, please add a line to user-config.py:

usernames['wikipedia']['test'] = 'myUsername'

  1. What is the url that is building. I mean if I want to go to the page and see if anyone has changed on that url.
  1. I could not get the parameters like 'fr', 'asLink'.
  2. what is interwiki/absolut link? What are allow interwiki / forceInterWiki?

Apart from these I have some general queries -

  1. What is pywikibot core and compat? How are these two different?
  2. What is parent task and subtask? What is the significant of adding parent task as someone has added a parent task in this task?

I apologize for my long question.
Please guide me.

For #1, user-config.py is missing : please run python pwb.py generate_user_files.py and follow steeps to create it. Note: you have to enter your Wikimédia (ie. wikipedia) username, create one if you haven't.

Perhaps you can join us at Pywikibot # pywikibot IRC channel on Freenode ? (direct link, tutorial).

@Mayank.jindal5 first of all, You should listen to @Framawiki advice and get used look for answers on our IRC channel.

  1. When I am executing t.save() command, I am getting error - pywikibot.exceptions.OtherPageSaveError: Edit to page [[test:User:Mayank.jindal5]] failed:

ERROR: Username for wikipedia:test is undefined.
If you have an account for that site, please add a line to user-config.py:

usernames['wikipedia']['test'] = 'myUsername'

@Framawiki is right - generate user-config.py and add usernames settings for sites, that You want to edit.

  1. What is the url that is building. I mean if I want to go to the page and see if anyone has changed on that url.

I don't know, if I understand You correctly, but the site, You're editing is configured in user-config.py (see family and mylang settings), or You can pass any other lang and family to pywikibot.Site object during creation. After creation of such site, You can create object of pywikibot.Page class (where You need to pass Your site and name of page) and it will have method named full_url, that should retrun a string, that is full URL, that You can poin in browser.

  1. I could not get the parameters like 'fr', 'asLink'.

Where couldn't You get them? Could You elaborate more about it? Maybe few lines of scripts, that will show, what You want to do here?

  1. what is interwiki/absolut link? What are allow interwiki / forceInterWiki?

Whole code of title method is available in pywikibot/page.py. You need to get familar with this few lines. There is also a docstring that describe all parameters (like allowInterwiki and forceInterwiki).

Apart from these I have some general queries -

  1. What is pywikibot core and compat? How are these two different?

Originally (as far as I remember) pywikibot was shiped in two versions (previously they were named as trunk and rewrite, around 2013/2014 they were renamed accordingly to compat and core). As for today compat is deprecated and not developed actively, so You could stick to core.

If You still to learn something about it: phabricator procject is/was Pywikibot-compat , source code is still available: https://phabricator.wikimedia.org/diffusion/PWBO/

  1. What is parent task and subtask? What is the significant of adding parent task as someone has added a parent task in this task?

Parent task is just logical contept, it stats, that it could be closed as resolved only if all subtasks will be resolved. https://www.mediawiki.org/wiki/Phabricator/Help#Parent_tasks_and_subtasks

I apologize for my long question.
Please guide me.

@Magul Thanks. You are right I should have asked these questions on IRC rather than posting here.
Now I have cleared my doubts with FramaWiki on IRC.

Xqt triaged this task as Low priority.May 14 2018, 11:25 AM

Change 509538 had a related patch set uploaded (by Dvorapa; owner: Dvorapa):
[pywikibot/core@master] [bugfix] Fix mediawikiwiki and testwiki shortcuts

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