Jump to content

Extension:PCR GUI Inserts

From mediawiki.org
MediaWiki extensions manual
PCR GUI Inserts
Release status: beta
Implementation Skin , MyWiki
Description Lets you easily add pieces of HTML code at several useful places of the GUI
Author(s) Patheticcockroachtalk
Latest version 2.0.4 (original)
3.0.0 (fork) (2023-11-24)
MediaWiki 1.35-1.38 (original)
1.35+ (fork)
PHP 7.3.19+
License Creative Commons Attribution Share Alike 4.0
Download
README
CHANGELOG

$wgPcrGuiHeadItems, $wgPcrGuiMetaItems, $wgPcrGuiSidebarItems, $wgPcrGuiDisplayBottom,

$wgPcrGuiScripts
Translate the PCR GUI Inserts extension if it is available at translatewiki.net

The PCR GUI Inserts extension lets you add pieces of HTML code at the top, bottom or below the sidebar of your wiki, the Graphical user interface (GUI) area. There is no limit to what you can add within these areas.

The idea for this extension came from the observation that adding a simple item to a wiki, like a stat-tracking script or a donation button, although easy in theory, is still quite tedious. Before you needed to either:

Install one extension for every feature causes problems:

  • first, you end up with quite a lot of tiny extensions, and
  • second, sometimes there isn't the extension you need to add one specific element. For example, what if you wanted to insert Ad Bard ads? No extension is able to do this currently.

That's where PCR GUI Inserts is useful: it handles the hooks, and only the hooks, and you handle the HTML code, all the HTML code.

This forked version of PCR GUI Inserts is currently maintained by WikiMANNia.

Installation

[edit]
  • Download and move the extracted PCRGUIInserts folder to your extensions/ directory.
    Developers and code contributors should install the extension from Git instead, using:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/PCRGUIInserts
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'PCRGUIInserts' );
    
  • Configure at your convenience.
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Configuration

[edit]

By default, the extension won't output anything. You can edit the following settings in LocalSettings.php (add them after the line which includes the extension):

Add to the top of the wiki

[edit]

Version 2

[edit]

$wgPCRguii_Inserts['addHeadItem'] is used to add items at the end of the <head></head> area. For meta-tags or if you want to add a script at the top:

  • $wgPCRguii_Inserts['addHeadItem']['on']: boolean, whether or not to enable this feature (default: false)
  • $wgPCRguii_Inserts['addHeadItem']['content']: an array of things you want to insert there, for instance:
$wgPCRguii_Inserts['addHeadItem']['on'] = true;

$wgPCRguii_Inserts['addHeadItem']['content'] = [
    '<script type="text/javascript">window.google_analytics_uacct = "688797";</script>',
    '<meta name="robots" content="noarchive" />'
    ];

Version 3

[edit]

$wgPcrGuiHeadItems is used to add items at the end of the <head></head> area. For meta-tags or if you want to add a script at the top:

Disable with $wgPcrGuiHeadItems = [];

$wgPcrGuiHeadItems = [
    '<script type="text/javascript">window.google_analytics_uacct = "688797";</script>',
    '<meta name="robots" content="noarchive" />'
    ];

You will want to keep statistics at the bottom for faster content loading.

Version 3 only

[edit]

$wgPcrGuiMetaItems is used to add meta entries into the <head></head> area. (See as an example Extension:AgeClassification)

Disable with $wgPcrGuiMetaItems = [];

$wgPcrGuiMetaItems = [
    "age-de-meta-label",
    "age=0 hash: 7217284da5 v=1.0 kind=sl protocol=all"
    ];

Add to the bottom of pages

[edit]

Version 2

[edit]

$wgPCRguii_Inserts['BeforePageDisplay'] adds items at the end of a page, at the bottom but still within the content frame.

  • $wgPCRguii_Inserts['BeforePageDisplay']['on']: boolean, whether or not to enable this feature (default: false)
  • $wgPCRguii_Inserts['BeforePageDisplay']['content']: a string of things you want to insert, for instance:
$wgPCRguii_Inserts['BeforePageDisplay']['on'] = true;

$wgPCRguii_Inserts['BeforePageDisplay']['content'] =
    '<p>Something at the bottom of every page.</p>';

Version 3

[edit]

$wgPcrGuiDisplayBottom adds items at the end of a page, at the bottom but still within the content frame.

Disable with $wgPcrGuiDisplayBottom = "";

$wgPcrGuiDisplayBottom =
    '<p>Something at the bottom of every page.</p>';

Add to the bottom of the wiki

[edit]

Version 2

[edit]

$wgPCRguii_Inserts['SkinAfterBottomScripts'] adds items at the very bottom of a page, below the footer including the "Powered by MediaWiki" button. This is usually where you'll want to add tracking scripts.

  • $wgPCRguii_Inserts['SkinAfterBottomScripts']['on']: boolean, whether or not to enable this feature (default: false)
  • $wgPCRguii_Inserts['SkinAfterBottomScripts']['content']: a string of things to insert there, for example Google Analytics and Quantcast tracking:
$wgPCRguii_Inserts['SkinAfterBottomScripts']['on'] = true;

$wgPCRguii_Inserts['SkinAfterBottomScripts']['content'] = '
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-606677-2");
pageTracker._trackPageview();
} catch(err) {}</script>

<!-- Start Quantcast tag -->
<script type="text/javascript">
_qoptions={
qacct:"p-53OjVXxXxXxX2"
};
</script>
<script type="text/javascript" src="http://edge.quantserve.com/quant.js"></script>
<noscript>
<img src="http://pixel.quantserve.com/pixel/p-53OjVXxXxXxX2.gif" style="display: none;" border="0" height="1" width="1" alt="Quantcast"/>
</noscript>
<!-- End Quantcast tag -->
';

