r103476 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103475‎ | r103476 | r103477 >
Date:16:46, 17 November 2011
Author:hashar
Status:reverted (Comments)
Tags:
Comment:
(bug 32450) MediaWiki: .js|.css pages parsed [[Category:#]] links

This patch skip the [[Category:#]] parsing logic when the Title is in
NS_MEDIAWIKI and ends with .js or .css. This way the code is kept as is
and pages are no more categorized.

How to reproduce the issue:

$ echo 'var foo = "[[Category:bug32450]]"' \
| php maintenance/parse.php --title MediaWiki:Foobar.js
<p>var foo = ""
</p>
$

Note how the text got stripped.

After this patch:

$ echo 'var foo = "[[Category:bug32450]]"' \
| php maintenance/parse.php --title MediaWiki:Foobar.js
<p>var foo = "[[Category:bug32450]]"
</p>
$

TEST PLAN:
==========

$ php parserTests.php --quiet
This is MediaWiki version 1.19alpha (r103473).

Reading tests from "tests/parser/parserTests.txt"...
Reading tests from "tests/parser/extraParserTests.txt"...
Passed 654 of 654 tests (100%)... ALL TESTS PASSED!
$
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/tests/parser/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -141,6 +141,7 @@
142142 * (bug 32168) Add wfAssembleUrl for use in wfExpandUrl
143143 * (bug 32168) fixed - wfExpandUrl expands dot segments now
144144 * (bug 31535) Upload comments now truncated properly, and don't have brackets
 145+* (bug 32450) Scripts pages in MediaWiki: namespace parse [[Category:#]] links
145146
146147 === API changes in 1.19 ===
147148 * (bug 19838) siprop=interwikimap can now use the interwiki cache.
Index: trunk/phase3/tests/parser/parserTests.txt
@@ -8908,6 +8908,28 @@
89098909
89108910 !! end
89118911
 8912+!! test
 8913+Bug 32450: MediaWiki: js pages should ignore Category syntax
 8914+!! options
 8915+title=[[MediaWiki:bug32450.js]]
 8916+!! input
 8917+var foo = "[[Category:bug32450]]"
 8918+!! result
 8919+<p>var foo = "[[Category:bug32450]]"
 8920+</p>
 8921+!! end
 8922+
 8923+!! test
 8924+Bug 32450: MediaWiki: css pages should ignore Category syntax
 8925+!! options
 8926+title=[[MediaWiki:bug32450.css]]
 8927+!! input
 8928+/** Css comment: "[[Category:bug32450]]" */
 8929+!! result
 8930+<p>/** Css comment: "[[Category:bug32450]]" */
 8931+</p>
 8932+!! end
 8933+
89128934 TODO:
89138935 more images
89148936 more tables
Index: trunk/phase3/includes/parser/Parser.php
@@ -1913,6 +1913,14 @@
19141914
19151915 if ( $ns == NS_CATEGORY ) {
19161916 wfProfileIn( __METHOD__."-category" );
 1917+ if( $this->getTitle()->isCssOrJsPage() ) {
 1918+ # bug 32450 : js and script pages in MediaWiki: namespace do not want
 1919+ # to get their code or comments altered. Think about js string:
 1920+ # var foobar = "[[Category:" + $catname + "]];
 1921+ $s .= "[[$text]]$trail";
 1922+ wfProfileOut( __METHOD__."-category" );
 1923+ continue;
 1924+ }
19171925 $s = rtrim( $s . "\n" ); # bug 87
19181926
19191927 if ( $wasblank ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r105161Skip replaceInternalLinks2 for js/css pages...hashar10:14, 5 December 2011
r105664* Revert r103476, r105161 and implement the fix for bug 32858 (a.k.a. bug 324......tstarling10:32, 9 December 2011
r107449Revert the fix for bug 32858 (r105664, r105161, r103476): no consensus, backw...tstarling22:50, 27 December 2011

Comments

#Comment by Platonides (talk | contribs)   00:12, 18 November 2011

Only categories? Why aren't you simply skipping the whole replaceInternalLinks2?

People have dealt with this in the past by eg. surrounding the code with <pre> tags. Maybe we should pretend they were plaintext?

#Comment by Hashar (talk | contribs)   16:40, 18 November 2011

Would skipping replaceInternalLinks2 be sufficient to force .js|.css page as plaintext? That would be a smarter move than that exception.

I am not sure how to do that in the parser though :(

#Comment by Platonides (talk | contribs)   17:36, 18 November 2011

If you want to make them completely plaintext, I'd early exit WikiPage::doEditUpdates() for those pages (similarly on how their special presentation is set on Article, not in parse).

#Comment by Nikerabbit (talk | contribs)   13:55, 18 November 2011

It might make more sense to add hook points instead of sprinkling exceptions all over the code base.

Status & tagging log