_ _ _ _____ ___ __ __ _(_) | _(_)___ / ( _ ) / /_ ___ ___ _ __ ___ \ \ /\ / / | |/ / | |_ \ / _ \| '_ \ / __/ _ \| '_ ` _ \ \ V V /| | <| |___) | (_) | (_) | (_| (_) | | | | | | \_/\_/ |_|_|\_\_|____/ \___/ \___(_)___\___/|_| |_| |_|
When completed, this script will remove duplicate list items from section (e.g.: See also, holding bin, general concepts, list section, etc.). That is, it will remove from the current section all topics that exist anywhere else in the body of the page (not in templates).
When completed, this script will remove duplicate list items from section (e.g.: See also, holding bin, general concepts, list section, etc.). That is, it will remove from the current section all topics that exist anywhere else in the body of the page (not in templates).
This is useful for culling lists of links gathered to a holding area (in an outline) awaiting placement into the outline. It can also help cleaning up the General concepts sections, List sections, and See also sections of outlines.
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:
importScript("User:The Transhumanist/OutlineDedupeHolding.js");
Save the page and bypass your cache to make sure the changes take effect. By the way, only logged-in users can install scripts.
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:
In addition to plain vanilla JavaScript code, this script relies heavily on the jQuery library.
If you have any comments or questions, feel free to post them at the bottom of this page under Discussions. Be sure to {{ping}} me when you do.
(general approach goes here)
More specifically, starting at the beginning...
An alias is one string defined to mean another. Another term for "alias" is "shortcut". In the script, the following aliases are used:
$
is the alias for jQuery (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...
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 here
3 } ) ( jQuery );
See also: bodyguard function solution.
To extend that to lock in "mw" to mean "mediawiki", use the following (this is what the script uses):
1 ( function(mw, $) {
2 // you put the body of the script here
3 } ) (mediawiki, jQuery);
For the best explanation of the bodyguard function I've found so far, see: Solving "$(document).ready is not a function" and other problems (Long live Spartacus!)
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.
In jQuery, it looks like this: $( document ).ready(function() {});
You can do that in jQuery shorthand, like this:
$().ready( function() {} );
Or even like this:
$(function() {});
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 });
This is all explained further at the jQuery page for .ready()
For the plain vanilla version see: http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
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.
I was discussing using "Place these" as the name of a holding section, but that would violate SRTA. A subheading under See also, called "Other" would be less obtrusive. But might already exist elsewhere in the outline; I'll deal with that when I encounter it.
This script will run on several holding sections:
It should remove a holding section if it is empty.
This script should process the see also section, the general concepts section, the list section, and the "Other" section.
See User:Ucucha/duplinks (highlights duplicate links, which means it must find them).
See User:Evad37/duplinks-alt (highlights duplicate links, which means it must find them).
See User talk:The Transhumanist/RedlinksRemover.js (edits an article to delete something - adapt it to delete duplicate list entries that don't have an annotation).
Based on discussion below, RedlinksRemover.js probably has all the technology in it that this script needs: regex applied to removing list items, in a nested loop.
This conducts semi-automated editing, and therefore needs to be on a menu item. (Should not run by default).
By the way, do I need to load any dependencies for the following code?
// ============== activation filters ==============
// Only activate on Vector skin
if ( mw.config.get( 'skin' ) === 'vector' ) {
Do all "mw." lines have dependencies? The Transhumanist 13:40, 1 January 2018 (UTC)
mw.config
is always available, and contains lots of other useful stuff – see mw:mw.config. Other mw modules, detailed at mw:ResourceLoader/Core modules, aren't necessarily available unless you load them – see mw:ResourceLoader/Migration_guide_(users)#mw.loader for further details. - Evad37 14:10, 1 January 2018 (UTC)
This is very exciting. That's one more step in one of the city outline building approaches that gets sped up...
Steps 3, 4, and 5 are currently done manually, but 3 (copy/paste) isn't as tedious, so 4 and 5 have priority.
Since deduping is more complicated after links are placed, developing this first, makes the most sense.
The Outline of Chicago is currently being drafted, using the above steps...
Step 1: See all the redlinks? Those are from the Template:Outline city. Many of the links in the template do not apply to Chicago, and so they turn red, but you never know what all is going to turn red when you first start a city outline, and they are time consuming to remove by hand. So, what we do is populate the outline with all the topics we can find, and then strip out the redlinks in step 6. The RedlinksRemover doesn't remove red entries that have children, it just delinks them. But, when the outline first starts out, most of the redlinks don't have children. If we strip them out too soon, we'll wind up having to type many of them back in when we find children topics for them.
Step 2: Here's where StripSearchSorted with TrueMatch comes in. You do some intitle searches, such as "in Chicago". Increase the limit in the url to 5,000 to get the maximum results you can at once. That produces the results here: https://en.wikipedia.org/w/index.php?title=Special:Search&limit=5000&offset=0&profile=default&search=intitle%3A%22of+Chicago%22&searchToken=bvc5dp6q7ldd4ayxph2a6ixg
Step 3: We copy and paste them to the "Place these" section in the outline (under See also). We repeat step 2 with further intitle searches (such as "of Chicago") and other gathering methods and send them all to "Place these" until we have all the topics we can find.
Step 4: The problem we have now is that many of the links in the "Place these" section are already in the body of the outline, like Culture of Chicago, Demographics of Chicago, and so on. And links may be duplicated in the "Place these" section itself. Therefore, we need to dedupe (remove the duplicates from) this section. That for each link in "Place these" that is found in the body of the outline (not navigation templates), or elsewhere in "Place these", gets removed.
Step 5: In this step, you take each of the topics one-by-one from the "Place these" section, after the duplicates have been removed, and put them into the body of the outline. Currently done by hand.
Step 6: Clean it all up with the RedlinksRemover. This tool is quick and painless – just click on the menu item. Without this tool, it is mind-numbingly tedious.
Which brings us to the design of OutlineDedupeHolding.js.
Eventually, this will dedupe more than one section, but its initial version will just process entries in the "Place these" section.
For each item, it needs to check the rest of the outline, excluding templates, and including the rest of "Place these", for a matching entry. If a match is found, that item is deleted from "Place these". If no match, go on to the next item.
I think this one may be within my ability level to write. I just need a little guidance...
How would you go about programming it? The Transhumanist 07:37, 22 January 2018 (UTC)
<li>
) with a duplicate link in them.