User talk:The Transhumanist/P-link.js


 * This script is under development, and is not yet fully 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, below.

Description & instruction manual for P-link.js

 * This script is under development, and is not yet fully functional

When completed, this script will create 3 menu items:

P link on category P link on template P link on root
 * if on category edit page it places corresponding portal link,
 * if on category page it starts category edit page,
 * otherwise it jumps to like-named category page
 * if on template edit page it places corresponding portal link,
 * if on template page it starts template edit page,
 * otherwise it jumps to like-named template page
 * if on article edit page it places corresponding portal link,
 * if on article page it starts article edit page,
 * otherwise jumps to like-named article page

The menu items are available on portal, category, template, and article pages.

This is a rudimentary version, and so it will require that the desired menu item be clicked on as a separate action up to 3 times. The goal is to use local storage so that link placement can be handled with a single click of the menu item.

General approach
(general approach goes here)

More specifically, starting at the beginning...

Desired/completed features

 * Completed features are marked with ✅

Rough rough talk-through
The nature of scripts is that they run every time a page is loaded. One peculiarity with this script is that it loads pages. Once a new page loads, the script ends and starts over again on the loaded page.

The challenge is making the script pick up where it left off once it has loaded another page. Therefore, the script needs to ascertain what kind of page it is on and where in the process it is. Without tracking those things, the script will go into an endless loop.

First try
Upon the click of a single menu item (instead of 3), I'd like this program to
 * 1) place a link to the current portal on the corresponding category page (if it isn't already there) and remove other (off-topic) portal links from that page
 * 2) then place a link to the same portal on the corresponding root article page (if it exists) in its See also section, creating the section if there isn't one, and remove existing portal links
 * 3) then place a link to the same portal at the bottom of the corresponding navbox footer page (if it exists), in the below= section, creating the section if there isn't one.

Second try
Does different stuff depending on what page it is on


 * 1) Portal base page (has no "/" in title)
 * 2) Show menu item if title has "Portal:"
 * 3) Menu item doesn't show up if there is a "/"
 * 4) Store the name of the current portal (portalTitle).
 * 5) Corresponding category edit page
 * 6) Check local storage = "went to category"
 * 7) Do search/replaces with regex
 * 8) Set local storage = "went to root"
 * 9) Goto root article edit page
 * 10) Corresponding root article edit page
 * 11) Check local storage = "went to root"
 * 12) Do search/replaces with regex
 * 13) Set local storage = "went to navbox"
 * 14) Goto navbox edit page
 * 15) Corresponding navbox footer edit page
 * 16) Check local storage = "went to navbox"
 * 17) Do search/replaces with regex

There's this script I've been working on...
It is now faster to build a portal than to place the links leading to it. So, I've been trying to write a link placer.

P-link stands for "portal link".

When completed, it will place links in 3 locations leading to a portal: on the corresponding category page, in the See also section of the corresponding article, and at the bottom of the corresponding navbox footer template. This will save loads of time, and should bring portal creation including link placement, down to under a minute for each portal.

I've got the "P link on category" menu item for placing the category page link working, sort of, but I had to resort to programming it to click the menu item up to 3 times instead of once, depending where you start from. I'd like it to work with one click from all of the allowed starting locations. It's a puzzle that has me stumped - working through the problem in my head or on paper with locally stored variables, I keep running into ambiguities discerning page types that I can't figure out. Once that problem is solved, I can move on to the other 2 menu items. &mdash; The Transhumanist  02:59, 26 December 2018 (UTC)

P.S.:pinging
 * One way around this would be to, when the script loads the edit page, use something like ?action=edit&plink=yes. Then, for category edit pages, you check if the plink=yes is in the URL: If so, you skip to the code that inserts the portal; if not, you add the menu item that when clicked will do that. As for determining page types, mw.config has a bunch of page-specific values that you can use, such as current action (like "edit" or "view"), namespace number, page title (both with and without the namespace prefix), categories (so you can check if page is in Category:All disambiguation pages or Category:All set index articles) – see mw:Manual:Interface/JavaScript. - Evad37 &#91;talk] 14:35, 26 December 2018 (UTC)
 * The problem I kept getting was endless loops. The program couldn't tell the difference between the edit page and the preview page (which is also an edit page). So, the program would make the change and activate preview, but when the preview page came up, the script ran again. And again. And again. Etc.  &mdash; The Transhumanist   08:03, 27 December 2018 (UTC)
 * mw.config.get('wgAction') will result in "edit" for the initial edit page, and "submit" for the preview edit page - Evad37 &#91;talk] 08:17, 27 December 2018 (UTC)

Script dependencies
= Discussions =


 * This is where the actual talk page starts for User:. Please post your discussion threads below...