Last modified: 2014-09-24 01:21:22 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T33865, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 31865 - Tag <dws> for discarding whitespaces.
Tag <dws> for discarding whitespaces.
Status: REOPENED
Product: MediaWiki
Classification: Unclassified
Parser (Other open bugs)
unspecified
All All
: Normal enhancement with 1 vote (vote)
: ---
Assigned To: Nobody - You can work on this!
: parser, patch, patch-need-review
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-10-21 20:30 UTC by Van de Bugger
Modified: 2014-09-24 01:21 UTC (History)
4 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
Implementation of tag <dws>. (2.25 KB, patch)
2011-10-21 20:34 UTC, Van de Bugger
Details
Tests. (991 bytes, text/plain)
2011-10-27 18:16 UTC, Van de Bugger
Details
A new hook. (413 bytes, patch)
2011-12-27 20:32 UTC, Van de Bugger
Details
Patch for hooks.txt (527 bytes, patch)
2012-01-28 21:47 UTC, Van de Bugger
Details
A new hook, v2. (412 bytes, patch)
2012-01-28 21:49 UTC, Van de Bugger
Details

Description Van de Bugger 2011-10-21 20:30:39 UTC
I propose tag <dws>. Preprocessor should discard the tag and all the whitespaces after it. Primary purpose of the tag -- freestyle formatting for templates. Let us consider an example:

* Some introductory text {{ template1 | param1=value1 | param2=value2 |
param3=value3 | ... }} continuation {{ template2 | param1=value1 |
param2=value2 | param3=value3 | ... }} and, finally, finish.

Not too readable. I would like to reformat it, use linebreaks and indents for better readability. Since leading and trailing whitespace is often ignored in templates, the example could be reformatted to:

* Some introductory text {{ template1 
| param1=value1 
| param2=value2 
| param3=value3 
| ... 
}} continuation {{ template2 
| param1=value1 
| param2=value2 
| param3=value3 
| ... 
}} and, finally, finish.

I can add indents:

* Some introductory text {{ template1 
    | param1=value1 
    | param2=value2 
    | param3=value3 
    | ... 
}} continuation {{ template2 
    | param1=value1 
    | param2=value2 
    | param3=value3 
    | ... 
}} and, finally, finish.

or add linebreak before template name:

* Some introductory text {{ 
    template1 
    | param1=value1 
    | param2=value2 
    | param3=value3 
    | ... 
}} continuation {{ 
    template2 
    | param1=value1 
    | param2=value2 
    | param3=value3 
    | ... 
}} and, finally, finish.

but anyway, braces must remain on the same line with surrounding text.

Using <dws> the example could be reformatted to:

*   Some introductory text <dws>
    {{  template1 
        | param1=value1 
        | param2=value2 
        | param3=value3 
        | ... 
    }} <dws>
    continuation <dws>
    {{  template2 
        | param1=value1 
        | param2=value2 
        | param3=value3 
        | ... 
    }} <dws>
    and, finally, finish.

Much better to my taste. 

This is a simple example. The more complex template code, the more value of good formatting. 

Other possible applications:

1. Unnamed leading and trailing whitespaces are not ignored in unnamed template arguments. <dws> may be used to format code:

{{  some template with unnamed arguments 
    |first unnamed argument value<dws>
    |second unnamed argument value<dws>
}}

2. If someone wants to avoid too long lines in wiki code:

* Linebreak terminates list element, <dws>
  so entire element must be written in one long line. <dws>
  But tag dws allows writing it in multiple short lines.

I think there are even more applications... I have been using the tag in my templates for some time and found in extremely helpful.
Comment 1 Van de Bugger 2011-10-21 20:34:02 UTC
Created attachment 9266 [details]
Implementation of tag <dws>.

