r79558 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79557‎ | r79558 | r79559 >
Date:04:20, 4 January 2011
Author:dantman
Status:resolved
Tags:
Comment:
Followup r79520 and r79528, one of the args was missing when calling doEditSectionLink. Additionally the LanguageConverter was screwing up editsection markers really badly. Switched to <editsection> pesudo-xml style markers for best compatibility with the language converter. (tags are already escaped so we don't need to worry about similar user input)
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/includes/parser/ParserOutput.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -3699,7 +3699,7 @@
37003700 if ( $showEditLink ) {
37013701 $editLinkAsToken = $this->mOptions->getEditSectionTokens();
37023702 if ( $editLinkAsToken ) {
3703 - $this->mOutput->setEditSectionTokens( "{$this->mUniqPrefix}-editsection-", self::MARKER_SUFFIX );
 3703+ $this->mOutput->setEditSectionTokens( true );
37043704 }
37053705 }
37063706
@@ -3964,10 +3964,20 @@
39653965 } else {
39663966 $editlinkArgs = array( $this->mTitle->getPrefixedText(), $sectionIndex, $headlineHint );
39673967 }
3968 - // We use nearly the same structure as uniqPrefix and the marker stuffix (besides there being nothing random)
3969 - // However the this is output into the parser output itself not replaced early, so we hardcode this in case
3970 - // the constants change in a different version of MediaWiki, which would break this code.
3971 - $editlink = "{$this->mUniqPrefix}-editsection-" . implode('|', array_map('urlencode', $editlinkArgs)) . self::MARKER_SUFFIX;
 3968+ // We use a bit of pesudo-xml for editsection markers. The language converter is run later on
 3969+ // Using a UNIQ style marker leads to the converter screwing up the tokens when it converts stuff
 3970+ // And trying to insert strip tags fails too. At this point all real inputted tags have already been escaped
 3971+ // so we don't have to worry about a user trying to input one of these markers directly.
 3972+ // We use a page and section attribute to stop the language converter from converting these important bits
 3973+ // of data, but put the headline hint inside a content block because the language converter is supposed to
 3974+ // be able to convert that piece of data.
 3975+ $editlink = '<editsection page="' . htmlspecialchars($editlinkArgs[0]);
 3976+ $editlink .= '" section="' . htmlspecialchars($editlinkArgs[1]) .'"';
 3977+ if ( isset($editlinkArgs[2]) ) {
 3978+ $editlink .= '>' . $editlinkArgs[2] . '</editsection>';
 3979+ } else {
 3980+ $editlink .= '/>';
 3981+ }
39723982 } else {
39733983 // Output edit section links directly as markup like we used to
39743984 if ( $isTemplate ) {
Index: trunk/phase3/includes/parser/ParserOutput.php
@@ -137,8 +137,7 @@
138138
139139 function getText() {
140140 if ( $this->mEditSectionTokens ) {
141 - $editSectionTokens = $this->mEditSectionTokens;
142 - return preg_replace_callback( "#{$editSectionTokens[0]}(.*?){$editSectionTokens[1]}#", array( &$this, 'replaceEditSectionLinksCallback' ), $this->mText );
 141+ return preg_replace_callback( '#<editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</editsection>))#', array( &$this, 'replaceEditSectionLinksCallback' ), $this->mText );
143142 }
144143 return $this->mText;
145144 }
@@ -149,7 +148,11 @@
150149 */
151150 function replaceEditSectionLinksCallback( $m ) {
152151 global $wgUser, $wgLang;
153 - $args = array_map('urldecode', explode('|', $m[1], 3));
 152+ $args = array(
 153+ htmlspecialchars_decode($m[1]),
 154+ htmlspecialchars_decode($m[2]),
 155+ $m[4] ? $m[3] : null,
 156+ );
154157 $args[0] = Title::newFromText( $args[0] );
155158 if ( !is_object($args[0]) ) {
156159 throw new MWException("Bad parser output text.");
@@ -184,7 +187,7 @@
185188
186189 function setTitleText( $t ) { return wfSetVar( $this->mTitleText, $t ); }
187190 function setSections( $toc ) { return wfSetVar( $this->mSections, $toc ); }
188 - function setEditSectionTokens( $p, $s ) { return wfSetVar( $this->mEditSectionTokens, array( $p, $s ) ); }
 191+ function setEditSectionTokens( $t ) { return wfSetVar( $this->mEditSectionTokens, $t ); }
189192 function setIndexPolicy( $policy ) { return wfSetVar( $this->mIndexPolicy, $policy ); }
190193 function setTOCHTML( $tochtml ) { return wfSetVar( $this->mTOCHTML, $tochtml ); }
191194

Follow-up revisions

RevisionCommit summaryAuthorDate
r79559*sigh* I was looking at parser tests, but not notices in a site this time... ...dantman04:23, 4 January 2011
r79568Partial revert of r79520, follow up to r79558. Unconditionally use the new fo...platonides11:31, 4 January 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r79520Try to output editsection markers instead of rendered editsection links and d...dantman20:17, 3 January 2011
r79528Followup r79520, some characters inside the encoded data were being modified ...dantman21:04, 3 January 2011

Status & tagging log