Commit graph

1394 commits

Author SHA1 Message Date
Thiemo Kreuz fae6118071 Document and use mw.Api parameter defaults
Reasoning:
* format=json must be the default. Nothing else makes sense in
  the context of this code. This should not be a surprise.
* formatversion=2 is only a default when the custom
  getContentApi() is used, but not when mw.Api is used. One
  might argue that it's safer to always specify formatversion=2.
  However, this is not done in other places in this codebase.
  It should never be done or always.
* I find it confusing when the action=… is missing. Let's not
  rely on this default.

Change-Id: I6ca29f76bffc0849103c5bcff4aaf28fcaaa4c52
2021-07-12 09:13:59 +02:00
Bartosz Dziewoński 58b230a308 Fix HotCat interface not working after cancelling visual editing
Cloning the #catlinks node loses all native event handlers registered
on it. jQuery's `.clone( true )` method can only copy jQuery event
handlers, so it does not help. As a result, when the node is
reattached to the page after cancelling visual editing, HotCat's
interface is still visible, but not functional.

To fix this problem, keep a reference to the original node rather than
a clone.

https://developer.mozilla.org/en-US/docs/Web/API/Node/cloneNode#notes
https://api.jquery.com/clone/

Change-Id: I2c0b3d1a919b67053a17dd11fd2b7dc7556267ef
2021-07-09 13:51:09 +02:00
Thiemo Kreuz c2017f74b2 Remove @param/@return docs that literally repeat the code
These don't add any knowledge but make the code harder to read
and maintain, and are an additional source of errors.

Change-Id: Ied57741a3f985e355adfddb4e75378d5c497faa9
2021-06-14 15:44:51 +02:00
Ed Sanders 857014fae9 Support watchlist expiry
Bug: T251348
Change-Id: I017a54784c758c5e97fb640721bd456adc0fbab5
2021-06-08 20:14:45 +00:00
Bartosz Dziewoński 32ecfe4caf Fix adding 've-init-mw-target-surface' class only to main surface
Bug: T284312
Change-Id: Ic5320f6747907542285674d386c7a59c9e857f0a
2021-06-04 20:48:08 +00:00
jenkins-bot 30bf60cb87 Merge "ArticleTarget: Always set fromEditedState when preloaded is true" 2021-05-25 20:24:29 +00:00
Ed Sanders a71dd4f797 Ensure correct classes are added to surfaces
* Create getSurfaceClasses method.
* Pass surfaceClasses to target widgets.

This ensures that the 'content' class is passed to mobile
target widgets, and the 'mw-body-content' class is added
in a less hacky way.

Change-Id: Ibce6d1a1d0fda63cca354761f1b91f808858e95b
2021-05-23 20:04:28 +01:00
jdlrobson 2a40996cb7 Add mw-body-content to surface element
VisualEditor recreates the mw-body-content element. The element
with mw-parser-output already exists as a child. All skins now
consistently follow this pattern.

To limit the impact to the editor, we use ArticleTarget and add the class
to the surface, which corresponds to the mw-body-content element of a skin.
This avoids unrelated regressions in experiences such as DiscussionTools.

Bug: T283014
Change-Id: I4833d1ca9fda4fc0bd433760e47fe7010f00db05
2021-05-17 19:06:54 +00:00
jenkins-bot 396876fe43 Merge "Check if actionTools.notices is set before using" 2021-05-05 15:16:44 +00:00
Kosta Harlan 298cb41ed3 Check if actionTools.notices is set before using
Ib957eac2d checked to see if actionTools.notices existed before
destroying it, but assumed it always existed if editNotices was
set. This patch adds a check before attempting to show editNotices.

The error occurs because Ibc7fa48df unregisters the 'notices' tool
(along with many others) for AddLinkArticleTarget.js in
GrowthExperiments. I92a3162ef in GrowthExperiments will empty out
any notices to work around this problem.

Bug: T281960
Change-Id: Idacd365efa82ecd5c0074ead035eda0cb9444b1f
2021-05-05 08:27:55 +00:00
Ed Sanders fab7ad9d92 Make convert to wikitext on paste feature configurable (temporarily)
Bug: T280745
Change-Id: Icc716563e5536b4ef33a48ba10a72f3a39bdec35
2021-05-03 21:16:54 +00:00
Ed Sanders 1f50769cff ArticleTarget: Always set fromEditedState when preloaded is true
This means we don't need to check this.preloaded again anywhere else.

Bug: T279448
Change-Id: Ic8abdd87074d404a47ab8a82abf36e5443f3d163
2021-05-03 14:34:25 +01:00
Gergő Tisza b902b09784 Fix ve.init.mw.MobileArticleTarget.save return value
Like its parent method, ve.init.mw.MobileArticleTarget.save
should return a promise.

Change-Id: Ic3b390e613aa71aea4e7375a1f6e421cbd4f854c
2021-04-22 14:58:59 +00:00
BrandonXLF 73adc9ac78 Strip all wikilinks for initial edit summary
The regex that removes the wikilinks to create the initial edit summary
should have the global flag since it was taken from preg_replace which
replaces globally implicitly.

Bug: T276722
Change-Id: I21e3cdfe752657ad37d9a6bd473a7e7dbb6e4cd6
2021-03-07 17:51:59 -05:00
Ed Sanders 80c530fb56 Fetch full document when diffing wikitext sections
The full document is required to diff the reference list correctly.

Bug: T260008
Change-Id: I8d714be30051c94a725cd2678c547f57fa0a0c5e
2021-02-22 13:46:08 +00:00
jenkins-bot 54f61eb54c Merge "Update save failure logging for EditAttemptStep schema, simplify code" 2021-02-01 18:28:10 +00:00
Ed Sanders 865a59d640 Compute entire old DM doc for section diffs
We need the whole DM doc to show reference diffs
correctly. We can filter down to the active section
after the conversion like we do with the editor.

Bug: T272813
Change-Id: I2081dd520ff414caadaed2efda955d600953c957
2021-01-24 23:12:26 +00:00
Ed Sanders f8c403dffb Update VE core submodule to master (a8919f78e)
New changes:
c17816c5f Diff sidebar: Make font size slightly smaller
f8439f4cc Deep-freeze linear data
a8919f78e Deep-freeze linear data added by transactions

Local changes:
Fixes for deep-frozen linear model

Bug: T119236
Change-Id: Iae4362c8dab0f2bd335e24498f3e0522b8b1d4fc
2021-01-23 19:55:14 +00:00
Ed Sanders 1ec49384dc MWSaveDialog: Use MessageWidget (inline, warning) to show save dialog warnings
This is the same style that is recommended for form warnings.

Change-Id: I163f5180c66b9eb165a610184b153bb1da99caab
2021-01-20 19:41:17 +00:00
Ed Sanders e20decc77c MWSaveDialog: Remove wrap option from showMessage
This was used when we used to pass API errors to showMessage, but
is now unused by the two remaining users (missing edit summary, and
"press ctrl+enter to submit").

Change-Id: I8a6b4db78d4e451cf3ec85fcdfd8293328aaaa3c
2021-01-16 16:22:23 +00:00
Bartosz Dziewoński df43a1ef96 Update save failure logging for EditAttemptStep schema, simplify code
* Remove custom internal events in ArticleTarget for every error type.
  The indirection was just making it harder to figure out what data
  goes where.

* Centralize the actual logging in ArticleTarget, instead of doing it
  in a dozen methods.

* Directly use the error code from the API for 'save_failure_message'.
  Previously we'd lose the original error code and generate a new one
  in the event indirection stuff, except for 'responseUnknown'.

* Update 'save_failure_type' map. Remove unused error codes, update
  the ones that changed, and sort in the order in which the types are
  listed on the schema page.

Bug: T272162
Change-Id: Ied602c456f4b0e7e9bb135e3200bec5ce65641ba
2021-01-15 20:06:20 +01:00
Gergő Tisza c88ee8cd54
Preserve vehidebetadialog URL flag when switching editor mode
Switching from visual editor to old wikitext editor results in a
page reload and loss of the mw.libs.ve.disableWelcomeDialog()
flag. Use an URL parameter to preserve the flag.

Bug: T235812
Change-Id: I3968e5b7ae536d45fd764a8b7c3ea1f6d616033f
2021-01-04 19:54:32 -08:00
Ed Sanders 069e9c68ed Reset originalDmDocPromise when setting doc
originalDmDocPromise is dervied from target.doc, so if that changes
ensure the promise is cleared.

