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! }
/** * 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; }
/** * 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; }
/** * 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"; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
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); }
/** * 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; }
/** * 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; }
/** * 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', ' ', $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(' ', ' ', wfMsg('smw_df_static_tab')) . '</td>' . '<td class="dftTabSpacer"> </td>' . '<td id="dftTab2" class="dftTabInactive">' . str_replace(' ', ' ', 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; }