This is implementation of the tag <dws>. The patch is developed for MediaWiki 1.17.1. I tested Preprocessor_DOM.php at my local wiki server. Unfotunately, I do not know when Preprocessor_Hash.php is used, so it is not tested. But fix is very similar for both preprocessors.
Comment 2 Van de Bugger 2011-10-21 22:25:16 UTC
I would like implement it as an extension, not a patch for MediaWiki core. But it seems it is hardly possible. A new tag can be implemented as an extension, but it is a very special one: it affects whitespace *after* the tag. Of cource, adding a closing tag </dws> makes extension implementation possible, but makes it useless:

{{  some template with unnamed arguments 
    |first unnamed argument value<dws>
    </dws>|second unnamed argument value<dws>
</dws>}}

looks ugly. The same effect may be achieved by comments:

{{  some template with unnamed arguments 
    |first unnamed argument value<!--
    -->|second unnamed argument value<!--
-->}}

but it does not improve readability, while standalone <dws> does.
Comment 3 Dan Bolser 2011-10-22 13:13:30 UTC
I think some way of allowing complex template code to be better formatted without creating masses of 'horizontal whitespace' in the calling page is essential. I'm not 100% sure this is the best way to do it, but I can't think of anything better, so it gets my vote. ... Sorry, I know I shouldn't use the issue tracker for discussion, but I just did.
Comment 4 Mark A. Hershberger 2011-10-26 19:22:26 UTC
(In reply to comment #3)
> Sorry, I know I shouldn't use the
> issue tracker for discussion, but I just did.

As long as the discussion is directly relevant to the original issue, discussion is fine.  Now to make my discussion ok:

(In reply to comment #1)
> This is implementation of the tag <dws>.

To get this applied could you please supply some parser tests?
Comment 5 Van de Bugger 2011-10-27 18:16:34 UTC
Created attachment 9299 [details]
Tests.

Tests in a separate file.
Comment 6 Van de Bugger 2011-11-09 17:23:31 UTC
> To get this applied could you please supply some parser tests?

Ping. Tests are ready.
Comment 7 Van de Bugger 2011-11-20 22:41:08 UTC
Ping again.
Comment 8 Mark A. Hershberger 2011-11-21 01:49:22 UTC
r103795
Comment 9 Van de Bugger 2011-11-21 17:22:49 UTC
Thanks!

BTW, what is `Preprocessor_HipHop.hphp'? Should I prepare a patch for it?
Comment 10 Platonides 2011-11-21 21:30:12 UTC
It's a preprocessor used when compiling with HipHop.
http://en.wikipedia.org/wiki/HipHop_(software)
Comment 11 Brion Vibber 2011-11-23 00:31:33 UTC
Reverted in r103990.

Not sure if this is something desirable at all; it's a weird-looking syntax and modifies the preprocessor (always a dangerous step).

Something like this needs to be discussed publicly on the core mailing lists rather than just on an out-of-the-way bug report.
Comment 12 Van de Bugger 2011-11-30 19:57:58 UTC
> Something like this needs to be discussed publicly on the core mailing lists…

Which of the mailing lists listed in http://www.mediawiki.org/wiki/Mailing_list is "core"?
Comment 13 Platonides 2011-11-30 22:30:00 UTC
Should use wikitech-l
Comment 14 Van de Bugger 2011-12-27 20:32:24 UTC
Created attachment 9766 [details]
A new hook.

> Not sure if this is something desirable at all; it's a weird-looking syntax 
> and modifies the preprocessor (always a dangerous step).

Ok, it could be undesirable and dangerous. Will you accept another one-line patch instead which introduces a new hook which makes implementation of <dws> possible as an extension?
Comment 15 Mark A. Hershberger 2012-01-04 00:13:35 UTC
> wfRunHooks( 'ParserBeforePreprocess', array( &$this, &$text, $flags ) );

Pretty sure that &$this could be just $this.

Please provide docs/hooks.txt for this as well.
Comment 16 Van de Bugger 2012-01-28 21:47:22 UTC
Created attachment 9921 [details]
Patch for hooks.txt

> Please provide docs/hooks.txt for this as well.

Here is the patch.
Comment 17 Van de Bugger 2012-01-28 21:49:41 UTC
Created attachment 9922 [details]
A new hook, v2.

> Pretty sure that &$this could be just $this.

The next attempt, without "&".
Comment 18 Sumana Harihareswara 2012-01-29 14:16:12 UTC
Changed "reviewed" tag to "need-review" to indicate that there's a new patch that awaits code review.
Comment 19 Van de Bugger 2012-02-09 17:58:46 UTC
Ping. Both comments by Mark have been addressed. Is there any more blockers?
Comment 20 Mark A. Hershberger 2012-02-14 02:31:05 UTC
(In reply to comment #19)
> Ping. Both comments by Mark have been addressed. Is there any more blockers?

Please post an RFC to wikitech-l and mediawiki.org (https://www.mediawiki.org/wiki/Requests_for_comment) for this.  The response I got was that this wasn't really something that anyone wanted.
Comment 21 Van de Bugger 2012-02-14 19:25:49 UTC
Mark,

Why didn't you ask for the most important blocker first? 

You requested parser tests — I wrote them, but the final destination for test was a trash bin, because of "a weird-looking syntax and modifies the preprocessor (always a dangerous step)".

Then I throw away my first implementation, and proposed a new one -- a new hook, one-line patch, to let me implement my weird-looking syntax as an extension, so my weird-looking syntax is not a problem because it is not a part of MediaWiki anymore. You requested hooks.txt. I wrote hooks.txt just to get know that you think this stuff is not really wanted by anyone.

Why didn't you request the most important thing — RFC from the very beginning? Why did you ask for parser test, hooks.txt, $this without ampersand? 

--------------------------------------------------

Off-topic:

> The response I got was that this wasn't really something that anyone wanted.

Err... Do you know something real that anyone wanted? (Immortality and tax-less life are not real.) Many people think Wikipedia is a trash created by lamers, so even Wikipedia is *not* a thing that *anyone* wanted. My awkward <dws/> is wanted by two persons. Not too bad for one-line hurtless patch.  

--------------------------------------------------

https://www.mediawiki.org/wiki/Requests_for_comment/New_hook:_ParserBeforePreprocess
Message to wikitech-l sent.
Comment 22 Mark A. Hershberger 2012-02-15 19:38:24 UTC
I apologize for offending you but thank you for sending the emails.
Comment 23 Van de Bugger 2012-02-21 21:42:20 UTC
I sent a message to wikitech-l@lists.wikimedia.org twice, but I have no evidence it was actually delivered — I don't see my message in the list archive. Could you please somebody resend it? My original text was quite trivial:

> https://www.mediawiki.org/wiki/Requests_for_comment/New_hook:_ParserBeforePreprocess
> Please comment.
> Van.
Comment 25 au 2012-06-17 18:41:13 UTC
Hi Van, thank you for the patch!

As you may already know, MediaWiki is currently revamping its PHP-based parser
into a "Parsoid" prototype component, to support the rich-text Visual Editor
project:

   https://www.mediawiki.org/wiki/Parsoid
   https://www.mediawiki.org/wiki/Visual_editor

Folks interested in enhancing the parser's capabilities are very much welcome
to join the Parsoid project, and contribute patches as Git branches:

   https://www.mediawiki.org/wiki/Git/Tutorial#How_to_submit_a_patch

Compared to .diff attachments in Bugzilla tickets, Git branches are much easier
for us to review, refine and merge features together.

Each change set has a distinct URL generated by the "git review" tool, which
can be referenced in Bugzilla by pasting its gerrit.wikimedia.org URL as a
comment.

If you run into any issues with the patch process, please feel free to ask on
irc.freenode.net #wikimedia-dev and the wikitext-l mailing list. Thank you!

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links