Version 3

[edit]

$wgPcrGuiScripts adds items at the very bottom of a page, below the footer including the "Powered by MediaWiki" button. This is usually where you'll want to add tracking scripts.

Disable with $wgPcrGuiScripts = "";

$wgPcrGuiScripts = '
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-606677-2");
pageTracker._trackPageview();
} catch(err) {}</script>

<!-- Start Quantcast tag -->
<script type="text/javascript">
_qoptions={
qacct:"p-53OjVXxXxXxX2"
};
</script>
<script type="text/javascript" src="http://edge.quantserve.com/quant.js"></script>
<noscript>
<img src="http://pixel.quantserve.com/pixel/p-53OjVXxXxXxX2.gif" style="display: none;" border="0" height="1" width="1" alt="Quantcast"/>
</noscript>
<!-- End Quantcast tag -->
';

Add below the side bar

[edit]

Version 2

[edit]

$wgPCRguii_Inserts['SkinBuildSidebar'] adds items below the side bar. For vertical ads or a donation button.

  • $wgPCRguii_Inserts['SkinBuildSidebar']['on']: boolean, whether or not to enable this feature (default: false)
  • $wgPCRguii_Inserts['SkinBuildSidebar']['content'] example:
$wgPCRguii_Inserts['SkinBuildSidebar']['on'] = true;

$wgPCRguii_Inserts['SkinBuildSidebar']['content'] = [
    ['Donate','<a href="http://my.paypal.com/donation/link">This is a donation button</a>'],
    ['Ads by Google','<script type="text/javascript"><!--
        google_ad_client = "pub-9471398824076666";
        google_ad_slot = "3512091103";
        google_ad_width = 120;
        google_ad_height = 240;
        //-->
        </script>
        <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>']
    ];

Version 3

[edit]

$wgPcrGuiSidebarItems adds items at the very bottom of a page, below the footer including the "Powered by MediaWiki" button. This is usually where you'll want to add tracking scripts.

Disable with $wgPcrGuiSidebarItems = [];

Note: In MediaWiki REL1_39 and above injecting HTML with the onSkinBuildSidebar hook is no longer supported. (See Extension:WimaAdvertising)

$wgPcrGuiSidebarItems = [
    ['Donate','<a href="http://my.paypal.com/donation/link">This is a donation button</a>'],
    ['Ads by Google','<script type="text/javascript"><!--
        google_ad_client = "pub-9471398824076666";
        google_ad_slot = "3512091103";
        google_ad_width = 120;
        google_ad_height = 240;
        //-->
        </script>
        <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>']
    ];

A few more practical examples

[edit]

Adding an Ad Bard ad in the sidebar

[edit]
$wgPCRguii_Inserts['SkinBuildSidebar']['on'] = true;

$wgPCRguii_Inserts['SkinBuildSidebar']['content'] = [
    ['Ads by Ad Bard', '<script type="text/javascript">
//<![CDATA[
var ab_h = "78448ff83a4ba39c3ba830a237a687fe";
var ab_s = "4c509963b61400983724025a4f058a21";
//]]>
</script>
<script type="text/javascript" src="http://cdn1.adbard.net/js/ab1.js"></script>']
    ];

Adding a StatCounter statistics code at the bottom

[edit]

Version 2

[edit]
$wgPCRguii_Inserts['SkinAfterBottomScripts']['on'] = true;

$wgPCRguii_Inserts['SkinAfterBottomScripts']['content'] = '<a href="http://my.statcounter.com/project/standard/stats.php?project_id=1425953&amp;guest=1"><img src="http://c12.statcounter.com/counter.php?sc_project=142953&amp;java=0&amp;security=7dss7e54" width="88" height="31" style="display:none" alt="counter" /></a>';

Version 3

[edit]

Disable with $wgPcrGuiScripts = "";

$wgPcrGuiScripts = '<a href="http://my.statcounter.com/project/standard/stats.php?project_id=1425953&amp;guest=1"><img src="http://c12.statcounter.com/counter.php?sc_project=142953&amp;java=0&amp;security=7dss7e54" width="88" height="31" style="display:none" alt="counter" /></a>';

Verifying site ownership with Google Webmaster Central

[edit]

Version 2

[edit]
$wgPCRguii_Inserts['addHeadItem']['on'] = true;

$wgPCRguii_Inserts['addHeadItem']['content'] = ['<meta name="google-site-verification" content="HFMLKJFDfds54Ui10u_XfF0zLt47tJFgLpWv4ghUA" />'];

Version 3

[edit]
$wgPcrGuiMetaItems = [
    "google-site-verification",
    "HFMLKJFDfds54Ui10u_XfF0zLt47tJFgLpWv4ghUA"
    ];

Adding a Piwik statistics code at the bottom

[edit]
$wgPCRguii_Inserts['SkinAfterBottomScripts']['on'] = true;
$wgPCRguii_Inserts['SkinAfterBottomScripts']['content'] = <<<EOF
<!-- Piwik -->
<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
  _paq.push(["setDomains", ["*.example.org"]]);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//example.org/piwik/";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', 1]);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<noscript><p><img src="//example.org/piwik/piwik.php?idsite=1" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->
<!-- Piwik Image Tracker-->
<img src="http://example.org/piwik/piwik.php?idsite=1&rec=1&action_name=Example" style="border:0" alt="" />
<!-- End Piwik -->
EOF;

Fork

[edit]
Version 3.0.0
https://github.com/WikiMANNia/mediawiki-extensions-PCRGUIInserts

See also

[edit]