Ejemplo n.º 1
0
 /**
  * @param User $user The User object
  * @param IContextSource $context
  * @return array Text/links to display as key; $skinkey as value
  */
 static function generateSkinOptions($user, IContextSource $context)
 {
     $ret = array();
     $mptitle = Title::newMainPage();
     $previewtext = $context->msg('skin-preview')->escaped();
     # Only show skins that aren't disabled in $wgSkipSkins
     $validSkinNames = Skin::getAllowedSkins();
     # Sort by UI skin name. First though need to update validSkinNames as sometimes
     # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
     foreach ($validSkinNames as $skinkey => &$skinname) {
         $msg = $context->msg("skinname-{$skinkey}");
         if ($msg->exists()) {
             $skinname = htmlspecialchars($msg->text());
         }
     }
     asort($validSkinNames);
     $config = $context->getConfig();
     $defaultSkin = $config->get('DefaultSkin');
     $allowUserCss = $config->get('AllowUserCss');
     $allowUserJs = $config->get('AllowUserJs');
     $foundDefault = false;
     foreach ($validSkinNames as $skinkey => $sn) {
         $linkTools = array();
         # Mark the default skin
         if (strcasecmp($skinkey, $defaultSkin) === 0) {
             $linkTools[] = $context->msg('default')->escaped();
             $foundDefault = true;
         }
         # Create preview link
         $mplink = htmlspecialchars($mptitle->getLocalURL(array('useskin' => $skinkey)));
         $linkTools[] = "<a target='_blank' href=\"{$mplink}\">{$previewtext}</a>";
         # Create links to user CSS/JS pages
         if ($allowUserCss) {
             $cssPage = Title::makeTitleSafe(NS_USER, $user->getName() . '/' . $skinkey . '.css');
             $linkTools[] = Linker::link($cssPage, $context->msg('prefs-custom-css')->escaped());
         }
         if ($allowUserJs) {
             $jsPage = Title::makeTitleSafe(NS_USER, $user->getName() . '/' . $skinkey . '.js');
             $linkTools[] = Linker::link($jsPage, $context->msg('prefs-custom-js')->escaped());
         }
         $display = $sn . ' ' . $context->msg('parentheses')->rawParams($context->getLanguage()->pipeList($linkTools))->escaped();
         $ret[$display] = $skinkey;
     }
     if (!$foundDefault) {
         // If the default skin is not available, things are going to break horribly because the
         // default value for skin selector will not be a valid value. Let's just not show it then.
         return array();
     }
     return $ret;
 }
Ejemplo n.º 2
0
 public function appendSkins($property)
 {
     $data = array();
     $allowed = Skin::getAllowedSkins();
     $default = Skin::normalizeKey('default');
     foreach (Skin::getSkinNames() as $name => $displayName) {
         $msg = $this->msg("skinname-{$name}");
         $code = $this->getParameter('inlanguagecode');
         if ($code && Language::isValidCode($code)) {
             $msg->inLanguage($code);
         } else {
             $msg->inContentLanguage();
         }
         if ($msg->exists()) {
             $displayName = $msg->text();
         }
         $skin = array('code' => $name);
         ApiResult::setContentValue($skin, 'name', $displayName);
         if (!isset($allowed[$name])) {
             $skin['unusable'] = true;
         }
         if ($name === $default) {
             $skin['default'] = true;
         }
         $data[] = $skin;
     }
     ApiResult::setIndexedTagName($data, 'skin');
     return $this->getResult()->addValue('query', $property, $data);
 }
Ejemplo n.º 3
0
 public function appendSkins($property)
 {
     $data = array();
     $allowed = Skin::getAllowedSkins();
     $default = Skin::normalizeKey('default');
     foreach (Skin::getSkinNames() as $name => $displayName) {
         $skin = array('code' => $name);
         ApiResult::setContent($skin, $displayName);
         if (!isset($allowed[$name])) {
             $skin['unusable'] = '';
         }
         if ($name === $default) {
             $skin['default'] = '';
         }
         $data[] = $skin;
     }
     $this->getResult()->setIndexedTagName($data, 'skin');
     return $this->getResult()->addValue('query', $property, $data);
 }
Ejemplo n.º 4
0
 /**
  * @param $user User The User object
  * @param $context IContextSource
  * @return Array: text/links to display as key; $skinkey as value
  */
 static function generateSkinOptions($user, IContextSource $context)
 {
     global $wgDefaultSkin, $wgAllowUserCss, $wgAllowUserJs;
     $ret = array();
     $mptitle = Title::newMainPage();
     $previewtext = $context->msg('skin-preview')->text();
     # Only show skins that aren't disabled in $wgSkipSkins
     $validSkinNames = Skin::getAllowedSkins();
     # Sort by UI skin name. First though need to update validSkinNames as sometimes
     # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
     foreach ($validSkinNames as $skinkey => &$skinname) {
         $msg = $context->msg("skinname-{$skinkey}");
         if ($msg->exists()) {
             $skinname = htmlspecialchars($msg->text());
         }
     }
     asort($validSkinNames);
     foreach ($validSkinNames as $skinkey => $sn) {
         $linkTools = array();
         # Mark the default skin
         if ($skinkey == $wgDefaultSkin) {
             $linkTools[] = $context->msg('default')->escaped();
         }
         # Create preview link
         $mplink = htmlspecialchars($mptitle->getLocalURL(array('useskin' => $skinkey)));
         $linkTools[] = "<a target='_blank' href=\"{$mplink}\">{$previewtext}</a>";
         # Create links to user CSS/JS pages
         if ($wgAllowUserCss) {
             $cssPage = Title::makeTitleSafe(NS_USER, $user->getName() . '/' . $skinkey . '.css');
             $linkTools[] = Linker::link($cssPage, $context->msg('prefs-custom-css')->escaped());
         }
         if ($wgAllowUserJs) {
             $jsPage = Title::makeTitleSafe(NS_USER, $user->getName() . '/' . $skinkey . '.js');
             $linkTools[] = Linker::link($jsPage, $context->msg('prefs-custom-js')->escaped());
         }
         $display = $sn . ' ' . $context->msg('parentheses', $context->getLanguage()->pipeList($linkTools))->text();
         $ret[$display] = $skinkey;
     }
     return $ret;
 }