Change-Id: I51219e06109b0ccf1a17c920131b764862be85e1
2020-12-08 17:28:28 +00:00
Thiemo Kreuz fb0e33f987 Fix incomplete return in DesktopArticleTarget.tryTeardown()
If a teardown has started, there should be a teardownPromise,
otherwise return a rejected promise.

Bug: T268358
Change-Id: Ia5cbd6b409a38f97243234ea7c87d24f71bdf3d6
2020-12-02 21:22:10 +00:00
Bartosz Dziewoński c49f919d90 Remove maxLength from new section title in NWE
MediaWiki doesn't have such a limitation. This might have been copied
from the edit summary code, which used to be limited to 255 bytes.

Change-Id: I4afe9b1cde0663c47c0c2502b6e32116b912208b
2020-11-26 00:22:36 +01:00
Gergő Tisza de7c6e913b
Avoid undefined in Math.max
Math.max( undefined, x ) is NaN.

Change-Id: I60bde01d4fc6e9a52182753f79232045f48d1f8b
2020-10-14 23:51:02 -07:00
jenkins-bot 05ec421073 Merge "Don't navigate back immediately when trying to teardown" 2020-10-02 00:22:23 +00:00
Ed Sanders 27e19025a4 Fix cancelled browser-back on desktop
Bug: T263464
Change-Id: I808f7effffca5fbe9d8416d447df61dde57776c3
2020-09-21 16:23:18 +01:00
Ed Sanders 587dc1a3c8 Don't navigate back immediately when trying to teardown
Let MobileFrontend deal with all the history management.

Bug: T247171
Change-Id: I666b31285761c80407b4f0fe65c48f76b3e72bf2
2020-09-21 15:21:24 +01:00
Ed Sanders 7a61992fbb Store revid as undefined when document doesn't exist (revid=0)
Bug: T262838
Change-Id: I9ac1815e281544916ea9aded8e80039245c9d871
2020-09-16 11:13:38 +00:00
Ed Sanders 1c9bb2518c Drop iceweasel and blackberry tests for new jQuery.client
Change-Id: Ie5fd40415b6c38471ef6df875f67678326007552
2020-09-10 13:49:03 +01:00
jenkins-bot a7832b6bf5 Merge "Start using edit api results for watchlist UI updates" 2020-08-26 23:32:44 +00:00
Dayllan Maza 4fc73112ee Start using edit api results for watchlist UI updates
This patch starts using watchlist related values from ApiEditPage
results instead of updating the "watch link" based on whether the
checkbox was selected or not at the time of saving the article.

This change does not depend on T261030 and can be merged without it
but T261030 needs to be fixed or temporarily watched items will not
display the right tooltip when hovering the "watch link" or star icon.

Bug: T260434
Change-Id: I2c844223620d7d28f36a0cd8ae3dee4b0c8ae5bf
2020-08-26 23:08:47 +00:00
Bartosz Dziewoński b9a0def93a ve.init.mw.MobileArticleTarget: Fix floating toolbar workaround for iOS 13.6
If we call getBoundingClientRect() while the 'transform' animation is
still ongoing, it's going to return values reflecting the transform
- that is, the rect will be partially offscreen - which will trigger
our code that runs the animation again.

I don't know why this wasn't a problem on iOS 13.3 and earlier. Either
the timing was slightly different and the 'transform' animation was
able to finish earlier, or getBoundingClientRect() was buggy and
returned wrong values that conveniently worked right for us.

Bug: T259321
Change-Id: I6be0ddaeb6df54295fb14c45ba15fee41d61e33f
2020-08-21 23:33:37 +02:00
Ed Sanders 4545f53245 build: Update eslint-config-wikimedia to 0.17.0
Fix instances of variable shadowing.

Change-Id: I6e2befb020d7d4b506c7b46131eafacd951aa6d1
2020-08-18 13:16:49 +01:00
Ed Sanders dd862a837d MobileArticleTarget: Move MWBackTool to a separate file
Change-Id: I1561f454bcc779f97c758ba7178b09d15f52fe42
2020-07-31 16:15:10 +00:00
jenkins-bot b55ba6f1dc Merge "Also check for revid conflict when RESTBase says page doesn't exist" 2020-07-27 21:29:50 +00:00
jenkins-bot 9d1b3a6d49 Merge "Always rebuild category list from Parsoid data on surfaceReady" 2020-07-17 16:01:23 +00:00
David Lynch c190fab8ea Always rebuild category list from Parsoid data on surfaceReady
Rebuild the category list from the data we got from the API. This makes
it work regardless of whether we came here from activating on an
existing page, switching from source mode, or loading via an edit URL.

