Removes Google web search from exception page
[lhc/web/wiklou.git] / includes / exception / MWExceptionRenderer.php
index 49cf71e..22be2be 100644 (file)
@@ -197,12 +197,21 @@ class MWExceptionRenderer {
         * @return string Message with arguments replaced
         */
        private static function msg( $key, $fallback /*[, params...] */ ) {
+               global $wgSitename;
                $args = array_slice( func_get_args(), 2 );
+
+               // FIXME: Keep logic in sync with MWException::msg.
                try {
-                       return wfMessage( $key, $args )->text();
+                       $res = wfMessage( $key, $args )->text();
                } catch ( Exception $e ) {
-                       return wfMsgReplaceArgs( $fallback, $args );
+                       $res = wfMsgReplaceArgs( $fallback, $args );
+                       // If an exception happens inside message rendering,
+                       // {{SITENAME}} sometimes won't be replaced.
+                       $res = strtr( $res, [
+                               '{{SITENAME}}' => $wgSitename,
+                       ] );
                }
+               return $res;
        }
 
        /**
@@ -263,7 +272,7 @@ class MWExceptionRenderer {
         */
        private static function printError( $message ) {
                // NOTE: STDERR may not be available, especially if php-cgi is used from the
-               // command line (bug #15602). Try to produce meaningful output anyway. Using
+               // command line (T17602). Try to produce meaningful output anyway. Using
                // echo may corrupt output to STDOUT though.
                if ( defined( 'STDERR' ) ) {
                        fwrite( STDERR, $message );
@@ -314,47 +323,7 @@ class MWExceptionRenderer {
                                htmlspecialchars( $e->getTraceAsString() ) . '</pre>';
                }
 
-               $html .= '<hr />';
-               $html .= self::googleSearchForm();
                $html .= '</body></html>';
                echo $html;
        }
-
-       /**
-        * @return string
-        */
-       private static function googleSearchForm() {
-               global $wgSitename, $wgCanonicalServer, $wgRequest;
-
-               $usegoogle = htmlspecialchars( self::msg(
-                       'dberr-usegoogle',
-                       'You can try searching via Google in the meantime.'
-               ) );
-               $outofdate = htmlspecialchars( self::msg(
-                       'dberr-outofdate',
-                       'Note that their indexes of our content may be out of date.'
-               ) );
-               $googlesearch = htmlspecialchars( self::msg( 'searchbutton', 'Search' ) );
-               $search = htmlspecialchars( $wgRequest->getVal( 'search' ) );
-               $server = htmlspecialchars( $wgCanonicalServer );
-               $sitename = htmlspecialchars( $wgSitename );
-               $trygoogle = <<<EOT
-<div style="margin: 1.5em">$usegoogle<br />
-<small>$outofdate</small>
-</div>
-<form method="get" action="//www.google.com/search" id="googlesearch">
-       <input type="hidden" name="domains" value="$server" />
-       <input type="hidden" name="num" value="50" />
-       <input type="hidden" name="ie" value="UTF-8" />
-       <input type="hidden" name="oe" value="UTF-8" />
-       <input type="text" name="q" size="31" maxlength="255" value="$search" />
-       <input type="submit" name="btnG" value="$googlesearch" />
-       <p>
-               <label><input type="radio" name="sitesearch" value="$server" checked="checked" />$sitename</label>
-               <label><input type="radio" name="sitesearch" value="" />WWW</label>
-       </p>
-</form>
-EOT;
-               return $trygoogle;
-       }
 }