Page MenuHomePhabricator

Expose `TitleCodec` via `Bot`
Closed, ResolvedPublicFeature

Description

Feature summary (what you would like to be able to do and where):
The Bot struct should have a method to directly access the underlying TitleCodec, since it automatically crafts one to help create Pages.

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):
I was looking into what would be required to make a bot that interfaced with the Translate extension, and one thing that would be useful is the ability to directly access the TitleCodec the bot is using in one way or another, since it would enable easy access to the various formatting methods on it instead of just to_pretty (exposed via Page::title).

Note that the main reason for this is that the Translate extension creates pages of the form Translations:Full_Title/ID/lang, and Full_Title would be the fully formatted title of the page being translated, using the namespace name instead of its ID. You can't create this from a Title alone since you need the ability to access the information stored in the site info.

Benefits (why should this be implemented?):
While you could *probably* make do with just relying on Page alone, but since the bot already exposes the underlying mwapi::Client and parsoid::Client, it feels reasonable to expose TitleCodec as well.

We could also just offer more formatting methods on Page, but this would require any functions operating on this function to rely on Page instead of being able to work with only mwtitle. So, that's why I think that exposing TitleCodec would be better than simply adding more formatting methods.

Event Timeline

Note that the main reason for this is that the Translate extension creates pages of the form Translations:Full_Title/ID/lang, and Full_Title would be the fully formatted title of the page being translated, using the namespace name instead of its ID

I'm a little confused by this, is this not the "pretty" formatted title? Like https://www.mediawiki.org/w/index.php?title=Translations:Manual:Common_errors_and_symptoms/132/fr&action=info is "Translations:Manual:Common errors and symptoms/132/fr", which is format!("Translations:{}/132/fr", page.title()), no? Am I missing something?


In any case, your underlying request seems entirely reasonable. When I first added mwtitle integration, it was never exposed as part of the public API, and I was hoping that would be good enough, but eventually I added Page.as_title() because I wanted the underlying dbkey, so it's already part of our public API. I'm happy to add it, but would you be interested in sending a pull request for it?

I was looking into what would be required to make a bot that interfaced with the Translate extension

Cool! Curious to see how this goes :)

mwbot 0.6.1 has been released.