public function getQueryLink($caption = false) { $params = array(trim($this->mQuery->getQueryString())); foreach ($this->mQuery->getExtraPrintouts() as $printout) { //$params[] = '?result.'.$printout->getData().'='.$printout->getLabel(); $params[] = '?result.' . $printout->getData() . '=' . $printout->getLabel(); } if ($caption == false) { smwfLoadExtensionMessages('SemanticMediaWiki'); $caption = ' ' . wfMsgForContent('smw_iq_moreresults'); // The space is right here, not in the QPs! } //unset limit and offset parameter since this is explicitly added by special:ask if (array_key_exists('limit', $this->mQuery->params)) { unset($this->mQuery->params['limit']); } if (array_key_exists('offset', $this->mQuery->params)) { unset($this->mQuery->params['offset']); } //add other query params like source and webservice to the link $params = array_merge($params, $this->mQuery->params); // Note: the initial : prevents SMW from reparsing :: in the query string. $result = SMWInfolink::newInternalLink($caption, ':Special:Ask', false, $params); return $result; }
/** * @since 2.4 * * @param Query $query * * @return Infolink */ public static function get(Query $query) { $link = Infolink::newInternalLink('', ':Special:Ask', false, array()); $params = self::getParameters($query); foreach ($params as $key => $param) { $link->setParameter($param, is_string($key) ? $key : false); } $link->setCaption(' ' . Message::get('smw_iq_moreresults', Message::TEXT, Message::USER_LANGUAGE)); return $link; }
public function execute($param) { global $wgOut; $params = SMWInfolink::decodeParameters($param, false); $typeLabel = reset($params); if ($typeLabel == false) { $wgOut->setPageTitle(wfMessage('types')->text()); $html = $this->getTypesList(); } else { $typeName = str_replace('_', ' ', $typeLabel); $wgOut->setPageTitle($typeName); // Maybe add a better message for this $html = $this->getTypeProperties($typeLabel); } $wgOut->addHTML($html); SMWOutputs::commitToOutputPage($wgOut); }
/** * Method for handling the ask concept function. * * @todo The possible use of this in an HTML or Specal page context needs to be revisited. The code mentions it, but can this actually happen? * @todo The escaping of symbols in concept queries needs to be revisited. * * @since 1.5.3 * * @param Parser $parser */ public static function render(Parser &$parser) { global $wgContLang, $wgTitle; $title = $parser->getTitle(); $pconc = new SMWDIProperty('_CONC'); if ($title->getNamespace() != SMW_NS_CONCEPT) { $result = smwfEncodeMessages(array(wfMsgForContent('smw_no_concept_namespace'))); SMWOutputs::commitToParser($parser); return $result; } elseif (count(SMWParseData::getSMWdata($parser)->getPropertyValues($pconc)) > 0) { $result = smwfEncodeMessages(array(wfMsgForContent('smw_multiple_concepts'))); SMWOutputs::commitToParser($parser); return $result; } // process input: $params = func_get_args(); array_shift($params); // We already know the $parser ... // Use first parameter as concept (query) string. $concept_input = str_replace(array('>', '<'), array('>', '<'), array_shift($params)); // second parameter, if any, might be a description $concept_docu = array_shift($params); // NOTE: the str_replace above is required in MediaWiki 1.11, but not in MediaWiki 1.14 $query = SMWQueryProcessor::createQuery($concept_input, SMWQueryProcessor::getProcessedParams(array('limit' => 20, 'format' => 'list')), SMWQueryProcessor::CONCEPT_DESC); $concept_text = $query->getDescription()->getQueryString(); if (!is_null(SMWParseData::getSMWData($parser))) { $diConcept = new SMWDIConcept($concept_text, $concept_docu, $query->getDescription()->getQueryFeatures(), $query->getDescription()->getSize(), $query->getDescription()->getDepth()); SMWParseData::getSMWData($parser)->addPropertyObjectValue($pconc, $diConcept); } // display concept box: $rdflink = SMWInfolink::newInternalLink(wfMsgForContent('smw_viewasrdf'), $wgContLang->getNsText(NS_SPECIAL) . ':ExportRDF/' . $title->getPrefixedText(), 'rdflink'); SMWOutputs::requireResource('ext.smw.style'); // TODO: escape output, preferably via Html or Xml class. $result = '<div class="smwfact"><span class="smwfactboxhead">' . wfMsgForContent('smw_concept_description', $title->getText()) . (count($query->getErrors()) > 0 ? ' ' . smwfEncodeMessages($query->getErrors()) : '') . '</span>' . '<span class="smwrdflink">' . $rdflink->getWikiText() . '</span>' . '<br />' . ($concept_docu ? "<p>{$concept_docu}</p>" : '') . '<pre>' . str_replace('[', '[', $concept_text) . "</pre>\n</div>"; if (!is_null($wgTitle) && $wgTitle->isSpecialPage()) { global $wgOut; SMWOutputs::commitToOutputPage($wgOut); } else { SMWOutputs::commitToParser($parser); } return $result; }
public function getQueryLink($caption = false) { $params = array(trim($this->mQuery->getQueryString())); foreach ($this->mQuery->getExtraPrintouts() as $printout) { $params[] = $printout->getSerialisation(); } if (count($this->mQuery->sortkeys) > 0) { $psort = ''; $porder = ''; $first = true; foreach ($this->mQuery->sortkeys as $sortkey => $order) { if ($first) { $first = false; } else { $psort .= ','; $porder .= ','; } $psort .= $sortkey; $porder .= $order; } if ($psort != '' || $porder != 'ASC') { // do not mention default sort (main column, ascending) $params['sort'] = $psort; $params['order'] = $porder; } } if ($caption == false) { wfLoadExtensionMessages('SemanticMediaWiki'); $caption = ' ' . wfMsgForContent('smw_iq_moreresults'); // the space is right here, not in the QPs! } $askPage = $this->mQuery instanceof SMWSPARQLQuery ? "AskTSC" : "Ask"; $result = SMWInfolink::newInternalLink($caption, ':Special:' . $askPage, false, $params); // Note: the initial : prevents SMW from reparsing :: in the query string return $result; }
/** * 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>"; }
/** * This function creates wiki text suitable for rendering a Factbox for a given * SMWSemanticData object that holds all relevant data. It also checks whether the * given setting of $showfactbox requires displaying the given data at all. * * @param SMWSemanticData $semdata * @param boolean $showfactbox * * @return string */ public static function getFactboxText(SMWSemanticData $semdata, $showfactbox = SMW_FACTBOX_NONEMPTY) { global $wgContLang; wfProfileIn('SMWFactbox::printFactbox (SMW)'); switch ($showfactbox) { case SMW_FACTBOX_HIDDEN: // never show wfProfileOut('SMWFactbox::printFactbox (SMW)'); return ''; case SMW_FACTBOX_SPECIAL: // show only if there are special properties if (!$semdata->hasVisibleSpecialProperties()) { wfProfileOut('SMWFactbox::printFactbox (SMW)'); return ''; } break; case SMW_FACTBOX_NONEMPTY: // show only if non-empty if (!$semdata->hasVisibleProperties()) { wfProfileOut('SMWFactbox::printFactbox (SMW)'); return ''; } break; // case SMW_FACTBOX_SHOWN: // just show ... } // actually build the Factbox text: $text = ''; if (wfRunHooks('smwShowFactbox', array(&$text, $semdata))) { $subjectDv = SMWDataValueFactory::newDataItemValue($semdata->getSubject(), null); SMWOutputs::requireResource('ext.smw.style'); $rdflink = SMWInfolink::newInternalLink(wfMessage('smw_viewasrdf')->inContentLanguage()->text(), $wgContLang->getNsText(NS_SPECIAL) . ':ExportRDF/' . $subjectDv->getWikiValue(), 'rdflink'); $browselink = SMWInfolink::newBrowsingLink($subjectDv->getText(), $subjectDv->getWikiValue(), 'swmfactboxheadbrowse'); $text .= '<div class="smwfact">' . '<span class="smwfactboxhead">' . wfMessage('smw_factbox_head', $browselink->getWikiText())->inContentLanguage()->text() . '</span>' . '<span class="smwrdflink">' . $rdflink->getWikiText() . '</span>' . '<table class="smwfacttable">' . "\n"; foreach ($semdata->getProperties() as $propertyDi) { $propertyDv = SMWDataValueFactory::newDataItemValue($propertyDi, null); if (!$propertyDi->isShown()) { // showing this is not desired, hide continue; } elseif ($propertyDi->isUserDefined()) { // user defined property $propertyDv->setCaption(preg_replace('/[ ]/u', ' ', $propertyDv->getWikiValue(), 2)); /// NOTE: the preg_replace is a slight hack to ensure that the left column does not get too narrow $text .= '<tr><td class="smwpropname">' . $propertyDv->getShortWikiText(true) . '</td><td class="smwprops">'; } elseif ($propertyDv->isVisible()) { // predefined property $text .= '<tr><td class="smwspecname">' . $propertyDv->getShortWikiText(true) . '</td><td class="smwspecs">'; } else { // predefined, internal property continue; } $propvalues = $semdata->getPropertyValues($propertyDi); $valuesHtml = array(); foreach ($propvalues as $dataItem) { $dataValue = SMWDataValueFactory::newDataItemValue($dataItem, $propertyDi); if ($dataValue->isValid()) { $valuesHtml[] = $dataValue->getLongWikiText(true) . $dataValue->getInfolinkText(SMW_OUTPUT_WIKI); } } $text .= $GLOBALS['wgLang']->listToText($valuesHtml); $text .= '</td></tr>'; } $text .= '</table></div>'; } wfProfileOut('SMWFactbox::printFactbox (SMW)'); return $text; }
public function execute($query) { global $wgRequest, $wgOut; $linker = smwfGetLinker(); $this->setHeaders(); // Get parameters $pagename = $wgRequest->getVal('from'); $propname = $wgRequest->getVal('type'); $limit = $wgRequest->getVal('limit'); $offset = $wgRequest->getVal('offset'); if ($limit === '') { $limit = 20; } if ($offset === '') { $offset = 0; } if ($propname === '') { // No GET parameters? Try the URL: $queryparts = explode('::', $query); $propname = $query; if (count($queryparts) > 1) { $pagename = $queryparts[0]; $propname = implode('::', array_slice($queryparts, 1)); } } $subject = SMWDataValueFactory::newTypeIDValue('_wpg', $pagename); $pagename = $subject->isValid() ? $subject->getPrefixedText() : ''; $property = SMWPropertyValue::makeUserProperty($propname); $propname = $property->isValid() ? $property->getWikiValue() : ''; // Produce output $html = ''; if ($propname === '') { // no property given, show a message $html .= wfMsg('smw_pp_docu') . "\n"; } else { // property given, find and display results // FIXME: very ugly, needs i18n $wgOut->setPagetitle(($pagename !== '' ? $pagename . ' ' : '') . $property->getWikiValue()); // get results (get one more, to see if we have to add a link to more) $options = new SMWRequestOptions(); $options->limit = $limit + 1; $options->offset = $offset; $options->sort = true; $results = smwfGetStore()->getPropertyValues($pagename !== '' ? $subject->getDataItem() : null, $property->getDataItem(), $options); // prepare navigation bar if needed if ($offset > 0 || count($results) > $limit) { if ($offset > 0) { $navigation = Html::element('a', array('href' => $this->getTitle()->getLocalURL(array('offset' => max(0, $offset - $limit), 'limit' => $limit, 'type' => $propname, 'from' => $pagename))), wfMsg('smw_result_prev')); } else { $navigation = wfMsg('smw_result_prev'); } $navigation .= '     <b>' . wfMsg('smw_result_results') . ' ' . ($offset + 1) . '– ' . ($offset + min(count($results), $limit)) . '</b>    '; if (count($results) == $limit + 1) { $navigation = Html::element('a', array('href' => $this->getTitle()->getLocalURL(array('offset' => $offset + $limit, 'limit' => $limit, 'type' => $propname, 'from' => $pagename))), wfMsg('smw_result_next')); } else { $navigation .= wfMsg('smw_result_next'); } } else { $navigation = ''; } // display results $html .= '<br />' . $navigation; if (count($results) == 0) { $html .= wfMsg('smw_result_noresults'); } else { $html .= "<ul>\n"; $count = $limit + 1; foreach ($results as $di) { $count--; if ($count < 1) { continue; } $dv = SMWDataValueFactory::newDataItemValue($di, $property->getDataItem()); $html .= '<li>' . $dv->getLongHTMLText($linker); // do not show infolinks, the magnifier "+" is ambiguous with the browsing '+' for '_wpg' (see below) if ($property->getDataItem()->findPropertyTypeID() == '_wpg') { $browselink = SMWInfolink::newBrowsingLink('+', $dv->getLongWikiText()); $html .= '  ' . $browselink->getHTML($linker); } $html .= "</li> \n"; } $html .= "</ul>\n"; } $html .= $navigation; } // Display query form $spectitle = $this->getTitle(); $html .= '<p> </p>'; $html .= '<form name="pageproperty" action="' . htmlspecialchars($spectitle->getLocalURL()) . '" method="get">' . "\n" . '<input type="hidden" name="title" value="' . $spectitle->getPrefixedText() . '"/>'; $html .= wfMsg('smw_pp_from') . ' <input type="text" name="from" value="' . htmlspecialchars($pagename) . '" />' . "   \n"; $html .= wfMsg('smw_pp_type') . ' <input type="text" name="type" value="' . htmlspecialchars($propname) . '" />' . "\n"; $html .= '<input type="submit" value="' . wfMsg('smw_pp_submit') . "\"/>\n</form>\n"; $wgOut->addHTML($html); SMWOutputs::commitToOutputPage($wgOut); // make sure locally collected output data is pushed to the output! }
protected function extractQueryParameters($p) { // This code rather hacky since there are many ways to call that special page, the most involved of // which is the way that this page calls itself when data is submitted via the form (since the shape // of the parameters then is governed by the UI structure, as opposed to being governed by reason). global $wgRequest, $smwgQMaxInlineLimit; // First make all inputs into a simple parameter list that can again be parsed into components later. if ($wgRequest->getCheck('q')) { // called by own Special, ignore full param string in that case $rawparams = SMWInfolink::decodeParameters($wgRequest->getVal('p'), false); // p is used for any additional parameters in certain links } else { // called from wiki, get all parameters $rawparams = SMWInfolink::decodeParameters($p, true); } // Check for q= query string, used whenever this special page calls itself (via submit or plain link): $this->m_querystring = $wgRequest->getText('q'); if ($this->m_querystring != '') { $rawparams[] = $this->m_querystring; } // Check for param strings in po (printouts), appears in some links and in submits: $paramstring = $wgRequest->getText('po'); if ($paramstring != '') { // parameters from HTML input fields $ps = explode("\n", $paramstring); // params separated by newlines here (compatible with text-input for printouts) foreach ($ps as $param) { // add initial ? if omitted (all params considered as printouts) $param = trim($param); if ($param != '' && $param[0] != '?') { $param = '?' . $param; } $rawparams[] = $param; } } // Now parse parameters and rebuilt the param strings for URLs SMWSPARQLQueryProcessor::processFunctionParams($rawparams, $this->m_querystring, $this->m_params, $this->m_printouts); // Try to complete undefined parameter values from dedicated URL params if (!array_key_exists('format', $this->m_params)) { if (array_key_exists('rss', $this->m_params)) { // backwards compatibility (SMW<=1.1 used this) $this->m_params['format'] = 'rss'; } else { // default $this->m_params['format'] = 'broadtable'; } } $sortcount = $wgRequest->getVal('sc'); if (!is_numeric($sortcount)) { $sortcount = 0; } // commented out because TSC does not accept empty sort/order parameters /*if ( !array_key_exists('order',$this->m_params) ) { $this->m_params['order'] = $wgRequest->getVal( 'order' ); // basic ordering parameter (, separated) for ($i=0; $i<$sortcount; $i++) { if ($this->m_params['order'] != '') { $this->m_params['order'] .= ','; } $value = $wgRequest->getVal( 'order' . $i ); $value = ($value == '')?'ASC':$value; $this->m_params['order'] .= $value; } } if ( !array_key_exists('sort',$this->m_params) ) { $this->m_params['sort'] = $wgRequest->getText( 'sort' ); // basic sorting parameter (, separated) for ($i=0; $i<$sortcount; $i++) { if ( ($this->m_params['sort'] != '') || ($i>0) ) { // admit empty sort strings here $this->m_params['sort'] .= ','; } $this->m_params['sort'] .= $wgRequest->getText( 'sort' . $i ); } }*/ // Find implicit ordering for RSS -- needed for downwards compatibility with SMW <=1.1 if ($this->m_params['format'] == 'rss' && $this->m_params['sort'] == '' && $sortcount == 0) { foreach ($this->m_printouts as $printout) { if (strtolower($printout->getLabel()) == "date" && $printout->getTypeID() == "_dat") { $this->m_params['sort'] = $printout->getTitle()->getText(); $this->m_params['order'] = 'DESC'; } } } if (!array_key_exists('offset', $this->m_params)) { $this->m_params['offset'] = $wgRequest->getVal('offset'); if ($this->m_params['offset'] == '') { $this->m_params['offset'] = 0; } } if (!array_key_exists('limit', $this->m_params)) { $this->m_params['limit'] = $wgRequest->getVal('limit'); if ($this->m_params['limit'] == '') { $this->m_params['limit'] = $this->m_params['format'] == 'rss' ? 10 : 20; // standard limit for RSS } } $this->m_params['limit'] = min($this->m_params['limit'], $smwgQMaxInlineLimit); if (!array_key_exists('merge', $this->m_params)) { $this->m_params['merge'] = $wgRequest->getVal('merge'); if ($this->m_params['merge'] == '') { $this->m_params['merge'] = true; // merge per default } } $this->m_editquery = $wgRequest->getVal('eq') != '' || '' == $this->m_querystring; }
/** * Displays a value, including all relevant links (browse and search by property) * * @param[in] $property SMWPropertyValue The property this value is linked to the subject with * @param[in] $value DataValue The actual value * @param[in] $incoming bool If this is an incoming or outgoing link * * @return string HTML with the link to the article, browse, and search pages */ private function displayValue(\SMWPropertyValue $property, DataValue $dataValue, $incoming) { $linker = smwfGetLinker(); // Allow the DV formatter to access a specific language code $dataValue->setOption(DataValue::OPT_CONTENT_LANGUAGE, Localizer::getInstance()->getPreferredContentLanguage($this->subject->getDataItem())->getCode()); $dataValue->setOption(DataValue::OPT_USER_LANGUAGE, Localizer::getInstance()->getUserLanguage()->getCode()); $dataValue->setContextPage($this->subject->getDataItem()); // Use LOCL formatting where appropriate (date) $dataValue->setOutputFormat('LOCL'); $html = $dataValue->getLongHTMLText($linker); if ($dataValue->getTypeID() === '_wpg' || $dataValue->getTypeID() === '__sob') { $html .= " " . \SMWInfolink::newBrowsingLink('+', $dataValue->getLongWikiText())->getHTML($linker); } elseif ($incoming && $property->isVisible()) { $html .= " " . \SMWInfolink::newInversePropertySearchLink('+', $dataValue->getTitle(), $property->getDataItem()->getLabel(), 'smwsearch')->getHTML($linker); } elseif ($dataValue->getProperty() instanceof DIProperty && $dataValue->getProperty()->getKey() !== '_INST') { $html .= $dataValue->getInfolinkText(SMW_OUTPUT_HTML, $linker); } return $html; }
/** * TODO: document */ protected function makeHTMLResult() { global $wgOut; // TODO: hold into account $smwgAutocompleteInSpecialAsk $wgOut->addModules('ext.smw.ask'); $result = ''; $result_mime = false; // output in MW Special page as usual // build parameter strings for URLs, based on current settings $urlArgs['q'] = $this->m_querystring; $tmp_parray = array(); foreach ($this->m_params as $key => $value) { if (!in_array($key, array('sort', 'order', 'limit', 'offset', 'title'))) { $tmp_parray[$key] = $value; } } $urlArgs['p'] = SMWInfolink::encodeParameters($tmp_parray); $printoutstring = ''; /** * @var SMWPrintRequest $printout */ foreach ($this->m_printouts as $printout) { $printoutstring .= $printout->getSerialisation() . "\n"; } if ($printoutstring !== '') { $urlArgs['po'] = $printoutstring; } if (array_key_exists('sort', $this->m_params)) { $urlArgs['sort'] = $this->m_params['sort']; } if (array_key_exists('order', $this->m_params)) { $urlArgs['order'] = $this->m_params['order']; } if ($this->m_querystring !== '') { // FIXME: this is a hack SMWQueryProcessor::addThisPrintout($this->m_printouts, $this->m_params); $params = SMWQueryProcessor::getProcessedParams($this->m_params, $this->m_printouts); $this->m_params['format'] = $params['format']->getValue(); $this->params = $params; $queryobj = SMWQueryProcessor::createQuery($this->m_querystring, $params, SMWQueryProcessor::SPECIAL_PAGE, $this->m_params['format'], $this->m_printouts); /** * @var SMWQueryResult $res */ // Determine query results $res = $params['source']->getValue()->getQueryResult($queryobj); // Try to be smart for rss/ical if no description/title is given and we have a concept query: if ($this->m_params['format'] == 'rss') { $desckey = 'rssdescription'; $titlekey = 'rsstitle'; } elseif ($this->m_params['format'] == 'icalendar') { $desckey = 'icalendardescription'; $titlekey = 'icalendartitle'; } else { $desckey = false; } if ($desckey && $queryobj->getDescription() instanceof SMWConceptDescription && (!isset($this->m_params[$desckey]) || !isset($this->m_params[$titlekey]))) { $concept = $queryobj->getDescription()->getConcept(); if (!isset($this->m_params[$titlekey])) { $this->m_params[$titlekey] = $concept->getText(); } if (!isset($this->m_params[$desckey])) { // / @bug The current SMWStore will never return SMWConceptValue (an SMWDataValue) here; it might return SMWDIConcept (an SMWDataItem) $dv = end(smwfGetStore()->getPropertyValues(SMWWikiPageValue::makePageFromTitle($concept), new SMWDIProperty('_CONC'))); if ($dv instanceof SMWConceptValue) { $this->m_params[$desckey] = $dv->getDocu(); } } } $printer = SMWQueryProcessor::getResultPrinter($this->m_params['format'], SMWQueryProcessor::SPECIAL_PAGE); global $wgRequest; $hidequery = $wgRequest->getVal('eq') == 'no'; if (!$printer->isExportFormat()) { if ($res->getCount() > 0) { if ($this->m_editquery) { $urlArgs['eq'] = 'yes'; } elseif ($hidequery) { $urlArgs['eq'] = 'no'; } $navigation = $this->getNavigationBar($res, $urlArgs); $result .= '<div style="text-align: center;">' . "\n" . $navigation . "\n</div>\n"; $query_result = $printer->getResult($res, $params, SMW_OUTPUT_HTML); if (is_array($query_result)) { $result .= $query_result[0]; } else { $result .= $query_result; } $result .= '<div style="text-align: center;">' . "\n" . $navigation . "\n</div>\n"; } else { $result = '<div style="text-align: center;">' . wfMessage('smw_result_noresults')->escaped() . '</div>'; } } } if (isset($printer) && $printer->isExportFormat()) { $wgOut->disable(); /** * @var SMWIExportPrinter $printer */ $printer->outputAsFile($res, $params); } else { if ($this->m_querystring) { $wgOut->setHTMLtitle($this->m_querystring); } else { $wgOut->setHTMLtitle(wfMessage('ask')->text()); } $urlArgs['offset'] = $this->m_params['offset']; $urlArgs['limit'] = $this->m_params['limit']; $result = $this->getInputForm($printoutstring, wfArrayToCGI($urlArgs)) . $result; $wgOut->addHTML($result); } }
/** * Add a link to the toolbox to view the properties of the current page in * Special:Browse. The links has the CSS id "t-smwbrowselink" so that it can be * skinned or hidden with all standard mechanisms (also by individual users * with custom CSS). * * @since 1.7.1 * * @param $skintemplate * * @return boolean */ public static function showBrowseLink($skintemplate) { if ($skintemplate->data['isarticle']) { $browselink = SMWInfolink::newBrowsingLink(wfMessage('smw_browselink')->text(), $skintemplate->data['titleprefixeddbkey'], false); echo '<li id="t-smwbrowselink">' . $browselink->getHTML() . '</li>'; } return true; }
/** * Create an SMWInfolink object representing a link to further query results. * This link can then be serialised or extended by further params first. * The optional $caption can be used to set the caption of the link (though this * can also be changed afterwards with SMWInfolink::setCaption()). If empty, the * message 'smw_iq_moreresults' is used as a caption. * * TODO: have this work for all params without manually overriding and adding everything * (this is possible since the param handling changes in 1.7) * * @param string|false $caption * * @return SMWInfolink */ public function getQueryLink($caption = false) { $params = array(trim($this->mQuery->getQueryString())); foreach ($this->mQuery->getExtraPrintouts() as $printout) { $serialization = $printout->getSerialisation(); // TODO: this is a hack to get rid of the mainlabel param in case it was automatically added // by SMWQueryProcessor::addThisPrintout. Should be done nicer when this link creation gets redone. if ($serialization !== '?#') { $params[] = $serialization; } } if ($this->mQuery->getMainLabel() !== false) { $params['mainlabel'] = $this->mQuery->getMainLabel(); } $params['offset'] = $this->mQuery->getOffset() + count($this->mResults); if ($params['offset'] === 0) { unset($params['offset']); } if ($this->mQuery->getLimit() > 0) { $params['limit'] = $this->mQuery->getLimit(); } if (count($this->mQuery->sortkeys) > 0) { $order = implode(',', $this->mQuery->sortkeys); $sort = implode(',', array_keys($this->mQuery->sortkeys)); if ($sort !== '' || $order != 'ASC') { $params['order'] = $order; $params['sort'] = $sort; } } if ($caption == false) { $caption = ' ' . wfMsgForContent('smw_iq_moreresults'); // The space is right here, not in the QPs! } // Note: the initial : prevents SMW from reparsing :: in the query string. $result = SMWInfolink::newInternalLink($caption, ':Special:Ask', false, $params); return $result; }
/** * 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. * * @todo I18N: some parentheses hardcoded * * @since 1.8 (was private displayResults before) * @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 */ protected function getResultList($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(smwfGetLinker()); // Add browsing link for wikipage results // Note: non-wikipage results are possible using inverse properties if ($result[0]->getTypeID() == '_wpg') { $listitem .= '  ' . SMWInfolink::newBrowsingLink('+', $result[0]->getLongWikiText())->getHTML(smwfGetLinker()); } // 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 SMWDataValue && (!$this->value->getDataItem()->equals($result[1]->getDataItem()) || $highlight)) { // TODO i18n: Hardcoded parentheses $listitem .= " <em><small>(" . $result[1]->getLongHTMLText(smwfGetLinker()) . ")</small></em>"; } // Highlight values if ($highlight) { $listitem = "<strong>{$listitem}</strong>"; } $html .= "<li>{$listitem}</li>\n"; } return "<ul>\n{$html}</ul>\n"; }
private function tryToFindAtLeastOnePropertyTableReferenceFor(DIProperty $property) { $resultList = ''; $resultMessage = ''; $resultCount = 0; $extra = ''; $dataItem = ApplicationFactory::getInstance()->getStore()->getPropertyTableIdReferenceFinder()->tryToFindAtLeastOneReferenceForProperty($property); if (!$dataItem instanceof DIWikiPage) { $resultMessage = 'No reference found.'; return array($resultMessage, $resultList, $resultCount); } // In case the item has already been marked as deleted but is yet pending // for removal if ($dataItem->getInterWiki() === ':smw-delete') { $resultMessage = 'Item reference "' . $dataItem->getSubobjectName() . '" has already been marked for removal.'; $dataItem = new DIWikiPage($dataItem->getDBKey(), $dataItem->getNamespace()); } $dataValue = DataValueFactory::getInstance()->newDataValueByItem($dataItem); $dataValue->setOutputFormat('LOCL'); if ($dataValue->isValid()) { //$resultMessage = 'Item reference for a zero-marked property.'; $resultList = $dataValue->getShortHtmlText($this->linker) . ' ' . $extra; $resultCount++; $resultList .= '  ' . Infolink::newBrowsingLink('+', $dataValue->getLongWikiText())->getHTML($this->linker); } return array($resultMessage, $resultList, $resultCount); }
/** * A method which decodes form data sent through form-elements generated * by its complement, getFormatSelectBox(). UIs may overload both to * change form parameters. * * @param WebRequest $wgRequest * @return array */ protected function processFormatSelectBox(WebRequest $wgRequest) { $queryVal = $wgRequest->getVal('p'); if (!empty($queryVal)) { $params = SMWInfolink::decodeParameters($queryVal, false); } else { $queryValues = $wgRequest->getArray('p'); if (is_array($queryValues)) { foreach ($queryValues as $key => $val) { if (empty($val)) { unset($queryValues[$key]); } } } // p is used for any additional parameters in certain links. $params = SMWInfolink::decodeParameters($queryValues, false); } return $params; }
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; }
/** * Format a list of articles chunked by letter in a table that shows subject articles in * one column and object articles/values in the other one. */ private function subjectObjectList() { global $wgContLang; $store = smwfGetStore(); $ac = count($this->annotations); if ($ac > $this->limit) { if ($this->until != '') { $start = 1; } else { $start = 0; $ac = $ac - 1; } } else { $start = 0; } $r = '<table style="width: 100%; ">'; $prev_start_char = 'None'; for ($index = $start; $index < $ac; $index++) { list($article, $values) = $this->annotations[$index]; $start_char = $wgContLang->convert($wgContLang->firstChar($article->getSortkey())); // Header for index letters if ($start_char != $prev_start_char) { $r .= '<tr><th class="smwpropname"><h3>' . htmlspecialchars($start_char) . "</h3></th><th></th></tr>\n"; $prev_start_char = $start_char; } // Property name $searchlink = SMWInfolink::newBrowsingLink('+', $article->getShortHTMLText()); $r .= '<tr><td class="smwpropname">' . $article->getLongHTMLText($this->getSkin()) . ' ' . $searchlink->getHTML($this->getSkin()) . '</td><td class="smwprops">'; // Property values $ropts = new SMWRequestOptions(); $ropts->limit = 4; for ($i = 0; $i < 4; $i++) { if (!array_key_exists($i, $values)) { break; } $value = $values[$i]; if ($i != 0) { $r .= ', '; } if ($i < 3) { $r .= $value->getLongHTMLText($this->getSkin()) . $value->getInfolinkText(SMW_OUTPUT_HTML, $this->getSkin()); } else { $searchlink = SMWInfolink::newInversePropertySearchLink('…', $article->getWikiValue(), $this->mTitle->getText()); $r .= $searchlink->getHTML($this->getSkin()); } } $r .= "</td></tr>\n"; } $r .= '</table>'; return $r; }
/** * Encode an array of parameters, formatted as $name => $value, to a parameter * string that can be used for linking. If $forTitle is true (default), then the * parameters are encoded for use in a MediaWiki page title (useful for making * internal links to parameterised special pages), otherwise the parameters are * encoded HTTP GET style. The parameter name "x" is used to collect parameters * that do not have any string keys in GET, and hence "x" should never be used * as a parameter name. * * The function SMWInfolink::decodeParameters() can be used to undo this encoding. * It is strongly recommended to not create any code that depends on the concrete * way of how parameters are encoded within this function, and to always use the * respective encoding/decoding methods instead. * * @param array $params * @param boolean $forTitle */ static public function encodeParameters( array $params, $forTitle = true ) { $result = ''; if ( $forTitle ) { foreach ( $params as $name => $value ) { if ( is_string( $name ) && ( $name !== '' ) ) { $value = $name . '=' . $value; } // Escape certain problematic values. Use SMW-escape // (like URLencode but - instead of % to prevent double encoding by later MW actions) // /// : SMW's parameter separator, must not occur within params // - : used in SMW-encoding strings, needs escaping too // [ ] < > < > '' |: problematic in MW titles // & : sometimes problematic in MW titles ([[&]] is OK, [[&test]] is OK, [[&test;]] is not OK) // (Note: '&' in strings obtained during parsing already has &entities; replaced by // UTF8 anyway) // ' ': are equivalent with '_' in MW titles, but are not equivalent in certain parameter values // "\n": real breaks not possible in [[...]] // "#": has special meaning in URLs, triggers additional MW escapes (using . for %) // '%': must be escaped to prevent any impact of double decoding when replacing - // by % before urldecode // '?': if not escaped, strange effects were observed on some sites (printout and other // parameters ignored without obvious cause); SMW-escaping is always save to do -- it just // make URLs less readable // $value = str_replace( array( '-', '#', "\n", ' ', '/', '[', ']', '<', '>', '<', '>', '&', '\'\'', '|', '&', '%', '?' ), array( '-2D', '-23', '-0A', '-20', '-2F', '-5B', '-5D', '-3C', '-3E', '-3C', '-3E', '-26', '-27-27', '-7C', '-26', '-25', '-3F' ), $value ); if ( $result !== '' ) { $result .= '/'; } $result .= $value; } } else { // Note: this requires to have HTTP compatible parameter names (ASCII) $q = array(); // collect unlabelled query parameters here foreach ( $params as $name => $value ) { if ( is_string( $name ) && ( $name !== '' ) ) { $value = $name . '=' . rawurlencode( $value ); if ( $result !== '' ) { $result .= '&'; } $result .= $value; } else { $q[] = $value; } } if ( count( $q ) > 0 ) { // prepend encoding for unlabelled parameters if ( $result !== '' ) { $result = '&' . $result; } $result = 'x=' . rawurlencode( SMWInfolink::encodeParameters( $q, true ) ) . $result; } } return $result; }
public function __construct($internal, $caption, $target, $style = false, array $params = array()) { parent::__construct($internal, $caption, $target, $style, $params); }
/** * Creates the HTML for a bullet list with all the results of the set query. * * @param[in] $results array of array of SMWWikiPageValue, SMWDataValue The entity and its datavalue * @param[in] $number int How many results should be displayed? -1 for all * @param[in] $first bool If less results should be displayed than given, should they show the first $number results, or the last $number results? * @param[in] $highlight bool Should the results be highlighted? * * @return string HTML with the bullet list and a header */ private function displayResults($results, $number = -1, $first = true, $highlight = false) { $html = "<ul>\n"; if (!$first && $number > 0) { // TODO: why is this reversed? // I (jeroendedauw) replaced a loop using array_shift by this, which is equivalent. $results = array_slice(array_reverse($results), 0, $number); } while ($results && $number != 0) { $result = array_shift($results); $html .= '<li>' . $result[0]->getLongHTMLText(smwfGetLinker()); if ($result[0]->getTypeID() == '_wpg') { $html .= '  ' . SMWInfolink::newBrowsingLink('+', $result[0]->getLongWikiText())->getHTML(smwfGetLinker()); } if (array_key_exists(1, $result) && is_object($result[1]) && ($this->value != $result[1] || $highlight)) { $html .= " <em><small>(" . $result[1]->getLongHTMLText(smwfGetLinker()) . ")</small></em>"; } $html .= "</li>"; if ($highlight) { $html = "<strong>" . $html . "</strong>"; } $html .= "\n"; $number--; } $html .= "</ul>\n"; return $html; }
protected function makeHTMLResult() { global $wgOut; $result = ''; $result_mime = false; // output in MW Special page as usual // build parameter strings for URLs, based on current settings $urltail = '&q=' . urlencode($this->m_querystring); $tmp_parray = array(); foreach ($this->m_params as $key => $value) { if (!in_array($key, array('sort', 'order', 'limit', 'offset', 'title'))) { $tmp_parray[$key] = $value; } } $urltail .= '&p=' . urlencode(SMWInfolink::encodeParameters($tmp_parray)); $printoutstring = ''; foreach ($this->m_printouts as $printout) { $printoutstring .= $printout->getSerialisation() . "\n"; } if ('' != $printoutstring) { $urltail .= '&po=' . urlencode($printoutstring); } if ('' != $this->m_params['sort']) { $urltail .= '&sort=' . $this->m_params['sort']; } if ('' != $this->m_params['order']) { $urltail .= '&order=' . $this->m_params['order']; } if ($this->m_querystring != '') { $queryobj = SMWQueryProcessor::createQuery($this->m_querystring, $this->m_params, false, '', $this->m_printouts); $queryobj->querymode = SMWQuery::MODE_INSTANCES; ///TODO: Somewhat hacky (just as the query mode computation in SMWQueryProcessor::createQuery!) $res = smwfGetStore()->getQueryResult($queryobj); $printer = SMWQueryProcessor::getResultPrinter($this->m_params['format'], false, $res); $result_mime = $printer->getMimeType($res); if ($result_mime == false) { $navigation = $this->getNavigationBar($res, $urltail); $result = '<div style="text-align: center;">' . $navigation; $result .= '</div>' . $printer->getResult($res, $this->m_params, SMW_OUTPUT_HTML); $result .= '<div style="text-align: center;">' . $navigation . '</div>'; } else { // make a stand-alone file $result = $printer->getResult($res, $this->m_params, SMW_OUTPUT_FILE); } } if ($result_mime == false) { if ($this->m_querystring) { $wgOut->setHTMLtitle($this->m_querystring); } else { $wgOut->setHTMLtitle(wfMsg('ask')); } $result = $this->getInputForm($printoutstring, 'offset=' . $this->m_params['offset'] . '&limit=' . $this->m_params['limit'] . $urltail) . $result; $wgOut->addHTML($result); } else { $wgOut->disable(); header("Content-type: {$result_mime}; charset=UTF-8"); print $result; } }
/** * Displays a value, including all relevant links (browse and search by property) * * @param[in] $property SMWPropertyValue The property this value is linked to the subject with * @param[in] $value SMWDataValue The actual value * @param[in] $incoming bool If this is an incoming or outgoing link * * @return string HTML with the link to the article, browse, and search pages */ private function displayValue( SMWPropertyValue $property, SMWDataValue $dataValue, $incoming ) { $linker = smwfGetLinker(); $html = $dataValue->getLongHTMLText( $linker ); if ( $dataValue->getTypeID() == '_wpg' ) { $html .= " " . SMWInfolink::newBrowsingLink( '+', $dataValue->getLongWikiText() )->getHTML( $linker ); } elseif ( $incoming && $property->isVisible() ) { $html .= " " . SMWInfolink::newInversePropertySearchLink( '+', $dataValue->getTitle(), $property->getDataItem()->getLabel(), 'smwsearch' )->getHTML( $linker ); } else { $html .= $dataValue->getInfolinkText( SMW_OUTPUT_HTML, $linker ); } return $html; }
/** * Format a list of articles chunked by letter in a table that shows subject articles in * one column and object articles/values in the other one. */ protected function myShortList(&$articles, &$startChar, $until) { global $wgContLang; $ac = count($articles); if ($ac > $this->limit) { if ($until != '') { $start = 1; } else { $start = 0; $ac = $ac - 1; } } else { $start = 0; } $r = '<table style="width: 100%; ">'; $prevchar = 'None'; for ($index = $start; $index < $ac; $index++) { global $smwgIP; include_once $smwgIP . '/includes/SMW_Infolink.php'; // Header for index letters if ($startChar[$index] != $prevchar) { $r .= '<tr><th class="smwpropname"><h3>' . htmlspecialchars($startChar[$index]) . "</h3></th><th></th></tr>\n"; $prevchar = $startChar[$index]; } $searchlink = SMWInfolink::newBrowsingLink('+', $articles[$index]->getPrefixedText()); $r .= '<tr><td class="smwpropname">' . $this->getSkin()->makeKnownLinkObj($articles[$index], $wgContLang->convert($articles[$index]->getPrefixedText())) . ' ' . $searchlink->getHTML($this->getSkin()) . '</td><td class="smwprops">'; $r .= "</td></tr>\n"; } $r .= '</table>'; return $r; }
/** * 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; }
private function encodePrefixedDBkey() { return Infolink::encodeParameters(array($this->skinTemplate->getSkin()->getTitle()->getPrefixedDBkey()), true); }
/** * Processes the QueryString, Params, and PrintOuts. * * @todo Combine this method with execute() or remove it altogether. */ public function extractParameters($p) { if ($this->context == self::SPECIAL_PAGE) { // assume setParams(), setPintouts and setQueryString have been called $rawParams = array_merge($this->parameters, array($this->queryString), $this->printOutStrings); } else { // context is WIKI_LINK $rawParams = SMWInfolink::decodeParameters($p, true); // calling setParams to fill in missing parameters $this->setParams($rawParams); $rawParams = $this->parameters; } SMWQueryProcessor::processFunctionParams($rawParams, $this->queryString, $this->parameters, $this->printOuts); }
/** * Returns a property list with a specific namespace as HTML table. * @param int $ns ID of the namespace of the properties of interest * (SMW_NS_PROPERTY, SMW_NS_ATTRIBUTE, -1 (=any namespace)) * @param array(Title) $properties All title object whose domain is the * category. * @param boolean $domain If <true> the properties whose domain is this * category are listed. Otherwise those whose range is this * category. * @return string HTML with the table of properties */ private function getPropertyList($ns, $properties, $domain) { global $wgContLang; global $smwgHaloContLang; $props = array(); $store = smwfGetStore(); $sspa = $smwgHaloContLang->getSpecialSchemaPropertyArray(); $relationDV = SMWPropertyValue::makeProperty($sspa[SMW_SSP_HAS_DOMAIN_AND_RANGE_HINT]); $hastypeDV = SMWPropertyValue::makeProperty("_TYPE"); foreach ($properties as $prop) { if (!$prop) { // $prop may be undefined continue; } $propFound = false; if ($prop->getNamespace() == $ns) { // Property with namespace of interest found $props[] = $prop; $propFound = true; } else { if ($prop->getNamespace() != SMW_NS_PROPERTY) { // The property is neither a relation nor an attribute. It is // probably redirected from one of those or it is wrongly annotated // with a domain hint. $titleName = $prop->getText(); $redirects = array(); $redirects[] = $prop; $nsFound = false; // Collect all redirects in an array. while (($rdSource = $this->getRedirectFrom($titleName)) != null) { $redirects[] = $rdSource; if ($rdSource->getNamespace() == $ns) { $nsFound = true; break; } $titleName = $rdSource->getText(); } if ($nsFound === true || $ns == -1) { $props[] = $redirects; $propFound = true; } } } if ($propFound) { // Find the range of the property $range = null; $type = $store->getPropertyValues($prop, $hastypeDV); if (count($type) > 0) { $type = $type[0]; $xsd = array_shift($type->getDBkeys()); if ($xsd != '_wpg') { $range = $type; } } if ($range == null) { $range = $store->getPropertyValues($prop, $relationDV); $rangePageContainers = array(); foreach ($range as $c) { $h = $c->getDVs(); $domainCatValue = reset($h); $rangeCatValue = next($h); if ($rangeCatValue != NULL) { $rangePageContainers[] = $rangeCatValue; } } $range = $rangePageContainers; } $props[] = $range; } } $ac = count($props); if ($ac == 0) { // No properties => return return ""; } $r = ""; $r = '<a name="SMWResults"></a> <div id="mw-pages">'; if ($ns == SMW_NS_PROPERTY) { if ($domain) { $r .= '<h4>' . wfMsg('smw_category_properties', $this->title->getText()) . "</h4>\n"; } else { $r .= '<h4>' . wfMsg('smw_category_properties_range', $this->title->getText()) . "</h4>\n"; } } else { if (count($props) > 0) { // Pages with a domain, that are neither relation nor attribute if ($domain) { $r .= '<h4>' . wfMsg('smw_category_nrna', $this->title->getText()) . "</h4>\n"; $r .= wfMsg('smw_category_nrna_expl') . "\n"; } else { $r .= '<h4>' . wfMsg('smw_category_nrna_range', $this->title->getText()) . "</h4>\n"; $r .= wfMsg('smw_category_nrna_range_expl') . "\n"; } } } $r .= "</div>"; $r .= '<table style="width: 100%;" class="smw-category-schema-table smwtable">'; if ($ns == SMW_NS_PROPERTY) { $r .= '<tr><th>Property</th><th>Range/Type</th></tr>'; } $prevchar = 'None'; for ($index = 0; $index < $ac; $index += 2) { // Property name if (is_array($props[$index])) { // Handle list of redirects $redirects = $props[$index]; $r .= '<tr><td>'; $rc = count($redirects); for ($i = 0; $i < $rc; $i++) { if ($i == 1) { $r .= ' <span class="smw-cat-redirected-from">(redirected from: '; } $rd = $redirects[$i]; $pt = $rd->getPrefixedText(); $searchlink = SMWInfolink::newBrowsingLink('+', $pt); $link = $this->getSkin()->makeKnownLinkObj($rd, $wgContLang->convert($rd->getText())); $link = preg_replace("/(.*?)(href=\".*?)\"(.*)/", "\$1\$2?redirect=no\"\$3", $link); $r .= $link; $r .= $searchlink->getHTML($this->getSkin()) . " "; } if ($rc > 1) { $r .= ')</span>'; } $r .= '</td><td>'; } else { $searchlink = SMWInfolink::newBrowsingLink('+', $props[$index]->getPrefixedText()); $r .= '<tr><td>' . $this->getSkin()->makeKnownLinkObj($props[$index], $wgContLang->convert($props[$index]->getText())) . ' ' . $searchlink->getHTML($this->getSkin()) . '</td><td>'; } // Show the range if (is_array($props[$index + 1])) { $range = $props[$index + 1]; if (count($range) > 0) { ///FIXME this check is just for compatibility reasons and as catch for obscure and buggy code; the class of $range[0] should not vary between different possibilities. if ($range[0] instanceof SMWWikiPageValue) { $r .= $this->getSkin()->makeKnownLinkObj($range[0]->getTitle(), $wgContLang->convert($range[0]->getTitle()->getText())); } elseif ($range[0] instanceof SMWDataValue) { $r .= $range[0]->getShortHTMLText(); } else { $r .= $range[0]; } } } else { if ($props[$index + 1] instanceof SMWTypesValue) { $t = $props[$index + 1]; $t = $t->getTypeLabels(); $r .= $t[0]; } } $r .= "</td></tr>\n"; } $r .= '</table>'; return $r; }
/** * Returns an SMWInfolink object with the QueryResults print requests as parameters. * * @since 1.8 * * @return SMWInfolink */ public function getLink() { $params = array(trim($this->mQuery->getQueryString())); foreach ($this->mQuery->getExtraPrintouts() as $printout) { $serialization = $printout->getSerialisation(); // TODO: this is a hack to get rid of the mainlabel param in case it was automatically added // by SMWQueryProcessor::addThisPrintout. Should be done nicer when this link creation gets redone. if ($serialization !== '?#') { $params[] = $serialization; } } // Note: the initial : prevents SMW from reparsing :: in the query string. return SMWInfolink::newInternalLink('', ':Special:Ask', false, $params); }
/** * Format $diWikiPages chunked by letter in a table that shows subject * articles in one column and object articles/values in the other one. * * @param $diWikiPages array * @return string */ protected function subjectObjectList(array $diWikiPages) { global $wgContLang, $smwgMaxPropertyValues; $ac = count($diWikiPages); if ($ac > $this->limit) { if ($this->until !== '') { $start = 1; } else { $start = 0; $ac = $ac - 1; } } else { $start = 0; } $r = '<table style="width: 100%; ">'; $prev_start_char = 'None'; for ($index = $start; $index < $ac; $index++) { $diWikiPage = $diWikiPages[$index]; $dvWikiPage = DataValueFactory::getInstance()->newDataItemValue($diWikiPage, null); $sortkey = $this->store->getWikiPageSortKey($diWikiPage); $start_char = $wgContLang->convert($wgContLang->firstChar($sortkey)); // Header for index letters if ($start_char != $prev_start_char) { $r .= '<tr><th class="smwpropname"><h3>' . htmlspecialchars($start_char) . "</h3></th><th></th></tr>\n"; $prev_start_char = $start_char; } // Property name $searchlink = SMWInfolink::newBrowsingLink('+', $dvWikiPage->getShortHTMLText()); $r .= '<tr><td class="smwpropname">' . $dvWikiPage->getShortHTMLText(smwfGetLinker()) . ' ' . $searchlink->getHTML(smwfGetLinker()) . '</td><td class="smwprops">'; // Property values $ropts = new SMWRequestOptions(); $ropts->limit = $smwgMaxPropertyValues + 1; $values = $this->store->getPropertyValues($diWikiPage, $this->mProperty, $ropts); $i = 0; foreach ($values as $di) { if ($i != 0) { $r .= ', '; } $i++; if ($i < $smwgMaxPropertyValues + 1) { $dv = DataValueFactory::getInstance()->newDataItemValue($di, $this->mProperty); $r .= $dv->getShortHTMLText(smwfGetLinker()) . $dv->getInfolinkText(SMW_OUTPUT_HTML, smwfGetLinker()); } else { $searchlink = SMWInfolink::newInversePropertySearchLink('…', $dvWikiPage->getWikiValue(), $this->mTitle->getText()); $r .= $searchlink->getHTML(smwfGetLinker()); } } $r .= "</td></tr>\n"; } $r .= '</table>'; return $r; }