Index: trunk/phase3/includes/Parser.php |
— | — | @@ -1586,7 +1586,7 @@ |
1587 | 1587 | $text = preg_replace_callback( "/{{{([$titleChars]*?)}}}/", 'wfArgSubstitution', $text ); |
1588 | 1588 | } |
1589 | 1589 | # Template substitution |
1590 | | - $regex = '/{{(['.$titleChars.']*)(\\|.*?|)}}/s'; |
| 1590 | + $regex = '/(\\n|{)?{{(['.$titleChars.']*)(\\|.*?|)}}/s'; |
1591 | 1591 | $text = preg_replace_callback( $regex, 'wfBraceSubstitution', $text ); |
1592 | 1592 | |
1593 | 1593 | array_pop( $this->mArgStack ); |
— | — | @@ -1663,21 +1663,25 @@ |
1664 | 1664 | $found = false; |
1665 | 1665 | $nowiki = false; |
1666 | 1666 | $noparse = false; |
1667 | | - $itcamefromthedatabase = false; |
1668 | 1667 | |
1669 | 1668 | $title = NULL; |
1670 | 1669 | |
| 1670 | + # Need to know if the template comes at the start of a line, |
| 1671 | + # to treat the beginning of the template like the beginning |
| 1672 | + # of a line for tables and block-level elements. |
| 1673 | + $linestart = $matches[1]; |
| 1674 | + |
1671 | 1675 | # $part1 is the bit before the first |, and must contain only title characters |
1672 | 1676 | # $args is a list of arguments, starting from index 0, not including $part1 |
1673 | 1677 | |
1674 | | - $part1 = $matches[1]; |
1675 | | - # If the second subpattern matched anything, it will start with | |
| 1678 | + $part1 = $matches[2]; |
| 1679 | + # If the third subpattern matched anything, it will start with | |
1676 | 1680 | |
1677 | | - $args = $this->getTemplateArgs($matches[2]); |
| 1681 | + $args = $this->getTemplateArgs($matches[3]); |
1678 | 1682 | $argc = count( $args ); |
1679 | 1683 | |
1680 | | - # {{{}}} |
1681 | | - if ( strpos( $matches[0], '{{{' ) !== false ) { |
| 1684 | + # Don't parse {{{}}} because that's only for template arguments |
| 1685 | + if ( $linestart === '{' ) { |
1682 | 1686 | $text = $matches[0]; |
1683 | 1687 | $found = true; |
1684 | 1688 | $noparse = true; |
— | — | @@ -1713,7 +1717,7 @@ |
1714 | 1718 | $mwInt =& MagicWord::get( MAG_INT ); |
1715 | 1719 | if ( $mwInt->matchStartAndRemove( $part1 ) ) { |
1716 | 1720 | if ( $this->incrementIncludeCount( 'int:'.$part1 ) ) { |
1717 | | - $text = wfMsgReal( $part1, $args, true ); |
| 1721 | + $text = $linestart . wfMsgReal( $part1, $args, true ); |
1718 | 1722 | $found = true; |
1719 | 1723 | } |
1720 | 1724 | } |
— | — | @@ -1725,12 +1729,12 @@ |
1726 | 1730 | $mwNs = MagicWord::get( MAG_NS ); |
1727 | 1731 | if ( $mwNs->matchStartAndRemove( $part1 ) ) { |
1728 | 1732 | if ( intval( $part1 ) ) { |
1729 | | - $text = $wgContLang->getNsText( intval( $part1 ) ); |
| 1733 | + $text = $linestart . $wgContLang->getNsText( intval( $part1 ) ); |
1730 | 1734 | $found = true; |
1731 | 1735 | } else { |
1732 | 1736 | $index = Namespace::getCanonicalIndex( strtolower( $part1 ) ); |
1733 | 1737 | if ( !is_null( $index ) ) { |
1734 | | - $text = $wgContLang->getNsText( $index ); |
| 1738 | + $text = $linestart . $wgContLang->getNsText( $index ); |
1735 | 1739 | $found = true; |
1736 | 1740 | } |
1737 | 1741 | } |
— | — | @@ -1754,9 +1758,9 @@ |
1755 | 1759 | $title = Title::newFromText( $part1 ); |
1756 | 1760 | if ( !is_null( $title ) ) { |
1757 | 1761 | if ( $argc > 0 ) { |
1758 | | - $text = $title->$func( $args[0] ); |
| 1762 | + $text = $linestart . $title->$func( $args[0] ); |
1759 | 1763 | } else { |
1760 | | - $text = $title->$func(); |
| 1764 | + $text = $linestart . $title->$func(); |
1761 | 1765 | } |
1762 | 1766 | $found = true; |
1763 | 1767 | } |
— | — | @@ -1767,7 +1771,7 @@ |
1768 | 1772 | if ( !$found && $argc == 1 ) { |
1769 | 1773 | $mwGrammar =& MagicWord::get( MAG_GRAMMAR ); |
1770 | 1774 | if ( $mwGrammar->matchStartAndRemove( $part1 ) ) { |
1771 | | - $text = $wgContLang->convertGrammar( $args[0], $part1 ); |
| 1775 | + $text = $linestart . $wgContLang->convertGrammar( $args[0], $part1 ); |
1772 | 1776 | $found = true; |
1773 | 1777 | } |
1774 | 1778 | } |
— | — | @@ -1778,7 +1782,7 @@ |
1779 | 1783 | # and we need to check for loops. |
1780 | 1784 | if ( !$found && isset( $this->mTemplates[$part1] ) ) { |
1781 | 1785 | # set $text to cached message. |
1782 | | - $text = $this->mTemplates[$part1]; |
| 1786 | + $text = $linestart . $this->mTemplates[$part1]; |
1783 | 1787 | $found = true; |
1784 | 1788 | |
1785 | 1789 | # Infinite loop test |
— | — | @@ -1801,14 +1805,13 @@ |
1802 | 1806 | $articleContent = $article->getContentWithoutUsingSoManyDamnGlobals(); |
1803 | 1807 | if ( $articleContent !== false ) { |
1804 | 1808 | $found = true; |
1805 | | - $text = $articleContent; |
1806 | | - $itcamefromthedatabase = true; |
| 1809 | + $text = $linestart . $articleContent; |
1807 | 1810 | } |
1808 | 1811 | } |
1809 | 1812 | |
1810 | 1813 | # If the title is valid but undisplayable, make a link to it |
1811 | 1814 | if ( $this->mOutputType == OT_HTML && !$found ) { |
1812 | | - $text = '[['.$title->getPrefixedText().']]'; |
| 1815 | + $text = $linestart . '[['.$title->getPrefixedText().']]'; |
1813 | 1816 | $found = true; |
1814 | 1817 | } |
1815 | 1818 | |
— | — | @@ -1852,28 +1855,22 @@ |
1853 | 1856 | if ( $this->mOutputType == OT_HTML && !is_null( $title ) ) { |
1854 | 1857 | $wgLinkCache->addLinkObj( $title ); |
1855 | 1858 | } |
1856 | | - } |
1857 | 1859 | |
1858 | | - # Empties the template path |
1859 | | - $this->mTemplatePath = array(); |
1860 | | - if ( !$found ) { |
1861 | | - return $matches[0]; |
1862 | | - } else { |
1863 | 1860 | # replace ==section headers== |
1864 | 1861 | # XXX this needs to go away once we have a better parser. |
1865 | | - if ( $this->mOutputType != OT_WIKI && $itcamefromthedatabase ) { |
| 1862 | + if ( $this->mOutputType == OT_HTML ) { |
1866 | 1863 | if( !is_null( $title ) ) |
1867 | 1864 | $encodedname = base64_encode($title->getPrefixedDBkey()); |
1868 | 1865 | else |
1869 | 1866 | $encodedname = base64_encode(""); |
1870 | | - $matches = preg_split('/(^={1,6}.*?={1,6}\s*?$)/m', $text, -1, |
| 1867 | + $m = preg_split('/(^={1,6}.*?={1,6}\s*?$)/m', $text, -1, |
1871 | 1868 | PREG_SPLIT_DELIM_CAPTURE); |
1872 | 1869 | $text = ''; |
1873 | 1870 | $nsec = 0; |
1874 | | - for( $i = 0; $i < count($matches); $i += 2 ) { |
1875 | | - $text .= $matches[$i]; |
1876 | | - if (!isset($matches[$i + 1]) || $matches[$i + 1] == "") continue; |
1877 | | - $hl = $matches[$i + 1]; |
| 1871 | + for( $i = 0; $i < count($m); $i += 2 ) { |
| 1872 | + $text .= $m[$i]; |
| 1873 | + if (!isset($m[$i + 1]) || $m[$i + 1] == "") continue; |
| 1874 | + $hl = $m[$i + 1]; |
1878 | 1875 | if( strstr($hl, "<!--MWTEMPLATESECTION") ) { |
1879 | 1876 | $text .= $hl; |
1880 | 1877 | continue; |
— | — | @@ -1885,6 +1882,19 @@ |
1886 | 1883 | $nsec++; |
1887 | 1884 | } |
1888 | 1885 | } |
| 1886 | + |
| 1887 | + # If the template begins with a table or block-level |
| 1888 | + # element, it should be treated as beginning a new line. |
| 1889 | + if ($linestart !== '\n' && preg_match('/^({\\||:|;|#|\*)/', $text)) { |
| 1890 | + $text = "\n" . $text; |
| 1891 | + } |
| 1892 | + } |
| 1893 | + |
| 1894 | + # Empties the template path |
| 1895 | + $this->mTemplatePath = array(); |
| 1896 | + if ( !$found ) { |
| 1897 | + return $matches[0]; |
| 1898 | + } else { |
1889 | 1899 | return $text; |
1890 | 1900 | } |
1891 | 1901 | } |