2010-09-15 03:02:35 +00:00
|
|
|
<?php
|
2010-09-15 22:40:50 +00:00
|
|
|
/**
|
2010-10-01 18:15:10 +00:00
|
|
|
* Hooks for WikiEditor extension
|
2011-09-13 08:56:32 +00:00
|
|
|
*
|
2010-09-15 22:40:50 +00:00
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
*/
|
|
|
|
|
|
|
|
class WikiEditorHooks {
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-16 23:41:08 +00:00
|
|
|
/* Protected Static Members */
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-16 23:41:08 +00:00
|
|
|
protected static $features = array(
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2013-05-25 15:07:46 +00:00
|
|
|
/* Toolbar Features */
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-16 21:11:46 +00:00
|
|
|
'toolbar' => array(
|
2012-04-11 13:40:13 +00:00
|
|
|
'preferences' => array(
|
|
|
|
// Ideally this key would be 'wikieditor-toolbar'
|
|
|
|
'usebetatoolbar' => array(
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'wikieditor-toolbar-preference',
|
2013-05-25 15:07:46 +00:00
|
|
|
'section' => 'editing/editor',
|
2012-04-11 13:40:13 +00:00
|
|
|
),
|
|
|
|
),
|
2010-09-16 21:11:46 +00:00
|
|
|
'requirements' => array(
|
|
|
|
'usebetatoolbar' => true,
|
|
|
|
),
|
|
|
|
'modules' => array(
|
2010-09-20 20:06:18 +00:00
|
|
|
'ext.wikiEditor.toolbar',
|
2010-09-16 21:11:46 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'dialogs' => array(
|
2012-04-16 22:17:41 +00:00
|
|
|
'preferences' => array(
|
|
|
|
// Ideally this key would be 'wikieditor-toolbar-dialogs'
|
|
|
|
'usebetatoolbar-cgd' => array(
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'wikieditor-toolbar-dialogs-preference',
|
2013-05-25 15:07:46 +00:00
|
|
|
'section' => 'editing/editor',
|
2012-04-16 22:17:41 +00:00
|
|
|
),
|
|
|
|
),
|
2010-09-16 21:11:46 +00:00
|
|
|
'requirements' => array(
|
|
|
|
'usebetatoolbar-cgd' => true,
|
2011-02-17 22:44:29 +00:00
|
|
|
'usebetatoolbar' => true,
|
2010-09-16 21:11:46 +00:00
|
|
|
),
|
|
|
|
'modules' => array(
|
2010-09-20 20:06:18 +00:00
|
|
|
'ext.wikiEditor.dialogs',
|
2010-09-16 21:11:46 +00:00
|
|
|
),
|
|
|
|
),
|
2011-04-22 12:10:18 +00:00
|
|
|
'hidesig' => array(
|
|
|
|
'preferences' => array(
|
|
|
|
'wikieditor-toolbar-hidesig' => array(
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'wikieditor-toolbar-hidesig',
|
2013-05-25 15:07:46 +00:00
|
|
|
'section' => 'editing/editor',
|
2011-04-22 12:10:18 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'requirements' => array(
|
|
|
|
'wikieditor-toolbar-hidesig' => true,
|
|
|
|
'usebetatoolbar' => true,
|
|
|
|
),
|
|
|
|
'modules' => array(
|
|
|
|
'ext.wikiEditor.toolbar.hideSig',
|
|
|
|
),
|
|
|
|
),
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-16 21:11:46 +00:00
|
|
|
/* Labs Features */
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-15 22:40:50 +00:00
|
|
|
'preview' => array(
|
2010-09-16 21:11:46 +00:00
|
|
|
'preferences' => array(
|
|
|
|
'wikieditor-preview' => array(
|
2010-09-15 22:40:50 +00:00
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'wikieditor-preview-preference',
|
|
|
|
'section' => 'editing/labs',
|
|
|
|
),
|
|
|
|
),
|
2010-09-16 21:11:46 +00:00
|
|
|
'requirements' => array(
|
|
|
|
'wikieditor-preview' => true,
|
|
|
|
),
|
|
|
|
'modules' => array(
|
2010-09-20 20:06:18 +00:00
|
|
|
'ext.wikiEditor.preview',
|
2010-09-15 22:40:50 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'previewDialog' => array(
|
2010-09-16 21:11:46 +00:00
|
|
|
'preferences' => array(
|
|
|
|
'wikieditor-previewDialog' => array(
|
2010-09-15 22:40:50 +00:00
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'wikieditor-previewDialog-preference',
|
|
|
|
'section' => 'editing/labs',
|
|
|
|
),
|
|
|
|
),
|
2010-09-16 21:11:46 +00:00
|
|
|
'requirements' => array(
|
|
|
|
'wikieditor-previewDialog' => true,
|
|
|
|
),
|
|
|
|
'modules' => array(
|
2010-09-20 20:06:18 +00:00
|
|
|
'ext.wikiEditor.previewDialog',
|
2010-09-16 21:11:46 +00:00
|
|
|
),
|
2010-09-15 22:40:50 +00:00
|
|
|
),
|
|
|
|
'publish' => array(
|
2010-09-16 21:11:46 +00:00
|
|
|
'preferences' => array(
|
|
|
|
'wikieditor-publish' => array(
|
2010-09-15 22:40:50 +00:00
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'wikieditor-publish-preference',
|
|
|
|
'section' => 'editing/labs',
|
|
|
|
),
|
|
|
|
),
|
2010-09-16 21:11:46 +00:00
|
|
|
'requirements' => array(
|
|
|
|
'wikieditor-publish' => true,
|
|
|
|
),
|
|
|
|
'modules' => array(
|
2010-09-20 20:06:18 +00:00
|
|
|
'ext.wikiEditor.publish',
|
2010-09-16 21:11:46 +00:00
|
|
|
),
|
2014-04-03 14:25:10 +00:00
|
|
|
)
|
2010-09-15 22:40:50 +00:00
|
|
|
);
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2011-02-25 00:01:57 +00:00
|
|
|
/* Static Methods */
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2011-02-25 00:01:57 +00:00
|
|
|
/**
|
|
|
|
* Checks if a certain option is enabled
|
|
|
|
*
|
|
|
|
* This method is public to allow other extensions that use WikiEditor to use the
|
|
|
|
* same configuration as WikiEditor itself
|
|
|
|
*
|
2012-01-31 20:19:22 +00:00
|
|
|
* @param $name string Name of the feature, should be a key of $features
|
|
|
|
* @return bool
|
2011-02-25 00:01:57 +00:00
|
|
|
*/
|
|
|
|
public static function isEnabled( $name ) {
|
2010-09-16 21:11:46 +00:00
|
|
|
global $wgWikiEditorFeatures, $wgUser;
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-16 22:40:24 +00:00
|
|
|
// Features with global set to true are always enabled
|
2010-09-16 21:11:46 +00:00
|
|
|
if ( !isset( $wgWikiEditorFeatures[$name] ) || $wgWikiEditorFeatures[$name]['global'] ) {
|
|
|
|
return true;
|
2010-09-15 22:40:50 +00:00
|
|
|
}
|
2010-09-16 21:11:46 +00:00
|
|
|
// Features with user preference control can have any number of preferences to be specific values to be enabled
|
|
|
|
if ( $wgWikiEditorFeatures[$name]['user'] ) {
|
|
|
|
if ( isset( self::$features[$name]['requirements'] ) ) {
|
|
|
|
foreach ( self::$features[$name]['requirements'] as $requirement => $value ) {
|
|
|
|
// Important! We really do want fuzzy evaluation here
|
|
|
|
if ( $wgUser->getOption( $requirement ) != $value ) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-15 22:40:50 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-16 21:11:46 +00:00
|
|
|
return true;
|
2010-09-15 22:40:50 +00:00
|
|
|
}
|
2011-09-13 08:56:32 +00:00
|
|
|
// Features controlled by $wgWikiEditorFeatures with both global and user set to false are awlways disabled
|
2010-09-16 21:11:46 +00:00
|
|
|
return false;
|
2010-09-15 22:40:50 +00:00
|
|
|
}
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-15 22:40:50 +00:00
|
|
|
/**
|
2010-09-16 21:11:46 +00:00
|
|
|
* EditPage::showEditForm:initial hook
|
2011-09-13 08:56:32 +00:00
|
|
|
*
|
2010-09-15 22:40:50 +00:00
|
|
|
* Adds the modules to the edit form
|
2011-09-13 08:56:32 +00:00
|
|
|
*
|
2010-09-16 23:41:08 +00:00
|
|
|
* @param $toolbar array list of toolbar items
|
2012-01-31 20:19:22 +00:00
|
|
|
* @return bool
|
2010-09-15 22:40:50 +00:00
|
|
|
*/
|
2010-09-16 21:11:46 +00:00
|
|
|
public static function editPageShowEditFormInitial( &$toolbar ) {
|
|
|
|
global $wgOut;
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-16 21:11:46 +00:00
|
|
|
// Add modules for enabled features
|
|
|
|
foreach ( self::$features as $name => $feature ) {
|
|
|
|
if ( isset( $feature['modules'] ) && self::isEnabled( $name ) ) {
|
|
|
|
$wgOut->addModules( $feature['modules'] );
|
2010-09-15 22:40:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2012-02-17 22:13:11 +00:00
|
|
|
/**
|
|
|
|
* EditPageBeforeEditToolbar hook
|
|
|
|
*
|
|
|
|
* Disable the old toolbar if the new one is enabled
|
|
|
|
*
|
|
|
|
* @param $toolbar html
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function EditPageBeforeEditToolbar( &$toolbar ) {
|
|
|
|
if ( self::isEnabled( 'toolbar' ) ) {
|
2012-04-17 22:19:03 +00:00
|
|
|
$toolbar = Html::rawElement(
|
|
|
|
'div', array(
|
|
|
|
'class' => 'wikiEditor-oldToolbar',
|
|
|
|
'style' => 'display:none;'
|
|
|
|
),
|
|
|
|
$toolbar
|
|
|
|
);
|
2012-02-17 22:13:11 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-15 22:40:50 +00:00
|
|
|
/**
|
|
|
|
* GetPreferences hook
|
2011-09-13 08:56:32 +00:00
|
|
|
*
|
2010-10-01 18:15:10 +00:00
|
|
|
* Adds WikiEditor-releated items to the preferences
|
2011-09-13 08:56:32 +00:00
|
|
|
*
|
2011-01-23 09:46:07 +00:00
|
|
|
* @param $user User current user
|
|
|
|
* @param $defaultPreferences array list of default user preference controls
|
2012-01-31 20:19:22 +00:00
|
|
|
* @return bool
|
2010-09-15 22:40:50 +00:00
|
|
|
*/
|
|
|
|
public static function getPreferences( $user, &$defaultPreferences ) {
|
2010-09-16 21:11:46 +00:00
|
|
|
global $wgWikiEditorFeatures;
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-16 21:11:46 +00:00
|
|
|
foreach ( self::$features as $name => $feature ) {
|
|
|
|
if (
|
|
|
|
isset( $feature['preferences'] ) &&
|
|
|
|
( !isset( $wgWikiEditorFeatures[$name] ) || $wgWikiEditorFeatures[$name]['user'] )
|
|
|
|
) {
|
2010-10-01 19:14:33 +00:00
|
|
|
foreach ( $feature['preferences'] as $key => $options ) {
|
|
|
|
$defaultPreferences[$key] = $options;
|
|
|
|
}
|
2010-09-15 22:40:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-15 22:40:50 +00:00
|
|
|
/**
|
|
|
|
* MakeGlobalVariablesScript hook
|
2011-09-13 08:56:32 +00:00
|
|
|
*
|
2010-10-01 18:15:10 +00:00
|
|
|
* Adds enabled/disabled switches for WikiEditor modules
|
2012-01-31 20:19:22 +00:00
|
|
|
* @param $vars array
|
|
|
|
* @return bool
|
2010-09-15 22:40:50 +00:00
|
|
|
*/
|
2011-03-13 10:51:45 +00:00
|
|
|
public static function resourceLoaderGetConfigVars( &$vars ) {
|
2010-09-16 21:11:46 +00:00
|
|
|
global $wgWikiEditorFeatures;
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-15 22:40:50 +00:00
|
|
|
$configurations = array();
|
2010-09-16 21:11:46 +00:00
|
|
|
foreach ( self::$features as $name => $feature ) {
|
2010-09-15 22:40:50 +00:00
|
|
|
if (
|
2010-09-16 21:11:46 +00:00
|
|
|
isset( $feature['configurations'] ) &&
|
|
|
|
( !isset( $wgWikiEditorFeatures[$name] ) || self::isEnabled( $name ) )
|
2010-09-15 22:40:50 +00:00
|
|
|
) {
|
2010-09-16 21:11:46 +00:00
|
|
|
foreach ( $feature['configurations'] as $configuration ) {
|
2010-09-15 22:40:50 +00:00
|
|
|
global $$configuration;
|
|
|
|
$configurations[$configuration] = $$configuration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( count( $configurations ) ) {
|
|
|
|
$vars = array_merge( $vars, $configurations );
|
|
|
|
}
|
2012-05-27 19:14:34 +00:00
|
|
|
//expose magic words for use by the wikieditor toolbar
|
|
|
|
WikiEditorHooks::getMagicWords( $vars );
|
2010-09-15 22:40:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2012-01-31 20:19:22 +00:00
|
|
|
/**
|
|
|
|
* @param $vars array
|
|
|
|
* @return bool
|
|
|
|
*/
|
2011-03-13 10:55:33 +00:00
|
|
|
public static function makeGlobalVariablesScript( &$vars ) {
|
|
|
|
// Build and export old-style wgWikiEditorEnabledModules object for back compat
|
|
|
|
$enabledModules = array();
|
|
|
|
foreach ( self::$features as $name => $feature ) {
|
|
|
|
$enabledModules[$name] = self::isEnabled( $name );
|
|
|
|
}
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2011-03-13 10:55:33 +00:00
|
|
|
$vars['wgWikiEditorEnabledModules'] = $enabledModules;
|
|
|
|
return true;
|
|
|
|
}
|
2012-05-27 19:14:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Expose useful magic words which are used by the wikieditor toolbar
|
|
|
|
* @param $vars array
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private static function getMagicWords( &$vars ){
|
|
|
|
$requiredMagicWords = array(
|
|
|
|
'redirect',
|
|
|
|
'img_right',
|
|
|
|
'img_left',
|
|
|
|
'img_none',
|
|
|
|
'img_center',
|
|
|
|
'img_thumbnail',
|
|
|
|
'img_framed',
|
|
|
|
'img_frameless',
|
|
|
|
);
|
|
|
|
foreach ( $requiredMagicWords as $name ) {
|
|
|
|
$magicWords[$name] = MagicWord::get( $name )->getSynonym( 0 );
|
|
|
|
}
|
|
|
|
$vars['wgWikiEditorMagicWords'] = $magicWords;
|
|
|
|
}
|
|
|
|
|
2010-11-19 13:59:34 +00:00
|
|
|
}
|