afch-rewrite icon indicating copy to clipboard operation
afch-rewrite copied to clipboard

Special handling for subcats of Category:Draft articles

Open enterprisey opened this issue 4 years ago • 10 comments

Remove subcats of Category:Draft articles when accepting https://en.wikipedia.org/w/index.php?diff=1001040898 davidwr at 23:59, 17 January 2021 (UTC)

Also don't convert subcats of Category:Draft articles into cat links during cleanup https://en.wikipedia.org/w/index.php?diff=1001705243 2pou at 22:56, 20 January 2021 (UTC)

enterprisey avatar Jan 18 '21 00:01 enterprisey

Hi @enterprisey , would like to take this as my next issue . Hope you could brief me about it, I went through the links you provided couldn't make much out of it. Much appreciated!

satcasm avatar Feb 19 '21 09:02 satcasm

@satcasm So there are two changes. Let's call all subcategories of Category:Draft articles "draft categories". Then these "draft categories" should:

  1. not be "disabled" during the cleaning process (in the "else" block of the isAccept if statement in AFCH.Text.prototype.cleanUp)
  2. be removed during accepting (I would recommend skipping them in the $.each block in AFCH.Text.prototype.updateCategories)

I can think of many ways to check if a category is a draft category. The "cheating" way is to just check if the name of the draft starts with "Drafts about" (or is equal to "Promising drafts"), because that catches most of them, but that wouldn't handle most of the subcategories. The better way, which we should use in the final product (maybe just use the "cheating" way to check that your category handling code above is correct, temporarily) is to use localStorage, like the loadWikiProjectList function. We could make a getDraftArticlesSubcats function that does the same thing (if lsKey is in localStorage, parse and return that array of categories; otherwise, get it from the API and then return it). You'll probably need https://www.mediawiki.org/wiki/API:Categorymembers, with cmtype=subcat. Unfortunately, it doesn't return subcategories of subcategories, so you'll need recursion... perhaps write a recursive getSubcats function, and then call it from getDraftArticlesSubcats with the parameter "Draft articles". Recursion and callbacks do not mix well at all; feel free to let me know when you get to that part.

So, once you have getDraftArticlesSubcats, you'll call it from the two places I checked above and then check if every category is in the return value, doing the appropriate thing in each place. Let me know what I should clarify or if you have any questions.

enterprisey avatar Feb 21 '21 10:02 enterprisey

@enterprisey in the else part of AFCH.Text.prototype.cleanUp nothing is mentioned about subcategories. So what exactly did you mean by not be "disabled" ?

image

satcasm avatar Feb 21 '21 18:02 satcasm

The comment is inaccurate; changing [[Category:Foo]] to [[:Category:Foo]] is "disabling" it (or to be completely accurate, "changing it to a link"). So I mean that this line of code should change [[Category:Rocks]] to [[:Category:Rocks]], but it should not change [[Category:Drafts about people]] to [[:Category:Drafts about people]] because Category:Drafts about people is a subcategory of Category:Draft articles.

enterprisey avatar Feb 21 '21 22:02 enterprisey

Hey @enterprisey , so I started small with the "cheating method". This is my code of updateCategories: image

This is of else part: image Can you tell what next step would be? I mean how to check it? I added

[[:Category:Drafts about people]]
[[:Category:Drafts about people]]
[[:Category:Drafts about people]]

in a draft and when I accepted it , in the text field I am getting one [[Category:Drafts about people]].

satcasm avatar Feb 22 '21 05:02 satcasm

In both of those functions, text is the whole text of the page; you may want to pass a function as the second parameter to replace in cleanUp.

enterprisey avatar Feb 22 '21 07:02 enterprisey

In both of those functions, text is the whole text of the page; you may want to pass a function as the second parameter to replace in cleanUp.

But for the time being is there something wrong with this code ? I mean I am using .test which should work just fine. Also how to get into the else part? If I accept an article it's just going into if(isAccept) loop.

satcasm avatar Feb 22 '21 08:02 satcasm

Yeah, if you use text then if you have two categories (and only one is a subcategory of Category:Draft articles), the code will act as if both are subcategories, which would be buggy. To use the else part, try using "clean", which you can get to by opening the "<<" menu on the far right side of the main menu.

enterprisey avatar Feb 22 '21 09:02 enterprisey

Okay so what should I pass along with the text as the syntax of categories and subcategories is similar?

satcasm avatar Feb 22 '21 09:02 satcasm

I would recommend creating a helper function, getDraftArticlesSubcats, that returns a list of categories; for now, you could just have it return a hard-coded array with a single item for testing, like Category:Drafts about people. Then, in updateCategories, check if category is in that returned array, and return from the callback if true. And in cleanUp, make the second parameter of .replace a callback, and check if the matched text is in that returned array.

enterprisey avatar Feb 22 '21 09:02 enterprisey