mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
3112448bde
This shuts up a strict standards notice Change-Id: I59ce775169965531dd10051418c927b769613abb
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?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 ) {
|
|
global $wgTitle;
|
|
// Vector skin supported for now.
|
|
if ( $skin->getSkinName() !== 'vector' ) {
|
|
return false;
|
|
}
|
|
// Be sure current page is VisualEditor:Something
|
|
if ( $wgTitle->getNamespace() !== NS_VISUALEDITOR ) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
/**
|
|
* Allow edits to the namespace only by admins
|
|
* Code used from Extension:NamespaceProtection
|
|
*/
|
|
public static function canUserEditPage( &$title, &$user, $action, &$result ){
|
|
global $wgUser, $wgNamespaceProtection;
|
|
|
|
if ( array_key_exists( $title->mNamespace, $wgNamespaceProtection ) ) {
|
|
$nsProt = $wgNamespaceProtection[ $title->mNamespace ];
|
|
|
|
if ( !is_array($nsProt) ) $nsProt = array($nsProt);
|
|
foreach( $nsProt as $right ) {
|
|
if( '' != $right && !$user->isAllowed( $right ) ) {
|
|
$result = false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|