/** * Return an array of SMWLink objects that provide additional resources * for the given value. Captions can contain some HTML markup which is * admissible for wiki text, but no more. Result might have no entries * but is always an array. */ public function getInfolinks() { if ($this->isValid() && !is_null($this->m_property)) { if (!$this->mHasSearchLink) { // add default search link $this->mHasSearchLink = true; $this->m_infolinks[] = SMWInfolink::newPropertySearchLink('+', $this->m_property->getLabel(), $this->getWikiValue()); } if (!$this->mHasServiceLinks && $this->serviceLinksRenderState) { // add further service links $this->addServiceLinks(); } } return $this->m_infolinks; }
function renderFolkTagCloud($input, $args, $parser) { # definition of variables $append = ''; $count = 0; $max_tags = 1000; $min_count = 1; $increase_factor = 100; $min_font_size = 77; $font_size = 0; $htmlout = ''; # disable cache $parser->disableCache(); # not needed with searchlink data # build URL path # global $wgServer, $wgArticlePath; # $path = $wgServer . $wgArticlePath; # default tagging property $tag_name = 'FolkTag'; # use a user-defined tagging property as default global $wgFTCTagName; if (isset($wgFTCTagName)) { $tag_name = $wgFTCTagName; } # use a user-defined tagging property for this tag cloud if (isset($args['property'])) { $tag_name = str_replace(' ', '_', ucfirst($args['property'])); } # maximum of tags shown if (isset($args['maxtags'])) { $max_tags = intval($args['maxtags']); } # minimum frequency for tags to be shown if (isset($args['mincount'])) { $min_count = intval($args['mincount']); } # increase factor if (isset($args['increasefactor'])) { $increase_factor = intval($args['increasefactor']); } # minimum font size if (isset($args['minfontsize'])) { $min_font_size = intval($args['minfontsize']); } # get database $db =& wfGetDB(DB_SLAVE); $store = new SMWSQLStore2(); extract($db->tableNames('categorylinks', 'page')); # make tagging property an SMWPorpertyValue in order to access store $property = SMWPropertyValue::makeProperty($tag_name); # initialising result arrays $values = array(); $result = array(); $links = array(); # if there is no filter category: if ($input == NULL) { $values = ft_getPropertyValues($property, $store); # $values = $store->getPropertyValues(NULL, $property); } else { $categories = explode(',', $input); # include subcategories: if (isset($args['subcategorylevel'])) { $subcategories = array(); foreach ($categories as $category) { $subcategories = array_merge($subcategories, getSubCategories($category, intval($args['subcategorylevel']))); } $categories = array_merge($categories, $subcategories); } # start building sql $sql = "SELECT page_title, page_namespace\n\t\t\t\tFROM {$page}\n\t\t\t\tINNER JOIN {$categorylinks}\n\t\t\t\tON {$page}.page_id = {$categorylinks}.cl_from\n\t\t\t\tAND ("; # disjunction of filter categories foreach ($categories as $category) { $category = trim($category); $category = str_replace(' ', '_', $category); $category = str_replace("'", "\\'", $category); $sql .= "{$categorylinks}.cl_to = '{$category}' OR "; } # remainder of sql (FALSE is required to absorb the last OR) $sql .= "FALSE) GROUP BY page_title"; # query $res = $db->query($sql); # parsing result of sql query: get name and namespace of pages placed in the # filter categories and look up all values of the given property for each page for ($i = 0; $i < $db->numRows($res); $i++) { $row = $db->fetchObject($res); $pagename = $row->page_title; $namespace = $row->page_namespace; $values = array_merge($values, $store->getPropertyValues(SMWWikiPageValue::makePage($pagename, $namespace), $property)); } $db->freeResult($res); } # counting frequencies foreach ($values as $value) { # get surface form of property value $tag = $value->getShortHTMLText(); # get Searchlink data for property and current property value $link = SMWInfolink::newPropertySearchLink($tag, $tag_name, $tag)->getHTML(); if (array_key_exists($tag, $result)) { $result[$tag] += 1; } else { $result[$tag] = 1; $links[$tag] = $link; } } # sorting results arsort($result); # if too many tags are found, remove rear part of result array if (count($result) > $max_tags) { $result = array_slice($result, 0, $max_tags, true); } # get minimum and maximum frequency for computing font sizes $min = end($result) or $min = 0; $max = reset($result) or $max = 1; if ($max == $min) { $max += 1; } # sorting results by frequency if (isset($args['order'])) { if ($args['order'] != "frequency") { # ksort($result, SORT_STRING); uksort($result, 'compareLowercase'); } } else { uksort($result, 'compareLowercase'); } # start building html output $htmlOut = $htmlOut . "<div align=justify>"; foreach ($result as $label => $count) { if ($count >= $min_count) { if (isset($args['increase'])) { # computing font size (logarithmic) if ($args[increase] = 'log') { $font_size = $min_font_size + $increase_factor * (log($count) - log($min)) / (log($max) - log($min)); } else { $font_size = $min_font_size + $increase_factor * ($count - $min) / ($max - $min); } } else { $font_size = $min_font_size + $increase_factor * ($count - $min) / ($max - $min); } $style = "font-size: {$font_size}%;"; # link to special page search by property with parameters # property=tagging property and value=current tag # find URL in searchlink data $matches = array(); preg_match('/href="(.)*"/U', $links[$label], $matches); $url = $matches[0]; # include freqency in brackets in output if ($args['count']) { $append = " ({$count})"; } # appending tag $currentRow = "<a style=\"{$style}\" {$url}>" . $label . $append . "</a>  "; $htmlOut = $htmlOut . $currentRow; } } $htmlOut = $htmlOut . "</div>"; return $htmlOut; }
/** * Creates the HTML for a bullet list with all the results of the set * query. Values can be highlighted to show exact matches among nearby * ones. * * @param array $results (array of (array of one or two SMWDataValues)) * @param integer $number How many results should be displayed? -1 for all * @param boolean $first If less results should be displayed than * given, should they show the first $number results, or the last * $number results? * @param boolean $highlight Should the results be highlighted? * * @return string HTML with the bullet list, including header */ private function makeResultList($results, $number, $first, $highlight = false) { if ($number > 0) { $results = $first ? array_slice($results, 0, $number) : array_slice($results, $number); } $html = ''; foreach ($results as $result) { $listitem = $result[0]->getLongHTMLText($this->linker); if ($this->canShowSearchByPropertyLink($result[0])) { $value = $result[0] instanceof StringValue ? $result[0]->getWikiValueForLengthOf(72) : $result[0]->getWikiValue(); $listitem .= '  ' . Infolink::newPropertySearchLink('+', $this->pageRequestOptions->propertyString, $value)->getHTML($this->linker); } elseif ($result[0]->getTypeID() === '_wpg') { // Add browsing link for wikipage results // Note: non-wikipage results are possible using inverse properties $listitem .= '  ' . Infolink::newBrowsingLink('+', $result[0]->getLongWikiText())->getHTML($this->linker); } // Show value if not equal to the value that was searched // or if the current results are to be highlighted: if (array_key_exists(1, $result) && $result[1] instanceof DataValue && !$result[1]->getDataItem() instanceof \SMWDIError && (!$this->pageRequestOptions->value->getDataItem()->equals($result[1]->getDataItem()) || $highlight)) { $listitem .= " <em><small>" . $this->messageBuilder->getMessage('parentheses')->rawParams($result[1]->getLongHTMLText($this->linker))->escaped() . "</small></em>"; } // Highlight values if ($highlight) { $listitem = "<strong>{$listitem}</strong>"; } $html .= "<li>{$listitem}</li>"; } return "<ul>{$html}</ul>"; }
/** * Produce a formatted string representation for showing a property and * its usage count in the list of used properties. * * @since 1.8 * * @param DIProperty $property * @param integer $useCount * @return string */ protected function formatPropertyItem(DIProperty $property, $useCount) { // Clear formatter before invoking messages $this->getMessageFormatter()->clear(); $diWikiPage = $property->getDiWikiPage(); $title = $diWikiPage !== null ? $diWikiPage->getTitle() : null; if ($useCount == 0 && !$this->settings->get('smwgPropertyZeroCountDisplay')) { return ''; } if ($property->isUserDefined()) { if ($title === null) { // Show even messed up property names. $typestring = ''; $proplink = $property->getLabel(); $this->getMessageFormatter()->addFromArray(array('ID: ' . (isset($property->id) ? $property->id : 'N/A')))->addFromKey('smw_notitle', $proplink); } else { list($typestring, $proplink) = $this->getUserDefinedPropertyInfo($title, $property, $useCount); } $infoLink = ''; // Add a link to SearchByProperty to hopefully identify the // "hidden" reference if ($useCount < 1) { $infoLink = ' ' . \SMWInfolink::newPropertySearchLink('+', $property->getLabel(), '')->getHTML($this->getLinker()); } $proplink .= $infoLink; } else { list($typestring, $proplink) = $this->getPredefinedPropertyInfo($property); } if ($typestring === '') { // Built-ins have no type // @todo Should use numParams for $useCount? return $this->msg('smw_property_template_notype')->rawParams($proplink)->numParams($useCount)->text() . ' ' . $this->getMessageFormatter()->setType('warning')->escape(false)->getHtml(); } else { // @todo Should use numParams for $useCount? return $this->msg('smw_property_template')->rawParams($proplink, $typestring)->numParams($useCount)->escaped() . ' ' . $this->getMessageFormatter()->setType('warning')->escape(false)->getHtml(); } }