Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special handling for subcats of Category:Draft articles #131

Open
enterprisey opened this issue Jan 18, 2021 · 10 comments
Open

Special handling for subcats of Category:Draft articles #131

enterprisey opened this issue Jan 18, 2021 · 10 comments
Assignees
Labels
C-bug Category: bug C-enhancement Category: enhancement

Comments

@enterprisey
Copy link
Contributor

enterprisey commented Jan 18, 2021

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 enterprisey added the C-enhancement Category: enhancement label Jan 18, 2021
@enterprisey enterprisey changed the title Remove subcats of Category:Draft articles when accepting Special handling for subcats of Category:Draft articles Jan 20, 2021
@enterprisey enterprisey added the C-bug Category: bug label Jan 20, 2021
@satcasm
Copy link
Contributor

satcasm commented Feb 19, 2021

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!

@enterprisey
Copy link
Contributor Author

@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.

@satcasm
Copy link
Contributor

satcasm commented Feb 21, 2021

@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

@enterprisey
Copy link
Contributor Author

enterprisey commented Feb 21, 2021

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.

@satcasm
Copy link
Contributor

satcasm commented Feb 22, 2021

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]].

@enterprisey
Copy link
Contributor Author

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.

@satcasm
Copy link
Contributor

satcasm commented Feb 22, 2021

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.

@enterprisey
Copy link
Contributor Author

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.

@satcasm
Copy link
Contributor

satcasm commented Feb 22, 2021

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

@enterprisey
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug C-enhancement Category: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants