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
|
|
|
) {
|
|
|
|
$output->addModules( array( 'ext.visualEditor.editPageInit' ) );
|
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-06-11 06:54:41 +00:00
|
|
|
|
2012-05-31 00:09:06 +00:00
|
|
|
/**
|
2012-06-11 06:54:41 +00:00
|
|
|
* Prevents editing in the VisualEditor namespace by non-sysop users.
|
|
|
|
*
|
|
|
|
* This is attached to the MediaWiki 'userCan' hook.
|
|
|
|
*/
|
|
|
|
public static function onUserCan( &$title, &$user, $action, &$result ) {
|
2012-05-31 00:09:06 +00:00
|
|
|
global $wgUser, $wgNamespaceProtection;
|
|
|
|
|
|
|
|
if ( array_key_exists( $title->mNamespace, $wgNamespaceProtection ) ) {
|
2012-06-11 06:54:41 +00:00
|
|
|
$nsProt = $wgNamespaceProtection[$title->mNamespace];
|
|
|
|
if ( !is_array( $nsProt ) ) {
|
|
|
|
$nsProt = array( $nsProt );
|
|
|
|
}
|
|
|
|
foreach( $nsProt as $right ) {
|
|
|
|
if ( $right != '' && !$user->isAllowed( $right ) ) {
|
|
|
|
$result = false;
|
2012-05-31 00:09:06 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-11 06:54:41 +00:00
|
|
|
}
|
2012-05-31 00:09:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-05-25 19:50:48 +00:00
|
|
|
}
|