2012-05-25 19:50:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class VisualEditorHooks {
|
|
|
|
/**
|
2012-06-11 06:54:41 +00:00
|
|
|
* Adds VisualEditor JS to the output if in the correct namespace.
|
|
|
|
*
|
|
|
|
* This is attached to the MediaWiki 'BeforePageDisplay' hook.
|
2012-05-25 19:50:48 +00:00
|
|
|
*
|
|
|
|
* @param $output OutputPage
|
|
|
|
* @param $skin Skin
|
|
|
|
*/
|
2012-06-11 06:54:41 +00:00
|
|
|
public static function onBeforePageDisplay( &$output, &$skin ) {
|
|
|
|
global $wgTitle;
|
|
|
|
if (
|
|
|
|
// Vector skin supported for now.
|
|
|
|
$skin->getSkinName() === 'vector' &&
|
2012-06-18 21:13:26 +00:00
|
|
|
(
|
|
|
|
// Article in the VisualEditor namespace
|
|
|
|
$wgTitle->getNamespace() === NS_VISUALEDITOR ||
|
|
|
|
// Special page action for an article in the VisualEditor namespace
|
|
|
|
$skin->getRelevantTitle()->getNamespace() === NS_VISUALEDITOR
|
|
|
|
)
|
2012-06-11 06:54:41 +00:00
|
|
|
) {
|
2012-06-28 09:52:03 +00:00
|
|
|
$output->addModules( array( 'ext.visualEditor.viewPageTarget' ) );
|
2012-05-25 19:50:48 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-11 06:54:41 +00:00
|
|
|
* Adds extra variables to the page config.
|
2012-05-25 19:50:48 +00:00
|
|
|
*
|
2012-06-11 06:54:41 +00:00
|
|
|
* This is attached to the MediaWiki 'MakeGlobalVariablesScript' hook.
|
2012-05-25 19:50:48 +00:00
|
|
|
*/
|
2012-06-11 06:54:41 +00:00
|
|
|
public static function onMakeGlobalVariablesScript( &$vars ) {
|
2012-06-01 23:26:03 +00:00
|
|
|
global $wgUser, $wgTitle;
|
2012-06-11 06:54:41 +00:00
|
|
|
$vars['wgVisualEditor'] = array(
|
|
|
|
'isPageWatched' => $wgUser->isWatched( $wgTitle )
|
|
|
|
);
|
2012-06-01 23:26:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-05-25 19:50:48 +00:00
|
|
|
}
|