Beispiel #1
0
 /**
  * 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 .= "&#160;<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>";
 }
Beispiel #2
0
 /**
  * @since 2.1
  *
  * @return string
  */
 public function getForm()
 {
     $content = '';
     foreach ($this->content as $value) {
         $content .= is_callable($value) ? $value($this) : $value;
     }
     if ($this->useFieldset) {
         $content = Xml::fieldset($this->messageBuilder->getMessage($this->name)->text(), $content, array('id' => $this->defaultPrefix . "-fieldset-{$this->name}"));
     }
     $form = Xml::tags('form', array('id' => $this->defaultPrefix . "-{$this->name}", 'name' => $this->name, 'method' => in_array($this->method, array('get', 'post')) ? $this->method : 'get', 'action' => htmlspecialchars($this->actionUrl ? $this->actionUrl : $GLOBALS['wgScript'])), Html::hidden('title', strtok($this->title->getPrefixedText(), '/')) . $content);
     $this->clear();
     return $form;
 }
Beispiel #3
0
 /**
  * Renders table content for a given SMWSemanticData object
  *
  * @since 1.9
  *
  * @param SMWSemanticData $semanticData
  */
 protected function getTableContent(SemanticData $semanticData)
 {
     Profiler::In(__METHOD__);
     // Do exclude some tags from processing otherwise the display
     // can become distorted due to unresolved/open tags (see Bug 23185)
     $excluded = array('table', 'tr', 'th', 'td', 'dl', 'dd', 'ul', 'li', 'ol', 'b', 'sup', 'sub');
     $attributes = array();
     foreach ($semanticData->getProperties() as $propertyDi) {
         $propertyDv = $this->dataValueFactory->newDataItemValue($propertyDi, null);
         if (!$propertyDi->isShown()) {
             // showing this is not desired, hide
             continue;
         } elseif ($propertyDi->isUserDefined()) {
             // User defined property (@note the preg_replace is a slight
             // hack to ensure that the left column does not get too narrow)
             $propertyDv->setCaption(preg_replace('/[ ]/u', '&#160;', $propertyDv->getWikiValue(), 2));
             $attributes['property'] = array('class' => 'smwpropname');
             $attributes['values'] = array('class' => 'smwprops');
         } elseif ($propertyDv->isVisible()) {
             // Predefined property
             $attributes['property'] = array('class' => 'smwspecname');
             $attributes['values'] = array('class' => 'smwspecs');
         } else {
             // predefined, internal property
             // @codeCoverageIgnoreStart
             continue;
             // @codeCoverageIgnoreEnd
         }
         $valuesHtml = array();
         foreach ($semanticData->getPropertyValues($propertyDi) as $dataItem) {
             $dataValue = $this->dataValueFactory->newDataItemValue($dataItem, $propertyDi);
             $dataValue->setServiceLinksRenderState(false);
             if ($dataValue->isValid()) {
                 $valuesHtml[] = Sanitizer::removeHTMLtags($dataValue->getLongWikiText(true), null, array(), array(), $excluded) . $dataValue->getInfolinkText(SMW_OUTPUT_WIKI);
             }
         }
         // Invoke table content
         $this->tableBuilder->addCell($propertyDv->getShortWikiText(true), $attributes['property']);
         $this->tableBuilder->addCell($this->messageBuilder->listToCommaSeparatedText($valuesHtml), $attributes['values']);
         $this->tableBuilder->addRow();
     }
     Profiler::Out(__METHOD__);
 }
Beispiel #4
0
 public function testNullLanguageThrowsException()
 {
     $instance = new MessageBuilder();
     $this->setExpectedException('RuntimeException');
     $instance->getMessage('properties');
 }