Gergő Tisza has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/355060 )

Change subject: Remove $wgExceptionHooks
......................................................................

Remove $wgExceptionHooks

Skip deprecation period because it is very unlikely that anyone used this:
it does not appear anywhere on gerrit/git, no nontrivial google hits,
the documentation has been flat out wrong for 9 years and no one
noticed it, and the whole feature is fairly useless as you need to declare
it separately for every single exception class you expect.

Change-Id: I85844a238d3135d05eeba10331149624b04bafe2
---
M RELEASE-NOTES-1.30
M includes/DefaultSettings.php
M includes/exception/MWException.php
M includes/exception/MWExceptionRenderer.php
M tests/phpunit/includes/exception/MWExceptionTest.php
5 files changed, 8 insertions(+), 139 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/60/355060/1

diff --git a/RELEASE-NOTES-1.30 b/RELEASE-NOTES-1.30
index fbe23ab..3d2b3a7 100644
--- a/RELEASE-NOTES-1.30
+++ b/RELEASE-NOTES-1.30
@@ -17,6 +17,7 @@
   This is intended for extensions that want control
   over the instantiation of their jobs,
   to allow for proper dependency injection.
+* $wgExceptionHooks has been removed.
 
 === New features in 1.30 ===
 * (T37247) Output from Parser::parse() will now be wrapped in a div with
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index 0d82d35..19c585d 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -7432,15 +7432,6 @@
 ];
 
 /**
- * Hooks that are used for outputting exceptions.  Format is:
- *   $wgExceptionHooks[] = $funcname
- * or:
- *   $wgExceptionHooks[] = [ $class, $funcname ]
- * Hooks should return strings or false
- */
-$wgExceptionHooks = [];
-
-/**
  * Page property link table invalidation lists. When a page property
  * changes, this may require other link tables to be updated (eg
  * adding __HIDDENCAT__ means the hiddencat tracking category will
diff --git a/includes/exception/MWException.php 
b/includes/exception/MWException.php
index 4ff8636..8c1f8dc 100644
--- a/includes/exception/MWException.php
+++ b/includes/exception/MWException.php
@@ -64,17 +64,6 @@
        }
 
        /**
-        * Run hook to allow extensions to modify the text of the exception
-        *
-        * @param string $name Class name of the exception
-        * @param array $args Arguments to pass to the callback functions
-        * @return string|null String to output or null if any hook has been 
called
-        */
-       public function runHooks( $name, $args = [] ) {
-               return MWExceptionRenderer::runHooks( $this, $name, $args );
-       }
-
-       /**
         * Get a message from i18n
         *
         * @param string $key Message name
@@ -164,12 +153,7 @@
                if ( $this->useOutputPage() ) {
                        $wgOut->prepareErrorPage( $this->getPageTitle() );
 
-                       $hookResult = $this->runHooks( static::class );
-                       if ( $hookResult ) {
-                               $wgOut->addHTML( $hookResult );
-                       } else {
-                               $wgOut->addHTML( $this->getHTML() );
-                       }
+                       $wgOut->addHTML( $this->getHTML() );
 
                        $wgOut->output();
                } else {
@@ -183,12 +167,7 @@
                                '<style>body { font-family: sans-serif; margin: 
0; padding: 0.5em 2em; }</style>' .
                                "</head><body>\n";
 
-                       $hookResult = $this->runHooks( static::class . 'Raw' );
-                       if ( $hookResult ) {
-                               echo $hookResult;
-                       } else {
-                               echo $this->getHTML();
-                       }
+                       echo $this->getHTML();
 
                        echo "</body></html>\n";
                }
diff --git a/includes/exception/MWExceptionRenderer.php 
b/includes/exception/MWExceptionRenderer.php
index 435fde3..bd43934 100644
--- a/includes/exception/MWExceptionRenderer.php
+++ b/includes/exception/MWExceptionRenderer.php
@@ -85,51 +85,6 @@
        }
 
        /**
-        * Run hook to allow extensions to modify the text of the exception
-        *
-        * Called by MWException for b/c
-        *
-        * @param Exception|Throwable $e
-        * @param string $name Class name of the exception
-        * @param array $args Arguments to pass to the callback functions
-        * @return string|null String to output or null if any hook has been 
called
-        */
-       public static function runHooks( $e, $name, $args = [] ) {
-               global $wgExceptionHooks;
-
-               if ( !isset( $wgExceptionHooks ) || !is_array( 
$wgExceptionHooks ) ) {
-                       return null; // Just silently ignore
-               }
-
-               if ( !array_key_exists( $name, $wgExceptionHooks ) ||
-                       !is_array( $wgExceptionHooks[$name] )
-               ) {
-                       return null;
-               }
-
-               $hooks = $wgExceptionHooks[$name];
-               $callargs = array_merge( [ $e ], $args );
-
-               foreach ( $hooks as $hook ) {
-                       if (
-                               is_string( $hook ) ||
-                               ( is_array( $hook ) && count( $hook ) >= 2 && 
is_string( $hook[0] ) )
-                       ) {
-                               // 'function' or [ 'class', 'hook' ]
-                               $result = call_user_func_array( $hook, 
$callargs );
-                       } else {
-                               $result = null;
-                       }
-
-                       if ( is_string( $result ) ) {
-                               return $result;
-                       }
-               }
-
-               return null;
-       }
-
-       /**
         * @param Exception|Throwable $e
         * @return bool Should the exception use $wgOut to output the error?
         */
