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

Add intestactions to loadQuery, auto-add XfD edit request #1091

Merged
merged 2 commits into from
Nov 12, 2020

Conversation

Amorymeltzer
Copy link
Collaborator

@Amorymeltzer Amorymeltzer commented Aug 7, 2020

There are two separate issues here, but the main question is whether adding intestactions to the page load query in Morebits.wiki.page is a good idea. I think it adds value being able to confirm early whether an action can take place, and should avoid running into a hard error if handled elegantly. While this is a simple proof of concept, there's a lot we can think about making use of it. Right now, I've just added edit, but an expansive view could imagine checks for move or delete, whether in morebits itself or available for modules to use. Even without additional checks, it'd be a helpful pre-edit early failure check. I've not tested or thought through the implications for non-load things like append.

I've used it here to enable twinklexfd to auto-add edit protected requests when a user can't edit the page in question. With the exception of TfM other template tagging, wgIsProbablyEditable would have sufficed for this implementation. (technically both are making assumptions about "protection" but in practice, that's it). I'm not certain that it's easier than using promises (cc @siddharthvp) but it's probably more efficient.

At any rate, I'd welcome thoughts on either side of things.

modules/twinklexfd.js Outdated Show resolved Hide resolved
modules/twinklexfd.js Outdated Show resolved Hide resolved
morebits.js Outdated
@@ -2056,6 +2056,7 @@ Morebits.wiki.page = function(pageName, currentAction) {
watchlistOption: 'nochange',
creator: null,
timestamp: null,
canEdit: null, // true or false after load
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better for this to be a testactions array or something, then just assign all found actions to that array. Then, separate getters can be used (return ctx.testactions.indexOf('edit') !== -1) or a bulk test (function(action) { return ctx.testactions.indexOf(action) !== -1 })

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also concerns about initial value here. Distinguishing null from false or true could be useful if there's a chance a page object hasn't been loaded yet...

Copy link
Collaborator Author

@Amorymeltzer Amorymeltzer Oct 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone and done this, still just with edit for now, using the former style.

modules/twinklexfd.js Outdated Show resolved Hide resolved
@Amorymeltzer Amorymeltzer marked this pull request as ready for review October 18, 2020 11:03
@Amorymeltzer Amorymeltzer added this to the November 2020 update milestone Oct 18, 2020
modules/twinklexfd.js Outdated Show resolved Hide resolved
Simple proof of concept with just `edit` being tested, but this could (should?) easily be expanded to include any relevant actions, allowing us to verify a number of actions ahead of time and catch likely errors early.  For now, return editability with `canEdit`.
Currently written with repetitive `if (pageobj.canEdit())` loop.  That's just because everyone but AfD has a distinct function on page load, but AfD is muddled within a bunch of other checks.  Those checks are good (and should maybe be added to the others...), so we would have to break out the actual tagging into a separate function that doesn't need more loading to cut down on the ifs while still handling the loading for everyone else.  PITA.

Would close wikimedia-gadgets#176
@Amorymeltzer Amorymeltzer merged commit f0172d0 into wikimedia-gadgets:master Nov 12, 2020
@Amorymeltzer Amorymeltzer deleted the morebits-intest branch November 12, 2020 11:42
@siddharthvp siddharthvp mentioned this pull request Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto-editprotected when XfD-ing protected pages
2 participants