Page MenuHomePhabricator

Lua's mw.text.nowiki() should escape exclamation point "!" on new line
Open, Needs TriagePublic

Description

According to the documentation, mw.text.nowiki() escapes all chars that have special meaning in wikitext. An exclamation point "!" is part of the table syntax, so it should be replaced when it starts a new line. Example wikitext:

{|
! heading
|}

Example of problem in practice:
On https://sv.wiktionary.org/wiki/Modul:grammar-table/test we have been forced to create a workaround for this issue.

Event Timeline

Skalman created this task.Jun 24 2017, 1:37 AM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJun 24 2017, 1:37 AM

Change 392419 had a related patch set uploaded (by Gerrit Patch Uploader; owner: Vlakoff):
[mediawiki/extensions/Scribunto@master] Make mw.text.nowiki() escape "!" at beginning of line

https://gerrit.wikimedia.org/r/392419

Restricted Application added a subscriber: jeblad. · View Herald TranscriptNov 20 2017, 1:20 PM
Od1n added a subscriber: Od1n.Nov 20 2017, 1:27 PM

Mmmm, wait. Table code would also accept such leading spaces/tabs:

{|
    ! heading
|}
Od1n added a comment.Nov 20 2017, 2:00 PM

New patch, that searches for \n[ \t]*!

Also added some missing tests, for \n----, __, PMID

Change 392475 had a related patch set uploaded (by Gerrit Patch Uploader; owner: Vlakoff):
[mediawiki/core@master] Make wfEscapeWikiText() escape "!" at beginning of line

https://gerrit.wikimedia.org/r/392475

Od1n added a comment.Nov 20 2017, 8:31 PM

As suggested on Gerrit, I added a patch that implements a similar change in core wfEscapeWikiText().

Though, it tickles me to add stuff to this function, and I'm not sure it's really useful. Could anyone provide a demo showing the need for this?

Od1n added a comment.Jan 21 2018, 10:05 PM

How about just escaping all ! characters? It would escape more than necessary, but the code would be much simpler (in particular the PHP one).

@Od1n , I didn't see your comment from November.

Could anyone provide a demo showing the need for this?

In this task description, I provided a use case, where we had to create a function to escape exclamation points, for text that would later be processed by mw.text.nowiki(). See our function nowiki() on https://sv.wiktionary.org/wiki/Modul:grammar-table/test.

How about just escaping all ! characters?

Fine by me.