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-05-31 00:09:06 +00:00
|
|
|
/**
|
|
|
|
* Allow edits to the namespace only by admins
|
|
|
|
* Code used from Extension:NamespaceProtection
|
|
|
|
*/
|
2012-05-31 09:41:21 +00:00
|
|
|
public static function canUserEditPage( &$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
|
|
|
}
|