/** * @return array */ protected function getFormFields() { // Allow the collaboration hub to be passed via parameter (full page title) ?collaborationhub= // Allow the feature name to be passed via parameter (subpage title) ?feature= if ($this->getRequest()->getVal('collaborationhub')) { $defaultCollabHub = $this->getRequest()->getVal('collaborationhub'); } else { $defaultCollabHub = ''; } if ($this->getRequest()->getVal('feature')) { $defaultFeatureName = $this->getRequest()->getVal('feature'); } else { $defaultFeatureName = ''; } $icons = CollaborationKitIcon::getCannedIcons(); $iconChoices = array_combine($icons, $icons); $fields = ['collaborationhub' => ['type' => 'title', 'cssclass' => 'mw-ck-title-input', 'label-message' => 'collaborationkit-createhubfeature-collaborationhub', 'default' => $defaultCollabHub], 'featurename' => ['type' => 'text', 'cssclass' => 'mw-ck-display-input', 'label-message' => 'collaborationkit-createhubfeature-featurename', 'default' => $defaultFeatureName], 'icon' => ['type' => 'combobox', 'cssclass' => 'mw-ck-icon-input', 'label-message' => 'collaborationkit-createhubfeature-icon', 'options' => $iconChoices], 'contenttype' => ['type' => 'radio', 'cssclass' => 'mw-ck-content-type-input', 'label-message' => 'collaborationkit-createhubfeature-contenttype', 'options' => [$this->msg('collaborationkit-createhubfeature-freetext')->text() => 'wikitext', $this->msg('collaborationkit-createhubfeature-articlelist')->text() => 'CollaborationListContent']]]; // If either of these fields is set, that means the user came to the special page // by way of a special workflow, meaning that the name of the hub and/or the feature // is already known. Changing it would cause problems (e.g. the hub saying the feature // is called one thing and then the user changes their mind) so we disable further edits // in the middle of the workflow. if ($defaultCollabHub != '') { $fields['collaborationhub']['readonly'] = true; } if ($defaultFeatureName != '') { $fields['featurename']['readonly'] = true; } return $fields; }
/** * Generate an in icon using a canned CK icon * @param $icon string icon id or random seed * @param $size int intended height/width for rendered icon in px * @param $fallback string what to do for no icon; allowed values are 'random', 'none', or a valid icon id * @return string html */ public static function makeIcon($icon, $size = 50, $colour, $background = 'transparent') { $iconsPreset = CollaborationKitIcon::getCannedIcons(); if (in_array($icon, $iconsPreset)) { $iconClass = Sanitizer::escapeClass($icon); } else { // Random time // Choose class name using $icon value as seed $iconClass = $iconsPreset[hexdec(sha1($icon)[0]) % 27]; } if (!isset($colour) || $colour == 'black') { $colorSuffix = ''; } else { $colorSuffix = '-' . $colour; } return Html::element('div', ['class' => ['mw-ck-icon', 'mw-ck-icon-' . $iconClass . $colorSuffix], 'css' => "height: {$size}px; width: {$size}px; background-color: {$background};"]); }
/** * Get item for ToC - link with icon and label as contents * @param $title Title for target * @param $text string diplay text for title * @param $image string seed for makeIconOrImage * @param $imageSize int size * @return string html */ protected function renderItem(Title $title, $text, $image, $imageSize) { $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); $icon = CollaborationKitIcon::makeIconOrImage($image, $imageSize); $linkContent = new HtmlArmor(Html::rawElement('div', [], $icon . Html::element('span', ['class' => 'mw-ck-toc-item-label'], $text))); return $link = $linkRenderer->makeLink($title, $linkContent); }
/** * Generate an image based on what's in 'image', be it an icon or a file * @param $fallback string for what to do for no icons - nothing, random, specific icon... * @param $size int for non-icon images * @param $seed string fallback seed for explicitly something somethinged ones * @return string */ public function getParsedImage($image, $size = 200) { return CollaborationKitIcon::makeIconOrImage($this->getImage(), $size, 'puzzlepiece'); }