[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Hooks for WikiEditor extension 4 * 5 * @file 6 * @ingroup Extensions 7 */ 8 9 class WikiEditorHooks { 10 11 /* Protected Static Members */ 12 13 protected static $features = array( 14 15 /* Toolbar Features */ 16 17 'toolbar' => array( 18 'preferences' => array( 19 // Ideally this key would be 'wikieditor-toolbar' 20 'usebetatoolbar' => array( 21 'type' => 'toggle', 22 'label-message' => 'wikieditor-toolbar-preference', 23 'section' => 'editing/editor', 24 ), 25 ), 26 'requirements' => array( 27 'usebetatoolbar' => true, 28 ), 29 'modules' => array( 30 'ext.wikiEditor.toolbar', 31 ), 32 'stylemodules' => array( 33 'ext.wikiEditor.toolbar.styles', 34 ), 35 ), 36 'dialogs' => array( 37 'preferences' => array( 38 // Ideally this key would be 'wikieditor-toolbar-dialogs' 39 'usebetatoolbar-cgd' => array( 40 'type' => 'toggle', 41 'label-message' => 'wikieditor-toolbar-dialogs-preference', 42 'section' => 'editing/editor', 43 ), 44 ), 45 'requirements' => array( 46 'usebetatoolbar-cgd' => true, 47 'usebetatoolbar' => true, 48 ), 49 'modules' => array( 50 'ext.wikiEditor.dialogs', 51 ), 52 ), 53 'hidesig' => array( 54 'preferences' => array( 55 'wikieditor-toolbar-hidesig' => array( 56 'type' => 'toggle', 57 'label-message' => 'wikieditor-toolbar-hidesig', 58 'section' => 'editing/editor', 59 ), 60 ), 61 'requirements' => array( 62 'wikieditor-toolbar-hidesig' => true, 63 'usebetatoolbar' => true, 64 ), 65 'modules' => array( 66 'ext.wikiEditor.toolbar.hideSig', 67 ), 68 ), 69 70 /* Labs Features */ 71 72 'preview' => array( 73 'preferences' => array( 74 'wikieditor-preview' => array( 75 'type' => 'toggle', 76 'label-message' => 'wikieditor-preview-preference', 77 'section' => 'editing/labs', 78 ), 79 ), 80 'requirements' => array( 81 'wikieditor-preview' => true, 82 ), 83 'modules' => array( 84 'ext.wikiEditor.preview', 85 ), 86 ), 87 'previewDialog' => array( 88 'preferences' => array( 89 'wikieditor-previewDialog' => array( 90 'type' => 'toggle', 91 'label-message' => 'wikieditor-previewDialog-preference', 92 'section' => 'editing/labs', 93 ), 94 ), 95 'requirements' => array( 96 'wikieditor-previewDialog' => true, 97 ), 98 'modules' => array( 99 'ext.wikiEditor.previewDialog', 100 ), 101 ), 102 'publish' => array( 103 'preferences' => array( 104 'wikieditor-publish' => array( 105 'type' => 'toggle', 106 'label-message' => 'wikieditor-publish-preference', 107 'section' => 'editing/labs', 108 ), 109 ), 110 'requirements' => array( 111 'wikieditor-publish' => true, 112 ), 113 'modules' => array( 114 'ext.wikiEditor.publish', 115 ), 116 ) 117 ); 118 119 /* Static Methods */ 120 121 /** 122 * Checks if a certain option is enabled 123 * 124 * This method is public to allow other extensions that use WikiEditor to use the 125 * same configuration as WikiEditor itself 126 * 127 * @param $name string Name of the feature, should be a key of $features 128 * @return bool 129 */ 130 public static function isEnabled( $name ) { 131 global $wgWikiEditorFeatures, $wgUser; 132 133 // Features with global set to true are always enabled 134 if ( !isset( $wgWikiEditorFeatures[$name] ) || $wgWikiEditorFeatures[$name]['global'] ) { 135 return true; 136 } 137 // Features with user preference control can have any number of preferences to be specific values to be enabled 138 if ( $wgWikiEditorFeatures[$name]['user'] ) { 139 if ( isset( self::$features[$name]['requirements'] ) ) { 140 foreach ( self::$features[$name]['requirements'] as $requirement => $value ) { 141 // Important! We really do want fuzzy evaluation here 142 if ( $wgUser->getOption( $requirement ) != $value ) { 143 return false; 144 } 145 } 146 } 147 return true; 148 } 149 // Features controlled by $wgWikiEditorFeatures with both global and user set to false are awlways disabled 150 return false; 151 } 152 153 /** 154 * EditPage::showEditForm:initial hook 155 * 156 * Adds the modules to the edit form 157 * 158 * @param $editPage EditPage the current EditPage object. 159 * @param $output OutputPage object. 160 * @return bool 161 */ 162 public static function editPageShowEditFormInitial( $editPage, $outputPage ) { 163 if ( $editPage->contentModel !== CONTENT_MODEL_WIKITEXT ) { 164 return true; 165 } 166 167 // Add modules for enabled features 168 foreach ( self::$features as $name => $feature ) { 169 if ( !self::isEnabled( $name ) ) { 170 continue; 171 } 172 if ( isset( $feature['stylemodules'] ) ) { 173 $outputPage->addModuleStyles( $feature['stylemodules'] ); 174 } 175 if ( isset( $feature['modules'] ) ) { 176 $outputPage->addModules( $feature['modules'] ); 177 } 178 } 179 return true; 180 } 181 182 /** 183 * EditPageBeforeEditToolbar hook 184 * 185 * Disable the old toolbar if the new one is enabled 186 * 187 * @param $toolbar html 188 * @return bool 189 */ 190 public static function EditPageBeforeEditToolbar( &$toolbar ) { 191 if ( self::isEnabled( 'toolbar' ) ) { 192 $toolbar = Html::rawElement( 193 'div', array( 194 'class' => 'wikiEditor-oldToolbar' 195 ), 196 $toolbar 197 ); 198 } 199 return true; 200 } 201 202 /** 203 * GetPreferences hook 204 * 205 * Adds WikiEditor-releated items to the preferences 206 * 207 * @param $user User current user 208 * @param $defaultPreferences array list of default user preference controls 209 * @return bool 210 */ 211 public static function getPreferences( $user, &$defaultPreferences ) { 212 global $wgWikiEditorFeatures; 213 214 foreach ( self::$features as $name => $feature ) { 215 if ( 216 isset( $feature['preferences'] ) && 217 ( !isset( $wgWikiEditorFeatures[$name] ) || $wgWikiEditorFeatures[$name]['user'] ) 218 ) { 219 foreach ( $feature['preferences'] as $key => $options ) { 220 $defaultPreferences[$key] = $options; 221 } 222 } 223 } 224 return true; 225 } 226 227 /** 228 * MakeGlobalVariablesScript hook 229 * 230 * Adds enabled/disabled switches for WikiEditor modules 231 * @param $vars array 232 * @return bool 233 */ 234 public static function resourceLoaderGetConfigVars( &$vars ) { 235 global $wgWikiEditorFeatures; 236 237 $configurations = array(); 238 foreach ( self::$features as $name => $feature ) { 239 if ( 240 isset( $feature['configurations'] ) && 241 ( !isset( $wgWikiEditorFeatures[$name] ) || self::isEnabled( $name ) ) 242 ) { 243 foreach ( $feature['configurations'] as $configuration ) { 244 global $$configuration; 245 $configurations[$configuration] = $$configuration; 246 } 247 } 248 } 249 if ( count( $configurations ) ) { 250 $vars = array_merge( $vars, $configurations ); 251 } 252 //expose magic words for use by the wikieditor toolbar 253 WikiEditorHooks::getMagicWords( $vars ); 254 return true; 255 } 256 257 /** 258 * @param $vars array 259 * @return bool 260 */ 261 public static function makeGlobalVariablesScript( &$vars ) { 262 // Build and export old-style wgWikiEditorEnabledModules object for back compat 263 $enabledModules = array(); 264 foreach ( self::$features as $name => $feature ) { 265 $enabledModules[$name] = self::isEnabled( $name ); 266 } 267 268 $vars['wgWikiEditorEnabledModules'] = $enabledModules; 269 return true; 270 } 271 272 /** 273 * Expose useful magic words which are used by the wikieditor toolbar 274 * @param $vars array 275 * @return bool 276 */ 277 private static function getMagicWords( &$vars ){ 278 $requiredMagicWords = array( 279 'redirect', 280 'img_right', 281 'img_left', 282 'img_none', 283 'img_center', 284 'img_thumbnail', 285 'img_framed', 286 'img_frameless', 287 ); 288 foreach ( $requiredMagicWords as $name ) { 289 $magicWords[$name] = MagicWord::get( $name )->getSynonym( 0 ); 290 } 291 $vars['wgWikiEditorMagicWords'] = $magicWords; 292 } 293 294 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |