It's in ext.Vector.editWarning.js, a function that's called at window.onbeforeunload. I don't understand why/how Watch/Unwatch escapes triggering this event. The link looks the same as other links.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The watch link is given a click event handler in mediawiki.action.watch.js, which performs an Ajax call to do the watch/unwatch action and uses preventDefault() and stopPropagation() to stop the browser from actually navigating to the link's target.
This is a bit different from what I want to do with links like [pdf] and display=download files, which is to simply go ahead to the link's target because I know it won't actually leave the page. I guess the best way to handle those is either to write an onbeforeunload handler to modify the behavior of the other one if a download link is being clicked (somehow), or put a click handler on the download links that suppresses Vector's onbeforeunload. I think I like the second option as more straightforward. Just remove the handler and let the click proceed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Now that I've got this mostly written, the problem is that it isn't safe. display=download can take you to another page, if the file can't be made or retrieved. I would have to do something more sophisticated to make sure the file's coming before letting go of the current page. Can I do a display=raw call by Ajax and let the file get downloaded if it comes with a success code?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK there are surely better uses for my time but I got it working: load the URL into a hidden iframe, use the load() event to catch failures and pop up a dialog. Had to hack the URL from display=download to display=raw, because download generates a MediaWiki page with error message somewhere within - which would be fine except that MW generates an X-Frame-Options header saying you can't embed it in an iframe!
Anyway there it is, if it succeeds you get to save or open the file, and if it fails you get a dialog saying it failed... if there's more specific error info you don't get it, you have to click to open the download link in another tab to see what the messages are. Not 100% sure whether this is better than just leaving the download link with the "leave this page" popup, but right now I think I could live with either...
Eventually I could either rewrite this to use the get-project-file API, or change display=raw (or a variant of it) to return all the error messages. That latter sounds like a good, simple idea, honestly.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ha! Got the actual messages in the dialog now, with display=raw. Also am no longer altering the links' targets in place, so you still get display=download if you open the link in another tab.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
"Watch this page" is a MW link that doesn't trigger this warning. Find out how they do it and do the same.
It only warns when previewing, not on the initial edit page, for some reason
It also warns on the initial edit page in MW 1.22alpha
It's in ext.Vector.editWarning.js, a function that's called at window.onbeforeunload. I don't understand why/how Watch/Unwatch escapes triggering this event. The link looks the same as other links.
The watch link is given a click event handler in mediawiki.action.watch.js, which performs an Ajax call to do the watch/unwatch action and uses preventDefault() and stopPropagation() to stop the browser from actually navigating to the link's target.
This is a bit different from what I want to do with links like [pdf] and display=download files, which is to simply go ahead to the link's target because I know it won't actually leave the page. I guess the best way to handle those is either to write an onbeforeunload handler to modify the behavior of the other one if a download link is being clicked (somehow), or put a click handler on the download links that suppresses Vector's onbeforeunload. I think I like the second option as more straightforward. Just remove the handler and let the click proceed.
Now that I've got this mostly written, the problem is that it isn't safe.
display=downloadcan take you to another page, if the file can't be made or retrieved. I would have to do something more sophisticated to make sure the file's coming before letting go of the current page. Can I do adisplay=rawcall by Ajax and let the file get downloaded if it comes with a success code?Maybe just put it in an invisible iframe and do something appropriate if there's an error?
maybe best leave this for now...
OK there are surely better uses for my time but I got it working: load the URL into a hidden iframe, use the load() event to catch failures and pop up a dialog. Had to hack the URL from display=download to display=raw, because download generates a MediaWiki page with error message somewhere within - which would be fine except that MW generates an X-Frame-Options header saying you can't embed it in an iframe!
Anyway there it is, if it succeeds you get to save or open the file, and if it fails you get a dialog saying it failed... if there's more specific error info you don't get it, you have to click to open the download link in another tab to see what the messages are. Not 100% sure whether this is better than just leaving the download link with the "leave this page" popup, but right now I think I could live with either...
Eventually I could either rewrite this to use the get-project-file API, or change display=raw (or a variant of it) to return all the error messages. That latter sounds like a good, simple idea, honestly.
Ha! Got the actual messages in the dialog now, with display=raw. Also am no longer altering the links' targets in place, so you still get display=download if you open the link in another tab.
Just clicked on a project-file link while previewing in my wiki (MW 1.19) and got the "Leave this page" popup. Why? The link is just this tag: