Merge "Clean up Language::markNoConversion()."
authorNikerabbit <niklas.laxstrom@gmail.com>
Fri, 23 Nov 2012 13:01:08 +0000 (13:01 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 23 Nov 2012 13:01:08 +0000 (13:01 +0000)
1  2 
languages/Language.php
tests/parser/parserTests.txt

diff --combined languages/Language.php
@@@ -3482,22 -3482,8 +3482,22 @@@ class Language 
                                }
                        }
                }
 -              // If all else fails, return the original string.
 -              return $str;
 +
 +              // If all else fails, return a standard duration or timestamp description.
 +              $time = strtotime( $str, 0 );
 +              if ( $time === false ) { // Unknown format. Return it as-is in case.
 +                      return $str;
 +              } elseif ( $time !== strtotime( $str, 1 ) ) { // It's a relative timestamp.
 +                      // $time is relative to 0 so it's a duration length.
 +                      return $this->formatDuration( $time );
 +              } else { // It's an absolute timestamp.
 +                      if ( $time === 0 ) {
 +                              // wfTimestamp() handles 0 as current time instead of epoch.
 +                              return $this->timeanddate( '19700101000000' );
 +                      } else {
 +                              return $this->timeanddate( $time );
 +                      }
 +              }
        }
  
        /**
        }
  
        /**
-        * Enclose a string with the "no conversion" tag. This is used by
-        * various functions in the Parser
+        * Prepare external link text for conversion. When the text is
+        * a URL, it shouldn't be converted, and it'll be wrapped in
+        * the "raw" tag (-{R| }-) to prevent conversion.
         *
-        * @param $text String: text to be tagged for no conversion
-        * @param $noParse bool
+        * This function is called "markNoConversion" for historical
+        * reasons.
+        *
+        * @param $text String: text to be used for external link
+        * @param $noParse bool: wrap it without confirming it's a real URL first
         * @return string the tagged text
         */
        public function markNoConversion( $text, $noParse = false ) {
-               return $this->mConverter->markNoConversion( $text, $noParse );
+               // Excluding protocal-relative URLs may avoid many false positives.
+               if ( $noParse || preg_match( '/^(?:' . wfUrlProtocolsWithoutProtRel() . ')/', $text ) ) {
+                       return $this->mConverter->markNoConversion( $text );
+               } else {
+                       return $text;
+               }
        }
  
        /**
@@@ -102,12 -102,6 +102,12 @@@ Template:table_attrib
  |</noinclude>style="color: red"| Foo
  !! endarticle
  
 +!! article
 +A?b
 +!! text
 +Weirdo titles!
 +!! endarticle
 +
  ###
  ### Basic tests
  ###
@@@ -2578,31 -2572,6 +2578,31 @@@ A table with nothing but a captio
  
  !! end
  
 +!! test
 +Table td-cell syntax variations
 +!! input
 +{|
 +| foo bar foo | baz
 +| foo bar foo || baz
 +| style='color:red;' | baz
 +| style='color:red;' || baz
 +|}
 +!! result
 +<table>
 +<tr>
 +<td> baz
 +</td>
 +<td> foo bar foo </td>
 +<td> baz
 +</td>
 +<td style="color:red;"> baz
 +</td>
 +<td> style='color:red;' </td>
 +<td> baz
 +</td></tr></table>
 +
 +!! end
 +
  !! test
  Simple table
  !! input
@@@ -3180,18 -3149,6 +3180,18 @@@ Plain link to protocol-relative URL wit
  </p>
  !! end
  
 +!! test
 +Plain link to page with question mark in title
 +!! input
 +[[A?b]]
 +
 +[[A?b|Baz]]
 +!! result
 +<p><a href="/wiki/A%3Fb" title="A?b">A?b</a>
 +</p><p><a href="/wiki/A%3Fb" title="A?b">Baz</a>
 +</p>
 +!! end
 +
  
  # I'm fairly sure the expected result here is wrong.
  # We want these to be URL links, not pseudo-pages with URLs for titles....
@@@ -3582,15 -3539,6 +3582,15 @@@ Horizontal ruler -- <4 dashes render a
  </p>
  !! end
  
 +!! test
 +Horizontal ruler -- Supports content following dashes on same line
 +!! input
 +---- Foo
 +!! result
 +<hr /> Foo
 +
 +!! end
 +
  ###
  ### Block-level elements
  ###
@@@ -4786,13 -4734,6 +4786,13 @@@ Foo<noinclude>zar</noinclude><includeon
  </p>
  !! end
  
 +!! test
 +Un-closed <noinclude>
 +!! input
 +<noinclude>
 +!! result
 +!! end
 +
  !! test
  <onlyinclude> on a page
  !! input
  </p>
  !! end
  
 +!! test
 +Un-closed <onlyinclude>
 +!! input
 +<onlyinclude>
 +!! result
 +!! end
 +
  !! article
  Template:Includeonly section
  !! text
@@@ -4867,13 -4801,6 +4867,13 @@@ section=
  ==Section 1==
  !! end
  
 +!! test
 +Un-closed <includeonly>
 +!! input
 +<includeonly>
 +!! result
 +!! end
 +
  ###
  ### <includeonly> and <noinclude> in attributes
  ###
@@@ -6118,19 -6045,6 +6118,19 @@@ Image with multiple captions -- only la
  
  !! end
  
 +!! test
 +Image with width attribute at different positions
 +!! input
 +[[Image:foobar.jpg|200px|right|Caption]]
 +[[Image:foobar.jpg|right|200px|Caption]]
 +[[Image:foobar.jpg|right|Caption|200px]]
 +!! result
 +<div class="floatright"><a href="/wiki/File:Foobar.jpg" class="image" title="Caption"><img alt="Caption" src="http://example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" width="200" height="23" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/400px-Foobar.jpg 2x" /></a></div>
 +<div class="floatright"><a href="/wiki/File:Foobar.jpg" class="image" title="Caption"><img alt="Caption" src="http://example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" width="200" height="23" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/400px-Foobar.jpg 2x" /></a></div>
 +<div class="floatright"><a href="/wiki/File:Foobar.jpg" class="image" title="Caption"><img alt="Caption" src="http://example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" width="200" height="23" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/400px-Foobar.jpg 2x" /></a></div>
 +
 +!! end
 +
  !! test
  Image with link parameter, wiki target
  !! input
@@@ -7274,23 -7188,6 +7274,23 @@@ DIV IN UPPERCAS
  
  !!end
  
 +!! test
 +Non-ASCII pseudo-tags are rendered as text
 +!! input
 +<khyô>
 +!! result
 +<p>&lt;khyô&gt;
 +</p>
 +!! end
 +
 +!! test
 +Pseudo-tag with URL 'name' renders as url link
 +!! input
 +<http://example.com/>
 +!! result
 +<p>&lt;<a rel="nofollow" class="external free" href="http://example.com/">http://example.com/</a>&gt;
 +</p>
 +!! end
  
  !! test
  text with amp in the middle of nowhere
@@@ -8077,30 -7974,6 +8077,30 @@@ disable
  Something need to be done. foo-2 ? 
  !! end
  
 +!! test
 +Sanitizer: Validating that <meta> and <link> work, but only for Microdata
 +!! input
 +<div itemscope>
 +      <meta itemprop="hello" content="world">
 +      <meta http-equiv="refresh" content="5">
 +      <meta itemprop="hello" http-equiv="refresh" content="5">
 +      <link itemprop="hello" href="{{SERVER}}">
 +      <link rel="stylesheet" href="{{SERVER}}">
 +      <link rel="stylesheet" itemprop="hello" href="{{SERVER}}">
 +</div>
 +!! result
 +<div itemscope="itemscope">
 +<p>   <meta itemprop="hello" content="world" />
 +      &lt;meta http-equiv="refresh" content="5"&gt;
 +      <meta itemprop="hello" content="5" />
 +</p>
 +      <link itemprop="hello" href="http&#58;//Britney-Spears" />
 +      &lt;link rel="stylesheet" href="<a rel="nofollow" class="external free" href="http://Britney-Spears">http://Britney-Spears</a>"&gt;
 +      <link itemprop="hello" href="http&#58;//Britney-Spears" />
 +</div>
 +
 +!! end
 +
  !! test
  Language converter: output gets cut off unexpectedly (bug 5757)
  !! options
@@@ -10623,6 -10496,29 +10623,29 @@@ Nested: -{zh-hans:Hi -{zh-cn:China;zh-s
  </p>
  !! end
  
+ !! test
+ Proper conversion of text in external links
+ !! options
+ language=sr variant=sr-ec
+ !! input
+ http://www.google.com
+ gopher://www.google.com
+ [http://www.google.com http://www.google.com]
+ [gopher://www.google.com gopher://www.google.com]
+ [https://www.google.com irc://www.google.com]
+ [ftp://www.google.com www.google.com/ftp://dir]
+ [//www.google.com www.google.com]
+ !! result
+ <p><a rel="nofollow" class="external free" href="http://www.google.com">http://www.google.com</a>
+ <a rel="nofollow" class="external free" href="gopher://www.google.com">gopher://www.google.com</a>
+ <a rel="nofollow" class="external free" href="http://www.google.com">http://www.google.com</a>
+ <a rel="nofollow" class="external free" href="gopher://www.google.com">gopher://www.google.com</a>
+ <a rel="nofollow" class="external text" href="https://www.google.com">irc://www.google.com</a>
+ <a rel="nofollow" class="external text" href="ftp://www.google.com">www.гоогле.цом/фтп://дир</a>
+ <a rel="nofollow" class="external text" href="//www.google.com">www.гоогле.цом</a>
+ </p>
+ !! end
  !! test
  Do not convert roman numbers to language variants
  !! options
@@@ -11591,6 -11487,22 +11614,6 @@@ Bug 31098 Template which includes syste
  </p>
  !! end
  
 -!! test
 -Deprecated presentational attributes are converted to css
 -!! input
 -{|
 -| valign=top align=left width=100 height=25% | Asdf
 -|}
 -<ul type="disc"></ul>
 -!! result
 -<table>
 -<tr>
 -<td style="text-align: left; height: 25%; vertical-align: top; width: 100px;"> Asdf
 -</td></tr></table>
 -<ul style="list-style-type: disc;"></ul>
 -
 -!! end
 -
  !! test
  Bug31490 Turkish: ucfirst 'blah'
  !! options
@@@ -12795,48 -12707,6 +12818,48 @@@ Escaping nowiki
  </p>
  !! end
  
 +!! test
 +Tag-like HTML structures are passed through as text
 +!! input
 +<x y>
 +
 +<x.y>
 +
 +<x-y>
 +
 +1>2
 +
 +x<y
 +
 +a>b
 +
 +1<d e>f
 +!! result
 +<p>&lt;x y&gt;
 +</p><p>&lt;x.y&gt;
 +</p><p>&lt;x-y&gt;
 +</p><p>1&gt;2
 +</p><p>x&lt;y
 +</p><p>a&gt;b
 +</p><p>1&lt;d e&gt;f
 +</p>
 +!! end
 +
 +
 +# This fails in the PHP parser (see bug 40670,
 +# https://bugzilla.wikimedia.org/show_bug.cgi?id=40670), so disabled for it.
 +!! test
 +Tag names followed by punctuation should not be recognized as tags
 +!! options
 +disabled
 +!! input
 +<s.ome> text
 +!! result
 +<p>&lt;s.ome&gt text
 +</p>
 +!! end
 +
 +
  TODO:
  more images
  more tables