}
}
}
- // 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;
+ }
}
/**
|</noinclude>style="color: red"| Foo
!! endarticle
+!! article
+A?b
+!! text
+Weirdo titles!
+!! endarticle
+
###
### Basic tests
###
!! 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
</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....
</p>
!! end
+!! test
+Horizontal ruler -- Supports content following dashes on same line
+!! input
+---- Foo
+!! result
+<hr /> Foo
+
+!! end
+
###
### Block-level elements
###
</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
==Section 1==
!! end
+!! test
+Un-closed <includeonly>
+!! input
+<includeonly>
+!! result
+!! end
+
###
### <includeonly> and <noinclude> in attributes
###
!! 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
!!end
+!! test
+Non-ASCII pseudo-tags are rendered as text
+!! input
+<khyô>
+!! result
+<p><khyô>
+</p>
+!! end
+
+!! test
+Pseudo-tag with URL 'name' renders as url link
+!! input
+<http://example.com/>
+!! result
+<p><<a rel="nofollow" class="external free" href="http://example.com/">http://example.com/</a>>
+</p>
+!! end
!! test
text with amp in the middle of nowhere
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" />
+ <meta http-equiv="refresh" content="5">
+ <meta itemprop="hello" content="5" />
+</p>
+ <link itemprop="hello" href="http://Britney-Spears" />
+ <link rel="stylesheet" href="<a rel="nofollow" class="external free" href="http://Britney-Spears">http://Britney-Spears</a>">
+ <link itemprop="hello" href="http://Britney-Spears" />
+</div>
+
+!! end
+
!! test
Language converter: output gets cut off unexpectedly (bug 5757)
!! options
</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
</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
</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><x y>
+</p><p><x.y>
+</p><p><x-y>
+</p><p>1>2
+</p><p>x<y
+</p><p>a>b
+</p><p>1<d e>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><s.ome> text
+</p>
+!! end
+
+
TODO:
more images
more tables