@@ -72,7 +72,13 @@ public function onMediaWikiPerformAction(
7272
7373 $ config = MediaWikiServices::getInstance ()->getMainConfig ();
7474 $ protectedActions = $ config ->get ( 'CrawlerProtectedActions ' );
75- $ denyFast = $ config ->get ( 'CrawlerProtectionUse418 ' );
75+ $ customDenialHeader = $ config ->get ( 'CrawlerProtectionDenialHeader ' );
76+ $ customDenialText = $ config ->get ( 'CrawlerProtectionDenialText ' );
77+ $ use418 = $ config ->get ( 'CrawlerProtectionUse418 ' );
78+ if ( empty ( $ customDenialHeader ) && empty ( $ customDenialText ) && $ use418 ) {
79+ $ customDenialHeader = 'HTTP/1.0 I \'m a teapot ' ;
80+ $ customDenialText = 'I \'m a teapot ' ;
81+ }
7682
7783 if (
7884 !$ user ->isRegistered ()
@@ -83,8 +89,8 @@ public function onMediaWikiPerformAction(
8389 || $ oldId > 0
8490 )
8591 ) {
86- if ( $ denyFast ) {
87- $ this ->denyAccessWith418 ( );
92+ if ( ! empty ( $ customDenialHeader ) && ! empty ( $ customDenialText ) ) {
93+ $ this ->denyAccessCustom ( $ customDenialHeader , $ customDenialText );
8894 }
8995 $ this ->denyAccess ( $ output );
9096 return false ;
@@ -110,7 +116,13 @@ public function onSpecialPageBeforeExecute( $special, $subPage ) {
110116
111117 $ config = MediaWikiServices::getInstance ()->getMainConfig ();
112118 $ protectedSpecialPages = $ config ->get ( 'CrawlerProtectedSpecialPages ' );
113- $ denyFast = $ config ->get ( 'CrawlerProtectionUse418 ' );
119+ $ customDenialHeader = $ config ->get ( 'CrawlerProtectionDenialHeader ' );
120+ $ customDenialText = $ config ->get ( 'CrawlerProtectionDenialText ' );
121+ $ use418 = $ config ->get ( 'CrawlerProtectionUse418 ' );
122+ if ( empty ( $ customDenialHeader ) && empty ( $ customDenialText ) && $ use418 ) {
123+ $ customDenialHeader = 'HTTP/1.0 I \'m a teapot ' ;
124+ $ customDenialText = 'I \'m a teapot ' ;
125+ }
114126
115127 // Normalize protected special pages: lowercase and strip 'Special:' prefix
116128 $ normalizedProtectedPages = array_map (
@@ -122,8 +134,8 @@ public function onSpecialPageBeforeExecute( $special, $subPage ) {
122134
123135 $ name = strtolower ( $ special ->getName () );
124136 if ( in_array ( $ name , $ normalizedProtectedPages , true ) ) {
125- if ( $ denyFast ) {
126- $ this ->denyAccessWith418 ( );
137+ if ( ! empty ( $ customDenialHeader ) && ! empty ( $ customDenialText ) ) {
138+ $ this ->denyAccessCustom ( $ customDenialHeader , $ customDenialText );
127139 }
128140 $ out = $ special ->getContext ()->getOutput ();
129141 $ this ->denyAccess ( $ out );
@@ -134,8 +146,8 @@ public function onSpecialPageBeforeExecute( $special, $subPage ) {
134146 $ request = $ special ->getContext ()->getRequest ();
135147 $ oldId = (int )$ request ->getVal ( 'oldid ' );
136148 if ( $ oldId > 0 ) {
137- if ( $ denyFast ) {
138- $ this ->denyAccessWith418 ( );
149+ if ( ! empty ( $ customDenialHeader ) && ! empty ( $ customDenialText ) ) {
150+ $ this ->denyAccessCustom ( $ customDenialHeader , $ customDenialText );
139151 }
140152 $ out = $ special ->getContext ()->getOutput ();
141153 $ this ->denyAccess ( $ out );
@@ -146,14 +158,14 @@ public function onSpecialPageBeforeExecute( $special, $subPage ) {
146158 }
147159
148160 /**
149- * Helper: output 418 Teapot and halt the processing immediately
161+ * Display custom text for the "access denied" message, to avoid unnecessarily taxing resources.
150162 *
151163 * @return void
152164 * @suppress PhanPluginNeverReturnMethod
153165 */
154- protected function denyAccessWith418 ( ) {
155- header ( ' HTTP/1.0 I \' m a teapot ' );
156- die ( ' I \' m a teapot ' );
166+ protected function denyAccessCustom ( $ customDenialHeader , $ customDenialText ) {
167+ header ( $ customDenialHeader );
168+ die ( htmlspecialchars ( $ customDenialText ) );
157169 }
158170
159171 /**
0 commit comments