User:Bawolff/how to use MikeSofaer's anti-SOPA js with MediaWiki

From MediaWiki.org
Jump to navigation Jump to search

There's lots of talk of blacking out sites to protest SOPA. Wikipedia is planning to have a giant banner, and Varnet is planning to make an extension to allow other mediawiki users to easily to join in the protest.

Another js black out app that some sites are using is here: http://mikesofaer.github.com/stop_censorship/

This can easily be installed on MediaWiki wikis, even if you don't have access needed to install extensions (You only need "Admin" or "Sysop" level access)

Note, these instructions are just adapted from [1]. I do not deserve any credit for this at all, this is all other people's work.


Method 1 (In Common.js)[edit]

This is perhaps the more proper way in many regards.

  • Go to the page Mediawiki:Common.js
  • Add to the bottom of the page:
addOnloadHook(function(){try{if(!window.CloudFlare){window.CloudFlare=[];
var a=document.createElement("script"),b=document.getElementsByTagName("head")[0];
a.type="text/javascript";a.async=!0;a.src="//ajax.cloudflare.com/cdn-cgi/nexp/cloudflare.js";
b.appendChild(a)}}catch(c){};var a=window.CloudFlare;
a.push({paths:{stop_censorship:"//ajax.cloudflare.com/cdn-cgi/nexp/apps/"}});
a.push(function(b,c){c("stop_censorship/config",function(){return {}});b(["stop_censorship"])});});
  • Hit save.

Downside to this method, is that (on older MediaWiki) users who have visited your site recently may have to do a hard refresh (ctrl+r) before seeing the censorship app. This is particularly a problem in older (pre 1.17) versions of MediaWiki, where it could be worked around by increasing $wgStyleVersion. In newer mediawiki this is less of an issue as RL is smarter about how js is cached, and js changes should take affect after about 5 minutes in general.

Method 2 (In the copyright message)[edit]

  • Go to the page MediaWiki:copyright on your wiki.
  • Edit (or create that page if it doesn't exist already), adding the following to the bottom:
            <script type="text/javascript"> var CloudFlare = CloudFlare || []; </script>
            <script type="text/javascript" src="//ajax.cloudflare.com/cdn-cgi/nexp/cloudflare.js" async></script>
            <script type="text/javascript">
                var censorshipConfig = {
                    "twitterHandle" : "", // Your Twitter handle; if not provided, your website domain will be used.
                    "position_x" : "right", // Badge position - right or left
                    "selector" : "p, h1, .censor_me", // Optional selector for elements to censor. Remove for default.
                    "regex" : ".{5}" //In case you like Regexes, and want to change the logic for how to black out text.
                    "persistent" : false //Make this true if you want the bars to appear on every page view, and not fade away when the box pops up.
                    }
                var a=window.CloudFlare;a.push({paths:{stop_censorship:"//ajax.cloudflare.com/cdn-cgi/nexp/apps/"}});a.push(function(b,c){c("stop_censorship/config",function(){return censorshipConfig});b(["stop_censorship"])});
            </script>
  • Hit save.

The downside to this approach, is this won't work on any special pages (like Special:Recentchanges). Depending on the caching strategy your website uses (in particular if it uses Squid cache or File cache) it may not show up for anonymous users [not a whole lot we can do about that, short of removing all the entries in the cache]. As an aside, some wiki hosts change where this message is located (for example, Wikimedia uses MediaWiki:Wikimedia-copyright instead). Additionally this method will only work if your wiki is set up to specify a license.

Other things you can do[edit]

The page MediaWiki:Sitenotice is included on all pages. You cannot put javascript in that page, but you can put arbitrary wikitext in there to display on all pages.

For example, adding the follow code to the page MediaWiki:Sitenotice on your wiki:

<div style="color:white !important;background-color:black !important;padding:1em;font-size:larger;text-align:center">
<big>'''WE NEED YOU TO PROTECT FREE SPEECH ONLINE'''</big><br/>

Please help us protest the Stop Online Piracy Act (SOPA) in the U.S. House of Representatives, and the PROTECTIP Act (PIPA) in the U.S. Senate.
If passed they will harm the free and open Internet. These bills endanger free speech both in the United States and abroad, potentially
setting a frightening precedent of Internet censorship for the world.

Today we ask you to take action.

To find out more, visit [http://americancensorship.org <span style="color:aqua !important">http://americancensorship.org</span>]
</div>

Which will produce a banner that looks like:

WE NEED YOU TO PROTECT FREE SPEECH ONLINE

Please help us protest the Stop Online Piracy Act (SOPA) in the U.S. House of Representatives, and the PROTECTIP Act (PIPA) in the U.S. Senate. If passed they will harm the free and open Internet. These bills endanger free speech both in the United States and abroad, potentially setting a frightening precedent of Internet censorship for the world.

Today we ask you to take action.

To find out more, visit http://americancensorship.org


Also make sure that mediawiki:Anonnotice either doesn't exist on your wiki, or also has the banner, or anonymous users will not see it.

See Manual:Interface/Sitenotice for more details.