r25573 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25572‎ | r25573 | r25574 >
Date:04:11, 6 September 2007
Author:tlaqua
Status:old
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
@@ -844,8 +844,11 @@
845845 $sectionanchor = $this->sectionAnchor( $this->summary );
846846 # This is a new section, so create a link to the new section
847847 # in the revision summary.
 848+ //$parsedSummary = $this->pseudoParseSectionAnchor( $this->summary );
 849+ $cleanSummary = $this->pseudoParseSectionAnchor( $this->summary );
 850+ $sectionanchor = $this->sectionAnchor( $cleanSummary );
848851 $this->summary = wfMsgForContent('newsectionsummary') .
849 - " [[{$this->mTitle->getPrefixedText()}#{$this->summary}|{$this->summary}]]";
 852+ " [[{$this->mTitle->getPrefixedText()}{$sectionanchor}|{$cleanSummary}]]";
850853 }
851854 } elseif( $this->section != '' ) {
852855 # Try to get a section anchor from the section source, redirect to edited section if header found
@@ -949,7 +952,9 @@
950953 $this->textbox1,
951954 $matches );
952955 if( !empty( $matches[2] ) ) {
953 - $this->summary = "/* ". trim($matches[2])." */ ";
 956+ $this->summary = "/* " .
 957+ $this->pseudoParseSectionAnchor(trim($matches[2])) .
 958+ " */ ";
954959 }
955960 }
956961 }
@@ -1605,13 +1610,43 @@
16061611 return true;
16071612 }
16081613
 1614+ /// Strips a text string of wikitext for use in a section anchor
16091615 /**
 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+ /**
16101643 * Format an anchor fragment as it would appear for a given section name
16111644 * @param string $text
16121645 * @return string
16131646 * @private
16141647 */
16151648 function sectionAnchor( $text ) {
 1649+ # Strip out wikitext links(they break the anchor)
 1650+ $text = $this->pseudoParseSectionAnchor( $text );
16161651 $headline = Sanitizer::decodeCharReferences( $text );
16171652 # strip out HTML
16181653 $headline = preg_replace( '/<.*?' . '>/', '', $headline );

Follow-up revisions

RevisionCommit summaryAuthorDate
r25607Merged revisions 25530-25606 via svnmerge from...david06:11, 7 September 2007

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r25398Fixed bug 10836...tlaqua01:41, 2 September 2007
r25400Backing off fix for bug 10836 - previous attempt was incomplete. Will revisi...tlaqua02:50, 2 September 2007
r25415Merged revisions 25372-25414 via svnmerge from...david21:15, 2 September 2007
r25445Fixed bug 10836...tlaqua17:46, 3 September 2007
r25454Merged revisions 25415-25453 via svnmerge from...david19:27, 3 September 2007

Status & tagging log