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
|
2010-09-15 22:40:50 +00:00
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
*/
|
|
|
|
|
|
|
|
class WikiEditorHooks {
|
|
|
|
|
2010-09-16 23:41:08 +00:00
|
|
|
/* Protected Static Members */
|
2010-09-15 22:40:50 +00:00
|
|
|
|
2010-09-16 23:41:08 +00:00
|
|
|
protected static $features = array(
|
2010-09-16 21:11:46 +00:00
|
|
|
|
|
|
|
/* Beta Features */
|
|
|
|
|
|
|
|
'toolbar' => array(
|
|
|
|
'preferences' => array(
|
|
|
|
// Ideally this key would be 'wikieditor-toolbar'
|
|
|
|
'usebetatoolbar' => array(
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'wikieditor-toolbar-preference',
|
|
|
|
'section' => 'editing/beta',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'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(
|
|
|
|
'preferences' => array(
|
|
|
|
// Ideally this key would be 'wikieditor-toolbar-dialogs'
|
|
|
|
'usebetatoolbar-cgd' => array(
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'wikieditor-toolbar-dialogs-preference',
|
|
|
|
'section' => 'editing/beta',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'requirements' => array(
|
|
|
|
'usebetatoolbar-cgd' => true,
|
|
|
|
),
|
|
|
|
'modules' => array(
|
2010-09-20 20:06:18 +00:00
|
|
|
'ext.wikiEditor.dialogs',
|
2010-09-16 21:11:46 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
/* Labs Features */
|
|
|
|
|
2010-09-15 22:40:50 +00:00
|
|
|
'templateEditor' => array(
|
2010-09-16 21:11:46 +00:00
|
|
|
'preferences' => array(
|
|
|
|
'wikieditor-template-editor' => array(
|
2010-09-15 22:40:50 +00:00
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'wikieditor-template-editor-preference',
|
|
|
|
'section' => 'editing/labs',
|
|
|
|
),
|
|
|
|
),
|
2010-09-16 21:11:46 +00:00
|
|
|
'requirements' => array(
|
|
|
|
'wikieditor-template-editor' => true,
|
|
|
|
),
|
|
|
|
'modules' => array(
|
2010-09-20 20:06:18 +00:00
|
|
|
'ext.wikiEditor.templateEditor',
|
2010-09-16 21:11:46 +00:00
|
|
|
),
|
2010-09-15 22:40:50 +00:00
|
|
|
),
|
|
|
|
'templates' => array(
|
2010-09-16 21:11:46 +00:00
|
|
|
'preferences' => array(
|
|
|
|
'wikieditor-templates' => array(
|
2010-09-15 22:40:50 +00:00
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'wikieditor-templates-preference',
|
|
|
|
'section' => 'editing/labs',
|
|
|
|
),
|
|
|
|
),
|
2010-09-16 21:11:46 +00:00
|
|
|
'requirements' => array(
|
|
|
|
'wikieditor-templates' => true,
|
|
|
|
),
|
|
|
|
'modules' => array(
|
2010-09-20 20:06:18 +00:00
|
|
|
'ext.wikiEditor.templates',
|
2010-09-16 21:11:46 +00:00
|
|
|
),
|
2010-09-15 22:40:50 +00:00
|
|
|
),
|
|
|
|
'addMediaWizard' => array(
|
2010-09-16 21:11:46 +00:00
|
|
|
'preferences' => array(
|
|
|
|
'addmediawizard-gadget' => array(
|
2010-09-15 22:40:50 +00:00
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'wikieditor-addMediaWizard-preference',
|
|
|
|
'section' => 'editing/labs',
|
|
|
|
),
|
|
|
|
),
|
2010-09-16 21:11:46 +00:00
|
|
|
'requirements' => array(
|
|
|
|
'addmediawizard-gadget' => true,
|
|
|
|
),
|
|
|
|
'modules' => array(
|
2010-09-20 20:06:18 +00:00
|
|
|
'ext.wikiEditor.addMediaWizard',
|
2010-09-16 21:11:46 +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
|
|
|
),
|
2010-09-15 22:40:50 +00:00
|
|
|
),
|
|
|
|
'toc' => array(
|
2010-09-16 21:11:46 +00:00
|
|
|
'preferences' => array(
|
2010-09-15 22:40:50 +00:00
|
|
|
// Ideally this key would be 'wikieditor-toc'
|
2010-09-16 21:11:46 +00:00
|
|
|
'usenavigabletoc' => array(
|
2010-09-15 22:40:50 +00:00
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'wikieditor-toc-preference',
|
|
|
|
'section' => 'editing/labs',
|
|
|
|
),
|
|
|
|
),
|
2010-09-16 21:11:46 +00:00
|
|
|
'requirements' => array(
|
|
|
|
'usenavigabletoc' => true,
|
|
|
|
),
|
|
|
|
'modules' => array(
|
2010-09-20 20:06:18 +00:00
|
|
|
'ext.wikiEditor.toc',
|
2010-09-16 21:11:46 +00:00
|
|
|
),
|
2010-09-15 22:40:50 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
/* Protected Static Methods */
|
|
|
|
|
2010-09-16 21:11:46 +00:00
|
|
|
protected static function isEnabled( $name ) {
|
|
|
|
global $wgWikiEditorFeatures, $wgUser;
|
2010-09-15 22:40:50 +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
|
|
|
}
|
2010-09-16 21:11:46 +00:00
|
|
|
// Features controlled by $wgWikiEditorFeatures with both global and user set to false are awlways disabled
|
|
|
|
return false;
|
2010-09-15 22:40:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Static Methods */
|
|
|
|
|
|
|
|
/**
|
2010-09-16 21:11:46 +00:00
|
|
|
* EditPage::showEditForm:initial hook
|
2010-09-15 22:40:50 +00:00
|
|
|
*
|
|
|
|
* Adds the modules to the edit form
|
|
|
|
*
|
2010-09-16 23:41:08 +00:00
|
|
|
* @param $toolbar array list of toolbar items
|
2010-09-15 22:40:50 +00:00
|
|
|
*/
|
2010-09-16 21:11:46 +00:00
|
|
|
public static function editPageShowEditFormInitial( &$toolbar ) {
|
|
|
|
global $wgOut;
|
2010-09-15 22:40:50 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetPreferences hook
|
|
|
|
*
|
2010-10-01 18:15:10 +00:00
|
|
|
* Adds WikiEditor-releated items to the preferences
|
2010-09-15 22:40:50 +00:00
|
|
|
*
|
|
|
|
* @param $out User current user
|
|
|
|
* @param $skin array list of default user preference controls
|
|
|
|
*/
|
|
|
|
public static function getPreferences( $user, &$defaultPreferences ) {
|
2010-09-16 21:11:46 +00:00
|
|
|
global $wgWikiEditorFeatures;
|
2010-09-15 22:40:50 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MakeGlobalVariablesScript hook
|
|
|
|
*
|
2010-10-01 18:15:10 +00:00
|
|
|
* Adds enabled/disabled switches for WikiEditor modules
|
2010-09-15 22:40:50 +00:00
|
|
|
*/
|
|
|
|
public static function makeGlobalVariablesScript( &$vars ) {
|
2010-09-16 21:11:46 +00:00
|
|
|
global $wgWikiEditorFeatures;
|
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 );
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2010-11-19 13:59:34 +00:00
|
|
|
}
|