Because Parsoid doesn't include redlink status on the <link>s it
represents the categories as, we do have to manually update those
styles.

Bug: T251398
Change-Id: Iaaef3223816269bba1371fbb07956119a120c1ca
2020-07-17 10:24:00 -05:00
Bartosz Dziewoński 8702d59879 Toggle TemplateStyles at a better time during (de)activation to avoid flashing
Change $originalContent to $editableContent, as counter-intuitively
the editing surface is attached inside $originalContent, while
$editableContent contains only the hidden existing page content.
It was not a problem previously because of the order.

Bug: T254518
Change-Id: I68f7ddb45f09dff475b183ccfeaf98e67b83066e
2020-07-15 21:27:27 +00:00
jenkins-bot 51b8ff5a72 Merge "Remove warning shown when editing a translatable page source" 2020-07-08 20:18:19 +00:00
Bartosz Dziewoński 4ea0cf0cab MobileArticleTarget: Double-check that section is not 'undefined'
It's supposed to be a string or null. The parent class sets
`this.section = null` for us by default.

Bug: T257355
Change-Id: I375a3f6724235f22888bb7f0cb77a7081153768e
2020-07-07 20:50:59 +02:00
Abijeet 24c8b2d2b6 Remove warning shown when editing a translatable page source
Translate itself will show an warning dialog when user tries to edit
a translatable page in visual mode. Editing in the source mode is
allowed.

Bug: T192052
Depends-On: I03ea64353b2d5b28d684f90936cab75ea4fd40d2
Change-Id: Ie4f3a6003c27773c6d0c5086c876fe424befe25a
2020-07-07 11:49:19 +05:30
Bartosz Dziewoński 36bd09c429 Also check for revid conflict when RESTBase says page doesn't exist
There used to be similar code here, but it was removed in 2015 in
85b745666f because it wasn't correct in
some cases. Restore it and instead separately check for those cases.

Bug: T257124
Change-Id: Id4a17266111d064805aa0ca865182bb2f4b019eb
2020-07-05 19:42:12 +02:00
jenkins-bot 6f6c4828a7 Merge "When returning to section, avoid counting sections outside the content" 2020-06-22 22:30:44 +00:00
Mvolz 842a728488 Revert "Allow generic params to be passed to getWikitextFragment"
This reverts commit e5c1ef651b.

This change caused an error where templates failed to be inserted
into wikitext in the 2017 wikitext editor.

Bug: T255785
Change-Id: Ie57c49e68e594be22af2b1b479840f29e46131db
2020-06-19 13:15:23 +00:00
Ed Sanders 013b7419bf build: Update eslint-config-wikimedia to 0.16.2
Use jsduck config

Change-Id: I5cd7bbcee83b0fa148b8fb8c3b4adcf08f96cefc
2020-06-18 19:16:52 +01:00
jenkins-bot 15443d35c5 Merge "Allow generic params to be passed to getWikitextFragment" 2020-06-15 20:42:45 +00:00
Ed Sanders 9c8195f823 Replace browser blacklist/whitelist with (un)supportedList
Bug: T254646
Change-Id: Iac0fc850520f2a83954d3fac21b38715e2f76a8c
2020-06-10 16:30:57 +01:00
Bartosz Dziewoński 27ca1082a9 When returning to section, avoid counting sections outside the content
Bug: T254593
Change-Id: I8126e21b3732b45c0a5b418e3832ccc4c72a1b73
2020-06-05 17:56:08 +02:00
Ed Sanders e5c1ef651b Allow generic params to be passed to getWikitextFragment
mw.Target doesn't know about revid and etag, so move that logic
to ArticleTarget, where the param can still just be a boolean.

Change-Id: Idf4632cd28554aaf5bbf5f2b44ded047c0c4b182
2020-06-04 22:45:09 +01:00
jenkins-bot 7a2fffae39 Merge "When switching from wikitext to visual, preserve the edit checkboxes" 2020-06-04 15:10:51 +00:00
Bartosz Dziewoński 186f5dc424 When switching from wikitext to visual, preserve the edit checkboxes
This handles the minor edit and watch checkboxes, as well as any added
by extensions (e.g. FlaggedRevs).

