2012-05-25 19:50:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class VisualEditorHooks {
|
|
|
|
/**
|
|
|
|
* Adds VisualEditor JS to the output if in the correct namespace
|
|
|
|
*
|
|
|
|
* @param $output OutputPage
|
|
|
|
* @param $skin Skin
|
|
|
|
*/
|
|
|
|
public static function onPageDisplay( &$output, &$skin ) {
|
|
|
|
if ( self::loadVisualEditor( $output, $skin ) ) {
|
|
|
|
$output->addModules( array( 'ext.visualEditor.core' ) );
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines whether or not we should construct the loader.
|
|
|
|
*
|
|
|
|
* @param $output OutputPage
|
|
|
|
* @param $skin Skin
|
|
|
|
*/
|
|
|
|
public static function loadVisualEditor( &$output, &$skin ) {
|
2012-05-25 23:33:39 +00:00
|
|
|
global $wgTitle;
|
2012-05-25 19:50:48 +00:00
|
|
|
// Vector skin supported for now.
|
|
|
|
if ( $skin->getSkinName() !== 'vector' ) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-31 00:09:06 +00:00
|
|
|
// Be sure current page is VisualEditor:Something
|
|
|
|
if ( $wgTitle->getNamespace() !== NS_VISUALEDITOR ) {
|
2012-05-25 23:33:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-05-25 19:50:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-06-04 21:29:27 +00:00
|
|
|
public static function makeGlobalVariablesScript( &$vars ) {
|
2012-06-01 23:26:03 +00:00
|
|
|
global $wgUser, $wgTitle;
|
|
|
|
$vars['vePageWatched'] = $wgUser->isWatched( $wgTitle ) ? true : false;
|
|
|
|
return true;
|
|
|
|
}
|
2012-05-31 00:09:06 +00:00
|
|
|
/**
|
2012-05-31 23:54:53 +00:00
|
|
|
*
|
2012-05-31 00:09:06 +00:00
|
|
|
*/
|
2012-05-31 23:54:53 +00:00
|
|
|
public static function namespaceProtection( &$title, &$user, $action, &$result ){
|
2012-05-31 00:09:06 +00:00
|
|
|
global $wgUser, $wgNamespaceProtection;
|
|
|
|
|
|
|
|
if ( array_key_exists( $title->mNamespace, $wgNamespaceProtection ) ) {
|
|
|
|
$nsProt = $wgNamespaceProtection[ $title->mNamespace ];
|
2012-05-25 19:50:48 +00:00
|
|
|
|
2012-05-31 00:09:06 +00:00
|
|
|
if ( !is_array($nsProt) ) $nsProt = array($nsProt);
|
|
|
|
foreach( $nsProt as $right ) {
|
|
|
|
if( '' != $right && !$user->isAllowed( $right ) ) {
|
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-05-25 19:50:48 +00:00
|
|
|
}
|