Commit graph

39 commits

Author SHA1 Message Date
Andrew Garrett 7e52a1ab2a Fail gracefully if there is no edit tab
For example, LiquidThreads pages, pages which are using DynamicTabs, etc.

Change-Id: I6b059dd76c150ee7fefb087aefe7fcccf41a3a43
2014-03-18 16:25:24 +11:00
James D. Forrester 5af9f61520 Let users set #REDIRECT and __STATICREDIRECT__ status
Adds setting and unsetting the #REDIRECT status of the page from the page
settings pane of the meta dialog, and toggle whether this is a static
redirect (i.e., it is not automatically changed when its target is moved).

If the page has a redirect set, the meta dialog will be shown on opening
the page so that users can adjust the redirect more swiftly.

Bug: 47328
Bug: 50878
Bug: 57173
Change-Id: Ibd89cf04486799f292b9fd045dae5bc23fcf6fd4
2014-02-12 15:24:12 -08:00
Ori Livneh 753d87e618 Tee tracked events to MediaWiki's mw.track
When running in the context of MediaWiki, VisualEditor should tee its event
stream to MediaWiki's main event bus, mw.track(), so that MediaWiki event
subscribers have a unified interface for subscribing to events. Each
VisualEditor event topic is prefixed with 've.'

To test this patch, you can use this snippet:

  mw.trackSubscribe( 've', function ( topic, data ) {
    console.log( this, topic, data );
  } );

Change-Id: I6b3f10b0dd0aa7fa47c3b35e2fc554622960ce52
2014-01-16 13:34:20 -08:00
James D. Forrester 0ffd654bed Bump copyright like it's 2014
Change-Id: Ic469ebda2c061dc7da0b4c1625f43a7be55da4fa
2014-01-05 20:06:50 +08:00
Timo Tijhof cf7f2b141d Set up node-jscs, pass it, and configure in local Gruntfile
Let's experiment with this via our local Gruntfile. If it works
fine we can install it in Jenkins (similar to node-csslint).

Verify through $ npm install && npm test;

Fixed all outstanding violations.

Also:
* Added syntaxhighight to ignore.
* Added imetests (which contain unformatted JSON) to ignore.
* In ve.dm.ModelRegistry#matchTypeRegExps, removed redundant
  !! cast from the [+!!withFunc] statement which was hitting
  a bug in node-jscs. All callers to this local private function
  pass a literal boolean true/false so no need to cast it.
* Removed "/* key .. , value */" from ve.setProp, though this
  wasn't caught by node-jscs, found it when searching for " , ".
* Made npm.devDependencies fixed instead of using tilde-ranges.
  This too often leads to strange bugs or sudden changes. Fixed
  them at the version they were currently ranging to.

Bug: 54218
Change-Id: Ib2630806f3946874c8b01e58cf171df83a28da29
2013-12-06 10:37:27 -08:00
James D. Forrester 7ba9f24121 Make veaction=edit work regardless of user preference
Move the userPrefEnabled check out of isAvailable and instead check
it in-line with isAvailable for setting up the tabs with CSS, but
not for the veaction=edit function.

Bug: 55900
Change-Id: I23984e377ff3fc797e921546492b8c73a5101235
2013-11-26 09:46:42 +00:00
Timo Tijhof 98bc6adf1f Use mw.util.getUrl instead of mw.util.wikiGetlink (deprecated)
Change-Id: I72afbbd909ce2394d54f78d465bd8ad245c1694f
2013-11-12 18:34:05 +01:00
Ed Sanders e8082ba968 Add requirements to BetaFeatures hook
Change-Id: Ifc809f49e1cf03015dbb295b6b092b4181edc38b
2013-10-11 14:50:41 +01:00
Ed Sanders 9cba9910c6 Enable VisualEditor using Beta Features
Change-Id: I76ba788751dacc24cdbc667b4d24f1656f0ade44
2013-10-11 14:50:24 +01:00
James D. Forrester 4da68b71d1 Reference core bug 53774 in bug 49000 comment
Bug: 49000
Bug: 53774
Change-Id: I1f26c7ac770daca06ae3c87742c1b3e3d2b17e41
2013-09-04 13:07:27 -07:00
Timo Tijhof 298afbf337 mw.ViewPageTarget.init: Don't add class ve-available when unavailable
In commit e1f8ee7 the return statement was moved into the
userPrefEnabled check, however addClass( 've-available' ) was
still unconditional. This has now been restored.

