/**
	 * @see SMWDescription:getQueryString
	 * 
	 * @since 0.6
	 * 
	 * @param Boolean $asValue
	 */
	public function getQueryString( $asValue = false ) {
		if ( $this->getDataItem() !== null ) {
			$queryString = SMWDataValueFactory::newDataItemValue( $this->getDataItem(), $this->m_property )->getWikiValue();
			return $asValue ? $queryString : "[[$queryString]]";
		} else {
			return $asValue ? '+' : '';
		}
	}
 /**
  * @param $skin
  * @param array $result First item is SMWDIProperty, second item is int
  * 
  * @return string
  */
 function formatResult($skin, $result)
 {
     $linker = smwfGetLinker();
     if ($result[0]->isUserDefined()) {
         $proplink = $linker->makeLinkObj($result[0]->getDiWikiPage()->getTitle(), htmlspecialchars($result[0]->getLabel()), 'action=view');
     } else {
         $proplink = SMWDataValueFactory::newDataItemValue($result[0], new SMWDIProperty('_TYPE'))->getLongHTMLText($linker);
     }
     return wfMsgExt('smw_wantedproperty_template', array('parsemag'), $proplink, $result[1]);
 }
 function formatResult($skin, $result)
 {
     $linker = smwfGetLinker();
     $proplink = $linker->link($result->getDiWikiPage()->getTitle(), $result->getLabel());
     $types = smwfGetStore()->getPropertyValues($result->getDiWikiPage(), new SMWDIProperty('_TYPE'));
     $errors = array();
     if (count($types) >= 1) {
         $typestring = SMWDataValueFactory::newDataItemValue(current($types), new SMWDIProperty('_TYPE'))->getLongHTMLText($linker);
     } else {
         $type = SMWTypesValue::newFromTypeId('_wpg');
         $typestring = $type->getLongHTMLText($linker);
         $errors[] = wfMsg('smw_propertylackstype', $type->getLongHTMLText());
     }
     return wfMsg('smw_unusedproperty_template', $proplink, $typestring) . ' ' . smwfEncodeMessages($errors);
 }
Beispiel #4
0
 /**
  * (non-PHPdoc)
  * @see SMWResultPrinter::getResultText()
  */
 protected function getResultText(SMWQueryResult $res, $outputmode)
 {
     $dataItems = $this->getSortKeys($res);
     if (empty($dataItems)) {
         return $this->params['default'];
     }
     $sortKeys = array_keys($dataItems);
     switch ($this->mFormat) {
         case 'latest':
             $result = max($sortKeys);
             break;
         case 'earliest':
             $result = min($sortKeys);
             break;
     }
     $dataValue = SMWDataValueFactory::newDataItemValue($dataItems[$result], null);
     return $dataValue->getLongHTMLText();
 }
 /**
  *
  * Load all semantic properties of a page as a hash
  * @param String $pagename
  * @param Integer $namespace
  * @param Boolean $normalizeTitle
  * @return an associative array with the property name as key and property value as value.
  */
 public static function &loadSemanticProperties($pagename, $namespace = NS_MAIN, $normalizeTitle = true)
 {
     //-----normalize title
     $data = null;
     if ($normalizeTitle) {
         $title = MWUtil::normalizePageTitle($pagename, false);
         $di = SMWDIWikiPage::newFromTitle($title);
         $data = smwfGetStore()->getSemanticData($di);
     } else {
         $di = new SMWDIWikiPage($pagename, $namespace, '');
         $data = smwfGetStore()->getSemanticData($di);
     }
     $valuehash = array();
     $diProperties = $data->getProperties();
     foreach ($diProperties as $diProperty) {
         $dvProperty = SMWDataValueFactory::newDataItemValue($diProperty, null);
         $name = null;
         if ($dvProperty->isVisible()) {
             $name = $diProperty->getLabel();
         } elseif ($diProperty->getKey() == '_INST') {
             $name = 'Categories';
         } else {
             continue;
             // skip this line
         }
         if (!$name) {
             continue;
         }
         $values = $data->getPropertyValues($diProperty);
         $vs = array();
         foreach ($values as $di) {
             $dv = SMWDataValueFactory::newDataItemValue($di, $diProperty);
             $vs[] = $dv->getWikiValue();
         }
         if (count($vs) == 1) {
             $valuehash[$name] = $vs[0];
         } else {
             $valuehash[$name] = $vs;
         }
     }
     #error_log(print_r($valuehash, true));
     return $valuehash;
 }
