Index: trunk/phase3/includes/EditPage.php |
— | — | @@ -844,8 +844,11 @@ |
845 | 845 | $sectionanchor = $this->sectionAnchor( $this->summary ); |
846 | 846 | # This is a new section, so create a link to the new section |
847 | 847 | # in the revision summary. |
| 848 | + //$parsedSummary = $this->pseudoParseSectionAnchor( $this->summary ); |
| 849 | + $cleanSummary = $this->pseudoParseSectionAnchor( $this->summary ); |
| 850 | + $sectionanchor = $this->sectionAnchor( $cleanSummary ); |
848 | 851 | $this->summary = wfMsgForContent('newsectionsummary') . |
849 | | - " [[{$this->mTitle->getPrefixedText()}#{$this->summary}|{$this->summary}]]"; |
| 852 | + " [[{$this->mTitle->getPrefixedText()}{$sectionanchor}|{$cleanSummary}]]"; |
850 | 853 | } |
851 | 854 | } elseif( $this->section != '' ) { |
852 | 855 | # Try to get a section anchor from the section source, redirect to edited section if header found |
— | — | @@ -949,7 +952,9 @@ |
950 | 953 | $this->textbox1, |
951 | 954 | $matches ); |
952 | 955 | if( !empty( $matches[2] ) ) { |
953 | | - $this->summary = "/* ". trim($matches[2])." */ "; |
| 956 | + $this->summary = "/* " . |
| 957 | + $this->pseudoParseSectionAnchor(trim($matches[2])) . |
| 958 | + " */ "; |
954 | 959 | } |
955 | 960 | } |
956 | 961 | } |
— | — | @@ -1605,13 +1610,43 @@ |
1606 | 1611 | return true; |
1607 | 1612 | } |
1608 | 1613 | |
| 1614 | + /// Strips a text string of wikitext for use in a section anchor |
1609 | 1615 | /** |
| 1616 | + * Accepts a text string and then removes all wikitext from the |
| 1617 | + * string and leaves only the resultant text (i.e. the result of |
| 1618 | + * [[User:WikiSysop|Sysop]] would be "Sysop" and the result of |
| 1619 | + * [[User:WikiSysop]] would be "User:WikiSysop") - this is intended |
| 1620 | + * to create valid section anchors by mimicing the output of the |
| 1621 | + * parser when headings are parsed. |
| 1622 | + * |
| 1623 | + * @param $text string Text string to be stripped of wikitext |
| 1624 | + * for use in a Section anchor |
| 1625 | + * @return Filtered text string |
| 1626 | + */ |
| 1627 | + function pseudoParseSectionAnchor( $text ) { |
| 1628 | + # Pseudo-Parse sectionanchor |
| 1629 | + |
| 1630 | + # Strip internal link markup |
| 1631 | + $text = preg_replace('/\[\[:?([^[|]+)\|([^[]+)\]\]/','$2',$text); |
| 1632 | + $text = preg_replace('/\[\[:?([^[]+)\]\]/','$1',$text); |
| 1633 | + |
| 1634 | + # Strip external link markup (FIXME: Not Tolerant to blank link text |
| 1635 | + # I.E. [http://www.mediawiki.org] will render as [1] or something depending |
| 1636 | + # on how many empty links there are on the page - need to figure that out. |
| 1637 | + $text = preg_replace('/\[(?:' . wfUrlProtocols() . ')([^ ]+?) ([^[]+)\]/','$2',$text); |
| 1638 | + |
| 1639 | + return $text; |
| 1640 | + } |
| 1641 | + |
| 1642 | + /** |
1610 | 1643 | * Format an anchor fragment as it would appear for a given section name |
1611 | 1644 | * @param string $text |
1612 | 1645 | * @return string |
1613 | 1646 | * @private |
1614 | 1647 | */ |
1615 | 1648 | function sectionAnchor( $text ) { |
| 1649 | + # Strip out wikitext links(they break the anchor) |
| 1650 | + $text = $this->pseudoParseSectionAnchor( $text ); |
1616 | 1651 | $headline = Sanitizer::decodeCharReferences( $text ); |
1617 | 1652 | # strip out HTML |
1618 | 1653 | $headline = preg_replace( '/<.*?' . '>/', '', $headline ); |