Change-Id: Ia59bfed93a8849a529cc3b9d1d2e0619d65240d4
2013-09-04 17:58:13 +00:00
Ori Livneh 825322d4ac Use internal ve.track to log events
This patch rounds off change I29740fa7a by replacing calls to EventLogging's
eventLog.logEvent with calls to VisualEditor's ve.track. ve.track publishes
events by providing an interface, ve.trackRegisterHandler, which event handlers
use to subscribe to VisualEditor events. By making it the responsibility of the
web analytics framework to register itself as a handler, VisualEditor can
remain decoupled from (and indeed ignorant of) any particular event logging
implementation. This allows VisualEditor to be integrated with many different
web analytics platforms with nothing more than a bit of glue code for mapping
ve's event semantics to those of the target platform.

The practical difference that this makes is that it frees VisualEditor from
having to know about EventLogging or from having to load EventLogging
components, which means we can remove quite a lot of gnarly code. My current
plan is to migrate the code for registering and loading the 'Edit'
schema module to Extension:CoreEvents, which is also where I'll commit the
handler for VE events. (CoreEvents exists precisely to provide an organized
place for persistent but WMF-particular instrumentation.)

Once this patch is merged and deployed, the following two configuration
variables may be removed from mediawiki-config:

- $wgVisualEditorEnableSplitTest
- $wgVisualEditorEnableEventLogging

Change-Id: Idfdf692668d2adfbe029e8f0c4ff9e96c60ff741
2013-08-15 19:43:36 +00:00
jenkins-bot ed5917faae Merge "Update reference to renamed init.setupSectionEditLinks method" 2013-08-05 09:20:14 +00:00
Matthew Flaschen ccd9889cd7 Tweak comment to explain isAvailable and what mw.libs.ve means
Change-Id: Ie5df644b0e70871345950afa188545279c3ee91c
2013-08-04 14:11:25 +00:00
Timo Tijhof 293b707acd Update reference to renamed init.setupSectionEditLinks method
Follows-up e1f8ee7890

Change-Id: Ib9e6c8cf472f656052adca4fbd87630ec1aaf697
2013-08-04 16:09:04 +02:00
Timo Tijhof e1f8ee7890 mw.ViewPageTarget.init: Setup "source" links even if VE is not available
Follows-up ced2a8a which moved the tab layout to the server-side
and changed it to set up "source" tab and section links always
everywhere (even if VE would not be availabe in the namespace
or browser).

The JS logic (which continues to exist to take care of pages
cached before we moved it to PHP and/or to fix up pages cached
with a different configuration in the future) didn't do this yet
causing the "Edit source" tab to inconsistently appear on pages
for anonymous users viewing pages where VE is not available.

Change-Id: Ic575b3fcef17e636adaa338abc7748a4388ed9a9
2013-08-02 22:25:44 +02:00
jenkins-bot 07a513ac9d Merge "Move edit tab generation into PHP and make it more configurable" 2013-08-02 04:10:46 +00:00
Roan Kattouw ced2a8aa59 Move edit tab generation into PHP and make it more configurable
* Generate the edit tabs and the section edit links in PHP, with a
  fallback in JS for cases where we don't have them yet due to
  caching. But only change things if VE is enabled, and have the JS
  correct the state if the wrong cached HTML comes through.
* Make the order of the tabs/links and the messages to use as captions
  configurable
* Make the edit tabs and section edit links always be present in the
  page (regardless of namespace, user prefs, etc.) but be hidden and
  have JS unhide them (using html.ve-available) if appropriate
* Add appendix messages so we can do a superscript "beta" even in places
  where we can't use HTML in the message

VisualEditor.php:
* Add new hook registrations
* Remove edit link caption messages from the init init module because
  they're now added dynamically in VisualEditor.hooks.php
* Add a noscript CSS module so we can hide some things in JS-less
  environments
* Remove $wgVisualEditorTabLayout and replace it with
  $wgVisualEditorPosition
* Add config vars for link captions, with null causing us to use
  the default caption
* Add config vars for link caption appendices. Too many config vars
  but we'll clean that up later

VisualEditor.hooks.php:
* Dynamically add tab messages to the init init module
* Remove unused globals in onBeforePageDisplay()
* Add noscript CSS module
* Add a SkinTemplateNavigation hook that changes and reorders the edit
  tabs as appropriate