Switching in the other direction already works fine, that is
implemented in ArticleTarget#getSaveFields.

It doesn't seem ideal to put this code into the constructor of
ve.init.mw.DesktopArticleTarget, but that's where we already have
similar logic for the edit summary. I filed T253696 about this.

Bug: T250388
Change-Id: Ia6a9c0465ed215e8f74b9fff4590593383e9a1e6
2020-06-03 23:30:45 +02:00
Ed Sanders 6076708ff3 build: Update eslint-config-wikimedia to 0.16.0
Change-Id: I638e0f82949597e2a2e4ea18fc2f0258f225358c
2020-06-02 21:30:00 +01:00
Bartosz Dziewoński 61de7530c7 Improve deactivating tabs when switching/exiting on MonoBook etc.
Previously we didn't deactivate them, so if you opened VE, then
switched to NWE, then exited the editor, all three tabs would appear
active.

Change-Id: I904d6daf2896ceadf004f5e57a88c2359f33fd44
2020-05-14 20:24:57 +02:00
Ed Sanders 0c6b6e3e89 Improve shortcut in getWikitextFragment
Use hasContent to
1. Catch cases where the document is empty, e.g. <p></p>
2. Avoid having to use the converter

Change-Id: Ib1bb36824ca871e535bef38cef8137fdfb81b53e
2020-04-29 17:32:09 +01:00
jenkins-bot 3e519667a1 Merge "DesktopArticleTarget: Move shouldShowWelcomeDialog() to init" 2020-04-21 21:27:04 +00:00
jenkins-bot 3e70794645 Merge "ArticleTarget: Move shouldShowWelcomeDialog() into DesktopArticleTarget" 2020-04-21 21:27:01 +00:00
jenkins-bot c8cffbd394 Merge "ArticleTarget: Clean up WelcomeDialog show/hide handling" 2020-04-21 21:25:36 +00:00
Roan Kattouw e0125e3e9d DesktopArticleTarget: Move shouldShowWelcomeDialog() to init
Move shouldShowWelcomeDialog() and stopShowingWelcomeDialog() from
DesktopArticleTarget to DesktopArticleTarget.init, and use them to
deduplicate code in init that manages the wikitext welcome dialog.

Look for both the vehidebetadialog and hidewelcomedialog URL params.
The code in DesktopArticleTarget used vehidebetadialog, but the code in
init for the wikitext welcome dialog used hidewelcomedialog.

Bug: T249954
Change-Id: I19f1a2da36bc65addb52811c3d3c73c1259bc8f5
2020-04-21 11:41:59 -07:00
Bartosz Dziewoński b01c69a800 mw.ArticleTarget: Fix #saveErrorBadToken / #saveErrorNewUser calls
Follow-up to 8065fdf2b9.
I noticed this while trying to reproduce an unrelated bug.

Change-Id: If5b18b055cbee6fc2513161a4f445667dd2a72e0
2020-04-21 18:52:02 +02:00
Roan Kattouw e1f4e3f148 ArticleTarget: Move shouldShowWelcomeDialog() into DesktopArticleTarget
The base class doesn't use it, it only defines it, and
DesktopArticleTarget is the only subclass that uses it.
MobileArticleTarget calls it, but also overrides it to be a no-op.

Change-Id: Ib3feea94844f4e1ed71dccece7657450516cac89
2020-04-17 15:46:07 -07:00
Roan Kattouw 7457834dc5 ArticleTarget: Clean up WelcomeDialog show/hide handling
Factor out the logic for whether the WelcomeDialog should be shown into
its own method, and write it in a less confusing way. Do the same thing
with the logic for setting the preference/storage/cookie for hiding the
WelcomeDialog.

This makes maybeShowWelcomeDialog() much simpler, and removes duplicated
code in DesktopArticleTarget.

There is one minor change in behavior: if the WelcomeDialog is
suppressed using the URL parameter, that no longer causes the preference
to be updated as if the dialog had been shown.

Change-Id: I1d4f912c5f6bd7a2bbad2b209b97c3ec1f250a07
2020-04-17 15:46:07 -07:00
Ed Sanders 651756c4fc eslint: Enable the mediawiki/class-doc rule and make pass
Also minor other adjustments

