Extension talk:HeadScript

Jump to navigation Jump to search

About this board

Seb35 (talkcontribs)

Given the number of comments on this talk page and on WikiApiary, it seems this extension is quite useful, the problem is that it is not really maintained and there will be probably more bugs over the years.

I’m wondering if it worth to put it in the common Wikimedia platform (Git+Gerrit+Phabricator), where maintenance will be easier. I will wait still a bit if the original author answers, else I will perhaps do the transfer. Any thought?

80.110.121.222 (talkcontribs)

I think it's a good idea!

Reply to "Maintenance of this extension"
Nicole Sharp (talkcontribs)
Reply to "license"
Z929669 (talkcontribs)

Will this print meta tags for SEO? I am using MW 1.21, and there don't seem to be any compatible extensions for that; however, this extension works fine for my GA script ... so was thinking I might be able to piggyback my meta tags as well.

Nicole Sharp (talkcontribs)

No. This is only for JavaScript (SCRIPT elements). I recommend WikiSEO or any number of similar MediaWiki extensions for adding META elements to HEAD. Nicole Sharp (talk) 07:55, 3 June 2019 (UTC)

Reply to "Can This Print <meta> Tags?"
Gryllida (talkcontribs)
S.Örvarr.S (talkcontribs)

I created a pull request half a month ago. Are you actively monitoring these extension repositories?

Nicole Sharp (talkcontribs)

Thanks for porting this to GitHub. It doesn't look like the original version from jingames.net by @JinRyuuNagy: has had any updates since November 2016, but the JinGames version still works on MediaWiki 1.31.1 LTS. Nicole Sharp (talk) 07:47, 3 June 2019 (UTC)

Reply to "git"

Instead of installing this extension...

3
WikiTeq (talkcontribs)

... which might be easier but also might cause problems, you could just add this to your LocalSettings.php:

$wgHooks['BeforePageDisplay'][] = function( OutputPage &$out, Skin &$skin ) {
     $code = <<<'START_END_MARKER'
<script></script>
<script></script>
<script></script>
START_END_MARKER;

     $out->addHeadItem( 'my-wonderful-script', $code );
     return true;
};

It does exactly the same thing as this extension.

104.142.125.214 (talkcontribs)

This grays out everything afterwards in LocalSettings.php in MediaWiki 32. Any idea how to fix?

104.142.125.214 (talkcontribs)
Reply to "Instead of installing this extension..."

different scripts for different pages

2
2001:16B8:305B:D400:12:F418:643D:B236 (talkcontribs)

i want to add different scripts to different pages, example the "mainpage" should have script A and all other sites should have script B. Is this possible?

0xMaker (talkcontribs)

jeah i want to do exactly the same thing. Would be nice if someone could help.

Reply to "different scripts for different pages"

Can I use the extension to place Fb's pixel on my wiki?

4
ZielonaMrowka (talkcontribs)

Hello! I wanted to add a Facebook's pixel to my wiki. It has to be placed in <head> of the website so I installed this extension and tried to add their script between <script></script> in LocalSettings.php. It does not work (I suppose that I'm placing the script in incorrect file :P) - probably "of course". The code after the </script> becomes grayed out (I use Notepad++) and colorizes back when I remove Fb's <script></script> body. The FB code looks as follows:

<script>
  !function(f,b,e,v,n,t,s)
  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
  n.callMethod.apply(n,arguments):n.queue.push(arguments)};
  if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
  n.queue=[];t=b.createElement(e);t.async=!0;
  t.src=v;s=b.getElementsByTagName(e)[0];
  s.parentNode.insertBefore(t,s)}(window, document,'script',
  'https://connect.facebook.net/en_US/fbevents.js');
  fbq('init', 'I_probaby_shouldn't_share_the_number_that_was_here');
  fbq('track', 'PageView');
</script>

Is there a way to include it with this extension and no knowledge in php?

109.192.67.232 (talkcontribs)

Same Problem with Google AdWords Conversion Tracking Script

109.192.67.232 (talkcontribs)

The problem seems to be: If the script uses apostrophes, the extension doesn't work.

Seb35 (talkcontribs)

PHP has a special syntax to deal easily with this issue about apostrophes inside strings, it’s called Heredoc or Nowdoc syntax. I’ve added some instructions in the Configuration section. For your initial question, you can use it that way:

$wgHeadScriptCode = <<<'START_END_MARKER'
<script>
  !function(f,b,e,v,n,t,s)
  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
  n.callMethod.apply(n,arguments):n.queue.push(arguments)};
  if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
  n.queue=[];t=b.createElement(e);t.async=!0;
  t.src=v;s=b.getElementsByTagName(e)[0];
  s.parentNode.insertBefore(t,s)}(window, document,'script',
  'https://connect.facebook.net/en_US/fbevents.js');
  fbq('init', 'I_probaby_shouldn't_share_the_number_that_was_here');
  fbq('track', 'PageView');
</script>
START_END_MARKER;
Reply to "Can I use the extension to place Fb's pixel on my wiki?"
Summary by Seb35

Was resolved, currently works.

Tapi0 (talkcontribs)

Link is not working.

Stefahn (talkcontribs)

Link still not working :/

Undefined variable

4
Summary by Seb35

Fix inside this discussion; added a section on the main page to help users facing this bug; message let to the author to fix it in the zip file.

Huwmanbeing (talkcontribs)

When I try to run maintenance/runJobs.php, I'm getting the following error:

PHP Notice:  Undefined variable: type in /var/www/eamon.wiki/public_html/mediawiki-1.30.0/extensions/HeadScript/HeadScript.php on line 3

I'm on MediaWiki 1.30.0 and have the latest HeadScript extension installed. Any idea what might be causing this problem? Huwmanbeing (talk) 18:04, 22 January 2018 (UTC)

John p new (talkcontribs)

HeadScript.php uses a (deprecated) array that adds the extension's information to the wiki's Special:Version page.

To fix the PHP error, in /path/to/mediawiki/extensions/HeadScript/HeadScript.php, change the following line (line 3):

$wgExtensionCredits[$type][] = array(

to

$wgExtensionCredits['specialpage'][] = array(

The developer simply forgot to replace $type with the proper value.

For a complete explanation of $wgExtensionCredits, see Manual:$wgExtensionCredits.

Huwmanbeing (talkcontribs)

That solved it. Thank you!

Djruess (talkcontribs)

That solved it for me too! I'm going to try and submit a change in the github repository.

Reply to "Undefined variable"
There are no older topics