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

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

StatusAssignedTask
OpenNone
OpenNone
Framawiki created this task.Nov 8 2016, 9:44 PM
Restricted Application added subscribers: pywikibot-bugs-list, Aklapper. · View Herald TranscriptNov 8 2016, 9:44 PM
Framawiki changed the title 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 edited the task description. (Show Details)
JJMC89 added a subscriber: JJMC89.EditedNov 9 2016, 4:09 AM

You can use forceInterwiki=True or insite

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

Mpaa added a subscriber: Mpaa.Nov 9 2016, 6:49 PM

Why do you need the first column?

JJMC89 added a comment.Nov 9 2016, 7:24 PM

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]]).

Mpaa added a comment.Nov 9 2016, 8:15 PM

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]]'
JJMC89 added a comment.Nov 9 2016, 8:58 PM

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 added a project: Easy.Nov 12 2016, 8:32 AM
Xqt added a subscriber: Xqt.

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.

Restricted Application added a subscriber: TerraCodes. · View Herald TranscriptNov 12 2016, 8:32 AM
Mayank.jindal5 added a subscriber: Mayank.jindal5.EditedDec 16 2016, 8:03 AM

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.

Magul added a subscriber: Magul.Dec 16 2016, 1:53 PM

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.

Mayank.jindal5 added a comment.EditedDec 16 2016, 4:57 PM

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.

Magul added a comment.Dec 16 2016, 5:09 PM

@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.

Framawiki added a comment.EditedDec 16 2016, 6:37 PM

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-core # pywikibot IRC channel on Freenode ? (direct link, tutorial).

Magul added a comment.Dec 17 2016, 4:07 PM

@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.

harikiran edited the task description. (Show Details)Mar 11 2017, 3:44 AM