/** * Change the object to become an exact copy of the given * SMWSemanticData object. This is used to make other types of * SMWSemanticData into an SMWContainerSemanticData. To copy objects of * the same type, PHP clone() should be used. * * @since 1.7 * * @param $semanticData SMWSemanticData object to copy from */ public function copyDataFrom(SMWSemanticData $semanticData) { $this->mSubject = $semanticData->getSubject(); $this->mProperties = $semanticData->getProperties(); $this->mPropVals = array(); foreach ($this->mProperties as $property) { $this->mPropVals[$property->getKey()] = $semanticData->getPropertyValues($property); } $this->mHasVisibleProps = $semanticData->hasVisibleProperties(); $this->mHasVisibleSpecs = $semanticData->hasVisibleSpecialProperties(); $this->mNoDuplicates = $semanticData->mNoDuplicates; }
/** * 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; }
/** * Add all data from the given SMWSemanticData. * * @since 1.7 * * @param $semanticData SMWSemanticData object to copy from */ public function importDataFrom(SMWSemanticData $semanticData) { // Shortcut when copying into empty objects that don't ask for more duplicate elimination: if (count($this->mProperties) == 0 && $semanticData->mNoDuplicates >= $this->mNoDuplicates) { $this->mProperties = $semanticData->getProperties(); $this->mPropVals = array(); foreach ($this->mProperties as $property) { $this->mPropVals[$property->getKey()] = $semanticData->getPropertyValues($property); } $this->mHasVisibleProps = $semanticData->hasVisibleProperties(); $this->mHasVisibleSpecs = $semanticData->hasVisibleSpecialProperties(); } else { foreach ($semanticData->getProperties() as $property) { $values = $semanticData->getPropertyValues($property); foreach ($values as $dataItem) { $this->addPropertyObjectValue($property, $dataItem); } } } }
/** * Add all data from the given SMWSemanticData. * Only works if the imported SMWSemanticData has the same subject as * this SMWSemanticData; an exception is thrown otherwise. * * @since 1.7 * @throws MWException if subjects do not match * * @param $semanticData SMWSemanticData object to copy from */ public function importDataFrom(SMWSemanticData $semanticData) { if (!$this->mSubject->equals($semanticData->getSubject())) { throw new MWException("SMWSemanticData can only represent data about one subject. Importing data for another subject is not possible."); } // Shortcut when copying into empty objects that don't ask for // more duplicate elimination: if (count($this->mProperties) == 0 && $semanticData->mNoDuplicates >= $this->mNoDuplicates) { $this->mProperties = $semanticData->getProperties(); $this->mPropVals = array(); foreach ($this->mProperties as $property) { $this->mPropVals[$property->getKey()] = $semanticData->getPropertyValues($property); } $this->mHasVisibleProps = $semanticData->hasVisibleProperties(); $this->mHasVisibleSpecs = $semanticData->hasVisibleSpecialProperties(); } else { foreach ($semanticData->getProperties() as $property) { $values = $semanticData->getPropertyValues($property); foreach ($values as $dataItem) { $this->addPropertyObjectValue($property, $dataItem); } } } foreach ($semanticData->getSubSemanticData() as $semData) { $this->addSubSemanticData($semData); } }
/** * Return true if there are any special properties that can * be displayed. * * @return boolean */ public function hasVisibleSpecialProperties() { $this->unstubProperties(); return parent::hasVisibleSpecialProperties(); }