Wikinews:Javascript

From Wikinews, the free news source you can write!
Jump to: navigation, search

The purpose of this page is to document the JavaScript used on Wikinews (right now it is more of an overview than documentation, but hopefully it is useful to someone). See also Wikinews:Skins. For information on enabling custom JavaScript for yourself, see meta:Help:User style.

If you discover a bug in the local javascript, or one of the gadgets, please report it at the bottom of this page.

Gadgets[edit]

Gadgets are optional functionality you can enable in your preferences.

  • See special:gadgets for full list. Some of the more popular ones are also listed here.

Hide fundraiser[edit]

Only available during fundraisers, hides the fundraiser notice.

Navigation popups[edit]

Copied from Wikipedia, so probably out of date. See Wikipedia:Tools/Navigation popups. Provides quick overviews of articles as you hover over text. See File:Popup-preview.png for an example.

HotCat[edit]

Imported from commons, allows easy insertion and removal of categories. For full documentation see Commons:Help:Gadget-HotCat.

WikEd[edit]

Stolen from Wikipedia. Adds syntax highlighting, and better editing toolbar. This directly loads the script from Wikipedia, so it should always be up to date. See w:User:Cacycle/wikEd for more details.

ReadyAlert[edit]

Adds to the sitenotice a list of articles currently needing to be reviewed, as well as a list of articles that are published but need to be re-flagged. Also includes how long the article has been waiting to be reviewed/flagged.

talkSeperate[edit]

Add a yellow border around different levels of indentation to make it easier to tell who is talking. Stolen from french Wikinews.

CommentWatch[edit]

If you add a page to your watchlist, also add the associated comment (opinion) page to your watchlist as well.

Wiktionary lookup gadget (Hover box variety)[edit]

FAQ[edit]

  • I want to use this, but at the same time I want to be able to double-click things without the pop-up coming up
    • hold down shift while double clicking
  • Can this be translated into <some language>
  • Can I use this on my website or wiki
    • Yes you can. See below for details on how to use on your own website. Ask user:Bawolff if you need help.
  • I know javascript and want to help with development of the script
  • I want to use this as a bookmarklet
    • Sure, just bookmark the following url (In firefox, highlight it and drag it to the toolbar)
      javascript:(function%20()%20%7Bvar%20src%20=%20document.createElement('script');src.type%20=%20'text/javascript';src.src%20=%20'http://en.wikinews.org/w/index.php?title=MediaWiki:WiktionaryLookup-external-bookmarklet.js&action=raw&ctype=text/javascript&scrver=1';document.getElementsByTagName('head')%5B0%5D.appendChild(src);%7D)();void%200
    • Alternatively, follow instructions at http://www.marklets.com/Bookmarklets/Wiktionary+lookup.aspx

Introduction[edit]

Screenshot of a definition given with the Look Up tool from the French Wiktionary

In short, double click a word, get its definition.

This gadget allows you to double click on a word, and a box will be overlaid showing the definition of that word. This gadget works, by detecting what is highlighted when you double-click on the page (double-clicking a word automatically highlights it). The gadget than looks up the word, using the following url http://en.wiktionary.org/w/api.php?action=parse&prop=text&format=xml&xslt=MediaWiki:extractFirst.xsl&page=Word (replacing word with the name of the word. It than displays that page in an overlay (absolutely positioned iframe for those familiar with html) on the current page. To close the overlay just click anywhere outside it. (preferably to the left or right of it. there is a little space directly under the overlay box which won't close [this is because it is actually a transparent part of the box, used to accomadate large definitions]).

A couple of notes

  • Internet explorer doesn't work with this gadget as of current. As a fall-back, it will just open up the relevent wiktionary page in a new window on internet explorer
    • This is due to mediawiki giving the xslt stylesheet the type of text/xml, which well technically correct, the real word requires text/xsl for cross-browser support.
  • If wiktionary has multiple definitions for a word, it will display the first one. This is not always the most relevent definition
  • Hopefully this will soon support searching for definitions in non-english. at the moment this only supports searching in english.
  • Holding down shift while double clicking will prevent the box from appearing. This can allow the gadget to be used in combination with the double-click to edit preference.
  • If you have any feature requests/suggestions/comments/bugs/hate-mail/love-mail etc. You can put them on MediaWiki talk:Gadget-dictionaryLookupHover.js or ask me directly.

How to install[edit]