Change-Id: I9ee48359e3e53799f2f6240e44b53972283ce328
2020-04-17 22:59:11 +01:00
Bartosz Dziewoński 92c3055628 Fix issues with treating section "numbers" as integers
In MediaWiki, section numbers may be prefixed with 'T-' if they refer
to sections on a transcluded page, so they are not really numbers.

Change e2cb9ce93e caused us to treat them as strings most of the time,
but it looks like there are several places where we treated them as
integer numbers, which I missed when making that patch.

The first two changes in ArticleTarget#restoreEditSection fix T248795
and T248968/T249112, respectively. The other changes are cleanup.

Bug: T248795
Bug: T248968
Bug: T249112
Change-Id: I8373a7ab515595769ce6f3051a182c922415b643
2020-04-01 21:41:17 +02:00
jenkins-bot 774c3ec1e4 Merge "Move MWutils to preinit and rename to parsoid utils" 2020-03-24 22:31:17 +00:00
Ed Sanders de47496b19 Move MWutils to preinit and rename to parsoid utils
Bring in ve.dm.MWInternalLinkAnnotation.static.getTargetDataFromHref
and ve.resolveUrl, so that the file has no dependencies on VE.

Change-Id: I03bc455d5484a6c51f3fa2397c64936b829fe7e3
2020-03-24 23:13:16 +01:00
Bartosz Dziewoński 494fc439fd Fix new section title when switching from NWE to OWE
This code path is triggered when saving a new section in NWE causes an
edit conflict, which should be impossible, but apparently does happen.

Add some TODOs for parameters being added to the API calls in weird
places, instead of the dedicated methods.

Bug: T248364
Change-Id: I0686671e86e35f9ba503d0dd84e9074dde72dc10
2020-03-24 21:57:03 +01:00
Bartosz Dziewoński 7b47575a45 Add accessibility labels to all type: 'list' toolbar groups
Bug: T245776
Change-Id: I67d8e239f4fed7dd7ac4b98be3362426e753076b
2020-03-14 14:13:53 +01:00
jenkins-bot 2c1383b79e Merge "Move checkbox widget creation to mw.libs.ve" 2020-03-13 18:13:46 +00:00
Ed Sanders e3d3e0869d Move checkbox widget creation to mw.libs.ve
So this can be used other VE API users (e.g. DiscussionTools).

Bug: T245222
Change-Id: I1e0e9bb9da53a62f8a20126e579dcd6300bd2376
2020-03-13 18:00:44 +00:00
jenkins-bot a5420c624a Merge "Update VE core submodule to master (ff82c0966)" 2020-03-11 23:32:23 +00:00
Ed Sanders 0091d69231 Update VE core submodule to master (ff82c0966)
New changes:
8a3e25b98 build: Updating acorn to 7.1.1
032a2520d Localisation updates from https://translatewiki.net.
ff82c0966 [BREAKING CHANGE] Remove ve.init.target lookup from TargetWidget

Local changes:
* Pass toolbarGroups explicitly form Target to TargetWidget

