/**
  * The preferences plugin callback
  * @param string $sAdapterName
  * @param BsConfig $oVariable
  * @return array MediaWiki preferences options array
  */
 public function runPreferencePlugin($sAdapterName, $oVariable)
 {
     $aPrefs = array();
     switch ($oVariable->getName()) {
         case 'WidgetNS':
             $aPrefs = array('type' => 'multiselectex', 'options' => BsNamespaceHelper::getNamespacesForSelectOptions(array(-2, NS_MEDIA, NS_MEDIAWIKI, NS_MEDIAWIKI_TALK, NS_SPECIAL)));
             break;
         case 'WidgetSortOdr':
             $aPrefs = array('options' => array(wfMessage('bs-pagesvisited-pref-sort-time')->plain() => 'time', wfMessage('bs-pagesvisited-pref-sort-pagename')->plain() => 'pagename'));
             break;
         default:
             break;
     }
     return $aPrefs;
 }
 /**
  * Adds Notifications preferences to the echo section
  * @param User $user
  * @param array $preferences
  * @return boolean
  */
 public function onGetPreferences($user, array &$preferences)
 {
     $preferences['MW::Notifications::NotifyNoMinor'] = array('type' => 'toggle', 'label-message' => 'bs-notifications-pref-notifynominor', 'section' => 'echo/echo-extended');
     $preferences['MW::Notifications::Active'] = array('type' => 'toggle', 'label-message' => 'bs-notifications-pref-active', 'section' => 'echo/echo-extended');
     // ugly workaraound for mw's handling of get default options from multivaluefields
     $sNotifyDefault = $user->getOption('MW::Notifications::NotifyNS', false) ? $user->getOption('MW::Notifications::NotifyNS') : array(0);
     $preferences['MW::Notifications::NotifyNS'] = array('type' => 'multiselectex', 'label-message' => 'bs-notifications-pref-notifyns', 'section' => 'echo/echo-extended', 'options' => BsNamespaceHelper::getNamespacesForSelectOptions(array(NS_SPECIAL, NS_MEDIA)), 'default' => $sNotifyDefault);
     return true;
 }
 /**
  * Sets parameters for more complex options in preferences
  * @param string $sAdapterName Name of the adapter, e.g. MW
  * @param BsConfig $oVariable Instance of variable
  * @return array Preferences options
  */
 public function runPreferencePlugin($sAdapterName, $oVariable)
 {
     $aPrefs = array();
     if ($oVariable->getName() === 'DefScopeUser') {
         $aPrefs = array('options' => array(wfMessage('bs-extendedsearch-pref-scope-text')->plain() => 'text', wfMessage('bs-extendedsearch-pref-scope-title')->plain() => 'title'));
     } elseif ($oVariable->getName() === 'MltNS') {
         $aPrefs = array('type' => 'multiselectex', 'options' => BsNamespaceHelper::getNamespacesForSelectOptions(array(NS_SPECIAL, NS_MEDIA)));
     }
     return $aPrefs;
 }
 public function buildLinksNs()
 {
     $oUser = $this->getUser();
     $set = new ViewFormElementFieldset();
     $set->setLabel(wfMessage('bs-blog-blog')->plain());
     $select = new ViewFormElementSelectbox();
     $select->setId('selFeedNsBlog');
     $select->setName('selFeedNsBlog');
     $select->setLabel(wfMessage('bs-ns')->plain());
     $aNamespacesTemp = BsNamespaceHelper::getNamespacesForSelectOptions(array(NS_SPECIAL, NS_MEDIA, NS_BLOG, NS_BLOG_TALK, NS_FILE));
     $aNamespaces = array();
     foreach ($aNamespacesTemp as $index => $name) {
         if ($index % 2 == 0) {
             $aNamespaces[$index] = $name;
         }
     }
     $oSpecialRSS = SpecialPage::getTitleFor('RSSFeeder');
     $sUserName = $oUser->getName();
     $sUserToken = $oUser->getToken();
     foreach ($aNamespaces as $key => $name) {
         $select->addData(array('value' => $oSpecialRSS->getLinkUrl(array('Page' => 'blog', 'ns' => $key, 'u' => $sUserName, 'h' => $sUserToken)), 'label' => $name));
     }
     $btn = new ViewFormElementButton();
     $btn->setId('btnFeedNsBlog');
     $btn->setName('btnFeedNsBlog');
     $btn->setType('button');
     $btn->setLabel(wfMessage('bs-rssfeeder-submit')->plain());
     $set->addItem($select);
     $set->addItem($btn);
     return $set;
 }
 /**
  * Sets parameters for more complex options in preferences
  * @param string $sAdapterName Name of the adapter, e.g. MW
  * @param BsConfig $oVariable Instance of variable
  * @return array Preferences options
  */
 public function runPreferencePlugin($sAdapterName, $oVariable)
 {
     switch ($oVariable->getName()) {
         case 'ActivatedNamespaces':
             $aPrefs = array('type' => 'multiselectex', 'options' => BsNamespaceHelper::getNamespacesForSelectOptions(array(-2, -1)));
             break;
         case 'AutoPermissions':
             global $wgGroupPermissions;
             $aAvailablePermissions = array();
             foreach ($wgGroupPermissions as $sGroup => $aPermissions) {
                 foreach ($aPermissions as $sName => $bValue) {
                     if (!in_array($sName, WikiAdmin::get('ExcludeRights'))) {
                         $aAvailablePermissions[$sName] = $sName;
                     }
                 }
             }
             natsort($aAvailablePermissions);
             $aPrefs = array('type' => 'multiselectex', 'options' => array_unique($aAvailablePermissions));
             break;
     }
     return $aPrefs;
 }
 public static function ajaxGetNamespaceFilter()
 {
     $aResult = array("success" => false, "errors" => array(), "message" => '', "data" => array());
     global $wgUser;
     if (!$wgUser->isAllowed('read')) {
         $aResult["message"] = wfMessage('bs-statistics-not-allowed')->plain();
         return json_encode($aResult);
     }
     foreach (BsNamespaceHelper::getNamespacesForSelectOptions(array(-2, -1)) as $key => $name) {
         $aResult['data'][] = array('key' => $key, 'displaytitle' => $name);
     }
     $aResult['success'] = true;
     return json_encode($aResult);
 }
 /**
  * Sets parameters for more complex options in preferences
  * @param string $sAdapterName Name of the adapter, e.g. MW
  * @param BsConfig $oVariable Instance of variable
  * @return array Preferences options
  */
 public function runPreferencePlugin($sAdapterName, $oVariable)
 {
     wfProfileIn('BS::' . __METHOD__);
     $aPrefs = array();
     switch ($oVariable->getName()) {
         case 'disableNS':
             global $wgContLang;
             $aExcludeNmsps = BsConfig::get('MW::VisualEditor::defaultNoContextNS');
             foreach ($wgContLang->getNamespaces() as $sNamespace) {
                 $iNsIndex = $wgContLang->getNsIndex($sNamespace);
                 if (!MWNamespace::isTalk($iNsIndex)) {
                     continue;
                 }
                 $aExcludeNmsps[] = $iNsIndex;
             }
             $aPrefs['type'] = 'multiselectex';
             $aPrefs['options'] = BsNamespaceHelper::getNamespacesForSelectOptions($aExcludeNmsps);
             break;
         default:
     }
     wfProfileOut('BS::' . __METHOD__);
     return $aPrefs;
 }
 public function buildLinksNs()
 {
     global $wgUser;
     $set = new ViewFormElementFieldset();
     $set->setLabel(wfMessage('bs-ns')->plain());
     $select = new ViewFormElementSelectbox();
     $select->setId('selFeedNs');
     $select->setName('selFeedNs');
     $select->setLabel(wfMessage('bs-ns')->plain());
     $aNamespaces = BsNamespaceHelper::getNamespacesForSelectOptions(array(NS_SPECIAL, NS_MEDIA));
     $oSpecialRSS = SpecialPage::getTitleFor('RSSFeeder');
     $sUserName = $wgUser->getName();
     $sUserToken = $wgUser->getToken();
     foreach ($aNamespaces as $key => $name) {
         $select->addData(array('value' => $oSpecialRSS->getLinkUrl(array('Page' => 'namespace', 'ns' => $key, 'u' => $sUserName, 'h' => $sUserToken)), 'label' => $name));
     }
     $btn = new ViewFormElementButton();
     $btn->setId('btnFeedNs');
     $btn->setName('btnFeedNs');
     $btn->setType('button');
     $btn->setLabel(wfMessage('bs-rssfeeder-submit')->plain());
     $set->addItem($select);
     $set->addItem($btn);
     return $set;
 }
 /**
  * Dynamically retrieves a list of all categories
  * @return array List of strings
  */
 public function loadAvailableValues()
 {
     return BsNamespaceHelper::getNamespacesForSelectOptions(array(-2, -1));
 }
 public static function setupLockmodePermissions()
 {
     global $wgAdditionalGroups, $wgGroupPermissions, $wgNamespacePermissionLockdown;
     // return directly if the settings got already checked in this session and the state of Lockmode didn't change.
     $oRequest = RequestContext::getMain()->getRequest();
     $bLockmodeActive = BsConfig::get('MW::PermissionManager::Lockmode');
     if ($oRequest->getSessionData('bsLockmodeIsSetup') === $bLockmodeActive) {
         return true;
     }
     $oRequest->setSessionData('bsLockmodeIsSetup', $bLockmodeActive);
     $bSave = false;
     if (!$bLockmodeActive) {
         if (isset($wgGroupPermissions[self::$sPmLockModeGroup]) && !empty($wgGroupPermissions[self::$sPmLockModeGroup])) {
             unset($wgGroupPermissions[self::$sPmLockModeGroup]);
             $bSave = true;
         }
         if (is_array($wgNamespacePermissionLockdown)) {
             foreach ($wgNamespacePermissionLockdown as $iNsIndex => $aNsRights) {
                 foreach ($aNsRights as $sRight => $aGroups) {
                     if (!in_array(self::$sPmLockModeGroup, $aGroups)) {
                         continue;
                     }
                     $key = array_search(self::$sPmLockModeGroup, $aGroups);
                     if ($key !== false) {
                         unset($wgNamespacePermissionLockdown[$iNsIndex][$sRight][$key]);
                         if (empty($wgNamespacePermissionLockdown[$iNsIndex][$sRight])) {
                             unset($wgNamespacePermissionLockdown[$iNsIndex][$sRight]);
                         }
                         $bSave = true;
                     }
                 }
                 if (empty($wgNamespacePermissionLockdown[$iNsIndex])) {
                     unset($wgNamespacePermissionLockdown[$iNsIndex]);
                 }
             }
         }
         if ($bSave) {
             self::writeGroupSettings($wgGroupPermissions, $wgNamespacePermissionLockdown);
         }
         return true;
     }
     $wgAdditionalGroups[self::$sPmLockModeGroup] = array();
     foreach (BsNamespaceHelper::getNamespacesForSelectOptions(array(NS_MEDIA, NS_SPECIAL)) as $nsKey => $nsName) {
         // skip mediawiki namespaces
         if (BsConfig::get('MW::PermissionManager::SkipSystemNS') && $nsKey <= 15) {
             continue;
         }
         if (!isset($wgGroupPermissions[self::$sPmLockModeGroup])) {
             $wgGroupPermissions[self::$sPmLockModeGroup] = array();
         }
         $aAvailablePermissions = User::getAllRights();
         foreach ($aAvailablePermissions as $permissionName) {
             if (!isset($wgGroupPermissions[self::$sPmLockModeGroup][$permissionName])) {
                 $wgGroupPermissions[self::$sPmLockModeGroup][$permissionName] = true;
                 $bSave = true;
             }
             if (isset($wgNamespacePermissionLockdown[$nsKey][$permissionName])) {
                 if (!in_array(self::$sPmLockModeGroup, $wgNamespacePermissionLockdown[$nsKey][$permissionName])) {
                     $wgNamespacePermissionLockdown[$nsKey][$permissionName] = array_unique(array_merge($wgNamespacePermissionLockdown[$nsKey][$permissionName], array(self::$sPmLockModeGroup)));
                     $bSave = true;
                 }
             } else {
                 $wgNamespacePermissionLockdown[$nsKey][$permissionName] = array(self::$sPmLockModeGroup);
                 $bSave = true;
             }
         }
     }
     if ($bSave) {
         self::writeGroupSettings($wgGroupPermissions, $wgNamespacePermissionLockdown);
     }
     return true;
 }