Page MenuHomePhabricator

if [[file:]] exists in the page Cosmetic changes.py will crash
Closed, ResolvedPublic

Description

If [[file:]] (or other namespaces) exists in the page Cosmetic_changes.py will crash
The error:

Traceback (most recent call last):
  File "pwb.py", line 164, in <module>
    run_python_file(fn, argv, argvu)
  File "pwb.py", line 69, in run_python_file
    exec(compile(source, filename, "exec"), main_mod.__dict__)
  File "scripts/cosmetic_changes.py", line 971, in <module>
    main()
  File "scripts/cosmetic_changes.py", line 965, in main
    bot.run()
  File "/home/reza/pycore/pywikibot/bot.py", line 939, in run
    self.treat(page)
  File "scripts/cosmetic_changes.py", line 904, in treat
    changedText = ccToolkit.change(page.get())
  File "scripts/cosmetic_changes.py", line 228, in change
    new_text = self._change(text)
  File "scripts/cosmetic_changes.py", line 221, in _change
    text = self.safe_execute(method, text)
  File "scripts/cosmetic_changes.py", line 199, in safe_execute
    result = method(text)
  File "scripts/cosmetic_changes.py", line 548, in cleanUpLinks
    'startspace'])
  File "/home/reza/pycore/pywikibot/textlib.py", line 224, in replaceExcept
    replacement = new(match)
  File "scripts/cosmetic_changes.py", line 442, in handleOneLink
    namespace = page.namespace()
  File "/home/reza/pycore/pywikibot/page.py", line 154, in namespace
    return self._link.namespace
  File "/home/reza/pycore/pywikibot/page.py", line 4160, in namespace
    self.parse()
  File "/home/reza/pycore/pywikibot/page.py", line 4137, in parse
    % self._text)
pywikibot.exceptions.Error: Invalid link (no page title): 'file:'
<class 'pywikibot.exceptions.Error'>
CRITICAL: Waiting for 1 network thread(s) to finish. Press ctrl-c to abort

Version: core-(2.0)
Severity: major

Details

Reference
bz71817

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 3:55 AM
bzimport set Reference to bz71817.
bzimport added a subscriber: Unknown Object (????).
Yamaha5 created this task.Oct 8 2014, 5:45 PM
XZise added a comment.Oct 9 2014, 7:31 PM

Okay https://gerrit.wikimedia.org/r/161671/ does indirectly fix this. The problem is that Link.parse() raises an Error and not InvalidTitle exception. If it'd raise an InvalidTitle, cosmetic_changes.py would work fine.

jayvdb added a comment.EditedNov 9 2014, 1:28 PM

Iec4f32fdefde15b2330dbb191fb3bbb0d04803e2 was merged [ as 71ccd1267c2407fc3fea1210c5f442edb7f6d9c3]. We should add a test case for this, if one doesnt already exist.

jayvdb triaged this task as Medium priority.Nov 29 2014, 4:55 PM
jayvdb set Security to None.
jayvdb removed a subscriber: Unknown Object (????).
jayvdb assigned this task to XZise.Jun 21 2015, 9:28 AM

f3bf9705 looks like it added some relevant tests for this ('Talk:' in link_tests) , so maybe this task is done.

Restricted Application added a subscriber: TerraCodes. · View Herald TranscriptMar 13 2017, 5:19 PM
Kizule added a subscriber: Kizule.EditedJan 12 2018, 12:19 AM

I tested using master version of pywikibot on my wiki downloaded from gerrit and I have not problems with this.

Steps:

  1. I added in page Test on my wiki in localhost [[file:Wiki.png]]
  2. I runned
python pwb.py cosmetic_changes -page:Test
  1. And when pywikibot requested to confirm it, I typed y and I pressed enter
  2. And it is changed without problems.
Kizule closed this task as Resolved.Jan 12 2018, 3:45 PM
Aklapper reopened this task as Open.Jan 12 2018, 3:57 PM
Aklapper added a subscriber: Aklapper.

I added in page Test on my wiki in localhost [[file:Wiki.png]]

@Zoranzoki21: That is not what this task is about. The task summary says "if [[file:]] exists in the page", not "[[file:Wiki.png]]".

Xqt removed XZise as the assignee of this task.Jan 12 2018, 3:58 PM
Xqt added a subscriber: Xqt.
This comment was removed by Xqt.
Kizule closed this task as Resolved.Jan 12 2018, 4:00 PM
This comment was removed by Kizule.
C:\Users\ZoranD\Desktop\pywikibot>python pwb.py cosmetic_changes -page:Test -verbose -summary:Test
Pywikibot rede13695872939f4cedbb139bd03ead318ef64cb
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)]

The summary message for the command line replacements will be something like: Test
Found 2 localhost:sr processes running, including this one.
Retrieving 1 pages from localhost:sr.


>>> Test <<<
@@ -1 +1 @@
- [[file:Wiki.png]]
+ [[Датотека:Wiki.png]]

Do you want to accept these changes? ([y]es, [N]o, [e]dit original, edit [l]atest, open in [b]rowser, [a]ll, [q]uit): y
APISite("sr", "localhost").login(False) called when a previous login was in progress.
Dropped throttle(s).

1 pages changed.
Dropped throttle(s).
Closing network session.
Network session closed.

C:\Users\ZoranD\Desktop\pywikibot>
Dvorapa reopened this task as Open.EditedJan 12 2018, 5:21 PM
Dvorapa added a subscriber: Dvorapa.

Test wasn't performed under the same conditions, the string to be tested differs from the task description. Per T73817#768177 this task may be fixed, but per T73817#768186 there is missing a testcase for this type of link in a wikipage.

Test wasn't performed under the same conditions, the string to be tested differs from the task description. Per T73817#768177 this task may be fixed, but per T73817#768186 there is missing a testcase for this type of link in a wikipage.

Support will be soon abolished.

Support for what? For [[file:]] string?

Dvorapa updated the task description. (Show Details)Jan 12 2018, 7:23 PM
Dvorapa updated the task description. (Show Details)

Support for what? For [[file:]] string?

No. For python 2.6-2.7 in pywiki

This is maybe an issue also for Python 3

This was error in Pywikibot, not a compatibility problem.

Python 3.6.1
>>> import pywikibot
>>> from pywikibot.cosmetic_changes import CosmeticChangesToolkit as Cct
>>> site = pywikibot.Site()
>>> cc = Cct(site, namespace=0)
>>> cc.change('[[File:]] [[Soubor:]]')
'[[Soubor:]] [[Soubor:]]'

Can be closed.

Dvorapa closed this task as Resolved.Jan 14 2018, 1:22 PM

Yes, finally tested on python 2 and 3, really resolved