Skip to content

Instantly share code, notes, and snippets.

@junaidpv
Created March 23, 2011 14:11
Show Gist options
  • Save junaidpv/883137 to your computer and use it in GitHub Desktop.
Save junaidpv/883137 to your computer and use it in GitHub Desktop.
<?php
/**
* Hooks for Narayam extension
* @file
* @ingroup Extensions
*/
class NarayamHooks {
protected static $disabled = false;
public static function addModules($out, $skin) {
global $wgUser;
self::$disabled = (bool) $wgUser->getOption('narayamDisable');
if (self::$disabled) {
return false;
}
$schemes = array_values(self::getSchemes ());
if (count($schemes)) {
$out->addModules($schemes);
$out->addModules('ext.narayam');
}
return true;
}
public static function addConfig(&$vars) {
global $wgNarayamEnabledByDefault, $wgNarayamShortcutKey;
$vars['wgNarayamEnabledByDefault'] = $wgNarayamEnabledByDefault;
$vars['wgNarayamShortcutKey'] = $wgNarayamShortcutKey;
return true;
}
public static function addVariables(&$vars) {
$vars['wgNarayamAvailableSchemes'] = self::getSchemes(); // Note: scheme names must be keys, not values
return true;
}
/**
* Get the available schemes for the user and content language
* @return array( scheme name => module name )
*/
protected static function getSchemes() {
global $wgLanguageCode, $wgLang, $wgNarayamSchemes;
$userlangCode = $wgLang->getCode();
$contlangSchemes = isset($wgNarayamSchemes[$wgLanguageCode]) ?
$wgNarayamSchemes[$wgLanguageCode] : array();
$userlangSchemes = isset($wgNarayamSchemes[$userlangCode]) ?
$wgNarayamSchemes[$userlangCode] : array();
return $userlangSchemes + $contlangSchemes;
}
public static function addPreference($user, &$preferences) {
// A checkbox to diable Narayam
$preferences['narayamDisable'] = array(
'type' => 'toggle',
'label-message' => 'naryam-disable-preference', // a system message
'section' => 'personal/info',
);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment