From 4a38a678ba3f752f5e15c73ad7069b080f4f8d18 Mon Sep 17 00:00:00 2001 From: Tim Laqua Date: Thu, 6 Sep 2007 04:11:45 +0000 Subject: [PATCH] Refining fix for bug 10836 - taking care of unintended behavior. Added EditPage::pseudoParseSectionAnchor function to mimic parsing for section headings. Now preloaded section header text /* ... */ is also passed through the pseudoParseSectionAnchor function to correct section linking in recent changes. Post-save Section anchors are also pseudoParsed. This should take care of most of the section anchor issues related to embeded wikitext in section headings. --- includes/EditPage.php | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index cceb053db8..3a875450a5 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -844,8 +844,11 @@ class EditPage { $sectionanchor = $this->sectionAnchor( $this->summary ); # This is a new section, so create a link to the new section # in the revision summary. + //$parsedSummary = $this->pseudoParseSectionAnchor( $this->summary ); + $cleanSummary = $this->pseudoParseSectionAnchor( $this->summary ); + $sectionanchor = $this->sectionAnchor( $cleanSummary ); $this->summary = wfMsgForContent('newsectionsummary') . - " [[{$this->mTitle->getPrefixedText()}#{$this->summary}|{$this->summary}]]"; + " [[{$this->mTitle->getPrefixedText()}{$sectionanchor}|{$cleanSummary}]]"; } } elseif( $this->section != '' ) { # Try to get a section anchor from the section source, redirect to edited section if header found @@ -949,7 +952,9 @@ class EditPage { $this->textbox1, $matches ); if( !empty( $matches[2] ) ) { - $this->summary = "/* ". trim($matches[2])." */ "; + $this->summary = "/* " . + $this->pseudoParseSectionAnchor(trim($matches[2])) . + " */ "; } } } @@ -1605,6 +1610,34 @@ END return true; } + /// Strips a text string of wikitext for use in a section anchor + /** + * Accepts a text string and then removes all wikitext from the + * string and leaves only the resultant text (i.e. the result of + * [[User:WikiSysop|Sysop]] would be "Sysop" and the result of + * [[User:WikiSysop]] would be "User:WikiSysop") - this is intended + * to create valid section anchors by mimicing the output of the + * parser when headings are parsed. + * + * @param $text string Text string to be stripped of wikitext + * for use in a Section anchor + * @return Filtered text string + */ + function pseudoParseSectionAnchor( $text ) { + # Pseudo-Parse sectionanchor + + # Strip internal link markup + $text = preg_replace('/\[\[:?([^[|]+)\|([^[]+)\]\]/','$2',$text); + $text = preg_replace('/\[\[:?([^[]+)\]\]/','$1',$text); + + # Strip external link markup (FIXME: Not Tolerant to blank link text + # I.E. [http://www.mediawiki.org] will render as [1] or something depending + # on how many empty links there are on the page - need to figure that out. + $text = preg_replace('/\[(?:' . wfUrlProtocols() . ')([^ ]+?) ([^[]+)\]/','$2',$text); + + return $text; + } + /** * Format an anchor fragment as it would appear for a given section name * @param string $text @@ -1612,6 +1645,8 @@ END * @private */ function sectionAnchor( $text ) { + # Strip out wikitext links(they break the anchor) + $text = $this->pseudoParseSectionAnchor( $text ); $headline = Sanitizer::decodeCharReferences( $text ); # strip out HTML $headline = preg_replace( '/<.*?' . '>/', '', $headline ); -- 2.20.1