mediawiki-extensions-Visual.../VisualEditor.hooks.php
Rob Moen 3f3b525d56 Add MakeGlobalVariablesScript hook to add new global, vePageWatched.
This allows us to check the watchlist checkbox on save dialog.
Added watchlist toggling to ve save api.
Added some i18n messages to core integration.

Change-Id: Ibed8edb2c59ad49e1738c937c3bea518238d0845
2012-06-01 16:30:17 -07:00

59 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;
}
public static function makeGlobalScriptVariables( &$vars ) {
global $wgUser, $wgTitle;
$vars['vePageWatched'] = $wgUser->isWatched( $wgTitle ) ? true : false;
return true;
}
/**
*
*/
public static function namespaceProtection( &$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;
}
}