* Add a DoEditSectionLink hook that overwrites the edit section links
* Export the new config variables to JS

VisualEditor.i18n.php:
* Add beta appendix message
* Add a message for the default VE edit section link

ve.init.mw.ViewPageTarget.init.css:
* Remove the animation on the edit section links
* Darken the color of the brackets and the pipe from #ccc to #555
* Style the beta message to be superscript-like (but not real <sup> to
  avoid moving the baseline)

ve.init.mw.ViewPageTarget.noscript.css:
* Hide the VE edit tab, the pipe and the VE edit section link initally
  unless and until JS unhides

ve.init.mw.ViewPageTarget.init.js:
* Toggle .ve-not-available / .ve-available
* Edit tabs
** Only generate the the edit tabs if they're not already there from PHP
** Rewrite the edit tab generation to mirror what's being done in PHP
* Section edit links
** Same as for edit tabs
** Also add mw-visualeditor-expanded to pad the brackets

ve.init.mw.ViewPageTarget.js:
* #ca-ve-edit is now always the VE tab (and #ca-edit always the
  edit source tab) so update the .selected behavior accordingly

Change-Id: Idcb15faea7fabe5fe7578b1508079969b27d2469
2013-08-01 21:08:13 -07:00
Ed Sanders 87bfe3ee09 mw.ViewPageTarget.init: Fix pageExists/isViewPage behaviour
"Let me clarify this for you" - Timo

Follows-up 1984c3ca46.

Bug: 49000
Change-Id: Ia094aa9aae1da1ba11dbaef827e305cbcf08f9b4
2013-08-01 23:58:10 +00:00
Ed Sanders 1984c3ca46 Fix edit links on special pages
Added wgIsArticle to isViewPage checks, otherwise we were attempting
to load VE dynamically on Special:Move/Delete, which resulted in a
broken h1 title and odd behavior off the 'Read' tab.

Also added !wgIsArticle to pageExists. This is a bit of a hack because
we don't have any info on page existence in the JS on these pages
(I think?). But it's better to display 'Edit' for a page that doesn't
exist, than 'Create' for a page that does.

Bug: 49000
Change-Id: Ib47e5524d41e6066b362e0f5645750c769de5193
2013-08-01 23:14:51 +01:00
Timo Tijhof 9e89c019f1 mw.ViewPageTarget.init: Don't depend on mediawiki.user
Follows-up 5036099. We don't have that dependency.

Change-Id: I2bdf397a0e575f3f0fb82b905c92c34278b39037
2013-08-01 03:46:49 +02:00
Timo Tijhof ac6c4da3a7 doc: @return -> @returns
Follows-up 8f05cdbf70.

Change-Id: Id2b68e521ab68862f0f635925708a35d10795342
2013-08-01 02:10:23 +02:00
jenkins-bot dd3d41841d Merge changes I9ca43005,I68f9258f
* changes:
  ve.init.mw.ViewPageTarget.init: Pass default values
  VisualEditor.hooks: Sort keys
2013-07-31 22:06:38 +00:00
Timo Tijhof 5036099906 ve.init.mw.ViewPageTarget.init: Pass default values
Though this is already handled by Ie50b63ba5064e85d26 for the
server-side, and that should automatically reflect to the
client-side. Since we're dealing with cache conditions in
wmf-production where the user.options manifest does not yet
contain an entry for these relatively new preferences, lets
transfer the default value here as well. This does not affect
logged-in users (since their user options are always up-to-date
and embedded in the page).

Also made ve.support.es5 be casted to boolean. Previously it
would be a reference to JSON.stringify (if supported), or the
bottom value of whichever feature the browser didn't support.
Doesn't change any behaviour but should make things slightly
more performant when this value is evaluated.

Change-Id: I9ca430051ae6f4e603c2d89982e540e455055255
2013-07-31 20:46:45 +00:00
Ori Livneh ca98a473c2 Add ve.now utility function
On browsers that implement the Navigation Timing API, performance.now()
provides values with microsecond precision that are guaranteed to be monotonic
(i.e., they are not subject to skew due to changes to the system clock).
This patch adds a `ve.now` utility function that will use this API when it is
available and fall back gracefully to `Date.now` when it is not.

