Difference between revisions of "Mediawiki Google PlusOne"
Jump to navigation
Jump to search
m (Created page with "This is just a little hack to add the [http://www.google.com/+1/button/ Google +1 button] to a mediawiki installation. See technical notes on [https://www.google.com/intl/en/webm…") |
m |
||
Line 30: | Line 30: | ||
</source> |
</source> |
||
− | And make sure you |
+ | And make sure you invalidate the server cache. One easy way is to [https://secure.wikimedia.org/wikipedia/mediawiki/wiki/Manual:$wgCacheEpoch add the following] to your LocalSettings.php to clean the cache whenever LocalSettings.php is edited: |
<source lang=php> |
<source lang=php> |
||
$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) ); |
$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) ); |
Latest revision as of 09:28, 1 September 2011
This is just a little hack to add the Google +1 button to a mediawiki installation. See technical notes on integrating Google +1 button for webmasters
Simply add the following snipped to your LocalSettings.php.
Remarks:
- It will add a button between title and article content.
- I chose to move it to the right for aesthetic reasons, cf "div align=right", feel free to modify
- I enforced the html attribute on g:plusone to avoid some special URLs to be taken into account instead of the canonical one, e.g. a button on http://wiki.yobi.be/index.php?title=Main_Page&action=print will actually link to http://wiki.yobi.be/wiki/Main_Page
- Because I used hook ArticleViewHeader, it will only display the button on article pages, and not on edition, history, etc.
# Google Plus
$wgHooks['BeforePageDisplay'][] = 'fnPlusOneJavaScript';
function fnPlusOneJavaScript( $out )
{
$script = '<script type="text/javascript" language="javascript" src="https://apis.google.com/js/plusone.js">'
. '</script>';
$out->addScript( $script);
return true;
}
$wgHooks['ArticleViewHeader'][] = 'fnPlusOneAnchor';
function fnPlusOneAnchor( &$article, &$outputDone, &$pcache )
{
global $wgOut;
global $wgTitle;
$wgOut->addHTML('<div align=right><g:plusone size="medium" href="' . $wgTitle->escapeLocalUrl() . '"></g:plusone></div>');
return true;
}
And make sure you invalidate the server cache. One easy way is to add the following to your LocalSettings.php to clean the cache whenever LocalSettings.php is edited:
$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
From v1.17 of mediawiki you can use this instead:
$wgInvalidateCacheOnLocalSettingsChange = true;