mediawiki-extensions-Visual.../VisualEditor.hooks.php
Trevor Parscal 9a0380c67d Removed Special:VisualEditorSandbox and refactored demo
Also renamed ext.visualEditor.editPageInit to
ext.visualEditor.viewPageTarget

Change-Id: I8bdd04b3442067e87bccbc60dd4947aae1c7dfd2
2012-07-18 17:57:50 -07:00

42 lines
1.1 KiB
PHP

<?php
class VisualEditorHooks {
/**
* Adds VisualEditor JS to the output if in the correct namespace.
*
* This is attached to the MediaWiki 'BeforePageDisplay' hook.
*
* @param $output OutputPage
* @param $skin Skin
*/
public static function onBeforePageDisplay( &$output, &$skin ) {
global $wgTitle;
if (
// Vector skin supported for now.
$skin->getSkinName() === 'vector' &&
(
// Article in the VisualEditor namespace
$wgTitle->getNamespace() === NS_VISUALEDITOR ||
// Special page action for an article in the VisualEditor namespace
$skin->getRelevantTitle()->getNamespace() === NS_VISUALEDITOR
)
) {
$output->addModules( array( 'ext.visualEditor.viewPageTarget' ) );
}
return true;
}
/**
* Adds extra variables to the page config.
*
* This is attached to the MediaWiki 'MakeGlobalVariablesScript' hook.
*/
public static function onMakeGlobalVariablesScript( &$vars ) {
global $wgUser, $wgTitle;
$vars['wgVisualEditor'] = array(
'isPageWatched' => $wgUser->isWatched( $wgTitle )
);
return true;
}
}