I just upgraded Citizendium to PHP 8.x and MediaWiki 1.39.x . The developer had to make some slight changes to the code for this extension in order to make it work with PHP 8.x. Is there someone here who could update this extension for others so that it will be available when other sites need it? I can be reached at manager A T citizendium.org
Extension talk:HeadScript
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?
I think it's a good idea!
I just changed the status to unmaintained. I guess it is time to transfer since the original author has not replied yet.
I make a pache of it with MediaWiki 1.34.1 and PHP 7.4.6 on FreeBSD.
Have fun!
--- HeadScript.php.org 2015-08-06 22:13:56.000000000 +0900 +++ HeadScript.php 2020-06-07 04:13:36.000000000 +0900 @@ -1,28 +1,31 @@ <?php -$wgExtensionCredits[$type][] = array( +if( !defined( 'MEDIAWIKI' ) ) { + echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" ); + die( 1 ); +} + +$wgExtensionCredits['parserhook'][] = array( 'path' => __FILE__, 'name' => "HeadScript", 'description' => "Allows Scripts to be added just before </head> to the wiki as configured in the LocalSettings.php file.", // 'descriptionmsg' => "", - 'version' => 1.0, + 'version' => '1.0.1', 'author' => "JinRyuu", 'url' => "http://www.mediawiki.org/wiki/Extension:HeadScript", + 'license-name' => 'MIT' ); -//Explicitly defining global variables - -$wgHeadScriptCode = '<!-- No Head Script -->'; -$wgHeadScriptName = '<!-- No Script Name -->'; - //Code for adding the head script to the wiki - $wgHooks['BeforePageDisplay'][] = 'HeadScript'; + function HeadScript( OutputPage &$out, Skin &$skin ) { - global $wgHeadScriptCode, $wgHeadScriptName; - - $out->addHeadItem($wgHeadScriptName, $wgHeadScriptCode ); + global $wgHeadScriptCode; + + if( !empty( $wgHeadScriptCode ) ) { + $out->addHeadItem('HeadScript', $wgHeadScriptCode ); + } return TRUE; }
Muchas gracias puedo tener tu correo electronico?
Since there are lots of work should be done to adapt new version of MediaWiki, I think it is necessary to do the transfer now.
I noticed that when this extension is installed, under "special:version
," it just says "License: License" instead of listing the license used for the extension (GNU General Public License 2.0). That should probably be fixed. More confusingly, the license wikilinked to is "The MIT License" (Special:Version/License/HeadScript
) and not the GNU General Public License 2.0. Not sure if the two licenses are equivalent or not. Nicole Sharp (talk) 10:10, 3 June 2019 (UTC)
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.
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)
Created a git repository now https://github.com/SvetlanaTkachenko/mediawiki-extension-HeadScript any issues may be reported (and/or patched!) there. I welcome the original author to join this project with push access.
I created a pull request half a month ago. Are you actively monitoring these extension repositories?
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)
... 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.
This grays out everything afterwards in LocalSettings.php in MediaWiki 32. Any idea how to fix?
The following snippet worked for my version when the code above didn't, no plugin needed. Snippets/Load an additional JavaScript or stylesheet file on all pages
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?
jeah i want to do exactly the same thing. Would be nice if someone could help.
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?
Same Problem with Google AdWords Conversion Tracking Script
The problem seems to be: If the script uses apostrophes, the extension doesn't work.
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;
Link is not working.
Link still not working :/
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)
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.
That solved it. Thank you!
That solved it for me too! I'm going to try and submit a change in the github repository.
There are no older topics