/**
  * @see SnakFormatter::formatSnak
  *
  * @param Snak $snak
  *
  * @return string Either plain text, wikitext or HTML, depending on the SnakFormatter provided.
  */
 public function formatSnak(Snak $snak)
 {
     if ($snak instanceof PropertyValueSnak) {
         $value = $snak->getDataValue();
         if ($value instanceof EntityIdValue) {
             $entityId = $value->getEntityId();
             $this->addLabelUsage($value->getEntityId());
             $this->usageAccumulator->addTitleUsage($entityId);
         }
     }
     return $this->snakFormatter->formatSnak($snak);
 }
コード例 #2
0
 /**
  * Format an auto summary argument
  *
  * @since 0.4
  *
  * @param mixed $arg
  *
  * @return string
  */
 protected function formatArg($arg)
 {
     try {
         if ($arg instanceof Snak) {
             return $this->snakFormatter->formatSnak($arg);
         } elseif ($arg instanceof EntityId) {
             return $this->idFormatter->formatEntityId($arg);
         } elseif ($arg instanceof DataValue) {
             return $this->valueFormatter->format($arg);
         } elseif (method_exists($arg, '__toString')) {
             return strval($arg);
         } elseif (is_object($arg)) {
             return '<' . get_class($arg) . '>';
         } elseif (is_array($arg)) {
             if (!empty($arg) && !isset($arg[0])) {
                 // turn assoc array into a list
                 $arg = $this->formatKeyValuePairs($arg);
             }
             $strings = $this->formatArgList($arg);
             return $this->language->commaList($strings);
         } else {
             return strval($arg);
         }
     } catch (Exception $ex) {
         wfWarn(__METHOD__ . ': failed to render value: ' . $ex->getMessage());
     }
     return '?';
 }
 /**
  * @param Snak[] $snaks
  *
  * @return string wikitext
  */
 private function formatSnaks(array $snaks)
 {
     $formattedValues = array();
     foreach ($snaks as $snak) {
         $formattedValues[] = $this->snakFormatter->formatSnak($snak);
     }
     return $this->language->commaList($formattedValues);
 }
 /**
  * Get formatted header for a snak, including the snak's property label and value.
  *
  * @since 0.4
  *
  * @param Snak $snak
  *
  * @return string HTML
  */
 public function getPropertyAndValueHeader(Snak $snak)
 {
     $before = $this->getPropertyHeader($snak);
     try {
         $after = $this->snakBreadCrumbFormatter->formatSnak($snak);
         $result = $this->getColonSeparatedHtml($before, $after);
     } catch (Exception $ex) {
         // just ignore it
         $result = $before;
     }
     return $result;
 }
コード例 #5
0
 /**
  * @fixme handle errors more consistently as done in JS UI, and perhaps add
  * localised exception messages.
  *
  * @param Snak $snak
  * @return string
  */
 private function getFormattedSnakValue($snak)
 {
     try {
         $formattedSnak = $this->snakFormatter->formatSnak($snak);
     } catch (FormattingException $ex) {
         return $this->getInvalidSnakMessage();
     } catch (PropertyDataTypeLookupException $ex) {
         return $this->getPropertyNotFoundMessage();
     } catch (InvalidArgumentException $ex) {
         return $this->getInvalidSnakMessage();
     }
     return $formattedSnak;
 }
 /**
  * @see SnakFormatter::formatSnak
  *
  * @param Snak $snak
  *
  * @throws InvalidArgumentException
  * @throws FormattingException
  * @return string Either plain text, wikitext or HTML, depending on the SnakFormatter provided.
  */
 public function formatSnak(Snak $snak)
 {
     try {
         return $this->snakFormatter->formatSnak($snak);
     } catch (MismatchingDataValueTypeException $ex) {
         if ($ex->getDataValueType() === UnDeserializableValue::getType()) {
             $warningText = $this->formatWarning('wikibase-undeserializable-value');
         } else {
             $warningText = $this->formatWarning('wikibase-snakformatter-valuetype-mismatch', $ex->getDataValueType(), $ex->getExpectedValueType());
         }
     } catch (PropertyDataTypeLookupException $ex) {
         $warningText = $this->formatWarning('wikibase-snakformatter-property-not-found', $snak->getPropertyId()->getSerialization());
     } catch (FormattingException $ex) {
         $warningText = $this->formatWarning('wikibase-snakformatter-formatting-exception', $ex->getMessage());
     }
     if ($snak instanceof PropertyValueSnak && $this->fallbackFormatter) {
         $value = $snak->getDataValue();
         $valueText = $this->fallbackFormatter->format($value);
         if ($valueText !== '') {
             return $valueText . ' ' . $warningText;
         }
     }
     return $warningText;
 }
 /**
  * Render a snak from its serialization as provided from Lua.
  *
  * @since 0.5
  *
  * @param array $snakSerialization As obtained from ItemSerializer
  *
  * @return string wikitext
  */
 public function renderSnak(array $snakSerialization)
 {
     $snak = $this->snakDeserializer->deserialize($snakSerialization);
     return $this->snakFormatter->formatSnak($snak);
 }
コード例 #8
0
 /**
  * @see SnakFormatter::formatSnak
  *
  * @param Snak $snak
  *
  * @return string Typically wikitext or HTML, depending on the $escapeCallback provided.
  */
 public function formatSnak(Snak $snak)
 {
     $text = $this->formatter->formatSnak($snak);
     $escaped = call_user_func($this->escapeCallback, $text);
     return $escaped;
 }