/** * 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; }
private function canShowSearchByPropertyLink(DataValue $dataValue) { $dataTypeClass = DataTypeRegistry::getInstance()->getDataTypeClassById($dataValue->getTypeID()); return $this->pageRequestOptions->value instanceof $dataTypeClass && $this->pageRequestOptions->valueString === ''; }
/** * 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; }
/** * Implementation of SMWStore::getInProperties(). This function is meant to * be used for finding properties that link to wiki pages. * @todo When used for other datatypes, the function may return too many * properties since it selects results by comparing the stored information * (DB keys) only, while not currently comparing the type of the returned * property to the type of the queried data. So values with the same DB keys * can be confused. This is a minor issue now since no code is known to use * this function in cases where this occurs. */ public function getInProperties(SMWDataValue $value, $requestoptions = null) { wfProfileIn("SMWSQLStoreLight::getInProperties (SMW)"); $db = wfGetDB(DB_SLAVE); $result = array(); $typeid = $value->getTypeID(); if ($requestoptions !== null) { // potentially need to get more results, since options apply to union $suboptions = clone $requestoptions; $suboptions->limit = $requestoptions->limit + $requestoptions->offset; $suboptions->offset = 0; } else { $suboptions = null; } foreach (array('smwsimple_data', 'smwsimple_special') as $tablename) { if (SMWSQLStoreLight::findTypeTableName($typeid) != $tablename) { continue; } $valuestring = $tablename == 'smwsimple_special' ? reset($value->getDBkeys()) : serialize($value->getDBkeys()); $where = 'value=' . $db->addQuotes($valuestring); $res = $db->select($tablename, 'DISTINCT propname', $where . $this->getSQLConditions($suboptions, 'propname', 'propname'), 'SMW::getInProperties', $this->getSQLOptions($suboptions, 'propname')); foreach ($res as $row) { $result[] = new SMWDIProperty($row->propname); } $db->freeResult($res); } $result = $this->applyRequestOptions($result, $requestoptions); // apply options to overall result wfProfileOut("SMWSQLStoreLight::getInProperties (SMW)"); return $result; }
/** * Hanldes a single property value. Returns an array with data for a single event or false. * * FIXME: 13 arguments, of which a whole bunch are byref... not a good design :) * * @since 1.5.3 * * @param SMWDataValue $object * @param $outputmode * @param SMWPrintRequest $pr * @param boolean $first_col * @param boolean &$hastitle * @param boolean &$hastime * @param boolean $first_value * @param boolean $isEventline * @param string &$curmeta * @param string &$curdata * @param &$date_value * @param boolean &$output * @param array &$positions * * @return false or array */ protected function handlePropertyValue( SMWDataValue $object, $outputmode, SMWPrintRequest $pr, $first_col, &$hastitle, &$hastime, $first_value, $isEventline, &$curmeta, &$curdata, $date_value, &$output, array &$positions ) { global $curarticle, $cururl; $event = false; $l = $this->getLinker( $first_col ); if ( !$hastitle && $object->getTypeID() != '_wpg' ) { // "linking" non-pages in title positions confuses timeline scripts, don't try this $l = null; } if ( $object->getTypeID() == '_wpg' ) { // use shorter "LongText" for wikipage $objectlabel = $object->getLongText( $outputmode, $l ); } else { $objectlabel = $object->getShortText( $outputmode, $l ); } $urlobject = ( $l !== null ); $header = ''; if ( $first_value ) { // find header for current value: if ( $this->mShowHeaders && ( '' != $pr->getLabel() ) ) { $header = $pr->getText( $outputmode, $this->mLinker ) . ': '; } // is this a start date? if ( ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) && ( $date_value == $this->m_tlstart ) ) { // FIXME: Timeline scripts should support XSD format explicitly. They // currently seem to implement iso8601 which deviates from XSD in cases. // NOTE: We can assume $object to be an SMWDataValue in this case. $curmeta .= Html::element( 'span', array( 'class' => 'smwtlstart' ), $object->getXMLSchemaDate() ); $positions[$object->getHash()] = $object->getXMLSchemaDate(); $hastime = true; } // is this the end date? if ( ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) && ( $date_value == $this->m_tlend ) ) { // NOTE: We can assume $object to be an SMWDataValue in this case. $curmeta .= Html::element( 'span', array( 'class' => 'smwtlend' ), $object->getXMLSchemaDate( false ) ); } // find title for displaying event if ( !$hastitle ) { $curmeta .= Html::element( 'span', array( 'class' => $urlobject ? 'smwtlurl' : 'smwtltitle' ), $objectlabel ); if ( $pr->getMode() == SMWPrintRequest::PRINT_THIS ) { $curarticle = $object->getShortText( $outputmode, false ); $cururl = $object->getTitle()->getFullUrl(); } // NOTE: type Title of $object implied $hastitle = true; } } elseif ( $output ) { // it *can* happen that output is false here, if the subject was not printed (fixed subject query) and mutliple items appear in the first row $curdata .= ', '; } if ( !$first_col || !$first_value || $isEventline ) { $curdata .= $header . $objectlabel; $output = true; } if ( $isEventline && ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) && ( $pr->getTypeID() == '_dat' ) && ( '' != $pr->getLabel() ) && ( $date_value != $this->m_tlstart ) && ( $date_value != $this->m_tlend ) ) { $event = array( $object->getXMLSchemaDate(), $pr->getLabel(), $object->getDataItem()->getSortKey(), ); } return $event; }
/** * Handles a single property (SMWPrintRequest) to be displayed for a record (SMWDataValue). * * @since 1.0 * * @param SMWDataValue $object * @param SMWPrintRequest $printRequest * * @return string */ protected function handleResultProperty(SMWDataValue $object, SMWPrintRequest $printRequest) { if ($this->template) { if ($object instanceof SMWWikiPageValue) { return $object->getTitle()->getPrefixedText(); } else { return $object->getLongText(SMW_OUTPUT_WIKI, NULL); } } if ($this->linkAbsolute) { $t = Title::newFromText($printRequest->getHTMLText(NULL), SMW_NS_PROPERTY); if ($t instanceof Title && $t->exists()) { $propertyName = $propertyName = Html::element('a', array('href' => $t->getFullUrl()), $printRequest->getHTMLText(NULL)); } else { $propertyName = $printRequest->getHTMLText(NULL); } } else { $propertyName = $printRequest->getHTMLText(smwfGetLinker()); } if ($this->linkAbsolute) { $hasPage = $object->getTypeID() == '_wpg'; if ($hasPage) { $t = Title::newFromText($object->getLongText($this->outputmode, NULL), NS_MAIN); $hasPage = $t->exists(); } if ($hasPage) { $propertyValue = Html::element('a', array('href' => $t->getFullUrl()), $object->getLongText($this->outputmode, NULL)); } else { $propertyValue = $object->getLongText($this->outputmode, NULL); } } else { $propertyValue = $object->getLongText($this->outputmode, smwfGetLinker()); } return $propertyName . ($propertyName === '' ? '' : ': ') . $propertyValue; }
/** * @since 2.4 * * {@inheritDoc} */ public function isFormatterFor(DataValue $dataValue) { return $dataValue->getTypeID() === '_cod'; }
/** * Removes $value from $values * @param array of SMWDataValue $values The haystack * @param SMWDataValue $value The needle * @return array of SMWDataValue The new haystack */ private function remove_value( /* array of SMWDataValue */ $values, SMWDataValue $value ) { if ( $value->getTypeID() == "_wpg" ) $value = SMWWriterData::resolveRedirect( $value ); $count = count( $values ); for ( $i = 0; $i < $count; $i++ ) if ( $values[$i] != '' && $values[$i]->getHash() === $value->getHash() ) { unset( $values[$i] ); $values = array_values( $values ); return $values; } }