On mediawiki wiki[edit]
  • If you want to enable this on your local wiki, add the following to somewhere where js is loaded:
importScriptURI('http://en.wikinews.org/w/index.php?title=MediaWiki:Gadget-dictionaryLookupHover.js&action=raw&ctype=text/javascript');
  • If you just want to enable it for yourself, put it in special:mypage/skinname.js (replacing skinname with your skin. for example special:mypage/monobook.js if monobook is your skin.)
  • If you want to enable it for everyone, put it in mediawiki:Common.js
  • If you want to make it a gadget, put the js snipit above in mediawiki:Gadget-wiktLookup.js . create mediawiki:Gadget-wiktLookup and put a description of the gadget in there (preferably with a link back here for bug reports). Add wiktLookup|wiktLookup.js to mediawiki:Gadgets-defintion .
On an arbitrary website (aka your blog)[edit]

Add the folowing somewhere into the html (preferably in the <head>, but should work anywhere:

<script src='http://en.wikinews.org/w/index.php?title=MediaWiki%3AWiktionaryLookup-external.js&amp;action=raw&amp;ctype=text/javascript' type='text/javascript'></script>

Note if for some reason you don't want to hot link hot-linking is highly recomended though), contact me (user:Bawolff) and i'll tell you how to set that up.

The script uses the lang attribute on the <html> element to determine the language of your website. You can also override this by setting a global js variable wgContentLanguage. For example: var wgContentLanguage = 'fr';. Theres some other options that can customize the script, but i havn't documented them yet (don't worry, they are not really useful).

Configuration options[edit]