Change-Id: I4ff6f432412ab958f2858879b2b857278866350a
2020-03-11 23:59:10 +01:00
Ed Sanders bcfb250f56 Ensure that ve.init.target is correct when re-activating an ArticleTarget
Change-Id: Ic30cd99583019823b51f52ab97ee6f9d7adc53f2
2020-03-11 14:45:37 +00:00
Ed Sanders 8726a71342 Move switchToWikitext to switchToFallbackWikitext
This should be a no-op as the inherited switchToWikitext
implementation will always call switchToFallbackWikitext
if 'source' is not passed as a supported mode (which it
isn't currently in MobileFrontend).

Change-Id: I213e7d54d158127b5c42bc05ff9ea2dececc42fe
2020-03-09 18:55:15 +00:00
Ed Sanders bc29a8cdd1 MobileArticleTarget: Remove definition of editSource, identical to parent
Change-Id: I939b34416722fe81f643ca48fe1c5f8ea9e3cbc5
2020-03-09 18:55:05 +00:00
jenkins-bot c69b46adfc Merge "Clean up code related to token and bad token handling" 2020-03-05 11:25:58 +00:00
jenkins-bot 5bcd4a82f8 Merge "Use built-in mw.Api 'badtoken' handling, also 'assert'/'assertuser'" 2020-03-05 11:25:46 +00:00
Ed Sanders 42194ec411 Fix checkbox handling in the API
The code for setting 'watchlist' in the EditAPI request
was completely broken as it always evaluated to 'unwatch'.
Instead pass through 'watchlist' directly from the client
where it must be set to 'watch' or 'unwatch'.

Bug: T245579
Change-Id: Ia5a2bb76ef35a685b39bcc0c4727796acd0f510d
2020-02-29 17:35:29 +00:00
Adam Wight c0ad11b960 Purge autosave before submitting merged content
When using TwoColConflict with VisualEditor, the autosave buffer wouldn't
be cleared after saving the successful merge.  This would cause a user to
see a "restore changes?" prompt the next time they entered the editor,
with the potential to confuse them and cause them to do extra work,
repeating the conflict resolution unnecessarily.

This change purges the autosave buffer before submitting a merge.

Note that it is not transactional, so there is a chance we're losing the
autosaved content even if the submit will fail.

Bug: T245119
Change-Id: I150023f548c5565412769d644a828176f907bc25
2020-02-20 09:43:26 +01:00
Bartosz Dziewoński 8065fdf2b9 Clean up code related to token and bad token handling
Things I noticed while writing I37f8e89b6d92c419d1b6569891612256342f8139,
but which felt too messy to include in that commit.

* Use promise chaining
* Update documentation
* Remove redundant code
* Split a method that now handles two different errors
* Grumble about localisation messages

Change-Id: I81e28a03af4f6c3452679ef6bbcaa89bb1235122
2020-02-15 03:52:40 +01:00
Bartosz Dziewoński 58757d4e3e Use built-in mw.Api 'badtoken' handling, also 'assert'/'assertuser'
When the user is saving their edit, we want to ensure that they
understand how it will be attributed. If the user gets logged out or
logs in in another tab, we want to display a message about it before
saving.

Instead of manually managing tokens and handling the 'badtoken' error
to detect this, use the 'assert'/'assertuser' parameters for the API
to detect it for us. Thanks to this we can rely on automatic retrying
for 'badtoken' errors in mw.Api#postWithToken.

It will be possible to share some of this code with other extensions
that already use ArticleTargetSaver, namely DiscussionTools, now that
it doesn't need to manage tokens for VisualEditor.

Bug: T245327
Depends-On: I485f99e1f5f493262b0c9af22370da01adf1e09c
Change-Id: I37f8e89b6d92c419d1b6569891612256342f8139
2020-02-15 03:37:22 +01:00
Bartosz Dziewoński c95be08cc4 Localize remaining hardcoded English error messages
Bug: T227325
Change-Id: Ibee27bd8457f83910da03ecb8801e5f26bdb3b2a
2020-02-12 22:18:40 +01:00
Bartosz Dziewoński f491196559 Fix reporting of loading errors from ArticleTarget#loadSuccess
It was broken on desktop and on mobile, but for different reasons:

Desktop: In change 5f1c68945d,
I removed some code from DesktopArticleTarget that was checking for
`typeof errorDetails === 'string'`. I thought it was unused, but it
was actually needed for this code.

Mobile: overlay.reportError() doesn't work here: that method displays
the error inside the save panel, which is not visible at this point.

This is now solved by treating those errors as if they were API errors,
which is something we were already doing in ArticleTargetSaver.

Change-Id: I5207836f56d65171b1240cef02fc17b9956036ef
2020-02-12 22:18:40 +01:00
David Lynch 0d6f984cc5 Change tags method so anon edits will go through
It turns out anonymous users can't apply change tags, so change
I2c1d0f8d69bc03e5c1877c790247e165f160e966 broke editing for them.

Bug: T242184
Change-Id: I7c27e4d9995428e213a980819810f235fdfe9435
2020-02-06 15:31:45 -06:00
jenkins-bot 124ae7a444 Merge "Tag VE edits from the client-side" 2020-02-04 16:43:59 +00:00
jenkins-bot 48da3746f8 Merge "Disallow switching in NWE welcome dialog if VE should be unavailable" 2020-02-03 23:59:10 +00:00
jenkins-bot f7a61e3f42 Merge "Allow switching in welcome dialog on mobile" 2020-02-03 23:57:18 +00:00
Bartosz Dziewoński f525f63b03 Remove hack to avoid iOS Safari menu bar area tap stealing
Explanation of what this code was for: T227628#5339392

As noted on that task, our behavior is actually unintuitive and
distracting, and iOS Safari limitations prevent us from doing it
better.

This reverts commit 600e369347.

Bug: T227628
Change-Id: Id1a5eebd06e4218e3e102165c60791999293d273
2020-01-31 21:22:23 +00:00
David Lynch d85d30f9b3 Tag VE edits from the client-side
This opens up the API so that other tools can use it without being
forced to tag those edits as being from VE.

Also, document that tags is a working parameter that can be passed
through to the edit API.

Bug: T242184
Change-Id: I2c1d0f8d69bc03e5c1877c790247e165f160e966
2020-01-29 21:55:07 -08:00
Bartosz Dziewoński 5c8d04afdb Disallow switching in NWE welcome dialog if VE should be unavailable
When NWE is enabled but VE is supposed to be unavailable on the page
(e.g. in talk namespaces), do not show the option to switch to VE in
the welcome dialog.

This is relevant if new users use NWE, due to config like below
(we use this on WMF Office wiki):

    $wgDefaultUserOptions['visualeditor-newwikitext'] = true;

Change-Id: Iee8c3d3604a13dcd20efa713e49461ba9b885749
2020-01-28 16:26:03 -08:00
Bartosz Dziewoński 36c2cb90ab Allow switching in welcome dialog on mobile
This code works perfectly on mobile now, I believe change
4fb17205b6 fixed that.

Note that the dialog is currently never shown due to the override
in MobileArticleTarget, but I tested after removing it.

Change-Id: I305a01fc78366a3d2d13662e6d71711864e0dffc
2020-01-28 16:25:53 -08:00
jenkins-bot 9e6a40a827 Merge "Use mw.Api#getErrorMessage instead of custom handling" 2020-01-10 14:22:14 +00:00
James D. Forrester 2c77e88d2c doc: Bump copyright year for 2020
Change-Id: I30539877543dc2a57bd1428a00d10ac46d8fc294
2020-01-08 09:13:24 -08:00
Ed Sanders edacc5bf65 MobileArticleTarget: Find DOM nodes after early return
No point running this jQuery search if we are about to return

Change-Id: I2240d4a15abbf7deb9b1f77154f299bd0d97ae18
2019-12-20 15:30:43 +00:00
Bartosz Dziewoński 5f1c68945d Use mw.Api#getErrorMessage instead of custom handling
Bug: T240519
Depends-On: Ie18666b41f4aff1ab4bcf93f9df6e3000ac7b500
Change-Id: I69d9432162f195dcfe9470485b549a1b007617ff
2019-12-14 17:01:35 +00:00
Bartosz Dziewoński a2b556ed56 ve.init.mw.DesktopArticleTarget: Remove dead error handling code
The .statusText and .status properties belong to the XMLHttpRequest
object, and are not present on the API response data object. I think
these checks were left over "just in case" when this code was ported
to use mw.Api instead of XMLHttpRequest directly.

MediaWiki API should never return just 'error' as the error code.

Change-Id: Iac6f721881b9405919d3397df6606e54f182bc59
2019-12-11 05:55:25 +01:00
Bartosz Dziewoński ef8ff1723a ve.init.mw.MobileArticleTarget: Don't close overlay when showing error
We've just displayed an error message in it, so don't close it.

I'm not sure if this code matters at all though. Usually when
there's an error during loading, code in MobileFrontend will close
the overlay and display an error message in a different way, so our
message won't be visible to the user. But maybe there's some case
I'm missing, and it's harmless. Closing the overlay was messing with
the MobileFrontend code though.

(found when working on I5146b726c5ce213992febb23f24c5937db0b9bfe)

Change-Id: Id1ea44d7bf6ef0f4fc0285e9e606dd415ed0a947
2019-12-11 05:55:25 +01:00
jenkins-bot 90bbfb5683 Merge "ApiVisualEditorEdit: Simplify diff handling a bit more!" 2019-12-02 11:18:52 +00:00
jenkins-bot 51ed492d0b Merge "Don't reject activatingDeferred on loadFail" 2019-11-28 19:47:43 +00:00