Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialAsk.php |
— | — | @@ -422,7 +422,7 @@ |
423 | 423 | } |
424 | 424 | |
425 | 425 | if ( !isset( $this->m_params[$desckey] ) ) { |
426 | | - $dv = end( smwfGetStore()->getPropertyValues( SMWWikiPageValue::makePageFromTitle( $concept ), SMWPropertyValue::makeProperty( '_CONC' ) ) ); |
| 426 | + $dv = end( smwfGetStore()->getPropertyValues( SMWWikiPageValue::makePageFromTitle( $concept ), new SMWDIProperty( '_CONC' ) ) ); |
427 | 427 | if ( $dv instanceof SMWConceptValue ) { |
428 | 428 | $this->m_params[$desckey] = $dv->getDocu(); |
429 | 429 | } |
Index: trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php |
— | — | @@ -72,7 +72,7 @@ |
73 | 73 | $errors[] = wfMsg( 'smw_propertyhardlyused' ); |
74 | 74 | } |
75 | 75 | if ( $result[0]->isUserDefined() && $result[0]->getWikiPageValue()->getTitle()->exists() ) { // FIXME: this bypasses SMWDataValueFactory; ungood |
76 | | - $types = smwfGetStore()->getPropertyValues( $result[0]->getWikiPageValue(), SMWPropertyValue::makeProperty( '_TYPE' ) ); |
| 76 | + $types = smwfGetStore()->getPropertyValues( $result[0]->getDiWikiPage(), new SMWDIProperty( '_TYPE' ) ); |
77 | 77 | if ( count( $types ) >= 1 ) { |
78 | 78 | $typestring = current( $types )->getLongHTMLText( $skin ); |
79 | 79 | } |
— | — | @@ -87,7 +87,7 @@ |
88 | 88 | $proplink = $result[0]->getLongHTMLText( $skin ); |
89 | 89 | } |
90 | 90 | if ( $typestring == '' ) { |
91 | | - $type = SMWDataValueFactory::newPropertyObjectValue( SMWPropertyValue::makeProperty( '_TYPE' ) ); |
| 91 | + $type = SMWDataValueFactory::newPropertyObjectValue( new SMWDIProperty( '_TYPE' ) ); |
92 | 92 | $type->setDBkeys( array( '_wpg' ) ); |
93 | 93 | $typestring = $type->getLongHTMLText( $skin ); |
94 | 94 | if ( $result[0]->getWikiPageValue()->getTitle()->exists() ) { // print only when we did not print a "nopage" warning yet |
Index: trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialUnusedProperties.php |
— | — | @@ -83,7 +83,7 @@ |
84 | 84 | function formatResult( $skin, $result ) { |
85 | 85 | global $wgLang; |
86 | 86 | $proplink = $skin->makeKnownLinkObj( $result->getWikiPageValue()->getTitle(), $result->getWikiValue() ); |
87 | | - $types = smwfGetStore()->getPropertyValues( $result->getWikiPageValue(), SMWPropertyValue::makeProperty( '_TYPE' ) ); // TODO: do not bypass SMWDataValueFactory! |
| 87 | + $types = smwfGetStore()->getPropertyValues( $result->getWikiPageValue(), new SMWDIProperty( '_TYPE' ) ); // TODO: do not bypass SMWDataValueFactory! |
88 | 88 | $errors = array(); |
89 | 89 | if ( count( $types ) >= 1 ) { |
90 | 90 | $typestring = current( $types )->getLongHTMLText( $skin ); |
Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php |
— | — | @@ -91,7 +91,7 @@ |
92 | 92 | |
93 | 93 | $html .= $this->displayHead(); |
94 | 94 | if ( $this->showoutgoing ) { |
95 | | - $data = smwfGetStore()->getSemanticData( $this->subject ); |
| 95 | + $data = smwfGetStore()->getSemanticData( $this->subject->getDataItem() ); |
96 | 96 | $html .= $this->displayData( $data, $leftside ); |
97 | 97 | $html .= $this->displayCenter(); |
98 | 98 | } |
— | — | @@ -126,16 +126,17 @@ |
127 | 127 | // In this case, there is an "i" after the "smwb-". This is set here. |
128 | 128 | $inv = $left ? '':'i'; |
129 | 129 | $html = "<table class=\"smwb-" . $inv . "factbox\" cellpadding=\"0\" cellspacing=\"0\">\n"; |
130 | | - $properties = $data->getProperties(); |
| 130 | + $diProperties = $data->getProperties(); |
131 | 131 | $noresult = true; |
132 | | - foreach ( $properties as $property ) { |
| 132 | + foreach ( $diProperties as $diProperty ) { |
| 133 | + $dvProperty = SMWDataValueFactory::newDataItemValue( $diProperty ); |
133 | 134 | $displayline = true; |
134 | | - if ( $property->isVisible() ) { |
135 | | - $property->setCaption( $this->getPropertyLabel( $property, $incoming ) ); |
136 | | - $proptext = $property->getShortHTMLText( $skin ) . "\n"; |
137 | | - } elseif ( $property->getPropertyID() == '_INST' ) { |
| 135 | + if ( $dvProperty->isVisible() ) { |
| 136 | + $dvProperty->setCaption( $this->getPropertyLabel( $dvProperty, $incoming ) ); |
| 137 | + $proptext = $dvProperty->getShortHTMLText( $skin ) . "\n"; |
| 138 | + } elseif ( $diProperty->getKey() == '_INST' ) { |
138 | 139 | $proptext = $skin->specialLink( 'Categories' ); |
139 | | - } elseif ( $property->getPropertyID() == '_REDI' ) { |
| 140 | + } elseif ( $diProperty->getKey() == '_REDI' ) { |
140 | 141 | $proptext = $skin->specialLink( 'Listredirects', 'isredirect' ); |
141 | 142 | } else { |
142 | 143 | $displayline = false; |
— | — | @@ -144,16 +145,17 @@ |
145 | 146 | $head = "<th>" . $proptext . "</th>\n"; |
146 | 147 | // display values |
147 | 148 | $body = "<td>\n"; |
148 | | - $values = $data->getPropertyValues( $property ); |
| 149 | + $values = $data->getPropertyValues( $diProperty ); |
149 | 150 | $count = count( $values ); |
150 | 151 | $more = ( $count >= SMWSpecialBrowse::$incomingvaluescount ); |
151 | | - foreach ( $values as $value ) { |
| 152 | + foreach ( $values as $di ) { |
152 | 153 | if ( ( $count == 1 ) && $more && $incoming ) { |
153 | 154 | // if there are more incoming values than a certain treshold, display a link to the rest instead |
154 | | - $body .= '<a href="' . $skin->makeSpecialUrl( 'SearchByProperty', 'property=' . urlencode( $property->getWikiValue() ) . '&value=' . urlencode( $data->getSubject()->getWikiValue() ) ) . '">' . wfMsg( "smw_browse_more" ) . "</a>\n"; |
| 155 | + $body .= '<a href="' . $skin->makeSpecialUrl( 'SearchByProperty', 'property=' . urlencode( $dvProperty->getWikiValue() ) . '&value=' . urlencode( $this->subject->getWikiValue() ) ) . '">' . wfMsg( "smw_browse_more" ) . "</a>\n"; |
155 | 156 | } else { |
| 157 | + $dv = SMWDataValueFactory::newDataItemValue( $di ); |
156 | 158 | $body .= "<span class=\"smwb-" . $inv . "value\">" . |
157 | | - $this->displayValue( $property, $value, $incoming ) . "</span>"; |
| 159 | + $this->displayValue( $dvProperty, $dv, $incoming ) . "</span>"; |
158 | 160 | } |
159 | 161 | $count--; |
160 | 162 | $body .= ( $count > 0 ) ? ", \n":"\n"; |
— | — | @@ -279,19 +281,19 @@ |
280 | 282 | * @return array(SMWSemanticData, bool) The semantic data including all inproperties, and if there are more inproperties left |
281 | 283 | */ |
282 | 284 | private function getInData() { |
283 | | - $indata = new SMWSemanticData( $this->subject ); |
| 285 | + $indata = new SMWSemanticData( $this->subject->getDataItem() ); |
284 | 286 | $options = new SMWRequestOptions(); |
285 | 287 | $options->sort = true; |
286 | 288 | $options->limit = SMWSpecialBrowse::$incomingpropertiescount; |
287 | 289 | if ( $this->offset > 0 ) $options->offset = $this->offset; |
288 | | - $inproperties = smwfGetStore()->getInProperties( $this->subject, $options ); |
| 290 | + $inproperties = smwfGetStore()->getInProperties( $this->subject->getDataItem(), $options ); |
289 | 291 | $more = ( count( $inproperties ) == SMWSpecialBrowse::$incomingpropertiescount ); |
290 | 292 | if ( $more ) array_pop( $inproperties ); // drop the last one |
291 | 293 | $valoptions = new SMWRequestOptions(); |
292 | 294 | $valoptions->sort = true; |
293 | 295 | $valoptions->limit = SMWSpecialBrowse::$incomingvaluescount; |
294 | 296 | foreach ( $inproperties as $property ) { |
295 | | - $values = smwfGetStore()->getPropertySubjects( $property, $this->subject, $valoptions ); |
| 297 | + $values = smwfGetStore()->getPropertySubjects( $property, $this->subject->getDataItem(), $valoptions ); |
296 | 298 | foreach ( $values as $value ) { |
297 | 299 | $indata->addPropertyObjectValue( $property, $value ); |
298 | 300 | } |
— | — | @@ -311,7 +313,7 @@ |
312 | 314 | private function getPropertyLabel( SMWPropertyValue $property, $incoming = false ) { |
313 | 315 | global $smwgBrowseShowInverse; |
314 | 316 | if ( $incoming && $smwgBrowseShowInverse ) { |
315 | | - $oppositeprop = SMWPropertyValue::makeProperty( wfMsg( 'smw_inverse_label_property' ) ); |
| 317 | + $oppositeprop = SMWPropertyValue::makeUserProperty( wfMsg( 'smw_inverse_label_property' ) ); |
316 | 318 | $labelarray = &smwfGetStore()->getPropertyValues( $property->getWikiPageValue(), $oppositeprop ); |
317 | 319 | $rv = ( count( $labelarray ) > 0 ) ? $labelarray[0]->getLongWikiText(): |
318 | 320 | wfMsg( 'smw_inverse_label_default', $property->getWikiValue() ); |
Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialPageProperty.php |
— | — | @@ -50,9 +50,9 @@ |
51 | 51 | } |
52 | 52 | |
53 | 53 | $subject = SMWDataValueFactory::newTypeIDValue( '_wpg', $pagename ); |
54 | | - $pagename = $subject->isValid() ? $subject->getText():''; |
| 54 | + $pagename = $subject->isValid() ? $subject->getText() : ''; |
55 | 55 | $property = SMWPropertyValue::makeUserProperty( $propname ); |
56 | | - $propname = $property->isvalid() ? $property->getWikiValue():''; |
| 56 | + $propname = $property->isvalid() ? $property->getWikiValue() : ''; |
57 | 57 | |
58 | 58 | // Produce output |
59 | 59 | $html = ''; |
— | — | @@ -66,7 +66,7 @@ |
67 | 67 | $options->limit = $limit + 1; |
68 | 68 | $options->offset = $offset; |
69 | 69 | $options->sort = true; |
70 | | - $results = smwfGetStore()->getPropertyValues( $pagename != '' ? $subject:NULL, $property, $options ); |
| 70 | + $results = smwfGetStore()->getPropertyValues( $pagename != '' ? $subject->getDataItem() : null, $property->getDataItem(), $options ); |
71 | 71 | |
72 | 72 | // prepare navigation bar if needed |
73 | 73 | if ( ( $offset > 0 ) || ( count( $results ) > $limit ) ) { |
— | — | @@ -93,12 +93,13 @@ |
94 | 94 | } else { |
95 | 95 | $html .= "<ul>\n"; |
96 | 96 | $count = $limit + 1; |
97 | | - foreach ( $results as $result ) { |
| 97 | + foreach ( $results as $di ) { |
98 | 98 | $count--; |
99 | 99 | if ( $count < 1 ) continue; |
100 | | - $html .= '<li>' . $result->getLongHTMLText( $skin ); // do not show infolinks, the magnifier "+" is ambiguous with the browsing '+' for '_wpg' (see below) |
101 | | - if ( $result->getTypeID() == '_wpg' ) { |
102 | | - $browselink = SMWInfolink::newBrowsingLink( '+', $result->getLongWikiText() ); |
| 100 | + $dv = SMWDataValueFactory::newDataItemValue( $di ); |
| 101 | + $html .= '<li>' . $dv->getLongHTMLText( $skin ); // do not show infolinks, the magnifier "+" is ambiguous with the browsing '+' for '_wpg' (see below) |
| 102 | + if ( $di->getTypeID() == '_wpg' ) { |
| 103 | + $browselink = SMWInfolink::newBrowsingLink( '+', $dv->getLongWikiText() ); |
103 | 104 | $html .= '  ' . $browselink->getHTML( $skin ); |
104 | 105 | } |
105 | 106 | $html .= "</li> \n"; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php |
— | — | @@ -53,7 +53,7 @@ |
54 | 54 | * This function retrieves the SMW data from a given parser, and creates |
55 | 55 | * a new empty container if it is not initiated yet. |
56 | 56 | * |
57 | | - * @retun SMWSemanticData |
| 57 | + * @return SMWSemanticData |
58 | 58 | */ |
59 | 59 | static public function getSMWdata( $parser ) { |
60 | 60 | $output = self::getOutput( $parser ); |
— | — | @@ -66,7 +66,7 @@ |
67 | 67 | |
68 | 68 | // No data container yet. |
69 | 69 | if ( !isset( $output->mSMWData ) ) { |
70 | | - $output->mSMWData = new SMWSemanticData( SMWWikiPageValue::makePageFromTitle( $title ) ); |
| 70 | + $output->mSMWData = new SMWSemanticData( new SMWDIWikiPage( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki() ) ); |
71 | 71 | } |
72 | 72 | |
73 | 73 | return $output->mSMWData; |
— | — | @@ -85,7 +85,7 @@ |
86 | 86 | return; |
87 | 87 | } |
88 | 88 | |
89 | | - $output->mSMWData = new SMWSemanticData( SMWWikiPageValue::makePageFromTitle( $title ) ); |
| 89 | + $output->mSMWData = new SMWSemanticData( new SMWDIWikiPage( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki() ) ); |
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
— | — | @@ -108,18 +108,18 @@ |
109 | 109 | global $smwgContLang; |
110 | 110 | |
111 | 111 | // See if this property is a special one, such as e.g. "has type". |
112 | | - $property = SMWPropertyValue::makeUserProperty( $propertyName ); |
113 | | - $result = SMWDataValueFactory::newPropertyObjectValue( $property, $value, $caption ); |
| 112 | + $propertyDv = SMWPropertyValue::makeUserProperty( $propertyName ); |
| 113 | + $propertyDi = $propertyDv->getDataItem(); |
| 114 | + $result = SMWDataValueFactory::newPropertyObjectValue( $propertyDi, $value, $caption ); |
114 | 115 | |
115 | | - if ( $property->isInverse() ) { |
| 116 | + if ( $propertyDi->isInverse() ) { |
116 | 117 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
117 | 118 | $result->addError( wfMsgForContent( 'smw_noinvannot' ) ); |
118 | 119 | } elseif ( $storeAnnotation && ( self::getSMWData( $parser ) !== null ) ) { |
119 | | - self::getSMWData( $parser )->addPropertyObjectValue( $property, $result ); |
120 | | - |
| 120 | + self::getSMWData( $parser )->addPropertyObjectValue( $propertyDi, $result->getDataItem() ); |
121 | 121 | // Take note of the error for storage (do this here and not in storage, thus avoiding duplicates). |
122 | 122 | if ( !$result->isValid() ) { |
123 | | - self::getSMWData( $parser )->addPropertyObjectValue( SMWPropertyValue::makeProperty( '_ERRP' ), $property->getWikiPageValue() ); |
| 123 | + self::getSMWData( $parser )->addPropertyObjectValue( new SMWDIProperty( '_ERRP' ), $propertyDi->getDiWikiPage() ); |
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
— | — | @@ -156,16 +156,18 @@ |
157 | 157 | $processSemantics = smwfIsSemanticsProcessed( $namespace ); |
158 | 158 | |
159 | 159 | if ( !isset( $semdata ) ) { // no data at all? |
160 | | - $semdata = new SMWSemanticData( SMWWikiPageValue::makePageFromTitle( $title ) ); |
| 160 | + $semdata = new SMWSemanticData( new SMWDIWikiPage( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki() ) ); |
161 | 161 | } |
162 | 162 | |
163 | 163 | if ( $processSemantics ) { |
164 | | - $pmdat = SMWPropertyValue::makeProperty( '_MDAT' ); |
| 164 | + $pmdat = new SMWDIProperty( '_MDAT' ); |
165 | 165 | |
166 | 166 | if ( count( $semdata->getPropertyValues( $pmdat ) ) == 0 ) { // no article data present yet, add it here |
167 | 167 | $timestamp = $smwgMW_1_14 ? Revision::getTimeStampFromID( $title, $title->getLatestRevID() ) : Revision::getTimeStampFromID( $title->getLatestRevID() ); |
168 | | - $dv = SMWDataValueFactory::newPropertyObjectValue( $pmdat, $wgContLang->sprintfDate( 'd M Y G:i:s', $timestamp ) ); |
169 | | - $semdata->addPropertyObjectValue( $pmdat, $dv ); |
| 168 | + $di = self::getDataItemFromMWTimestamp( $timestamp ); |
| 169 | + if ( $di !== null ) { |
| 170 | + $semdata->addPropertyObjectValue( $pmdat, $di ); |
| 171 | + } |
170 | 172 | } |
171 | 173 | } else { // data found, but do all operations as if it was empty |
172 | 174 | $semdata = new SMWSemanticData( $semdata->getSubject() ); |
— | — | @@ -180,7 +182,7 @@ |
181 | 183 | |
182 | 184 | if ( $makejobs && $smwgEnableUpdateJobs && ( $namespace == SMW_NS_PROPERTY ) ) { |
183 | 185 | // If it is a property, then we need to check if the type or the allowed values have been changed. |
184 | | - $ptype = SMWPropertyValue::makeProperty( '_TYPE' ); |
| 186 | + $ptype = new SMWDIProperty( '_TYPE' ); |
185 | 187 | $oldtype = smwfGetStore()->getPropertyValues( $title, $ptype ); |
186 | 188 | $newtype = $semdata->getPropertyValues( $ptype ); |
187 | 189 | |
— | — | @@ -188,7 +190,7 @@ |
189 | 191 | $updatejobflag = true; |
190 | 192 | } else { |
191 | 193 | foreach ( $smwgDeclarationProperties as $prop ) { |
192 | | - $pv = SMWPropertyValue::makeProperty( $prop ); |
| 194 | + $pv = new SMWDIProperty( $prop ); |
193 | 195 | $oldvalues = smwfGetStore()->getPropertyValues( $semdata->getSubject(), $pv ); |
194 | 196 | $newvalues = $semdata->getPropertyValues( $pv ); |
195 | 197 | $updatejobflag = !self::equalDatavalues( $oldvalues, $newvalues ); |
— | — | @@ -196,7 +198,7 @@ |
197 | 199 | } |
198 | 200 | |
199 | 201 | if ( $updatejobflag ) { |
200 | | - $prop = SMWPropertyValue::makeProperty( $title->getDBkey() ); |
| 202 | + $prop = new SMWDIProperty( $title->getDBkey() ); |
201 | 203 | $subjects = smwfGetStore()->getAllPropertySubjects( $prop ); |
202 | 204 | |
203 | 205 | foreach ( $subjects as $subject ) { |
— | — | @@ -204,7 +206,7 @@ |
205 | 207 | } |
206 | 208 | wfRunHooks( 'smwUpdatePropertySubjects', array( &$jobs ) ); |
207 | 209 | |
208 | | - $subjects = smwfGetStore()->getPropertySubjects( SMWPropertyValue::makeProperty( '_ERRP' ), $prop->getWikiPageValue() ); |
| 210 | + $subjects = smwfGetStore()->getPropertySubjects( new SMWDIProperty( '_ERRP' ), $prop->getWikiPageValue() ); |
209 | 211 | |
210 | 212 | foreach ( $subjects as $subject ) { |
211 | 213 | $jobs[] = new SMWUpdateJob( $subject->getTitle() ); |
— | — | @@ -212,8 +214,8 @@ |
213 | 215 | } |
214 | 216 | } elseif ( $makejobs && $smwgEnableUpdateJobs && ( $namespace == SMW_NS_TYPE ) ) { |
215 | 217 | // if it is a type we need to check if the conversion factors have been changed |
216 | | - $pconv = SMWPropertyValue::makeProperty( '_CONV' ); |
217 | | - $ptype = SMWPropertyValue::makeProperty( '_TYPE' ); |
| 218 | + $pconv = new SMWDIProperty( '_CONV' ); |
| 219 | + $ptype = new SMWDIProperty( '_TYPE' ); |
218 | 220 | |
219 | 221 | $oldfactors = smwfGetStore()->getPropertyValues( $semdata->getSubject(), $pconv ); |
220 | 222 | $newfactors = $semdata->getPropertyValues( $pconv ); |
— | — | @@ -228,7 +230,7 @@ |
229 | 231 | |
230 | 232 | foreach ( $proppages as $proppage ) { |
231 | 233 | $jobs[] = new SMWUpdateJob( $proppage->getTitle() ); |
232 | | - $prop = SMWPropertyValue::makeProperty( $proppage->getDBkey() ); |
| 234 | + $prop = new SMWDIProperty( $proppage->getDBkey() ); |
233 | 235 | $subjects = $store->getAllPropertySubjects( $prop ); |
234 | 236 | |
235 | 237 | foreach ( $subjects as $subject ) { |
— | — | @@ -236,7 +238,7 @@ |
237 | 239 | } |
238 | 240 | |
239 | 241 | $subjects = smwfGetStore()->getPropertySubjects( |
240 | | - SMWPropertyValue::makeProperty( '_ERRP' ), |
| 242 | + new SMWDIProperty( '_ERRP' ), |
241 | 243 | $prop->getWikiPageValue() |
242 | 244 | ); |
243 | 245 | |
— | — | @@ -309,6 +311,7 @@ |
310 | 312 | /** |
311 | 313 | * Hook function fetches category information and other final settings from parser output, |
312 | 314 | * so that they are also replicated in SMW for more efficient querying. |
| 315 | + * @bug Sortkey currently not stored. Needs to be done differently now. |
313 | 316 | */ |
314 | 317 | static public function onParserAfterTidy( &$parser, &$text ) { |
315 | 318 | global $smwgUseCategoryHierarchy, $smwgCategoriesAsInstances; |
— | — | @@ -318,25 +321,23 @@ |
319 | 322 | } |
320 | 323 | |
321 | 324 | $categories = $parser->mOutput->getCategoryLinks(); |
322 | | - |
323 | | - foreach ( $categories as $name ) { |
| 325 | + foreach ( $categories as $catname ) { |
324 | 326 | if ( $smwgCategoriesAsInstances && ( self::getSMWData( $parser )->getSubject()->getNamespace() != NS_CATEGORY ) ) { |
325 | | - $pinst = SMWPropertyValue::makeProperty( '_INST' ); |
326 | | - $dv = SMWDataValueFactory::newPropertyObjectValue( $pinst ); |
327 | | - $dv->setValues( $name, NS_CATEGORY ); |
328 | | - self::getSMWData( $parser )->addPropertyObjectValue( $pinst, $dv ); |
| 327 | + $pinst = new SMWDIProperty( '_INST' ); |
| 328 | + $categoryDi = new SMWDIWikiPage( $catname, NS_CATEGORY, '' ); |
| 329 | + self::getSMWData( $parser )->addPropertyObjectValue( $pinst, $categoryDi ); |
329 | 330 | } |
330 | 331 | |
331 | 332 | if ( $smwgUseCategoryHierarchy && ( self::getSMWData( $parser )->getSubject()->getNamespace() == NS_CATEGORY ) ) { |
332 | | - $psubc = SMWPropertyValue::makeProperty( '_SUBC' ); |
333 | | - $dv = SMWDataValueFactory::newPropertyObjectValue( $psubc ); |
334 | | - $dv->setValues( $name, NS_CATEGORY ); |
335 | | - self::getSMWData( $parser )->addPropertyObjectValue( $psubc, $dv ); |
| 333 | + $psubc = new SMWDIProperty( '_SUBC' ); |
| 334 | + $categoryDi = new SMWDIWikiPage( $catname, NS_CATEGORY, '' ); |
| 335 | + self::getSMWData( $parser )->addPropertyObjectValue( $psubc, $categoryDi ); |
336 | 336 | } |
337 | 337 | } |
338 | 338 | |
339 | | - $sortkey = ( $parser->mDefaultSort ? $parser->mDefaultSort : self::getSMWData( $parser )->getSubject()->getText() ); |
340 | | - self::getSMWData( $parser )->getSubject()->setSortkey( $sortkey ); |
| 339 | +// $sortkey = ( $parser->mDefaultSort ? $parser->mDefaultSort : |
| 340 | +// str_replace( '_', ' ', self::getSMWData( $parser )->getSubject()->getDBkey() ) ); |
| 341 | +// self::getSMWData( $parser )->getSubject()->setSortkey( $sortkey ); |
341 | 342 | |
342 | 343 | return true; |
343 | 344 | } |
— | — | @@ -363,7 +364,7 @@ |
364 | 365 | return true; // nothing we can do |
365 | 366 | } |
366 | 367 | if ( !isset( $output->mSMWData ) ) { // no data container yet, make one |
367 | | - $output->mSMWData = new SMWSemanticData( SMWWikiPageValue::makePageFromTitle( $title ) ); |
| 368 | + $output->mSMWData = new SMWSemanticData( new SMWDIWikiPage( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki() ) ); |
368 | 369 | } |
369 | 370 | |
370 | 371 | $semdata = $output->mSMWData; |
— | — | @@ -371,20 +372,13 @@ |
372 | 373 | return true; |
373 | 374 | } |
374 | 375 | |
375 | | - $pmdat = SMWPropertyValue::makeProperty( '_MDAT' ); |
376 | | - |
377 | | - // create a date string that is certainly parsable in the current language: |
| 376 | + $pmdat = new SMWDIProperty( '_MDAT' ); |
378 | 377 | $timestamp = $article->getTimestamp(); |
| 378 | + $di = self::getDataItemFromMWTimestamp( $timestamp ); |
| 379 | + if ( $di !== null ) { |
| 380 | + $semdata->addPropertyObjectValue( $pmdat, $di ); |
| 381 | + } |
379 | 382 | |
380 | | - $date = $wgContLang->sprintfDate( 'd ', $timestamp ) . |
381 | | - $smwgContLang->getMonthLabel( ( $wgContLang->sprintfDate( 'm', $timestamp ) + 0 ) ) . |
382 | | - $wgContLang->sprintfDate( ' Y G:i:s', $timestamp ); |
383 | | - $dv = SMWDataValueFactory::newPropertyObjectValue( $pmdat, $date ); |
384 | | - |
385 | | - // The below method is not safe, since "M" as used in MW may not be the month label as used in SMW if SMW falls back to some other language: |
386 | | - // $dv = SMWDataValueFactory::newPropertyObjectValue( $pmdat, $wgContLang->sprintfDate( 'd M Y G:i:s', $article->getTimestamp() ) ); |
387 | | - $semdata->addPropertyObjectValue( $pmdat, $dv ); |
388 | | - |
389 | 383 | return true; |
390 | 384 | } |
391 | 385 | |
— | — | @@ -426,4 +420,27 @@ |
427 | 421 | return true; // always return true, in order not to stop MW's hook processing! |
428 | 422 | } |
429 | 423 | |
| 424 | + /** |
| 425 | + * Create an SMWDITime object from a MediaWiki timestamp. A timestamp |
| 426 | + * is a 14 character string YYYYMMDDhhmmss. |
| 427 | + * |
| 428 | + * @param $timestamp string MediaWiki timestamp |
| 429 | + * @return SWMDITime object or null if errors occurred |
| 430 | + */ |
| 431 | + static protected function getDataItemFromMWTimestamp( $timestamp ) { |
| 432 | + $year = intval( substr( $timestamp, 0, 4 ) ); |
| 433 | + $month = intval( substr( $timestamp, 4, 2 ) ); |
| 434 | + $day = intval( substr( $timestamp, 6, 2 ) ); |
| 435 | + $hour = intval( substr( $timestamp, 8, 2 ) ); |
| 436 | + $min = intval( substr( $timestamp, 10, 2 ) ); |
| 437 | + $sec = intval( substr( $timestamp, 12, 2 ) ); |
| 438 | + try { |
| 439 | + return new SMWDITime( $year, $month, $day, $hour, $min, $sec ); |
| 440 | + } catch ( SMWDataItemException $e ) { |
| 441 | + // we rely on MW timestamp format above -- if it ever changes, |
| 442 | + // exceptions might possibly occur but this should not prevent editing |
| 443 | + return null; |
| 444 | + } |
| 445 | + } |
| 446 | + |
430 | 447 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Record_Descriptions.php |
— | — | @@ -77,7 +77,7 @@ |
78 | 78 | protected $m_position; |
79 | 79 | |
80 | 80 | public function __construct( $position, SMWDescription $description ) { |
81 | | - parent::__construct( SMWPropertyValue::makeProperty( '_' . ( $position + 1 ) ), $description ); |
| 81 | + parent::__construct( new SMWDIProperty( '_' . ( $position + 1 ) ), $description ); |
82 | 82 | $this->m_position = $position; |
83 | 83 | } |
84 | 84 | |
Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_ExportController.php |
— | — | @@ -136,23 +136,23 @@ |
137 | 137 | * features like recursive export or backlinks that are available for this |
138 | 138 | * type of data. |
139 | 139 | * |
140 | | - * @param SMWWikiPageValue $value specifying the page to be exported |
| 140 | + * @param SMWDIWikiPage $diWikiPage specifying the page to be exported |
141 | 141 | * @param integer $recursiondepth specifying the depth of recursion, see |
142 | 142 | * SMWSmallTitle::$recdepth |
143 | 143 | */ |
144 | | - protected function serializePage( SMWWikiPageValue $value, $recursiondepth = 1 ) { |
| 144 | + protected function serializePage( SMWDIWikiPage $diWikiPage, $recursiondepth = 1 ) { |
145 | 145 | $st = new SMWSmallTitle(); |
146 | | - $st->dbkey = $value->getDBKey(); |
147 | | - $st->namespace = $value->getNamespace(); |
| 146 | + $st->dbkey = $diWikiPage->getDBKey(); |
| 147 | + $st->namespace = $diWikiPage->getNamespace(); |
148 | 148 | $st->recdepth = $recursiondepth; |
149 | 149 | if ( $this->isDone( $st ) ) return; // do not export twice |
150 | 150 | $this->markAsDone( $st ); |
151 | | - $data = SMWExporter::makeExportData( $this->getSemanticData( $value, ( $recursiondepth == 0 ) ) ); |
| 151 | + $data = SMWExporter::makeExportData( $this->getSemanticData( $diWikiPage, ( $recursiondepth == 0 ) ) ); |
152 | 152 | $this->serializer->serializeExpData( $data, $recursiondepth ); |
153 | 153 | |
154 | 154 | // let other extensions add additional RDF data for this page |
155 | 155 | $additionalDataArray = array(); |
156 | | - wfRunHooks( 'smwAddToRDFExport', array( $value->getTitle(), &$additionalDataArray, ( $recursiondepth != 0 ), $this->add_backlinks ) ); |
| 156 | + wfRunHooks( 'smwAddToRDFExport', array( $diWikiPage, &$additionalDataArray, ( $recursiondepth != 0 ), $this->add_backlinks ) ); |
157 | 157 | foreach ( $additionalDataArray as $additionalData ) { |
158 | 158 | $this->serializer->serializeExpData( $additionalData ); // serialise |
159 | 159 | } |
— | — | @@ -186,12 +186,13 @@ |
187 | 187 | // if they were serialised at recdepth 0 only). |
188 | 188 | if ( $this->add_backlinks ) { |
189 | 189 | wfProfileIn( "RDF::PrintPages::GetBacklinks" ); |
190 | | - $inprops = smwfGetStore()->getInProperties( $value ); |
| 190 | + $inprops = smwfGetStore()->getInProperties( $diWikiPage ); |
191 | 191 | foreach ( $inprops as $inprop ) { |
192 | | - if ( $inprop->getWikiPageValue() instanceof SMWWikiPageValue ) { |
193 | | - $this->queuePage( $inprop->getWikiPageValue(), 0 ); // no real recursion along properties |
| 192 | + $propWikiPage = $inprop->getDiWikiPage(); |
| 193 | + if ( $propWikiPage !== null ) { |
| 194 | + $this->queuePage( $propWikiPage, 0 ); // no real recursion along properties |
194 | 195 | } |
195 | | - $inSubs = smwfGetStore()->getPropertySubjects( $inprop, $value ); |
| 196 | + $inSubs = smwfGetStore()->getPropertySubjects( $inprop, $diWikiPage ); |
196 | 197 | foreach ( $inSubs as $inSub ) { |
197 | 198 | $stb = new SMWSmallTitle(); |
198 | 199 | $stb->dbkey = $inSub->getDBkey(); |
— | — | @@ -199,18 +200,18 @@ |
200 | 201 | $stb->recdepth = $subrecdepth; |
201 | 202 | if ( !$this->isDone($stb) ) { |
202 | 203 | $semdata = $this->getSemanticData( $inSub, true ); |
203 | | - $semdata->addPropertyObjectValue( $inprop, $value ); |
| 204 | + $semdata->addPropertyObjectValue( $inprop, $diWikiPage ); |
204 | 205 | $data = SMWExporter::makeExportData( $semdata ); |
205 | 206 | $this->serializer->serializeExpData( $data, $subrecdepth ); |
206 | 207 | } |
207 | 208 | } |
208 | 209 | } |
209 | 210 | |
210 | | - if ( NS_CATEGORY === $value->getNamespace() ) { // also print elements of categories |
| 211 | + if ( NS_CATEGORY === $diWikiPage->getNamespace() ) { // also print elements of categories |
211 | 212 | $options = new SMWRequestOptions(); |
212 | 213 | $options->limit = 100; // Categories can be large, always use limit |
213 | | - $instances = smwfGetStore()->getPropertySubjects( SMWPropertyValue::makeProperty( '_INST' ), $value, $options ); |
214 | | - $pinst = SMWPropertyValue::makeProperty( '_INST' ); |
| 214 | + $instances = smwfGetStore()->getPropertySubjects( new SMWDIProperty( '_INST' ), $diWikiPage, $options ); |
| 215 | + $pinst = new SMWDIProperty( '_INST' ); |
215 | 216 | |
216 | 217 | foreach ( $instances as $instance ) { |
217 | 218 | $stb = new SMWSmallTitle(); |
— | — | @@ -219,20 +220,20 @@ |
220 | 221 | |
221 | 222 | if ( !array_key_exists( $stb->getHash(), $this->element_done ) ) { |
222 | 223 | $semdata = $this->getSemanticData( $instance, true ); |
223 | | - $semdata->addPropertyObjectValue( $pinst, $value ); |
| 224 | + $semdata->addPropertyObjectValue( $pinst, $diWikiPage ); |
224 | 225 | $data = SMWExporter::makeExportData( $semdata ); |
225 | 226 | $this->serializer->serializeExpData( $data, $subrecdepth ); |
226 | 227 | } |
227 | 228 | } |
228 | | - } elseif ( SMW_NS_CONCEPT === $value->getNamespace() ) { // print concept members (slightly different code) |
229 | | - $desc = new SMWConceptDescription( $value->getTitle() ); |
| 229 | + } elseif ( SMW_NS_CONCEPT === $diWikiPage->getNamespace() ) { // print concept members (slightly different code) |
| 230 | + $desc = new SMWConceptDescription( $diWikiPage ); |
230 | 231 | $desc->addPrintRequest( new SMWPrintRequest( SMWPrintRequest::PRINT_THIS, '' ) ); |
231 | 232 | $query = new SMWQuery( $desc ); |
232 | 233 | $query->setLimit( 100 ); |
233 | 234 | |
234 | 235 | $res = smwfGetStore()->getQueryResult( $query ); |
235 | 236 | $resarray = $res->getNext(); |
236 | | - $pinst = SMWPropertyValue::makeProperty( '_INST' ); |
| 237 | + $pinst = new SMWDIProperty( '_INST' ); |
237 | 238 | |
238 | 239 | while ( $resarray !== false ) { |
239 | 240 | $instance = end( $resarray )->getNextObject(); |
— | — | @@ -243,7 +244,7 @@ |
244 | 245 | |
245 | 246 | if ( !array_key_exists( $stb->getHash(), $this->element_done ) ) { |
246 | 247 | $semdata = $this->getSemanticData( $instance, true ); |
247 | | - $semdata->addPropertyObjectValue( $pinst, $value ); |
| 248 | + $semdata->addPropertyObjectValue( $pinst, $diWikiPage ); |
248 | 249 | $data = SMWExporter::makeExportData( $semdata ); |
249 | 250 | $this->serializer->serializeExpData( $data ); |
250 | 251 | } |
— | — | @@ -263,17 +264,17 @@ |
264 | 265 | */ |
265 | 266 | protected function serializeSmallTitle( SMWSmallTitle $st ) { |
266 | 267 | if ( $this->isDone( $st ) ) return; // do not export twice |
267 | | - $value = SMWWikiPageValue::makePage( $st->dbkey, $st->namespace ); |
268 | | - $this->serializePage( $value, $st->recdepth ); |
| 268 | + $diWikiPage = new SMWDIWikiPage( $st->dbkey, $st->namespace, '' ); |
| 269 | + $this->serializePage( $diWikiPage, $st->recdepth ); |
269 | 270 | } |
270 | 271 | |
271 | 272 | /** |
272 | | - * Add a given SMWWikiPageValue to the export queue if needed. |
| 273 | + * Add a given SMWDIWikiPage to the export queue if needed. |
273 | 274 | */ |
274 | | - protected function queuePage( SMWWikiPageValue $pagevalue, $recursiondepth ) { |
| 275 | + protected function queuePage( SMWDIWikiPage $diWikiPage, $recursiondepth ) { |
275 | 276 | $spt = new SMWSmallTitle(); |
276 | | - $spt->dbkey = $pagevalue->getDBkey(); |
277 | | - $spt->namespace = $pagevalue->getNamespace(); |
| 277 | + $spt->dbkey = $diWikiPage->getDBkey(); |
| 278 | + $spt->namespace = $diWikiPage->getNamespace(); |
278 | 279 | $spt->recdepth = $recursiondepth; |
279 | 280 | if ( !$this->isDone( $spt ) ) { |
280 | 281 | $this->element_queue[$spt->getHash()] = $spt; |
— | — | @@ -318,12 +319,12 @@ |
319 | 320 | * and we do not want to modify the store's result which may be used for |
320 | 321 | * caching purposes elsewhere. |
321 | 322 | */ |
322 | | - protected function getSemanticData( $pagevalue, $core_props_only ) { |
323 | | - $semdata = smwfGetStore()->getSemanticData( $pagevalue, $core_props_only ? array( '__spu', '__typ', '__imp' ) : false ); // advise store to retrieve only core things |
| 323 | + protected function getSemanticData( SMWDIWikiPage $diWikiPage, $core_props_only ) { |
| 324 | + $semdata = smwfGetStore()->getSemanticData( $diWikiPage, $core_props_only ? array( '__spu', '__typ', '__imp' ) : false ); // advise store to retrieve only core things |
324 | 325 | if ( $core_props_only ) { // be sure to filter all non-relevant things that may still be present in the retrieved |
325 | | - $result = new SMWSemanticData( $pagevalue ); |
| 326 | + $result = new SMWSemanticData( $diWikiPage ); |
326 | 327 | foreach ( array( '_URI', '_TYPE', '_IMPO' ) as $propid ) { |
327 | | - $prop = SMWPropertyValue::makeProperty( $propid ); |
| 328 | + $prop = new SMWDIProperty( $propid ); |
328 | 329 | $values = $semdata->getPropertyValues( $prop ); |
329 | 330 | foreach ( $values as $dv ) { |
330 | 331 | $result->addPropertyObjectValue( $prop, $dv ); |
Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exporter.php |
— | — | @@ -48,7 +48,7 @@ |
49 | 49 | SMWExporter::initBaseURIs(); |
50 | 50 | $subject = $semdata->getSubject(); |
51 | 51 | if ( $subject->getNamespace() == SMW_NS_PROPERTY ) { |
52 | | - $types = $semdata->getPropertyValues( SMWPropertyValue::makeProperty( '_TYPE' ) ); |
| 52 | + $types = $semdata->getPropertyValues( new SMWDIProperty( '_TYPE' ) ); |
53 | 53 | } else { |
54 | 54 | $types = array(); |
55 | 55 | } |
— | — | @@ -66,10 +66,10 @@ |
67 | 67 | * can be used to pass a particular SMWTypesValue object that is used |
68 | 68 | * for determining the OWL type for property pages. |
69 | 69 | * |
70 | | - * @param SMWWikiPageValue $subject |
| 70 | + * @param SMWDIWikiPage $subject |
71 | 71 | * @param mixed $typesvalueforproperty either an SMWTypesValue or null |
72 | 72 | */ |
73 | | - static public function makeExportDataForSubject( SMWWikiPageValue $subject, $typesvalueforproperty = null ) { |
| 73 | + static public function makeExportDataForSubject( SMWDIWikiPage $subject, $typesvalueforproperty = null ) { |
74 | 74 | $result = $subject->getExportData(); |
75 | 75 | switch ( $subject->getNamespace() ) { |
76 | 76 | case NS_CATEGORY: case SMW_NS_CONCEPT: |
— | — | @@ -78,7 +78,7 @@ |
79 | 79 | break; |
80 | 80 | case SMW_NS_PROPERTY: |
81 | 81 | if ( $typesvalueforproperty == null ) { |
82 | | - $types = smwfGetStore()->getPropertyValues( $subject, SMWPropertyValue::makeProperty( '_TYPE' ) ); |
| 82 | + $types = smwfGetStore()->getPropertyValues( $subject, new SMWDIProperty( '_TYPE' ) ); |
83 | 83 | $typesvalueforproperty = end( $types ); |
84 | 84 | } |
85 | 85 | $maintype_pe = SMWExporter::getSpecialElement( 'owl', SMWExporter::getOWLPropertyType( $typesvalueforproperty ) ); |
— | — | @@ -103,14 +103,14 @@ |
104 | 104 | |
105 | 105 | /** |
106 | 106 | * Extend a given SMWExpData element by adding export data for the |
107 | | - * specified property values. This method is called when constructing |
108 | | - * export data structures from SMWSemanticData objects. |
| 107 | + * specified property data itme. This method is called when |
| 108 | + * constructing export data structures from SMWSemanticData objects. |
109 | 109 | * |
110 | | - * @param SMWPropertyValue $property |
| 110 | + * @param SMWDIProperty $property |
111 | 111 | * @param array $values of SMWDataValue objects for the given property |
112 | 112 | * @param SMWExpData $data to add the data to |
113 | 113 | */ |
114 | | - static public function addPropertyValues(SMWPropertyValue $property, $values, SMWExpData &$data) { |
| 114 | + static public function addPropertyValues(SMWDIProperty $property, $values, SMWExpData &$data) { |
115 | 115 | if ( $property->isUserDefined() ) { |
116 | 116 | $pe = SMWExporter::getResourceElement( $property ); |
117 | 117 | foreach ( $values as $dv ) { |
— | — | @@ -161,7 +161,7 @@ |
162 | 162 | if ( $pe === null ) return; // unknown special property, not exported |
163 | 163 | foreach ( $values as $dv ) { |
164 | 164 | if ( $cat_only ) { |
165 | | - if ( !( $dv instanceof SMWWikiPageValue ) || ( $dv->getNamespace() != NS_CATEGORY ) ) { |
| 165 | + if ( !( $dv instanceof SMWDIWikiPage ) || ( $dv->getNamespace() != NS_CATEGORY ) ) { |
166 | 166 | continue; |
167 | 167 | } |
168 | 168 | } |
— | — | @@ -185,25 +185,23 @@ |
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
189 | | - * Create an SMWExpElement for some internal resource, given by a Title or |
190 | | - * SMWWikiPageValue object. Returns null on error. |
| 189 | + * Create an SMWExpElement for some internal resource, given by an |
| 190 | + * SMWDIWikiPage or SMWDIProperty object. Returns null on error. |
191 | 191 | * This is the one place in the code where URIs of wiki pages and |
192 | 192 | * properties are defined. |
193 | 193 | * |
194 | | - * @param mixed Title or SMWWikiPagevalue or SMWPropertyValues |
195 | | - * @return SMWExpResource |
| 194 | + * @param mixed SMWDIWikiPage or SMWDIProperty |
| 195 | + * @return SMWExpResource or null |
196 | 196 | */ |
197 | | - static public function getResourceElement( $resource ) { |
198 | | - if ( $resource instanceof SMWWikiPageValue ) { |
| 197 | + static public function getResourceElement( SMWDataItem $resource ) { |
| 198 | + if ( $resource instanceof SMWDIWikiPage ) { |
199 | 199 | $dv = $resource; |
200 | | - } elseif ( $resource instanceof SMWPropertyValue ) { |
| 200 | + } elseif ( $resource instanceof SMWDIProperty ) { |
201 | 201 | $dv = $resource->getWikiPageValue(); |
202 | | - } elseif ( $resource instanceof Title ) { |
203 | | - $dv = SMWWikiPageValue::makePageFromTitle( $resource ); |
204 | 202 | } else { |
205 | 203 | return null; |
206 | 204 | } |
207 | | - $idvs = smwfGetStore()->getPropertyValues( $dv, SMWPropertyValue::makeProperty( '_IMPO' ) ); |
| 205 | + $idvs = smwfGetStore()->getPropertyValues( $dv, new SMWDIProperty( '_IMPO' ) ); |
208 | 206 | if ( count( $idvs ) > 0 ) { |
209 | 207 | $namespace = current( $idvs )->getNS(); |
210 | 208 | $namespaceid = current( $idvs )->getNSID(); |
— | — | @@ -326,5 +324,63 @@ |
327 | 325 | return $data; |
328 | 326 | } |
329 | 327 | |
| 328 | + /** |
| 329 | + * Create an SWMExpData container that encodes the data of the given |
| 330 | + * datavalue object. |
| 331 | + * |
| 332 | + * @param SMWDataValue $dv the datavalue to encode |
| 333 | + */ |
| 334 | + static public function getDVExpData( SMWDataValue $dv ) { |
| 335 | + if ( !$dv->isValid() ) return null; |
330 | 336 | |
| 337 | + switch ( $dv->getBaseType() ) { |
| 338 | + case SMWDataValue::TYPE_NUMBER: |
| 339 | + $lit = new SMWExpLiteral( $dv->getNumber(), $dv, 'http://www.w3.org/2001/XMLSchema#double' ); |
| 340 | + return new SMWExpData( $lit ); |
| 341 | + break; |
| 342 | + case SMWDataValue::TYPE_STRING: case SMWDataValue::TYPE_BLOB: |
| 343 | + $lit = new SMWExpLiteral( smwfHTMLtoUTF8( $dv->getWikiText() ), $dv, 'http://www.w3.org/2001/XMLSchema#string' ); |
| 344 | + return new SMWExpData( $lit ); |
| 345 | + break; |
| 346 | + case SMWDataValue::TYPE_BOOL: |
| 347 | + $xsdvalue = $dv->getBoolean() ? 'true' : 'false'; |
| 348 | + $lit = new SMWExpLiteral( $xsdvalue, $dv, 'http://www.w3.org/2001/XMLSchema#boolean' ); |
| 349 | + return new SMWExpData( $lit ); |
| 350 | + break; |
| 351 | + case SMWDataValue::TYPE_URI: |
| 352 | + /// TODO This escaping seems very odd. The serialisation should handle such things. |
| 353 | + $res = new SMWExpResource( str_replace( '&', '&', $dv->getURI() ), $dv ); |
| 354 | + return new SMWExpData( $res ); |
| 355 | + break; |
| 356 | + case SMWDataValue::TYPE_TIME: |
| 357 | + $lit = new SMWExpLiteral( $dv->getXMLSchemaDate(), $dv, 'http://www.w3.org/2001/XMLSchema#dateTime' ); |
| 358 | + return new SMWExpData( $lit ); |
| 359 | + break; |
| 360 | + case SMWDataValue::TYPE_GEO: |
| 361 | + /// TODO |
| 362 | + break; |
| 363 | + case SMWDataValue::TYPE_CONT: |
| 364 | + /// TODO |
| 365 | + break; |
| 366 | + case SMWDataValue::TYPE_PAGE: |
| 367 | + if ( $dv->getNamespace() == NS_MEDIA ) { // special handling for linking media files directly (object only) |
| 368 | + $file = wfFindFile( $dv->getTitle() ); |
| 369 | + if ( $file !== false ) { |
| 370 | + return new SMWExpData( new SMWExpResource( $file->getFullURL(), $this ) ); |
| 371 | + } else { // Medialink to non-existing file :-/ |
| 372 | + return null; |
| 373 | + } |
| 374 | + } else { |
| 375 | + return new SMWExpData( SMWExporter::getResourceElement( $dv ) ); |
| 376 | + } |
| 377 | + break; |
| 378 | + case SMWDataValue::TYPE_CONCEPT: |
| 379 | + /// TODO |
| 380 | + break; |
| 381 | + case SMWDataValue::TYPE_PROP: |
| 382 | + return new SMWExpData( SMWExporter::getResourceElement( $dv->getWikiPageValue() ) ); |
| 383 | + break; |
| 384 | + } |
| 385 | + } |
| 386 | + |
331 | 387 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php |
— | — | @@ -48,29 +48,6 @@ |
49 | 49 | */ |
50 | 50 | abstract class SMWDataValue { |
51 | 51 | |
52 | | - /// Primitive type for numbers as implemented by SMWNumberValue |
53 | | - const TYPE_NUMBER = 1; |
54 | | - /// Primitive type for plain strings as implemented by SMWImportValue, SMWStringValue, SMWTypeListValue, SMW_ErrorValue |
55 | | - const TYPE_STRING = 2; |
56 | | - /// Primitive type Blob (long string) implemented by SMWStringValue |
57 | | - const TYPE_BLOB = 3; |
58 | | - /// Primitive type Boolean as implemented by SMWBoolValue |
59 | | - const TYPE_BOOL = 4; |
60 | | - /// Primitive type URI as implemented by SMWURIValue |
61 | | - const TYPE_URI = 5; |
62 | | - /// Primitive type Time as implemented by SMWTimeValue |
63 | | - const TYPE_TIME = 6; |
64 | | - /// Primitive type Geographic coordinate as implemented |
65 | | - const TYPE_GEO = 7; |
66 | | - /// Primitive type Container as implemented by SMWContainerValue |
67 | | - const TYPE_CONT = 8; |
68 | | - /// Primitive type for pages as implemented by SMWPageValue |
69 | | - const TYPE_PAGE = 9; |
70 | | - /// Primitive type Concept as implemented by SMWConceptValue |
71 | | - const TYPE_CONCEPT = 10; |
72 | | - /// Primitive type representing a property implemented by SMWPropertyValue |
73 | | - const TYPE_PROP = 11; |
74 | | - |
75 | 52 | /** |
76 | 53 | * Associated data item. This is the reference to the immutable object |
77 | 54 | * that represents the current data content. All other data stored here |
— | — | @@ -100,7 +77,7 @@ |
101 | 78 | * True if a value was set. |
102 | 79 | * @var boolean |
103 | 80 | */ |
104 | | - protected $m_isset = false; |
| 81 | + private $m_isset; |
105 | 82 | |
106 | 83 | /** |
107 | 84 | * The type id for this value object. |
— | — | @@ -176,11 +153,10 @@ |
177 | 154 | public function setUserValue( $value, $caption = false ) { |
178 | 155 | wfProfileIn( 'SMWDataValue::setUserValue (SMW)' ); |
179 | 156 | |
180 | | - $this->m_dataitem = null; |
| 157 | + unset( $this->m_dataitem ); |
181 | 158 | $this->mErrors = array(); // clear errors |
182 | 159 | $this->mHasErrors = false; |
183 | 160 | $this->m_infolinks = array(); // clear links |
184 | | - $this->m_isset = false; |
185 | 161 | $this->mHasSearchLink = false; |
186 | 162 | $this->mHasServiceLinks = false; |
187 | 163 | $this->m_stubvalues = false; |
— | — | @@ -193,7 +169,6 @@ |
194 | 170 | // Note: \x07 was used in MediaWiki 1.11.0, \x7f is used now |
195 | 171 | if ( ( strpos( $value, "\x7f" ) === false ) && ( strpos( $value, "\x07" ) === false ) ) { |
196 | 172 | $this->parseUserValue( $value ); // may set caption if not set yet, depending on datavalue |
197 | | - $this->m_isset = true; |
198 | 173 | } else { |
199 | 174 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
200 | 175 | $this->addError( wfMsgForContent( 'smw_parseerror' ) ); |
— | — | @@ -219,6 +194,7 @@ |
220 | 195 | * @param array $args |
221 | 196 | */ |
222 | 197 | public function setDBkeys( array $args ) { |
| 198 | + throw new Exception( "setDBkeys() must no longer be called." ); |
223 | 199 | $this->mErrors = array(); // clear errors |
224 | 200 | $this->mHasErrors = false; |
225 | 201 | $this->m_infolinks = array(); // clear links |
— | — | @@ -226,7 +202,6 @@ |
227 | 203 | $this->mHasServiceLinks = false; |
228 | 204 | $this->m_caption = false; |
229 | 205 | $this->m_stubvalues = $args; |
230 | | - $this->m_isset = true; |
231 | 206 | } |
232 | 207 | |
233 | 208 | /** |
— | — | @@ -237,24 +212,24 @@ |
238 | 213 | * It takes only very little effort if unstubbing is not needed. |
239 | 214 | */ |
240 | 215 | protected function unstub() { |
241 | | - if ( $this->m_stubvalues !== false ) { |
242 | | - wfProfileIn( 'SMWDataValue::unstub-' . $this->m_typeid . ' (SMW)' ); |
243 | | - |
244 | | - $args = $this->m_stubvalues; |
245 | | - $this->m_stubvalues = false; // Careful to avoid recursive unstubbing. |
246 | | - $this->parseDBkeys( $args ); |
247 | | - |
248 | | - wfProfileOut( 'SMWDataValue::unstub-' . $this->m_typeid . ' (SMW)' ); |
249 | | - } |
| 216 | +// if ( $this->m_stubvalues !== false ) { |
| 217 | +// wfProfileIn( 'SMWDataValue::unstub-' . $this->m_typeid . ' (SMW)' ); |
| 218 | +// |
| 219 | +// $args = $this->m_stubvalues; |
| 220 | +// $this->m_stubvalues = false; // Careful to avoid recursive unstubbing. |
| 221 | +// $this->parseDBkeys( $args ); |
| 222 | +// |
| 223 | +// wfProfileOut( 'SMWDataValue::unstub-' . $this->m_typeid . ' (SMW)' ); |
| 224 | +// } |
250 | 225 | } |
251 | 226 | |
252 | 227 | /** |
253 | 228 | * Specify the property to which this value refers. Used to generate search links and |
254 | 229 | * to find custom settings that relate to the property. |
255 | 230 | * |
256 | | - * @param SMWPropertyValue $property |
| 231 | + * @param SMWDIProperty $property |
257 | 232 | */ |
258 | | - public function setProperty( SMWPropertyValue $property ) { |
| 233 | + public function setProperty( SMWDIProperty $property ) { |
259 | 234 | $this->m_property = $property; |
260 | 235 | } |
261 | 236 | |
— | — | @@ -299,7 +274,7 @@ |
300 | 275 | } |
301 | 276 | |
302 | 277 | array_unshift( $args, '' ); // add a 0 element as placeholder |
303 | | - $servicelinks = smwfGetStore()->getPropertyValues( $this->m_property->getWikiPageValue(), SMWPropertyValue::makeProperty( '_SERV' ) ); |
| 278 | + $servicelinks = smwfGetStore()->getPropertyValues( $this->m_property->getWikiPageValue(), new SMWDIProperty( '_SERV' ) ); |
304 | 279 | |
305 | 280 | foreach ( $servicelinks as $dv ) { |
306 | 281 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
— | — | @@ -453,13 +428,39 @@ |
454 | 429 | /** |
455 | 430 | * Get the actual data contained in this object or null if the data is |
456 | 431 | * not defined (due to errors or due to not being set at all). |
| 432 | + * @note Most implementations ensure that a data item is always set, |
| 433 | + * even if errors occurred, to avoid additional checks for not |
| 434 | + * accessing null. Hence, one must not assume that a non-null return |
| 435 | + * value here implies that isValid() returns true. |
| 436 | + * |
457 | 437 | * @return SMWDataItem |
458 | 438 | */ |
459 | 439 | public function getDataItem() { |
460 | | - return $this->m_dataitem; |
| 440 | + if ( $this->isValid() ) { |
| 441 | + return $this->m_dataitem; |
| 442 | + } else { |
| 443 | + return new SMWDIError( $this->mErrors ); |
| 444 | + } |
461 | 445 | } |
462 | 446 | |
463 | 447 | /** |
| 448 | + * Set the actual data contained in this object. The method returns |
| 449 | + * true if this was successful (requiring the type of the dataitem |
| 450 | + * to match the data value). If false is returned, the data value is |
| 451 | + * left unchanged (the data item was rejected). |
| 452 | + * |
| 453 | + * @note Even if this function returns true, the data value object |
| 454 | + * might become invalid if the content of the data item caused errors |
| 455 | + * in spite of it being of the right basic type. False is only returned |
| 456 | + * if the data item is fundamentally incompatible with the data value. |
| 457 | + * |
| 458 | + * @param $dataitem SMWDataItem |
| 459 | + * @return boolean |
| 460 | + * @bug This method must get some wrapper to reset basic values of this class. Currently, things like error messages are kept. |
| 461 | + */ |
| 462 | + abstract public function setDataItem( SMWDataItem $dataItem ); |
| 463 | + |
| 464 | + /** |
464 | 465 | * Return an array of values that characterize the given datavalue |
465 | 466 | * completely, and that are sufficient to reproduce a value of identical |
466 | 467 | * content using the function setDBkeys(). The value array must use number |
— | — | @@ -760,7 +761,7 @@ |
761 | 762 | */ |
762 | 763 | public function isValid() { |
763 | 764 | $this->unstub(); |
764 | | - return ( ( !$this->mHasErrors ) && $this->m_isset ); |
| 765 | + return ( ( !$this->mHasErrors ) && isset( $this->m_dataitem ) ); |
765 | 766 | } |
766 | 767 | |
767 | 768 | /** |
— | — | @@ -801,36 +802,36 @@ |
802 | 803 | * Creates an error if the value is illegal. |
803 | 804 | */ |
804 | 805 | protected function checkAllowedValues() { |
805 | | - if ( ( $this->m_property === null ) || ( $this->m_property->getWikiPageValue() === null ) ) { |
806 | | - return; // no property known |
| 806 | + if ( ( $this->m_property === null ) || ( $this->m_property->getDiWikiPage() === null ) || ( !isset( $this->m_dataitem ) ) ) { |
| 807 | + return; // no property known, or no data to check |
807 | 808 | } |
808 | 809 | |
809 | 810 | $allowedvalues = smwfGetStore()->getPropertyValues( |
810 | | - $this->m_property->getWikiPageValue(), |
811 | | - SMWPropertyValue::makeProperty( '_PVAL' ) |
| 811 | + $this->m_property->getDiWikiPage(), |
| 812 | + new SMWDIProperty( '_PVAL' ) |
812 | 813 | ); |
813 | 814 | |
814 | 815 | if ( count( $allowedvalues ) == 0 ) { |
815 | 816 | return; |
816 | 817 | } |
817 | 818 | |
818 | | - $hash = $this->getHash(); |
819 | | - $value = SMWDataValueFactory::newTypeIDValue( $this->getTypeID() ); |
| 819 | + $hash = $this->m_dataitem->getHash(); |
| 820 | + $testdv = SMWDataValueFactory::newTypeIDValue( $this->getTypeID() ); |
820 | 821 | $accept = false; |
821 | 822 | $valuestring = ''; |
| 823 | + foreach ( $allowedvalues as $di ) { |
| 824 | + if ( $di->getDIType() === SMWDataItem::TYPE_STRING ) { |
| 825 | + $testdv->setUserValue( $di->getString() ); |
822 | 826 | |
823 | | - foreach ( $allowedvalues as $stringvalue ) { |
824 | | - $value->setUserValue( $stringvalue->getWikiValue() ); |
825 | | - |
826 | | - if ( $hash === $value->getHash() ) { |
827 | | - $accept = true; |
828 | | - break; |
829 | | - } else { |
830 | | - if ( $valuestring != '' ) { |
831 | | - $valuestring .= ', '; |
| 827 | + if ( $hash === $testdv->getDataItem()->getHash() ) { |
| 828 | + $accept = true; |
| 829 | + break; |
| 830 | + } else { |
| 831 | + if ( $valuestring != '' ) { |
| 832 | + $valuestring .= ', '; |
| 833 | + } |
| 834 | + $valuestring .= $di->getString(); |
832 | 835 | } |
833 | | - |
834 | | - $valuestring .= $value->getShortWikiText(); |
835 | 836 | } |
836 | 837 | } |
837 | 838 | |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php |
— | — | @@ -196,11 +196,12 @@ |
197 | 197 | * |
198 | 198 | * @param string $result |
199 | 199 | * @param SMWQueryResult $results |
200 | | - * @param $outputmode |
| 200 | + * @param integer $outputmode |
201 | 201 | * |
202 | 202 | * @return string |
203 | 203 | */ |
204 | 204 | protected function handleNonFileResult( $result, SMWQueryResult $results, $outputmode ) { |
| 205 | + global $wgParser; |
205 | 206 | $result .= $this->getErrorString( $results ); // append errors |
206 | 207 | |
207 | 208 | if ( ( !$this->isHTML ) && ( $this->hasTemplates ) ) { // preprocess embedded templates if needed |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php |
— | — | @@ -37,7 +37,7 @@ |
38 | 38 | // Process redirects, if any (it seems that there is indeed no more direct way of getting this info from MW) |
39 | 39 | $rt = Title::newFromRedirect( $text ); |
40 | 40 | if ( $rt !== null ) { |
41 | | - $p = SMWPropertyValue::makeProperty( '_REDI' ); |
| 41 | + $p = new SMWDIProperty( '_REDI' ); |
42 | 42 | $dv = SMWDataValueFactory::newPropertyObjectValue( $p, $rt->getPrefixedText() ); |
43 | 43 | |
44 | 44 | if ( $smwgStoreAnnotations ) { |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Import.php |
— | — | @@ -114,23 +114,38 @@ |
115 | 115 | } |
116 | 116 | |
117 | 117 | protected function parseDBkeys( $args ) { |
118 | | - $parts = explode( ' ', $args[0], 3 ); |
119 | | - if ( count( $parts ) != 3 ) { |
| 118 | + try { |
| 119 | + $dataItem = new SMWDIString( $args[0] ); |
| 120 | + $this->setDataItem( $dataItem ); |
| 121 | + } catch ( SMWStringLengthException $e ) { |
120 | 122 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
121 | | - $this->addError( wfMsgForContent( 'smw_parseerror' ) ); |
122 | | - } else { |
123 | | - $this->m_namespace = $parts[0]; |
124 | | - $this->m_section = $parts[1]; |
125 | | - $this->m_uri = $parts[2]; |
126 | | - try { |
127 | | - $this->m_dataitem = new SMWDIString( $args[0] ); |
128 | | - } catch ( SMWStringLengthException $e ) { |
| 123 | + $this->addError( wfMsgForContent( 'smw_maxstring', '"' . $args[0] . '"' ) ); |
| 124 | + $this->m_dataitem = new SMWDIString( '' ); |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * @see SMWDataValue::setDataItem() |
| 130 | + * @param $dataitem SMWDataItem |
| 131 | + * @return boolean |
| 132 | + */ |
| 133 | + public function setDataItem( SMWDataItem $dataItem ) { |
| 134 | + if ( $dataItem->getDIType() == SMWDataItem::TYPE_STRING ) { |
| 135 | + $this->m_dataitem = $dataItem; |
| 136 | + $parts = explode( ' ', $dataItem->getString(), 3 ); |
| 137 | + if ( count( $parts ) != 3 ) { |
129 | 138 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
130 | | - $this->addError( wfMsgForContent( 'smw_maxstring', '"' . $args[0] . '"' ) ); |
131 | | - $this->m_dataitem = new SMWDIString( '' ); |
| 139 | + $this->addError( wfMsgForContent( 'smw_parseerror' ) ); |
| 140 | + } else { |
| 141 | + $this->m_namespace = $parts[0]; |
| 142 | + $this->m_section = $parts[1]; |
| 143 | + $this->m_uri = $parts[2]; |
| 144 | + $this->m_qname = $this->m_namespace . ':' . $this->m_section; |
| 145 | + $this->m_caption = "[" . $this->m_uri . " " . $this->m_qname . "] (" . $this->m_name . ")"; |
132 | 146 | } |
133 | | - $this->m_qname = $this->m_namespace . ':' . $this->m_section; |
134 | | - $this->m_caption = "[" . $this->m_uri . " " . $this->m_qname . "] (" . $this->m_name . ")"; |
| 147 | + return true; |
| 148 | + } else { |
| 149 | + return false; |
135 | 150 | } |
136 | 151 | } |
137 | 152 | |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Linear.php |
— | — | @@ -118,22 +118,24 @@ |
119 | 119 | $this->m_unitfactors = array(); |
120 | 120 | $this->m_mainunit = false; |
121 | 121 | |
122 | | - $typepage = SMWWikiPageValue::makePage( $this->m_typeid, SMW_NS_TYPE ); |
123 | | - if ( !$typepage->isValid() ) { |
| 122 | + try { |
| 123 | + $typeDiWikiPage = new SMWDIWikiPage( $this->m_typeid, SMW_NS_TYPE, '' ); |
| 124 | + } catch ( SMWDataItemException $e ) { |
124 | 125 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
125 | 126 | $this->addError( wfMsgForContent( 'smw_unknowntype', SMWDataValueFactory::findTypeLabel( $this->getTypeID() ) ) ); |
126 | 127 | return; |
127 | 128 | } |
128 | | - $factors = smwfGetStore()->getPropertyValues( $typepage, SMWPropertyValue::makeProperty( '_CONV' ) ); |
| 129 | + $factors = smwfGetStore()->getPropertyValues( $typeDiWikiPage, new SMWDIProperty( '_CONV' ) ); |
129 | 130 | if ( count( $factors ) == 0 ) { // no custom type |
130 | 131 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
131 | 132 | $this->addError( wfMsgForContent( 'smw_unknowntype', SMWDataValueFactory::findTypeLabel( $this->getTypeID() ) ) ); |
132 | 133 | return; |
133 | 134 | } |
134 | 135 | $number = $unit = ''; |
135 | | - foreach ( $factors as $dv ) { |
136 | | - if ( SMWNumberValue::parseNumberValue( $dv->getWikiValue(), $number, $unit ) != 0 ) { |
137 | | - continue; // ignore problematic conversions |
| 136 | + foreach ( $factors as $di ) { |
| 137 | + if ( ( $di->getDIType() !== SMWDataItem::TYPE_STRING ) || |
| 138 | + ( SMWNumberValue::parseNumberValue( $di->getString(), $number, $unit ) != 0 ) ) { |
| 139 | + continue; // ignore corrupted data and bogus inputs |
138 | 140 | } |
139 | 141 | $unit_aliases = preg_split( '/\s*,\s*/u', $unit ); |
140 | 142 | $first = true; |
— | — | @@ -170,11 +172,15 @@ |
171 | 173 | if ( $this->m_displayunits !== false ) return; // do the below only once |
172 | 174 | $this->initConversionData(); // needed to normalise unit strings |
173 | 175 | $this->m_displayunits = array(); |
174 | | - if ( ( $this->m_property === null ) || ( $this->m_property->getWikiPageValue() === null ) ) return; |
175 | | - $values = smwfGetStore()->getPropertyValues( $this->m_property->getWikiPageValue(), SMWPropertyValue::makeProperty( '_UNIT' ) ); |
| 176 | + if ( ( $this->m_property === null ) || ( $this->m_property->getDIWikiPage() === null ) ) { |
| 177 | + return; |
| 178 | + } |
| 179 | + $dataItems = smwfGetStore()->getPropertyValues( $this->m_property->getDIWikiPage(), new SMWDIProperty( '_UNIT' ) ); |
176 | 180 | $units = array(); |
177 | | - foreach ( $values as $value ) { // Join all if many annotations exist. Discouraged (random order) but possible. |
178 | | - $units = $units + preg_split( '/\s*,\s*/u', $value->getWikiValue() ); |
| 181 | + foreach ( $dataItems as $di ) { // Join all if many annotations exist. Discouraged (random order) but possible. |
| 182 | + if ( $di->getDIType() === SMWDataItem::TYPE_STRING ) { |
| 183 | + $units = $units + preg_split( '/\s*,\s*/u', $di->getString() ); |
| 184 | + } |
179 | 185 | } |
180 | 186 | foreach ( $units as $unit ) { |
181 | 187 | $unit = SMWNumberValue::normalizeUnit( $unit ); |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_TypeList.php |
— | — | @@ -41,6 +41,26 @@ |
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
| 45 | + * @see SMWDataValue::setDataItem() |
| 46 | + * @param $dataitem SMWDataItem |
| 47 | + * @return boolean |
| 48 | + */ |
| 49 | + public function setDataItem( SMWDataItem $dataItem ) { |
| 50 | + if ( $dataItem->getDIType() == SMWDataItem::TYPE_STRING ) { |
| 51 | + $this->m_dataitem = $dataItem; |
| 52 | + $this->m_typevalues = array(); |
| 53 | + $ids = explode( ';', $dataItem->getString() ); |
| 54 | + foreach ( $ids as $id ) { |
| 55 | + $this->m_typevalues[] = SMWDataValueFactory::newTypeIDValue( '__typ', SMWDataValueFactory::findTypeLabel( $id ) ); |
| 56 | + } |
| 57 | + $this->m_caption = false; |
| 58 | + return true; |
| 59 | + } else { |
| 60 | + return false; |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + /** |
45 | 65 | * The special feature of this implementation of getDBkeys is that it uses |
46 | 66 | * internal type ids to obtain a short internal value for the type. Note |
47 | 67 | * that this also given language independence but that this is of little |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Record.php |
— | — | @@ -51,14 +51,14 @@ |
52 | 52 | if ( $querymode ) { |
53 | 53 | $subdescriptions[] = new SMWRecordFieldDescription( $i, new SMWValueDescription( $dv, $comparator ) ); |
54 | 54 | } else { |
55 | | - $property = SMWPropertyValue::makeProperty( '_' . ( $i + 1 ) ); |
| 55 | + $property = new SMWDIProperty( '_' . ( $i + 1 ) ); |
56 | 56 | $this->m_data->addPropertyObjectValue( $property, $dv ); |
57 | 57 | } |
58 | 58 | $vi++; |
59 | 59 | $empty = false; |
60 | 60 | } elseif ( ( count( $values ) - $vi ) == ( count( $types ) - $i ) ) { |
61 | 61 | // too many errors: keep this one to have enough slots left |
62 | | - $this->m_data->addPropertyObjectValue( SMWPropertyValue::makeProperty( '_' . ( $i + 1 ) ), $dv ); |
| 62 | + $this->m_data->addPropertyObjectValue( new SMWDIProperty( '_' . ( $i + 1 ) ), $dv ); |
63 | 63 | $this->addError( $dv->getErrors() ); |
64 | 64 | $vi++; |
65 | 65 | } |
— | — | @@ -84,7 +84,7 @@ |
85 | 85 | if ( count( $args ) > 0 ) { |
86 | 86 | foreach ( reset( $args ) as $value ) { |
87 | 87 | if ( is_array( $value ) && ( count( $value ) == 2 ) ) { |
88 | | - $property = SMWPropertyValue::makeProperty( reset( $value ) ); |
| 88 | + $property = new SMWDIProperty( reset( $value ) ); |
89 | 89 | $pnum = intval( substr( reset( $value ), 1 ) ); // try to find the number of this property |
90 | 90 | if ( array_key_exists( $pnum - 1, $types ) ) { |
91 | 91 | $dv = SMWDataValueFactory::newTypeObjectValue( $types[$pnum - 1] ); |
— | — | @@ -138,7 +138,7 @@ |
139 | 139 | * @todo This is not a full reset yet (the case that property is changed after a value |
140 | 140 | * was set does not occur in the normal flow of things, hence this has low priority). |
141 | 141 | */ |
142 | | - public function setProperty( SMWPropertyValue $property ) { |
| 142 | + public function setProperty( SMWDIProperty $property ) { |
143 | 143 | parent::setProperty( $property ); |
144 | 144 | $this->m_typevalues = null; |
145 | 145 | } |
— | — | @@ -204,7 +204,7 @@ |
205 | 205 | if ( ( $this->m_property === null ) || ( $this->m_property->getWikiPageValue() === null ) ) { |
206 | 206 | $this->m_typevalues = array(); // no property known -> no types |
207 | 207 | } else { // query for type values |
208 | | - $typelist = smwfGetStore()->getPropertyValues( $this->m_property->getWikiPageValue(), SMWPropertyValue::makeProperty( '_LIST' ) ); |
| 208 | + $typelist = smwfGetStore()->getPropertyValues( $this->m_property->getWikiPageValue(), new SMWDIProperty( '_LIST' ) ); |
209 | 209 | if ( count( $typelist ) == 1 ) { |
210 | 210 | $this->m_typevalues = reset( $typelist )->getTypeValues(); |
211 | 211 | } else { ///TODO internalionalize |
— | — | @@ -228,7 +228,7 @@ |
229 | 229 | } elseif ( $i > 1 ) { |
230 | 230 | $result .= ( $type == 4 ) ? '; ':", "; |
231 | 231 | } |
232 | | - $property = SMWPropertyValue::makeProperty( '_' . ( $i + 1 ) ); |
| 232 | + $property = new SMWDIProperty( '_' . ( $i + 1 ) ); |
233 | 233 | $propertyvalues = $this->m_data->getPropertyValues( $property ); // combining this with next line violates PHP strict standards |
234 | 234 | $dv = reset( $propertyvalues ); |
235 | 235 | $result .= ( $dv !== false ) ? $this->makeValueOutputText( $type, $dv, $linker ): '?'; |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Property.php |
— | — | @@ -87,9 +87,10 @@ |
88 | 88 | * in any case. |
89 | 89 | */ |
90 | 90 | static public function makeProperty( $propertyid ) { |
91 | | - $property = new SMWPropertyValue( '__pro' ); |
92 | | - $property->setDBkeys( array( $propertyid ) ); |
93 | | - return $property; |
| 91 | + $diProperty = new SMWDIProperty( $propertyid ); |
| 92 | + $dvProperty = new SMWPropertyValue( '__pro' ); |
| 93 | + $dvProperty->setDataItem( $diProperty ); |
| 94 | + return $dvProperty; |
94 | 95 | } |
95 | 96 | |
96 | 97 | /** |
— | — | @@ -136,24 +137,37 @@ |
137 | 138 | * internal property id accordingly. |
138 | 139 | */ |
139 | 140 | protected function parseDBkeys( $args ) { |
140 | | - $this->mPropTypeValue = null; |
141 | | - $this->mPropTypeId = ''; |
142 | | - unset( $this->m_wikipage ); |
143 | | - |
144 | 141 | try { |
145 | | - $this->m_dataitem = new SMWDIProperty( $args[0], false, $this->m_typeid ); |
| 142 | + $dataItem = new SMWDIProperty( $args[0], false, $this->m_typeid ); |
146 | 143 | } catch ( SMWDataItemException $e ) { |
147 | 144 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
148 | 145 | $this->addError( wfMsgForContent( 'smw_parseerror' ) ); // very rare to get an error here, don't bother with detailed reporting |
149 | | - $this->m_dataitem = new SMWDIProperty( 'ERROR', false, $this->m_typeid ); // just to have something |
| 146 | + $dataItem = new SMWDIProperty( 'ERROR', false, $this->m_typeid ); // just to have something |
150 | 147 | } |
| 148 | + $this->setDataItem( $dataItem ); |
| 149 | + } |
151 | 150 | |
152 | | - $this->m_caption = false; |
| 151 | + /** |
| 152 | + * @see SMWDataValue::setDataItem() |
| 153 | + * @param $dataitem SMWDataItem |
| 154 | + * @return boolean |
| 155 | + */ |
| 156 | + public function setDataItem( SMWDataItem $dataItem ) { |
| 157 | + if ( $dataItem->getDIType() == SMWDataItem::TYPE_PROPERTY ) { |
| 158 | + $this->m_dataitem = $dataItem; |
| 159 | + $this->mPropTypeValue = null; |
| 160 | + $this->mPropTypeId = ''; |
| 161 | + unset( $this->m_wikipage ); |
| 162 | + $this->m_caption = false; |
| 163 | + return true; |
| 164 | + } else { |
| 165 | + return false; |
| 166 | + } |
153 | 167 | } |
154 | 168 | |
155 | 169 | public function setCaption( $caption ) { |
156 | 170 | parent::setCaption( $caption ); |
157 | | - if ( $this->m_wikipage instanceof SMWDataValue ) { // pass caption to embedded datavalue (used for printout) |
| 171 | + if ( $this->getWikiPageValue() instanceof SMWDataValue ) { // pass caption to embedded datavalue (used for printout) |
158 | 172 | $this->m_wikipage->setCaption( $caption ); |
159 | 173 | } |
160 | 174 | } |
— | — | @@ -179,11 +193,9 @@ |
180 | 194 | public function getWikiPageValue() { |
181 | 195 | $this->unstub(); |
182 | 196 | if ( !isset( $this->m_wikipage ) ) { |
183 | | - $label = $this->m_dataitem->getLabel(); |
184 | | - if ( $label != '' ) { |
185 | | - $this->m_wikipage = SMWDataValueFactory::newTypeIDValue( '_wpp' ); |
186 | | - $this->m_wikipage->setDBkeys( array( str_replace( ' ', '_', $label ), SMW_NS_PROPERTY, '', '' ) ); |
187 | | - $this->m_wikipage->setCaption( $this->m_caption ); |
| 197 | + $diWikiPage = $this->m_dataitem->getDiWikiPage(); |
| 198 | + if ( $diWikiPage !== null ) { |
| 199 | + $this->m_wikipage = SMWDataValueFactory::newDataItemValue( $diWikiPage, $this->m_caption ); |
188 | 200 | $this->m_wikipage->setOutputFormat( $this->m_outformat ); |
189 | 201 | $this->addError( $this->m_wikipage->getErrors() ); |
190 | 202 | } else { // should rarely happen ($value is only changed if the input $value really was a label for a predefined prop) |
— | — | @@ -200,7 +212,7 @@ |
201 | 213 | */ |
202 | 214 | public function isVisible() { |
203 | 215 | $this->unstub(); |
204 | | - return ( $this->getWikiPageValue() !== null ); |
| 216 | + return ( $this->m_dataitem->isUserDefined() ) || ( $this->m_dataitem->getLabel() != '' ); |
205 | 217 | } |
206 | 218 | |
207 | 219 | public function getShortWikiText( $linked = null ) { |
— | — | @@ -263,7 +275,7 @@ |
264 | 276 | $result->setDBkeys( array( '__err' ) ); |
265 | 277 | $result->addError( $this->getErrors() ); |
266 | 278 | } elseif ( $this->m_dataitem->isUserDefined() ) { // normal property |
267 | | - $typearray = smwfGetStore()->getPropertyValues( $this->getWikiPageValue(), SMWPropertyValue::makeProperty( '_TYPE' ) ); |
| 279 | + $typearray = smwfGetStore()->getPropertyValues( $this->getWikiPageValue(), new SMWDIProperty( '_TYPE' ) ); |
268 | 280 | if ( count( $typearray ) == 1 ) { // unique type given |
269 | 281 | $result = current( $typearray ); |
270 | 282 | } elseif ( count( $typearray ) == 0 ) { // no type given |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Number.php |
— | — | @@ -118,13 +118,28 @@ |
119 | 119 | } |
120 | 120 | |
121 | 121 | protected function parseDBkeys( $args ) { |
122 | | - $this->m_dataitem = SMWDINumber::doUnserialize( $args[0], $this->m_typeid ); |
123 | | - $this->m_caption = false; |
124 | | - $this->m_unitin = false; |
125 | | - $this->makeUserValue(); |
126 | | - $this->m_unitvalues = false; |
| 122 | + $dataItem = SMWDINumber::doUnserialize( $args[0], $this->m_typeid ); |
| 123 | + $this->setDataItem( $dataItem ); |
127 | 124 | } |
128 | 125 | |
| 126 | + /** |
| 127 | + * @see SMWDataValue::setDataItem() |
| 128 | + * @param $dataitem SMWDataItem |
| 129 | + * @return boolean |
| 130 | + */ |
| 131 | + public function setDataItem( SMWDataItem $dataItem ) { |
| 132 | + if ( $dataItem->getDIType() == SMWDataItem::TYPE_NUMBER ) { |
| 133 | + $this->m_dataitem = $dataItem; |
| 134 | + $this->m_caption = false; |
| 135 | + $this->m_unitin = false; |
| 136 | + $this->makeUserValue(); |
| 137 | + $this->m_unitvalues = false; |
| 138 | + return true; |
| 139 | + } else { |
| 140 | + return false; |
| 141 | + } |
| 142 | + } |
| 143 | + |
129 | 144 | public function setOutputFormat( $formatstring ) { |
130 | 145 | if ( $formatstring != $this->m_outformat ) { |
131 | 146 | $this->m_outformat = $formatstring; |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Error.php |
— | — | @@ -15,16 +15,20 @@ |
16 | 16 | */ |
17 | 17 | class SMWErrorValue extends SMWDataValue { |
18 | 18 | |
19 | | - public function __construct( $errormsg = '', $uservalue = '', $caption = false ) { |
20 | | - $this->setUserValue( $uservalue, $caption ); |
21 | | - if ( $errormsg != '' ) $this->addError( $errormsg ); |
| 19 | + public function __construct( $typeid, $errormsg = '', $uservalue = '', $caption = false ) { |
| 20 | + parent::__construct( $typeid ); |
| 21 | + $this->m_caption = ( $caption !== false ) ? $caption : $uservalue; |
| 22 | + if ( $errormsg != '' ) { |
| 23 | + $this->addError( $errormsg ); |
| 24 | + } |
22 | 25 | } |
23 | 26 | |
24 | 27 | protected function parseUserValue( $value ) { |
25 | 28 | if ( $this->m_caption === false ) { |
26 | 29 | $this->m_caption = $value; |
27 | 30 | } |
28 | | - $this->m_dataitem = new SMWDIBlob( $value ); |
| 31 | + smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
| 32 | + $this->addError( wfMsgForContent( 'smw_parseerror' ) ); |
29 | 33 | } |
30 | 34 | |
31 | 35 | protected function parseDBkeys( $args ) { |
— | — | @@ -36,6 +40,21 @@ |
37 | 41 | // irrelevant. |
38 | 42 | } |
39 | 43 | |
| 44 | + /** |
| 45 | + * @see SMWDataValue::setDataItem() |
| 46 | + * @param $dataitem SMWDataItem |
| 47 | + * @return boolean |
| 48 | + */ |
| 49 | + public function setDataItem( SMWDataItem $dataItem ) { |
| 50 | + if ( $dataItem->getDIType() == SMWDataItem::TYPE_ERROR ) { |
| 51 | + $this->addError( $dataItem->getErrors() ); |
| 52 | + $this->m_caption = $this->getErrorText(); |
| 53 | + return true; |
| 54 | + } else { |
| 55 | + return false; |
| 56 | + } |
| 57 | + } |
| 58 | + |
40 | 59 | public function getShortWikiText( $linked = null ) { |
41 | 60 | $this->unstub(); |
42 | 61 | return $this->m_caption; |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Bool.php |
— | — | @@ -44,7 +44,7 @@ |
45 | 45 | } else { |
46 | 46 | $this->addError( wfMsgForContent( 'smw_noboolean', $value ) ); |
47 | 47 | } |
48 | | - $this->m_dataitem = new SMWDIBool( $boolvalue, $this->m_typeid ); |
| 48 | + $this->m_dataitem = new SMWDIBoolean( $boolvalue, $this->m_typeid ); |
49 | 49 | } |
50 | 50 | |
51 | 51 | protected function parseDBkeys( $args ) { |
— | — | @@ -52,6 +52,21 @@ |
53 | 53 | $this->m_caption = $this->getStandardCaption( true ); // use default for this language |
54 | 54 | } |
55 | 55 | |
| 56 | + /** |
| 57 | + * @see SMWDataValue::setDataItem() |
| 58 | + * @param $dataitem SMWDataItem |
| 59 | + * @return boolean |
| 60 | + */ |
| 61 | + public function setDataItem( SMWDataItem $dataItem ) { |
| 62 | + if ( $dataItem->getDIType() == SMWDataItem::TYPE_BOOLEAN ) { |
| 63 | + $this->m_dataitem = $dataItem; |
| 64 | + $this->m_caption = $this->getStandardCaption( true ); // use default for this language |
| 65 | + return true; |
| 66 | + } else { |
| 67 | + return false; |
| 68 | + } |
| 69 | + } |
| 70 | + |
56 | 71 | public function setOutputFormat( $formatstring ) { |
57 | 72 | if ( $formatstring == $this->m_outformat ) return; |
58 | 73 | unset( $this->m_truecaption ); |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Concept.php |
— | — | @@ -28,6 +28,21 @@ |
29 | 29 | $this->m_dataitem = new SMWDIConcept( $args[0], smwfXMLContentEncode( $args[1] ), $args[2], $args[3], $args[4], $this->m_typeid ); |
30 | 30 | } |
31 | 31 | |
| 32 | + /** |
| 33 | + * @see SMWDataValue::setDataItem() |
| 34 | + * @param $dataitem SMWDataItem |
| 35 | + * @return boolean |
| 36 | + */ |
| 37 | + public function setDataItem( SMWDataItem $dataItem ) { |
| 38 | + if ( $dataItem->getDIType() == SMWDataItem::TYPE_CONCEPT ) { |
| 39 | + $this->m_dataitem = $dataItem; |
| 40 | + $this->m_caption = $dataItem->getConceptQuery(); // probably useless |
| 41 | + return true; |
| 42 | + } else { |
| 43 | + return false; |
| 44 | + } |
| 45 | + } |
| 46 | + |
32 | 47 | protected function clear() { |
33 | 48 | $this->m_dataitem = new SMWDIConcept( '', '', 0, -1, -1, $this->m_typeid ); |
34 | 49 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Time.php |
— | — | @@ -159,7 +159,7 @@ |
160 | 160 | if ( ( $era === false ) && ( $hours === false ) && ( $timeoffset == 0 ) ) { |
161 | 161 | try { |
162 | 162 | $jd = floatval( reset( $datecomponents ) ); |
163 | | - if ( $calendarmodel == 'MJD' ) $jd += SMWTimeValue::MJD_EPOCH; |
| 163 | + if ( $calendarmodel == 'MJD' ) $jd += self::MJD_EPOCH; |
164 | 164 | $this->m_dataitem = SMWDITime::newFromJD( $jd, SMWDITime::CM_GREGORIAN, SMWDITime::PREC_YMDT, $this->m_typeid ); |
165 | 165 | } catch ( SMWDataItemException $e ) { |
166 | 166 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
— | — | @@ -231,18 +231,18 @@ |
232 | 232 | $calendarmodel = $match; |
233 | 233 | } elseif ( ( $ampm === false ) && ( ( strtolower( $match ) == 'am' ) || ( strtolower( $match ) == 'pm' ) ) ) { |
234 | 234 | $ampm = strtolower( $match ); |
235 | | - } elseif ( ( $hours === false ) && ( $this->parseTimeString( $match, $hours, $minutes, $seconds, $timeoffset ) ) ) { |
| 235 | + } elseif ( ( $hours === false ) && ( self::parseTimeString( $match, $hours, $minutes, $seconds, $timeoffset ) ) ) { |
236 | 236 | // nothing to do |
237 | 237 | } elseif ( ( $hours === true ) && ( $timezoneoffset === false ) && |
238 | | - ( array_key_exists( $match, SMWTimeValue::$m_tz ) ) ) { |
| 238 | + ( array_key_exists( $match, self::$m_tz ) ) ) { |
239 | 239 | // only accept timezone if time has already been set |
240 | | - $timezoneoffset = SMWTimeValue::$m_tz[ $match ]; |
| 240 | + $timezoneoffset = self::$m_tz[ $match ]; |
241 | 241 | } elseif ( ( $prevmatchwasnumber ) && ( $hours === false ) && ( $timezoneoffset === false ) && |
242 | | - ( array_key_exists( $match, SMWTimeValue::$m_miltz ) ) && |
243 | | - ( $this->parseMilTimeString( end( $datecomponents ), $hours, $minutes, $seconds ) ) ) { |
| 242 | + ( array_key_exists( $match, self::$m_miltz ) ) && |
| 243 | + ( self::parseMilTimeString( end( $datecomponents ), $hours, $minutes, $seconds ) ) ) { |
244 | 244 | // military timezone notation is found after a number -> re-interpret the number as military time |
245 | 245 | array_pop( $datecomponents ); |
246 | | - $timezoneoffset = SMWTimeValue::$m_miltz[ $match ]; |
| 246 | + $timezoneoffset = self::$m_miltz[ $match ]; |
247 | 247 | } elseif ( ( $prevmatchwasdate || ( count( $datecomponents ) == 0 ) ) && |
248 | 248 | $this->parseMonthString( $match, $monthname ) ) { |
249 | 249 | $datecomponents[] = $monthname; |
— | — | @@ -284,6 +284,8 @@ |
285 | 285 | * If successful, the function sets the provided call-by-ref values to |
286 | 286 | * the respective numbers and returns true. Otherwise, it returns |
287 | 287 | * false and does not set any values. |
| 288 | + * @note This method is only temporarily public for enabling SMWCompatibilityHelpers. Do not use it directly in your code. |
| 289 | + * |
288 | 290 | * @param $string string input time representation, e.g. "13:45:23-3:30" |
289 | 291 | * @param $hours integer between 0 and 24 |
290 | 292 | * @param $minutes integer between 0 and 59 |
— | — | @@ -291,7 +293,7 @@ |
292 | 294 | * @param $timeoffset double for time offset (e.g. 3.5), or false if not given |
293 | 295 | * @return boolean stating if the parsing succeeded |
294 | 296 | */ |
295 | | - protected static function parseTimeString( $string, &$hours, &$minutes, &$seconds, &$timeoffset ) { |
| 297 | + public static function parseTimeString( $string, &$hours, &$minutes, &$seconds, &$timeoffset ) { |
296 | 298 | if ( !preg_match( "/^[T]?([0-2]?[0-9]):([0-5][0-9])(:[0-5][0-9])?(([+\-][0-2]?[0-9])(:(30|00))?)?$/u", $string, $match ) ) { |
297 | 299 | return false; |
298 | 300 | } else { |
— | — | @@ -365,12 +367,12 @@ |
366 | 368 | if ( $monthnum !== false ) { |
367 | 369 | $monthnum -= 1; |
368 | 370 | } else { |
369 | | - $monthnum = array_search( $string, SMWTimeValue::$m_months ); // check English names |
| 371 | + $monthnum = array_search( $string, self::$m_months ); // check English names |
370 | 372 | } |
371 | 373 | if ( $monthnum !== false ) { |
372 | | - $monthname = SMWTimeValue::$m_monthsshort[ $monthnum ]; |
| 374 | + $monthname = self::$m_monthsshort[ $monthnum ]; |
373 | 375 | return true; |
374 | | - } elseif ( array_search( $string, SMWTimeValue::$m_monthsshort ) !== false ) { |
| 376 | + } elseif ( array_search( $string, self::$m_monthsshort ) !== false ) { |
375 | 377 | $monthname = $string; |
376 | 378 | return true; |
377 | 379 | } else { |
— | — | @@ -432,7 +434,7 @@ |
433 | 435 | foreach ( $dateformats[count( $propercomponents ) - 1] as $formatvector ) { |
434 | 436 | if ( !( ~$datevector & $formatvector ) ) { // check if $formatvector => $datevector ("the input supports the format") |
435 | 437 | $i = 0; |
436 | | - foreach ( SMWTimeValue::$m_formats[$formatvector] as $fieldname ) { |
| 438 | + foreach ( self::$m_formats[$formatvector] as $fieldname ) { |
437 | 439 | $date[$fieldname] = $propercomponents[$i]; |
438 | 440 | $i += 1; |
439 | 441 | } |
— | — | @@ -487,7 +489,7 @@ |
488 | 490 | // Having more than years or specifying a calendar model does |
489 | 491 | // not make sense for prehistoric dates, and our calendar |
490 | 492 | // conversion would not be reliable if JD numbers get too huge: |
491 | | - if ( ( $date['y'] <= SMWTimeValue::PREHISTORY ) && |
| 493 | + if ( ( $date['y'] <= self::PREHISTORY ) && |
492 | 494 | ( ( $this->m_dataitem->getPrecision() > SMWDITime::PREC_Y ) || ( $calendarmodel !== false ) ) ) { |
493 | 495 | $this->addError( wfMsgForContent( 'smw_nodatetime', $this->m_wikivalue ) ); |
494 | 496 | return false; |
— | — | @@ -536,7 +538,7 @@ |
537 | 539 | return 0; |
538 | 540 | } |
539 | 541 | } else { |
540 | | - $monthnum = array_search( $component, SMWTimeValue::$m_monthsshort ); |
| 542 | + $monthnum = array_search( $component, self::$m_monthsshort ); |
541 | 543 | if ( $monthnum !== false ) { |
542 | 544 | $numvalue = $monthnum + 1; |
543 | 545 | return SMW_MONTH; |
— | — | @@ -568,7 +570,7 @@ |
569 | 571 | ( ( $year == 1582 ) && ( $month > 10 ) ) || |
570 | 572 | ( ( $year == 1582 ) && ( $month == 10 ) && ( $day > 4 ) ) ) { |
571 | 573 | return SMWDITime::CM_GREGORIAN; |
572 | | - } elseif ( $year > SMWTimeValue::PREHISTORY ) { |
| 574 | + } elseif ( $year > self::PREHISTORY ) { |
573 | 575 | return SMWDITime::CM_JULIAN; |
574 | 576 | } else { |
575 | 577 | // proleptic Julian years at some point deviate from the count of complete revolutions of the earth around the sun |
— | — | @@ -583,9 +585,9 @@ |
584 | 586 | $timedate = explode( 'T', $args[0], 2 ); |
585 | 587 | if ( ( count( $args ) == 2 ) && ( count( $timedate ) == 2 ) ) { |
586 | 588 | $date = reset( $timedate ); |
587 | | - $hours = $minutes = $seconds = $timeoffset = false; |
| 589 | + $year = $month = $day = $hours = $minutes = $seconds = $timeoffset = false; |
588 | 590 | if ( ( end( $timedate ) == '' ) || |
589 | | - ( $this->parseTimeString( end( $timedate ), $hours, $minutes, $seconds, $timeoffset ) == true ) ) { |
| 591 | + ( self::parseTimeString( end( $timedate ), $hours, $minutes, $seconds, $timeoffset ) == true ) ) { |
590 | 592 | $d = explode( '/', $date, 3 ); |
591 | 593 | if ( count( $d ) == 3 ) { |
592 | 594 | list( $year, $month, $day ) = $d; |
— | — | @@ -609,6 +611,21 @@ |
610 | 612 | $this->m_dataitem = new SMWDITime( SMWDITime::CM_GREGORIAN, 32202 ); // always default to something |
611 | 613 | } |
612 | 614 | |
| 615 | + /** |
| 616 | + * @see SMWDataValue::setDataItem() |
| 617 | + * @param $dataitem SMWDataItem |
| 618 | + * @return boolean |
| 619 | + */ |
| 620 | + public function setDataItem( SMWDataItem $dataItem ) { |
| 621 | + if ( $dataItem->getDIType() == SMWDataItem::TYPE_TIME ) { |
| 622 | + $this->m_dataitem = $dataItem; |
| 623 | + $this->m_caption = $this->m_wikivalue = false; |
| 624 | + return true; |
| 625 | + } else { |
| 626 | + return false; |
| 627 | + } |
| 628 | + } |
| 629 | + |
613 | 630 | public function getShortWikiText( $linked = NULL ) { |
614 | 631 | return ( $this->m_caption !== false ) ? $this->m_caption : $this->getPreferredCaption(); |
615 | 632 | } |
— | — | @@ -770,7 +787,7 @@ |
771 | 788 | $result .= str_pad( $this->getYear() + 1, 4, "0", STR_PAD_LEFT ) . |
772 | 789 | '-' . str_pad( $monthnum, 2, "0", STR_PAD_LEFT ); |
773 | 790 | if ( !$mindefault && ( $this->m_dataitem->getPrecision() < SMWDITime::PREC_YMD ) ) { |
774 | | - $maxday = SMWTimeValue::getDayNumberForMonth( $monthnum, $this->getYear(), SMWDITime::CM_GREGORIAN ); |
| 791 | + $maxday = self::getDayNumberForMonth( $monthnum, $this->getYear(), SMWDITime::CM_GREGORIAN ); |
775 | 792 | $result .= '-' . str_pad( $this->getDay( SMWDITime::CM_GREGORIAN, $maxday ), 2, "0", STR_PAD_LEFT ); |
776 | 793 | } else { |
777 | 794 | $result .= '-' . str_pad( $this->getDay(), 2, "0", STR_PAD_LEFT ); |
— | — | @@ -791,7 +808,7 @@ |
792 | 809 | * @return SMWDITime |
793 | 810 | */ |
794 | 811 | protected function getDataForCalendarModel( $calendarmodel ) { |
795 | | - if ( $this->m_dataitem->getYear() <= SMWTimeValue::PREHISTORY ) { |
| 812 | + if ( $this->m_dataitem->getYear() <= self::PREHISTORY ) { |
796 | 813 | return ( $this->m_dataitem->getCalendarModel() == $calendarmodel ) ? $this->m_dataitem : null; |
797 | 814 | } elseif ( $calendarmodel == SMWDITime::CM_GREGORIAN ) { |
798 | 815 | if ( $this->m_dataitem_greg === null ) { |
— | — | @@ -843,9 +860,9 @@ |
844 | 861 | if ( ( strtoupper( $this->m_outformat ) == 'ISO' ) || ( $this->m_outformat == '-' ) ) { |
845 | 862 | return $this->getISO8601Date(); |
846 | 863 | } else { |
847 | | - if ( $this->m_dataitem->getYear() <= SMWTimeValue::PREHISTORY ) { |
| 864 | + if ( $this->m_dataitem->getYear() <= self::PREHISTORY ) { |
848 | 865 | return $this->getCaptionFromDataitem( $this->m_dataitem ); // should be Gregorian, but don't bother here |
849 | | - } elseif ( $this->m_dataitem->getJD() < SMWTimeValue::J1582 ) { |
| 866 | + } elseif ( $this->m_dataitem->getJD() < self::J1582 ) { |
850 | 867 | return $this->getCaptionFromDataitem( $this->getDataForCalendarModel( SMWDITime::CM_JULIAN ) ); |
851 | 868 | } else { |
852 | 869 | return $this->getCaptionFromDataitem( $this->getDataForCalendarModel( SMWDITime::CM_GREGORIAN ) ); |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_URI.php |
— | — | @@ -65,7 +65,7 @@ |
66 | 66 | $scheme = $hierpart = $query = $fragment = ''; |
67 | 67 | if ( $value == '' ) { // do not accept empty strings |
68 | 68 | $this->addError( wfMsgForContent( 'smw_emptystring' ) ); |
69 | | - $this->m_dataitem = new SMWDIURI( 'http', '//example.com', '', '', $this->m_typeid ); // define data item to have some value |
| 69 | + $this->m_dataitem = new SMWDIUri( 'http', '//example.com', '', '', $this->m_typeid ); // define data item to have some value |
70 | 70 | return; |
71 | 71 | } |
72 | 72 | |
— | — | @@ -83,7 +83,7 @@ |
84 | 84 | $uri = trim( $uri ); |
85 | 85 | if ( $uri == mb_substr( $value, 0, mb_strlen( $uri ) ) ) { // disallowed URI! |
86 | 86 | $this->addError( wfMsgForContent( 'smw_baduri', $value ) ); |
87 | | - $this->m_dataitem = new SMWDIURI( 'http', '//example.com', '', '', $this->m_typeid ); // define data item to have some value |
| 87 | + $this->m_dataitem = new SMWDIUri( 'http', '//example.com', '', '', $this->m_typeid ); // define data item to have some value |
88 | 88 | return; |
89 | 89 | } |
90 | 90 | } |
— | — | @@ -145,10 +145,10 @@ |
146 | 146 | |
147 | 147 | // Now create the URI data item: |
148 | 148 | try { |
149 | | - $this->m_dataitem = new SMWDIURI( $scheme, $hierpart, $query, $fragment, $this->m_typeid); |
| 149 | + $this->m_dataitem = new SMWDIUri( $scheme, $hierpart, $query, $fragment, $this->m_typeid); |
150 | 150 | } catch ( SMWDataItemException $e ) { |
151 | 151 | $this->addError( wfMsgForContent( 'smw_baduri', $this->m_wikitext ) ); |
152 | | - $this->m_dataitem = new SMWDIURI( 'http', '//example.com', '', '', $this->m_typeid ); // define data item to have some value |
| 152 | + $this->m_dataitem = new SMWDIUri( 'http', '//example.com', '', '', $this->m_typeid ); // define data item to have some value |
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
— | — | @@ -164,22 +164,35 @@ |
165 | 165 | |
166 | 166 | protected function parseDBkeys( $args ) { |
167 | 167 | try { |
168 | | - $this->m_dataitem = SMWDIURI::doUnserialize( $args[0], $this->m_typeid); |
| 168 | + $dataItem = SMWDIUri::doUnserialize( $args[0], $this->m_typeid); |
| 169 | + $this->setDataItem( $dataItem ); |
169 | 170 | } catch ( SMWDataItemException $e ) { |
170 | 171 | $this->addError( wfMsgForContent( 'smw_baduri', $this->m_wikitext ) ); |
171 | | - $this->m_dataitem = new SMWDIURI( 'http', '//example.com', '', '', $this->m_typeid ); // define data item to have some value |
| 172 | + $this->m_dataitem = new SMWDIUri( 'http', '//example.com', '', '', $this->m_typeid ); // define data item to have some value |
172 | 173 | return; |
173 | 174 | } |
| 175 | + } |
174 | 176 | |
175 | | - if ( $this->m_mode == SMW_URI_MODE_EMAIL ) { |
176 | | - $this->m_wikitext = substr( $this->m_wikitext, 7 ); |
177 | | - } elseif ( $this->m_mode == SMW_URI_MODE_TEL ) { |
178 | | - $this->m_wikitext = substr( $this->m_wikitext, 4 ); |
179 | | - $this->m_wikitext = $this->m_caption; |
| 177 | + /** |
| 178 | + * @see SMWDataValue::setDataItem() |
| 179 | + * @param $dataitem SMWDataItem |
| 180 | + * @return boolean |
| 181 | + */ |
| 182 | + public function setDataItem( SMWDataItem $dataItem ) { |
| 183 | + if ( $dataItem->getDIType() == SMWDataItem::TYPE_URI ) { |
| 184 | + $this->m_dataitem = $dataItem; |
| 185 | + if ( $this->m_mode == SMW_URI_MODE_EMAIL ) { |
| 186 | + $this->m_wikitext = substr( $dataItem->getURI(), 7 ); |
| 187 | + } elseif ( $this->m_mode == SMW_URI_MODE_TEL ) { |
| 188 | + $this->m_wikitext = substr( $dataItem->getURI(), 4 ); |
| 189 | + } else { |
| 190 | + $this->m_wikitext = $dataItem->getURI(); |
| 191 | + } |
| 192 | + $this->m_caption = $this->m_wikitext; |
| 193 | + return true; |
180 | 194 | } else { |
181 | | - $this->m_wikitext = $this->m_dataitem->getURI(); |
| 195 | + return false; |
182 | 196 | } |
183 | | - $this->m_caption = $this->m_wikitext; |
184 | 197 | } |
185 | 198 | |
186 | 199 | public function getShortWikiText( $linked = null ) { |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_WikiPage.php |
— | — | @@ -88,22 +88,26 @@ |
89 | 89 | * |
90 | 90 | * @return SMWWikiPageValue |
91 | 91 | */ |
92 | | - static public function makePage( $title, $namespace, $sortkey = '', $interwiki = '' ) { |
93 | | - $page = new SMWWikiPageValue( '_wpg' ); |
94 | | - $page->setDBkeys( array( $title, $namespace, $interwiki, $sortkey ) ); |
95 | | - return $page; |
| 92 | + static public function makePage( $dbkey, $namespace, $sortkey = '', $interwiki = '' ) { |
| 93 | + $diWikiPage = new SMWDIWikiPage( $dbkey, $namespace, $interwiki ); |
| 94 | + $dvWikiPage = new SMWWikiPageValue( '_wpg' ); |
| 95 | + $dvWikiPage->setDataItem( $diWikiPage ); |
| 96 | + return $dvWikiPage; |
96 | 97 | } |
97 | 98 | |
98 | 99 | /** |
99 | 100 | * Static function for creating a new wikipage object from a |
100 | 101 | * MediaWiki Title object. |
| 102 | + * @todo Evaluate whether we really want this function. It might be obsolete due to recent changes. |
101 | 103 | * |
102 | 104 | * @return SMWWikiPageValue |
103 | 105 | */ |
104 | | - static public function makePageFromTitle( $titleobject ) { |
105 | | - $page = new SMWWikiPageValue( '_wpg' ); |
106 | | - $page->setTitle( $titleobject ); |
107 | | - return $page; |
| 106 | + static public function makePageFromTitle( Title $title ) { |
| 107 | + $dvWikiPage = new SMWWikiPageValue( '_wpg' ); |
| 108 | + $diWikiPage = new SMWDIWikiPage( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki() ); |
| 109 | + $dvWikiPage->setDataItem( $diWikiPage ); |
| 110 | + $dvWikiPage->m_title = $title; |
| 111 | + return $dvWikiPage; |
108 | 112 | } |
109 | 113 | |
110 | 114 | public function __construct( $typeid ) { |
— | — | @@ -166,16 +170,31 @@ |
167 | 171 | $this->addError( wfMsgForContent( 'smw_notitle', $this->getPrefixedText() ) ); |
168 | 172 | $this->m_dataitem = new SMWDIWikiPage( 'ERROR', NS_MAIN, '', $this->m_typeid ); |
169 | 173 | } else { |
170 | | - $this->m_dataitem = new SMWDIWikiPage( $args[0], floatval( $args[1] ), $args[2], $this->m_typeid ); |
171 | | - $this->m_textform = str_replace( '_', ' ', $this->m_dataitem->getDBkey() ); |
| 174 | + $dataItem = new SMWDIWikiPage( $args[0], floatval( $args[1] ), $args[2], $this->m_typeid ); |
| 175 | + $this->setDataItem( $dataItem ); |
| 176 | + } |
| 177 | + } |
| 178 | + |
| 179 | + /** |
| 180 | + * @see SMWDataValue::setDataItem() |
| 181 | + * @param $dataitem SMWDataItem |
| 182 | + * @return boolean |
| 183 | + */ |
| 184 | + public function setDataItem( SMWDataItem $dataItem ) { |
| 185 | + if ( $dataItem->getDIType() == SMWDataItem::TYPE_WIKIPAGE ) { |
| 186 | + $this->m_dataitem = $dataItem; |
| 187 | + $this->m_textform = str_replace( '_', ' ', $dataItem->getDBkey() ); |
172 | 188 | $this->m_id = -1; |
173 | 189 | $this->m_title = null; |
174 | 190 | $this->m_sortkey = $this->m_fragment = $this->m_prefixedtext = ''; |
175 | 191 | $this->m_caption = false; |
176 | | - if ( ( $this->m_fixNamespace != NS_MAIN ) && ( $this->m_fixNamespace != $this->m_dataitem->getNamespace() ) ) { |
| 192 | + if ( ( $this->m_fixNamespace != NS_MAIN ) && ( $this->m_fixNamespace != $dataItem->getNamespace() ) ) { |
177 | 193 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
178 | 194 | $this->addError( wfMsgForContent( 'smw_notitle', $this->getPrefixedText() ) ); |
179 | 195 | } |
| 196 | + return true; |
| 197 | + } else { |
| 198 | + return false; |
180 | 199 | } |
181 | 200 | } |
182 | 201 | |
— | — | @@ -398,9 +417,11 @@ |
399 | 418 | |
400 | 419 | /** |
401 | 420 | * Init this data value object based on a given Title object. |
| 421 | + * @deprecated Use setDataItem(); it's easy to create an SMWDIWikiPage from a Title, will vanish before SMW 1.7 |
402 | 422 | */ |
403 | 423 | public function setTitle( $title ) { |
404 | | - $this->setDBkeys( array( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki(), '' ) ); |
| 424 | + $diWikiPage = new SMWDIWikiPage( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki() ); |
| 425 | + $this->setDataItem( $diWikiPage ); |
405 | 426 | $this->m_title = $title; |
406 | 427 | } |
407 | 428 | |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Types.php |
— | — | @@ -34,6 +34,21 @@ |
35 | 35 | $this->m_isalias = false; |
36 | 36 | } |
37 | 37 | |
| 38 | + /** |
| 39 | + * @see SMWDataValue::setDataItem() |
| 40 | + * @param $dataitem SMWDataItem |
| 41 | + * @return boolean |
| 42 | + */ |
| 43 | + public function setDataItem( SMWDataItem $dataItem ) { |
| 44 | + if ( parent::setDataItem( $dataItem ) ) { |
| 45 | + $this->m_reallabel = $this->m_textform; |
| 46 | + $this->m_isalias = false; |
| 47 | + return true; |
| 48 | + } else { |
| 49 | + return false; |
| 50 | + } |
| 51 | + } |
| 52 | + |
38 | 53 | public function getLongWikiText( $linked = null ) { |
39 | 54 | $this->unstub(); |
40 | 55 | if ( ( $linked === null ) || ( $linked === false ) ) { |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_String.php |
— | — | @@ -40,6 +40,26 @@ |
41 | 41 | $this->m_caption = $this->m_dataitem->getString(); // this is our output text |
42 | 42 | } |
43 | 43 | |
| 44 | + /** |
| 45 | + * @see SMWDataValue::setDataItem() |
| 46 | + * @param $dataitem SMWDataItem |
| 47 | + * @return boolean |
| 48 | + */ |
| 49 | + public function setDataItem( SMWDataItem $dataItem ) { |
| 50 | + $diType = ( ( $this->m_typeid == '_txt' ) || ( $this->m_typeid == '_cod' ) ) ? SMWDataItem::TYPE_BLOB : SMWDataItem::TYPE_STRING; |
| 51 | + if ( $dataItem->getDIType() == $diType ) { |
| 52 | + $this->m_dataitem = $dataItem; |
| 53 | + if ( $this->m_typeid == '_cod' ) { |
| 54 | + $this->m_caption = $this->getCodeDisplay( $this->m_dataitem->getString() ); |
| 55 | + } else { |
| 56 | + $this->m_caption = $this->m_dataitem->getString(); |
| 57 | + } |
| 58 | + return true; |
| 59 | + } else { |
| 60 | + return false; |
| 61 | + } |
| 62 | + } |
| 63 | + |
44 | 64 | public function getShortWikiText( $linked = null ) { |
45 | 65 | $this->unstub(); |
46 | 66 | return $this->m_caption; |
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_JSONlink.php |
— | — | @@ -94,7 +94,7 @@ |
95 | 95 | } |
96 | 96 | if ( $rowsubject !== false ) { // stuff in the page URI and some category data |
97 | 97 | $valuestack[] = '"uri" : "' . $wgServer . $wgScriptPath . '/index.php?title=' . $rowsubject->getPrefixedText() . '"'; |
98 | | - $page_cats = smwfGetStore()->getPropertyValues( $rowsubject, SMWPropertyValue::makeProperty( '_INST' ) ); // TODO: set limit to 1 here |
| 98 | + $page_cats = smwfGetStore()->getPropertyValues( $rowsubject, new SMWDIProperty( '_INST' ) ); // TODO: set limit to 1 here |
99 | 99 | if ( count( $page_cats ) > 0 ) { |
100 | 100 | $valuestack[] = '"type" : "' . reset($page_cats)->getShortHTMLText() . '"'; |
101 | 101 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_Table.php |
— | — | @@ -53,19 +53,20 @@ |
54 | 54 | $result .= ">"; |
55 | 55 | |
56 | 56 | $first = true; |
57 | | - while ( ( $object = $field->getNextObject() ) !== false ) { |
| 57 | + while ( ( $dv = $field->getNextDataValue() ) !== false ) { |
58 | 58 | if ( $first ) { |
59 | | - if ( $object->isNumeric() ) { // additional hidden sortkey for numeric entries |
60 | | - $result .= '<span class="smwsortkey">' . $object->getValueKey() . '</span>'; |
| 59 | + $sortkey = $dv->getDataItem()->getSortKey(); |
| 60 | + if ( is_numeric( $sortkey ) ) { // additional hidden sortkey for numeric entries |
| 61 | + $result .= '<span class="smwsortkey">' . $sortkey . '</span>'; |
61 | 62 | } |
62 | 63 | $first = false; |
63 | 64 | } else { |
64 | 65 | $result .= '<br />'; |
65 | 66 | } |
66 | 67 | // use shorter "LongText" for wikipage |
67 | | - $result .= ( ( $object->getTypeID() == '_wpg' ) || ( $object->getTypeID() == '__sin' ) ) ? |
68 | | - $object->getLongText( $outputmode, $this->getLinker( $firstcol ) ): |
69 | | - $object->getShortText( $outputmode, $this->getLinker( $firstcol ) ); |
| 68 | + $result .= ( ( $dv->getTypeID() == '_wpg' ) || ( $dv->getTypeID() == '__sin' ) ) ? |
| 69 | + $dv->getLongText( $outputmode, $this->getLinker( $firstcol ) ) : |
| 70 | + $dv->getShortText( $outputmode, $this->getLinker( $firstcol ) ); |
70 | 71 | } |
71 | 72 | $result .= "</td>\n"; |
72 | 73 | $firstcol = false; |
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_RDF.php |
— | — | @@ -58,7 +58,7 @@ |
59 | 59 | $property = $printreq->getData(); |
60 | 60 | break; |
61 | 61 | case SMWPrintRequest::PRINT_CATS: |
62 | | - $property = SMWPropertyValue::makeProperty( '_TYPE' ); |
| 62 | + $property = new SMWDIProperty( '_TYPE' ); |
63 | 63 | break; |
64 | 64 | case SMWPrintRequest::PRINT_CCAT: |
65 | 65 | // not serialised right now |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryParser.php |
— | — | @@ -315,7 +315,7 @@ |
316 | 316 | return null; ///TODO: read some more chunks and try to finish [[ ]] |
317 | 317 | } |
318 | 318 | |
319 | | - $typeid = $property->getPropertyTypeID(); |
| 319 | + $typeid = $property->getDataItem()->findPropertyTypeID(); |
320 | 320 | $inverse = $property->isInverse(); |
321 | 321 | $prevname = $name; |
322 | 322 | $properties[] = $property; |
— | — | @@ -377,7 +377,7 @@ |
378 | 378 | } |
379 | 379 | } ///NOTE: at this point, we normally already read one more chunk behind the value |
380 | 380 | |
381 | | - $dv = SMWDataValueFactory::newPropertyObjectValue( $property ); |
| 381 | + $dv = SMWDataValueFactory::newPropertyObjectValue( $property->getDataItem() ); |
382 | 382 | $vd = $dv->getQueryDescription( $value ); |
383 | 383 | $innerdesc = $this->addDescription( $innerdesc, $vd, false ); |
384 | 384 | $this->m_errors = $this->m_errors + $dv->getErrors(); |
— | — | @@ -395,7 +395,7 @@ |
396 | 396 | $properties = array_reverse( $properties ); |
397 | 397 | |
398 | 398 | foreach ( $properties as $property ) { |
399 | | - $innerdesc = new SMWSomeProperty( $property, $innerdesc ); |
| 399 | + $innerdesc = new SMWSomeProperty( $property->getDataItem(), $innerdesc ); |
400 | 400 | } |
401 | 401 | |
402 | 402 | $result = $innerdesc; |
Index: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Concept.php |
— | — | @@ -28,7 +28,7 @@ |
29 | 29 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
30 | 30 | |
31 | 31 | $title = $parser->getTitle(); |
32 | | - $pconc = SMWPropertyValue::makeProperty( '_CONC' ); |
| 32 | + $pconc = new SMWDIProperty( '_CONC' ); |
33 | 33 | |
34 | 34 | if ( $title->getNamespace() != SMW_NS_CONCEPT ) { |
35 | 35 | $result = smwfEncodeMessages( array( wfMsgForContent( 'smw_no_concept_namespace' ) ) ); |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php |
— | — | @@ -36,47 +36,49 @@ |
37 | 37 | return ''; |
38 | 38 | } |
39 | 39 | break; |
40 | | - // case SMW_FACTBOX_SHOWN: // just show ... |
| 40 | + // case SMW_FACTBOX_SHOWN: // just show ... |
41 | 41 | } |
42 | 42 | |
43 | 43 | // actually build the Factbox text: |
44 | 44 | $text = ''; |
45 | 45 | if ( wfRunHooks( 'smwShowFactbox', array( &$text, $semdata ) ) ) { |
46 | 46 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
| 47 | + $subjectDv = SMWDataValueFactory::newDataItemValue( $semdata->getSubject() ); |
47 | 48 | SMWOutputs::requireHeadItem( SMW_HEADER_STYLE ); |
48 | 49 | $rdflink = SMWInfolink::newInternalLink( |
49 | 50 | wfMsgForContent( 'smw_viewasrdf' ), |
50 | 51 | $wgContLang->getNsText( NS_SPECIAL ) . ':ExportRDF/' . |
51 | | - $semdata->getSubject()->getWikiValue(), |
| 52 | + $subjectDv->getWikiValue(), |
52 | 53 | 'rdflink' |
53 | 54 | ); |
54 | 55 | |
55 | 56 | $browselink = SMWInfolink::newBrowsingLink( |
56 | | - $semdata->getSubject()->getText(), |
57 | | - $semdata->getSubject()->getWikiValue(), |
| 57 | + $subjectDv->getText(), |
| 58 | + $subjectDv->getWikiValue(), |
58 | 59 | 'swmfactboxheadbrowse' |
59 | 60 | ); |
60 | 61 | $text .= '<div class="smwfact">' . |
61 | 62 | '<span class="smwfactboxhead">' . wfMsgForContent( 'smw_factbox_head', $browselink->getWikiText() ) . '</span>' . |
62 | 63 | '<span class="smwrdflink">' . $rdflink->getWikiText() . '</span>' . |
63 | 64 | '<table class="smwfacttable">' . "\n"; |
64 | | - foreach ( $semdata->getProperties() as $property ) { |
65 | | - if ( !$property->isShown() ) { // showing this is not desired, hide |
| 65 | + foreach ( $semdata->getProperties() as $propertyDi ) { |
| 66 | + $propertyDv = SMWDataValueFactory::newDataItemValue( $propertyDi ); |
| 67 | + if ( !$propertyDi->isShown() ) { // showing this is not desired, hide |
66 | 68 | continue; |
67 | | - } elseif ( $property->isUserDefined() ) { // user defined property |
68 | | - $property->setCaption( preg_replace( '/[ ]/u', ' ', $property->getWikiValue(), 2 ) ); |
| 69 | + } elseif ( $propertyDi->isUserDefined() ) { // user defined property |
| 70 | + $propertyDv->setCaption( preg_replace( '/[ ]/u', ' ', $propertyDv->getWikiValue(), 2 ) ); |
69 | 71 | /// NOTE: the preg_replace is a slight hack to ensure that the left column does not get too narrow |
70 | | - $text .= '<tr><td class="smwpropname">' . $property->getLongWikiText( true ) . '</td><td class="smwprops">'; |
71 | | - } elseif ( $property->isVisible() ) { // predefined property |
72 | | - $text .= '<tr><td class="smwspecname">' . $property->getLongWikiText( true ) . '</td><td class="smwspecs">'; |
| 72 | + $text .= '<tr><td class="smwpropname">' . $propertyDv->getLongWikiText( true ) . '</td><td class="smwprops">'; |
| 73 | + } elseif ( $propertyDv->isVisible() ) { // predefined property |
| 74 | + $text .= '<tr><td class="smwspecname">' . $propertyDv->getLongWikiText( true ) . '</td><td class="smwspecs">'; |
73 | 75 | } else { // predefined, internal property |
74 | 76 | continue; |
75 | 77 | } |
76 | 78 | |
77 | | - $propvalues = $semdata->getPropertyValues( $property ); |
| 79 | + $propvalues = $semdata->getPropertyValues( $propertyDi ); |
78 | 80 | $l = count( $propvalues ); |
79 | 81 | $i = 0; |
80 | | - foreach ( $propvalues as $propvalue ) { |
| 82 | + foreach ( $propvalues as $di ) { |
81 | 83 | if ( $i != 0 ) { |
82 | 84 | if ( $i > $l - 2 ) { |
83 | 85 | $text .= wfMsgForContent( 'smw_finallistconjunct' ) . ' '; |
— | — | @@ -85,7 +87,8 @@ |
86 | 88 | } |
87 | 89 | } |
88 | 90 | $i += 1; |
89 | | - $text .= $propvalue->getLongWikiText( true ) . $propvalue->getInfolinkText( SMW_OUTPUT_WIKI ); |
| 91 | + $dv = SMWDataValueFactory::newDataItemValue( $di ); |
| 92 | + $text .= $dv->getLongWikiText( true ) . $dv->getInfolinkText( SMW_OUTPUT_WIKI ); |
90 | 93 | } |
91 | 94 | $text .= '</td></tr>'; |
92 | 95 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_OrderedListPage.php |
— | — | @@ -159,7 +159,7 @@ |
160 | 160 | $first = $this->from; |
161 | 161 | |
162 | 162 | if ( $ac > $this->limit ) { |
163 | | - $last = $this->articles[$ac - 1]->getSortkey(); |
| 163 | + $last = SMWCompatibilityHelpers::getSortKey( $this->articles[$ac - 1] ); |
164 | 164 | } else { |
165 | 165 | $last = ''; |
166 | 166 | } |
— | — | @@ -199,21 +199,22 @@ |
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
203 | | - * Like Article's getTitle(), but returning a suitable SMWWikiPageValue |
| 203 | + * Like Article's getTitle(), but returning a suitable SMWDIWikiPage. |
204 | 204 | * |
205 | | - * @return SMWWikiPageValue |
| 205 | + * @return SMWDIWikiPage |
206 | 206 | */ |
207 | | - protected function getDataValue() { |
208 | | - return SMWWikiPageValue::makePageFromTitle( $this->getTitle() ); |
| 207 | + protected function getDataItem() { |
| 208 | + $title = $this->getTitle(); |
| 209 | + return new SMWDIWikiPage( $title->getDBKey(), $title->getNamespace(), $title->getInterwiki() ); |
209 | 210 | } |
210 | 211 | |
211 | 212 | /** |
212 | | - * Format a list of SMWWikipageValues chunked by letter in a three-column |
| 213 | + * Format a list of SMWDIWikiPage objects chunked by letter in a three-column |
213 | 214 | * list, ordered vertically. |
214 | 215 | * |
215 | | - * @param integer $start |
216 | | - * @param integer $end |
217 | | - * @param array $elements |
| 216 | + * @param $start integer |
| 217 | + * @param $end integer |
| 218 | + * @param $elements of SMWDIWikiPage |
218 | 219 | * |
219 | 220 | * @return string |
220 | 221 | */ |
— | — | @@ -237,6 +238,7 @@ |
238 | 239 | |
239 | 240 | // output all articles |
240 | 241 | for ( $index = $startChunk ; $index < $endChunk && $index < $end; $index++ ) { |
| 242 | + $elementDv = SMWDataValueFactory::newDataItemValue( $elements[$index] ); |
241 | 243 | // check for change of starting letter or begining of chunk |
242 | 244 | $start_char = $wgContLang->convert( $wgContLang->firstChar( $elements[$index]->getSortkey() ) ); |
243 | 245 | |
— | — | @@ -258,7 +260,7 @@ |
259 | 261 | $prev_start_char = $start_char; |
260 | 262 | } |
261 | 263 | |
262 | | - $r .= "<li>" . $elements[$index]->getLongHTMLText( $this->getSkin() ) . "</li>\n"; |
| 264 | + $r .= "<li>" . $elementDv->getLongHTMLText( $this->getSkin() ) . "</li>\n"; |
263 | 265 | } |
264 | 266 | |
265 | 267 | if ( !$atColumnTop ) { |
— | — | @@ -288,9 +290,11 @@ |
289 | 291 | $start_char = $wgContLang->convert( $wgContLang->firstChar( $elements[$start]->getSortkey() ) ); |
290 | 292 | $prev_start_char = $start_char; |
291 | 293 | $r = '<h3>' . htmlspecialchars( $start_char ) . "</h3>\n"; |
292 | | - $r .= '<ul><li>' . $elements[$start]->getLongHTMLText( $this->getSkin() ) . '</li>'; |
| 294 | + $elementStartDv = SMWDataValueFactory::newDataItemValue( $elements[$start] ); |
| 295 | + $r .= '<ul><li>' . $elementStartDv->getLongHTMLText( $this->getSkin() ) . '</li>'; |
293 | 296 | |
294 | 297 | for ( $index = $start + 1; $index < $end; $index++ ) { |
| 298 | + $elementDv = SMWDataValueFactory::newDataItemValue( $elements[$index] ); |
295 | 299 | $start_char = $wgContLang->convert( $wgContLang->firstChar( $elements[$index]->getSortkey() ) ); |
296 | 300 | |
297 | 301 | if ( $start_char != $prev_start_char ) { |
— | — | @@ -298,7 +302,7 @@ |
299 | 303 | $prev_start_char = $start_char; |
300 | 304 | } |
301 | 305 | |
302 | | - $r .= '<li>' . $elements[$index]->getLongHTMLText( $this->getSkin() ) . '</li>'; |
| 306 | + $r .= '<li>' . $elementDv->getLongHTMLText( $this->getSkin() ) . '</li>'; |
303 | 307 | } |
304 | 308 | |
305 | 309 | $r .= '</ul>'; |
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_TypePage.php |
— | — | @@ -42,14 +42,14 @@ |
43 | 43 | $options->boundary = $this->from; |
44 | 44 | $options->ascending = true; |
45 | 45 | $options->include_boundary = true; |
46 | | - $this->articles = $store->getPropertySubjects( SMWPropertyValue::makeProperty( '_TYPE' ), $typevalue, $options ); |
| 46 | + $this->articles = $store->getPropertySubjects( new SMWDIProperty( '_TYPE' ), $typevalue->getDataItem(), $options ); |
47 | 47 | } elseif ( $this->until != '' ) { |
48 | 48 | $options->boundary = $this->until; |
49 | 49 | $options->ascending = false; |
50 | 50 | $options->include_boundary = false; |
51 | | - $this->articles = array_reverse( $store->getPropertySubjects( SMWPropertyValue::makeProperty( '_TYPE' ), $typevalue, $options ) ); |
| 51 | + $this->articles = array_reverse( $store->getPropertySubjects( new SMWDIProperty( '_TYPE' ), $typevalue->getDataItem(), $options ) ); |
52 | 52 | } else { |
53 | | - $this->articles = $store->getPropertySubjects( SMWPropertyValue::makeProperty( '_TYPE' ), $typevalue, $options ); |
| 53 | + $this->articles = $store->getPropertySubjects( new SMWDIProperty( '_TYPE' ), $typevalue->getDataItem(), $options ); |
54 | 54 | } |
55 | 55 | } else { |
56 | 56 | $this->articles = array(); |
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_PropertyPage.php |
— | — | @@ -18,15 +18,13 @@ |
19 | 19 | private $mProperty; // property object |
20 | 20 | |
21 | 21 | /** |
22 | | - * Use small $limit (property pages might become large) |
| 22 | + * @see SMWOrderedListPage::initParameters() |
| 23 | + * @note We use a smaller limit here; property pages might become large. |
23 | 24 | */ |
24 | 25 | protected function initParameters() { |
25 | | - global $smwgContLang, $smwgPropertyPagingLimit; |
26 | | - |
| 26 | + global $smwgPropertyPagingLimit; |
27 | 27 | $this->limit = $smwgPropertyPagingLimit; |
28 | | - $this->mProperty = SMWPropertyValue::makeProperty( $this->mTitle->getDBkey() ); |
29 | | - $this->mProperty->setInverse( false ); |
30 | | - |
| 28 | + $this->mProperty = new SMWDIProperty( $this->mTitle->getDBkey(), false ); |
31 | 29 | return true; |
32 | 30 | } |
33 | 31 | |
— | — | @@ -72,7 +70,7 @@ |
73 | 71 | $s_options = new SMWRequestOptions(); |
74 | 72 | $s_options->sort = true; |
75 | 73 | $s_options->ascending = true; |
76 | | - $this->subproperties = $store->getPropertySubjects( SMWPropertyValue::makeProperty( '_SUBP' ), $this->getDataValue(), $s_options ); |
| 74 | + $this->subproperties = $store->getPropertySubjects( new SMWDIProperty( '_SUBP' ), $this->getDataItem(), $s_options ); |
77 | 75 | } |
78 | 76 | |
79 | 77 | /** |
— | — | @@ -144,7 +142,9 @@ |
145 | 143 | $prev_start_char = 'None'; |
146 | 144 | |
147 | 145 | for ( $index = $start; $index < $ac; $index++ ) { |
148 | | - $start_char = $wgContLang->convert( $wgContLang->firstChar( $this->articles[$index]->getSortkey() ) ); |
| 146 | + $diWikiPage = $this->articles[$index]; |
| 147 | + $dvWikiPage = SMWDataValueFactory::newDataItemValue( $diWikiPage ); |
| 148 | + $start_char = $wgContLang->convert( $wgContLang->firstChar( SMWCompatibilityHelpers::getSortKey( $diWikiPage ) ) ); |
149 | 149 | |
150 | 150 | // Header for index letters |
151 | 151 | if ( $start_char != $prev_start_char ) { |
— | — | @@ -153,31 +153,31 @@ |
154 | 154 | } |
155 | 155 | |
156 | 156 | // Property name |
157 | | - $searchlink = SMWInfolink::newBrowsingLink( '+', $this->articles[$index]->getShortHTMLText() ); |
158 | | - $r .= '<tr><td class="smwpropname">' . $this->articles[$index]->getLongHTMLText( $this->getSkin() ) . |
| 157 | + $searchlink = SMWInfolink::newBrowsingLink( '+', $dvWikiPage->getShortHTMLText() ); |
| 158 | + $r .= '<tr><td class="smwpropname">' . $dvWikiPage->getLongHTMLText( $this->getSkin() ) . |
159 | 159 | ' ' . $searchlink->getHTML( $this->getSkin() ) . '</td><td class="smwprops">'; |
160 | 160 | |
161 | 161 | // Property values |
162 | 162 | $ropts = new SMWRequestOptions(); |
163 | 163 | $ropts->limit = $smwgMaxPropertyValues + 1; |
164 | | - $values = $store->getPropertyValues( $this->articles[$index], $this->mProperty, $ropts ); |
| 164 | + $values = $store->getPropertyValues( $diWikiPage, $this->mProperty, $ropts ); |
165 | 165 | $i = 0; |
166 | 166 | |
167 | | - foreach ( $values as $value ) { |
| 167 | + foreach ( $values as $di ) { |
168 | 168 | if ( $i != 0 ) { |
169 | 169 | $r .= ', '; |
170 | 170 | } |
171 | | - |
172 | 171 | $i++; |
173 | | - |
| 172 | + |
174 | 173 | if ( $i < $smwgMaxPropertyValues + 1 ) { |
175 | | - $r .= $value->getLongHTMLText( $this->getSkin() ) . $value->getInfolinkText( SMW_OUTPUT_HTML, $this->getSkin() ); |
| 174 | + $dv = SMWDataValueFactory::newDataItemValue( $di ); |
| 175 | + $r .= $dv->getLongHTMLText( $this->getSkin() ) . $dv->getInfolinkText( SMW_OUTPUT_HTML, $this->getSkin() ); |
176 | 176 | } else { |
177 | | - $searchlink = SMWInfolink::newInversePropertySearchLink( '…', $this->articles[$index]->getWikiValue(), $this->mTitle->getText() ); |
| 177 | + $searchlink = SMWInfolink::newInversePropertySearchLink( '…', $dvWikiPage->getWikiValue(), $this->mTitle->getText() ); |
178 | 178 | $r .= $searchlink->getHTML( $this->getSkin() ); |
179 | 179 | } |
180 | 180 | } |
181 | | - |
| 181 | + |
182 | 182 | $r .= "</td></tr>\n"; |
183 | 183 | } |
184 | 184 | |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_SetupLight.php |
— | — | @@ -104,15 +104,16 @@ |
105 | 105 | $wgAutoloadClasses['SMWDataItem'] = $diDir . 'SMW_DataItem.php'; |
106 | 106 | $wgAutoloadClasses['SMWDataItemException'] = $diDir . 'SMW_DataItem.php'; |
107 | 107 | $wgAutoloadClasses['SMWDIProperty'] = $diDir . 'SMW_DI_Property.php'; |
108 | | -// $wgAutoloadClasses['SMWDIBool'] = $diDir . 'SMW_DI_Bool.php'; |
| 108 | +// $wgAutoloadClasses['SMWDIBoolean'] = $diDir . 'SMW_DI_Bool.php'; |
109 | 109 | $wgAutoloadClasses['SMWDINumber'] = $diDir . 'SMW_DI_Number.php'; |
110 | 110 | $wgAutoloadClasses['SMWDIBlob'] = $diDir . 'SMW_DI_Blob.php'; |
111 | 111 | $wgAutoloadClasses['SMWDIString'] = $diDir . 'SMW_DI_String.php'; |
112 | 112 | $wgAutoloadClasses['SMWStringLengthException'] = $diDir . 'SMW_DI_String.php'; |
113 | | - $wgAutoloadClasses['SMWDIURI'] = $diDir . 'SMW_DI_URI.php'; |
| 113 | + $wgAutoloadClasses['SMWDIUri'] = $diDir . 'SMW_DI_URI.php'; |
114 | 114 | $wgAutoloadClasses['SMWDIWikiPage'] = $diDir . 'SMW_DI_WikiPage.php'; |
115 | 115 | $wgAutoloadClasses['SMWDITime'] = $diDir . 'SMW_DI_Time.php'; |
116 | 116 | // $wgAutoloadClasses['SMWDIConcept'] = $diDir . 'SMW_DI_Concept.php'; |
| 117 | + $wgAutoloadClasses['SMWDIError'] = $diDir . 'SMW_DI_Error.php'; |
117 | 118 | |
118 | 119 | // Datavalues |
119 | 120 | $dvDir = $smwgIP . 'includes/datavalues/'; |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php |
— | — | @@ -285,7 +285,7 @@ |
286 | 286 | |
287 | 287 | protected $m_concept; |
288 | 288 | |
289 | | - public function __construct( Title $concept ) { |
| 289 | + public function __construct( SMWDIWikiPage $concept ) { |
290 | 290 | $this->m_concept = $concept; |
291 | 291 | } |
292 | 292 | |
— | — | @@ -738,7 +738,7 @@ |
739 | 739 | protected $m_description; |
740 | 740 | protected $m_property; |
741 | 741 | |
742 | | - public function __construct( SMWPropertyValue $property, SMWDescription $description ) { |
| 742 | + public function __construct( SMWDIProperty $property, SMWDescription $description ) { |
743 | 743 | $this->m_property = $property; |
744 | 744 | $this->m_description = $description; |
745 | 745 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_QueryResult.php |
— | — | @@ -28,8 +28,8 @@ |
29 | 29 | class SMWQueryResult { |
30 | 30 | |
31 | 31 | /** |
32 | | - * Array of SMWWikiPageValue objects that are the basis for this result |
33 | | - * @var Array of SMWWikiPageValue |
| 32 | + * Array of SMWDIWikiPage objects that are the basis for this result |
| 33 | + * @var Array of SMWDIWikiPage |
34 | 34 | */ |
35 | 35 | protected $mResults; |
36 | 36 | |
— | — | @@ -66,7 +66,7 @@ |
67 | 67 | * |
68 | 68 | * @param array of SMWPrintRequest $printRequests |
69 | 69 | * @param SMWQuery $query |
70 | | - * @param array of SMWWikiPageValue $results |
| 70 | + * @param array of SMWDIWikiPage $results |
71 | 71 | * @param SMWStore $store |
72 | 72 | * @param boolean $furtherRes |
73 | 73 | */ |
— | — | @@ -110,10 +110,10 @@ |
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
114 | | - * Return an array of SMWWikiPageValue objects that make up the |
| 114 | + * Return an array of SMWDIWikiPage objects that make up the |
115 | 115 | * results stored in this object. |
116 | 116 | * |
117 | | - * @return array of SMWWikiPageValue |
| 117 | + * @return array of SMWDIWikiPage |
118 | 118 | */ |
119 | 119 | public function getResults() { |
120 | 120 | return $this->mResults; |
— | — | @@ -220,7 +220,7 @@ |
221 | 221 | |
222 | 222 | /** |
223 | 223 | * Container for the contents of a single result field of a query result, |
224 | | - * i.e. basically an array of SMWDataValues with some additional parameters. |
| 224 | + * i.e. basically an array of SMWDataItems with some additional parameters. |
225 | 225 | * The content of the array is fetched on demand only. |
226 | 226 | * @ingroup SMWQuery |
227 | 227 | */ |
— | — | @@ -231,7 +231,7 @@ |
232 | 232 | protected $mPrintRequest; |
233 | 233 | |
234 | 234 | /** |
235 | | - * @var SMWWikiPageValue |
| 235 | + * @var SMWDIWikiPage |
236 | 236 | */ |
237 | 237 | protected $mResult; |
238 | 238 | |
— | — | @@ -241,7 +241,7 @@ |
242 | 242 | protected $mStore; |
243 | 243 | |
244 | 244 | /** |
245 | | - * @var array of SMWDataValue or false |
| 245 | + * @var array of SMWDataItem or false |
246 | 246 | */ |
247 | 247 | protected $mContent; |
248 | 248 | |
— | — | @@ -251,11 +251,11 @@ |
252 | 252 | /** |
253 | 253 | * Constructor. |
254 | 254 | * |
255 | | - * @param SMWWikiPageValue $resultPage |
| 255 | + * @param SMWDIWikiPage $resultPage |
256 | 256 | * @param SMWPrintRequest $printRequest |
257 | 257 | * @param SMWStore $store |
258 | 258 | */ |
259 | | - public function __construct( SMWWikiPageValue $resultPage, SMWPrintRequest $printRequest, SMWStore $store ) { |
| 259 | + public function __construct( SMWDIWikiPage $resultPage, SMWPrintRequest $printRequest, SMWStore $store ) { |
260 | 260 | $this->mResult = $resultPage; |
261 | 261 | $this->mPrintRequest = $printRequest; |
262 | 262 | $this->mStore = $store; |
— | — | @@ -263,21 +263,21 @@ |
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
267 | | - * Returns the SMWWikiPageValue object to which this SMWResultArray refers. |
| 267 | + * Returns the SMWDIWikiPage object to which this SMWResultArray refers. |
268 | 268 | * If you only care for those objects, consider using SMWQueryResult::getResults() |
269 | 269 | * directly. |
270 | 270 | * |
271 | | - * @return SMWWikiPageValue |
| 271 | + * @return SMWDIWikiPage |
272 | 272 | */ |
273 | 273 | public function getResultSubject() { |
274 | 274 | return $this->mResult; |
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
278 | | - * Returns an array of SMWDataValue objects that contain the results of |
| 278 | + * Returns an array of SMWDataItem objects that contain the results of |
279 | 279 | * the given print request for the given result object. |
280 | 280 | * |
281 | | - * @return array of SMWDataValue or false |
| 281 | + * @return array of SMWDataItem or false |
282 | 282 | */ |
283 | 283 | public function getContent() { |
284 | 284 | $this->loadContent(); |
— | — | @@ -295,37 +295,62 @@ |
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
299 | | - * Return the next SMWDataValue object or false if no further object exists. |
| 299 | + * Compatibility alias for getNextDatItem(). |
| 300 | + * @deprecated Call getNextDataValue() or getNextDataItem() directly as needed. Method will vanish before SMW 1.7. |
| 301 | + */ |
| 302 | + public function getNextObject() { |
| 303 | + return $this->getNextDataValue(); |
| 304 | + } |
| 305 | + |
| 306 | + /** |
| 307 | + * Return the next SMWDataItem object or false if no further object exists. |
300 | 308 | * |
301 | | - * @return SMWDataValue |
| 309 | + * @return SMWDataItem or false |
302 | 310 | */ |
303 | | - public function getNextObject() { |
| 311 | + public function getNextDataItem() { |
304 | 312 | $this->loadContent(); |
305 | | - |
306 | 313 | $result = current( $this->mContent ); |
307 | 314 | next( $this->mContent ); |
308 | | - |
309 | 315 | return $result; |
310 | 316 | } |
311 | 317 | |
| 318 | + |
312 | 319 | /** |
313 | | - * Return the main text representation of the next SMWDataValue object |
| 320 | + * Return an SMWDataValue object for the next SMWDataItem object or |
| 321 | + * false if no further object exists. |
| 322 | + * |
| 323 | + * @return SMWDataValue or false |
| 324 | + */ |
| 325 | + public function getNextDataValue() { |
| 326 | + $di = $this->getNextDataItem(); |
| 327 | + if ( $di === false ) { |
| 328 | + return false; |
| 329 | + } |
| 330 | + $dv = SMWDataValueFactory::newDataItemValue( $di ); |
| 331 | + if ( $this->mPrintRequest->getOutputFormat() ) { |
| 332 | + $dv->setOutputFormat( $this->mPrintRequest->getOutputFormat() ); |
| 333 | + } |
| 334 | + return $dv; |
| 335 | + } |
| 336 | + |
| 337 | + /** |
| 338 | + * Return the main text representation of the next SMWDataItem object |
314 | 339 | * in the specified format, or false if no further object exists. |
315 | 340 | * |
316 | 341 | * The parameter $linker controls linking of title values and should |
317 | | - * be some Linker object (or NULL for no linking). At some stage its |
318 | | - * interpretation should be part of the generalised SMWDataValue. |
| 342 | + * be some Linker object (or NULL for no linking). |
319 | 343 | * |
320 | | - * @param $outputMode |
321 | | - * @param $linker |
| 344 | + * @param integer $outputMode |
| 345 | + * @param mixed $linker |
322 | 346 | */ |
323 | 347 | public function getNextText( $outputMode, $linker = null ) { |
324 | | - $object = $this->getNextObject(); |
325 | | - |
326 | | - if ( $object instanceof SMWDataValue ) { // Print data values. |
327 | | - return ( ( $object->getTypeID() == '_wpg' ) || ( $object->getTypeID() == '__sin' ) ) ? // Prefer "long" text for page-values. |
328 | | - $object->getLongText( $outputMode, $linker ) : |
329 | | - $object->getShortText( $outputMode, $linker ); |
| 348 | + $dv = $this->getNextDataValue(); |
| 349 | + if ( $dv !== false ) { // Print data values. |
| 350 | + if ( ( $dv->getTypeID() == '_wpg' ) || ( $dv->getTypeID() == '__sin' ) ) { // Prefer "long" text for page-values. |
| 351 | + return $dv->getLongText( $outputMode, $linker ); |
| 352 | + } else { |
| 353 | + return $dv->getShortText( $outputMode, $linker ); |
| 354 | + } |
330 | 355 | } else { |
331 | 356 | return false; |
332 | 357 | } |
— | — | @@ -342,30 +367,24 @@ |
343 | 368 | |
344 | 369 | switch ( $this->mPrintRequest->getMode() ) { |
345 | 370 | case SMWPrintRequest::PRINT_THIS: // NOTE: The limit is ignored here. |
346 | | - if ( $this->mPrintRequest->getOutputFormat() ) { |
347 | | - $res = clone $this->mResult; |
348 | | - $res->setOutputFormat( $this->mPrintRequest->getOutputFormat() ); |
349 | | - } else { |
350 | | - $res = $this->mResult; |
351 | | - } |
352 | | - |
353 | | - $this->mContent = array( $res ); |
| 371 | + $this->mContent = array( $this->mResult ); |
354 | 372 | break; |
355 | 373 | case SMWPrintRequest::PRINT_CATS: |
356 | 374 | // Always recompute cache here to ensure output format is respected. |
357 | | - self::$catCache = $this->mStore->getPropertyValues( $this->mResult, SMWPropertyValue::makeProperty( '_INST' ), $this->getRequestOptions( false ), $this->mPrintRequest->getOutputFormat() ); |
| 375 | + self::$catCache = $this->mStore->getPropertyValues( $this->mResult, new SMWDIProperty( '_INST' ), $this->getRequestOptions( false ) ); |
358 | 376 | self::$catCacheObj = $this->mResult->getHash(); |
359 | 377 | |
360 | 378 | $limit = $this->mPrintRequest->getParameter( 'limit' ); |
361 | 379 | $this->mContent = ( $limit === false ) ? ( self::$catCache ) : array_slice( self::$catCache, 0, $limit ); |
362 | 380 | break; |
363 | 381 | case SMWPrintRequest::PRINT_PROP: |
364 | | - $this->mContent = $this->mStore->getPropertyValues( $this->mResult, $this->mPrintRequest->getData(), $this->getRequestOptions(), $this->mPrintRequest->getOutputFormat() ); |
365 | | - |
| 382 | + $this->mContent = $this->mStore->getPropertyValues( $this->mResult, $this->mPrintRequest->getData()->getDataItem(), $this->getRequestOptions() ); |
| 383 | + |
366 | 384 | // Print one component of a multi-valued string. |
367 | 385 | // Known limitation: the printrequest still is of type _rec, so if printers check |
368 | 386 | // for this then they will not recognize that it returns some more concrete type. |
369 | | - if ( ( $this->mPrintRequest->getTypeID() == '_rec' ) && ( $this->mPrintRequest->getParameter( 'index' ) !== false ) ) { |
| 387 | + if ( ( $this->mPrintRequest->getTypeID() == '_rec' ) && |
| 388 | + ( $this->mPrintRequest->getParameter( 'index' ) !== false ) ) { |
370 | 389 | $pos = $this->mPrintRequest->getParameter( 'index' ) - 1; |
371 | 390 | $newcontent = array(); |
372 | 391 | |
— | — | @@ -381,24 +400,20 @@ |
382 | 401 | break; |
383 | 402 | case SMWPrintRequest::PRINT_CCAT: ///NOTE: The limit is ignored here. |
384 | 403 | if ( self::$catCacheObj != $this->mResult->getHash() ) { |
385 | | - self::$catCache = $this->mStore->getPropertyValues( $this->mResult, SMWPropertyValue::makeProperty( '_INST' ) ); |
| 404 | + self::$catCache = $this->mStore->getPropertyValues( $this->mResult, new SMWDIProperty( '_INST' ) ); |
386 | 405 | self::$catCacheObj = $this->mResult->getHash(); |
387 | 406 | } |
388 | | - |
| 407 | + |
389 | 408 | $found = '0'; |
390 | 409 | $prkey = $this->mPrintRequest->getData()->getDBkey(); |
391 | | - |
| 410 | + |
392 | 411 | foreach ( self::$catCache as $cat ) { |
393 | 412 | if ( $cat->getDBkey() == $prkey ) { |
394 | 413 | $found = '1'; |
395 | 414 | break; |
396 | 415 | } |
397 | 416 | } |
398 | | - |
399 | | - $dv = SMWDataValueFactory::newTypeIDValue( '_boo' ); |
400 | | - $dv->setOutputFormat( $this->mPrintRequest->getOutputFormat() ); |
401 | | - $dv->setDBkeys( array( $found ) ); |
402 | | - $this->mContent = array( $dv ); |
| 417 | + $this->mContent = array( new SMWDIBoolean( $found ) ); |
403 | 418 | break; |
404 | 419 | default: $this->mContent = array(); // Unknown print request. |
405 | 420 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStoreLight.php |
— | — | @@ -100,7 +100,7 @@ |
101 | 101 | return $this->m_semdata[$sid]; |
102 | 102 | } |
103 | 103 | |
104 | | - public function getPropertyValues( $subject, SMWPropertyValue $property, $requestoptions = null, $outputformat = '' ) { |
| 104 | + public function getPropertyValues( $subject, SMWDIProperty $property, $requestoptions = null, $outputformat = '' ) { |
105 | 105 | wfProfileIn( "SMWSQLStoreLight::getPropertyValues (SMW)" ); |
106 | 106 | if ( $property->isInverse() ) { // inverses are working differently |
107 | 107 | $noninverse = clone $property; |
— | — | @@ -136,7 +136,7 @@ |
137 | 137 | return $result; |
138 | 138 | } |
139 | 139 | |
140 | | - public function getPropertySubjects( SMWPropertyValue $property, $value, $requestoptions = null ) { |
| 140 | + public function getPropertySubjects( SMWDIProperty $property, $value, $requestoptions = null ) { |
141 | 141 | wfProfileIn( "SMWSQLStoreLight::getPropertySubjects (SMW)" ); |
142 | 142 | if ( $property->isInverse() ) { // inverses are working differently |
143 | 143 | $noninverse = clone $property; |
— | — | @@ -170,7 +170,7 @@ |
171 | 171 | return $result; |
172 | 172 | } |
173 | 173 | |
174 | | - public function getAllPropertySubjects( SMWPropertyValue $property, $requestoptions = null ) { |
| 174 | + public function getAllPropertySubjects( SMWDIProperty $property, $requestoptions = null ) { |
175 | 175 | wfProfileIn( "SMWSQLStoreLight::getAllPropertySubjects (SMW)" ); |
176 | 176 | $result = $this->getPropertySubjects( $property, null, $requestoptions ); |
177 | 177 | wfProfileOut( "SMWSQLStoreLight::getAllPropertySubjects (SMW)" ); |
— | — | @@ -202,7 +202,7 @@ |
203 | 203 | 'pageid=' . $db->addQuotes($sid) . $this->getSQLConditions( $suboptions, 'propname', 'propname' ), |
204 | 204 | 'SMW::getProperties', $this->getSQLOptions( $suboptions, 'propname' ) ); |
205 | 205 | while ( $row = $db->fetchObject( $res ) ) { |
206 | | - $result[] = SMWPropertyValue::makeProperty( $row->propname ); |
| 206 | + $result[] = new SMWDIProperty( $row->propname ); |
207 | 207 | } |
208 | 208 | $db->freeResult( $res ); |
209 | 209 | } |
— | — | @@ -242,7 +242,7 @@ |
243 | 243 | $where . $this->getSQLConditions( $suboptions, 'propname', 'propname' ), |
244 | 244 | 'SMW::getInProperties', $this->getSQLOptions( $suboptions, 'propname' ) ); |
245 | 245 | while ( $row = $db->fetchObject( $res ) ) { |
246 | | - $result[] = SMWPropertyValue::makeProperty( $row->propname ); |
| 246 | + $result[] = new SMWDIProperty( $row->propname ); |
247 | 247 | } |
248 | 248 | $db->freeResult( $res ); |
249 | 249 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_PrintRequest.php |
— | — | @@ -135,13 +135,15 @@ |
136 | 136 | /** |
137 | 137 | * If this print request refers to some property, return the type id of this property. |
138 | 138 | * Otherwise return FALSE. |
| 139 | + * |
| 140 | + * @todo It is unclear why the actual code returns '_wpg' as a default given this documentation. |
139 | 141 | * |
140 | 142 | * @return string |
141 | 143 | */ |
142 | 144 | public function getTypeID() { |
143 | 145 | if ( $this->m_typeid === false ) { |
144 | 146 | if ( $this->m_mode == SMWPrintRequest::PRINT_PROP ) { |
145 | | - $this->m_typeid = $this->m_data->getPropertyTypeID(); |
| 147 | + $this->m_typeid = $this->m_data->getDataItem()->findPropertyTypeID(); |
146 | 148 | } else { |
147 | 149 | $this->m_typeid = '_wpg'; // return objects might be titles, but anyway |
148 | 150 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php |
— | — | @@ -101,9 +101,9 @@ |
102 | 102 | return $this->m_errors; |
103 | 103 | } |
104 | 104 | |
105 | | - $values = $this->m_store->getPropertyValues( $concept, SMWPropertyValue::makeProperty( '_CONC' ) );// two lines due to "strict standards" warning |
106 | | - $dv = end( $values ); |
107 | | - $desctxt = ( $dv !== false ) ? $dv->getWikiValue() : false; |
| 105 | + $values = $this->m_store->getPropertyValues( $concept, new SMWDIProperty( '_CONC' ) );// two lines due to "strict standards" warning |
| 106 | + $di = end( $values ); |
| 107 | + $desctxt = ( $di !== false ) ? $di->getConceptQuery() : false; |
108 | 108 | $this->m_errors = array(); |
109 | 109 | |
110 | 110 | if ( $desctxt ) { // concept found |
— | — | @@ -408,7 +408,7 @@ |
409 | 409 | |
410 | 410 | while ( ( $count < $query->getLimit() ) && ( $row = $this->m_dbs->fetchObject( $res ) ) ) { |
411 | 411 | $count++; |
412 | | - $v = SMWWikiPageValue::makePage( $row->t, $row->ns, $row->sortkey ); |
| 412 | + $v = new SMWDIWikiPage( $row->t, $row->ns, $row->iw ); |
413 | 413 | $qr[] = $v; |
414 | 414 | $this->m_store->cacheSMWPageID( $row->id, $row->t, $row->ns, $row->iw ); |
415 | 415 | } |
— | — | @@ -587,14 +587,14 @@ |
588 | 588 | * to check for this and discard the query in this case. |
589 | 589 | * @todo Check if hierarchy queries work as expected. |
590 | 590 | */ |
591 | | - protected function compilePropertyCondition( SMWSQLStore2Query $query, $property, SMWDescription $valuedesc ) { |
| 591 | + protected function compilePropertyCondition( SMWSQLStore2Query $query, SMWDIProperty $property, SMWDescription $valuedesc ) { |
592 | 592 | $tableid = SMWSQLStore2::findPropertyTableID( $property ); |
593 | 593 | |
594 | 594 | if ( $tableid == '' ) { // probably a type-polymorphic property |
595 | 595 | $typeid = $valuedesc->getTypeID(); |
596 | 596 | $tableid = SMWSQLStore2::findTypeTableID( $typeid ); |
597 | 597 | } else { // normal property |
598 | | - $typeid = $property->getPropertyTypeID(); |
| 598 | + $typeid = $property->findPropertyTypeID(); |
599 | 599 | } |
600 | 600 | |
601 | 601 | if ( $tableid == '' ) { // Still no table to query? Give up. |
— | — | @@ -611,7 +611,7 @@ |
612 | 612 | } |
613 | 613 | |
614 | 614 | list( $sig, $valueindex, $labelindex ) = SMWSQLStore2::getTypeSignature( $typeid ); |
615 | | - $sortkey = $property->getDBkey(); // TODO: strictly speaking, the DB key is not what we want here, since sortkey is based on a "wiki value" |
| 615 | + $sortkey = $property->getKey(); // TODO: strictly speaking, the DB key is not what we want here, since sortkey is based on a "wiki value" |
616 | 616 | |
617 | 617 | // *** Basic settings: table, joinfield, and objectfields ***// |
618 | 618 | $query->jointable = $proptable->name; |
— | — | @@ -634,7 +634,7 @@ |
635 | 635 | if ( $proptable->fixedproperty == false ) { |
636 | 636 | $pid = $this->m_store->getSMWPropertyID( $property ); |
637 | 637 | |
638 | | - if ( !$property->getPropertyID() || ( $property->getPropertyTypeID() != '__err' ) ) { |
| 638 | + if ( $property->isUserDefined() || ( $property->findPropertyTypeID() != '__err' ) ) { |
639 | 639 | // also make property hierarchy (may or may not be executed later on) |
640 | 640 | // exclude type-polymorphic properties _1, _2, ... (2nd check above suffices, but 1st is faster to check) |
641 | 641 | // we could also exclude other cases here, if desired |
— | — | @@ -1076,7 +1076,7 @@ |
1077 | 1077 | $sortprop = SMWPropertyValue::makeUserProperty( $propkey ); |
1078 | 1078 | |
1079 | 1079 | if ( $sortprop->isValid() ) { |
1080 | | - $extraproperties[] = new SMWSomeProperty( $sortprop, new SMWThingDescription() ); |
| 1080 | + $extraproperties[] = new SMWSomeProperty( $sortprop->getDataItem(), new SMWThingDescription() ); |
1081 | 1081 | } |
1082 | 1082 | } |
1083 | 1083 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php |
— | — | @@ -77,10 +77,9 @@ |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * Should the result be ordered? The employed order is defined |
81 | | - * by the type of result that are requested: Title objects and |
82 | | - * strings are ordered alphabetically, whereas SMWDataValue |
83 | | - * objects can provide different custom orders if they are scalar. |
84 | | - * Usually, the order should be fairly "natural". |
| 81 | + * by the type of result that are requested: wiki pages and strings |
| 82 | + * are ordered alphabetically, whereas other data is ordered |
| 83 | + * numerically. Usually, the order should be fairly "natural". |
85 | 84 | */ |
86 | 85 | public $sort = false; |
87 | 86 | |
— | — | @@ -155,47 +154,45 @@ |
156 | 155 | * than requested when a filter is used. Filtering just ensures that |
157 | 156 | * only necessary requests are made, i.e. it improves performance. |
158 | 157 | */ |
159 | | - public abstract function getSemanticData( $subject, $filter = false ); |
| 158 | + public abstract function getSemanticData( SMWDIWikiPage $subject, $filter = false ); |
160 | 159 | |
161 | 160 | /** |
162 | 161 | * Get an array of all property values stored for the given subject and property. The result |
163 | | - * is an array of SMWDataValue objects. The provided outputformat is a string identifier that |
164 | | - * may be used by the datavalues to modify their output behaviour, e.g. when interpreted as a |
165 | | - * desired unit to convert the output to. |
| 162 | + * is an array of SMWDataItem objects. |
166 | 163 | * |
167 | 164 | * If called with $subject == NULL, all values for the given property are returned. |
168 | 165 | */ |
169 | | - public abstract function getPropertyValues( $subject, SMWPropertyValue $property, $requestoptions = null, $outputformat = '' ); |
| 166 | + public abstract function getPropertyValues( $subject, SMWDIProperty $property, $requestoptions = null ); |
170 | 167 | |
171 | 168 | /** |
172 | 169 | * Get an array of all subjects that have the given value for the given property. The |
173 | | - * result is an array of SMWWikiPageValue objects. If NULL is given as a value, all subjects having |
| 170 | + * result is an array of SMWDIWikiPage objects. If NULL is given as a value, all subjects having |
174 | 171 | * that property are returned. |
175 | 172 | */ |
176 | | - public abstract function getPropertySubjects( SMWPropertyValue $property, $value, $requestoptions = null ); |
| 173 | + public abstract function getPropertySubjects( SMWDIProperty $property, $value, $requestoptions = null ); |
177 | 174 | |
178 | 175 | /** |
179 | 176 | * Get an array of all subjects that have some value for the given property. The |
180 | | - * result is an array of SMWWikiPageValue objects. |
| 177 | + * result is an array of SMWDIWikiPage objects. |
181 | 178 | */ |
182 | | - public abstract function getAllPropertySubjects( SMWPropertyValue $property, $requestoptions = null ); |
| 179 | + public abstract function getAllPropertySubjects( SMWDIProperty $property, $requestoptions = null ); |
183 | 180 | |
184 | 181 | /** |
185 | 182 | * Get an array of all properties for which the given subject has some value. The result is an |
186 | | - * array of SMWPropertyValue objects. |
| 183 | + * array of SMWDIProperty objects. |
187 | 184 | * |
188 | | - * @param $subject Title or SMWWikiPageValue denoting the subject |
| 185 | + * @param $subject SMWDIWikiPage denoting the subject |
189 | 186 | * @param $requestoptions SMWRequestOptions optionally defining further options |
190 | 187 | */ |
191 | | - public abstract function getProperties( $subject, $requestoptions = null ); |
| 188 | + public abstract function getProperties( SMWDIWikiPage $subject, $requestoptions = null ); |
192 | 189 | |
193 | 190 | /** |
194 | 191 | * Get an array of all properties for which there is some subject that relates to the given value. |
195 | | - * The result is an array of SMWWikiPageValue objects. |
| 192 | + * The result is an array of SMWDIWikiPage objects. |
196 | 193 | * @note In some stores, this function might be implemented partially so that only values of type Page |
197 | 194 | * (_wpg) are supported. |
198 | 195 | */ |
199 | | - public abstract function getInProperties( SMWDataValue $object, $requestoptions = null ); |
| 196 | + public abstract function getInProperties( SMWDataItem $object, $requestoptions = null ); |
200 | 197 | |
201 | 198 | ///// Writing methods ///// |
202 | 199 | |
— | — | @@ -215,31 +212,33 @@ |
216 | 213 | public abstract function doDataUpdate( SMWSemanticData $data ); |
217 | 214 | |
218 | 215 | /** |
219 | | - * Update the semantic data stored for some individual. The data is given |
220 | | - * as a SMWSemanticData object, which contains all semantic data for one particular |
221 | | - * subject. |
| 216 | + * Update the semantic data stored for some individual. The data is |
| 217 | + * given as a SMWSemanticData object, which contains all semantic data |
| 218 | + * for one particular subject. |
| 219 | + * |
| 220 | + * @param $data SMWSemanticData |
222 | 221 | */ |
223 | 222 | public function updateData( SMWSemanticData $data ) { |
224 | 223 | wfRunHooks( 'SMWStore::updateDataBefore', array( $this, $data ) ); |
225 | | - |
| 224 | + |
226 | 225 | $this->doDataUpdate( $data ); |
227 | | - |
| 226 | + |
228 | 227 | // Invalidate the page, so data stored on it gets displayed immeditaely in queries. |
229 | 228 | global $smwgAutoRefreshSubject, $wgDBtype; |
230 | 229 | if ( $smwgAutoRefreshSubject && !wfReadOnly() ) { |
231 | | - $title = $data->getSubject()->getTitle(); |
| 230 | + $title = Title::makeTitle( $data->getSubject()->getNamespace(), $data->getSubject()->getDBkey() ); |
232 | 231 | $dbw = wfGetDB( DB_MASTER ); |
233 | | - |
| 232 | + |
234 | 233 | $dbw->update( |
235 | 234 | 'page', |
236 | 235 | array( 'page_touched' => $dbw->timestamp( time() + 9001 ) ), |
237 | 236 | $title->pageCond(), |
238 | 237 | __METHOD__ |
239 | 238 | ); |
240 | | - |
| 239 | + |
241 | 240 | HTMLFileCache::clearFileCache( $title ); |
242 | 241 | } |
243 | | - |
| 242 | + |
244 | 243 | wfRunHooks( 'SMWStore::updateDataAfter', array( $this, $data ) ); |
245 | 244 | } |
246 | 245 | |
— | — | @@ -247,7 +246,7 @@ |
248 | 247 | * Clear all semantic data specified for some page. |
249 | 248 | */ |
250 | 249 | public function clearData( Title $subject ) { |
251 | | - $emptydata = new SMWSemanticData( SMWWikiPageValue::makePageFromTitle( $subject ) ); |
| 250 | + $emptydata = new SMWSemanticData( new SMWDIWikiPage( $subject->getDbKey(), $subject->getNamespace(), $subject->getInterwiki() ) ); |
252 | 251 | $this->updateData( $emptydata ); |
253 | 252 | } |
254 | 253 | |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_TestStore.php |
— | — | @@ -67,7 +67,7 @@ |
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
71 | | - function getPropertyValues( $subject, SMWPropertyValue $property, $requestoptions = null, $outputformat = '' ) { |
| 71 | + function getPropertyValues( $subject, SMWDIProperty $property, $requestoptions = null, $outputformat = '' ) { |
72 | 72 | $type = $this->getSpecialValues( $property, SMW_SP_HAS_TYPE ); |
73 | 73 | $type = $type[0]; |
74 | 74 | $valarray = array(); |
— | — | @@ -98,14 +98,14 @@ |
99 | 99 | return $result; |
100 | 100 | } |
101 | 101 | |
102 | | - function getPropertySubjects( SMWPropertyValue $property, $value, $requestoptions = null ) { |
| 102 | + function getPropertySubjects( SMWDIProperty $property, $value, $requestoptions = null ) { |
103 | 103 | if ( !$value->isValid() ) { |
104 | 104 | return array(); |
105 | 105 | } |
106 | 106 | return $this->getTestTitles( $requestoptions ); |
107 | 107 | } |
108 | 108 | |
109 | | - function getAllPropertySubjects( SMWPropertyValue $property, $requestoptions = null ) { |
| 109 | + function getAllPropertySubjects( SMWDIProperty $property, $requestoptions = null ) { |
110 | 110 | return $this->getTestTitles( $requestoptions ); |
111 | 111 | } |
112 | 112 | |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php |
— | — | @@ -145,35 +145,24 @@ |
146 | 146 | |
147 | 147 | ///// Reading methods ///// |
148 | 148 | |
149 | | - public function getSemanticData( $subject, $filter = false ) { |
| 149 | + public function getSemanticData( SMWDIWikiPage $subject, $filter = false ) { |
150 | 150 | wfProfileIn( "SMWSQLStore2::getSemanticData (SMW)" ); |
151 | 151 | |
152 | 152 | // Do not clear the cache when called recursively. |
153 | 153 | self::$in_getSemanticData++; |
154 | 154 | |
155 | 155 | // *** Find out if this subject exists ***// |
156 | | - if ( $subject instanceof Title ) { ///TODO: can this still occur? |
157 | | - $sid = $this->getSMWPageID( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki() ); |
158 | | - $svalue = SMWWikiPageValue::makePageFromTitle( $subject ); |
159 | | - } elseif ( $subject instanceof SMWWikiPageValue ) { |
160 | | - $sid = $subject->isValid() ? |
161 | | - $this->getSMWPageID( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki() ): |
162 | | - 0; |
163 | | - $svalue = $subject; |
164 | | - } else { |
165 | | - $sid = 0; |
166 | | - } |
167 | | - |
| 156 | + $sid = $this->getSMWPageID( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki() ); |
168 | 157 | if ( $sid == 0 ) { // no data, safe our time |
169 | 158 | /// NOTE: we consider redirects for getting $sid, so $sid == 0 also means "no redirects" |
170 | 159 | self::$in_getSemanticData--; |
171 | 160 | wfProfileOut( "SMWSQLStore2::getSemanticData (SMW)" ); |
172 | | - return isset( $svalue ) ? ( new SMWSemanticData( $svalue ) ):null; |
| 161 | + return new SMWSemanticData( $subject ); |
173 | 162 | } |
174 | 163 | |
175 | 164 | // *** Prepare the cache ***// |
176 | 165 | if ( !array_key_exists( $sid, $this->m_semdata ) ) { // new cache entry |
177 | | - $this->m_semdata[$sid] = new SMWSemanticData( $svalue, false ); |
| 166 | + $this->m_semdata[$sid] = new SMWSemanticData( $subject, false ); |
178 | 167 | $this->m_sdstate[$sid] = array(); |
179 | 168 | } |
180 | 169 | |
— | — | @@ -197,7 +186,7 @@ |
198 | 187 | if ( !$relevant ) continue; |
199 | 188 | } |
200 | 189 | |
201 | | - $data = $this->fetchSemanticData( $sid, $svalue, $proptable ); |
| 190 | + $data = $this->fetchSemanticData( $sid, $subject, $proptable ); |
202 | 191 | |
203 | 192 | foreach ( $data as $d ) { |
204 | 193 | $this->m_semdata[$sid]->addPropertyStubValue( reset( $d ), end( $d ) ); |
— | — | @@ -216,35 +205,21 @@ |
217 | 206 | /** |
218 | 207 | * @see SMWStore::getPropertyValues |
219 | 208 | * |
220 | | - * @param $subject |
221 | | - * @param SMWPropertyValue $property |
| 209 | + * @param SMWDataItem $subject |
| 210 | + * @param SMWDIProperty $property |
222 | 211 | * @param SMWRequestOptions $requestoptions |
223 | | - * @param string $outputformat |
224 | 212 | * |
225 | | - * @return array |
| 213 | + * @return array of SMWDataItem |
226 | 214 | */ |
227 | | - public function getPropertyValues( $subject, SMWPropertyValue $property, $requestoptions = null, $outputformat = '' ) { |
| 215 | + public function getPropertyValues( $subject, SMWDIProperty $property, $requestoptions = null ) { |
228 | 216 | wfProfileIn( "SMWSQLStore2::getPropertyValues (SMW)" ); |
229 | 217 | |
230 | 218 | if ( $property->isInverse() ) { // inverses are working differently |
231 | | - $noninverse = clone $property; |
232 | | - $noninverse->setInverse( false ); |
| 219 | + $noninverse = new SMWDIProperty( $property->getKey(), false, $property->findPropertyTypeID() ); |
233 | 220 | $result = $this->getPropertySubjects( $noninverse, $subject, $requestoptions ); |
234 | | - } elseif ( $subject !== null ) { // subject given, use semantic data cache: |
235 | | - $sd = $this->getSemanticData( $subject, array( $property->getPropertyTypeID() ) ); |
| 221 | + } elseif ( $subject !== null ) { // subject given, use semantic data cache |
| 222 | + $sd = $this->getSemanticData( $subject, array( $property->findPropertyTypeID() ) ); |
236 | 223 | $result = $this->applyRequestOptions( $sd->getPropertyValues( $property ), $requestoptions ); |
237 | | - |
238 | | - if ( $outputformat != '' ) { // reformat cached values |
239 | | - $newres = array(); |
240 | | - |
241 | | - foreach ( $result as $dv ) { |
242 | | - $ndv = clone $dv; |
243 | | - $ndv->setOutputFormat( $outputformat ); |
244 | | - $newres[] = $ndv; |
245 | | - } |
246 | | - |
247 | | - $result = $newres; |
248 | | - } |
249 | 224 | } else { // no subject given, get all values for the given property |
250 | 225 | $pid = $this->getSMWPropertyID( $property ); |
251 | 226 | $tableid = self::findPropertyTableID( $property ); |
— | — | @@ -259,10 +234,12 @@ |
260 | 235 | $result = array(); |
261 | 236 | |
262 | 237 | foreach ( $data as $dbkeys ) { |
263 | | - $dv = SMWDataValueFactory::newPropertyObjectValue( $property ); |
264 | | - if ( $outputformat != '' ) $dv->setOutputFormat( $outputformat ); |
265 | | - $dv->setDBkeys( $dbkeys ); |
266 | | - $result[] = $dv; |
| 238 | + try { |
| 239 | + $result[] = SMWDataValueFactory::newTypeIdItem( $property->findPropertyTypeID(), $dbkeys ); |
| 240 | + } catch ( SMWDataItemException $e ) { |
| 241 | + // maybe some type assignment changed since the data was stored; |
| 242 | + // don't worry, but we can ony drop the data here |
| 243 | + } |
267 | 244 | } |
268 | 245 | } |
269 | 246 | |
— | — | @@ -280,7 +257,7 @@ |
281 | 258 | * In case (1), the first two parameters are taken to refer to a subject; in case (2) they |
282 | 259 | * are taken to refer to a property. In any case, the retrieval is limited to the specified |
283 | 260 | * $proptable. The parameters are an internal $id (of a subject or property), and an $object |
284 | | - * (being an SMWPageValue or SMWPropertyValue). Moreover, when filtering by property, it is |
| 261 | + * (being an SMWDIWikiPage or SMWDIProperty). Moreover, when filtering by property, it is |
285 | 262 | * assumed that the given $proptable belongs to the property: if it is a table with fixed |
286 | 263 | * property, it will not be checked that this is the same property as the one that was given |
287 | 264 | * in $object. |
— | — | @@ -297,8 +274,8 @@ |
298 | 275 | * @todo Maybe share DB handler; asking for it seems to take quite some time and we do not want |
299 | 276 | * to change it in one call. |
300 | 277 | * |
301 | | - * @param $id |
302 | | - * @param $object |
| 278 | + * @param integer $id |
| 279 | + * @param SMWDataItem $object |
303 | 280 | * @param SMWSQLStore2Table $proptable |
304 | 281 | * @param boolean $issubject |
305 | 282 | * @param SMWRequestOptions $requestoptions |
— | — | @@ -438,13 +415,13 @@ |
439 | 416 | /** |
440 | 417 | * @see SMWStore::getPropertySubjects |
441 | 418 | * |
442 | | - * @param SMWPropertyValue $property |
443 | | - * @param $value |
| 419 | + * @param SMWDiProperty $property |
| 420 | + * @param mixed $value SMWDataItem or null |
444 | 421 | * @param SMWRequestOptions $requestoptions |
445 | 422 | * |
446 | | - * @return array |
| 423 | + * @return array of SMWDIWikiPage |
447 | 424 | */ |
448 | | - public function getPropertySubjects( SMWPropertyValue $property, $value, $requestoptions = null ) { |
| 425 | + public function getPropertySubjects( SMWDiProperty $property, $value, $requestoptions = null ) { |
449 | 426 | /// TODO: should we share code with #ask query computation here? Just use queries? |
450 | 427 | wfProfileIn( "SMWSQLStore2::getPropertySubjects (SMW)" ); |
451 | 428 | |
— | — | @@ -467,7 +444,7 @@ |
468 | 445 | $tableid = self::findTypeTableID( $value->getTypeID() ); |
469 | 446 | } |
470 | 447 | |
471 | | - if ( ( $pid == 0 ) || ( $tableid == '' ) || ( ( $value !== null ) && ( !$value->isValid() ) ) ) { |
| 448 | + if ( ( $pid == 0 ) || ( $tableid == '' ) ) { |
472 | 449 | wfProfileOut( "SMWSQLStoreLight::getPropertySubjects (SMW)" ); |
473 | 450 | return array(); |
474 | 451 | } |
— | — | @@ -498,7 +475,11 @@ |
499 | 476 | $this->getSQLOptions( $requestoptions, 'smw_sortkey' ) ); |
500 | 477 | |
501 | 478 | while ( $row = $db->fetchObject( $res ) ) { |
502 | | - $result[] = SMWWikiPageValue::makePage( $row->title, $row->namespace, $row->smw_sortkey ); |
| 479 | + try { |
| 480 | + $result[] = new SMWDIWikiPage( $row->title, $row->namespace, '' ); |
| 481 | + } catch ( SMWDataItemException $e ) { |
| 482 | + // silently drop data, should be extremely rare and will usually fix itself at next edit |
| 483 | + } |
503 | 484 | } |
504 | 485 | |
505 | 486 | $db->freeResult( $res ); |
— | — | @@ -518,16 +499,16 @@ |
519 | 500 | * @todo Maybe do something about redirects. The old code was |
520 | 501 | * $oid = $this->getSMWPageID($value->getDBkey(),$value->getNamespace(),$value->getInterwiki(),false); |
521 | 502 | * |
522 | | - * @param $from |
523 | | - * @param $where |
524 | | - * @param $proptable |
525 | | - * @param $value |
526 | | - * @param $tableindex |
| 503 | + * @param string $from |
| 504 | + * @param string $where |
| 505 | + * @param SMWSQLStore2Table $proptable |
| 506 | + * @param SMWDataItem $value |
| 507 | + * @param integer $tableindex |
527 | 508 | */ |
528 | 509 | protected function prepareValueQuery( &$from, &$where, $proptable, $value, $tableindex = 1 ) { |
529 | 510 | $db = wfGetDB( DB_SLAVE ); |
530 | 511 | |
531 | | - if ( $value instanceof SMWContainerValue ) { // recursive handling of containers |
| 512 | + if ( $value instanceof SMWDIContainer ) { // recursive handling of containers |
532 | 513 | $joinfield = "t$tableindex." . reset( array_keys( $proptable->objectfields ) ); // this must be a type 'p' object |
533 | 514 | $proptables = self::getPropertyTables(); |
534 | 515 | |
— | — | @@ -559,7 +540,7 @@ |
560 | 541 | } |
561 | 542 | } |
562 | 543 | } elseif ( $value !== null ) { // add conditions for given value |
563 | | - $dbkeys = $value->getDBkeys(); |
| 544 | + $dbkeys = SMWCompatibilityHelpers::getDBkeysFromDataItem( $value ); |
564 | 545 | $i = 0; |
565 | 546 | |
566 | 547 | foreach ( $proptable->objectfields as $fieldname => $typeid ) { |
— | — | @@ -581,12 +562,12 @@ |
582 | 563 | /** |
583 | 564 | * @see SMWStore::getAllPropertySubjects |
584 | 565 | * |
585 | | - * @param SMWPropertyValue $property |
| 566 | + * @param SMWDIProperty $property |
586 | 567 | * @param SMWRequestOptions $requestoptions |
587 | 568 | * |
588 | | - * @return array |
| 569 | + * @return array of SMWDIWikiPage |
589 | 570 | */ |
590 | | - public function getAllPropertySubjects( SMWPropertyValue $property, $requestoptions = null ) { |
| 571 | + public function getAllPropertySubjects( SMWDIProperty $property, $requestoptions = null ) { |
591 | 572 | wfProfileIn( "SMWSQLStore2::getAllPropertySubjects (SMW)" ); |
592 | 573 | $result = $this->getPropertySubjects( $property, null, $requestoptions ); |
593 | 574 | wfProfileOut( "SMWSQLStore2::getAllPropertySubjects (SMW)" ); |
— | — | @@ -596,13 +577,11 @@ |
597 | 578 | |
598 | 579 | /** |
599 | 580 | * @see SMWStore::getProperties |
600 | | - * |
601 | | - * TODO: Restrict this function to SMWWikiPageValue subjects. |
602 | 581 | * |
603 | | - * @param $subject |
| 582 | + * @param SMWDIWikiPage $subject |
604 | 583 | * @param SMWRequestOptions $requestoptions |
605 | 584 | */ |
606 | | - public function getProperties( $subject, $requestoptions = null ) { |
| 585 | + public function getProperties( SMWDIWikiPage $subject, $requestoptions = null ) { |
607 | 586 | wfProfileIn( "SMWSQLStore2::getProperties (SMW)" ); |
608 | 587 | $sid = $this->getSMWPageID( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki() ); |
609 | 588 | |
— | — | @@ -640,13 +619,13 @@ |
641 | 620 | 'SMW::getProperties', $this->getSQLOptions( $suboptions, 'smw_sortkey' ) ); |
642 | 621 | |
643 | 622 | while ( $row = $db->fetchObject( $res ) ) { |
644 | | - $result[] = SMWPropertyValue::makeProperty( $row->smw_title ); |
| 623 | + $result[] = new SMWDIProperty( $row->smw_title ); |
645 | 624 | } |
646 | 625 | } else { // just check if subject occurs in table |
647 | 626 | $res = $db->select( $from, '*', $where, 'SMW::getProperties', array( 'LIMIT' => 1 ) ); |
648 | 627 | |
649 | 628 | if ( $db->numRows( $res ) > 0 ) { |
650 | | - $result[] = SMWPropertyValue::makeProperty( $proptable->fixedproperty ); |
| 629 | + $result[] = new SMWDIProperty( $proptable->fixedproperty ); |
651 | 630 | } |
652 | 631 | } |
653 | 632 | |
— | — | @@ -672,12 +651,12 @@ |
673 | 652 | * can be confused. This is a minor issue now since no code is known to use |
674 | 653 | * this function in cases where this occurs. |
675 | 654 | * |
676 | | - * @param SMWDataValue $value |
| 655 | + * @param SMWDataItem $value |
677 | 656 | * @param SMWRequestOptions $requestoptions |
678 | 657 | * |
679 | 658 | * @return array of SMWWikiPageValue |
680 | 659 | */ |
681 | | - public function getInProperties( SMWDataValue $value, $requestoptions = null ) { |
| 660 | + public function getInProperties( SMWDataItem $value, $requestoptions = null ) { |
682 | 661 | wfProfileIn( "SMWSQLStore2::getInProperties (SMW)" ); |
683 | 662 | |
684 | 663 | $db = wfGetDB( DB_SLAVE ); |
— | — | @@ -706,7 +685,7 @@ |
707 | 686 | 'SMW::getInProperties', $this->getSQLOptions( $suboptions, 'smw_sortkey' ) ); |
708 | 687 | |
709 | 688 | while ( $row = $db->fetchObject( $res ) ) { |
710 | | - $result[] = SMWPropertyValue::makeProperty( $row->smw_title ); |
| 689 | + $result[] = new SMWDIProperty( $row->smw_title ); |
711 | 690 | } |
712 | 691 | } else { |
713 | 692 | $from = $db->tableName( $proptable->name ) . " AS t1"; |
— | — | @@ -714,7 +693,7 @@ |
715 | 694 | $res = $db->select( $from, '*', $where, 'SMW::getProperties', array( 'LIMIT' => 1 ) ); |
716 | 695 | |
717 | 696 | if ( $db->numRows( $res ) > 0 ) { |
718 | | - $result[] = SMWPropertyValue::makeProperty( $proptable->fixedproperty ); |
| 697 | + $result[] = new SMWDIProperty( $proptable->fixedproperty ); |
719 | 698 | } |
720 | 699 | } |
721 | 700 | $db->freeResult( $res ); |
— | — | @@ -766,7 +745,7 @@ |
767 | 746 | |
768 | 747 | $subject = $data->getSubject(); |
769 | 748 | $this->deleteSemanticData( $subject ); |
770 | | - $redirects = $data->getPropertyValues( SMWPropertyValue::makeProperty( '_REDI' ) ); |
| 749 | + $redirects = $data->getPropertyValues( new SMWDIProperty( '_REDI' ) ); |
771 | 750 | |
772 | 751 | if ( count( $redirects ) > 0 ) { |
773 | 752 | $redirect = end( $redirects ); // at most one redirect per page |
— | — | @@ -862,8 +841,8 @@ |
863 | 842 | |
864 | 843 | $proptable = $proptables[$tableid]; |
865 | 844 | |
866 | | - foreach ( $data->getPropertyValues( $property ) as $dv ) { |
867 | | - if ( !$dv->isValid() || ( $tableid == 'smw_redi2' ) ) continue; |
| 845 | + foreach ( $data->getPropertyValues( $property ) as $di ) { |
| 846 | + if ( $tableid == 'smw_redi2' ) continue; |
868 | 847 | |
869 | 848 | // errors are already recorded separately, no need to store them here; |
870 | 849 | // redirects were treated above |
— | — | @@ -874,13 +853,13 @@ |
875 | 854 | $uvals['p_id'] = $this->makeSMWPropertyID( $property ); |
876 | 855 | } |
877 | 856 | |
878 | | - if ( $dv instanceof SMWContainerValue ) { // process subobjects recursively |
879 | | - $bnode = $this->prepareDBUpdates( $updates, $dv->getData(), $pageid ); |
| 857 | + if ( $di instanceof SMWDIContainer ) { // process subobjects recursively |
| 858 | + $bnode = $this->prepareDBUpdates( $updates, $di->getData(), $pageid ); |
880 | 859 | // Note: tables for container objects MUST have objectfields == array(<somename> => 'p') |
881 | 860 | reset( $proptable->objectfields ); |
882 | 861 | $uvals[key( $proptable->objectfields )] = $bnode; |
883 | 862 | } else { |
884 | | - $dbkeys = $dv->getDBkeys(); |
| 863 | + $dbkeys = SMWCompatibilityHelpers::getDBkeysFromDataItem( $di ); |
885 | 864 | reset( $dbkeys ); |
886 | 865 | |
887 | 866 | foreach ( $proptable->objectfields as $fieldname => $typeid ) { |
— | — | @@ -1040,7 +1019,7 @@ |
1041 | 1020 | $result = array(); |
1042 | 1021 | |
1043 | 1022 | while ( $row = $db->fetchObject( $res ) ) { |
1044 | | - $result[] = array( SMWPropertyValue::makeProperty( $row->smw_title ), $row->count ); |
| 1023 | + $result[] = array( new SMWDIProperty( $row->smw_title ), $row->count ); |
1045 | 1024 | } |
1046 | 1025 | |
1047 | 1026 | $db->freeResult( $res ); |
— | — | @@ -1120,7 +1099,7 @@ |
1121 | 1100 | $result = array(); |
1122 | 1101 | |
1123 | 1102 | while ( $row = $db->fetchObject( $res ) ) { |
1124 | | - $result[] = SMWPropertyValue::makeProperty( $row->title ); |
| 1103 | + $result[] = new SMWDIProperty( $row->title ); |
1125 | 1104 | } |
1126 | 1105 | |
1127 | 1106 | $db->freeResult( $res ); |
— | — | @@ -1162,7 +1141,7 @@ |
1163 | 1142 | 'SMW::getWantedPropertiesSpecial', $options ); |
1164 | 1143 | |
1165 | 1144 | while ( $row = $db->fetchObject( $res ) ) { |
1166 | | - $result[] = array( SMWPropertyValue::makeProperty( $row->smw_title ), $row->count ); |
| 1145 | + $result[] = array( new SMWDIProperty( $row->smw_title ), $row->count ); |
1167 | 1146 | } |
1168 | 1147 | } |
1169 | 1148 | |
— | — | @@ -1179,7 +1158,7 @@ |
1180 | 1159 | $proptables = self::getPropertyTables(); |
1181 | 1160 | |
1182 | 1161 | // count number of declared properties by counting "has type" annotations |
1183 | | - $typeprop = SMWPropertyValue::makeProperty( '_TYPE' ); |
| 1162 | + $typeprop = new SMWDIProperty( '_TYPE' ); |
1184 | 1163 | $typetable = $proptables[self::findPropertyTableID( $typeprop )]; |
1185 | 1164 | $res = $db->select( $typetable->name, 'COUNT(s_id) AS count', array( 'p_id' => $this->getSMWPropertyID( $typeprop ) ), 'SMW::getStatistics' ); |
1186 | 1165 | $row = $db->fetchObject( $res ); |
— | — | @@ -1403,13 +1382,13 @@ |
1404 | 1383 | $this->reportProgress( " ... writing entries for internal properties.", $verbose ); |
1405 | 1384 | |
1406 | 1385 | foreach ( self::$special_ids as $prop => $id ) { |
1407 | | - $p = SMWPropertyValue::makeProperty( $prop ); |
| 1386 | + $p = new SMWDIProperty( $prop ); |
1408 | 1387 | $db->replace( 'smw_ids', array( 'smw_id' ), array( |
1409 | 1388 | 'smw_id' => $id, |
1410 | | - 'smw_title' => $p->getDBkey(), |
| 1389 | + 'smw_title' => $p->getKey(), |
1411 | 1390 | 'smw_namespace' => SMW_NS_PROPERTY, |
1412 | 1391 | 'smw_iw' => $this->getPropertyInterwiki( $p ), |
1413 | | - 'smw_sortkey' => $p->getDBkey() |
| 1392 | + 'smw_sortkey' => $p->getKey() |
1414 | 1393 | ), 'SMW::setup' |
1415 | 1394 | ); |
1416 | 1395 | } |
— | — | @@ -1710,7 +1689,7 @@ |
1711 | 1690 | |
1712 | 1691 | foreach ( $data as $item ) { |
1713 | 1692 | $ok = true; // keep datavalue only if this remains true |
1714 | | - $keys = $item->getDBkeys(); |
| 1693 | + $keys = SMWCompatibilityHelpers::getDBkeysFromDataItem( $item ); |
1715 | 1694 | $value = array_key_exists( $valueIndex, $keys ) ? $keys[$valueIndex] : ''; |
1716 | 1695 | $label = array_key_exists( $labelIndex, $keys ) ? $keys[$labelIndex] : ''; |
1717 | 1696 | |
— | — | @@ -1865,7 +1844,7 @@ |
1866 | 1845 | * Retrieve the id of the property table that is to be used for storing |
1867 | 1846 | * values for the given property object. |
1868 | 1847 | */ |
1869 | | - public static function findPropertyTableID( $property ) { |
| 1848 | + public static function findPropertyTableID( SMWDIProperty $property ) { |
1870 | 1849 | if ( self::$fixed_prop_tables === null ) { // Build lookup array once. |
1871 | 1850 | self::$fixed_prop_tables = array(); |
1872 | 1851 | |
— | — | @@ -1876,17 +1855,16 @@ |
1877 | 1856 | } |
1878 | 1857 | } |
1879 | 1858 | |
1880 | | - $propertykey = ( $property->isUserDefined() ) ? $property->getDBkey() : $property->getPropertyId(); |
1881 | | - |
| 1859 | + $propertykey = $property->getKey(); |
1882 | 1860 | if ( array_key_exists( $propertykey, self::$fixed_prop_tables ) ) { |
1883 | | - $signature = self::getTypeSignature( $property->getPropertyTypeID() ); |
| 1861 | + $signature = self::getTypeSignature( $property->findPropertyTypeID() ); |
1884 | 1862 | |
1885 | 1863 | if ( self::tableFitsSignature( SMWSQLStore2::$fixed_prop_tables[$propertykey], $signature ) ) { |
1886 | 1864 | return self::$fixed_prop_tables[$propertykey]; |
1887 | 1865 | } |
1888 | 1866 | } // else: Don't check for non-fitting entries in $fixed_prop_tables: not really important. |
1889 | 1867 | |
1890 | | - return self::findTypeTableID( $property->getPropertyTypeID() ); |
| 1868 | + return self::findTypeTableID( $property->findPropertyTypeID() ); |
1891 | 1869 | } |
1892 | 1870 | |
1893 | 1871 | /** |
— | — | @@ -2038,11 +2016,11 @@ |
2039 | 2017 | * predefined properties from the ids for the current pages (which may, |
2040 | 2018 | * e.g. be moved, while the predefined object is not movable). |
2041 | 2019 | */ |
2042 | | - protected function getPropertyInterwiki( SMWPropertyValue $property ) { |
| 2020 | + protected function getPropertyInterwiki( SMWDIProperty $property ) { |
2043 | 2021 | if ( $property->isUserDefined() ) { |
2044 | 2022 | return ''; |
2045 | 2023 | } else { |
2046 | | - return $property->isVisible() ? SMW_SQL2_SMWPREDEFIW : SMW_SQL2_SMWINTDEFIW; |
| 2024 | + return ( $property->getLabel() != '' ) ? SMW_SQL2_SMWPREDEFIW : SMW_SQL2_SMWINTDEFIW; |
2047 | 2025 | } |
2048 | 2026 | } |
2049 | 2027 | |
— | — | @@ -2050,11 +2028,11 @@ |
2051 | 2029 | * This function does the same as getSMWPageID() but takes into account |
2052 | 2030 | * that properties might be predefined. |
2053 | 2031 | */ |
2054 | | - public function getSMWPropertyID( SMWPropertyValue $property ) { |
2055 | | - if ( ( !$property->isUserDefined() ) && ( array_key_exists( $property->getPropertyID(), self::$special_ids ) ) ) { |
2056 | | - return self::$special_ids[$property->getPropertyID()]; // very important property with fixed id |
| 2032 | + public function getSMWPropertyID( SMWDIProperty $property ) { |
| 2033 | + if ( ( !$property->isUserDefined() ) && ( array_key_exists( $property->getKey(), self::$special_ids ) ) ) { |
| 2034 | + return self::$special_ids[$property->getKey()]; // very important property with fixed id |
2057 | 2035 | } else { |
2058 | | - return $this->getSMWPageID( $property->getDBkey(), SMW_NS_PROPERTY, $this->getPropertyInterwiki( $property ), true ); |
| 2036 | + return $this->getSMWPageID( $property->getKey(), SMW_NS_PROPERTY, $this->getPropertyInterwiki( $property ), true ); |
2059 | 2037 | } |
2060 | 2038 | } |
2061 | 2039 | |
— | — | @@ -2062,11 +2040,11 @@ |
2063 | 2041 | * This function does the same as makeSMWPageID() but takes into account |
2064 | 2042 | * that properties might be predefined. |
2065 | 2043 | */ |
2066 | | - protected function makeSMWPropertyID( SMWPropertyValue $property ) { |
2067 | | - if ( ( !$property->isUserDefined() ) && ( array_key_exists( $property->getPropertyID(), self::$special_ids ) ) ) { |
2068 | | - return self::$special_ids[$property->getPropertyID()]; // very important property with fixed id |
| 2044 | + protected function makeSMWPropertyID( SMWDIProperty $property ) { |
| 2045 | + if ( ( !$property->isUserDefined() ) && ( array_key_exists( $property->getKey(), self::$special_ids ) ) ) { |
| 2046 | + return self::$special_ids[$property->getKey()]; // very important property with fixed id |
2069 | 2047 | } else { |
2070 | | - return $this->makeSMWPageID( $property->getDBkey(), SMW_NS_PROPERTY, $this->getPropertyInterwiki( $property ), true ); |
| 2048 | + return $this->makeSMWPageID( $property->getKey(), SMW_NS_PROPERTY, $this->getPropertyInterwiki( $property ), true ); |
2071 | 2049 | } |
2072 | 2050 | } |
2073 | 2051 | |
— | — | @@ -2270,12 +2248,12 @@ |
2271 | 2249 | } |
2272 | 2250 | |
2273 | 2251 | /** |
2274 | | - * Delete all semantic data stored for the given subject. Used for update |
2275 | | - * purposes. |
| 2252 | + * Delete all semantic data stored for the given subject. Used for |
| 2253 | + * update purposes. |
2276 | 2254 | * |
2277 | | - * @param SMWWikiPageValue $subject |
| 2255 | + * @param $subject SMWDIWikiPage the data of which is deleted |
2278 | 2256 | */ |
2279 | | - protected function deleteSemanticData( SMWWikiPageValue $subject ) { |
| 2257 | + protected function deleteSemanticData( SMWDIWikiPage $subject ) { |
2280 | 2258 | $db = wfGetDB( DB_MASTER ); |
2281 | 2259 | |
2282 | 2260 | $fname = 'SMW::deleteSemanticData'; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Compatibility_Helpers.php |
— | — | @@ -0,0 +1,159 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * This file contains the SMWCompatibilityHelper class. |
| 5 | + * @note This file and its contents will vanish before SMW 1.7. Please modify your code to not require these helpers. |
| 6 | + * |
| 7 | + * @author Markus Krötzsch |
| 8 | + * |
| 9 | + * @file |
| 10 | + * @ingroup SMW |
| 11 | + */ |
| 12 | + |
| 13 | +/** |
| 14 | + * Helper class to collect various static functions that provide some |
| 15 | + * interfaces used in SMW 1.6 that are no longer available in SMW 1.7. |
| 16 | + * In particular, this relates to the new data model based on data items |
| 17 | + * instead of data value classes with DB key arrays and singatures. |
| 18 | + * |
| 19 | + * @note This class will vanish before SMW 1.7. Please change your code to not require the old interfaces at all. |
| 20 | + * |
| 21 | + * @ingroup SMW |
| 22 | + */ |
| 23 | +class SMWCompatibilityHelpers { |
| 24 | + |
| 25 | + /** |
| 26 | + * Method to create a dataitem from a type ID and array of DB keys. |
| 27 | + * Throws SMWDataItemException if problems occur, to get our callers |
| 28 | + * used to it. |
| 29 | + * |
| 30 | + * @param $typeid id string for the given type |
| 31 | + * @param $dbkeys array of mixed |
| 32 | + * |
| 33 | + * @return SMWDataItem |
| 34 | + */ |
| 35 | + static public function dataItemFromDBKeys( $typeid, $dbkeys ) { |
| 36 | + switch ( SMWDataValueFactory::getDataItemId( $typeid ) ) { |
| 37 | + case SMWDataItem::TYPE_ERROR: |
| 38 | + break; |
| 39 | + case SMWDataItem::TYPE_NUMBER: |
| 40 | + return SMWDINumber::doUnserialize( $dbkeys[0], $typeid ); |
| 41 | + case SMWDataItem::TYPE_STRING: |
| 42 | + return new SMWDIString( $dbkeys[0], $typeid ); |
| 43 | + case SMWDataItem::TYPE_BLOB: |
| 44 | + return new SMWDIBlob( $dbkeys[0], $typeid ); |
| 45 | + case SMWDataItem::TYPE_BOOLEAN: |
| 46 | + return new SMWDIBoolean( ( $dbkeys[0] == '1' ), $typeid ); |
| 47 | + case SMWDataItem::TYPE_URI: |
| 48 | + return SMWDIUri::doUnserialize( $dbkeys[0], $typeid); |
| 49 | + case SMWDataItem::TYPE_TIME: |
| 50 | + $timedate = explode( 'T', $dbkeys[0], 2 ); |
| 51 | + if ( ( count( $dbkeys ) == 2 ) && ( count( $timedate ) == 2 ) ) { |
| 52 | + $date = reset( $timedate ); |
| 53 | + $year = $month = $day = $hours = $minutes = $seconds = $timeoffset = false; |
| 54 | + if ( ( end( $timedate ) == '' ) || |
| 55 | + ( SMWTimeValue::parseTimeString( end( $timedate ), $hours, $minutes, $seconds, $timeoffset ) == true ) ) { |
| 56 | + $d = explode( '/', $date, 3 ); |
| 57 | + if ( count( $d ) == 3 ) { |
| 58 | + list( $year, $month, $day ) = $d; |
| 59 | + } elseif ( count( $d ) == 2 ) { |
| 60 | + list( $year, $month ) = $d; |
| 61 | + } elseif ( count( $d ) == 1 ) { |
| 62 | + list( $year ) = $d; |
| 63 | + } |
| 64 | + $calendarmodel = SMWDITime::CM_GREGORIAN; |
| 65 | + return new SMWDITime( $calendarmodel, $year, $month, $day, $hours, $minutes, $seconds, $typeid ); |
| 66 | + } |
| 67 | + } |
| 68 | + break; |
| 69 | + case SMWDataItem::TYPE_GEO: |
| 70 | + break; |
| 71 | + case SMWDataItem::TYPE_CONTAINER: |
| 72 | + break; |
| 73 | + case SMWDataItem::TYPE_WIKIPAGE: |
| 74 | + if ( $typeid == '__typ' ) { // DBkeys for types values are special (used to be a SMWSimpleWikiPageValue) |
| 75 | + $pagedbkey = str_replace( ' ', '_', SMWDataValueFactory::findTypeLabel( $dbkeys[0] ) ); |
| 76 | + return new SMWDIWikiPage( $pagedbkey, SMW_NS_TYPE, '', $typeid ); |
| 77 | + } elseif ( count( $dbkeys ) >= 3 ) { |
| 78 | + return new SMWDIWikiPage( $dbkeys[0], floatval( $dbkeys[1] ), $dbkeys[2], $typeid ); |
| 79 | + } |
| 80 | + break; |
| 81 | + case SMWDataItem::TYPE_CONCEPT: |
| 82 | + if ( count( $dbkeys ) >= 5 ) { |
| 83 | + new SMWDIConcept( $dbkeys[0], smwfXMLContentEncode( $dbkeys[1] ), $dbkeys[2], $dbkeys[3], $dbkeys[4], $typeid ); |
| 84 | + } |
| 85 | + break; |
| 86 | + case SMWDataItem::TYPE_PROPERTY: |
| 87 | + return new SMWDIProperty( $dbkeys[0], false, $typeid ); |
| 88 | + case SMWDataItem::TYPE_NOTYPE: |
| 89 | + if ( ( $typeid != '' ) && ( $typeid{0} != '_' ) ) { // linear conversion type |
| 90 | + return SMWDINumber::doUnserialize( $dbkeys[0], $typeid ); |
| 91 | + } |
| 92 | + } |
| 93 | + throw new SMWDataItemException( 'Failed to create data item from DB keys.' ); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Compatibility function for computing the old getDBkeys() array for the new SMW data items. |
| 98 | + */ |
| 99 | + public static function getDBkeysFromDataItem( SMWDataItem $dataItem ) { |
| 100 | + switch ( $dataItem->getTypeId() ) { |
| 101 | + case '_txt': case '_cod': case '_str': case '__sps': case '__tls': case '__imp': |
| 102 | + if ( $dataItem->getDIType() !== SMWDataItem::TYPE_STRING ) break; |
| 103 | + return array( $dataItem->getString() ); |
| 104 | + case '_ema': case '_uri': case '_anu': case '_tel': case '__spu': |
| 105 | + if ( $dataItem->getDIType() !== SMWDataItem::TYPE_URI ) break; |
| 106 | + return array( $dataItem->getSerialization() ); |
| 107 | + case '_wpg': case '_wpp': case '_wpc': case '_wpf': case '__sup': |
| 108 | + case '__suc': case '__spf': case '__sin': case '__red': |
| 109 | + if ( $dataItem->getDIType() !== SMWDataItem::TYPE_WIKIPAGE ) break; |
| 110 | + return array( $dataItem->getDBkey(), $dataItem->getNamespace(), $dataItem->getInterwiki(), $dataItem->getDBkey() ); |
| 111 | + case '_num': case '_tem': case '__lin': |
| 112 | + if ( $dataItem->getDIType() !== SMWDataItem::TYPE_NUMBER ) break; |
| 113 | + return array( $dataItem->getSerialization(), floatval( $dataItem->getNumber() ) ); |
| 114 | + case '_dat': |
| 115 | + if ( $dataItem->getDIType() !== SMWDataItem::TYPE_TIME ) break; |
| 116 | + $xsdvalue = $dataItem->getYear() . "/" . |
| 117 | + ( ( $dataItem->getPrecision() >= SMWDITime::PREC_YM ) ? $dataItem->getMonth() : '' ) . "/" . |
| 118 | + ( ( $dataItem->getPrecision() >= SMWDITime::PREC_YMD ) ? $dataItem->getDay() : '' ) . "T"; |
| 119 | + if ( $dataItem->getPrecision() == SMWDITime::PREC_YMDT ) { |
| 120 | + $xsdvalue .= sprintf( "%02d", $dataItem->getHour() ) . ':' . |
| 121 | + sprintf( "%02d", $dataItem->getMinute()) . ':' . |
| 122 | + sprintf( "%02d", $dataItem->getSecond() ); |
| 123 | + } |
| 124 | + return array( $xsdvalue, $dataItem->getSortKey() ); |
| 125 | + case '_boo': |
| 126 | + if ( $dataItem->getDIType() !== SMWDataItem::TYPE_BOOLEAN ) break; |
| 127 | + return $dataItem->getBoolean() ? array( '1', 1 ) : array( '0', 0 ); |
| 128 | + case '_rec': |
| 129 | + if ( $dataItem->getDIType() !== SMWDataItem::TYPE_CONTAINER ) break; |
| 130 | + return array( false ); |
| 131 | + case '__typ': |
| 132 | + if ( $dataItem->getDIType() !== SMWDataItem::TYPE_WIKIPAGE ) break; |
| 133 | + return array( SMWDataValueFactory::findTypeID( str_replace( '_', ' ', $dataItem->getDBkey() ) ) ); |
| 134 | + case '__con': |
| 135 | + if ( $dataItem->getDIType() !== SMWDataItem::TYPE_CONCEPT ) break; |
| 136 | + array( $dataItem->getConceptQuery(), $dataItem->getDocumentation(), $dataItem->getQueryFeatures(), $dataItem->getSize(), $dataItem->getDepth() ); |
| 137 | + case '__err': |
| 138 | + return array( false ); |
| 139 | + case '__pro': |
| 140 | + if ( $dataItem->getDIType() !== SMWDataItem::TYPE_PROPERTY ) break; |
| 141 | + return array( $dataItem->getKey() ); |
| 142 | + default: |
| 143 | + $typeid = $dataItem->getTypeId(); |
| 144 | + if ( ( $typeid != '' ) && ( $typeid{0} != '_' ) && |
| 145 | + ( $dataItem->getDIType() == SMWDataItem::TYPE_NUMBER ) ) { // linear conversion type |
| 146 | + return array( $dataItem->getSerialization(), floatval( $dataItem->getNumber() ) ); |
| 147 | + } |
| 148 | + } |
| 149 | + return array( false ); |
| 150 | + } |
| 151 | + |
| 152 | + /** |
| 153 | + * Find the sortkey for a SMWDIWikiPage. |
| 154 | + * @bug Not correct. Only an intermediate solution. |
| 155 | + */ |
| 156 | + public static function getSortKey( SMWDIWikiPage $wikiPage ) { |
| 157 | + return str_replace( '_', ' ', $wikiPage->getDBkey() ); |
| 158 | + } |
| 159 | + |
| 160 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_Compatibility_Helpers.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 161 | + native |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php |
— | — | @@ -1,8 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * The class in this file manages (special) mProperties that are |
5 | | - * associated with a certain subject (article). It is used as a |
6 | | - * container for chunks of subject-centred data. |
| 4 | + * The class in this file provides a container for chunks of subject-centred |
| 5 | + * data. |
7 | 6 | * |
8 | 7 | * @file |
9 | 8 | * @ingroup SMW |
— | — | @@ -13,45 +12,54 @@ |
14 | 13 | |
15 | 14 | /** |
16 | 15 | * Class for representing chunks of semantic data for one given |
17 | | - * article (subject), similar what is typically displayed in the factbox. |
| 16 | + * article (subject), similar what is typically displayed in the Factbox. |
18 | 17 | * This is a light-weight data container. |
| 18 | + * |
| 19 | + * By its very design, the container is unable to hold inverse properties. |
| 20 | + * For one thing, it would not be possible to identify them with mere keys. |
| 21 | + * Since SMW cannot annotate pages with inverses, this is not a limitation. |
19 | 22 | * |
20 | 23 | * @ingroup SMW |
21 | 24 | */ |
22 | 25 | class SMWSemanticData { |
23 | 26 | |
24 | 27 | /** |
25 | | - * States whether this is a stub object. Stubbing might happen on serialisation to save DB space. |
| 28 | + * Cache for the localized version of the namespace prefix "Property:". |
26 | 29 | * |
27 | | - * @var boolean |
| 30 | + * @var string |
28 | 31 | */ |
29 | | - public $stubObject = true; |
| 32 | + static protected $mPropertyPrefix = ''; |
30 | 33 | |
31 | 34 | /** |
32 | | - * Cache for the local version of "Property:" |
| 35 | + * States whether this is a stub object. Stubbing might happen on |
| 36 | + * serialisation to save DB space. |
33 | 37 | * |
34 | | - * @var mixed |
| 38 | + * @todo Check why this is public and document this here. Or fix it. |
| 39 | + * |
| 40 | + * @var boolean |
35 | 41 | */ |
36 | | - static protected $mPropertyPrefix = false; |
| 42 | + public $stubObject; |
37 | 43 | |
38 | 44 | /** |
39 | | - * Text keys and arrays of datavalue objects. |
| 45 | + * Array mapping property keys (string) to arrays of SMWDataItem |
| 46 | + * objects. |
40 | 47 | * |
41 | 48 | * @var array |
42 | 49 | */ |
43 | | - protected $mPropVals = array(); |
| 50 | + protected $mPropVals; |
44 | 51 | |
45 | 52 | /** |
46 | | - * Text keys and title objects. |
| 53 | + * Array mapping property keys (string) to SMWDIProperty objects. |
47 | 54 | * |
48 | 55 | * @var array |
49 | 56 | */ |
50 | | - protected $mProperties = array(); |
| 57 | + protected $mProperties; |
51 | 58 | |
52 | 59 | /** |
53 | | - * Stub property data that is not part of $propvals and $mProperties yet. Entries use |
54 | | - * property DB keys as keys. The value is an array of DBkey-arrays that define individual |
55 | | - * datavalues. The stubs will be set up when first accessed. |
| 60 | + * Stub property data that is not part of $mPropVals and $mProperties |
| 61 | + * yet. Entries use property keys as keys. The value is an array of |
| 62 | + * DBkey-arrays that define individual datavalues. The stubs will be |
| 63 | + * set up when first accessed. |
56 | 64 | * |
57 | 65 | * @var array |
58 | 66 | */ |
— | — | @@ -65,39 +73,47 @@ |
66 | 74 | protected $mHasVisibleProps = false; |
67 | 75 | |
68 | 76 | /** |
69 | | - * States whether the container holds any displayable special mProperties (some are internal only without a display name). |
| 77 | + * States whether the container holds any displayable predefined |
| 78 | + * $mProperties (as opposed to predefined properties without a display |
| 79 | + * label). For some settings we need this to decide if a Factbox is |
| 80 | + * displayed. |
70 | 81 | * |
71 | 82 | * @var boolean |
72 | 83 | */ |
73 | 84 | protected $mHasVisibleSpecs = false; |
74 | 85 | |
75 | 86 | /** |
76 | | - * States whether repeated values should be avoided. Not needing duplicte elimination |
77 | | - * (e.g. when loading from store) can save much time, since objects can remain stubs until someone |
78 | | - * really acesses their value. |
| 87 | + * States whether repeated values should be avoided. Not needing |
| 88 | + * duplicate elimination (e.g. when loading from store) can save much |
| 89 | + * time, since objects can remain stubs until someone really acesses |
| 90 | + * their value. |
| 91 | + * |
| 92 | + * @note This setting is merely for optimization. The SMW data model |
| 93 | + * never cares about the multiplicity of identical data assignments. |
79 | 94 | * |
80 | 95 | * @var boolean |
81 | 96 | */ |
82 | 97 | protected $mNoDuplicates; |
83 | 98 | |
84 | 99 | /** |
85 | | - * SMWWikiPageValue object that is the subject of this container. |
86 | | - * Subjects that are NULL are used to represent "internal objects" only. |
| 100 | + * SMWDIWikiPage object that is the subject of this container. |
| 101 | + * Subjects that are null are used to represent "internal objects" |
| 102 | + * only. |
87 | 103 | * |
88 | | - * @var SMWWikiPageValue |
| 104 | + * @var SMWDIWikiPage |
89 | 105 | */ |
90 | 106 | protected $mSubject; |
91 | 107 | |
92 | 108 | /** |
93 | 109 | * Constructor. |
94 | 110 | * |
95 | | - * @param SMWWikiPageValue $subject |
96 | | - * @param boolean $noDuplicates |
| 111 | + * @param $subject SMWDIWikiPage to which this data refers |
| 112 | + * @param $noDuplicates boolean stating if duplicate data should be avoided |
97 | 113 | */ |
98 | | - public function __construct( $subject, $noDuplicates = true ) { |
| 114 | + public function __construct( SMWDIWikiPage $subject, $noDuplicates = true ) { |
| 115 | + $this->clear(); |
99 | 116 | $this->mSubject = $subject; |
100 | 117 | $this->mNoDuplicates = $noDuplicates; |
101 | | - $this->stubObject = false; |
102 | 118 | } |
103 | 119 | |
104 | 120 | /** |
— | — | @@ -118,7 +134,7 @@ |
119 | 135 | /** |
120 | 136 | * Return subject to which the stored semantic annotation refer to. |
121 | 137 | * |
122 | | - * @return SMWWikiPageValue subject |
| 138 | + * @return SMWDIWikiPage subject |
123 | 139 | */ |
124 | 140 | public function getSubject() { |
125 | 141 | return $this->mSubject; |
— | — | @@ -126,6 +142,8 @@ |
127 | 143 | |
128 | 144 | /** |
129 | 145 | * Get the array of all properties that have stored values. |
| 146 | + * |
| 147 | + * @return array of SMWDIProperty objects |
130 | 148 | */ |
131 | 149 | public function getProperties() { |
132 | 150 | $this->unstubProperties(); |
— | — | @@ -137,40 +155,45 @@ |
138 | 156 | /** |
139 | 157 | * Get the array of all stored values for some property. |
140 | 158 | * |
141 | | - * @param SMWPropertyValue $property |
142 | | - * |
143 | | - * @return array |
| 159 | + * @param $property SMWDIProperty |
| 160 | + * @return array of SMWDataItem |
144 | 161 | */ |
145 | | - public function getPropertyValues( SMWPropertyValue $property ) { |
146 | | - if ( array_key_exists( $property->getDBkey(), $this->mStubPropVals ) ) { |
147 | | - // Unstub those entries completely. |
148 | | - $this->unstubProperty( $property->getDBkey(), $property ); |
| 162 | + public function getPropertyValues( SMWDIProperty $property ) { |
| 163 | + if ( $property->isInverse() ) { // we never have any data for inverses |
| 164 | + return array(); |
| 165 | + } |
149 | 166 | |
150 | | - foreach ( $this->mStubPropVals[$property->getDBkey()] as $dbkeys ) { |
151 | | - $dv = SMWDataValueFactory::newPropertyObjectValue( $property ); |
152 | | - $dv->setDBkeys( $dbkeys ); |
| 167 | + if ( array_key_exists( $property->getKey(), $this->mStubPropVals ) ) { |
| 168 | + $this->unstubProperty( $property->getKey(), $property ); |
153 | 169 | |
154 | | - if ( $this->mNoDuplicates ) { |
155 | | - $this->mPropVals[$property->getDBkey()][$dv->getHash()] = $dv; |
156 | | - } else { |
157 | | - $this->mPropVals[$property->getDBkey()][] = $dv; |
| 170 | + foreach ( $this->mStubPropVals[$property->getKey()] as $dbkeys ) { |
| 171 | + try { |
| 172 | + $di = SMWCompatibilityHelpers::dataItemFromDBKeys( $property->findPropertyTypeID(), $dbkeys ); |
| 173 | + if ( $this->mNoDuplicates ) { |
| 174 | + $this->mPropVals[$property->getKey()][$di->getHash()] = $di; |
| 175 | + } else { |
| 176 | + $this->mPropVals[$property->getKey()][] = $di; |
| 177 | + } |
| 178 | + } catch ( SMWDataItemException $e ) { |
| 179 | + // ignore data |
158 | 180 | } |
159 | 181 | } |
160 | 182 | |
161 | | - unset( $this->mStubPropVals[$property->getDBkey()] ); |
| 183 | + unset( $this->mStubPropVals[$property->getKey()] ); |
162 | 184 | } |
163 | 185 | |
164 | | - if ( array_key_exists( $property->getDBkey(), $this->mPropVals ) ) { |
165 | | - return $this->mPropVals[$property->getDBkey()]; |
| 186 | + if ( array_key_exists( $property->getKey(), $this->mPropVals ) ) { |
| 187 | + return $this->mPropVals[$property->getKey()]; |
166 | 188 | } else { |
167 | 189 | return array(); |
168 | 190 | } |
169 | 191 | } |
170 | 192 | |
171 | 193 | /** |
172 | | - * Generate a hash value to simplify the comparison of this data container with other |
173 | | - * containers. The hash uses PHP's md5 implementation, which is among the fastest hash |
174 | | - * algorithms that PHP offers. |
| 194 | + * Generate a hash value to simplify the comparison of this data |
| 195 | + * container with other containers. The hash uses PHP's md5 |
| 196 | + * implementation, which is among the fastest hash algorithms that |
| 197 | + * PHP offers. |
175 | 198 | * |
176 | 199 | * @return string |
177 | 200 | */ |
— | — | @@ -178,14 +201,14 @@ |
179 | 202 | $ctx = hash_init( 'md5' ); |
180 | 203 | |
181 | 204 | if ( $this->mSubject !== null ) { // here and below, use "_#_" to separate values; really not much care needed here |
182 | | - hash_update( $ctx, '_#_' . $this->mSubject->getHash() ); |
| 205 | + hash_update( $ctx, '_#_' . $this->mSubject->getSerialisation() ); |
183 | 206 | } |
184 | 207 | |
185 | 208 | foreach ( $this->getProperties() as $property ) { |
186 | | - hash_update( $ctx, '_#_' . $property->getHash() . '##' ); |
| 209 | + hash_update( $ctx, '_#_' . $property->getKey() . '##' ); |
187 | 210 | |
188 | 211 | foreach ( $this->getPropertyValues( $property ) as $dv ) { |
189 | | - hash_update( $ctx, '_#_' . $dv->getHash() ); |
| 212 | + hash_update( $ctx, '_#_' . $dv->getSerialisation() ); |
190 | 213 | } |
191 | 214 | } |
192 | 215 | |
— | — | @@ -195,8 +218,9 @@ |
196 | 219 | /** |
197 | 220 | * Return true if there are any visible properties. |
198 | 221 | * |
199 | | - * @note While called "visible" this check actually refers to the function |
200 | | - * SMWPropertyValue::isShown(). The name is kept for compatibility. |
| 222 | + * @note While called "visible" this check actually refers to the |
| 223 | + * function SMWDIProperty::isShown(). The name is kept for |
| 224 | + * compatibility. |
201 | 225 | * |
202 | 226 | * @return boolean |
203 | 227 | */ |
— | — | @@ -209,8 +233,9 @@ |
210 | 234 | * Return true if there are any special properties that can |
211 | 235 | * be displayed. |
212 | 236 | * |
213 | | - * @note While called "visible" this check actually refers to the function |
214 | | - * SMWPropertyValue::isShown(). The name is kept for compatibility. |
| 237 | + * @note While called "visible" this check actually refers to the |
| 238 | + * function SMWDIProperty::isShown(). The name is kept for |
| 239 | + * compatibility. |
215 | 240 | * |
216 | 241 | * @return boolean |
217 | 242 | */ |
— | — | @@ -220,30 +245,30 @@ |
221 | 246 | } |
222 | 247 | |
223 | 248 | /** |
224 | | - * Store a value for a property identified by its title object. Duplicate |
225 | | - * value entries are usually ignored. |
| 249 | + * Store a value for a property identified by its SMWDataItem object. |
226 | 250 | * |
227 | | - * @note Attention: there is no check whether the type of the given datavalue agrees |
228 | | - * with what SMWDataValueFactory is producing (based on predefined property records and |
229 | | - * the current DB content). Always use SMWDataValueFactory to produce fitting values! |
| 251 | + * @note There is no check whether the type of the given data item |
| 252 | + * agrees with the type of the property. Since property types can |
| 253 | + * change, all parts of SMW are prepared to handle mismatched data item |
| 254 | + * types anyway. |
230 | 255 | * |
231 | | - * @param SMWPropertyValue $property |
232 | | - * @param SMWDataValue $value |
| 256 | + * @param $property SMWDIProperty |
| 257 | + * @param $dataItem SMWDataItem |
233 | 258 | */ |
234 | | - public function addPropertyObjectValue( SMWPropertyValue $property, SMWDataValue $value ) { |
235 | | - if ( !$property->isValid() ) { |
236 | | - return; // nothing we can do |
| 259 | + public function addPropertyObjectValue( SMWDIProperty $property, SMWDataItem $dataItem ) { |
| 260 | + if ( $property->isInverse() ) { // inverse properties cannot be used for annotation |
| 261 | + return; |
237 | 262 | } |
238 | 263 | |
239 | | - if ( !array_key_exists( $property->getDBkey(), $this->mPropVals ) ) { |
240 | | - $this->mPropVals[$property->getDBkey()] = array(); |
241 | | - $this->mProperties[$property->getDBkey()] = $property; |
| 264 | + if ( !array_key_exists( $property->getKey(), $this->mPropVals ) ) { |
| 265 | + $this->mPropVals[$property->getKey()] = array(); |
| 266 | + $this->mProperties[$property->getKey()] = $property; |
242 | 267 | } |
243 | 268 | |
244 | 269 | if ( $this->mNoDuplicates ) { |
245 | | - $this->mPropVals[$property->getDBkey()][$value->getHash()] = $value; |
| 270 | + $this->mPropVals[$property->getKey()][$dataItem->getHash()] = $dataItem; |
246 | 271 | } else { |
247 | | - $this->mPropVals[$property->getDBkey()][] = $value; |
| 272 | + $this->mPropVals[$property->getKey()][] = $dataItem; |
248 | 273 | } |
249 | 274 | |
250 | 275 | if ( !$property->isUserDefined() ) { |
— | — | @@ -257,31 +282,33 @@ |
258 | 283 | } |
259 | 284 | |
260 | 285 | /** |
261 | | - * Store a value for a given property identified by its text label (without |
262 | | - * namespace prefix). Duplicate value entries are usually ignored. |
| 286 | + * Store a value for a given property identified by its text label |
| 287 | + * (without namespace prefix). |
263 | 288 | * |
264 | | - * @param string $propertyName |
265 | | - * @param SMWDataValue $value |
| 289 | + * @param $propertyName string |
| 290 | + * @param $dataItem SMWDataItem |
266 | 291 | */ |
267 | | - public function addPropertyValue( $propertyName, SMWDataValue $value ) { |
268 | | - $propertykey = smwfNormalTitleDBKey( $propertyName ); |
| 292 | + public function addPropertyValue( $propertyName, SMWDataItem $dataItem ) { |
| 293 | + $propertyKey = smwfNormalTitleDBKey( $propertyName ); |
269 | 294 | |
270 | | - if ( array_key_exists( $propertykey, $this->mProperties ) ) { |
271 | | - $property = $this->mProperties[$propertykey]; |
| 295 | + if ( array_key_exists( $propertyKey, $this->mProperties ) ) { |
| 296 | + $property = $this->mProperties[$propertyKey]; |
272 | 297 | } else { |
273 | | - if ( self::$mPropertyPrefix == false ) { |
| 298 | + if ( SMWSemanticData::$mPropertyPrefix == '' ) { |
274 | 299 | global $wgContLang; |
275 | | - self::$mPropertyPrefix = $wgContLang->getNsText( SMW_NS_PROPERTY ) . ':'; |
| 300 | + SMWSemanticData::$mPropertyPrefix = $wgContLang->getNsText( SMW_NS_PROPERTY ) . ':'; |
276 | 301 | } // explicitly use prefix to cope with things like [[Property:User:Stupid::somevalue]] |
277 | 302 | |
278 | | - $property = SMWPropertyValue::makeUserProperty( self::$mPropertyPrefix . $propertyName ); |
| 303 | + $propertyDV = SMWPropertyValue::makeUserProperty( SMWSemanticData::$mPropertyPrefix . $propertyName ); |
279 | 304 | |
280 | | - if ( !$property->isValid() ) { // error, maybe illegal title text |
| 305 | + if ( !$propertyDV->isValid() ) { // error, maybe illegal title text |
281 | 306 | return; |
282 | 307 | } |
| 308 | + |
| 309 | + $property = $propertyDV->getDataItem(); |
283 | 310 | } |
284 | 311 | |
285 | | - $this->addPropertyObjectValue( $property, $value ); |
| 312 | + $this->addPropertyObjectValue( $property, $dataItem ); |
286 | 313 | } |
287 | 314 | |
288 | 315 | /** |
— | — | @@ -290,12 +317,12 @@ |
291 | 318 | * the added value that will be used to initialize the value if needed at some point. |
292 | 319 | */ |
293 | 320 | public function addPropertyStubValue( $propertyKey, $valueKeys ) { |
294 | | - // Catch built-in mProperties, since their internal key is not what is used as a key elsewhere in SMWSemanticData. |
295 | | - if ( $propertyKey { 0 } == '_' ) { |
296 | | - $property = SMWPropertyValue::makeProperty( $propertyKey ); |
297 | | - $propertyKey = $property->getDBkey(); |
298 | | - $this->unstubProperty( $propertyKey, $property ); |
299 | | - } |
| 321 | + // Catch built-in properties, since their internal key is not what is used as a key elsewhere in SMWSemanticData. |
| 322 | +// if ( $propertyKey { 0 } == '_' ) { |
| 323 | +// $property = new SMWDIProperty( $propertyKey ); |
| 324 | +// $propertyKey = $property->getKey(); |
| 325 | +// $this->unstubProperty( $propertyKey, $property ); |
| 326 | +// } |
300 | 327 | |
301 | 328 | $this->mStubPropVals[$propertyKey][] = $valueKeys; |
302 | 329 | } |
— | — | @@ -309,14 +336,16 @@ |
310 | 337 | $this->mStubPropVals = array(); |
311 | 338 | $this->mHasVisibleProps = false; |
312 | 339 | $this->mHasVisibleSpecs = false; |
| 340 | + $this->stubObject = false; |
313 | 341 | } |
314 | 342 | |
315 | 343 | /** |
316 | | - * Process all mProperties that have been added as stubs. Associated data may remain in stub form. |
| 344 | + * Process all mProperties that have been added as stubs. |
| 345 | + * Associated data may remain in stub form. |
317 | 346 | */ |
318 | 347 | protected function unstubProperties() { |
319 | | - foreach ( $this->mStubPropVals as $pname => $values ) { // unstub property values only, the value lists are still kept as stubs |
320 | | - $this->unstubProperty( $pname ); |
| 348 | + foreach ( $this->mStubPropVals as $pkey => $values ) { // unstub property values only, the value lists are still kept as stubs |
| 349 | + $this->unstubProperty( $pkey ); |
321 | 350 | } |
322 | 351 | } |
323 | 352 | |
— | — | @@ -325,19 +354,21 @@ |
326 | 355 | * for that property might be provided, so we do not need to make a new one. It is not |
327 | 356 | * checked if the object matches the property name. |
328 | 357 | * |
329 | | - * @param string $propertyName |
330 | | - * @param $propertyObject |
| 358 | + * @param $propertyKey string |
| 359 | + * @param SMWDIProperty $diProperty |
331 | 360 | */ |
332 | | - protected function unstubProperty( $propertyName, $propertyObject = null ) { |
333 | | - if ( !array_key_exists( $propertyName, $this->mProperties ) ) { |
334 | | - if ( $propertyObject === null ) { |
335 | | - $propertyObject = SMWPropertyValue::makeProperty( $propertyName ); |
| 361 | + protected function unstubProperty( $propertyKey, $diProperty = null ) { |
| 362 | + if ( !array_key_exists( $propertyKey, $this->mProperties ) ) { |
| 363 | + if ( $diProperty === null ) { |
| 364 | + //$propertyDV = SMWPropertyValue::makeProperty( $propertyKey ); |
| 365 | + //$diProperty = $propertyDV->getDataItem(); |
| 366 | + $diProperty = new SMWDIProperty( $propertyKey, false ); |
336 | 367 | } |
337 | 368 | |
338 | | - $this->mProperties[$propertyName] = $propertyObject; |
| 369 | + $this->mProperties[$propertyKey] = $diProperty; |
339 | 370 | |
340 | | - if ( !$propertyObject->isUserDefined() ) { |
341 | | - if ( $propertyObject->isShown() ) { |
| 371 | + if ( !$diProperty->isUserDefined() ) { |
| 372 | + if ( $diProperty->isShown() ) { |
342 | 373 | $this->mHasVisibleSpecs = true; |
343 | 374 | $this->mHasVisibleProps = true; |
344 | 375 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php |
— | — | @@ -43,11 +43,26 @@ |
44 | 44 | /** |
45 | 45 | * Array of class names for creating new SMWDataValue, indexed by type id. |
46 | 46 | * |
47 | | - * @var array of SMWDataValue |
| 47 | + * @var array of string |
48 | 48 | */ |
49 | 49 | static private $mTypeClasses; |
50 | 50 | |
51 | 51 | /** |
| 52 | + * Array of data item classes, indexed by type id. |
| 53 | + * |
| 54 | + * @note This is only used for transition. Data items will not be created directly by SMWDataValueFactory in the future. |
| 55 | + * @var array of string |
| 56 | + */ |
| 57 | + static private $mTypeDiClasses; |
| 58 | + |
| 59 | + /** |
| 60 | + * Array of data item classes, indexed by type id. |
| 61 | + * |
| 62 | + * @var array of integer |
| 63 | + */ |
| 64 | + static private $mTypeDataItemIds; |
| 65 | + |
| 66 | + /** |
52 | 67 | * Create an SMWDataValue object that can hold values for the type that the |
53 | 68 | * given SMWTypesValue object specifies. If no $value is given, an empty |
54 | 69 | * container is created, the value of which can be set later on. |
— | — | @@ -55,7 +70,7 @@ |
56 | 71 | * @param SMWTypesValue $typevalue Represents the type of the object |
57 | 72 | * @param mixed $value user value string, or false if unknown |
58 | 73 | * @param mixed $caption user-defined caption or false if none given |
59 | | - * @param $property SMWPropertyValue property object for which this value was made, or NULL |
| 74 | + * @param SMWDIProperty $property property object for which this value was made, or null |
60 | 75 | */ |
61 | 76 | static public function newTypeObjectValue( SMWTypesValue $typeValue, $value = false, $caption = false, $property = null ) { |
62 | 77 | if ( !$typeValue->isValid() ) { // just return the error, pass it through |
— | — | @@ -73,13 +88,13 @@ |
74 | 89 | * is created, the value of which can be set later on. |
75 | 90 | * |
76 | 91 | * @param $typeid id string for the given type |
77 | | - * @param mixed $value user value string, or false if unknown |
78 | | - * @param mixed $caption user-defined caption or false if none given |
79 | | - * @param SMWPropertyValue $property Property object for which this value was made, or NULL |
| 92 | + * @param $value mixed user value string, or false if unknown |
| 93 | + * @param $caption mixed user-defined caption, or false if none given |
| 94 | + * @param $property SMWDIProperty property object for which this value is made, or NULL |
80 | 95 | * |
81 | 96 | * @return SMWDataValue |
82 | 97 | */ |
83 | | - static public function newTypeIDValue( $typeid, $value = false, $caption = false, $property = null ) { |
| 98 | + static public function newTypeIdValue( $typeid, $value = false, $caption = false, $property = null ) { |
84 | 99 | self::initDatatypes(); |
85 | 100 | |
86 | 101 | if ( array_key_exists( $typeid, self::$mTypeClasses ) ) { // direct response for basic types |
— | — | @@ -88,7 +103,7 @@ |
89 | 104 | $result = new self::$mTypeClasses['__lin']( $typeid ); |
90 | 105 | } else { // type really unknown |
91 | 106 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
92 | | - return new SMWErrorValue( wfMsgForContent( 'smw_unknowntype', $typeid ), $value, $caption ); |
| 107 | + return new SMWErrorValue( $typeid, wfMsgForContent( 'smw_unknowntype', $typeid ), $value, $caption ); |
93 | 108 | } |
94 | 109 | |
95 | 110 | if ( $property !== null ) { |
— | — | @@ -102,21 +117,57 @@ |
103 | 118 | } |
104 | 119 | |
105 | 120 | /** |
106 | | - * Create a value for the given property, provided as an SMWPropertyValue |
| 121 | + * Create a value for a data item. |
| 122 | + * |
| 123 | + * @param SMWDataItem $typeid id string for the given type |
| 124 | + * @param mixed $caption user-defined caption, or false if none given |
| 125 | + * @param SMWDIProperty $property property object for which this value is made, or NULL |
| 126 | + * |
| 127 | + * @return SMWDataValue |
| 128 | + */ |
| 129 | + static public function newDataItemValue( SMWDataItem $dataItem, $caption = false, $property = null ) { |
| 130 | + $result = self::newTypeIdValue( $dataItem->getTypeID(), false, $caption, $property ); |
| 131 | + $result->setDataItem( $dataItem ); |
| 132 | + if ( $caption !== false ) { |
| 133 | + $result->setCaption( $caption ); |
| 134 | + } |
| 135 | + return $result; |
| 136 | + } |
| 137 | + |
| 138 | + |
| 139 | + /** |
| 140 | + * Get the preferred data item ID for a given type. The ID defines the |
| 141 | + * appropriate data item class for processing data of this type. See |
| 142 | + * SMWDataItem for possible values. |
| 143 | + * |
| 144 | + * @param $typeid id string for the given type |
| 145 | + * @return integer data item ID |
| 146 | + */ |
| 147 | + static public function getDataItemId( $typeid ) { |
| 148 | + self::initDatatypes(); |
| 149 | + if ( array_key_exists( $typeid, self::$mTypeDataItemIds ) ) { |
| 150 | + return self::$mTypeDataItemIds[$typeid]; |
| 151 | + } else { |
| 152 | + return SMWDataItem::TYPE_NOTYPE; |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + /** |
| 157 | + * Create a value for the given property, provided as an SMWDIProperty |
107 | 158 | * object. If no value is given, an empty container is created, the value |
108 | 159 | * of which can be set later on. |
109 | 160 | * |
110 | | - * @param SMWPropertyValue $property |
111 | | - * @param mixed $value |
112 | | - * @param mixed $caption |
| 161 | + * @param $property SMWDIProperty |
| 162 | + * @param $value mixed |
| 163 | + * @param $caption mixed |
113 | 164 | * |
114 | 165 | * @return SMWDataValue |
115 | 166 | */ |
116 | | - static public function newPropertyObjectValue( SMWPropertyValue $property, $value = false, $caption = false ) { |
| 167 | + static public function newPropertyObjectValue( SMWDIProperty $property, $value = false, $caption = false ) { |
117 | 168 | if ( $property->isInverse() ) { |
118 | 169 | return self::newTypeIdValue( '_wpg', $value, $caption, $property ); |
119 | 170 | } else { |
120 | | - return self::newTypeIDValue( $property->getPropertyTypeID(), $value, $caption, $property ); |
| 171 | + return self::newTypeIdValue( $property->findPropertyTypeID(), $value, $caption, $property ); |
121 | 172 | } |
122 | 173 | } |
123 | 174 | |
— | — | @@ -172,6 +223,74 @@ |
173 | 224 | '__pro' => 'SMWPropertyValue', // Property type (possibly predefined, no always based on a page) |
174 | 225 | ); |
175 | 226 | |
| 227 | + self::$mTypeDiClasses = array( |
| 228 | + '_txt' => 'SMWDIBlob', // Text type |
| 229 | + '_cod' => 'SMWDIBlob', // Code type |
| 230 | + '_str' => 'SMWDIString', // String type |
| 231 | + '_ema' => 'SMWDIUri', // Email type |
| 232 | + '_uri' => 'SMWDIUri', // URL/URI type |
| 233 | + '_anu' => 'SMWDIUri', // Annotation URI type |
| 234 | + '_tel' => 'SMWDIUri', // Phone number (URI) type |
| 235 | + '_wpg' => 'SMWDIWikiPage', // Page type |
| 236 | + '_wpp' => 'SMWDIWikiPage', // Property page type TODO: make available to user space |
| 237 | + '_wpc' => 'SMWDIWikiPage', // Category page type TODO: make available to user space |
| 238 | + '_wpf' => 'SMWDIWikiPage', // Form page type for Semantic Forms |
| 239 | + '_num' => 'SMWDINumber', // Number type |
| 240 | + '_tem' => 'SMWDINumber', // Temperature type |
| 241 | + '_dat' => 'SMWDITime', // Time type |
| 242 | + '_boo' => 'SMWDIBoolean', // Boolean type |
| 243 | + '_rec' => 'SMWDIContainer', // Value list type (replacing former nary properties) |
| 244 | + // Special types are not avaialble directly for users (and have no local language name): |
| 245 | + '__typ' => 'SMWDIWikiPage', // Special type page type |
| 246 | + '__tls' => 'SMWDIString', // Special type list for decalring _rec properties |
| 247 | + '__con' => 'SMWDIConcept', // Special concept page type |
| 248 | + '__sps' => 'SMWDIString', // Special string type |
| 249 | + '__spu' => 'SMWDIUri', // Special uri type |
| 250 | + '__sup' => 'SMWDIWikiPage', // Special subproperty type |
| 251 | + '__suc' => 'SMWDIWikiPage', // Special subcategory type |
| 252 | + '__spf' => 'SMWDIWikiPage', // Special Form page type for Semantic Forms |
| 253 | + '__sin' => 'SMWDIWikiPage', // Special instance of type |
| 254 | + '__red' => 'SMWDIWikiPage', // Special redirect type |
| 255 | + '__lin' => 'SMWDINumber', // Special linear unit conversion type |
| 256 | + '__err' => 'SMWDIString', // Special error type |
| 257 | + '__imp' => 'SMWDIString', // Special import vocabulary type |
| 258 | + '__pro' => 'SMWDIProperty', // Property type (possibly predefined, no always based on a page) |
| 259 | + ); |
| 260 | + |
| 261 | + self::$mTypeDataItemIds = array( |
| 262 | + '_txt' => SMWDataItem::TYPE_BLOB, // Text type |
| 263 | + '_cod' => SMWDataItem::TYPE_BLOB, // Code type |
| 264 | + '_str' => SMWDataItem::TYPE_STRING, // String type |
| 265 | + '_ema' => SMWDataItem::TYPE_URI, // Email type |
| 266 | + '_uri' => SMWDataItem::TYPE_URI, // URL/URI type |
| 267 | + '_anu' => SMWDataItem::TYPE_URI, // Annotation URI type |
| 268 | + '_tel' => SMWDataItem::TYPE_URI, // Phone number (URI) type |
| 269 | + '_wpg' => SMWDataItem::TYPE_WIKIPAGE, // Page type |
| 270 | + '_wpp' => SMWDataItem::TYPE_WIKIPAGE, // Property page type TODO: make available to user space |
| 271 | + '_wpc' => SMWDataItem::TYPE_WIKIPAGE, // Category page type TODO: make available to user space |
| 272 | + '_wpf' => SMWDataItem::TYPE_WIKIPAGE, // Form page type for Semantic Forms |
| 273 | + '_num' => SMWDataItem::TYPE_NUMBER, // Number type |
| 274 | + '_tem' => SMWDataItem::TYPE_NUMBER, // Temperature type |
| 275 | + '_dat' => SMWDataItem::TYPE_TIME, // Time type |
| 276 | + '_boo' => SMWDataItem::TYPE_BOOLEAN, // Boolean type |
| 277 | + '_rec' => SMWDataItem::TYPE_CONTAINER, // Value list type (replacing former nary properties) |
| 278 | + // Special types are not avaialble directly for users (and have no local language name): |
| 279 | + '__typ' => SMWDataItem::TYPE_WIKIPAGE, // Special type page type |
| 280 | + '__tls' => SMWDataItem::TYPE_STRING, // Special type list for decalring _rec properties |
| 281 | + '__con' => SMWDataItem::TYPE_CONCEPT, // Special concept page type |
| 282 | + '__sps' => SMWDataItem::TYPE_STRING, // Special string type |
| 283 | + '__spu' => SMWDataItem::TYPE_URI, // Special uri type |
| 284 | + '__sup' => SMWDataItem::TYPE_WIKIPAGE, // Special subproperty type |
| 285 | + '__suc' => SMWDataItem::TYPE_WIKIPAGE, // Special subcategory type |
| 286 | + '__spf' => SMWDataItem::TYPE_WIKIPAGE, // Special Form page type for Semantic Forms |
| 287 | + '__sin' => SMWDataItem::TYPE_WIKIPAGE, // Special instance of type |
| 288 | + '__red' => SMWDataItem::TYPE_WIKIPAGE, // Special redirect type |
| 289 | + '__lin' => SMWDataItem::TYPE_NUMBER, // Special linear unit conversion type |
| 290 | + '__err' => SMWDataItem::TYPE_STRING, // Special error type |
| 291 | + '__imp' => SMWDataItem::TYPE_STRING, // Special import vocabulary type |
| 292 | + '__pro' => SMWDataItem::TYPE_PROPERTY, // Property type (possibly predefined, no always based on a page) |
| 293 | + ); |
| 294 | + |
176 | 295 | wfRunHooks( 'smwInitDatatypes' ); |
177 | 296 | } |
178 | 297 | |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Number.php |
— | — | @@ -34,6 +34,10 @@ |
35 | 35 | return $this->m_number; |
36 | 36 | } |
37 | 37 | |
| 38 | + public function getSortKey() { |
| 39 | + return $this->m_number; |
| 40 | + } |
| 41 | + |
38 | 42 | public function getSerialization() { |
39 | 43 | return strval( $this->m_number ); |
40 | 44 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Error.php |
— | — | @@ -0,0 +1,53 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @file |
| 5 | + * @ingroup SMWDataItems |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * This class implements error list data items. These data items are used to |
| 10 | + * pass around lists of error messages within the application. They are not |
| 11 | + * meant to be stored or exported, but they can be useful to a user. |
| 12 | + * |
| 13 | + * @author Markus Krötzsch |
| 14 | + * @ingroup SMWDataItems |
| 15 | + */ |
| 16 | +class SMWDIError extends SMWDataItem { |
| 17 | + |
| 18 | + /** |
| 19 | + * List of error messages. Should always be safe for HTML. |
| 20 | + * @var array of strings |
| 21 | + */ |
| 22 | + protected $m_errors; |
| 23 | + |
| 24 | + public function __construct( $errors, $typeid = '__err' ) { |
| 25 | + parent::__construct( $typeid ); |
| 26 | + $this->m_errors = $errors; |
| 27 | + } |
| 28 | + |
| 29 | + public function getDIType() { |
| 30 | + return SMWDataItem::TYPE_ERROR; |
| 31 | + } |
| 32 | + |
| 33 | + public function getErrors() { |
| 34 | + return $this->m_errors; |
| 35 | + } |
| 36 | + |
| 37 | + public function getSortKey() { |
| 38 | + return 'error'; |
| 39 | + } |
| 40 | + |
| 41 | + public function getSerialization() { |
| 42 | + return serialize( $this->m_errors ); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Create a data item from the provided serialization string and type |
| 47 | + * ID. |
| 48 | + * @return SMWDIError |
| 49 | + */ |
| 50 | + public static function doUnserialize( $serialization, $typeid ) { |
| 51 | + return new SMWDIError( unserialize( $serialization ), $typeid ); |
| 52 | + } |
| 53 | + |
| 54 | +} |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Error.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 55 | + native |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Bool.php |
— | — | @@ -10,7 +10,7 @@ |
11 | 11 | * @author Markus Krötzsch |
12 | 12 | * @ingroup SMWDataItems |
13 | 13 | */ |
14 | | -class SMWDIBool extends SMWDataItem { |
| 14 | +class SMWDIBoolean extends SMWDataItem { |
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Internal value. |
— | — | @@ -24,7 +24,7 @@ |
25 | 25 | } |
26 | 26 | |
27 | 27 | public function getDIType() { |
28 | | - return SMWDataItem::TYPE_BOOL; |
| 28 | + return SMWDataItem::TYPE_BOOLEAN; |
29 | 29 | } |
30 | 30 | |
31 | 31 | public function getBoolean() { |
— | — | @@ -35,16 +35,20 @@ |
36 | 36 | return $this->m_boolean ? 't' : 'f'; |
37 | 37 | } |
38 | 38 | |
| 39 | + public function getSortKey() { |
| 40 | + return $this->m_boolean ? 1 : 0; |
| 41 | + } |
| 42 | + |
39 | 43 | /** |
40 | 44 | * Create a data item from the provided serialization string and type |
41 | 45 | * ID. |
42 | | - * @return SMWDIBool |
| 46 | + * @return SMWDIBoolean |
43 | 47 | */ |
44 | 48 | public static function doUnserialize( $serialization, $typeid ) { |
45 | 49 | if ( $serialization == 't' ) { |
46 | | - return new SMWDIBool( true, $typeid ); |
| 50 | + return new SMWDIBoolean( true, $typeid ); |
47 | 51 | } elseif ( $serialization == 'f' ) { |
48 | | - return new SMWDIBool( true, $typeid ); |
| 52 | + return new SMWDIBoolean( true, $typeid ); |
49 | 53 | } else { |
50 | 54 | throw new SMWDataItemException( "Boolean data item unserialised from illegal value '$serialization'" ); |
51 | 55 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Concept.php |
— | — | @@ -82,6 +82,10 @@ |
83 | 83 | return $this->m_depth; |
84 | 84 | } |
85 | 85 | |
| 86 | + public function getSortKey() { |
| 87 | + return $this->m_docu; |
| 88 | + } |
| 89 | + |
86 | 90 | public function getSerialization() { |
87 | 91 | return serialize( $this ); |
88 | 92 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DataItem.php |
— | — | @@ -42,28 +42,32 @@ |
43 | 43 | */ |
44 | 44 | abstract class SMWDataItem { |
45 | 45 | |
| 46 | + /// Data item ID that can be used to indicate that no data item class is appropriate |
| 47 | + const TYPE_NOTYPE = 0; |
46 | 48 | /// Data item ID for SMWDINumber |
47 | | - const TYPE_NUMBER = 1; |
| 49 | + const TYPE_NUMBER = 1; |
48 | 50 | /// Data item ID for SMWDIString |
49 | | - const TYPE_STRING = 2; |
| 51 | + const TYPE_STRING = 2; |
50 | 52 | /// Data item ID for SMWDIBlob |
51 | | - const TYPE_BLOB = 3; |
52 | | - /// Data item ID for SMWDIBool |
53 | | - const TYPE_BOOL = 4; |
54 | | - /// Data item ID for SMWDIURI |
55 | | - const TYPE_URI = 5; |
| 53 | + const TYPE_BLOB = 3; |
| 54 | + /// Data item ID for SMWDIBoolean |
| 55 | + const TYPE_BOOLEAN = 4; |
| 56 | + /// Data item ID for SMWDIUri |
| 57 | + const TYPE_URI = 5; |
56 | 58 | /// Data item ID for SMWDITimePoint |
57 | | - const TYPE_TIME = 6; |
| 59 | + const TYPE_TIME = 6; |
58 | 60 | /// Data item ID for SMWDIGeoCoords |
59 | | - const TYPE_GEO = 7; |
| 61 | + const TYPE_GEO = 7; |
60 | 62 | /// Data item ID for SMWDIContainer |
61 | | - const TYPE_CONT = 8; |
| 63 | + const TYPE_CONTAINER = 8; |
62 | 64 | /// Data item ID for SMWDIWikiPage |
63 | | - const TYPE_WIKIPAGE = 9; |
| 65 | + const TYPE_WIKIPAGE = 9; |
64 | 66 | /// Data item ID for SMWDIConcept |
65 | | - const TYPE_CONCEPT = 10; |
| 67 | + const TYPE_CONCEPT = 10; |
66 | 68 | /// Data item ID for SMWDIProperty |
67 | | - const TYPE_PROP = 11; |
| 69 | + const TYPE_PROPERTY = 11; |
| 70 | + /// Data item ID for SMWDIError |
| 71 | + const TYPE_ERROR = 12; |
68 | 72 | |
69 | 73 | /** |
70 | 74 | * The SMW type ID that governs the handling of this data item. |
— | — | @@ -99,14 +103,35 @@ |
100 | 104 | } |
101 | 105 | |
102 | 106 | /** |
| 107 | + * Return a value that can be used for sorting data of this type. |
| 108 | + * If the data is of a numerical type, the sorting must be done in |
| 109 | + * numerical order. If the data is a string, the data must be sorted |
| 110 | + * alphabetically. |
| 111 | + * |
| 112 | + * @return float or string |
| 113 | + */ |
| 114 | + abstract public function getSortKey(); |
| 115 | + |
| 116 | + /** |
103 | 117 | * Get a UTF-8 encoded string serialization of this data item. |
104 | 118 | * The serialisation should be concise and need not be pretty, but it |
105 | | - * must allow unserialization. For this purpose |
| 119 | + * must allow unserialization. Each subclass of SMWDataItem implements |
| 120 | + * a static method doUnserialize() for this purpose. |
106 | 121 | * @return string |
107 | 122 | */ |
108 | 123 | abstract public function getSerialization(); |
109 | 124 | |
110 | 125 | /** |
| 126 | + * Get a hash string for this data item. Might be overwritten in |
| 127 | + * subclasses to obtain shorter or more efficient hashes. |
| 128 | + * |
| 129 | + * @return string |
| 130 | + */ |
| 131 | + public function getHash() { |
| 132 | + return $this->getSerialization(); |
| 133 | + } |
| 134 | + |
| 135 | + /** |
111 | 136 | * Create a data item from the provided serialization string and type |
112 | 137 | * ID. This static method really needs to be re-implemented by each |
113 | 138 | * data item class. It is given here only for reference. Note that PHP |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Blob.php |
— | — | @@ -31,6 +31,10 @@ |
32 | 32 | return $this->m_string; |
33 | 33 | } |
34 | 34 | |
| 35 | + public function getSortKey() { |
| 36 | + return $this->m_string; |
| 37 | + } |
| 38 | + |
35 | 39 | public function getSerialization() { |
36 | 40 | return $this->m_string; |
37 | 41 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Time.php |
— | — | @@ -110,16 +110,16 @@ |
111 | 111 | } |
112 | 112 | parent::__construct( $typeid ); |
113 | 113 | $this->m_model = $calendarmodel; |
114 | | - $this->m_year = $year; |
115 | | - $this->m_month = $month !== false ? $month : 1; |
116 | | - $this->m_day = $day !== false ? $day : 1; |
117 | | - $this->m_hours = $hour !== false ? $hour : 0; |
118 | | - $this->m_minutes = $minute !== false ? $minute : 0; |
119 | | - $this->m_seconds = $second !== false ? $second : 0; |
| 114 | + $this->m_year = intval( $year ); |
| 115 | + $this->m_month = $month != false ? intval( $month ) : 1; |
| 116 | + $this->m_day = $day != false ? intval( $day ) : 1; |
| 117 | + $this->m_hours = $hour !== false ? intval( $hour ) : 0; |
| 118 | + $this->m_minutes = $minute !== false ? intval( $minute ) : 0; |
| 119 | + $this->m_seconds = $second !== false ? intval( $second ) : 0; |
120 | 120 | if ( ( $this->m_hours < 0 ) || ( $this->m_hours > 23 ) || |
121 | 121 | ( $this->m_minutes < 0 ) || ( $this->m_minutes > 59 ) || |
122 | 122 | ( $this->m_seconds < 0 ) || ( $this->m_seconds > 59 ) || |
123 | | - ( $this->m_month < 0 ) || ( $this->m_month > 12 ) ) { |
| 123 | + ( $this->m_month < 1 ) || ( $this->m_month > 12 ) ) { |
124 | 124 | throw new SMWDataItemException( "Part of the date is out of bounds." ); |
125 | 125 | } |
126 | 126 | if ( $this->m_day > SMWDITime::getDayNumberForMonth( $this->m_month, $this->m_year, $this->m_model ) ) { |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_URI.php |
— | — | @@ -10,7 +10,7 @@ |
11 | 11 | * @author Markus Krötzsch |
12 | 12 | * @ingroup SMWDataItems |
13 | 13 | */ |
14 | | -class SMWDIURI extends SMWDataItem { |
| 14 | +class SMWDIUri extends SMWDataItem { |
15 | 15 | |
16 | 16 | /** |
17 | 17 | * URI scheme such as "html" or "mailto". |
— | — | @@ -87,6 +87,10 @@ |
88 | 88 | return $this->m_fragment; |
89 | 89 | } |
90 | 90 | |
| 91 | + public function getSortKey() { |
| 92 | + return $this->getURI(); |
| 93 | + } |
| 94 | + |
91 | 95 | public function getSerialization() { |
92 | 96 | return $this->getURI(); |
93 | 97 | } |
— | — | @@ -94,7 +98,7 @@ |
95 | 99 | /** |
96 | 100 | * Create a data item from the provided serialization string and type |
97 | 101 | * ID. |
98 | | - * @return SMWDIURI |
| 102 | + * @return SMWDIUri |
99 | 103 | */ |
100 | 104 | public static function doUnserialize( $serialization, $typeid ) { |
101 | 105 | $parts = explode( ':', $serialization, 2 ); // try to split "schema:rest" |
— | — | @@ -114,7 +118,7 @@ |
115 | 119 | $hierpart = $parts[0]; |
116 | 120 | $fragment = ( count( $parts ) == 2 ) ? $parts[1] : ''; |
117 | 121 | } |
118 | | - return new SMWDIURI( $scheme, $hierpart, $query, $fragment, $typeid ); |
| 122 | + return new SMWDIUri( $scheme, $hierpart, $query, $fragment, $typeid ); |
119 | 123 | } |
120 | 124 | |
121 | 125 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_WikiPage.php |
— | — | @@ -62,6 +62,15 @@ |
63 | 63 | return $this->m_interwiki; |
64 | 64 | } |
65 | 65 | |
| 66 | + /** |
| 67 | + * Get the sortkey of the wiki page data item. Note that this is not |
| 68 | + * the sortkey that might have been set for the corresponding wiki |
| 69 | + * page. |
| 70 | + */ |
| 71 | + public function getSortKey() { |
| 72 | + return $this->m_dbkey; |
| 73 | + } |
| 74 | + |
66 | 75 | public function getSerialization() { |
67 | 76 | return strval( $this->m_dbkey . '#' . strval( $this->m_namespace ) . '#' . $this->m_interwiki ); |
68 | 77 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Property.php |
— | — | @@ -53,6 +53,11 @@ |
54 | 54 | * @var boolean |
55 | 55 | */ |
56 | 56 | protected $m_inverse; |
| 57 | + /** |
| 58 | + * Cache for property type ID. |
| 59 | + * @var string |
| 60 | + */ |
| 61 | + protected $m_proptypeid; |
57 | 62 | |
58 | 63 | /** |
59 | 64 | * Initialise a property. This constructor checks that keys of |
— | — | @@ -81,7 +86,7 @@ |
82 | 87 | } |
83 | 88 | |
84 | 89 | public function getDIType() { |
85 | | - return SMWDataItem::TYPE_PROP; |
| 90 | + return SMWDataItem::TYPE_PROPERTY; |
86 | 91 | } |
87 | 92 | |
88 | 93 | public function getKey() { |
— | — | @@ -92,6 +97,10 @@ |
93 | 98 | return $this->m_inverse; |
94 | 99 | } |
95 | 100 | |
| 101 | + public function getSortKey() { |
| 102 | + return $this->m_key; |
| 103 | + } |
| 104 | + |
96 | 105 | /** |
97 | 106 | * Specifies whether values of this property should be shown in the |
98 | 107 | * Factbox. A property may wish to prevent this if either |
— | — | @@ -141,6 +150,26 @@ |
142 | 151 | } |
143 | 152 | |
144 | 153 | /** |
| 154 | + * Get an object of type SMWDIWikiPage that represents the page which |
| 155 | + * relates to this property, or null if no such page exists. The latter |
| 156 | + * can happen for special properties without user-readable label, and |
| 157 | + * for inverse properties. |
| 158 | + */ |
| 159 | + public function getDiWikiPage() { |
| 160 | + if ( $this->m_inverse ) return null; |
| 161 | + if ( $this->isUserDefined() ) { |
| 162 | + $dbkey = $this->m_key; |
| 163 | + } else { |
| 164 | + $dbkey = str_replace( ' ', '_', $this->getLabel() ); |
| 165 | + } |
| 166 | + try { |
| 167 | + return new SMWDIWikiPage( $dbkey, SMW_NS_PROPERTY, '', '_wpp' ); |
| 168 | + } catch ( SMWDataItemException $e ) { |
| 169 | + return null; |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + /** |
145 | 174 | * Get the type ID of a predefined property, or '' if the property |
146 | 175 | * is not predefined. |
147 | 176 | * The function is guaranteed to return a type ID if isUserDefined() |
— | — | @@ -155,6 +184,35 @@ |
156 | 185 | } |
157 | 186 | } |
158 | 187 | |
| 188 | + /** |
| 189 | + * Find the property's type ID, either by looking up its predefined ID |
| 190 | + * (if any) or by retrieving the relevant information from the store. |
| 191 | + * If no type is stored for a user defined property, the global default |
| 192 | + * type will be used. |
| 193 | + * |
| 194 | + * @return string type ID |
| 195 | + */ |
| 196 | + public function findPropertyTypeID() { |
| 197 | + global $smwgPDefaultType; |
| 198 | + if ( !isset( $this->m_proptypeid ) ) { |
| 199 | + if ( $this->isUserDefined() ) { // normal property |
| 200 | + $diWikiPage = new SMWDIWikiPage( $this->getKey(), SMW_NS_PROPERTY, '' ); |
| 201 | + $typearray = smwfGetStore()->getPropertyValues( $diWikiPage, new SMWDIProperty( '_TYPE' ) ); |
| 202 | + if ( count( $typearray ) >= 1 ) { // some types given, pick one (hopefully unique) |
| 203 | + $typeString = reset( $typearray ); |
| 204 | + $this->m_proptypeid = ( $typeString instanceOf SMWDIWikiPage ) ? |
| 205 | + SMWDataValueFactory::findTypeID( $typeString->getDBKey() ) : '__err'; |
| 206 | + } elseif ( count( $typearray ) == 0 ) { // no type given |
| 207 | + $this->m_proptypeid = $smwgPDefaultType; |
| 208 | + } |
| 209 | + } else { // pre-defined property |
| 210 | + $this->m_proptypeid = $this->getPredefinedPropertyTypeID(); |
| 211 | + } |
| 212 | + } |
| 213 | + return $this->m_proptypeid; |
| 214 | + } |
| 215 | + |
| 216 | + |
159 | 217 | public function getSerialization() { |
160 | 218 | return ( $this->m_inverse ? '-' : '' ) . $this->m_key ; |
161 | 219 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php |
— | — | @@ -109,6 +109,7 @@ |
110 | 110 | $wgAutoloadClasses['SMWDataValueFactory'] = $smwgIP . 'includes/SMW_DataValueFactory.php'; |
111 | 111 | $wgAutoloadClasses['SMWDataValue'] = $smwgIP . 'includes/SMW_DataValue.php'; |
112 | 112 | $wgAutoloadClasses['SMWQueryLanguage'] = $smwgIP . 'includes/SMW_QueryLanguage.php'; |
| 113 | + $wgAutoloadClasses['SMWCompatibilityHelpers'] = $smwgIP . 'includes/SMW_Compatibility_Helpers.php'; |
113 | 114 | |
114 | 115 | // Article pages |
115 | 116 | $apDir = $smwgIP . 'includes/articlepages/'; |
— | — | @@ -135,15 +136,16 @@ |
136 | 137 | $wgAutoloadClasses['SMWDataItem'] = $diDir . 'SMW_DataItem.php'; |
137 | 138 | $wgAutoloadClasses['SMWDataItemException'] = $diDir . 'SMW_DataItem.php'; |
138 | 139 | $wgAutoloadClasses['SMWDIProperty'] = $diDir . 'SMW_DI_Property.php'; |
139 | | - $wgAutoloadClasses['SMWDIBool'] = $diDir . 'SMW_DI_Bool.php'; |
| 140 | + $wgAutoloadClasses['SMWDIBoolean'] = $diDir . 'SMW_DI_Bool.php'; |
140 | 141 | $wgAutoloadClasses['SMWDINumber'] = $diDir . 'SMW_DI_Number.php'; |
141 | 142 | $wgAutoloadClasses['SMWDIBlob'] = $diDir . 'SMW_DI_Blob.php'; |
142 | 143 | $wgAutoloadClasses['SMWDIString'] = $diDir . 'SMW_DI_String.php'; |
143 | 144 | $wgAutoloadClasses['SMWStringLengthException'] = $diDir . 'SMW_DI_String.php'; |
144 | | - $wgAutoloadClasses['SMWDIURI'] = $diDir . 'SMW_DI_URI.php'; |
| 145 | + $wgAutoloadClasses['SMWDIUri'] = $diDir . 'SMW_DI_URI.php'; |
145 | 146 | $wgAutoloadClasses['SMWDIWikiPage'] = $diDir . 'SMW_DI_WikiPage.php'; |
146 | 147 | $wgAutoloadClasses['SMWDITime'] = $diDir . 'SMW_DI_Time.php'; |
147 | 148 | $wgAutoloadClasses['SMWDIConcept'] = $diDir . 'SMW_DI_Concept.php'; |
| 149 | + $wgAutoloadClasses['SMWDIError'] = $diDir . 'SMW_DI_Error.php'; |
148 | 150 | |
149 | 151 | // Datavalues |
150 | 152 | $dvDir = $smwgIP . 'includes/datavalues/'; |