Umherirrender has uploaded a new change for review. https://gerrit.wikimedia.org/r/144182
Change subject: Use local variables when handle editsection's ...................................................................... Use local variables when handle editsection's In Parser.php a array was build and than the elements of that array was used, replaced this by local vars. In ParserOutput.php also no local vars was used to make the code more readable. Also inline the private callback with a anonymous function. Change-Id: I1c31c9e4855f93a8fb65e1c21faba46fcdcb1f4b --- M includes/parser/Parser.php M includes/parser/ParserOutput.php 2 files changed, 32 insertions(+), 35 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/82/144182/1 diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index e5917b8..dfc76e7 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -4595,13 +4595,13 @@ if ( $isTemplate ) { # Put a T flag in the section identifier, to indicate to extractSections() # that sections inside <includeonly> should be counted. - $editlinkArgs = array( $titleText, "T-$sectionIndex"/*, null */ ); + $editsectionPage = $titleText; + $editsectionSection = "T-$sectionIndex"; + $editsectionContent = null; } else { - $editlinkArgs = array( - $this->mTitle->getPrefixedText(), - $sectionIndex, - $headlineHint - ); + $editsectionPage = $this->mTitle->getPrefixedText(); + $editsectionSection = $sectionIndex; + $editsectionContent = $headlineHint; } // We use a bit of pesudo-xml for editsection markers. The // language converter is run later on. Using a UNIQ style marker @@ -4614,10 +4614,11 @@ // important bits of data, but put the headline hint inside a // content block because the language converter is supposed to // be able to convert that piece of data. - $editlink = '<mw:editsection page="' . htmlspecialchars( $editlinkArgs[0] ); - $editlink .= '" section="' . htmlspecialchars( $editlinkArgs[1] ) . '"'; - if ( isset( $editlinkArgs[2] ) ) { - $editlink .= '>' . $editlinkArgs[2] . '</mw:editsection>'; + // Gets replaced with html in ParserOutput::getText + $editlink = '<mw:editsection page="' . htmlspecialchars( $editsectionPage ); + $editlink .= '" section="' . htmlspecialchars( $editsectionSection ) . '"'; + if ( $editsectionContent !== null ) { + $editlink .= '>' . $editsectionContent . '</mw:editsection>'; } else { $editlink .= '/>'; } diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index 09f714f..1a387c1 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -74,8 +74,27 @@ wfProfileIn( __METHOD__ ); $text = $this->mText; if ( $this->mEditSectionTokens ) { - $text = preg_replace_callback( ParserOutput::EDITSECTION_REGEX, - array( &$this, 'replaceEditSectionLinksCallback' ), $text ); + $text = preg_replace_callback( + ParserOutput::EDITSECTION_REGEX, + function ( $m ) { + global $wgOut, $wgLang; + $editsectionPage = Title::newFromText( htmlspecialchars_decode( $m[1] ) ); + $editsectionSection = htmlspecialchars_decode( $m[2] ); + $editsectionContent = isset( $m[4] ) ? $m[3] : null; + + if ( !is_object( $editsectionPage ) ) { + throw new MWException( "Bad parser output text." ); + } + + $skin = $wgOut->getSkin(); + return call_user_func_array( + array( $skin, 'doEditSectionLink' ), + array( $editsectionPage, $editsectionSection, + $editsectionContent, $wgLang->getCode() ) + ); + }, + $text + ); } else { $text = preg_replace( ParserOutput::EDITSECTION_REGEX, '', $text ); } @@ -92,29 +111,6 @@ } wfProfileOut( __METHOD__ ); return $text; - } - - /** - * callback used by getText to replace editsection tokens - * @private - * @param array $m - * @throws MWException - * @return mixed - */ - function replaceEditSectionLinksCallback( $m ) { - global $wgOut, $wgLang; - $args = array( - htmlspecialchars_decode( $m[1] ), - htmlspecialchars_decode( $m[2] ), - isset( $m[4] ) ? $m[3] : null, - ); - $args[0] = Title::newFromText( $args[0] ); - if ( !is_object( $args[0] ) ) { - throw new MWException( "Bad parser output text." ); - } - $args[] = $wgLang->getCode(); - $skin = $wgOut->getSkin(); - return call_user_func_array( array( $skin, 'doEditSectionLink' ), $args ); } function &getLanguageLinks() { -- To view, visit https://gerrit.wikimedia.org/r/144182 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1c31c9e4855f93a8fb65e1c21faba46fcdcb1f4b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Umherirrender <umherirrender_de...@web.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits