Page MenuHomePhabricator

[WIP RFC] Pywikibot console text message lengths
Open, LowestPublic

Description

Pywikibot includes lots of text messages (especially scripts) presented to the user on the console, and they may be divided into four categories with regards to console width:

  1. very short messages, unlikely to wrap except on very small devices
  2. no length limits, with long text wrapping onto the next line, and
  3. fixed width, and
  4. variable width with an attempt to limit the width in a sensible but unreliable way

As option 1 is very common, we should decide on a 'minimum width' that is acceptable for Pywikibot usage, and any message shorter than or equal to that is considered OK from a UI perspective.

Almost any attempt to provide a nice layout will fail when page titles are involved, as the page title can be 255 *bytes* of utf8, which can mean fewer characters in some scripts, but it means 255 characters of typical Latin script. An example of a very long redirect is https://en.wikipedia.org/w/index.php?title=To_authorize_the_President_to_extend_the_term_of_the_Agreement_for_Cooperation_between_the_Government_of_the_United_States_of_America_and_the_Government_of_the_Republic_of_Korea_Concerning_Civil_Uses_of_Nuclear_Energy&redirect=no. https://en.wikipedia.org/wiki/Suzukake_no_Ki_no_Michi_de_%22Kimi_no_Hohoemi_o_Yume_ni_Miru%22_to_Itte_Shimattara_Bokutachi_no_Kankei_wa_D%C5%8D_Kawatte_Shimau_no_ka,_Bokunari_ni_Nannichi_ka_Kangaeta_Ue_de_no_Yaya_Kihazukashii_Ketsuron_no_Y%C5%8D_na_Mono is the longest real page on English Wikipedia at 210 characters including at least two non-ASCII characters, so the actually number of bytes is slightly higher..

Pywikibot code prefers to display one page title per line, partially to address the variable width of page titles.
But if there is a prefix on each line, such as a numbered or ordered list, the wrapping of long titles is a small UI problem. If we also add leading whitespace (indents), then wrapping of long titles causes a 'well intended' text layout to break badly and create a UI mess.

We need a consistent approach for handling very long titles. The simplest approach that is almost perfect is to detect when a page title is too large for the screen and try to find a prefix substring that is sufficient to uniquely identify the page, e.g. [[abc foo s...]]

wcwidth can be used to accurately guess the width of a variable so that it can be trimmed at the correct position to not exceed the desired width.

In order to improve the level of 'sensible' width, we need to know what the width of the terminal is.
This was added in Python 3.3 shutil and a backport exists , but it hasnt been added to [[https://github.com/PythonCharmers/python-future/search?utf8=%E2%9C%93&q=get_terminal_size|python-future]] .

The current UI patch regarding length is https://gerrit.wikimedia.org/r/#/c/266587/ (warning about incoming links to page being deleted) . It is going down the path of option 4 - sensible but unreliable limits.

Event Timeline

Some examples of options 3

$ git grep --context 2 '\\'"n'$"
...
pywikibot/config2.py:        warning('family and mylang are not set.\n'
pywikibot/config2.py-                "Defaulting to family='test' and mylang='test'.")
...
pywikibot/site.py-                raise NotImplementedError(
pywikibot/site.py:                    u'Method or function "%s"\n'
pywikibot/site.py-                    u"isn't implemented in MediaWiki version < %s"
...
pywikibot/site.py-            raise NotImplementedError(
pywikibot/site.py:                u'Support of "revid" parameter\n'
pywikibot/site.py-                u'is not implemented in MediaWiki version < "1.22"')
...
pywikibot/textlib.py-            'The Pywikibot is no longer allowed to touch categories on the '
pywikibot/textlib.py-            'German\nWikipedia on pages that contain the Personendaten '
pywikibot/textlib.py:            'template because of the\nnon-standard placement of that template.\n'
pywikibot/textlib.py-            'See https://de.wikipedia.org/wiki/Hilfe:Personendaten#Kopiervorlage')
...
scripts/nowcommons.py-                            if pywikibot.input_yn(
scripts/nowcommons.py-                                    u'Does the description on Commons contain '
scripts/nowcommons.py:                                    'all required source and license\n'
scripts/nowcommons.py-                                    'information?',
scripts/nowcommons.py-                                    default=False, automatic_quit=False):
$ git grep -E --context 2 '^\s*u?'"'"'\\n'
pywikibot/i18n.py-        raise TranslationError(
pywikibot/i18n.py-            'Unable to load messages package %s for bundle %s'
pywikibot/i18n.py:            '\nIt can happen due to lack of i18n submodule or files. '
pywikibot/i18n.py-            'Read %s/i18n'
pywikibot/i18n.py-            % (_messages_package_name, twtitle, __url__))
...
scripts/category.py-        filename = pywikibot.input(
scripts/category.py-            u'Please enter the name of the file where the tree should be saved,'
scripts/category.py:            u'\nor press enter to simply show the tree:')
...
scripts/newitem.py-        pywikibot.output('Page age is set to %s days so only pages created'
scripts/newitem.py:                         '\nbefore %s will be considered.'
scripts/newitem.py-                         % (self.pageAge, self.pageAgeBefore.isoformat()))
scripts/newitem.py-        pywikibot.output('Last edit is set to %s days so only pages last edited'
scripts/newitem.py:                         '\nbefore %s will be considered.'
scripts/newitem.py-                         % (self.lastEdit, self.lastEditBefore.isoformat()))
jayvdb renamed this task from Pywikibot text message lengths to Pywikibot console text message lengths.Apr 1 2016, 6:02 PM
jayvdb renamed this task from Pywikibot console text message lengths to [WIP RFC] Pywikibot console text message lengths.
jayvdb updated the task description. (Show Details)
jayvdb updated the task description. (Show Details)
Xqt triaged this task as Lowest priority.Apr 25 2018, 4:00 PM
Xqt subscribed.

I guess most of them could be easily replaced by using textwrap.fill. Maybe we could ohange the pywikibot.output to always keep in a given line length range.