/** * Returns an array of CustomTexts set by the admin in WatchlistConditions * for this group and property. * * @since 0.2 * * @param SMWDIProperty $property * @param String $newValue * * @return String or false */ public function getPropertyCustomText(SMWDIProperty $property, $newValue) { $this->initCustomTexts(); if (array_key_exists($property->getLabel(), $this->customTexts) && array_key_exists($newValue, $this->customTexts[$property->getLabel()])) { return $this->customTexts[$property->getLabel()][$newValue]; } else { return false; } }
/** * Return an array of SMWLink objects that provide additional resources * for the given value. Captions can contain some HTML markup which is * admissible for wiki text, but no more. Result might have no entries * but is always an array. */ public function getInfolinks() { if ($this->isValid() && !is_null($this->m_property)) { if (!$this->mHasSearchLink) { // add default search link $this->mHasSearchLink = true; $this->m_infolinks[] = SMWInfolink::newPropertySearchLink('+', $this->m_property->getLabel(), $this->getWikiValue()); } if (!$this->mHasServiceLinks && $this->serviceLinksRenderState) { // add further service links $this->addServiceLinks(); } } return $this->m_infolinks; }
public function execute() { global $wgDBtype; if ($this->hasOption('setup')) { $store = new SMWSQLStore3(); // Lets do a drop to ensure the user doesn't has any Store3 tables already (happens when running this script twice) $tables = array('smw_stats'); foreach (SMWSQLStore3::getPropertyTables() as $proptable) { $tables[] = $proptable->name; } $dbw = wfGetDB(DB_MASTER); foreach ($tables as $table) { $name = $dbw->tableName($table); $dbw->query('DROP TABLE ' . ($wgDBtype == 'postgres' ? '' : 'IF EXISTS ') . $name, 'SMWMigrate::drop'); } $store->setup(); //enter user defined properties into smw_stats (internal ones are handled by setup already ) $query = 'Replace into ' . $dbw->tableName('smw_stats') . ' (pid,usage_count) Select smw_id,0 from ' . $dbw->tableName('smw_ids') . ' where smw_namespace = ' . SMW_NS_PROPERTY . ' and smw_iw = "" '; $dbw->query($query, 'SMWMigrate:commandLine'); } elseif ($this->hasOption('migrate')) { $options = array(); if ($this->hasArg(0)) { if ($this->hasArg(1)) { $options['LIMIT'] = $this->getArg(0); $options['OFFSET'] = $this->getArg(1); } } $dbw = wfGetDB(DB_MASTER); $oldStore = new SMWSQLStore2(); $newStore = new SMWSQLStore3(); $proptables = SMWSQLStore3::getPropertyTables(); //get properties $res = $dbw->select('smw_ids', array('smw_id', 'smw_title', 'smw_namespace'), array('smw_namespace' => SMW_NS_PROPERTY), __METHOD__, $options); foreach ($res as $row) { $property = new SMWDIProperty($row->smw_title); echo 'Now migrating data for Property ' . $property->getLabel() . " into Store3 \n"; //get the table $tableId = SMWSQLStore3::findPropertyTableID($property); $proptable = $proptables[$tableId]; //get the DIHandler $dataItemId = SMWDataValueFactory::getDataItemId($property->findPropertyTypeId()); $diHandler = $newStore->getDataItemHandlerForDIType($dataItemId); $subjects = $oldStore->getPropertySubjects($property, null); $insertions = array(); foreach ($subjects as $subject) { $sid = $newStore->makeSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName(), true, str_replace('_', ' ', $subject->getDBkey()) . $subject->getSubobjectName()); //now prepare udpates $propvals = $oldStore->getPropertyValues($subject, $property); $uvals = $proptable->idsubject ? array('s_id' => $sid) : array('s_title' => $subject->getDBkey(), 's_namespace' => $subject->getNamespace()); if ($proptable->fixedproperty == false) { $uvals['p_id'] = $newStore->makeSMWPropertyID($property); } foreach ($propvals as $propval) { $uvals = array_merge($uvals, $diHandler->getInsertValues($propval)); $insertions[] = $uvals; } } // now write to the DB for all subjects (is this too much?) $dbw->insert($proptable->name, $insertions, "SMW::migrate{$proptable->name}"); } $dbw->freeResult($res); } else { echo "Sorry I refuse to work without any options currently"; } }
/** * Properties have a mechanisms for being predefined (i.e. in PHP instead * of in wiki). Special "interwiki" prefixes separate the ids of such * predefined properties from the ids for the current pages (which may, * e.g., be moved, while the predefined object is not movable). */ protected function getPropertyInterwiki(SMWDIProperty $property) { if ($property->isUserDefined()) { return ''; } else { return $property->getLabel() !== '' ? SMW_SQL2_SMWPREDEFIW : SMW_SQL2_SMWINTDEFIW; } }
/** * Properties have a mechanisms for being predefined (i.e. in PHP instead * of in wiki). Special "interwiki" prefixes separate the ids of such * predefined properties from the ids for the current pages (which may, * e.g., be moved, while the predefined object is not movable). * * @todo This documentation is out of date. Right now, the special * interwiki is used only for special properties without a label, i.e., * which cannot be shown to a user. This allows us to filter such cases * from all queries that retrieve lists of properties. It should be * checked that this is really the only use that this has throughout * the code. * * @since 1.8 * @param SMWDIProperty $property * @return string */ public function getPropertyInterwiki(SMWDIProperty $property) { return $property->getLabel() !== '' ? '' : SMW_SQL3_SMWINTDEFIW; }
/** * 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); }
/** * Produce a formatted string representation for showing a property and * its usage count in the list of used properties. * * @since 1.8 * * @param SMWDIProperty $property * @param integer $useCount * @return string */ protected function formatPropertyItem(SMWDIProperty $property, $useCount) { global $wgLang; $linker = smwfGetLinker(); $errors = array(); $diWikiPage = $property->getDiWikiPage(); $title = !is_null($diWikiPage) ? $diWikiPage->getTitle() : null; if ($property->isUserDefined() && is_null($title)) { // Show even messed up property names. $typestring = ''; $proplink = $property->getLabel(); $errors[] = wfMessage('smw_notitle', $property->getLabel())->escaped(); } elseif ($property->isUserDefined()) { 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; } }