Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php |
— | — | @@ -95,6 +95,8 @@ |
96 | 96 | * @param mixed $caption string or false |
97 | 97 | * @param Parser $parser |
98 | 98 | * @param boolean $storeAnnotation |
| 99 | + * |
| 100 | + * @return SMWDataValue |
99 | 101 | */ |
100 | 102 | static public function addProperty( $propertyName, $value, $caption, Parser $parser, $storeAnnotation = true ) { |
101 | 103 | wfProfileIn( "SMWParseData::addProperty (SMW)" ); |
— | — | @@ -111,7 +113,8 @@ |
112 | 114 | } elseif ( $storeAnnotation && ( self::getSMWData( $parser ) !== null ) ) { |
113 | 115 | self::getSMWData( $parser )->addPropertyObjectValue( $property, $result ); |
114 | 116 | |
115 | | - if ( !$result->isValid() ) { // take note of the error for storage (do this here and not in storage, thus avoiding duplicates) |
| 117 | + // Take note of the error for storage (do this here and not in storage, thus avoiding duplicates). |
| 118 | + if ( !$result->isValid() ) { |
116 | 119 | self::getSMWData( $parser )->addPropertyObjectValue( SMWPropertyValue::makeProperty( '_ERRP' ), $property->getWikiPageValue() ); |
117 | 120 | } |
118 | 121 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php |
— | — | @@ -331,11 +331,13 @@ |
332 | 332 | * | area = 396 km² |
333 | 333 | * | sea = Adria |
334 | 334 | * }} |
| 335 | + * |
335 | 336 | * This creates annotations with the properties as stated on the left side, and the |
336 | 337 | * values on the right side. |
337 | 338 | * |
338 | | - * @param[in] &$parser Parser The current parser |
339 | | - * @return nothing |
| 339 | + * @param Parser &$parser The current parser |
| 340 | + * |
| 341 | + * @return empty string |
340 | 342 | */ |
341 | 343 | static public function doSet( &$parser ) { |
342 | 344 | $params = func_get_args(); |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php |
— | — | @@ -3,8 +3,10 @@ |
4 | 4 | * The class in this file manages (special) properties that are |
5 | 5 | * associated with a certain subject (article). It is used as a |
6 | 6 | * container for chunks of subject-centred data. |
| 7 | + * |
7 | 8 | * @file |
8 | 9 | * @ingroup SMW |
| 10 | + * |
9 | 11 | * @author Markus Krötzsch |
10 | 12 | */ |
11 | 13 | |
— | — | @@ -12,6 +14,7 @@ |
13 | 15 | * Class for representing chunks of semantic data for one given |
14 | 16 | * article (subject), similar what is typically displayed in the factbox. |
15 | 17 | * This is a light-weight data container. |
| 18 | + * |
16 | 19 | * @ingroup SMW |
17 | 20 | */ |
18 | 21 | class SMWSemanticData { |
— | — | @@ -79,21 +82,28 @@ |
80 | 83 | |
81 | 84 | /** |
82 | 85 | * Get the array of all stored values for some property. |
| 86 | + * |
| 87 | + * @param SMWPropertyValue $property |
83 | 88 | */ |
84 | 89 | public function getPropertyValues( SMWPropertyValue $property ) { |
85 | | - if ( array_key_exists( $property->getDBkey(), $this->stubpropvals ) ) { // unstub those entries completely |
| 90 | + if ( array_key_exists( $property->getDBkey(), $this->stubpropvals ) ) { |
| 91 | + // Unstub those entries completely. |
86 | 92 | $this->unstubProperty( $property->getDBkey(), $property ); |
| 93 | + |
87 | 94 | foreach ( $this->stubpropvals[$property->getDBkey()] as $dbkeys ) { |
88 | 95 | $dv = SMWDataValueFactory::newPropertyObjectValue( $property ); |
89 | 96 | $dv->setDBkeys( $dbkeys ); |
| 97 | + |
90 | 98 | if ( $this->m_noduplicates ) { |
91 | 99 | $this->propvals[$property->getDBkey()][$dv->getHash()] = $dv; |
92 | 100 | } else { |
93 | 101 | $this->propvals[$property->getDBkey()][] = $dv; |
94 | 102 | } |
95 | 103 | } |
| 104 | + |
96 | 105 | unset( $this->stubpropvals[$property->getDBkey()] ); |
97 | 106 | } |
| 107 | + |
98 | 108 | if ( array_key_exists( $property->getDBkey(), $this->propvals ) ) { |
99 | 109 | return $this->propvals[$property->getDBkey()]; |
100 | 110 | } else { |
— | — | @@ -108,15 +118,19 @@ |
109 | 119 | */ |
110 | 120 | public function getHash() { |
111 | 121 | $ctx = hash_init( 'md5' ); |
| 122 | + |
112 | 123 | if ( $this->subject !== null ) { // here and below, use "_#_" to separate values; really not much care needed here |
113 | 124 | hash_update( $ctx, '_#_' . $this->subject->getHash() ); |
114 | 125 | } |
| 126 | + |
115 | 127 | foreach ( $this->getProperties() as $property ) { |
116 | 128 | hash_update( $ctx, '_#_' . $property->getHash() . '##' ); |
| 129 | + |
117 | 130 | foreach ( $this->getPropertyValues( $property ) as $dv ) { |
118 | 131 | hash_update( $ctx, '_#_' . $dv->getHash() ); |
119 | 132 | } |
120 | 133 | } |
| 134 | + |
121 | 135 | return hash_final( $ctx ); |
122 | 136 | } |
123 | 137 | |
— | — | @@ -150,15 +164,18 @@ |
151 | 165 | */ |
152 | 166 | public function addPropertyObjectValue( SMWPropertyValue $property, SMWDataValue $value ) { |
153 | 167 | if ( !$property->isValid() ) return; // nothing we can do |
| 168 | + |
154 | 169 | if ( !array_key_exists( $property->getDBkey(), $this->propvals ) ) { |
155 | 170 | $this->propvals[$property->getDBkey()] = array(); |
156 | 171 | $this->properties[$property->getDBkey()] = $property; |
157 | 172 | } |
| 173 | + |
158 | 174 | if ( $this->m_noduplicates ) { |
159 | 175 | $this->propvals[$property->getDBkey()][$value->getHash()] = $value; |
160 | 176 | } else { |
161 | 177 | $this->propvals[$property->getDBkey()][] = $value; |
162 | 178 | } |
| 179 | + |
163 | 180 | if ( !$property->isUserDefined() ) { |
164 | 181 | if ( $property->isShown() ) { |
165 | 182 | $this->hasvisiblespecs = true; |
— | — | @@ -175,6 +192,7 @@ |
176 | 193 | */ |
177 | 194 | public function addPropertyValue( $propertyname, SMWDataValue $value ) { |
178 | 195 | $propertykey = smwfNormalTitleDBKey( $propertyname ); |
| 196 | + |
179 | 197 | if ( array_key_exists( $propertykey, $this->properties ) ) { |
180 | 198 | $property = $this->properties[$propertykey]; |
181 | 199 | } else { |
— | — | @@ -182,11 +200,14 @@ |
183 | 201 | global $wgContLang; |
184 | 202 | SMWSemanticData::$m_propertyprefix = $wgContLang->getNsText( SMW_NS_PROPERTY ) . ':'; |
185 | 203 | } // explicitly use prefix to cope with things like [[Property:User:Stupid::somevalue]] |
| 204 | + |
186 | 205 | $property = SMWPropertyValue::makeUserProperty( SMWSemanticData::$m_propertyprefix . $propertyname ); |
| 206 | + |
187 | 207 | if ( !$property->isValid() ) { // error, maybe illegal title text |
188 | 208 | return; |
189 | 209 | } |
190 | 210 | } |
| 211 | + |
191 | 212 | $this->addPropertyObjectValue( $property, $value ); |
192 | 213 | } |
193 | 214 | |
— | — | @@ -196,12 +217,13 @@ |
197 | 218 | * the added value that will be used to initialize the value if needed at some point. |
198 | 219 | */ |
199 | 220 | public function addPropertyStubValue( $propertykey, $valuekeys ) { |
200 | | - // catch built-in properties, since their internal key is not what is used as a key elsewhere in SMWSemanticData |
| 221 | + // Catch built-in properties, since their internal key is not what is used as a key elsewhere in SMWSemanticData. |
201 | 222 | if ( $propertykey { 0 } == '_' ) { |
202 | 223 | $property = SMWPropertyValue::makeProperty( $propertykey ); |
203 | 224 | $propertykey = $property->getDBkey(); |
204 | 225 | $this->unstubProperty( $propertykey, $property ); |
205 | 226 | } |
| 227 | + |
206 | 228 | $this->stubpropvals[$propertykey][] = $valuekeys; |
207 | 229 | } |
208 | 230 | |
— | — | @@ -235,7 +257,9 @@ |
236 | 258 | if ( $propertyobj === null ) { |
237 | 259 | $propertyobj = SMWPropertyValue::makeProperty( $pname ); |
238 | 260 | } |
| 261 | + |
239 | 262 | $this->properties[$pname] = $propertyobj; |
| 263 | + |
240 | 264 | if ( !$propertyobj->isUserDefined() ) { |
241 | 265 | if ( $propertyobj->isShown() ) { |
242 | 266 | $this->hasvisiblespecs = true; |
— | — | @@ -247,5 +271,4 @@ |
248 | 272 | } |
249 | 273 | } |
250 | 274 | |
251 | | -} |
252 | | - |
| 275 | +} |
\ No newline at end of file |