jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/357584 )

Change subject: Parser: Ensure function and tag hook callbacks are callable 
upon registration
......................................................................


Parser: Ensure function and tag hook callbacks are callable upon registration

This is to safeguard against issues like T167238, where the callback was 
invalid,
but was only noticed when the magic word was used in an article.

In general, type checks should be applied when things get
registered for later use. Fail early, stay sane.

Change-Id: Ifb7005ee214829c98cec534261c0db7d13f50f35
---
M includes/parser/Parser.php
1 file changed, 4 insertions(+), 16 deletions(-)

Approvals:
  Krinkle: Looks good to me, but someone else must approve
  Aleksey Bekh-Ivanov (WMDE): Looks good to me, but someone else must approve
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified
  Thiemo Mättig (WMDE): Looks good to me, but someone else must approve



diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php
index 34f6232..dc7871c 100644
--- a/includes/parser/Parser.php
+++ b/includes/parser/Parser.php
@@ -3377,11 +3377,6 @@
 
                list( $callback, $flags ) = $this->mFunctionHooks[$function];
 
-               # Workaround for PHP bug 35229 and similar
-               if ( !is_callable( $callback ) ) {
-                       throw new MWException( "Tag hook for $function is not 
callable\n" );
-               }
-
                // Avoid PHP 7.1 warning from passing $this by reference
                $parser = $this;
 
@@ -3882,17 +3877,10 @@
                        }
 
                        if ( isset( $this->mTagHooks[$name] ) ) {
-                               # Workaround for PHP bug 35229 and similar
-                               if ( !is_callable( $this->mTagHooks[$name] ) ) {
-                                       throw new MWException( "Tag hook for 
$name is not callable\n" );
-                               }
                                $output = call_user_func_array( 
$this->mTagHooks[$name],
                                        [ $content, $attributes, $this, $frame 
] );
                        } elseif ( isset( $this->mFunctionTagHooks[$name] ) ) {
                                list( $callback, ) = 
$this->mFunctionTagHooks[$name];
-                               if ( !is_callable( $callback ) ) {
-                                       throw new MWException( "Tag hook for 
$name is not callable\n" );
-                               }
 
                                // Avoid PHP 7.1 warning from passing $this by 
reference
                                $parser = $this;
@@ -4761,7 +4749,7 @@
         * @throws MWException
         * @return callable|null The old value of the mTagHooks array 
associated with the hook
         */
-       public function setHook( $tag, $callback ) {
+       public function setHook( $tag, callable $callback ) {
                $tag = strtolower( $tag );
                if ( preg_match( '/[<>\r\n]/', $tag, $m ) ) {
                        throw new MWException( "Invalid character {$m[0]} in 
setHook('$tag', ...) call" );
@@ -4792,7 +4780,7 @@
         * @throws MWException
         * @return callable|null The old value of the mTagHooks array 
associated with the hook
         */
-       public function setTransparentTagHook( $tag, $callback ) {
+       public function setTransparentTagHook( $tag, callable $callback ) {
                $tag = strtolower( $tag );
                if ( preg_match( '/[<>\r\n]/', $tag, $m ) ) {
                        throw new MWException( "Invalid character {$m[0]} in 
setTransparentHook('$tag', ...) call" );
@@ -4855,7 +4843,7 @@
         * @throws MWException
         * @return string|callable The old callback function for this name, if 
any
         */
-       public function setFunctionHook( $id, $callback, $flags = 0 ) {
+       public function setFunctionHook( $id, callable $callback, $flags = 0 ) {
                global $wgContLang;
 
                $oldVal = isset( $this->mFunctionHooks[$id] ) ? 
$this->mFunctionHooks[$id][0] : null;
@@ -4907,7 +4895,7 @@
         * @throws MWException
         * @return null
         */
-       public function setFunctionTagHook( $tag, $callback, $flags ) {
+       public function setFunctionTagHook( $tag, callable $callback, $flags ) {
                $tag = strtolower( $tag );
                if ( preg_match( '/[<>\r\n]/', $tag, $m ) ) {
                        throw new MWException( "Invalid character {$m[0]} in 
setFunctionTagHook('$tag', ...) call" );

-- 
To view, visit https://gerrit.wikimedia.org/r/357584
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ifb7005ee214829c98cec534261c0db7d13f50f35
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: C. Scott Ananian <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: Umherirrender <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to