This is the workshop support page for the user script ViewAsOutline-Glossary.js. Comments and requests concerning the program are most welcome. Please post discussion threads below the section titled Discussions. Thank you. By the way, the various scripts I have written are listed at the bottom of the page.
This script is under development, and is not yet functional
Script's workshop
This is the work area for developing the script and its documentation. The talk page portion of this page starts at #Discussions, below.
Description / instruction manual for ViewAsOutline-Glossary.js
This script is under development, and is not yet functional
When completed,
this script will
How to install this script
Important: this script was developed for use with the Vector skin (it's Wikipedia's default skin), and might not work with other skins. See the top of your Preferences appearance page, to be sure Vector is the chosen skin for your account.
To install this script, add this line to your vector.js page:
Save the page and bypass your cache to make sure the changes take effect. By the way, only logged-in users can install scripts.
Explanatory notes (source code walk-through)
This section explains the source code, in detail. It is for JavaScript programmers, and for those who want to learn how to program in JavaScript. Hopefully, this will enable you to adapt existing source code into new user scripts with greater ease, and perhaps even compose user scripts from scratch.
You can only use so many comments in the source code before you start to choke or bury the programming itself. So, I've put short summaries in the source code, and have provided in-depth explanations here.
My intention is Threefold:
to thoroughly document the script so that even relatively new JavaScript programmers can understand what it does and how it works, including the underlying programming conventions. This is so that the components and approaches can be modified, or used again and again elsewhere, with confidence. (I often build scripts by copying and pasting code that I don't fully understand, which often leads to getting stuck). To prevent getting stuck, the notes below include extensive interpretations, explanations, instructions, examples, and links to relevant documentation and tutorials, etc. Hopefully, this will help both you and I grok the source code and the language it is written in (JavaScript).
to refresh my memory of exactly how the script works, in case I don't look at the source code for weeks or months.
to document my understanding, so that it can be corrected. If you see that I have a misconception about something, please let me know!
In addition to plain vanilla JavaScript code, this script relies heavily on the jQuery library.
mw is the alias for mediawiki (the mediawiki library)
These two aliases are set up like this:
(function(mw,$){}(mediaWiki,jQuery));
That also happens to be a "bodyguard function", which is explained in the section below...
Bodyguard function
The bodyguard function assigns an alias for a name within the function, and reserves that alias for that purpose only. For example, if you want "t" to be interpreted only as "transhumanist".
Since the script uses jQuery, we want to defend jQuery's alias, the "$". The bodyguard function makes it so that "$" means only "jQuery" inside the function, even if it means something else outside the function. That is, it prevents other javascript libraries from overwriting the $() shortcut for jQuery within the function. It does this via scoping.
The bodyguard function is used like a wrapper, with the alias-containing source code inside it, typically, wrapping the whole rest of the script. Here's what a jQuery bodyguard function looks like:
1(function($){2// you put the body of the script here3})(jQuery);
The ready() event listener/handler makes the rest of the script wait until the page (and its DOM) is loaded and ready to be worked on. If the script tries to do its thing before the page is loaded, there won't be anything there for the script to work on (such as with scripts that will have nowhere to place the menu item mw.util.addPortletLink), and the script will fail.
The part of the script that is being made to wait goes inside the curly brackets. But you would generally start that on the next line, and put the ending curly bracket, closing parenthesis, and semicolon following that on a line of their own), like this:
1$(function(){2// Body of function (or even the rest of the script) goes here, such as a click handler.3});
Initially each script I write is made to work only on the vector skin, the skin under which I developed it, and by default the only skin for which it is initially tested with. To limit the script to working for vector only, I use the following if control structure:
if(mw.config.get('skin')==='vector'){}
To test it with another skin, remove or comment out the above code from the script.
Change log for ViewAsOutline-Glossary.js
2018-01-06
Start script
Make headings go bye bye
2018-01-17
Insert wikicode
Leading asterisk
Wrap linked items with ]
2018-01-17
Insert en dashes
Remove newline between dt and dd elements (thanks to Evad37)
Process entries for annotation grammar
Strip out A, An, The
Decapitalize first letter
Task list
Bug reports
Some of the leading letters are supposed to be capitalized. But they're not.
n. an interest, or tenure, in land where the holder's title deeds were copy of the entries kept by the lord of the manor. It was incrementally abolished from 1841 to 1925.
RedlinksRemover.js – remove red linked list items that are end nodes (last item of a branch), reiteratively, and delink the rest, from outlines and lists.
Search results page enhancements
SearchSuite.js – suite of search features, each on a switch, so you can turn them on and off as desired (and it remembers the switch positions). SearchSuite replaces all the search scripts below.
StripSearchSorted.js – provides menu item that turns sorted strip search on/off; Includes the features of all the other search scripts below, and sorts the results alphabetically. Co-written by User:Evad37; he did the heavy-duty programming. StripSearch.js – provides menu item that turns strip search on/off; strips search results down to bare pagenames. StripSearchSansRedirecteds.js – strips search results down to bare pagenames, with redirected entries removed. No off switch. StripSearchInWikicode.js – strips search results down to bare pagenames, and presents as bullet list with pagenames enclosed in double square bracket link delimiters (just like in wikicode). Redirected entries are also removed. No off switch.
StripSearchSimple.js – strips all search results down to bare pagenames. No off switch.
Viewing enhancements for list and outline editors hunting for list items
ViewAsOutline-AllPagesWithPrefix.js – adds list item wikicodes to the on screen results of All pages with prefix, for easy copying/pasting into outlines and lists. No off switch.
ViewAsOutline-Category.js – removes the alphabetical headings, and adds list item wikicodes, for easy copying/pasting into outlines and lists. No off switch. ViewAsOutline-Book.js – converts page to outline format on screen, with wikicodes for easy copy and paste into outlines and lists. No off switch. ViewAsOutline-CategoryTree.js – on menu item click, converts tree to outline format on screen, with wikicodes for easy copying/pasting into outlines and lists. Refresh page to undo. ViewAsOutline-Templates.js – converts navboxes and sidebar boxes on current page into outline format, with wikicodes displayed, for easy copying/pasting into outlines. No off switch. (Needs to be enhanced to show base links rather than pipes.)
ViewAsOutline-Glossary.js – converts glossaries to list format on screen, with wikicodes for easy copy-and-paste into outlines and lists. No off switch. (In early development, very rough. Currently, only converts bullet list glossary format.).
Coming eventually
QuickPortal.js – portal tool, for creating and restarting portals. Will be expanded for modification and maintenance as well.
OutlineDedupeHolding.js – remove duplicate list items from the outline's holding sections (See also, holding bin, place these, general concepts, and list section). That is, it will remove from each of these sections, in turn, all topics that exist anywhere else in the body of the page (not in templates). StripSearchFilter.js – narrow down search results. OutlineMain2LI.js – convert main links in outline to list items. TopicPlacerFromBin.js – Topic placer (loads topics from holding bin into an array, then assists in placing each one). For use on lists and outlines. FetchCategory.js – import category to present location. FetchCategories.js – import categories to tagged locations. FetchSection.js – import section to present location.
TopicSender.js – prompts for parent topic (outline), then checks
if it is already there, if it isn't, then it sends it to the receiving section of that outline) PlaceCategory.js –
OutlineViewConventional.js – change the viewed formatting of the current outline into that of a conventionally indented outline, without headings.