Change-Id: I377025fcb23cb26399b9e437e33c8afa138916af
2013-07-31 13:42:08 -07:00
MatmaRex 54c5230b01 Unblacklist Opera >= 12
Opera 12 seems to work well enough, but I'm not confident enough to
whitelist it just yet.

Opera 15 is basically Chrome with a different interface, so it should
work perfectly, but it's barely out of beta and untested right now.

Bug: 36000
Change-Id: Ia80a6f53f8c128ef52d0bfde1828fdc132046afb
2013-07-29 12:30:06 -07:00
Roan Kattouw e49df7f9d9 Infrastructure for loading plugins in the MW integration
Server-side, plugins can register themselves by adding to
$wgVisualEditorPluginModules. This is the recommended way for
MW extensions to extend VE. Client-side, plugins can register
themselves through mw.libs.ve.addPlugin(), which takes a string
(RL module name) or a callback.

When VisualEditor loads, we load the registered plugin modules in
parallel with ext.visualEditor.core. Note that they're loaded in
parallel, not after, and so the plugins should explicitly depend
on ext.visualEditor.core if they use or extend classes in VE core.
Once the modules finish loading and user and site scripts have run,
we execute the registered plugin callbacks. These callbacks can
optionally return a promise. We gather these promises and wait for
all of them to be resolved, then initialize the editor.

This allows Gadgets to extend VE by top-loading a small module that
depends on ext.visualEditor.viewPageTarget.init and calls
mw.libs.ve.addPlugin( 'ext.gadget.bottomHalfGadget' ); , the bottom
half being a hidden Gadget that depends on ext.visualEditor.core and
contains the actual code. The addPlugin() call needs to be in a
top-loading module because otherwise there's no guarantee that the
plugin will be registered before the user clicks edit and VE loads.

User and site scripts can extend VE by simply calling addPlugin()
directly, as mw.libs.ve is already present when user scripts run (since
it's top-loaded) and VE waits for 'user' and 'site' to run before
executing plugins.

If user/site scripts need to load additional JS files, they can load
these with $.getScript() and return the corresponding promise:
mw.libs.ve.addPlugin( function() { return $.getScript( 'URL' ); } );

For a diagram of all this, see
https://www.mediawiki.org/wiki/File:VE-plugin-infrastructure.jpg :)

VisualEditor.php:
* Add $wgVisualEditorPluginModules

VisualEditor.hooks.php:
* Expose $wgVisualEditorPluginModules in JS

ve.init.mw.ViewPageTarget.init.js:
* Add mw.libs.ve.addPlugin function that just stores the registered
  values in an array and passes them into the mw.Target when it's
  being initialized

ve.init.mw.Target.js:
* Add $wgVisualEditorPluginModules to the set of modules to load when
  initializing VE
* Add a Deferred (this.modulesReady) to track module loading
* Add addPlugin() and addPlugins() methods that add to either
  this.modules or this.pluginCallbacks
* In load(), instead of mw.loader.load()ing this.modules, use using()
  to load this.modules plus user and site, and fire onModulesReady()
  when they're loaded
* In onModulesReady(), execute the registered callbacks, gather the
  returned promises, wait for all of them to be resolved, then resolve
  this.modulesReady
* Fire onReady based on this.modulesReady being resolved, rather than
  using a second using() call

Bug: 50514
Change-Id: Ib7d87a17eaac6ecdb8b0803b13840d7ee58902df
2013-07-26 19:31:56 +00:00
James D. Forrester 0536d22370 Create temporary preference to disable VisualEditor during beta
This preference will allow users to opt-out of VisualEditor during the beta
if they so choose. We do not re-use the alpha enablement flag because (a) this
would lead to a confusing preference description, and (b) because opting in
and then out of the alpha is not the same user choice as opting out of the
beta period.

Change-Id: I0f0a1b5eb21703ad422d007cab65c75ac1aa6fd8
2013-07-24 01:59:47 +00:00
Timo Tijhof a81beef27a mw.ViewPageTarget.init: Move conditionals client-side
Load the module always and have the conditionals on the
client-side so that we can change these without running into
problems with the new conditions not being rolled-out quickly
for anonymous users because the load queue is in the HTML
and cached for 30+ days.

This also allows us to fix above problem retroactively in wmf
production by just adding a mw.loader.load for this module
in something like MediaWiki:Common.js or something else that is
already in the cached load queue (temporarily, until the cache
has rolled over).

Removed unreachable code for loading ext.visualEditor.splitTest.

Change-Id: I21114960a88d224747447f2dc83d17d160f5f066
2013-07-23 20:25:37 +02:00
Timo Tijhof 61a1e8c738 mw.ViewPageTarget.init: Expose support.visualEditor
Refactor a few things to make it easier for scripts to see
not just whether mw.libs.ve is present but also whether it
allows the user to activate VisualEditor.

Change-Id: I50da8d9a260207d4ec1c43254dfe738f91386a9e
2013-07-19 03:56:25 +02:00
Timo Tijhof a7e8c9d660 mw.ViewPageTarget.init: Document use of mw.libs.ve to test presence
The presence check used to be against the VE global, but we
recently made that impossible without providing an alternative.

Though by accident, mw.libs.ve has become the new way to check
for presence.

Change-Id: If85695525777a71dde467675052d2ede4e52c9b7
2013-07-10 15:55:17 +02:00
Timo Tijhof fdedbb36e2 mw.ViewPageTarget.init: Clarify reason for FF12 / FF14 blacklist
Follows-up I7a9dddb693091f.

Change-Id: I49a952f6b1714808cd4f063c48cf3102997f8746
2013-07-09 13:11:15 +02:00
James D. Forrester d59a3f1202 Blacklist Firefox 13 and 14 too
Firefox 13 and 14 were the cause of links magically turning into [[./Foo]].
Once the immediate rush of deployment is over, we'll want to investigate as
to why and hopefully find a way to unblacklist FF.

Bug: 50720
Change-Id: I7a9dddb693091fa1e44b4325e77b9e4f55e5c193
2013-07-08 18:20:42 -07:00
Timo Tijhof 106f357852 mw.ViewPageTarget.init: Only bind edit section links on view page
The handler for the Edit tab already is in this conditional,
for edit section we were making the assumption that they only
ever appear on a view page, but that's wrong. They're also shown
on a diff against the latest revision of the page.

Bug: 50925
Change-Id: I802e548cbcdc03cfca66129466668854604bc3e7
2013-07-08 16:12:47 -07:00
jenkins-bot 614a1a3d9c Merge "mw.ViewPageTarget.init: Move edit section to top init" 2013-07-05 18:40:12 +00:00
Timo Tijhof eddd0b384a mw.ViewPageTarget.init: Move edit section to top init
Since we're now only loading the light-weight init on page load,
the section editing wasn't just deferred to after page load (like
it was before), but wasn't happening at all until you clicked
"Edit" (at which point the library loads). It only worked when
going back to "View" after "Edit".

