Hi, I don't think this is a bug, but despite the documentation, I can't find a solution to my problems…
========= Problem 1 I'm trying to instantiate a `Page` based on its id, but I can't seem to find something that does… The closest to it seems to be "page_from_repository('Q'+pageId)", but I get "pywikibot.exceptions.UnknownExtensionError: Wikibase is not implemented for [mywikifamily:fr]."
From there on, I don't know what to do. =========
========= Problem 2 I'm using a personal wiki, self hosted, where read is for registered users only :
#Gestion des langues $wgPageLanguageUseDB = true ; $wgGroupPermissions['sysop']['pagelang'] = true;
# The following permissions were set based on your choice in the installer $wgGroupPermissions['*']['edit'] = false; //pour formations = true $wgGroupPermissions['*']['read'] = false; //pour formations = true # Prevent new user registrations except by sysops $wgGroupPermissions['*']['createaccount'] = false;
When I try to connect (I have created a bot for myself, configured my wiki family, my user-config and my user-password). The system refuses : "pywikibot.exceptions.NoUsernameError: Username '[blabla@blablaBot]' does not have read permissions on [mywikifamily:fr]." Then, if I comment my access rights, everything works fine. Later on, if I uncomment my access rights, it still works fine. How could I configure my rights without resorting to that strange/dangerous workaround? I have spent hours on that and have not found a solution =========
Sorry about those personal problems, which are not bugs, and which could be documented. But despite hours of searching, I haven't found out where they would be documented… Thanks to whoever takes the time to read this (let alone, reply…)
when I say page id it is the page id in the database, which can be used directly using curid, e.g : https://en.wikipedia.org/wiki/?curid=6666
It seems problem2 was just about adding
def isPublic(self): return False
in my family file : https://www.mediawiki.org/wiki/Manual:Pywikibot/Use_on_third-party_wikis#Bot... Sorry I hadn't found that earlier.
Problem 1 remains :
I'm trying to instantiate a `Page` based on its id, but I can't seem to find something that does… The closest to it seems to be "page_from_repository(pageId)", but I get "pywikibot.exceptions.UnknownExtensionError: Wikibase is not implemented for [mywikifamily:fr]." From there on, I don't know what to do.
There isn't a way to instantiate `Page` from an id. You need a title. What you are attempting with page_from_repository is for sites with a Wikibase repository and uses the Wikibase QID, not the page id from the database.
The closest is site.load_pages_from_pageids https://doc.wikimedia.org/pywikibot/stable/api_ref/pywikibot.site.html#pywikibot.site._generators.GeneratorsMixin.load_pages_from_pageids, which creates a generator yielding `Page`s by querying for the titles. pagegenerators.PagesFromPageidGenerator https://doc.wikimedia.org/pywikibot/stable/api_ref/pywikibot.pagegenerators.html#pagegenerators.PagesFromPageidGenerator wraps around that for use on the CLI (-pageid). I usually have some variation of the below when using pywikibot's page generators on the CLI.
local_args = pywikibot.handle_args() site = pywikibot.Site() gen_factory = pywikibot.pagegenerators.GeneratorFactory(site) script_args = gen_factory.handle_args(local_args) gen = gen_factory.getCombinedGenerator(preload=True)
If you're querying your DB, you may find pagegenerators.MySQLPageGenerator https://doc.wikimedia.org/pywikibot/stable/api_ref/pywikibot.pagegenerators.html#pagegenerators.MySQLPageGenerator (-mysqlquery) useful.
Regards, JJ
On Thu, May 11, 2023 at 3:13 PM mlois_-gr@lezinter.net wrote:
It seems problem2 was just about adding
def isPublic(self): return False
in my family file : https://www.mediawiki.org/wiki/Manual:Pywikibot/Use_on_third-party_wikis#Bot... Sorry I hadn't found that earlier.
Problem 1 remains :
I'm trying to instantiate a `Page` based on its id, but I can't seem to
find
something that does… The closest to it seems to be "page_from_repository(pageId)", but I get
"pywikibot.exceptions.UnknownExtensionError: Wikibase is not implemented for [mywikifamily:fr]."
From there on, I don't know what to do.
pywikibot mailing list -- pywikibot@lists.wikimedia.org Public archives at https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/me... To unsubscribe send an email to pywikibot-leave@lists.wikimedia.org
JJMC89 jjmc89.wikimedia@gmail.com ezt írta (időpont: 2023. máj. 12., P, 1:12):
There isn't a way to instantiate `Page` from an id.
But perhaps should be. Title is not always good for restoring the same page.
Your page id is 1. Sb. renames it – the actual article will have other title with id 1, the redirect page the old title with new id. However, you cannot be sure that the redirect leads to the old page at any time! While manually check the logs is simply, to create an algorithm that finds the original is very complicated.
The other case is deletion and recreation, that is not a big problem.
So I think page from id is a legal use case.
I realize that setting isPublic to false actually does not solve my problems :( There is something wrong in my local settings… But… Thank you so much JJMC89 !!! This works :
import pywikibot as pwb import pywikibot.pagegenerators as pwbpg
site = pwb.Site()
def get_page_by_id(site, id): res = None for pg in pwbpg.PagesFromPageidGenerator(str(id), site): if res == None: res = pg else: raise Exception("Too many results") #probably useless return res