This script has a number of configuration options. to configure add the following to somewhere where js is loaded (could be loaded before or after the script). For example on a wiki, if you wanted to configure for the entire site, it could be at mediawiki:Common.js . If its just for you, special:mypage/monobook.js (or special:mypage/vector.js if you use vector, etc for other skins). If its a blog, where ever you can execute js (for example, insert it between a <script> and </script> tags.

The following parameters are supported (prefix with wiktLookup.)

  • count - maximun number of definitions to display (defaults to 1; values other than 1 not well tested. Will only display a maximun of the number of definitions it can find.)
  • showWord - show the word that this definition is for. (use one of link, none, or bold. defaults to none)
  • noRedir - disable auto-redirection. for example disable mapping FOOD → food (not recomended).
  • preferLang - this is your user language. This is the language that the definition appears in (not the language that the word is assumed to be of) (don't mess with this unless you have a good reason. defaults to your mediawiki preference)
  • audio - One of true, false, autoplay. have audio pronounciation of word where available. Not yet implemented
  • height - how many pixels high the maximun size of the box should be. defaults to about 420
  • width - how many pixels wide the max size of box should be. defaults 180.
  • key - a single (lowercase) letter to specify the ctrl+shift+key combo. for example if you put wiktLookup.key = 'b', ctrl+shift+b will look up any word thats highlighted. defaults to 'l'. Note: sometimes the box will popup in weird places when looking up things by key combo.
  • reverseShift - Normally if you press shift, it stops the popup from coming up when double clicking. with this option, you have to press shift and double click for the pop up to come up.
  • disableByDefault Only enable in sections marked <span class="wiktLookup-enable"> foo bar baz </span>

For example, to use a count of 3 defintions, the bold showWord, a slightly wider box, add the following js:

if (!window.wiktLookup) wiktLookup = {};
wiktLookup.count = 3;
wiktLookup.showWord = 'bold';
wiktLookup.width = 220;

If you are on a wiki, you would either add it to special:mypage/monobook.js (replacing monobook with the skin you use) if you just want it for you, or mediawiki:Common.js if you want the options. If you are using an external website, such as blog, you would suround it with <script> tags, and insert it into the html source of your website.

If you are using this from a blog (not a wiki), you can also use the global variable wgContentLanguage to overide the assumed content language of your blog (it defaults to the lang attribute of the html element) This is used to figure out what language the word you clicked on is in. The global variable wgUserLanguage controls what language it is assumed the user speaks (aka what language to present the definition in).

Always enabled[edit]

mediawiki:Common.js[edit]

Rss Feeds[edit]

  • A <link> to http://toolserver.org/~zach/cgi-bin/rss.cgi?cat=<Category Name> is included for every category. This allows browsers like Firefox to put a little RSS icon in the corner linking to an RSS feed for recently published articles in that category only. The main feed is handled on mediawiki side.
  • Any portal page that has some element with the id rssFeedLink Will add a rss <link> for http://toolserver.org/~zach/cgi-bin/rss.cgi?cat=<Page name without portal prefix>. {{topic header}} and {{Region header}} automatically add such an id if it is detected there is a category with the same name as the portal in existence.

Dynamic Navigation[edit]

A script for the collapsible boxes you know and love. It was stolen from some other project a long time, and was modified so that there is an option to make the open boxes close if another one is opened (only one open at a time). This script is rather ugly, and could be much improved.

Tabber[edit]

script to create tab boxes. Created by by Patrick Fitzgerald, and released under an open source MIT license (go open source). Was modified slightly to suit our purposes. Creates tab boxes.

IRC box[edit]

Creates an IRC login box anytime you put <div id="cgiircbox"></div> on a page. Logs you into the wikizine cgi:irc web interface. Used to be used on WN:IRC, not anymore. Still on WN:V

Custom edit buttons[edit]

Adds a button to the edit toolbar for Linking to Wikipedia, and for creating redirects.

Comment crap[edit]

  • Script for making the comment namespace a pseudo-second-talk ns. (adds a opinions tab, and turns it red if it doesn't exist) Could be improved imho. Mostly contained in MediaWiki:Comments.js

Ticker[edit]

Shows a list of items, one at a time. If you're using an old computer, and don't want to waste cpu cycles, it can be disabled via a gadget, or by doing var disable_ticker2=true;.

Note: Historically we used a different ticker system - mediawiki:Ticker.js. It is no longer loaded by the english wikinews js, but some other languages use it.

Edit tools (MediaWiki:Edittools.js)[edit]

Add a drop down menu to the insert markup box that comes after the editbox.

per page customization[edit]

  • Loads [[mediawiki:common.css/<PageName>]] and [[mediawiki:Common.js/<pageName]] dependent on what page you're looking at. The following per page scripts/css currently exists.
Common.css/Main Page Common.css/Main Page Lite Common.css/Portal:Africa
Common.css/Portal:Asia Common.css/Portal:Australia Common.css/Portal:Brian McNeil - Sandbox
Common.css/Portal:Canada Common.css/Portal:Central America Common.css/Portal:Chile
Common.css/Portal:Europe Common.css/Portal:Illinois Common.css/Portal:Iran
Common.css/Portal:Middle East Common.css/Portal:North America Common.css/Portal:Oceania
Common.css/Portal:Pichilemu Common.css/Portal:Scotland Common.css/Portal:South America
Common.css/Portal:United Kingdom Common.css/Portal:United States Common.css/Special:RecentChanges
Common.css/Template:Main stories Common.css/Template:NewPortal Common.css/User:Bawolff/Sandbox/MessedRocker based main page redesign
Common.css/User:Bawolff/sandbox/alt citations Common.css/User:Bawolff/sandbox/horizInfobox Common.css/User:Bawolff/sandbox/leads
Common.css/User:Bawolff/sandbox/leads/fixed width 1280x1024 Common.css/User:Bawolff/sandbox/mockup based on tempo's local news idea Common.css/User:Bawolff/sandbox/powerFlag
Common.css/User:Bawolff/sandbox/ticker Common.css/User:Brian McNeil Common.css/User:Dendodge
Common.css/User:Dendodge/Country portal Common.css/User:Dendodge/Main Page Common.css/User:Dendodge/Portal example
Common.css/User:Dendodge/Portal headers Common.css/User:Dendodge/Region portal Common.css/User:Dendodge/Topic portal
Common.css/User:Diego Grez/old Common.css/User:Mono
Common.css/User:Mono/Sandbox2 Common.css/User:Rayboy8 Common.css/User:Rayboy8/Articles
Common.css/User:Rayboy8/Articles/101 to 200 Common.css/User:Rayboy8/Articles/1 to 100 Common.css/User:Rayboy8/Articles/201 to 300
Common.css/User:Rayboy8/Articles 101 to 200 Common.css/User:Rayboy8/Articles 1 to 100 Common.css/User:Rayboy8/Main page
Common.css/User:RockerballAustralia/main page rejig Common.css/User:RockerballAustralia/main page rejig 2 Common.css/User:ShakataGaNai/Main Page
Common.css/User:Tempodivalse/Main Common.css/User:TheFearow Common.css/User:The wub/Main Page
Common.css/User:Tristan Thomas Common.css/User talk:Brian McNeil Common.css/User talk:Diego Grez
Common.css/User talk:Rayboy8 Common.css/Wikinews:CommonsTicker Common.css/Wikinews:Education
Common.css/Wikinews:Education/About Common.css/Wikinews:Education/Let's begin Common.css/Wikinews:Education/Navigation
Common.css/Wikinews:Education/Teaching tool Common.css/Wikinews:Education/Welcome Common.css/Wikinews:IRC workshop/May 22, 2011
Common.css/Wikinews:Newsroom Common.css/Wikinews:Reusing Wikinews content Common.css/Wikinews:Sandbox with CSS
Common.css/Wikinews:Water cooler Common.css/Wikinews:Water cooler/miscellaneous/Archive/monobook.css Common.css/Wikinews:Who What When Why Where and How
Common.css/Wikinews:World News Quiz Common.css/Wikinews:Writing contest 2010 Common.css/test
Common.js/Category:Review Common.js/Main Page Common.js/Special:Contributions
Common.js/Special:MovePage Common.js/Template:Social bookmarks Common.js/User:BarkingFish
Common.js/User:Bawolff/idea Common.js/User:Bawolff/sandbox/MainPageHeader collapse Common.js/User:Bawolff/sandbox/Wiktionary query
Common.js/User:Bawolff/sandbox/alt citations Common.js/User:Bawolff/sandbox/catStats Common.js/User:Bawolff/sandbox/horizInfobox
Common.js/User:Bawolff/sandbox/leads Common.js/User:Bawolff/sandbox/leads/1024
Common.js/User:Bawolff/sandbox/powerFlag Common.js/User:Bawolff/sandbox/resizeEditbox Common.js/User:Bawolff/sandbox/tabs
Common.js/User:Bawolff/sandbox/ticker Common.js/User:Bawolff/sandbox/utcclockthingy Common.js/User:Bawolff/sandbox/wiki2text
Common.js/User:Brianmc/sandbox Common.js/User:Doldrums/Main page Common.js/User:Gryllida/GalleryThings
Common.js/Wikinews:Dialog Common.js/Wikinews:Dialog/do Common.js/Wikinews:Dialog/echo
Common.js/Wikinews:Dialog/xyzzy Common.js/Wikinews:Make lead Common.js/Wikinews:Newsroom
Common.js/Wikinews:Syndication

Social networking stuff[edit]

For use with template:Social bookmarks.

Custom Editintros[edit]

from wikipedia[edit]

We append &editintro=Template:Editintro_from_wikipedia to all the editlinks on any page, when the user has a referrer starting with http://en.wikipedia.org . This puts {{Editintro from wikipedia}} above the edit box.

not current[edit]

Any article that has a publish date (in {{date}}, or more accurately the date category that the date template adds) over 48 hours ago, is in category published, and not in category archived, has &editintro=template:Editintro_notcurrent to the end of all edit urls (unless they already have an edit intro). This makes {{Editintro notcurrent}} go on top of the edit box

Note if there is a conflict between not current, and from wikipedia, not current wins. This was a completely arbitrary decesion, it could be switched, or we could have another template when both apply if people would prefer that.

{{develop}} → {{review}}[edit]

Recognizes a span with a specific id (develop_to_review_link), that contains a link to edit the current page, and replaces it with a button that magically replaces {{Develop}} with {{review}}. Note you can change the text inside the link to change the text in the button, but do not change the link or the span, or add whitespace between the span and the link.

mediawiki:Monobook.js[edit]

Monobook only JavaScript

Alt stylesheets[edit]

  • Loads alternate stylesheets for the monobook skin. These can be accessed in Firefox and Opera. In Firefox it is under View→Page Style→ <stylesheet>.

Main Page stuff[edit]

Hides the title if skin is monobook, and page is main page (This should possibly be moved to css).

Mediawiki:Modern.js[edit]

  • Add the Wikinews logo to the left navigation bar.

Other Stuff[edit]

user:Bawolff/mwapilib.js/user:Bawolff/mwapilib2.js[edit]

Called by some of the per-page js, and some js in my (Bawolff's) userspace. Aims to make using the mediawiki api easier to use. Some docs at user:Bawolff/mwapilib

jQuery[edit]

Bugs[edit]

Please use this area to report bugs and/or feature requests (for gadgets or the core js. If its a gadget maintained on wikinews you can alternatively report it to the maintainer of that gadget)

  • DragonFire's supercool lead thingy.