Page MenuHomePhabricator

[GoogleCustomWikiSearch] Special:GoogleCustomWikiSearch fails silently
Open, Needs TriagePublic

Description

Setup

  • MediaWiki 1.35.1 (3ff1919) 01:03, 7 February 2021
  • PHP 7.3.19-1~deb10u1 (apache2handler)
  • MariaDB 10.3.27-MariaDB-0+deb10u1
  • ICU 63.1
  • GoogleCustomWikiSearch 0.5.0 beta (8c619e7) 14:05, 7 February 2021

Configuration

## GoogleCustomWikiSearch
wfLoadExtension( 'GoogleCustomWikiSearch' );
$wgGoogleCustomWikiSearchId = '**********';
$wgGoogleCustomWikiSearchReplaceSearch = false;
$wgGoogleCustomWikiSearchTheme = 'GREENSKY';
$wgGoogleCustomWikiSearchOptions = <<<END
    var customSearchOptions = {};
    var orderByOptions = {};
<script>
  (function() {
    var cx = '**********';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<gcse:search></gcse:search>
END;

Search ID obfuscated with **********.

Issue
Special page "GoogleCustomWikiSearch" fails silently, i.e. no errors logged.

Event Timeline

@Kizule FYI since you just recently worked on the extension. Perhaps you have a pointer to resolve. Will be much appreciated.

Aklapper renamed this task from Extension "Google Custom Wiki Search" / Special page "GoogleCustomWikiSearch" fails silently to [GoogleCustomWikiSearch] Special:GoogleCustomWikiSearch fails silently.Feb 13 2021, 5:43 PM

Hello @Kghbln, thank you very much for reporting this problem and I'm sorry because of it. I will check what's happening.

Thanks @Kizule for your recent patches. I'm inclined to archive the extension instead of adding this to the WikiTeq group. There already is a more popular (though unmaintained) extension with similar functionality. What do you think @Kizule?

Thanks @Kizule for your recent patches. I'm inclined to archive the extension instead of adding this to the WikiTeq group. There already is a more popular (though unmaintained) extension with similar functionality. What do you think @Kizule?

I'm not really sure, as and mentioned extension is unmaintained too.

I'm not really sure, as and mentioned extension is unmaintained too.

As a person interested in this functionality this is a concern, too. Moreover this on allows to replace the wiki search which the other one does not. :)

I understand. Let's try to fix this one.

This is happening to you, when you want to open the special page, right?

I understand. Let's try to fix this one.

This will be great!

This is happening to you, when you want to open the special page, right?

Affirmative!

I only found this:

index.php?title=Посебно:GoogleCustomWikiSearch:199 Mixed Content: The page at 'https://wiki.kizule.ga/index.php?title=%D0%9F%D0%BE%D1%81%D0%B5%D0%B1%D0%BD%D0%BE:GoogleCustomWikiSearch' was loaded over HTTPS, but requested an insecure script 'http://www.google.com/cse/cse.js?theme=GREENSKY&language=en&cx=21c257af9bd496012'. This request has been blocked; the content must be served over HTTPS.

I got this working, but when I visit Special:GoogleCustomWikiSearch, It shows this content and downloads some txt file.

diff --git a/includes/GoogleCustomWikiSearch.php b/includes/GoogleCustomWikiSearch.php
index 30e271c..1477df3 100644
--- a/includes/GoogleCustomWikiSearch.php
+++ b/includes/GoogleCustomWikiSearch.php
@@ -183,8 +183,7 @@ window.__gcse = {
        var cx = '{$this->getId()}';
        var gcse = document.createElement('script'); gcse.type = 'text/javascript';
        gcse.async = true;
-       gcse.src = (document.location.protocol == 'https' ? 'https:' : 'http:') +
-               '//www.google.com/cse/cse.js?theme={$this->getTheme()}&language={$this->getLanguage()->getCode()}&cx=' + cx;
+       gcse.src = document.location = 'https://' + 'www.google.com/cse/cse.js?theme={$this->getTheme()}&language={$this->getLanguage()->getCode()}&cx=' + cx;
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
 })();
 END;

Change 664299 had a related patch set uploaded (by Gerrit Patch Uploader; owner: Zoranzoki21):
[mediawiki/extensions/GoogleCustomWikiSearch@master] Unbreak Special:GoogleCustomWikiSearch and bump required version of the MediaWiki to 1.35+

https://gerrit.wikimedia.org/r/664299

Looking at your patch makes me think that adding all of this to "LocalSettings.php" is probably not the way to do it:

<script>
  (function() {
    var cx = '**********';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<gcse:search></gcse:search>

When creating new code the most basic code for embedding on your website you get is:

<script async src="https://cse.google.com/cse.js?cx=**********"></script>
<div class="gcse-search"></div>

Probably this is what you would like to replace /* lots of other Google code here */ with as documented on wiki?

EDIT; Obviously I have not understood yet what code to add to $wgGoogleCustomWikiSearchOptions the Google script is not found at all.

Looks like you're right. I've tried to replace your code with Google's generated, but the same bug happens.

Looks like you're right. I've tried to replace your code with Google's generated, but the same bug happens.

I guess it is time to take a rest and think about this a bit more. :) Anyhow I am really happy that you at least tried to make a difference. Much appreciated.