From 3d560be428920fd4eb10ea6e9760dafbba8f9ddc Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Thu, 7 Dec 2017 22:16:47 +0100 Subject: [PATCH] Change php extract() to explicit code Avoid php magic and make var settings more visible Change-Id: I223874fd871104b0ac6a80d7f39c6dd997d0551d --- includes/parser/Parser.php | 34 +++++++++++++++---- includes/parser/Preprocessor_DOM.php | 48 ++++++++++++++++++++++----- includes/parser/Preprocessor_Hash.php | 44 +++++++++++++++++++++--- includes/parser/Sanitizer.php | 11 +++++- 4 files changed, 117 insertions(+), 20 deletions(-) diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 3548da9581..75c1faf712 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -3108,10 +3108,29 @@ class Parser { throw $ex; } - # The interface for parser functions allows for extracting - # flags into the local scope. Extract any forwarded flags - # here. - extract( $result ); + // Extract any forwarded flags + if ( isset( $result['found'] ) ) { + $found = $result['found']; + } + if ( array_key_exists( 'text', $result ) ) { + // a string or null + $text = $result['text']; + } + if ( isset( $result['nowiki'] ) ) { + $nowiki = $result['nowiki']; + } + if ( isset( $result['isHTML'] ) ) { + $isHTML = $result['isHTML']; + } + if ( isset( $result['forceRawInterwiki'] ) ) { + $forceRawInterwiki = $result['forceRawInterwiki']; + } + if ( isset( $result['isChildObj'] ) ) { + $isChildObj = $result['isChildObj']; + } + if ( isset( $result['isLocalObj'] ) ) { + $isLocalObj = $result['isLocalObj']; + } } } @@ -3862,11 +3881,12 @@ class Parser { } if ( is_array( $output ) ) { - # Extract flags to local scope (to override $markerType) + // Extract flags $flags = $output; $output = $flags[0]; - unset( $flags[0] ); - extract( $flags ); + if ( isset( $flags['markerType'] ) ) { + $markerType = $flags['markerType']; + } } } else { if ( is_null( $attrText ) ) { diff --git a/includes/parser/Preprocessor_DOM.php b/includes/parser/Preprocessor_DOM.php index 2588962604..5368125f35 100644 --- a/includes/parser/Preprocessor_DOM.php +++ b/includes/parser/Preprocessor_DOM.php @@ -559,8 +559,16 @@ class Preprocessor_DOM extends Preprocessor { 'count' => $count ]; $stack->push( $piece ); $accum =& $stack->getAccum(); - $flags = $stack->getFlags(); - extract( $flags ); + $stackFlags = $stack->getFlags(); + if ( isset( $stackFlags['findEquals'] ) ) { + $findEquals = $stackFlags['findEquals']; + } + if ( isset( $stackFlags['findPipe'] ) ) { + $findPipe = $stackFlags['findPipe']; + } + if ( isset( $stackFlags['inHeading'] ) ) { + $inHeading = $stackFlags['inHeading']; + } $i += $count; } } elseif ( $found == 'line-end' ) { @@ -610,8 +618,16 @@ class Preprocessor_DOM extends Preprocessor { // Unwind the stack $stack->pop(); $accum =& $stack->getAccum(); - $flags = $stack->getFlags(); - extract( $flags ); + $stackFlags = $stack->getFlags(); + if ( isset( $stackFlags['findEquals'] ) ) { + $findEquals = $stackFlags['findEquals']; + } + if ( isset( $stackFlags['findPipe'] ) ) { + $findPipe = $stackFlags['findPipe']; + } + if ( isset( $stackFlags['inHeading'] ) ) { + $inHeading = $stackFlags['inHeading']; + } // Append the result to the enclosing accumulator $accum .= $element; @@ -640,8 +656,16 @@ class Preprocessor_DOM extends Preprocessor { $stack->push( $piece ); $accum =& $stack->getAccum(); - $flags = $stack->getFlags(); - extract( $flags ); + $stackFlags = $stack->getFlags(); + if ( isset( $stackFlags['findEquals'] ) ) { + $findEquals = $stackFlags['findEquals']; + } + if ( isset( $stackFlags['findPipe'] ) ) { + $findPipe = $stackFlags['findPipe']; + } + if ( isset( $stackFlags['inHeading'] ) ) { + $inHeading = $stackFlags['inHeading']; + } } else { # Add literal brace(s) $accum .= htmlspecialchars( str_repeat( $curChar, $count ) ); @@ -748,8 +772,16 @@ class Preprocessor_DOM extends Preprocessor { $accum .= $s; } } - $flags = $stack->getFlags(); - extract( $flags ); + $stackFlags = $stack->getFlags(); + if ( isset( $stackFlags['findEquals'] ) ) { + $findEquals = $stackFlags['findEquals']; + } + if ( isset( $stackFlags['findPipe'] ) ) { + $findPipe = $stackFlags['findPipe']; + } + if ( isset( $stackFlags['inHeading'] ) ) { + $inHeading = $stackFlags['inHeading']; + } # Add XML element to the enclosing accumulator $accum .= $element; diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/Preprocessor_Hash.php index 332f8e9fa7..b45b02606d 100644 --- a/includes/parser/Preprocessor_Hash.php +++ b/includes/parser/Preprocessor_Hash.php @@ -497,7 +497,16 @@ class Preprocessor_Hash extends Preprocessor { 'count' => $count ]; $stack->push( $piece ); $accum =& $stack->getAccum(); - extract( $stack->getFlags() ); + $stackFlags = $stack->getFlags(); + if ( isset( $stackFlags['findEquals'] ) ) { + $findEquals = $stackFlags['findEquals']; + } + if ( isset( $stackFlags['findPipe'] ) ) { + $findPipe = $stackFlags['findPipe']; + } + if ( isset( $stackFlags['inHeading'] ) ) { + $inHeading = $stackFlags['inHeading']; + } $i += $count; } } elseif ( $found == 'line-end' ) { @@ -554,7 +563,16 @@ class Preprocessor_Hash extends Preprocessor { // Unwind the stack $stack->pop(); $accum =& $stack->getAccum(); - extract( $stack->getFlags() ); + $stackFlags = $stack->getFlags(); + if ( isset( $stackFlags['findEquals'] ) ) { + $findEquals = $stackFlags['findEquals']; + } + if ( isset( $stackFlags['findPipe'] ) ) { + $findPipe = $stackFlags['findPipe']; + } + if ( isset( $stackFlags['inHeading'] ) ) { + $inHeading = $stackFlags['inHeading']; + } // Append the result to the enclosing accumulator array_splice( $accum, count( $accum ), 0, $element ); @@ -584,7 +602,16 @@ class Preprocessor_Hash extends Preprocessor { $stack->push( $piece ); $accum =& $stack->getAccum(); - extract( $stack->getFlags() ); + $stackFlags = $stack->getFlags(); + if ( isset( $stackFlags['findEquals'] ) ) { + $findEquals = $stackFlags['findEquals']; + } + if ( isset( $stackFlags['findPipe'] ) ) { + $findPipe = $stackFlags['findPipe']; + } + if ( isset( $stackFlags['inHeading'] ) ) { + $inHeading = $stackFlags['inHeading']; + } } else { # Add literal brace(s) self::addLiteral( $accum, str_repeat( $curChar, $count ) ); @@ -695,7 +722,16 @@ class Preprocessor_Hash extends Preprocessor { } } - extract( $stack->getFlags() ); + $stackFlags = $stack->getFlags(); + if ( isset( $stackFlags['findEquals'] ) ) { + $findEquals = $stackFlags['findEquals']; + } + if ( isset( $stackFlags['findPipe'] ) ) { + $findPipe = $stackFlags['findPipe']; + } + if ( isset( $stackFlags['inHeading'] ) ) { + $inHeading = $stackFlags['inHeading']; + } # Add XML element to the enclosing accumulator array_splice( $accum, count( $accum ), 0, $element ); diff --git a/includes/parser/Sanitizer.php b/includes/parser/Sanitizer.php index 20fee2db29..b570a43c06 100644 --- a/includes/parser/Sanitizer.php +++ b/includes/parser/Sanitizer.php @@ -477,7 +477,16 @@ class Sanitizer { public static function removeHTMLtags( $text, $processCallback = null, $args = [], $extratags = [], $removetags = [], $warnCallback = null ) { - extract( self::getRecognizedTagData( $extratags, $removetags ) ); + $tagData = self::getRecognizedTagData( $extratags, $removetags ); + $htmlpairs = $tagData['htmlpairs']; + $htmlsingle = $tagData['htmlsingle']; + $htmlsingleonly = $tagData['htmlsingleonly']; + $htmlnest = $tagData['htmlnest']; + $tabletags = $tagData['tabletags']; + $htmllist = $tagData['htmllist']; + $listtags = $tagData['listtags']; + $htmlsingleallowed = $tagData['htmlsingleallowed']; + $htmlelements = $tagData['htmlelements']; # Remove HTML comments $text = self::removeHTMLcomments( $text ); -- 2.20.1