Contrary to tab layout, edit section handling needs to be
accessible both in the top init and in the main target class
because we need to run it both at run time and after the user
has saved a page when we show them the updated page without
refresh. This is why we need to transfer the method at run time
and give the main class access to it as well.
Can't wait for bug 50707 to get rid of this mess...

Bug: 50731
Bug: 49993
Change-Id: Iab9c81222df7f1084179c3643d158374a89ca14b
2013-07-05 18:29:12 +00:00
James D. Forrester 92991ef20f Blacklist Firefox 11 and 12
Bug: 50780

Change-Id: I6461f066443223dfd5f6d73aeea0c87cbbdb81d0
2013-07-05 11:24:06 -07:00
Timo Tijhof 1875851f7e mw.ViewPageTarget.init: Remove harmless debugging code for ES5
Was accidentally kept in Ic8b0004ab5288fa9.

Change-Id: I1c95189437e3e74c5e2884d14c1ccf000ef0c178
2013-07-04 02:08:41 +02:00
Timo Tijhof b21fe5fbc1 Split off setup from the rest of mw.ViewPageTarget
Initialisation initialisation? It's time to rename ve.init
to ve.platform and ve.init.Platform to ve.platform.Environment,
but that'll come later.

* Moved support detection and skin set up to separate class-less
  file.
* Swapped usage of ve.msg for mw.msg.
* Callback of edit tab now does an mw.loader call to fetch
  the actual VisualEditor libraries.
  Though mw.loader won't load the same thing twice, we would
  bind a callback each time. To avoid instantiating ViewPageTarget
  more than once we use a Deferred.

Bug: 50542
Bug: 50608
Bug: 50612
Change-Id: Ic8b0004ab5288fa91bb29d496485b93ffd8d977e
2013-07-04 01:18:28 +02:00