Beispiel #6
0
 /**
  * Creates and returns the HTML representatation of the property and it's changes.
  * 
  * @since 0.1
  * 
  * @param SMWDIProperty $property
  * @param array $changes
  * 
  * @return string
  */
 protected static function getPropertyHTML(SMWDIProperty $property, array $changes)
 {
     $insertions = array();
     $deletions = array();
     // Convert the changes into a list of insertions and a list of deletions.
     foreach ($changes as $change) {
         if (!is_null($change->getOldValue())) {
             $deletions[] = SMWDataValueFactory::newDataItemValue($change->getOldValue(), $property)->getShortHTMLText();
         }
         if (!is_null($change->getNewValue())) {
             $insertions[] = SMWDataValueFactory::newDataItemValue($change->getNewValue(), $property)->getShortHTMLText();
         }
     }
     $lines = array();
     if (count($insertions) > 0) {
         $lines[] = Html::element('span', array(), wfMsg('swl-watchlist-insertions')) . ' ' . implode(', ', $insertions);
     }
     if (count($deletions) > 0) {
         $lines[] = Html::element('span', array(), wfMsg('swl-watchlist-deletions')) . ' ' . implode(', ', $deletions);
     }
     $html = Html::element('b', array(), $property->getLabel());
     $html .= Html::rawElement('div', array('class' => 'swl-prop-div'), implode('<br />', $lines));
     return $html;
 }
Beispiel #7
0
 /**
  * Create an SMWExpElement for some internal resource, given by an
  * SMWDIWikiPage object. This is the one place in the code where URIs
  * of wiki pages and user-defined properties are determined. A modifier
  * can be given to make variants of a URI, typically done for
  * auxiliary properties. In this case, the URI is modiied by appending
  * "-23$modifier" where "-23" is the URI encoding of "#" (a symbol not
  * occuring in MW titles).
  *
  * @param $diWikiPage SMWDIWikiPage or SMWDIProperty
  * @param $modifier string, using only Latin letters and numbers
  * @return SMWExpResource
  */
 public static function getResourceElementForWikiPage(SMWDIWikiPage $diWikiPage, $modifier = '')
 {
     global $wgContLang;
     if ($diWikiPage->getNamespace() == NS_MEDIA) {
         // special handling for linking media files directly (object only)
         $title = Title::makeTitle($diWikiPage->getNamespace(), $diWikiPage->getDBkey());
         $file = wfFindFile($title);
         if ($file !== false) {
             return new SMWExpResource($file->getFullURL());
         }
         // else: Medialink to non-existing file :-/ fall through
     }
     if ($diWikiPage->getSubobjectName() !== '') {
         $modifier = $diWikiPage->getSubobjectName();
     }
     if ($modifier === '') {
         $importProperty = new SMWDIProperty('_IMPO');
         $importDis = smwfGetStore()->getPropertyValues($diWikiPage, $importProperty);
         $importURI = count($importDis) > 0;
     } else {
         $importURI = false;
     }
     if ($importURI) {
         $importValue = SMWDataValueFactory::newDataItemValue(current($importDis), $importProperty);
         $namespace = $importValue->getNS();
         $namespaceId = $importValue->getNSID();
         $localName = $importValue->getLocalName();
     } else {
         $localName = '';
         if ($diWikiPage->getNamespace() == SMW_NS_PROPERTY) {
             $namespace = self::getNamespaceUri('property');
             $namespaceId = 'property';
             $localName = self::encodeURI(rawurlencode($diWikiPage->getDBkey()));
         }
         if ($localName === '' || in_array($localName[0], array('-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))) {
             $namespace = self::getNamespaceUri('wiki');
             $namespaceId = 'wiki';
             if ($diWikiPage->getNamespace() !== 0) {
                 $localName = str_replace(' ', '_', $wgContLang->getNSText($diWikiPage->getNamespace())) . ':' . $diWikiPage->getDBkey();
             } else {
                 $localName = $diWikiPage->getDBkey();
             }
             $localName = self::encodeURI(wfUrlencode($localName));
         }
         if ($modifier !== '') {
             $localName .= '-23' . $modifier;
         }
     }
     return new SMWExpNsResource($localName, $namespace, $namespaceId, $diWikiPage);
 }
Beispiel #8
0
 /**
  * Load results of the given print request and result subject. This is only
  * done when needed.
  */
 protected function loadContent()
 {
     if ($this->mContent !== false) {
         return;
     }
     wfProfileIn('SMWQueryResult::loadContent (SMW)');
     switch ($this->mPrintRequest->getMode()) {
         case SMWPrintRequest::PRINT_THIS:
             // NOTE: The limit is ignored here.
             $this->mContent = array($this->mResult);
             break;
         case SMWPrintRequest::PRINT_CATS:
             // Always recompute cache here to ensure output format is respected.
             self::$catCache = $this->mStore->getPropertyValues($this->mResult, new SMWDIProperty('_INST'), $this->getRequestOptions(false));
             self::$catCacheObj = $this->mResult->getHash();
             $limit = $this->mPrintRequest->getParameter('limit');
             $this->mContent = $limit === false ? self::$catCache : array_slice(self::$catCache, 0, $limit);
             break;
         case SMWPrintRequest::PRINT_PROP:
             $propertyValue = $this->mPrintRequest->getData();
             if ($propertyValue->isValid()) {
                 $this->mContent = $this->mStore->getPropertyValues($this->mResult, $propertyValue->getDataItem(), $this->getRequestOptions());
             } else {
                 $this->mContent = array();
             }
             // Print one component of a multi-valued string.
             // Known limitation: the printrequest still is of type _rec, so if printers check
             // for this then they will not recognize that it returns some more concrete type.
             if ($this->mPrintRequest->getTypeID() == '_rec' && $this->mPrintRequest->getParameter('index') !== false) {
                 $pos = $this->mPrintRequest->getParameter('index') - 1;
                 $newcontent = array();
                 foreach ($this->mContent as $diContainer) {
                     /* SMWRecordValue */
                     $recordValue = SMWDataValueFactory::newDataItemValue($diContainer, $propertyValue->getDataItem());
                     $dataItems = $recordValue->getDataItems();
                     if (array_key_exists($pos, $dataItems) && !is_null($dataItems[$pos])) {
                         $newcontent[] = $dataItems[$pos];
                     }
                 }
                 $this->mContent = $newcontent;
             }
             break;
         case SMWPrintRequest::PRINT_CCAT:
             ///NOTE: The limit is ignored here.
             if (self::$catCacheObj != $this->mResult->getHash()) {
                 self::$catCache = $this->mStore->getPropertyValues($this->mResult, new SMWDIProperty('_INST'));
                 self::$catCacheObj = $this->mResult->getHash();
             }
             $found = false;
             $prkey = $this->mPrintRequest->getData()->getDBkey();
             foreach (self::$catCache as $cat) {
                 if ($cat->getDBkey() == $prkey) {
                     $found = true;
                     break;
                 }
             }
             $this->mContent = array(new SMWDIBoolean($found));
             break;
         default:
             $this->mContent = array();
             // Unknown print request.
     }
     reset($this->mContent);
     wfProfileOut('SMWQueryResult::loadContent (SMW)');
 }
 /**
  * Returns all results that have exactly the value on the property.
  *
  * @return array of array of SMWWikiPageValue, SMWDataValue with the first being the entity, and the second the value
  */
 private function getExactResults()
 {
     $options = new SMWRequestOptions();
     $options->limit = $this->limit + 1;
     $options->offset = $this->offset;
     $options->sort = true;
     $res = smwfGetStore()->getPropertySubjects($this->property->getDataItem(), $this->value->getDataItem(), $options);
     $results = array();
     foreach ($res as $result) {
         array_push($results, array(SMWDataValueFactory::newDataItemValue($result, null), $this->value));
     }
     return $results;
 }
 /**
  * Produce a formatted string representation for showing a property in
  * the list of unused properties.
  *
  * @since 1.8
  *
  * @param SMWDIProperty $property
  * @return string
  */
 protected function formatPropertyItem(SMWDIProperty $property)
 {
     $linker = smwfGetLinker();
     $errors = array();
     if ($property->isUserDefined()) {
         $proplink = $linker->link($property->getDiWikiPage()->getTitle(), $property->getLabel());
         $types = smwfGetStore()->getPropertyValues($property->getDiWikiPage(), new SMWDIProperty('_TYPE'));
         if (count($types) >= 1) {
             $typeDataValue = SMWDataValueFactory::newDataItemValue(current($types), new SMWDIProperty('_TYPE'));
         } else {
             $typeDataValue = SMWTypesValue::newFromTypeId('_wpg');
             $errors[] = wfMessage('smw_propertylackstype', $typeDataValue->getLongHTMLText())->text();
         }
         $typeString = $typeDataValue->getLongHTMLText($linker);
     } else {
         $typeid = $property->findPropertyTypeID();
         $typeDataValue = SMWTypesValue::newFromTypeId($typeid);
         $typeString = $typeDataValue->getLongHTMLText($linker);
         $propertyDataValue = SMWDataValueFactory::newDataItemValue($property, null);
         $proplink = $propertyDataValue->getShortHtmlText($linker);
     }
     return wfMessage('smw_unusedproperty_template', $proplink, $typeString)->text() . ' ' . smwfEncodeMessages($errors);
 }
 /**
  * Return a wiki page value that can be used for displaying this
  * property, or null if no such wiki page exists (for predefined
  * properties without any label).
  * @return SMWWikiPageValue or null
  */
 public function getWikiPageValue()
 {
     if (!isset($this->m_wikipage)) {
         $diWikiPage = $this->m_dataitem->getDiWikiPage();
         if (!is_null($diWikiPage)) {
             $this->m_wikipage = SMWDataValueFactory::newDataItemValue($diWikiPage, null, $this->m_caption);
             $this->m_wikipage->setOutputFormat($this->m_outformat);
             $this->addError($this->m_wikipage->getErrors());
         } else {
             // should rarely happen ($value is only changed if the input $value really was a label for a predefined prop)
             $this->m_wikipage = null;
         }
     }
     return $this->m_wikipage;
 }
Beispiel #12
0
 protected function makeOutputText($type = 0, $linker = null)
 {
     if (!$this->isValid()) {
         return $type == 0 || $type == 1 ? '' : $this->getErrorText();
     }
     $result = '';
     $i = 0;
     foreach ($this->getPropertyDataItems() as $propertyDataItem) {
         if ($i == 1) {
             $result .= $type == 4 ? '; ' : ' (';
         } elseif ($i > 1) {
             $result .= $type == 4 ? '; ' : ', ';
         }
         ++$i;
         $propertyValues = $this->m_dataitem->getSemanticData()->getPropertyValues($propertyDataItem);
         // combining this with next line violates PHP strict standards
         $dataItem = reset($propertyValues);
         if ($dataItem !== false) {
             $dataValue = SMWDataValueFactory::newDataItemValue($dataItem, $propertyDataItem);
             $result .= $this->makeValueOutputText($type, $dataValue, $linker);
         } else {
             $result .= '?';
         }
     }
     if ($i > 1 && $type != 4) {
         $result .= ')';
     }
     return $result;
 }
Beispiel #13
0
 /**
  * Returns the iCal for a single item.
  * 
  * @since 1.5.2
  * 
  * @param array $row
  * 
  * @return string
  */
 protected function getIcalForItem(array $row)
 {
     $result = '';
     $wikipage = $row[0]->getResultSubject();
     // get the object
     $wikipage = SMWDataValueFactory::newDataItemValue($wikipage, null);
     $params = array('summary' => $wikipage->getShortWikiText());
     foreach ($row as $field) {
         // later we may add more things like a generic
         // mechanism to add whatever you want :)
         // could include funny things like geo, description etc. though
         $req = $field->getPrintRequest();
         $label = strtolower($req->getLabel());
         switch ($label) {
             case 'start':
             case 'end':
                 if ($req->getTypeID() == '_dat') {
                     $dataValue = $field->getNextDataValue();
                     if ($dataValue === false) {
                         unset($params[$label]);
                     } else {
                         $params[$label] = $dataValue;
                     }
                 }
                 break;
             case 'location':
             case 'description':
             case 'summary':
                 $value = $field->getNextDataValue();
                 if ($value !== false) {
                     $params[$label] = $value->getShortWikiText();
                 }
                 break;
         }
     }
     $title = $wikipage->getTitle();
     $article = new Article($title);
     $url = $title->getFullURL();
     $result .= "BEGIN:VEVENT\r\n";
     $result .= "SUMMARY:" . $params['summary'] . "\r\n";
     $result .= "URL:{$url}\r\n";
     $result .= "UID:{$url}\r\n";
     if (array_key_exists('start', $params)) {
         $result .= "DTSTART:" . $this->parsedate($params['start']) . "\r\n";
     }
     if (array_key_exists('end', $params)) {
         $result .= "DTEND:" . $this->parsedate($params['end'], true) . "\r\n";
     }
     if (array_key_exists('location', $params)) {
         $result .= "LOCATION:" . $params['location'] . "\r\n";
     }
     if (array_key_exists('description', $params)) {
         $result .= "DESCRIPTION:" . $params['description'] . "\r\n";
     }
     $t = strtotime(str_replace('T', ' ', $article->getTimestamp()));
     $result .= "DTSTAMP:" . date("Ymd", $t) . "T" . date("His", $t) . "\r\n";
     $result .= "SEQUENCE:" . $title->getLatestRevID() . "\r\n";
     $result .= "END:VEVENT\r\n";
     return $result;
 }
Beispiel #14
0
 /**
  * Format a list of diWikiPages chunked by letter in a bullet list.
  * 
  * @param $start integer
  * @param $end integer
  * @param $diWikiPages array of SMWDataItem
  * @param $diProperty SMWDIProperty that the wikipages are values of, or null
  * 
  * @return string
  */
 public static function getShortList($start, $end, array $diWikiPages, $diProperty)
 {
     global $wgContLang;
     $startDv = SMWDataValueFactory::newDataItemValue($diWikiPages[$start], $diProperty);
     $sortkey = smwfGetStore()->getWikiPageSortKey($diWikiPages[$start]);
     $startChar = $wgContLang->convert($wgContLang->firstChar($sortkey));
     $r = '<h3>' . htmlspecialchars($startChar) . "</h3>\n" . '<ul><li>' . $startDv->getLongHTMLText(smwfGetLinker()) . '</li>';
     $prevStartChar = $startChar;
     for ($index = $start + 1; $index < $end; $index++) {
         $dataValue = SMWDataValueFactory::newDataItemValue($diWikiPages[$index], $diProperty);
         $sortkey = smwfGetStore()->getWikiPageSortKey($diWikiPages[$index]);
         $startChar = $wgContLang->convert($wgContLang->firstChar($sortkey));
         if ($startChar != $prevStartChar) {
             $r .= "</ul><h3>" . htmlspecialchars($startChar) . "</h3>\n<ul>";
             $prevStartChar = $startChar;
         }
         $r .= '<li>' . $dataValue->getLongHTMLText(smwfGetLinker()) . '</li>';
     }
     $r .= '</ul>';
     return $r;
 }
 protected function getResultText(SMWQueryResult $res, $outputmode)
 {
     /*
      * @todo
      * labels of requested properties could define default values. Seems not possible at the moment because
      * SMWPrintRequest::getLable() always returns the property name even if no specific label is defined.
      */
     $perPage_items = array();
     //for each page:
     while ($row = $res->getNext()) {
         $perProperty_items = array();
         /**
          * first field is always the page title, except, mainlabel is set to '-'
          * @todo Is there some other way to check the data value directly for being the
          *        page title or not? SMWs behavior could change on mainlabel handling...
          */
         $isPageTitle = !$this->mMainLabelHack;
         //for each property on that page:
         foreach ($row as $field) {
             // $row is array(), $field of type SMWResultArray
             $manyValue_items = array();
             $isMissingProperty = false;
             $manyValues = $field->getContent();
             //If property is not set (has no value) on a page:
             if (empty($manyValues)) {
                 $delivery = $this->deliverMissingProperty($field);
                 $manyValue_items = $this->fillDeliveryArray($manyValue_items, $delivery);
                 $isMissingProperty = true;
             } else {
                 //otherwise collect property value (potentially many values):
                 while ($obj = $field->getNextDataValue()) {
                     $value_items = array();
                     $isRecord = false;
                     // handle page Title:
                     if ($isPageTitle) {
                         if (!$this->mShowPageTitles) {
                             $isPageTitle = false;
                             continue 2;
                             //next property
                         }
                         $value_items = $this->fillDeliveryArray($value_items, $this->deliverPageTitle($obj, $this->mLinkFirst));
                     } elseif ($obj instanceof SMWRecordValue) {
                         $recordItems = $obj->getDataItems();
                         // walk all single values of the record set:
                         foreach ($recordItems as $dataItem) {
                             $recordField = $dataItem !== null ? SMWDataValueFactory::newDataItemValue($dataItem, null) : null;
                             $value_items = $this->fillDeliveryArray($value_items, $this->deliverRecordField($recordField, $this->mLinkOthers));
                         }
                         $isRecord = true;
                     } else {
                         $value_items = $this->fillDeliveryArray($value_items, $this->deliverSingleValue($obj, $this->mLinkOthers));
                     }
                     $delivery = $this->deliverSingleManyValuesData($value_items, $isRecord, $isPageTitle);
                     $manyValue_items = $this->fillDeliveryArray($manyValue_items, $delivery);
                 }
             }
             // foreach...
             $delivery = $this->deliverPropertiesManyValues($manyValue_items, $isMissingProperty, $isPageTitle, $field);
             $perProperty_items = $this->fillDeliveryArray($perProperty_items, $delivery);
             $isPageTitle = false;
             // next one could be record or normal value
         }
         // foreach...
         $delivery = $this->deliverPageProperties($perProperty_items);
         $perPage_items = $this->fillDeliveryArray($perPage_items, $delivery);
     }
     // while...
     $output = $this->deliverQueryResultPages($perPage_items);
     return $output;
 }
 protected function makeOutputText($type, $linker = null)
 {
     if (!$this->isValid()) {
         return $type == 0 || $type == 1 ? '' : $this->getErrorText();
     }
     $result = '';
     $sep = $type == 4 ? '; ' : ', ';
     foreach ($this->m_diProperties as $diProperty) {
         if ($result !== '') {
             $result .= $sep;
         }
         $propertyValue = SMWDataValueFactory::newDataItemValue($diProperty, null);
         $result .= $this->makeValueOutputText($type, $propertyValue, $linker);
     }
     return $result;
 }
Beispiel #17
0
 /**
  * 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;
     $store = smwfGetStore();
     $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 = SMWDataValueFactory::newDataItemValue($diWikiPage, null);
         $sortkey = smwfGetStore()->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()) . '&#160;' . $searchlink->getHTML(smwfGetLinker()) . '</td><td class="smwprops">';
         // Property values
         $ropts = new SMWRequestOptions();
         $ropts->limit = $smwgMaxPropertyValues + 1;
         $values = $store->getPropertyValues($diWikiPage, $this->mProperty, $ropts);
         $i = 0;
         foreach ($values as $di) {
             if ($i != 0) {
                 $r .= ', ';
             }
             $i++;
             if ($i < $smwgMaxPropertyValues + 1) {
                 $dv = SMWDataValueFactory::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;
 }
	public function getQueryString( $asvalue = false ) {
		$comparator = SMWQueryLanguage::getStringForComparator( $this->m_comparator );
		$dataValue = SMWDataValueFactory::newDataItemValue( $this->m_dataItem, $this->m_property );
		if ( $asvalue ) {
			return $comparator . $dataValue->getWikiValue();
		} else { // this only is possible for values of Type:Page
			if ( $comparator === '' ) { // some extra care for Category: pages
				return '[[:' . $dataValue->getWikiValue() . ']]';
			} else {
				return '[[' . $comparator . $dataValue->getWikiValue() . ']]';
			}
		}
	}
 /**
  * Creates and returns the HTML representation of the property and it's changes.
  *
  * @since 0.1
  *
  * @param SMWDIProperty $property
  * @param array $changes
  * @param SWLCustomTexts $customTexts
  * @return string
  */
 private static function getPropertyHTML(SMWDIProperty $property, array $changes, $customTexts)
 {
     $insertions = array();
     $deletions = array();
     $customMessages = array();
     $justCustomMessage = false;
     // Convert the changes into a list of insertions and a list of deletions.
     foreach ($changes as $change) {
         $justCustomMessage = false;
         if (!is_null($change->getNewValue()) && $customTexts->getPropertyCustomText($property, $change->getNewValue()->getSerialization())) {
             $customMessages[] = $customTexts->getPropertyCustomText($property, $change->getNewValue()->getSerialization());
             $justCustomMessage = true;
         }
         if (!$justCustomMessage) {
             if (!is_null($change->getOldValue())) {
                 $deletions[] = SMWDataValueFactory::newDataItemValue($change->getOldValue(), $property)->getShortHTMLText();
             }
             if (!is_null($change->getNewValue())) {
                 $insertions[] = SMWDataValueFactory::newDataItemValue($change->getNewValue(), $property)->getShortHTMLText();
             }
         }
     }
     $lines = array();
     if (count($insertions) > 0) {
         $lines[] = Html::element('span', array(), wfMessage('swl-watchlist-insertions')->text()) . ' ' . implode(', ', $insertions);
     }
     if (count($deletions) > 0) {
         $lines[] = Html::element('span', array(), wfMessage('swl-watchlist-deletions')->text()) . ' ' . implode(', ', $deletions);
     }
     foreach ($customMessages as $customMessage) {
         $lines[] = Html::element('span', array(), $customMessage);
     }
     $html = Html::element('b', array(), $property->getLabel());
     $html .= Html::rawElement('div', array('class' => 'swl-prop-div'), implode('<br />', $lines));
     return $html;
 }
Beispiel #20
0
 protected function getResultText(SMWQueryResult $res, $outputmode)
 {
     global $wgParser;
     // No page should embed itself, find out who we are:
     if ($wgParser->getTitle() instanceof Title) {
         $title = $wgParser->getTitle()->getPrefixedText();
     } else {
         // this is likely to be in vain -- this case is typical if we run on special pages
         global $wgTitle;
         $title = $wgTitle->getPrefixedText();
     }
     // print header
     $result = '';
     $footer = '';
     $embstart = '';
     $embend = '';
     $headstart = '';
     $headend = '';
     $this->hasTemplates = true;
     switch ($this->m_embedformat) {
         case 'h1':
         case 'h2':
         case 'h3':
         case 'h4':
         case 'h5':
         case 'h6':
             $headstart = '<' . $this->m_embedformat . '>';
             $headend = '</' . $this->m_embedformat . ">\n";
             break;
         case 'ul':
         case 'ol':
             $result .= '<' . $this->m_embedformat . '>';
             $footer = '</' . $this->m_embedformat . '>';
             $embstart = '<li>';
             $headend = "<br />\n";
             $embend = "</li>\n";
             break;
     }
     // Print all result rows:
     foreach ($res->getResults() as $diWikiPage) {
         if ($diWikiPage instanceof SMWDIWikiPage) {
             // ensure that we deal with title-likes
             $dvWikiPage = SMWDataValueFactory::newDataItemValue($diWikiPage, null);
             $result .= $embstart;
             if ($this->m_showhead) {
                 $result .= $headstart . $dvWikiPage->getLongWikiText($this->mLinker) . $headend;
             }
             if ($dvWikiPage->getLongWikiText() != $title) {
                 if ($diWikiPage->getNamespace() == NS_MAIN) {
                     $result .= '{{:' . $diWikiPage->getDBkey() . '}}';
                 } else {
                     $result .= '{{' . $dvWikiPage->getLongWikiText() . '}}';
                 }
             } else {
                 // block recursion
                 $result .= '<b>' . $dvWikiPage->getLongWikiText() . '</b>';
             }
             $result .= $embend;
         }
     }
     // show link to more results
     if ($this->linkFurtherResults($res)) {
         $result .= $embstart . $this->getFurtherResultsLink($res, $outputmode)->getText(SMW_OUTPUT_WIKI, $this->mLinker) . $embend;
     }
     $result .= $footer;
     return $result;
 }
	/**
	 * Creates the HTML table displaying the data of one subject.
	 *
	 * @param[in] $data SMWSemanticData  The data to be displayed
	 * @param[in] $left bool  Should properties be displayed on the left side?
	 * @param[in] $incoming bool  Is this an incoming? Or an outgoing?
	 *
	 * @return A string containing the HTML with the factbox
	 */
	private function displayData( SMWSemanticData $data, $left = true, $incoming = false ) {
		// Some of the CSS classes are different for the left or the right side.
		// In this case, there is an "i" after the "smwb-". This is set here.
		$ccsPrefix = $left ? 'smwb-' : 'smwb-i';

		$html = "<table class=\"{$ccsPrefix}factbox\" cellpadding=\"0\" cellspacing=\"0\">\n";

		$diProperties = $data->getProperties();
		$noresult = true;
		foreach ( $diProperties as $diProperty ) {
			$dvProperty = SMWDataValueFactory::newDataItemValue( $diProperty, null );

			if ( $dvProperty->isVisible() ) {
				$dvProperty->setCaption( $this->getPropertyLabel( $dvProperty, $incoming ) );
				$proptext = $dvProperty->getShortHTMLText( smwfGetLinker() ) . "\n";
			} elseif ( $diProperty->getKey() == '_INST' ) {
				$proptext = smwfGetLinker()->specialLink( 'Categories' );
			} elseif ( $diProperty->getKey() == '_REDI' ) {
				$proptext = smwfGetLinker()->specialLink( 'Listredirects', 'isredirect' );
			} else {
				continue; // skip this line
			}

			$head  = "<th>" . $proptext . "</th>\n";

			$body  = "<td>\n";

			$values = $data->getPropertyValues( $diProperty );
			if ( $incoming && ( count( $values ) >= SMWSpecialBrowse::$incomingvaluescount ) ) {
				$moreIncoming = true;
				array_pop( $values );
			} else {
				$moreIncoming = false;
			}

			$first = true;
			foreach ( $values as $di ) {
				if ( $first ) {
					$first = false;
				} else {
					$body .= ', ';
				}

				if ( $incoming ) {
					$dv = SMWDataValueFactory::newDataItemValue( $di, null );
				} else {
					$dv = SMWDataValueFactory::newDataItemValue( $di, $diProperty );
				}
				$body .= "<span class=\"{$ccsPrefix}value\">" .
				         $this->displayValue( $dvProperty, $dv, $incoming ) . "</span>\n";
			}

			if ( $moreIncoming ) { // link to the remaining incoming pages:
				$body .= Html::element(
					'a',
					array(
						'href' => SpecialPage::getSafeTitleFor( 'SearchByProperty' )->getLocalURL( array(
							 'property' => $dvProperty->getWikiValue(),
							 'value' => $this->subject->getWikiValue()
						) )
					),
					wfMsg( "smw_browse_more" )
				);

			}

			$body .= "</td>\n";

			// display row
			$html .= "<tr class=\"{$ccsPrefix}propvalue\">\n" .
					( $left ? ( $head . $body ):( $body . $head ) ) . "</tr>\n";
			$noresult = false;
		} // end foreach properties

		if ( $noresult ) {
			$html .= "<tr class=\"smwb-propvalue\"><th> &#160; </th><td><em>" .
			         wfMsg( $incoming ? 'smw_browse_no_incoming':'smw_browse_no_outgoing' ) . "</em></td></tr>\n";
		}
		$html .= "</table>\n";
		return $html;
	}
Beispiel #22
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;
 }
 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 .= '&#160;&#160;&#160;&#160; <b>' . wfMsg('smw_result_results') . ' ' . ($offset + 1) . '– ' . ($offset + min(count($results), $limit)) . '</b>&#160;&#160;&#160;&#160;';
             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 .= ' &#160;' . $browselink->getHTML($linker);
                 }
                 $html .= "</li> \n";
             }
             $html .= "</ul>\n";
         }
         $html .= $navigation;
     }
     // Display query form
     $spectitle = $this->getTitle();
     $html .= '<p>&#160;</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) . '" />' . "&#160;&#160;&#160;\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!
 }
 function formatResult($skin, $result)
 {
     global $wgLang;
     $linker = smwfGetLinker();
     list($property, $useCount) = $result;
     $errors = array();
     $diWikiPage = $property->getDiWikiPage();
     $title = !is_null($diWikiPage) ? $diWikiPage->getTitle() : null;
     if ($property->isUserDefined()) {
         if ($title === null) {
             return '';
         }
         if ($useCount <= 5) {
             $errors[] = wfMessage('smw_propertyhardlyused')->escaped();
         }
         // User defined types default to Page
         global $smwgPDefaultType;
         $typeDataValue = SMWTypesValue::newFromTypeId($smwgPDefaultType);
         $typestring = $typeDataValue->getLongHTMLText($linker);
         $label = htmlspecialchars($property->getLabel());
         if ($title->exists()) {
             $typeProperty = new SMWDIProperty('_TYPE');
             $types = smwfGetStore()->getPropertyValues($diWikiPage, $typeProperty);
             if (count($types) >= 1) {
                 $typeDataValue = SMWDataValueFactory::newDataItemValue(current($types), $typeProperty);
                 $typestring = $typeDataValue->getLongHTMLText($linker);
             } else {
                 $errors[] = wfMessage('smw_propertylackstype')->rawParams($typestring)->escaped();
             }
             $proplink = $linker->link($title, $label);
         } else {
             $errors[] = wfMessage('smw_propertylackspage')->escaped();
             $proplink = $linker->link($title, $label, array(), array('action' => 'view'));
         }
     } else {
         // predefined property
         $typeid = $property->findPropertyTypeID();
         $typeDataValue = SMWTypesValue::newFromTypeId($typeid);
         $typestring = $typeDataValue->getLongHTMLText($linker);
         $propertyDataValue = SMWDataValueFactory::newDataItemValue($property, null);
         $proplink = $propertyDataValue->getShortHtmlText($linker);
     }
     $warnings = smwfEncodeMessages($errors, 'warning', '', false);
     $useCount = $wgLang->formatNum($useCount);
     if ($typestring === '') {
         // Builtins have no type
         // @todo Should use numParams for $useCount?
         return wfMessage('smw_property_template_notype')->rawParams($proplink)->params($useCount)->text() . ' ' . $warnings;
     } else {
         // @todo Should use numParams for $useCount?
         return wfMessage('smw_property_template')->rawParams($proplink, $typestring)->params($useCount)->escaped() . ' ' . $warnings;
     }
 }