예제 #1
0
 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;
 }
예제 #2
0
 /**
  * @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;
 }
예제 #3
0
 /**
  * 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('&gt;', '&lt;'), 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('[', '&#x005B;', $concept_text) . "</pre>\n</div>";
     if (!is_null($wgTitle) && $wgTitle->isSpecialPage()) {
         global $wgOut;
         SMWOutputs::commitToOutputPage($wgOut);
     } else {
         SMWOutputs::commitToParser($parser);
     }
     return $result;
 }
예제 #4
0
 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;
 }
예제 #5
0
 /**
  * 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);
 }
예제 #6
0
 /**
  * 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;
 }
예제 #7
0
 /**
  * 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', '&#160;', $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;
 }
예제 #8
0
/**
 * Callback function for the hook 'smwShowFactbox'. It is called when SMW creates
 * the factbox for an article.
 * This method replaces the whole factbox with a tabbed version that contains
 * the original factbox in one tab and the derived facts in another.
 *
 * @param string $text
 * 		The HTML for the tabbed factbox is returned in this parameter
 * @param SMWSemanticData $semdata
 * 		All static facts for the article
 * @return bool
 * 		<false> : This means that SMW's factbox is completely replaced.
 */
function smwfAddDerivedFacts(&$text, $semdata)
{
    global $smwgHaloScriptPath, $wgContLang;
    wfLoadExtensionMessages('SemanticMediaWiki');
    SMWOutputs::requireHeadItem(SMW_HEADER_STYLE);
    $rdflink = SMWInfolink::newInternalLink(wfMsgForContent('smw_viewasrdf'), $wgContLang->getNsText(NS_SPECIAL) . ':ExportRDF/' . $semdata->getSubject()->getWikiValue(), 'rdflink');
    $browselink = SMWInfolink::newBrowsingLink($semdata->getSubject()->getText(), $semdata->getSubject()->getWikiValue(), 'swmfactboxheadbrowse');
    $fbText = '<div class="smwfact">' . '<span class="smwfactboxhead">' . wfMsgForContent('smw_factbox_head', $browselink->getWikiText()) . '</span>' . '<span class="smwrdflink">' . $rdflink->getWikiText() . '</span>' . '<table class="smwfacttable">' . "\n";
    foreach ($semdata->getProperties() as $property) {
        if (!$property->isShown()) {
            // showing this is not desired, hide
            continue;
        } elseif ($property->isUserDefined()) {
            // user defined property
            $property->setCaption(preg_replace('/[ ]/u', '&nbsp;', $property->getWikiValue(), 2));
            /// NOTE: the preg_replace is a slight hack to ensure that the left column does not get too narrow
            $fbText .= '<tr><td class="smwpropname">' . $property->getLongWikiText(true) . '</td><td class="smwprops">';
        } elseif ($property->isVisible()) {
            // predefined property
            $fbText .= '<tr><td class="smwspecname">' . $property->getLongWikiText(true) . '</td><td class="smwspecs">';
        } else {
            // predefined, internal property
            continue;
        }
        $propvalues = $semdata->getPropertyValues($property);
        $l = count($propvalues);
        $i = 0;
        foreach ($propvalues as $propvalue) {
            if ($i != 0) {
                if ($i > $l - 2) {
                    $fbText .= wfMsgForContent('smw_finallistconjunct') . ' ';
                } else {
                    $fbText .= ', ';
                }
            }
            $i += 1;
            $fbText .= $propvalue->getLongWikiText(true) . $propvalue->getInfolinkText(SMW_OUTPUT_WIKI);
        }
        $fbText .= '</td></tr>';
    }
    $fbText .= '</table></div>';
    $text = '<div id="smw_dft_rendered_boxcontent"> <br />' . '<table>' . '<tr>' . '<td id="dftTab1" class="dftTabActive">' . str_replace(' ', '&nbsp;', wfMsg('smw_df_static_tab')) . '</td>' . '<td class="dftTabSpacer">&nbsp;</td>' . '<td id="dftTab2" class="dftTabInactive">' . str_replace(' ', '&nbsp;', wfMsg('smw_df_derived_tab')) . '</td>' . '<td class="dftTabSpacer" width="100%"></td>' . '</tr>' . '<tr>' . '<td colspan="4" class="dftTabCont">' . '<div id="dftTab1Content" >' . $fbText . '</div>' . '<div id="dftTab2Content" style="display:none">' . '<div id="dftTab2ContentInnerDiv">' . wfMsg('smw_df_loading_df') . '</div>' . '</div>' . '</td>' . '</tr>' . '</table>' . '</div>';
    return false;
}