afch-rewrite
afch-rewrite copied to clipboard
Special handling for subcats of Category:Draft articles
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)
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 So there are two changes. Let's call all subcategories of Category:Draft articles "draft categories". Then these "draft categories" should:
- not be "disabled" during the cleaning process (in the "else" block of the isAccept if statement in AFCH.Text.prototype.cleanUp)
- 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 in the else part of AFCH.Text.prototype.cleanUp nothing is mentioned about subcategories. So what exactly did you mean by not be "disabled"
?
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.
Hey @enterprisey , so I started small with the "cheating method".
This is my code of updateCategories:
This is of else part:
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]]
.
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.
In both of those functions,
text
is the whole text of the page; you may want to pass a function as the second parameter toreplace
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.
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.
Okay so what should I pass along with the text
as the syntax of categories and subcategories is similar?
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.