@@ -167,16 +122,11 @@
                                $wgOut->prepareErrorPage( self::msg( 
'internalerror', 'Internal error' ) );
                        }
 
-                       $hookResult = self::runHooks( $e, get_class( $e ) );
-                       if ( $hookResult ) {
-                               $wgOut->addHTML( $hookResult );
-                       } else {
-                               // Show any custom GUI message before the 
details
-                               if ( $e instanceof MessageSpecifier ) {
-                                       $wgOut->addHTML( 
Message::newFromSpecifier( $e )->escaped() );
-                               }
-                               $wgOut->addHTML( self::getHTML( $e ) );
+                       // Show any custom GUI message before the details
+                       if ( $e instanceof MessageSpecifier ) {
+                               $wgOut->addHTML( Message::newFromSpecifier( $e 
)->escaped() );
                        }
+                       $wgOut->addHTML( self::getHTML( $e ) );
 
                        $wgOut->output();
                } else {
@@ -191,12 +141,7 @@
                                '<style>body { font-family: sans-serif; margin: 
0; padding: 0.5em 2em; }</style>' .
                                "</head><body>\n";
 
-                       $hookResult = self::runHooks( $e, get_class( $e ) . 
'Raw' );
-                       if ( $hookResult ) {
-                               echo $hookResult;
-                       } else {
-                               echo self::getHTML( $e );
-                       }
+                       echo self::getHTML( $e );
 
                        echo "</body></html>\n";
                }
diff --git a/tests/phpunit/includes/exception/MWExceptionTest.php 
b/tests/phpunit/includes/exception/MWExceptionTest.php
index 7c36f7d..614a1c9 100644
--- a/tests/phpunit/includes/exception/MWExceptionTest.php
+++ b/tests/phpunit/includes/exception/MWExceptionTest.php
@@ -76,53 +76,6 @@
        }
 
        /**
-        * @dataProvider provideRunHooks
-        * @covers MWException::runHooks
-        */
-       public function testRunHooks( $wgExceptionHooks, $name, $args, 
$expectedReturn ) {
-               $this->setMwGlobals( [
-                       'wgExceptionHooks' => $wgExceptionHooks,
-               ] );
-               $e = new MWException();
-               $this->assertEquals( $expectedReturn, $e->runHooks( $name, 
$args ) );
-       }
-
-       public static function provideRunHooks() {
-               return [
-                       [ null, null, null, null ],
-                       [ [], 'name', [], null ],
-                       [ [ 'name' => false ], 'name', [], null ],
-                       [
-                               [ 'mockHook' => [ 'MWExceptionTest::mockHook' ] 
],
-                               'mockHook', [], 'YAY.[]'
-                       ],
-                       [
-                               [ 'mockHook' => [ 'MWExceptionTest::mockHook' ] 
],
-                               'mockHook', [ 'a' ], 'YAY.{"1":"a"}'
-                       ],
-                       [
-                               [ 'mockHook' => [ 'MWExceptionTest::mockHook' ] 
],
-                               'mockHook', [ null ], null
-                       ],
-               ];
-       }
-
-       /**
-        * Used in conjunction with provideRunHooks and testRunHooks as a mock 
callback for a hook
-        */
-       public static function mockHook() {
-               $args = func_get_args();
-               if ( !$args[0] instanceof MWException ) {
-                       return '$caller not instance of MWException';
-               }
-               unset( $args[0] );
-               if ( array_key_exists( 1, $args ) && $args[1] === null ) {
-                       return null;
-               }
-               return 'YAY.' . json_encode( $args );
-       }
-
-       /**
         * @dataProvider provideIsCommandLine
         * @covers MWException::isCommandLine
         */

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I85844a238d3135d05eeba10331149624b04bafe2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: GergÅ‘ Tisza <[email protected]>

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

Reply via email to