2012-05-25 19:50:48 +00:00
|
|
|
|
<?php
|
2012-07-19 00:11:26 +00:00
|
|
|
|
/**
|
|
|
|
|
* VisualEditor extension hooks
|
2012-07-19 21:25:16 +00:00
|
|
|
|
*
|
2012-07-19 00:11:26 +00:00
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Extensions
|
2018-01-03 00:54:47 +00:00
|
|
|
|
* @copyright 2011-2018 VisualEditor Team and others; see AUTHORS.txt
|
2012-07-19 00:11:26 +00:00
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
|
*/
|
2012-05-25 19:50:48 +00:00
|
|
|
|
|
2017-04-19 15:15:06 +00:00
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
|
2012-05-25 19:50:48 +00:00
|
|
|
|
class VisualEditorHooks {
|
2017-04-27 15:23:26 +00:00
|
|
|
|
|
|
|
|
|
// Known parameters that VE does not handle
|
|
|
|
|
// TODO: Other params too?
|
2017-09-20 15:16:32 +00:00
|
|
|
|
// Known-good parameters: edit, veaction, section, oldid, lintid, preload, preloadparams, editintro
|
|
|
|
|
// Partially-good: preloadtitle (source-mode only)
|
2017-04-27 15:23:26 +00:00
|
|
|
|
private static $unsupportedEditParams = [
|
|
|
|
|
'undo',
|
|
|
|
|
'undoafter',
|
|
|
|
|
'veswitched'
|
|
|
|
|
];
|
|
|
|
|
|
2015-01-27 05:47:31 +00:00
|
|
|
|
/**
|
2015-08-02 21:30:43 +00:00
|
|
|
|
* Initialise the 'VisualEditorAvailableNamespaces' setting, and add content
|
|
|
|
|
* namespaces to it. This will run after LocalSettings.php is processed.
|
2015-01-27 05:47:31 +00:00
|
|
|
|
*/
|
|
|
|
|
public static function onRegistration() {
|
2015-08-02 21:30:43 +00:00
|
|
|
|
global $wgVisualEditorAvailableNamespaces, $wgContentNamespaces;
|
2015-01-27 05:47:31 +00:00
|
|
|
|
|
2015-08-02 21:30:43 +00:00
|
|
|
|
foreach ( $wgContentNamespaces as $contentNamespace ) {
|
|
|
|
|
if ( !isset( $wgVisualEditorAvailableNamespaces[$contentNamespace] ) ) {
|
|
|
|
|
$wgVisualEditorAvailableNamespaces[$contentNamespace] = true;
|
|
|
|
|
}
|
2015-07-06 18:57:13 +00:00
|
|
|
|
}
|
2015-01-27 05:47:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-04 22:17:29 +00:00
|
|
|
|
public static function getVisualEditorApiFactory( $main, $name ) {
|
2015-01-27 05:47:31 +00:00
|
|
|
|
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' );
|
|
|
|
|
$class = $name === 'visualeditor' ? 'ApiVisualEditor' : 'ApiVisualEditorEdit';
|
|
|
|
|
return new $class( $main, $name, $config );
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-25 19:50:48 +00:00
|
|
|
|
/**
|
2013-08-01 19:14:41 +00:00
|
|
|
|
* Adds VisualEditor JS to the output.
|
2012-06-11 06:54:41 +00:00
|
|
|
|
*
|
|
|
|
|
* This is attached to the MediaWiki 'BeforePageDisplay' hook.
|
2012-05-25 19:50:48 +00:00
|
|
|
|
*
|
2017-05-04 22:59:27 +00:00
|
|
|
|
* @param OutputPage &$output The page view.
|
|
|
|
|
* @param Skin &$skin The skin that's going to build the UI.
|
2017-07-25 14:49:56 +00:00
|
|
|
|
* @return bool Always true.
|
2012-05-25 19:50:48 +00:00
|
|
|
|
*/
|
2014-09-25 05:06:57 +00:00
|
|
|
|
public static function onBeforePageDisplay( OutputPage &$output, Skin &$skin ) {
|
2016-02-17 16:18:02 +00:00
|
|
|
|
$output->addModules( [
|
2015-07-29 13:41:30 +00:00
|
|
|
|
'ext.visualEditor.desktopArticleTarget.init',
|
Load RL modules in one load.php request, rather than in two stages
This introduces TargetLoader, which manages plugins and RL modules
in a slightly more generic fashion so that Targets themselves don't
have to. This allows us to load all RL modules in one load.php
request, rather than first loading ViewPageTarget which then
loads the other modules.
TargetLoader loads in the bottom queue, so it will be loaded
as part of the main load.php request, but in VPT.init.js we
still have to wait for it with using() because it might not
have arrived yet. This also degrades gracefully on cached pages
where TargetLoader isn't in the bottom queue: it'll be loaded
as a separate request instead, which is suboptimal but no
worse that what we were doing before.
Right now TargetLoader is small enough that it could also be in
the top queue, but in the future we want to add things like
the action=visualeditor API request to it, and mw.Api is
relatively big.
Note: this also makes a breaking change to the plugin API:
plugin callbacks no longer receive the target instance
as a parameter, as they're now executed before the target
has been constructed rather than after. In the long term,
if we want to give plugins access to the target instance,
we could give them the target promise somehow. For now,
I've killed this feature because nothing used it and
the change from a direct object reference to a promise
would have been a breaking change anyway.
Also fixed incorrect documentation index for ve.init.mw.ViewPageTarget.init.
Bug: T53569
Change-Id: Ibfa6abbeaf872ae2aadc6ed9d5beba7473ea441a
2015-02-26 01:22:44 +00:00
|
|
|
|
'ext.visualEditor.targetLoader'
|
2016-02-17 16:18:02 +00:00
|
|
|
|
] );
|
|
|
|
|
$output->addModuleStyles( [ 'ext.visualEditor.desktopArticleTarget.noscript' ] );
|
2015-04-09 09:18:22 +00:00
|
|
|
|
// add scroll offset js variable to output
|
|
|
|
|
$veConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' );
|
|
|
|
|
$skinsToolbarScrollOffset = $veConfig->get( 'VisualEditorSkinToolbarScrollOffset' );
|
|
|
|
|
$toolbarScrollOffset = 0;
|
|
|
|
|
$skinName = $skin->getSkinName();
|
|
|
|
|
if ( isset( $skinsToolbarScrollOffset[$skinName] ) ) {
|
|
|
|
|
$toolbarScrollOffset = $skinsToolbarScrollOffset[$skinName];
|
|
|
|
|
}
|
|
|
|
|
$output->addJsConfigVars( 'wgVisualEditorToolbarScrollOffset', $toolbarScrollOffset );
|
2017-04-27 15:23:26 +00:00
|
|
|
|
$output->addJsConfigVars( 'wgVisualEditorUnsupportedEditParams', self::$unsupportedEditParams );
|
2016-06-30 14:04:51 +00:00
|
|
|
|
|
2018-02-07 19:48:49 +00:00
|
|
|
|
$output->addJsConfigVars(
|
|
|
|
|
'wgEditSubmitButtonLabelPublish',
|
|
|
|
|
$veConfig->get( 'EditSubmitButtonLabelPublish' )
|
|
|
|
|
);
|
2013-08-01 19:14:41 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-09 13:45:59 +00:00
|
|
|
|
public static function onDiffViewHeader(
|
|
|
|
|
DifferenceEngine $diff,
|
2017-06-28 21:12:17 +00:00
|
|
|
|
Revision $oldRev = null,
|
|
|
|
|
Revision $newRev = null
|
2017-06-09 13:45:59 +00:00
|
|
|
|
) {
|
|
|
|
|
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' );
|
|
|
|
|
$output = RequestContext::getMain()->getOutput();
|
2018-01-25 21:36:05 +00:00
|
|
|
|
$user = RequestContext::getMain()->getUser();
|
|
|
|
|
|
|
|
|
|
if ( !(
|
|
|
|
|
// Enabled globally on wiki
|
|
|
|
|
$config->get( 'VisualEditorEnableDiffPage' ) ||
|
|
|
|
|
// Enabled as user beta feature
|
|
|
|
|
$user->getOption( 'visualeditor-visualdiffpage' ) ||
|
|
|
|
|
// Enabled by query param
|
|
|
|
|
$output->getRequest()->getVal( 'visualdiff' ) !== null
|
|
|
|
|
) ) {
|
2017-06-09 13:45:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-18 22:09:04 +00:00
|
|
|
|
$veConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' );
|
|
|
|
|
if ( !ApiVisualEditor::isAllowedContentType( $veConfig, $diff->getTitle()->getContentModel() ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-09 13:45:59 +00:00
|
|
|
|
$output->addModuleStyles( [
|
|
|
|
|
'ext.visualEditor.diffPage.init.styles',
|
|
|
|
|
'oojs-ui.styles.icons-alerts',
|
|
|
|
|
'oojs-ui.styles.icons-editing-advanced'
|
|
|
|
|
] );
|
|
|
|
|
$output->addModules( 'ext.visualEditor.diffPage.init' );
|
|
|
|
|
$output->enableOOUI();
|
|
|
|
|
$output->addHtml(
|
|
|
|
|
'<div class="ve-init-mw-diffPage-diffMode">' .
|
|
|
|
|
// Will be replaced by a ButtonSelectWidget in JS
|
|
|
|
|
new OOUI\ButtonGroupWidget( [
|
|
|
|
|
'items' => [
|
|
|
|
|
new \OOUI\ButtonWidget( [
|
|
|
|
|
'data' => 'visual',
|
|
|
|
|
'icon' => 'eye',
|
|
|
|
|
'disabled' => true,
|
|
|
|
|
'label' => $output->msg( 'visualeditor-savedialog-review-visual' )->plain()
|
|
|
|
|
] ),
|
|
|
|
|
new \OOUI\ButtonWidget( [
|
|
|
|
|
'data' => 'source',
|
|
|
|
|
'icon' => 'wikiText',
|
|
|
|
|
'active' => true,
|
|
|
|
|
'label' => $output->msg( 'visualeditor-savedialog-review-wikitext' )->plain()
|
|
|
|
|
] )
|
|
|
|
|
]
|
|
|
|
|
] ) .
|
|
|
|
|
'</div>'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 22:39:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* Detect incompatibile browsers which we can't expect to load VE
|
|
|
|
|
*
|
|
|
|
|
* @param WebRequest $req The web request to check the details of
|
|
|
|
|
* @param Config $config VE config object
|
2017-07-25 14:49:56 +00:00
|
|
|
|
* @return bool True if the User Agent is blacklisted
|
2015-12-16 22:39:19 +00:00
|
|
|
|
*/
|
|
|
|
|
private static function isUABlacklisted( WebRequest $req, $config ) {
|
|
|
|
|
if ( $req->getVal( 'vewhitelist' ) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$blacklist = $config->get( 'VisualEditorBrowserBlacklist' );
|
|
|
|
|
$ua = strtolower( $req->getHeader( 'User-Agent' ) );
|
|
|
|
|
foreach ( $blacklist as $uaSubstr => $rules ) {
|
2016-01-22 02:22:34 +00:00
|
|
|
|
if ( !strpos( $ua, $uaSubstr . '/' ) ) {
|
2015-12-16 22:39:19 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if ( !is_array( $rules ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 16:18:02 +00:00
|
|
|
|
$matches = [];
|
2016-01-22 02:22:34 +00:00
|
|
|
|
$ret = preg_match( '/' . $uaSubstr . '\/([0-9\.]*) ?/i', $ua, $matches );
|
|
|
|
|
if ( $ret !== 1 ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$version = $matches[1];
|
2015-12-16 22:39:19 +00:00
|
|
|
|
foreach ( $rules as $rule ) {
|
|
|
|
|
list( $op, $matchVersion ) = $rule;
|
|
|
|
|
if (
|
|
|
|
|
( $op === '<' && $version < $matchVersion ) ||
|
|
|
|
|
( $op === '>' && $version > $matchVersion ) ||
|
|
|
|
|
( $op === '<=' && $version <= $matchVersion ) ||
|
|
|
|
|
( $op === '>=' && $version >= $matchVersion )
|
|
|
|
|
) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 15:23:26 +00:00
|
|
|
|
private static function isSupportedEditPage( Title $title, User $user, WebRequest $req ) {
|
|
|
|
|
if ( $req->getVal( 'action' ) !== 'edit' || !$title->quickUserCan( 'edit' ) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( self::$unsupportedEditParams as $param ) {
|
|
|
|
|
if ( $req->getVal( $param ) !== null ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $req->getVal( 'wteswitched' ) ) {
|
|
|
|
|
return self::isVisualAvailable( $title );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch ( self::getPreferredEditor( $user, $req ) ) {
|
|
|
|
|
case 'visualeditor':
|
|
|
|
|
return self::isVisualAvailable( $title ) || self::isWikitextAvailable( $title, $user );
|
|
|
|
|
case 'wikitext':
|
|
|
|
|
return self::isWikitextAvailable( $title, $user );
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static function isVisualAvailable( $title ) {
|
|
|
|
|
$veConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' );
|
|
|
|
|
return ApiVisualEditor::isAllowedNamespace( $veConfig, $title->getNamespace() ) &&
|
|
|
|
|
ApiVisualEditor::isAllowedContentType( $veConfig, $title->getContentModel() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static function isWikitextAvailable( $title, $user ) {
|
|
|
|
|
$veConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' );
|
|
|
|
|
return $veConfig->get( 'VisualEditorEnableWikitext' ) &&
|
|
|
|
|
$user->getOption( 'visualeditor-newwikitext' ) &&
|
|
|
|
|
$title->getContentModel() === 'wikitext';
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-23 16:29:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* Decide whether to bother showing the wikitext editor at all.
|
|
|
|
|
* If not, we expect the VE initialisation JS to activate.
|
2017-05-04 22:59:27 +00:00
|
|
|
|
*
|
|
|
|
|
* @param Article $article The article being viewed.
|
|
|
|
|
* @param User $user The user-specific settings.
|
2017-07-25 14:49:56 +00:00
|
|
|
|
* @return bool Whether to show the wikitext editor or not.
|
2015-10-23 16:29:56 +00:00
|
|
|
|
*/
|
|
|
|
|
public static function onCustomEditor( Article $article, User $user ) {
|
2015-12-17 18:18:32 +00:00
|
|
|
|
$req = $article->getContext()->getRequest();
|
2015-10-23 16:29:56 +00:00
|
|
|
|
$veConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' );
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
!$user->getOption( 'visualeditor-enable' ) ||
|
|
|
|
|
$user->getOption( 'visualeditor-betatempdisable' ) ||
|
|
|
|
|
$user->getOption( 'visualeditor-autodisable' ) ||
|
|
|
|
|
( $veConfig->get( 'VisualEditorDisableForAnons' ) && $user->isAnon() ) ||
|
2015-12-16 22:39:19 +00:00
|
|
|
|
self::isUABlacklisted( $req, $veConfig )
|
2015-10-23 16:29:56 +00:00
|
|
|
|
) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$title = $article->getTitle();
|
|
|
|
|
|
2017-04-27 15:23:26 +00:00
|
|
|
|
if ( $req->getVal( 'venoscript' ) ) {
|
2016-02-17 16:18:02 +00:00
|
|
|
|
$req->response()->setCookie( 'VEE', 'wikitext', 0, [ 'prefix' => '' ] );
|
2015-12-17 18:18:32 +00:00
|
|
|
|
$user->setOption( 'visualeditor-editor', 'wikitext' );
|
2016-04-21 14:33:24 +00:00
|
|
|
|
if ( !wfReadOnly() && !$user->isAnon() ) {
|
|
|
|
|
DeferredUpdates::addCallableUpdate( function () use ( $user ) {
|
|
|
|
|
$user->saveSettings();
|
|
|
|
|
} );
|
|
|
|
|
}
|
2015-12-17 18:18:32 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 15:23:26 +00:00
|
|
|
|
if ( self::isSupportedEditPage( $title, $user, $req ) ) {
|
|
|
|
|
$params = $req->getValues();
|
|
|
|
|
$params['venoscript'] = '1';
|
|
|
|
|
$url = wfScript() . '?' . wfArrayToCgi( $params );
|
2016-01-23 00:14:32 +00:00
|
|
|
|
$escapedUrl = htmlspecialchars( $url );
|
2016-02-05 02:26:14 +00:00
|
|
|
|
|
2017-04-27 15:23:26 +00:00
|
|
|
|
$out = $article->getContext()->getOutput();
|
2016-02-05 02:26:14 +00:00
|
|
|
|
$titleMsg = $title->exists() ? 'editing' : 'creating';
|
|
|
|
|
$out->setPageTitle( wfMessage( $titleMsg, $title->getPrefixedText() ) );
|
2016-02-27 01:47:15 +00:00
|
|
|
|
$out->addWikiMsg( 'visualeditor-toload', wfExpandUrl( $url ) );
|
2017-04-27 15:23:26 +00:00
|
|
|
|
|
|
|
|
|
// Redirect if the user has no JS (<noscript>)
|
|
|
|
|
$out->addHeadItem(
|
|
|
|
|
've-noscript-fallback',
|
|
|
|
|
"<noscript><meta http-equiv=\"refresh\" content=\"0; url=$escapedUrl\"></noscript>"
|
|
|
|
|
);
|
|
|
|
|
// Redirect if the user has no ResourceLoader
|
2017-04-18 17:47:04 +00:00
|
|
|
|
$out->addScript( Html::inlineScript(
|
|
|
|
|
"(window.NORLQ=window.NORLQ||[]).push(" .
|
|
|
|
|
"function(){" .
|
|
|
|
|
"location.href=\"$url\";" .
|
|
|
|
|
"}" .
|
|
|
|
|
");"
|
|
|
|
|
) );
|
2017-11-08 14:41:40 +00:00
|
|
|
|
$out->setRevisionId( $req->getInt( 'oldid', $article->getRevIdFetched() ) );
|
2017-04-27 15:23:26 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static function getPreferredEditor( User $user, WebRequest $req ) {
|
2017-05-15 11:33:40 +00:00
|
|
|
|
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' );
|
|
|
|
|
// On dual-edit-tab wikis, the edit page must mean the user wants wikitext
|
|
|
|
|
if ( !$config->get( 'VisualEditorUseSingleEditTab' ) ) {
|
|
|
|
|
return 'wikitext';
|
|
|
|
|
}
|
2017-04-27 15:23:26 +00:00
|
|
|
|
switch ( $user->getOption( 'visualeditor-tabs' ) ) {
|
|
|
|
|
case 'prefer-ve':
|
|
|
|
|
return 'visualeditor';
|
|
|
|
|
case 'prefer-wt':
|
|
|
|
|
return 'wikitext';
|
|
|
|
|
case 'remember-last':
|
|
|
|
|
return self::getLastEditor( $user, $req );
|
|
|
|
|
case 'multi-tab':
|
|
|
|
|
// May have got here by switching from VE
|
|
|
|
|
// TODO: Make such an action explicitly request wikitext
|
|
|
|
|
// so we can use getLastEditor here instead.
|
|
|
|
|
return 'wikitext';
|
2015-12-17 18:18:32 +00:00
|
|
|
|
}
|
2017-04-27 15:23:26 +00:00
|
|
|
|
return null;
|
2015-10-23 16:29:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 15:23:26 +00:00
|
|
|
|
private static function getLastEditor( User $user, WebRequest $req ) {
|
2016-04-11 22:56:33 +00:00
|
|
|
|
// This logic matches getLastEditor in:
|
|
|
|
|
// modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
|
|
|
|
|
$editor = $req->getCookie( 'VEE', '' );
|
|
|
|
|
// Set editor to user's preference or site's default if …
|
|
|
|
|
if (
|
|
|
|
|
// … user is logged in,
|
|
|
|
|
!$user->isAnon() ||
|
|
|
|
|
// … no cookie is set, or
|
|
|
|
|
!$editor ||
|
|
|
|
|
// value is invalid.
|
|
|
|
|
!( $editor === 'visualeditor' || $editor === 'wikitext' )
|
|
|
|
|
) {
|
|
|
|
|
$editor = $user->getOption( 'visualeditor-editor' );
|
2015-12-10 20:30:01 +00:00
|
|
|
|
}
|
2016-04-11 22:56:33 +00:00
|
|
|
|
return $editor;
|
2015-12-10 20:30:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-01 19:14:41 +00:00
|
|
|
|
/**
|
|
|
|
|
* Changes the Edit tab and adds the VisualEditor tab.
|
|
|
|
|
*
|
|
|
|
|
* This is attached to the MediaWiki 'SkinTemplateNavigation' hook.
|
|
|
|
|
*
|
2017-05-04 22:59:27 +00:00
|
|
|
|
* @param SkinTemplate &$skin The skin template on which the UI is built.
|
|
|
|
|
* @param array &$links Navigation links.
|
2017-07-25 14:49:56 +00:00
|
|
|
|
* @return bool Always true.
|
2013-08-01 19:14:41 +00:00
|
|
|
|
*/
|
2014-09-25 05:06:57 +00:00
|
|
|
|
public static function onSkinTemplateNavigation( SkinTemplate &$skin, array &$links ) {
|
2015-08-25 15:53:55 +00:00
|
|
|
|
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' );
|
|
|
|
|
|
2015-10-23 16:29:56 +00:00
|
|
|
|
// Exit if there's no edit link for whatever reason (e.g. protected page)
|
|
|
|
|
if ( !isset( $links['views']['edit'] ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-10 20:30:01 +00:00
|
|
|
|
$user = $skin->getUser();
|
2015-10-23 16:29:56 +00:00
|
|
|
|
if (
|
|
|
|
|
$config->get( 'VisualEditorUseSingleEditTab' ) &&
|
2015-12-10 20:30:01 +00:00
|
|
|
|
$user->getOption( 'visualeditor-tabs' ) === 'prefer-wt'
|
|
|
|
|
) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-07 19:14:07 +00:00
|
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2015-12-10 20:30:01 +00:00
|
|
|
|
if (
|
|
|
|
|
$config->get( 'VisualEditorUseSingleEditTab' ) &&
|
2016-03-06 00:07:06 +00:00
|
|
|
|
!$user->isAnon() &&
|
|
|
|
|
!$user->getOption( 'visualeditor-autodisable' ) &&
|
|
|
|
|
!$user->getOption( 'visualeditor-betatempdisable' ) &&
|
|
|
|
|
!$user->getOption( 'visualeditor-hidetabdialog' ) &&
|
|
|
|
|
$user->getOption( 'visualeditor-tabs' ) === 'remember-last' &&
|
|
|
|
|
$dbr->select(
|
|
|
|
|
'revision',
|
|
|
|
|
'1',
|
|
|
|
|
[
|
|
|
|
|
'rev_user' => $user->getId(),
|
|
|
|
|
'rev_timestamp < ' . $dbr->addQuotes(
|
|
|
|
|
$config->get( 'VisualEditorSingleEditTabSwitchTime' )
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
__METHOD__,
|
|
|
|
|
[ 'LIMIT' => 1 ]
|
|
|
|
|
)->numRows() === 1
|
2015-10-23 16:29:56 +00:00
|
|
|
|
) {
|
2016-03-06 00:07:06 +00:00
|
|
|
|
$links['views']['edit']['class'] .= ' visualeditor-showtabdialog';
|
2015-10-23 16:29:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-10 23:29:12 +00:00
|
|
|
|
// Exit if the user doesn't have VE enabled
|
2013-08-01 19:14:41 +00:00
|
|
|
|
if (
|
2015-12-10 20:30:01 +00:00
|
|
|
|
!$user->getOption( 'visualeditor-enable' ) ||
|
|
|
|
|
$user->getOption( 'visualeditor-betatempdisable' ) ||
|
|
|
|
|
$user->getOption( 'visualeditor-autodisable' ) ||
|
|
|
|
|
( $config->get( 'VisualEditorDisableForAnons' ) && $user->isAnon() )
|
2013-08-01 19:14:41 +00:00
|
|
|
|
) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$title = $skin->getRelevantTitle();
|
2016-04-29 16:00:57 +00:00
|
|
|
|
$namespaceEnabled = ApiVisualEditor::isAllowedNamespace( $config, $title->getNamespace() );
|
2015-08-25 04:08:50 +00:00
|
|
|
|
$pageContentModel = $title->getContentModel();
|
2016-06-01 01:28:34 +00:00
|
|
|
|
$contentModelEnabled = ApiVisualEditor::isAllowedContentType( $config, $pageContentModel );
|
2015-08-25 04:08:50 +00:00
|
|
|
|
// Don't exit if this page isn't VE-enabled, since we should still
|
|
|
|
|
// change "Edit" to "Edit source".
|
2016-04-21 11:40:42 +00:00
|
|
|
|
$isAvailable = $namespaceEnabled && $contentModelEnabled;
|
2015-08-10 23:29:12 +00:00
|
|
|
|
|
|
|
|
|
// HACK: Exit if we're in the Education Program namespace (even though it's content)
|
2014-04-10 18:57:17 +00:00
|
|
|
|
if ( defined( 'EP_NS' ) && $title->inNamespace( EP_NS ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-08-10 23:29:12 +00:00
|
|
|
|
|
2014-08-13 08:15:42 +00:00
|
|
|
|
$tabMessages = $config->get( 'VisualEditorTabMessages' );
|
2013-08-01 19:14:41 +00:00
|
|
|
|
// Rebuild the $links['views'] array and inject the VisualEditor tab before or after
|
|
|
|
|
// the edit tab as appropriate. We have to rebuild the array because PHP doesn't allow
|
|
|
|
|
// us to splice into the middle of an associative array.
|
2016-02-17 16:18:02 +00:00
|
|
|
|
$newViews = [];
|
2013-08-01 19:14:41 +00:00
|
|
|
|
foreach ( $links['views'] as $action => $data ) {
|
|
|
|
|
if ( $action === 'edit' ) {
|
|
|
|
|
// Build the VisualEditor tab
|
|
|
|
|
$existing = $title->exists() || (
|
2014-09-25 05:06:57 +00:00
|
|
|
|
$title->inNamespace( NS_MEDIAWIKI ) &&
|
2013-08-01 19:14:41 +00:00
|
|
|
|
$title->getDefaultMessageText() !== false
|
|
|
|
|
);
|
2014-04-08 23:07:33 +00:00
|
|
|
|
$action = $existing ? 'edit' : 'create';
|
2013-08-01 19:14:41 +00:00
|
|
|
|
$veParams = $skin->editUrlOptions();
|
2017-05-04 22:27:27 +00:00
|
|
|
|
// Remove action=edit
|
|
|
|
|
unset( $veParams['action'] );
|
|
|
|
|
// Set veaction=edit
|
|
|
|
|
$veParams['veaction'] = 'edit';
|
2014-08-13 08:15:42 +00:00
|
|
|
|
$veTabMessage = $tabMessages[$action];
|
2013-08-01 19:14:41 +00:00
|
|
|
|
$veTabText = $veTabMessage === null ? $data['text'] :
|
2014-09-25 05:06:57 +00:00
|
|
|
|
$skin->msg( $veTabMessage )->text();
|
2016-02-17 16:18:02 +00:00
|
|
|
|
$veTab = [
|
2013-08-01 19:14:41 +00:00
|
|
|
|
'href' => $title->getLocalURL( $veParams ),
|
|
|
|
|
'text' => $veTabText,
|
|
|
|
|
'primary' => true,
|
|
|
|
|
'class' => '',
|
2016-02-17 16:18:02 +00:00
|
|
|
|
];
|
2013-08-01 19:14:41 +00:00
|
|
|
|
|
|
|
|
|
// Alter the edit tab
|
|
|
|
|
$editTab = $data;
|
2014-04-08 23:07:33 +00:00
|
|
|
|
if (
|
|
|
|
|
$title->inNamespace( NS_FILE ) &&
|
|
|
|
|
WikiPage::factory( $title ) instanceof WikiFilePage &&
|
|
|
|
|
!WikiPage::factory( $title )->isLocal()
|
|
|
|
|
) {
|
2014-08-13 08:15:42 +00:00
|
|
|
|
$editTabMessage = $tabMessages[$action . 'localdescriptionsource'];
|
2014-04-08 23:07:33 +00:00
|
|
|
|
} else {
|
2014-08-13 08:15:42 +00:00
|
|
|
|
$editTabMessage = $tabMessages[$action . 'source'];
|
2014-04-08 23:07:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-01 19:14:41 +00:00
|
|
|
|
if ( $editTabMessage !== null ) {
|
2014-09-25 05:06:57 +00:00
|
|
|
|
$editTab['text'] = $skin->msg( $editTabMessage )->text();
|
2013-08-01 19:14:41 +00:00
|
|
|
|
}
|
2015-12-10 20:30:01 +00:00
|
|
|
|
|
2017-04-27 15:23:26 +00:00
|
|
|
|
$editor = self::getLastEditor( $user, $skin->getRequest() );
|
2015-12-10 20:30:01 +00:00
|
|
|
|
if (
|
|
|
|
|
$isAvailable &&
|
|
|
|
|
$config->get( 'VisualEditorUseSingleEditTab' ) &&
|
|
|
|
|
(
|
|
|
|
|
$user->getOption( 'visualeditor-tabs' ) === 'prefer-ve' ||
|
|
|
|
|
(
|
|
|
|
|
$user->getOption( 'visualeditor-tabs' ) === 'remember-last' &&
|
|
|
|
|
$editor === 'visualeditor'
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
$editTab['text'] = $veTabText;
|
|
|
|
|
$newViews['edit'] = $editTab;
|
|
|
|
|
} elseif (
|
|
|
|
|
$isAvailable &&
|
|
|
|
|
(
|
|
|
|
|
!$config->get( 'VisualEditorUseSingleEditTab' ) ||
|
|
|
|
|
$user->getOption( 'visualeditor-tabs' ) === 'multi-tab'
|
|
|
|
|
)
|
|
|
|
|
) {
|
2015-08-25 03:46:53 +00:00
|
|
|
|
// Inject the VE tab before or after the edit tab
|
|
|
|
|
if ( $config->get( 'VisualEditorTabPosition' ) === 'before' ) {
|
|
|
|
|
$editTab['class'] .= ' collapsible';
|
|
|
|
|
$newViews['ve-edit'] = $veTab;
|
|
|
|
|
$newViews['edit'] = $editTab;
|
|
|
|
|
} else {
|
|
|
|
|
$veTab['class'] .= ' collapsible';
|
|
|
|
|
$newViews['edit'] = $editTab;
|
|
|
|
|
$newViews['ve-edit'] = $veTab;
|
|
|
|
|
}
|
2015-12-10 20:30:01 +00:00
|
|
|
|
} elseif (
|
|
|
|
|
!$config->get( 'VisualEditorUseSingleEditTab' ) ||
|
|
|
|
|
!$isAvailable ||
|
|
|
|
|
$user->getOption( 'visualeditor-tabs' ) === 'multi-tab' ||
|
|
|
|
|
(
|
|
|
|
|
$user->getOption( 'visualeditor-tabs' ) === 'remember-last' &&
|
|
|
|
|
$editor === 'wikitext'
|
|
|
|
|
)
|
|
|
|
|
) {
|
2015-08-25 03:46:53 +00:00
|
|
|
|
// Don't add ve-edit, but do update the edit tab (e.g. "Edit source").
|
2013-08-01 19:14:41 +00:00
|
|
|
|
$newViews['edit'] = $editTab;
|
2015-12-10 20:30:01 +00:00
|
|
|
|
} else {
|
|
|
|
|
// This should not happen.
|
2013-08-01 19:14:41 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Just pass through
|
|
|
|
|
$newViews[$action] = $data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$links['views'] = $newViews;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 15:17:44 +00:00
|
|
|
|
/**
|
|
|
|
|
* Called when the normal wikitext editor is shown.
|
2014-03-08 17:49:53 +00:00
|
|
|
|
* Inserts a 'veswitched' hidden field if requested by the client
|
2014-02-16 15:17:44 +00:00
|
|
|
|
*
|
2017-05-04 22:59:27 +00:00
|
|
|
|
* @param EditPage $editPage The edit page view.
|
|
|
|
|
* @param OutputPage $output The page view.
|
2017-07-25 14:49:56 +00:00
|
|
|
|
* @return bool Always true.
|
2014-02-16 15:17:44 +00:00
|
|
|
|
*/
|
|
|
|
|
public static function onEditPageShowEditFormFields( EditPage $editPage, OutputPage $output ) {
|
2014-08-13 05:54:51 +00:00
|
|
|
|
$request = $output->getRequest();
|
2014-03-08 17:49:53 +00:00
|
|
|
|
if ( $request->getBool( 'veswitched' ) ) {
|
2017-09-03 07:30:13 +00:00
|
|
|
|
$output->addHTML( Html::hidden( 'veswitched', '1' ) );
|
2014-02-16 15:17:44 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when an edit is saved
|
|
|
|
|
* Adds 'visualeditor-switched' tag to the edit if requested
|
|
|
|
|
*
|
2017-05-04 22:59:27 +00:00
|
|
|
|
* @param RecentChange $rc The new RC entry.
|
2017-07-25 14:49:56 +00:00
|
|
|
|
* @return bool Always true.
|
2014-02-16 15:17:44 +00:00
|
|
|
|
*/
|
2017-05-04 22:17:29 +00:00
|
|
|
|
public static function onRecentChangeSave( RecentChange $rc ) {
|
2014-02-16 15:17:44 +00:00
|
|
|
|
$request = RequestContext::getMain()->getRequest();
|
2015-05-27 18:19:39 +00:00
|
|
|
|
if ( $request->getBool( 'veswitched' ) && $rc->mAttribs['rc_this_oldid'] ) {
|
2016-09-27 15:36:28 +00:00
|
|
|
|
$rc->addTags( 'visualeditor-switched' );
|
2014-02-16 15:17:44 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-01 19:14:41 +00:00
|
|
|
|
/**
|
|
|
|
|
* Changes the section edit links to add a VE edit link.
|
|
|
|
|
*
|
2015-02-19 18:09:34 +00:00
|
|
|
|
* This is attached to the MediaWiki 'SkinEditSectionLinks' hook.
|
2013-08-01 19:14:41 +00:00
|
|
|
|
*
|
2017-05-04 22:59:27 +00:00
|
|
|
|
* @param Skin $skin Skin being used to render the UI
|
|
|
|
|
* @param Title $title Title being used for request
|
|
|
|
|
* @param string $section The name of the section being pointed to.
|
|
|
|
|
* @param string $tooltip The default tooltip.
|
|
|
|
|
* @param array &$result All link detail arrays.
|
|
|
|
|
* @param Language $lang The user interface language.
|
2017-07-25 14:49:56 +00:00
|
|
|
|
* @return bool Always true.
|
2013-08-01 19:14:41 +00:00
|
|
|
|
*/
|
2015-02-19 18:09:34 +00:00
|
|
|
|
public static function onSkinEditSectionLinks( Skin $skin, Title $title, $section,
|
2014-09-25 05:06:57 +00:00
|
|
|
|
$tooltip, &$result, $lang
|
|
|
|
|
) {
|
2015-09-12 00:26:39 +00:00
|
|
|
|
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' );
|
|
|
|
|
|
2015-08-10 23:29:12 +00:00
|
|
|
|
// Exit if we're in parserTests
|
|
|
|
|
if ( isset( $GLOBALS[ 'wgVisualEditorInParserTests' ] ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-13 21:45:53 +00:00
|
|
|
|
$user = $skin->getUser();
|
2015-08-10 23:29:12 +00:00
|
|
|
|
// Exit if the user doesn't have VE enabled
|
2013-08-01 19:14:41 +00:00
|
|
|
|
if (
|
2016-10-13 21:45:53 +00:00
|
|
|
|
!$user->getOption( 'visualeditor-enable' ) ||
|
|
|
|
|
$user->getOption( 'visualeditor-betatempdisable' ) ||
|
|
|
|
|
$user->getOption( 'visualeditor-autodisable' ) ||
|
|
|
|
|
( $config->get( 'VisualEditorDisableForAnons' ) && $user->isAnon() )
|
2015-08-10 23:29:12 +00:00
|
|
|
|
) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Exit if we're on a foreign file description page
|
|
|
|
|
if (
|
|
|
|
|
$title->inNamespace( NS_FILE ) &&
|
|
|
|
|
WikiPage::factory( $title ) instanceof WikiFilePage &&
|
|
|
|
|
!WikiPage::factory( $title )->isLocal()
|
2013-08-01 19:14:41 +00:00
|
|
|
|
) {
|
2014-09-25 05:06:57 +00:00
|
|
|
|
return true;
|
2013-08-01 19:14:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 15:23:26 +00:00
|
|
|
|
$editor = self::getLastEditor( $user, RequestContext::getMain()->getRequest() );
|
2016-06-30 01:11:13 +00:00
|
|
|
|
if (
|
|
|
|
|
!$config->get( 'VisualEditorUseSingleEditTab' ) ||
|
2016-10-13 21:45:53 +00:00
|
|
|
|
$user->getOption( 'visualeditor-tabs' ) === 'multi-tab' ||
|
2016-06-30 01:11:13 +00:00
|
|
|
|
(
|
2016-10-13 21:45:53 +00:00
|
|
|
|
$user->getOption( 'visualeditor-tabs' ) === 'remember-last' &&
|
2016-06-30 01:11:13 +00:00
|
|
|
|
$editor === 'wikitext'
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
// Don't add ve-edit, but do update the edit tab (e.g. "Edit source").
|
|
|
|
|
$tabMessages = $config->get( 'VisualEditorTabMessages' );
|
|
|
|
|
$sourceEditSection = $tabMessages['editsectionsource'] !== null ?
|
|
|
|
|
$tabMessages['editsectionsource'] : 'editsection';
|
|
|
|
|
$result['editsection']['text'] = $skin->msg( $sourceEditSection )->inLanguage( $lang )->text();
|
|
|
|
|
}
|
2013-08-01 19:14:41 +00:00
|
|
|
|
|
2016-06-30 01:11:13 +00:00
|
|
|
|
// Exit if we're using the single edit tab.
|
|
|
|
|
if (
|
|
|
|
|
$config->get( 'VisualEditorUseSingleEditTab' ) &&
|
2016-10-13 21:45:53 +00:00
|
|
|
|
$user->getOption( 'visualeditor-tabs' ) !== 'multi-tab'
|
2016-06-30 01:11:13 +00:00
|
|
|
|
) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-02-19 18:09:34 +00:00
|
|
|
|
|
2015-09-12 10:35:44 +00:00
|
|
|
|
// add VE edit section in VE available namespaces
|
2016-04-29 16:00:57 +00:00
|
|
|
|
if ( ApiVisualEditor::isAllowedNamespace( $config, $title->getNamespace() ) ) {
|
2015-09-12 10:35:44 +00:00
|
|
|
|
$veEditSection = $tabMessages['editsection'] !== null ?
|
|
|
|
|
$tabMessages['editsection'] : 'editsection';
|
2016-02-17 16:18:02 +00:00
|
|
|
|
$veLink = [
|
2015-09-12 10:35:44 +00:00
|
|
|
|
'text' => $skin->msg( $veEditSection )->inLanguage( $lang )->text(),
|
|
|
|
|
'targetTitle' => $title,
|
2016-02-17 16:18:02 +00:00
|
|
|
|
'attribs' => $result['editsection']['attribs'] + [
|
2015-09-12 10:35:44 +00:00
|
|
|
|
'class' => 'mw-editsection-visualeditor'
|
2016-02-17 16:18:02 +00:00
|
|
|
|
],
|
2016-11-05 02:07:39 +00:00
|
|
|
|
'query' => [ 'veaction' => 'edit', 'section' => $section ],
|
2016-02-17 16:18:02 +00:00
|
|
|
|
'options' => [ 'noclasses', 'known' ]
|
|
|
|
|
];
|
2013-06-26 17:23:56 +00:00
|
|
|
|
|
2015-09-12 10:35:44 +00:00
|
|
|
|
$result['veeditsection'] = $veLink;
|
|
|
|
|
if ( $config->get( 'VisualEditorTabPosition' ) === 'before' ) {
|
|
|
|
|
krsort( $result );
|
|
|
|
|
// TODO: This will probably cause weird ordering if any other extensions added something
|
|
|
|
|
// already.
|
|
|
|
|
// ... wfArrayInsertBefore?
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-25 19:50:48 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-26 06:31:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Convert a namespace index to the local text for display to the user.
|
|
|
|
|
*
|
|
|
|
|
* @param $nsIndex int
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private static function convertNs( $nsIndex ) {
|
|
|
|
|
global $wgLang;
|
|
|
|
|
if ( $nsIndex ) {
|
|
|
|
|
return $wgLang->convertNamespace( $nsIndex );
|
|
|
|
|
} else {
|
|
|
|
|
return wfMessage( 'blanknamespace' )->text();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-13 05:57:21 +00:00
|
|
|
|
public static function onGetPreferences( User $user, array &$preferences ) {
|
2014-08-13 08:15:42 +00:00
|
|
|
|
global $wgLang;
|
2016-06-01 16:06:22 +00:00
|
|
|
|
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' );
|
2014-09-20 17:49:37 +00:00
|
|
|
|
if ( !class_exists( 'BetaFeatures' ) ) {
|
2016-06-01 16:06:22 +00:00
|
|
|
|
$namespaces = ApiVisualEditor::getAvailableNamespaceIds( $config );
|
2014-09-16 17:35:57 +00:00
|
|
|
|
|
2016-02-17 16:18:02 +00:00
|
|
|
|
$enablePreference = [
|
2013-09-30 16:18:46 +00:00
|
|
|
|
'type' => 'toggle',
|
2016-02-17 16:18:02 +00:00
|
|
|
|
'label-message' => [
|
2014-04-26 06:31:32 +00:00
|
|
|
|
'visualeditor-preference-enable',
|
|
|
|
|
$wgLang->commaList( array_map(
|
2016-02-17 16:18:02 +00:00
|
|
|
|
[ 'self', 'convertNs' ],
|
2016-06-01 16:06:22 +00:00
|
|
|
|
$namespaces
|
2014-09-16 17:35:57 +00:00
|
|
|
|
) ),
|
2016-06-01 16:06:22 +00:00
|
|
|
|
count( $namespaces )
|
2016-02-17 16:18:02 +00:00
|
|
|
|
],
|
2014-04-07 09:42:41 +00:00
|
|
|
|
'section' => 'editing/editor'
|
2016-02-17 16:18:02 +00:00
|
|
|
|
];
|
2015-08-11 22:31:43 +00:00
|
|
|
|
if ( $user->getOption( 'visualeditor-autodisable' ) ) {
|
|
|
|
|
$enablePreference['default'] = false;
|
|
|
|
|
}
|
|
|
|
|
$preferences['visualeditor-enable'] = $enablePreference;
|
2013-09-30 16:18:46 +00:00
|
|
|
|
}
|
2016-02-17 16:18:02 +00:00
|
|
|
|
$preferences['visualeditor-betatempdisable'] = [
|
2013-07-24 01:11:56 +00:00
|
|
|
|
'type' => 'toggle',
|
|
|
|
|
'label-message' => 'visualeditor-preference-betatempdisable',
|
2015-09-29 01:19:56 +00:00
|
|
|
|
'section' => 'editing/editor',
|
|
|
|
|
'default' => $user->getOption( 'visualeditor-betatempdisable' ) ||
|
|
|
|
|
$user->getOption( 'visualeditor-autodisable' )
|
2016-02-17 16:18:02 +00:00
|
|
|
|
];
|
2015-10-23 16:29:56 +00:00
|
|
|
|
|
2015-12-09 22:38:53 +00:00
|
|
|
|
if (
|
|
|
|
|
$config->get( 'VisualEditorUseSingleEditTab' ) &&
|
|
|
|
|
!$user->getOption( 'visualeditor-autodisable' ) &&
|
|
|
|
|
!$user->getOption( 'visualeditor-betatempdisable' )
|
|
|
|
|
) {
|
2016-02-17 16:18:02 +00:00
|
|
|
|
$preferences['visualeditor-tabs'] = [
|
2015-10-23 16:29:56 +00:00
|
|
|
|
'type' => 'select',
|
|
|
|
|
'label-message' => 'visualeditor-preference-tabs',
|
|
|
|
|
'section' => 'editing/editor',
|
2016-02-17 16:18:02 +00:00
|
|
|
|
'options' => [
|
2015-10-23 16:29:56 +00:00
|
|
|
|
wfMessage( 'visualeditor-preference-tabs-remember-last' )->escaped() => 'remember-last',
|
|
|
|
|
wfMessage( 'visualeditor-preference-tabs-prefer-ve' )->escaped() => 'prefer-ve',
|
|
|
|
|
wfMessage( 'visualeditor-preference-tabs-prefer-wt' )->escaped() => 'prefer-wt',
|
|
|
|
|
wfMessage( 'visualeditor-preference-tabs-multi-tab' )->escaped() => 'multi-tab'
|
2016-02-17 16:18:02 +00:00
|
|
|
|
]
|
|
|
|
|
];
|
2015-10-23 16:29:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 16:18:02 +00:00
|
|
|
|
$api = [ 'type' => 'api' ];
|
2015-10-04 12:39:58 +00:00
|
|
|
|
$preferences['visualeditor-autodisable'] = $api;
|
2017-11-04 18:31:23 +00:00
|
|
|
|
// The diff mode is persisted for each editor mode separately,
|
|
|
|
|
// e.g. use visual diffs for visual mode only.
|
|
|
|
|
$preferences['visualeditor-diffmode-source'] = $api;
|
|
|
|
|
$preferences['visualeditor-diffmode-visual'] = $api;
|
2015-10-23 16:29:56 +00:00
|
|
|
|
$preferences['visualeditor-editor'] = $api;
|
2015-10-04 12:39:58 +00:00
|
|
|
|
$preferences['visualeditor-hidebetawelcome'] = $api;
|
2015-10-23 16:29:56 +00:00
|
|
|
|
$preferences['visualeditor-hidetabdialog'] = $api;
|
2015-11-10 23:01:49 +00:00
|
|
|
|
$preferences['visualeditor-hidesourceswitchpopup'] = $api;
|
2016-04-04 16:31:39 +00:00
|
|
|
|
$preferences['visualeditor-hidevisualswitchpopup'] = $api;
|
2015-10-30 02:08:25 +00:00
|
|
|
|
$preferences['visualeditor-hideusered'] = $api;
|
2017-02-26 12:22:15 +00:00
|
|
|
|
$preferences['visualeditor-findAndReplace-diacritic'] = $api;
|
2015-10-04 12:39:58 +00:00
|
|
|
|
$preferences['visualeditor-findAndReplace-findText'] = $api;
|
|
|
|
|
$preferences['visualeditor-findAndReplace-replaceText'] = $api;
|
|
|
|
|
$preferences['visualeditor-findAndReplace-regex'] = $api;
|
|
|
|
|
$preferences['visualeditor-findAndReplace-matchCase'] = $api;
|
2015-12-03 17:25:06 +00:00
|
|
|
|
$preferences['visualeditor-findAndReplace-word'] = $api;
|
2012-11-05 20:46:14 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-13 05:57:21 +00:00
|
|
|
|
public static function onGetBetaPreferences( User $user, array &$preferences ) {
|
2014-08-13 08:15:42 +00:00
|
|
|
|
$coreConfig = RequestContext::getMain()->getConfig();
|
2018-01-02 09:36:14 +00:00
|
|
|
|
$iconpath = $coreConfig->get( 'ExtensionAssetsPath' ) . "/VisualEditor/images";
|
2013-11-08 16:33:53 +00:00
|
|
|
|
|
2014-08-13 08:15:42 +00:00
|
|
|
|
$veConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' );
|
2016-02-17 16:18:02 +00:00
|
|
|
|
$preferences['visualeditor-enable'] = [
|
2013-09-30 16:18:46 +00:00
|
|
|
|
'version' => '1.0',
|
|
|
|
|
'label-message' => 'visualeditor-preference-core-label',
|
|
|
|
|
'desc-message' => 'visualeditor-preference-core-description',
|
2016-02-17 16:18:02 +00:00
|
|
|
|
'screenshot' => [
|
2014-03-22 20:43:28 +00:00
|
|
|
|
'ltr' => "$iconpath/betafeatures-icon-VisualEditor-ltr.svg",
|
|
|
|
|
'rtl' => "$iconpath/betafeatures-icon-VisualEditor-rtl.svg",
|
2016-02-17 16:18:02 +00:00
|
|
|
|
],
|
2013-10-30 20:57:05 +00:00
|
|
|
|
'info-message' => 'visualeditor-preference-core-info-link',
|
|
|
|
|
'discussion-message' => 'visualeditor-preference-core-discussion-link',
|
2016-02-17 16:18:02 +00:00
|
|
|
|
'requirements' => [
|
2013-10-10 12:33:49 +00:00
|
|
|
|
'javascript' => true,
|
2014-08-13 08:15:42 +00:00
|
|
|
|
'blacklist' => $veConfig->get( 'VisualEditorBrowserBlacklist' ),
|
2016-02-17 16:18:02 +00:00
|
|
|
|
]
|
|
|
|
|
];
|
2016-09-01 19:04:54 +00:00
|
|
|
|
|
2016-09-21 20:24:04 +00:00
|
|
|
|
if ( $veConfig->get( 'VisualEditorEnableWikitext' ) ) {
|
|
|
|
|
$preferences['visualeditor-newwikitext'] = [
|
|
|
|
|
'version' => '1.0',
|
|
|
|
|
'label-message' => 'visualeditor-preference-newwikitexteditor-label',
|
|
|
|
|
'desc-message' => 'visualeditor-preference-newwikitexteditor-description',
|
|
|
|
|
'screenshot' => [
|
|
|
|
|
'ltr' => "$iconpath/betafeatures-icon-WikitextEditor-ltr.svg",
|
|
|
|
|
'rtl' => "$iconpath/betafeatures-icon-WikitextEditor-rtl.svg",
|
|
|
|
|
],
|
|
|
|
|
'info-message' => 'visualeditor-preference-newwikitexteditor-info-link',
|
|
|
|
|
'discussion-message' => 'visualeditor-preference-newwikitexteditor-discussion-link',
|
|
|
|
|
'requirements' => [
|
|
|
|
|
'javascript' => true,
|
|
|
|
|
'blacklist' => $veConfig->get( 'VisualEditorBrowserBlacklist' ),
|
2017-09-20 13:31:00 +00:00
|
|
|
|
]
|
2016-09-21 20:24:04 +00:00
|
|
|
|
];
|
|
|
|
|
}
|
2018-01-25 21:36:05 +00:00
|
|
|
|
|
|
|
|
|
if ( $veConfig->get( 'VisualEditorEnableDiffPageBetaFeature' ) ) {
|
|
|
|
|
$preferences['visualeditor-visualdiffpage'] = [
|
|
|
|
|
'version' => '1.0',
|
|
|
|
|
'label-message' => 'visualeditor-preference-visualdiffpage-label',
|
|
|
|
|
'desc-message' => 'visualeditor-preference-visualdiffpage-description',
|
|
|
|
|
'screenshot' => [
|
|
|
|
|
'ltr' => "$iconpath/betafeatures-icon-VisualDiffPage-ltr.svg",
|
|
|
|
|
'rtl' => "$iconpath/betafeatures-icon-VisualDiffPage-rtl.svg",
|
|
|
|
|
],
|
|
|
|
|
'info-message' => 'visualeditor-preference-visualdiffpage-info-link',
|
|
|
|
|
'discussion-message' => 'visualeditor-preference-visualdiffpage-discussion-link',
|
|
|
|
|
'requirements' => [
|
|
|
|
|
'javascript' => true,
|
|
|
|
|
'blacklist' => $veConfig->get( 'VisualEditorBrowserBlacklist' ),
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
2013-08-12 05:50:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-11 22:31:43 +00:00
|
|
|
|
/**
|
|
|
|
|
* Implements the PreferencesFormPreSave hook, to remove the 'autodisable' flag
|
|
|
|
|
* when the user it was set on explicitly enables VE.
|
2017-05-04 22:59:27 +00:00
|
|
|
|
*
|
2015-08-11 22:31:43 +00:00
|
|
|
|
* @param array $data User-submitted data
|
|
|
|
|
* @param PreferencesForm $form A ContextSource
|
|
|
|
|
* @param User $user User with new preferences already set
|
2017-07-25 14:49:56 +00:00
|
|
|
|
* @param bool &$result Success or failure
|
2015-08-11 22:31:43 +00:00
|
|
|
|
*/
|
|
|
|
|
public static function onPreferencesFormPreSave( $data, $form, $user, &$result ) {
|
2015-09-29 01:19:56 +00:00
|
|
|
|
$veConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' );
|
|
|
|
|
// On a wiki where enable is hidden and set to 1, if user sets betatempdisable=0
|
|
|
|
|
// then set autodisable=0
|
|
|
|
|
// On a wiki where betatempdisable is hidden and set to 0, if user sets enable=1
|
|
|
|
|
// then set autodisable=0
|
2015-08-11 22:31:43 +00:00
|
|
|
|
if (
|
|
|
|
|
$user->getOption( 'visualeditor-autodisable' ) &&
|
2015-09-29 01:19:56 +00:00
|
|
|
|
$user->getOption( 'visualeditor-enable' ) &&
|
|
|
|
|
!$user->getOption( 'visualeditor-betatempdisable' )
|
2015-08-11 22:31:43 +00:00
|
|
|
|
) {
|
|
|
|
|
$user->setOption( 'visualeditor-autodisable', false );
|
2015-09-29 01:19:56 +00:00
|
|
|
|
} elseif (
|
|
|
|
|
// On a wiki where betatempdisable is hidden and set to 0, if user sets enable=0,
|
|
|
|
|
// then set autodisable=1
|
|
|
|
|
$veConfig->get( 'VisualEditorTransitionDefault' ) &&
|
|
|
|
|
!$user->getOption( 'visualeditor-betatempdisable' ) &&
|
|
|
|
|
!$user->getOption( 'visualeditor-enable' ) &&
|
|
|
|
|
!$user->getOption( 'visualeditor-autodisable' )
|
|
|
|
|
) {
|
|
|
|
|
$user->setOption( 'visualeditor-autodisable', true );
|
2015-08-11 22:31:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-29 04:02:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* Implements the ListDefinedTags and ChangeTagsListActive hooks, to populate
|
|
|
|
|
* core Special:Tags with the change tags in use by VisualEditor.
|
|
|
|
|
*
|
2017-05-04 22:59:27 +00:00
|
|
|
|
* @param array &$tags Available change tags.
|
2017-07-25 14:49:56 +00:00
|
|
|
|
* @return bool Always true.
|
2015-01-29 04:02:37 +00:00
|
|
|
|
*/
|
2012-11-22 02:26:29 +00:00
|
|
|
|
public static function onListDefinedTags( &$tags ) {
|
|
|
|
|
$tags[] = 'visualeditor';
|
2017-05-04 22:27:27 +00:00
|
|
|
|
// No longer in active use:
|
|
|
|
|
$tags[] = 'visualeditor-needcheck';
|
2014-02-16 15:17:44 +00:00
|
|
|
|
$tags[] = 'visualeditor-switched';
|
2016-10-10 23:32:02 +00:00
|
|
|
|
$tags[] = 'visualeditor-wikitext';
|
2012-11-22 02:26:29 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-25 19:50:48 +00:00
|
|
|
|
/**
|
2012-06-11 06:54:41 +00:00
|
|
|
|
* Adds extra variables to the page config.
|
2017-05-04 22:15:55 +00:00
|
|
|
|
*
|
2017-05-04 22:59:27 +00:00
|
|
|
|
* @param array &$vars Global variables object
|
|
|
|
|
* @param OutputPage $out The page view.
|
2017-07-25 14:49:56 +00:00
|
|
|
|
* @return bool Always true
|
2012-05-25 19:50:48 +00:00
|
|
|
|
*/
|
2012-12-06 05:57:53 +00:00
|
|
|
|
public static function onMakeGlobalVariablesScript( array &$vars, OutputPage $out ) {
|
2013-11-08 16:19:15 +00:00
|
|
|
|
$pageLanguage = $out->getTitle()->getPageLanguage();
|
2017-05-31 16:46:37 +00:00
|
|
|
|
$fallbacks = $pageLanguage->getConverter()->getVariantFallbacks(
|
|
|
|
|
$pageLanguage->getPreferredVariant()
|
|
|
|
|
);
|
2013-11-08 16:19:15 +00:00
|
|
|
|
|
2016-02-17 16:18:02 +00:00
|
|
|
|
$vars['wgVisualEditor'] = [
|
2013-11-08 16:19:15 +00:00
|
|
|
|
'pageLanguageCode' => $pageLanguage->getHtmlCode(),
|
2014-01-26 22:59:30 +00:00
|
|
|
|
'pageLanguageDir' => $pageLanguage->getDir(),
|
2017-05-31 16:46:37 +00:00
|
|
|
|
'pageVariantFallbacks' => $fallbacks,
|
2014-11-20 17:05:47 +00:00
|
|
|
|
'usePageImages' => defined( 'PAGE_IMAGES_INSTALLED' ),
|
|
|
|
|
'usePageDescriptions' => defined( 'WBC_VERSION' ),
|
2016-02-17 16:18:02 +00:00
|
|
|
|
];
|
2013-04-17 16:48:09 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds extra variables to the global config
|
2017-05-04 22:15:55 +00:00
|
|
|
|
*
|
2017-05-04 22:59:27 +00:00
|
|
|
|
* @param array &$vars Global variables object
|
2017-07-25 14:49:56 +00:00
|
|
|
|
* @return bool Always true
|
2013-04-17 16:48:09 +00:00
|
|
|
|
*/
|
|
|
|
|
public static function onResourceLoaderGetConfigVars( array &$vars ) {
|
2014-08-13 08:15:42 +00:00
|
|
|
|
$coreConfig = RequestContext::getMain()->getConfig();
|
|
|
|
|
$defaultUserOptions = $coreConfig->get( 'DefaultUserOptions' );
|
|
|
|
|
$thumbLimits = $coreConfig->get( 'ThumbLimits' );
|
|
|
|
|
$veConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' );
|
2016-06-01 16:06:22 +00:00
|
|
|
|
$availableNamespaces = ApiVisualEditor::getAvailableNamespaceIds( $veConfig );
|
2016-06-24 15:04:32 +00:00
|
|
|
|
$availableContentModels = array_filter(
|
2016-06-01 16:06:22 +00:00
|
|
|
|
array_merge(
|
|
|
|
|
ExtensionRegistry::getInstance()->getAttribute( 'VisualEditorAvailableContentModels' ),
|
|
|
|
|
$veConfig->get( 'VisualEditorAvailableContentModels' )
|
|
|
|
|
)
|
2016-06-24 15:04:32 +00:00
|
|
|
|
);
|
2013-06-03 22:23:45 +00:00
|
|
|
|
|
2016-02-17 16:18:02 +00:00
|
|
|
|
$vars['wgVisualEditorConfig'] = [
|
2014-08-13 08:15:42 +00:00
|
|
|
|
'disableForAnons' => $veConfig->get( 'VisualEditorDisableForAnons' ),
|
2017-02-01 17:00:07 +00:00
|
|
|
|
'preloadModules' => $veConfig->get( 'VisualEditorPreloadModules' ),
|
2014-08-13 08:15:42 +00:00
|
|
|
|
'preferenceModules' => $veConfig->get( 'VisualEditorPreferenceModules' ),
|
2016-06-01 16:06:22 +00:00
|
|
|
|
'namespaces' => $availableNamespaces,
|
|
|
|
|
'contentModels' => $availableContentModels,
|
2015-11-08 17:05:33 +00:00
|
|
|
|
'signatureNamespaces' => array_values(
|
2017-02-28 21:38:26 +00:00
|
|
|
|
array_filter( MWNamespace::getValidNamespaces(), 'MWNamespace::wantSignatures' )
|
2015-11-08 17:05:33 +00:00
|
|
|
|
),
|
2015-01-27 05:47:31 +00:00
|
|
|
|
'pluginModules' => array_merge(
|
|
|
|
|
ExtensionRegistry::getInstance()->getAttribute( 'VisualEditorPluginModules' ),
|
2017-05-04 22:27:27 +00:00
|
|
|
|
// @todo deprecate the global setting
|
|
|
|
|
$veConfig->get( 'VisualEditorPluginModules' )
|
2015-01-27 05:47:31 +00:00
|
|
|
|
),
|
2016-02-17 16:18:02 +00:00
|
|
|
|
'defaultUserOptions' => [
|
2014-08-13 08:15:42 +00:00
|
|
|
|
'defaultthumbsize' => $thumbLimits[ $defaultUserOptions['thumbsize'] ]
|
2016-02-17 16:18:02 +00:00
|
|
|
|
],
|
2016-08-04 23:28:53 +00:00
|
|
|
|
'galleryOptions' => $coreConfig->get( 'GalleryOptions' ),
|
2014-08-13 08:15:42 +00:00
|
|
|
|
'blacklist' => $veConfig->get( 'VisualEditorBrowserBlacklist' ),
|
|
|
|
|
'tabPosition' => $veConfig->get( 'VisualEditorTabPosition' ),
|
|
|
|
|
'tabMessages' => $veConfig->get( 'VisualEditorTabMessages' ),
|
2015-10-23 16:29:56 +00:00
|
|
|
|
'singleEditTab' => $veConfig->get( 'VisualEditorUseSingleEditTab' ),
|
2014-08-13 08:15:42 +00:00
|
|
|
|
'showBetaWelcome' => $veConfig->get( 'VisualEditorShowBetaWelcome' ),
|
2015-02-13 08:19:49 +00:00
|
|
|
|
'enableTocWidget' => $veConfig->get( 'VisualEditorEnableTocWidget' ),
|
2016-05-26 12:08:26 +00:00
|
|
|
|
'enableWikitext' => $veConfig->get( 'VisualEditorEnableWikitext' ),
|
2015-02-13 08:19:49 +00:00
|
|
|
|
'svgMaxSize' => $coreConfig->get( 'SVGMaxSize' ),
|
|
|
|
|
'namespacesWithSubpages' => $coreConfig->get( 'NamespacesWithSubpages' ),
|
2015-08-25 05:48:16 +00:00
|
|
|
|
'specialBooksources' => urldecode( SpecialPage::getTitleFor( 'Booksources' )->getPrefixedURL() ),
|
2016-10-25 20:44:26 +00:00
|
|
|
|
'rebaserUrl' => $coreConfig->get( 'VisualEditorRebaserURL' ),
|
2015-03-13 22:15:17 +00:00
|
|
|
|
'restbaseUrl' => $coreConfig->get( 'VisualEditorRestbaseURL' ),
|
2015-10-08 22:16:56 +00:00
|
|
|
|
'fullRestbaseUrl' => $coreConfig->get( 'VisualEditorFullRestbaseURL' ),
|
2017-08-16 08:23:51 +00:00
|
|
|
|
'feedbackApiUrl' => $veConfig->get( 'VisualEditorFeedbackAPIURL' ),
|
|
|
|
|
'feedbackTitle' => $veConfig->get( 'VisualEditorFeedbackTitle' ),
|
2016-02-17 16:18:02 +00:00
|
|
|
|
];
|
2012-12-06 05:57:53 +00:00
|
|
|
|
|
2012-06-01 23:26:03 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-07-27 23:43:27 +00:00
|
|
|
|
|
2013-12-05 02:28:59 +00:00
|
|
|
|
/**
|
2014-07-22 23:49:06 +00:00
|
|
|
|
* Conditionally register the jquery.uls.data and jquery.i18n modules, in case they've already
|
2015-01-03 17:10:08 +00:00
|
|
|
|
* been registered by the UniversalLanguageSelector extension or the TemplateData extension.
|
2013-12-05 22:45:44 +00:00
|
|
|
|
*
|
2017-05-04 22:59:27 +00:00
|
|
|
|
* @param ResourceLoader &$resourceLoader Client-side code and assets to be loaded.
|
2017-07-25 14:49:56 +00:00
|
|
|
|
* @return bool Always true.
|
2013-12-05 02:28:59 +00:00
|
|
|
|
*/
|
|
|
|
|
public static function onResourceLoaderRegisterModules( ResourceLoader &$resourceLoader ) {
|
2014-08-13 08:15:42 +00:00
|
|
|
|
$resourceModules = $resourceLoader->getConfig()->get( 'ResourceModules' );
|
2015-07-07 01:34:35 +00:00
|
|
|
|
|
2016-02-17 16:18:02 +00:00
|
|
|
|
$veResourceTemplate = [
|
2015-01-27 05:47:31 +00:00
|
|
|
|
'localBasePath' => __DIR__,
|
|
|
|
|
'remoteExtPath' => 'VisualEditor',
|
2016-02-17 16:18:02 +00:00
|
|
|
|
];
|
2014-02-14 22:31:15 +00:00
|
|
|
|
|
2015-07-07 01:34:35 +00:00
|
|
|
|
// Only pull in VisualEditor core's local version of jquery.uls.data if it hasn't been
|
|
|
|
|
// installed locally already (presumably, by the UniversalLanguageSelector extension).
|
|
|
|
|
if (
|
|
|
|
|
!isset( $resourceModules[ 'jquery.uls.data' ] ) &&
|
|
|
|
|
!$resourceLoader->isModuleRegistered( 'jquery.uls.data' )
|
|
|
|
|
) {
|
2016-02-17 16:18:02 +00:00
|
|
|
|
$resourceLoader->register( [
|
|
|
|
|
'jquery.uls.data' => $veResourceTemplate + [
|
|
|
|
|
'scripts' => [
|
2018-02-09 18:31:58 +00:00
|
|
|
|
'../lib/ve/lib/jquery.uls/src/jquery.uls.data.js',
|
|
|
|
|
'../lib/ve/lib/jquery.uls/src/jquery.uls.data.utils.js',
|
2016-02-17 16:18:02 +00:00
|
|
|
|
],
|
|
|
|
|
'targets' => [ 'desktop', 'mobile' ],
|
|
|
|
|
] ] );
|
2013-12-05 22:08:29 +00:00
|
|
|
|
}
|
2013-12-09 23:00:09 +00:00
|
|
|
|
|
2016-07-12 19:32:27 +00:00
|
|
|
|
$extensionMessages = [];
|
|
|
|
|
if ( class_exists( 'ConfirmEditHooks' ) ) {
|
|
|
|
|
$extensionMessages[] = 'captcha-edit';
|
|
|
|
|
$extensionMessages[] = 'captcha-label';
|
|
|
|
|
|
|
|
|
|
if ( class_exists( 'QuestyCaptcha' ) ) {
|
|
|
|
|
$extensionMessages[] = 'questycaptcha-edit';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( class_exists( 'FancyCaptcha' ) ) {
|
|
|
|
|
$extensionMessages[] = 'fancycaptcha-edit';
|
|
|
|
|
$extensionMessages[] = 'fancycaptcha-reload-text';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$resourceLoader->register( [
|
|
|
|
|
'ext.visualEditor.mwextensionmessages' => $veResourceTemplate + [
|
|
|
|
|
'messages' => $extensionMessages,
|
|
|
|
|
'targets' => [ 'desktop', 'mobile' ],
|
|
|
|
|
]
|
|
|
|
|
] );
|
|
|
|
|
|
2013-12-05 02:28:59 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-30 11:00:36 +00:00
|
|
|
|
public static function onResourceLoaderTestModules(
|
|
|
|
|
array &$testModules,
|
|
|
|
|
ResourceLoader &$resourceLoader
|
|
|
|
|
) {
|
2016-02-17 16:18:02 +00:00
|
|
|
|
$testModules['qunit']['ext.visualEditor.test'] = [
|
|
|
|
|
'styles' => [
|
2013-09-30 12:11:49 +00:00
|
|
|
|
// jsdifflib
|
2013-12-19 23:07:19 +00:00
|
|
|
|
'lib/ve/lib/jsdifflib/diffview.css',
|
2016-02-17 16:18:02 +00:00
|
|
|
|
],
|
|
|
|
|
'scripts' => [
|
2013-07-03 01:30:10 +00:00
|
|
|
|
// MW config preload
|
2014-07-11 09:09:29 +00:00
|
|
|
|
'modules/ve-mw/tests/mw-preload.js',
|
2013-09-30 12:11:49 +00:00
|
|
|
|
// jsdifflib
|
2013-12-19 23:07:19 +00:00
|
|
|
|
'lib/ve/lib/jsdifflib/diffview.js',
|
|
|
|
|
'lib/ve/lib/jsdifflib/difflib.js',
|
2012-07-27 23:43:27 +00:00
|
|
|
|
// QUnit plugin
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/ve.qunit.js',
|
2012-07-27 23:43:27 +00:00
|
|
|
|
// VisualEditor Tests
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/ve.test.utils.js',
|
2014-07-11 09:09:29 +00:00
|
|
|
|
'modules/ve-mw/tests/ve.test.utils.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/ve.test.js',
|
2017-04-28 15:42:04 +00:00
|
|
|
|
'lib/ve/tests/ve.EventSequencer.test.js',
|
|
|
|
|
'lib/ve/tests/ve.Scheduler.test.js',
|
|
|
|
|
'lib/ve/tests/ve.Range.test.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/ve.Document.test.js',
|
|
|
|
|
'lib/ve/tests/ve.Node.test.js',
|
|
|
|
|
'lib/ve/tests/ve.BranchNode.test.js',
|
|
|
|
|
'lib/ve/tests/ve.LeafNode.test.js',
|
2012-07-27 23:43:27 +00:00
|
|
|
|
// VisualEditor DataModel Tests
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/dm/ve.dm.example.js',
|
2017-04-28 15:42:04 +00:00
|
|
|
|
'lib/ve/tests/dm/ve.dm.Annotation.test.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/dm/ve.dm.AnnotationSet.test.js',
|
2017-04-28 15:42:04 +00:00
|
|
|
|
'lib/ve/tests/dm/ve.dm.LinkAnnotation.test.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/dm/ve.dm.NodeFactory.test.js',
|
|
|
|
|
'lib/ve/tests/dm/ve.dm.Node.test.js',
|
|
|
|
|
'lib/ve/tests/dm/ve.dm.Converter.test.js',
|
|
|
|
|
'lib/ve/tests/dm/ve.dm.BranchNode.test.js',
|
|
|
|
|
'lib/ve/tests/dm/ve.dm.LeafNode.test.js',
|
|
|
|
|
'lib/ve/tests/dm/nodes/ve.dm.TextNode.test.js',
|
2014-07-11 09:09:29 +00:00
|
|
|
|
'modules/ve-mw/tests/dm/nodes/ve.dm.MWTransclusionNode.test.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/dm/ve.dm.Document.test.js',
|
2014-09-18 23:56:11 +00:00
|
|
|
|
'modules/ve-mw/tests/dm/ve.dm.Document.test.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/dm/ve.dm.IndexValueStore.test.js',
|
|
|
|
|
'lib/ve/tests/dm/ve.dm.InternalList.test.js',
|
2017-04-28 15:42:04 +00:00
|
|
|
|
'lib/ve/tests/dm/ve.dm.LinearData.test.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/dm/ve.dm.Transaction.test.js',
|
2017-04-28 15:42:04 +00:00
|
|
|
|
'lib/ve/tests/dm/ve.dm.TransactionBuilder.test.js',
|
2017-09-13 13:57:11 +00:00
|
|
|
|
'lib/ve/tests/dm/ve.dm.Change.test.js',
|
2017-09-06 20:23:41 +00:00
|
|
|
|
'lib/ve/tests/dm/ve.dm.TreeModifier.test.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/dm/ve.dm.TransactionProcessor.test.js',
|
2015-02-07 01:35:34 +00:00
|
|
|
|
'lib/ve/tests/dm/ve.dm.APIResultsQueue.test.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/dm/ve.dm.Surface.test.js',
|
|
|
|
|
'lib/ve/tests/dm/ve.dm.SurfaceFragment.test.js',
|
2014-07-11 09:09:29 +00:00
|
|
|
|
'modules/ve-mw/tests/dm/ve.dm.SurfaceFragment.test.js',
|
2017-04-28 15:42:04 +00:00
|
|
|
|
'lib/ve/tests/dm/ve.dm.SourceSurfaceFragment.test.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/dm/ve.dm.ModelRegistry.test.js',
|
|
|
|
|
'lib/ve/tests/dm/ve.dm.MetaList.test.js',
|
2017-04-28 15:42:04 +00:00
|
|
|
|
'lib/ve/tests/dm/ve.dm.Scalable.test.js',
|
|
|
|
|
'lib/ve/tests/dm/selections/ve.dm.LinearSelection.test.js',
|
|
|
|
|
'lib/ve/tests/dm/selections/ve.dm.NullSelection.test.js',
|
|
|
|
|
'lib/ve/tests/dm/selections/ve.dm.TableSelection.test.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/dm/lineardata/ve.dm.FlatLinearData.test.js',
|
|
|
|
|
'lib/ve/tests/dm/lineardata/ve.dm.ElementLinearData.test.js',
|
2014-07-11 09:09:29 +00:00
|
|
|
|
'modules/ve-mw/tests/dm/ve.dm.mwExample.js',
|
|
|
|
|
'modules/ve-mw/tests/dm/ve.dm.Converter.test.js',
|
|
|
|
|
'modules/ve-mw/tests/dm/ve.dm.MWImageModel.test.js',
|
2016-09-21 16:33:42 +00:00
|
|
|
|
'modules/ve-mw/tests/dm/ve.dm.MWInternalLinkAnnotation.test.js',
|
2012-07-27 23:43:27 +00:00
|
|
|
|
// VisualEditor ContentEditable Tests
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/ce/ve.ce.test.js',
|
|
|
|
|
'lib/ve/tests/ce/ve.ce.Document.test.js',
|
2017-06-22 19:55:28 +00:00
|
|
|
|
'modules/ve-mw/tests/ce/ve.ce.Document.test.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/ce/ve.ce.Surface.test.js',
|
2014-07-11 09:09:29 +00:00
|
|
|
|
'modules/ve-mw/tests/ce/ve.ce.Surface.test.js',
|
2017-04-28 15:42:04 +00:00
|
|
|
|
'lib/ve/tests/ce/ve.ce.RangeState.test.js',
|
|
|
|
|
'lib/ve/tests/ce/ve.ce.TextState.test.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/ce/ve.ce.NodeFactory.test.js',
|
|
|
|
|
'lib/ve/tests/ce/ve.ce.Node.test.js',
|
|
|
|
|
'lib/ve/tests/ce/ve.ce.BranchNode.test.js',
|
|
|
|
|
'lib/ve/tests/ce/ve.ce.ContentBranchNode.test.js',
|
2014-07-11 09:09:29 +00:00
|
|
|
|
'modules/ve-mw/tests/ce/ve.ce.ContentBranchNode.test.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/ce/ve.ce.LeafNode.test.js',
|
|
|
|
|
'lib/ve/tests/ce/nodes/ve.ce.TextNode.test.js',
|
2017-04-28 15:42:04 +00:00
|
|
|
|
'lib/ve/tests/ce/nodes/ve.ce.TableNode.test.js',
|
|
|
|
|
// VisualEditor UI Tests
|
|
|
|
|
'lib/ve/tests/ui/ve.ui.Trigger.test.js',
|
|
|
|
|
'lib/ve/tests/ui/ve.ui.DiffElement.test.js',
|
2013-05-14 23:45:42 +00:00
|
|
|
|
// VisualEditor Actions Tests
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/ui/actions/ve.ui.AnnotationAction.test.js',
|
2017-04-28 15:42:04 +00:00
|
|
|
|
'lib/ve/tests/ui/actions/ve.ui.ContentAction.test.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/ui/actions/ve.ui.FormatAction.test.js',
|
2014-07-11 09:09:29 +00:00
|
|
|
|
'modules/ve-mw/tests/ui/actions/ve.ui.FormatAction.test.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/ui/actions/ve.ui.IndentationAction.test.js',
|
2015-08-12 20:55:31 +00:00
|
|
|
|
'lib/ve/tests/ui/actions/ve.ui.LinkAction.test.js',
|
2015-08-17 16:28:57 +00:00
|
|
|
|
'modules/ve-mw/tests/ui/actions/ve.ui.MWLinkAction.test.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/ui/actions/ve.ui.ListAction.test.js',
|
2017-04-28 15:42:04 +00:00
|
|
|
|
'lib/ve/tests/ui/actions/ve.ui.TableAction.test.js',
|
2015-08-12 19:24:39 +00:00
|
|
|
|
// VisualEditor DataTransferHandler tests
|
2017-04-28 15:42:04 +00:00
|
|
|
|
'lib/ve/tests/ui/ve.ui.DataTransferHandlerFactory.test.js',
|
2015-08-12 19:24:39 +00:00
|
|
|
|
'lib/ve/tests/ui/datatransferhandlers/ve.ui.DSVFileTransferHandler.test.js',
|
|
|
|
|
'lib/ve/tests/ui/datatransferhandlers/ve.ui.UrlStringTransferHandler.test.js',
|
2015-08-07 18:16:09 +00:00
|
|
|
|
'modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.test.js',
|
2015-08-23 16:40:22 +00:00
|
|
|
|
'modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.UrlStringTransferHandler.test.js',
|
2012-12-04 06:56:41 +00:00
|
|
|
|
// VisualEditor initialization Tests
|
2015-07-29 13:41:30 +00:00
|
|
|
|
'modules/ve-mw/tests/init/targets/ve.init.mw.DesktopArticleTarget.test.js',
|
2013-09-06 19:25:21 +00:00
|
|
|
|
// IME tests
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/ce/ve.ce.TestRunner.js',
|
|
|
|
|
'lib/ve/tests/ce/ve.ce.imetests.test.js',
|
2015-06-26 18:09:41 +00:00
|
|
|
|
'lib/ve/tests/ce/imetests/backspace-chromium-ubuntu-none.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/backspace-firefox-ubuntu-none.js',
|
2015-09-29 22:04:13 +00:00
|
|
|
|
'lib/ve/tests/ce/imetests/backspace-ie9-win7-none.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/home-firefox-win7-none.js',
|
2015-06-29 21:31:38 +00:00
|
|
|
|
'lib/ve/tests/ce/imetests/input-chrome-mac-native-japanese-hiragana.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/input-chrome-mac-native-japanese-katakana.js',
|
2015-09-29 22:04:13 +00:00
|
|
|
|
'lib/ve/tests/ce/imetests/input-chrome-win7-chinese-traditional-handwriting.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/input-chrome-win7-greek.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/input-chrome-win7-polish.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/input-chrome-win7-welsh.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/ce/imetests/input-chromium-ubuntu-ibus-chinese-cantonese.js',
|
2015-09-29 22:04:13 +00:00
|
|
|
|
'lib/ve/tests/ce/imetests/input-chromium-ubuntu-ibus-japanese-anthy--hiraganaonly.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/input-chromium-ubuntu-ibus-japanese-mozc.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/ce/imetests/input-chromium-ubuntu-ibus-korean-korean.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/input-chromium-ubuntu-ibus-malayalam-swanalekha.js',
|
2015-06-29 21:31:38 +00:00
|
|
|
|
'lib/ve/tests/ce/imetests/input-firefox-mac-native-japanese-hiragana.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/input-firefox-mac-native-japanese-katakana.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/ce/imetests/input-firefox-ubuntu-ibus-chinese-cantonese.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/input-firefox-ubuntu-ibus-japanese-anthy--hiraganaonly.js',
|
2015-09-29 22:04:13 +00:00
|
|
|
|
'lib/ve/tests/ce/imetests/input-firefox-ubuntu-ibus-japanese-mozc.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/ce/imetests/input-firefox-ubuntu-ibus-korean-korean.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/input-firefox-ubuntu-ibus-malayalam.swanalekha.js',
|
2015-09-29 22:04:13 +00:00
|
|
|
|
'lib/ve/tests/ce/imetests/input-firefox-win7-chinese-traditional-handwriting.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/input-firefox-win7-greek.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/input-firefox-win7-welsh.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/input-ie9-win7-chinese-traditional-handwriting.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/input-ie9-win7-greek.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/input-ie9-win7-korean.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/input-ie9-win7-welsh.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/input-ie11-win8.1-korean.js',
|
2015-06-29 21:31:38 +00:00
|
|
|
|
'lib/ve/tests/ce/imetests/input-safari-mac-native-japanese-hiragana.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/input-safari-mac-native-japanese-katakana.js',
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'lib/ve/tests/ce/imetests/leftarrow-chromium-ubuntu-none.js',
|
|
|
|
|
'lib/ve/tests/ce/imetests/leftarrow-firefox-ubuntu-none.js',
|
2015-09-29 22:04:13 +00:00
|
|
|
|
'lib/ve/tests/ce/imetests/leftarrow-ie9-win7-none.js',
|
2016-02-17 16:18:02 +00:00
|
|
|
|
],
|
|
|
|
|
'dependencies' => [
|
2014-08-14 21:16:47 +00:00
|
|
|
|
'unicodejs',
|
2012-07-27 23:43:27 +00:00
|
|
|
|
'ext.visualEditor.core',
|
2014-02-26 00:50:20 +00:00
|
|
|
|
'ext.visualEditor.mwcore',
|
|
|
|
|
'ext.visualEditor.mwformatting',
|
|
|
|
|
'ext.visualEditor.mwlink',
|
|
|
|
|
'ext.visualEditor.mwgallery',
|
|
|
|
|
'ext.visualEditor.mwimage',
|
|
|
|
|
'ext.visualEditor.mwmeta',
|
|
|
|
|
'ext.visualEditor.mwtransclusion',
|
2015-06-23 02:30:31 +00:00
|
|
|
|
'ext.visualEditor.mwalienextension',
|
2016-09-08 22:44:12 +00:00
|
|
|
|
'ext.visualEditor.language',
|
2013-04-16 17:31:17 +00:00
|
|
|
|
'ext.visualEditor.experimental',
|
2015-07-29 13:41:30 +00:00
|
|
|
|
'ext.visualEditor.desktopArticleTarget.init',
|
|
|
|
|
'ext.visualEditor.desktopArticleTarget',
|
2017-09-13 13:57:11 +00:00
|
|
|
|
'ext.visualEditor.rebase'
|
2016-02-17 16:18:02 +00:00
|
|
|
|
],
|
2018-02-05 18:59:37 +00:00
|
|
|
|
'localBasePath' => __DIR__ . '/..',
|
2013-12-19 20:28:07 +00:00
|
|
|
|
'remoteExtPath' => 'VisualEditor',
|
2016-02-17 16:18:02 +00:00
|
|
|
|
];
|
2012-07-27 23:43:27 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-09-16 21:12:50 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Ensures that we know whether we're running inside a parser test.
|
2017-05-04 22:35:14 +00:00
|
|
|
|
*
|
2017-05-04 22:59:27 +00:00
|
|
|
|
* @param array &$settings The settings with which MediaWiki is being run.
|
2013-09-16 21:12:50 +00:00
|
|
|
|
*/
|
|
|
|
|
public static function onParserTestGlobals( array &$settings ) {
|
|
|
|
|
$settings['wgVisualEditorInParserTests'] = true;
|
|
|
|
|
}
|
2014-05-22 07:04:41 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2017-05-04 22:12:46 +00:00
|
|
|
|
* @param Array &$redirectParams Parameters preserved on special page redirects
|
2014-05-22 07:04:41 +00:00
|
|
|
|
* to wiki pages
|
2017-07-25 14:49:56 +00:00
|
|
|
|
* @return bool Always true
|
2014-05-22 07:04:41 +00:00
|
|
|
|
*/
|
|
|
|
|
public static function onRedirectSpecialArticleRedirectParams( &$redirectParams ) {
|
2016-11-05 02:07:39 +00:00
|
|
|
|
array_push( $redirectParams, 'veaction' );
|
2014-05-22 07:04:41 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-09 22:58:15 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If the user has specified that they want to edit the page with VE, suppress any redirect.
|
2017-05-04 22:59:27 +00:00
|
|
|
|
*
|
2014-06-09 22:58:15 +00:00
|
|
|
|
* @param Title $title Title being used for request
|
2017-05-04 22:59:27 +00:00
|
|
|
|
* @param Article|null $article The page being viewed.
|
|
|
|
|
* @param OutputPage $output The page view.
|
|
|
|
|
* @param User $user The user-specific settings.
|
|
|
|
|
* @param WebRequest $request The request.
|
|
|
|
|
* @param MediaWiki $mediaWiki Helper class.
|
2017-07-25 14:49:56 +00:00
|
|
|
|
* @return bool Always true
|
2014-06-09 22:58:15 +00:00
|
|
|
|
*/
|
|
|
|
|
public static function onBeforeInitialize(
|
|
|
|
|
Title $title, $article, OutputPage $output,
|
|
|
|
|
User $user, WebRequest $request, MediaWiki $mediaWiki
|
|
|
|
|
) {
|
|
|
|
|
if ( $request->getVal( 'veaction' ) === 'edit' ) {
|
|
|
|
|
$request->setVal( 'redirect', 'no' );
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-04-17 21:01:11 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2016-05-19 13:22:39 +00:00
|
|
|
|
* Set user preferences for new and auto-created accounts if so configured.
|
2015-04-17 21:01:11 +00:00
|
|
|
|
*
|
2015-07-16 14:13:41 +00:00
|
|
|
|
* Sets user preference to enable the VisualEditor account for new auto-
|
|
|
|
|
* created ('auth') accounts, if $wgVisualEditorAutoAccountEnable is set.
|
|
|
|
|
*
|
2016-05-19 13:22:39 +00:00
|
|
|
|
* Sets user preference to enable the VisualEditor account for new non-auto-
|
|
|
|
|
* created accounts, if the account's userID matches, modulo the value of
|
|
|
|
|
* $wgVisualEditorNewAccountEnableProportion, if set. If set to '1', all new
|
|
|
|
|
* accounts would have VisualEditor enabled; at '2', 50% would; at '20',
|
|
|
|
|
* 5% would, and so on.
|
|
|
|
|
*
|
2015-07-16 14:13:41 +00:00
|
|
|
|
* To be removed once no longer needed.
|
2017-05-04 22:15:55 +00:00
|
|
|
|
*
|
2017-05-04 22:59:27 +00:00
|
|
|
|
* @param User $user The user-specific settings.
|
2017-07-25 14:49:56 +00:00
|
|
|
|
* @param bool $autocreated True if the user was auto-created (not a new global user).
|
|
|
|
|
* @return bool Always true
|
2015-07-16 14:13:41 +00:00
|
|
|
|
*/
|
2016-05-19 13:22:39 +00:00
|
|
|
|
public static function onLocalUserCreated( $user, $autocreated ) {
|
|
|
|
|
$config = RequestContext::getMain()->getConfig();
|
|
|
|
|
$enableProportion = $config->get( 'VisualEditorNewAccountEnableProportion' );
|
|
|
|
|
|
2015-07-16 14:13:41 +00:00
|
|
|
|
if (
|
2016-05-19 13:22:39 +00:00
|
|
|
|
// Only act on actual accounts (avoid race condition bugs)
|
|
|
|
|
$user->isLoggedin() &&
|
|
|
|
|
// Only act if the default isn't already set
|
|
|
|
|
!User::getDefaultOption( 'visualeditor-enable' ) &&
|
|
|
|
|
// Act if either …
|
|
|
|
|
(
|
|
|
|
|
// … this is an auto-created account and we're configured so to do
|
|
|
|
|
(
|
|
|
|
|
$autocreated &&
|
|
|
|
|
$config->get( 'VisualEditorAutoAccountEnable' )
|
|
|
|
|
) ||
|
|
|
|
|
// … this is a real new account that matches the modulo and we're configured so to do
|
|
|
|
|
(
|
|
|
|
|
!$autocreated &&
|
|
|
|
|
$enableProportion &&
|
|
|
|
|
( ( $user->getId() % $enableProportion ) === 0 )
|
|
|
|
|
)
|
|
|
|
|
)
|
2015-07-16 14:13:41 +00:00
|
|
|
|
) {
|
|
|
|
|
$user->setOption( 'visualeditor-enable', 1 );
|
|
|
|
|
$user->saveSettings();
|
|
|
|
|
}
|
2016-05-19 13:22:39 +00:00
|
|
|
|
|
2015-07-16 14:13:41 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 21:13:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* On login, if user has a VEE cookie, set their preference equal to it.
|
2017-05-04 22:31:20 +00:00
|
|
|
|
*
|
2017-05-04 22:59:27 +00:00
|
|
|
|
* @param User $user The user-specific settings.
|
2017-07-25 14:49:56 +00:00
|
|
|
|
* @return bool Always true.
|
2016-06-20 21:13:36 +00:00
|
|
|
|
*/
|
|
|
|
|
public static function onUserLoggedIn( $user ) {
|
|
|
|
|
$cookie = RequestContext::getMain()->getRequest()->getCookie( 'VEE', '' );
|
|
|
|
|
if ( $cookie === 'visualeditor' || $cookie === 'wikitext' ) {
|
2017-04-19 15:15:06 +00:00
|
|
|
|
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
|
2016-08-18 23:11:38 +00:00
|
|
|
|
DeferredUpdates::addUpdate( new AtomicSectionUpdate(
|
2017-04-19 15:15:06 +00:00
|
|
|
|
$lb->getLazyConnectionRef( DB_MASTER ),
|
2016-08-18 23:11:38 +00:00
|
|
|
|
__METHOD__,
|
|
|
|
|
function () use ( $user, $cookie ) {
|
2017-04-19 15:15:06 +00:00
|
|
|
|
if ( wfReadOnly() ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-18 23:11:38 +00:00
|
|
|
|
$uLatest = $user->getInstanceForUpdate();
|
|
|
|
|
$uLatest->setOption( 'visualeditor-editor', $cookie );
|
|
|
|
|
$uLatest->saveSettings();
|
|
|
|
|
}
|
|
|
|
|
) );
|
2016-06-20 21:13:36 +00:00
|
|
|
|
}
|
2016-08-18 23:11:38 +00:00
|
|
|
|
|
2016-06-20 21:13:36 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-05-25 19:50:48 +00:00
|
|
|
|
}
|