Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php |
— | — | @@ -107,8 +107,8 @@ |
108 | 108 | if ( $showfactbox == SMW_FACTBOX_HIDDEN ) { // use shortcut |
109 | 109 | return ''; |
110 | 110 | } |
111 | | - // deal with complete dataset only if needed: |
112 | | - if ( !isset( $parseroutput->mSMWData ) || $parseroutput->mSMWData->stubobject ) { |
| 111 | + // Deal with complete dataset only if needed: |
| 112 | + if ( !isset( $parseroutput->mSMWData ) || $parseroutput->mSMWData->stubObject ) { |
113 | 113 | $semdata = smwfGetStore()->getSemanticData( $title ); |
114 | 114 | } else { |
115 | 115 | $semdata = $parseroutput->mSMWData; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * The class in this file manages (special) properties that are |
| 4 | + * The class in this file manages (special) mProperties 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,6 +8,7 @@ |
9 | 9 | * @ingroup SMW |
10 | 10 | * |
11 | 11 | * @author Markus Krötzsch |
| 12 | + * @author Jeroen De Dauw |
12 | 13 | */ |
13 | 14 | |
14 | 15 | /** |
— | — | @@ -18,37 +19,85 @@ |
19 | 20 | * @ingroup SMW |
20 | 21 | */ |
21 | 22 | class SMWSemanticData { |
22 | | - /// Text keys and arrays of datavalue objects. |
23 | | - protected $propvals = array(); |
24 | | - /// Text keys and title objects. |
25 | | - protected $properties = array(); |
26 | | - /// Stub property data that is not part of $propvals and $properties yet. Entries use |
27 | | - /// property DB keys as keys. The value is an array of DBkey-arrays that define individual |
28 | | - /// datavalues. The stubs will be set up when first accessed. |
29 | | - protected $stubpropvals = array(); |
30 | | - /// Boolean, stating whether the container holds any normal properties. |
31 | | - protected $hasvisibleprops = false; |
32 | | - /// Boolean, stating whether the container holds any displayable special properties (some are internal only without a display name). |
33 | | - protected $hasvisiblespecs = false; |
34 | | - /// Boolean, stating whether this is a stub object. Stubbing might happen on serialisation to safe DB space |
35 | | - public $stubobject = true; |
| 23 | + |
36 | 24 | /** |
37 | | - * Boolean, stating whether repeated values should be avoided. Not needing duplicte elimination |
| 25 | + * States whether this is a stub object. Stubbing might happen on serialisation to safe DB space. |
| 26 | + * |
| 27 | + * @var boolean |
| 28 | + */ |
| 29 | + public $stubObject = true; |
| 30 | + |
| 31 | + /** |
| 32 | + * Cache for the local version of "Property:" |
| 33 | + * |
| 34 | + * @var mixed |
| 35 | + */ |
| 36 | + static protected $mPropertyPrefix = false; |
| 37 | + |
| 38 | + /** |
| 39 | + * Text keys and arrays of datavalue objects. |
| 40 | + * |
| 41 | + * @var array |
| 42 | + */ |
| 43 | + protected $mPropVals = array(); |
| 44 | + |
| 45 | + /** |
| 46 | + * Text keys and title objects. |
| 47 | + * |
| 48 | + * @var array |
| 49 | + */ |
| 50 | + protected $mProperties = array(); |
| 51 | + |
| 52 | + /** |
| 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. |
| 56 | + * |
| 57 | + * @var array |
| 58 | + */ |
| 59 | + protected $mStubPropVals = array(); |
| 60 | + |
| 61 | + /** |
| 62 | + * States whether the container holds any normal properties. |
| 63 | + * |
| 64 | + * @var boolean |
| 65 | + */ |
| 66 | + protected $mHasVisibleProps = false; |
| 67 | + |
| 68 | + /** |
| 69 | + * States whether the container holds any displayable special mProperties (some are internal only without a display name). |
| 70 | + * |
| 71 | + * @var boolean |
| 72 | + */ |
| 73 | + protected $mHasVisibleSpecs = false; |
| 74 | + |
| 75 | + /** |
| 76 | + * States whether repeated values should be avoided. Not needing duplicte elimination |
38 | 77 | * (e.g. when loading from store) can safe much time, since objects can remain stubs until someone |
39 | 78 | * really acesses their value. |
| 79 | + * |
| 80 | + * @var boolean |
40 | 81 | */ |
41 | | - protected $m_noduplicates; |
42 | | - /// Cache for the local version of "Property:" |
43 | | - static protected $m_propertyprefix = false; |
| 82 | + protected $mNoDuplicates; |
44 | 83 | |
45 | | - /// SMWWikiPageValue object that is the subject of this container. |
46 | | - /// Subjects that are NULL are used to represent "internal objects" only. |
47 | | - protected $subject; |
| 84 | + /** |
| 85 | + * SMWWikiPageValue object that is the subject of this container. |
| 86 | + * Subjects that are NULL are used to represent "internal objects" only. |
| 87 | + * |
| 88 | + * @var SMWWikiPageValue |
| 89 | + */ |
| 90 | + protected $mSubject; |
48 | 91 | |
49 | | - public function __construct( $subject, $noduplicates = true ) { |
50 | | - $this->subject = $subject; |
51 | | - $this->m_noduplicates = $noduplicates; |
52 | | - $this->stubobject = false; |
| 92 | + /** |
| 93 | + * Constructor. |
| 94 | + * |
| 95 | + * @param SMWWikiPageValue $subject |
| 96 | + * @param boolean $noDuplicates |
| 97 | + */ |
| 98 | + public function __construct( $subject, $noDuplicates = true ) { |
| 99 | + $this->mSubject = $subject; |
| 100 | + $this->mNoDuplicates = $noDuplicates; |
| 101 | + $this->stubObject = false; |
53 | 102 | } |
54 | 103 | |
55 | 104 | /** |
— | — | @@ -57,7 +106,10 @@ |
58 | 107 | * subject is serialised, yielding a minimal stub data container after unserialisation. This is a little safer than serialising |
59 | 108 | * nothing: if, for any reason, SMW should ever access an unserialised parser output, then the Semdata container will at least |
60 | 109 | * look as if properly initialised (though empty). |
| 110 | + * |
61 | 111 | * @note It might be even better to have other members with stub object data that is used for serializing, thus using much less data. |
| 112 | + * |
| 113 | + * @return array |
62 | 114 | */ |
63 | 115 | public function __sleep() { |
64 | 116 | return array( 'subject' ); |
— | — | @@ -65,10 +117,11 @@ |
66 | 118 | |
67 | 119 | /** |
68 | 120 | * Return subject to which the stored semantic annotation refer to. |
| 121 | + * |
69 | 122 | * @return SMWWikiPageValue subject |
70 | 123 | */ |
71 | 124 | public function getSubject() { |
72 | | - return $this->subject; |
| 125 | + return $this->mSubject; |
73 | 126 | } |
74 | 127 | |
75 | 128 | /** |
— | — | @@ -76,36 +129,39 @@ |
77 | 130 | */ |
78 | 131 | public function getProperties() { |
79 | 132 | $this->unstubProperties(); |
80 | | - ksort( $this->properties, SORT_STRING ); |
81 | | - return $this->properties; |
| 133 | + ksort( $this->mProperties, SORT_STRING ); |
| 134 | + |
| 135 | + return $this->mProperties; |
82 | 136 | } |
83 | 137 | |
84 | 138 | /** |
85 | 139 | * Get the array of all stored values for some property. |
86 | 140 | * |
87 | 141 | * @param SMWPropertyValue $property |
| 142 | + * |
| 143 | + * @return array |
88 | 144 | */ |
89 | 145 | public function getPropertyValues( SMWPropertyValue $property ) { |
90 | | - if ( array_key_exists( $property->getDBkey(), $this->stubpropvals ) ) { |
| 146 | + if ( array_key_exists( $property->getDBkey(), $this->mStubPropVals ) ) { |
91 | 147 | // Unstub those entries completely. |
92 | 148 | $this->unstubProperty( $property->getDBkey(), $property ); |
93 | 149 | |
94 | | - foreach ( $this->stubpropvals[$property->getDBkey()] as $dbkeys ) { |
| 150 | + foreach ( $this->mStubPropVals[$property->getDBkey()] as $dbkeys ) { |
95 | 151 | $dv = SMWDataValueFactory::newPropertyObjectValue( $property ); |
96 | 152 | $dv->setDBkeys( $dbkeys ); |
97 | 153 | |
98 | | - if ( $this->m_noduplicates ) { |
99 | | - $this->propvals[$property->getDBkey()][$dv->getHash()] = $dv; |
| 154 | + if ( $this->mNoDuplicates ) { |
| 155 | + $this->mPropVals[$property->getDBkey()][$dv->getHash()] = $dv; |
100 | 156 | } else { |
101 | | - $this->propvals[$property->getDBkey()][] = $dv; |
| 157 | + $this->mPropVals[$property->getDBkey()][] = $dv; |
102 | 158 | } |
103 | 159 | } |
104 | 160 | |
105 | | - unset( $this->stubpropvals[$property->getDBkey()] ); |
| 161 | + unset( $this->mStubPropVals[$property->getDBkey()] ); |
106 | 162 | } |
107 | 163 | |
108 | | - if ( array_key_exists( $property->getDBkey(), $this->propvals ) ) { |
109 | | - return $this->propvals[$property->getDBkey()]; |
| 164 | + if ( array_key_exists( $property->getDBkey(), $this->mPropVals ) ) { |
| 165 | + return $this->mPropVals[$property->getDBkey()]; |
110 | 166 | } else { |
111 | 167 | return array(); |
112 | 168 | } |
— | — | @@ -115,12 +171,14 @@ |
116 | 172 | * Generate a hash value to simplify the comparison of this data container with other |
117 | 173 | * containers. The hash uses PHP's md5 implementation, which is among the fastest hash |
118 | 174 | * algorithms that PHP offers. |
| 175 | + * |
| 176 | + * @return string |
119 | 177 | */ |
120 | 178 | public function getHash() { |
121 | 179 | $ctx = hash_init( 'md5' ); |
122 | 180 | |
123 | | - if ( $this->subject !== null ) { // here and below, use "_#_" to separate values; really not much care needed here |
124 | | - hash_update( $ctx, '_#_' . $this->subject->getHash() ); |
| 181 | + if ( $this->mSubject !== null ) { // here and below, use "_#_" to separate values; really not much care needed here |
| 182 | + hash_update( $ctx, '_#_' . $this->mSubject->getHash() ); |
125 | 183 | } |
126 | 184 | |
127 | 185 | foreach ( $this->getProperties() as $property ) { |
— | — | @@ -136,72 +194,85 @@ |
137 | 195 | |
138 | 196 | /** |
139 | 197 | * Return true if there are any visible properties. |
| 198 | + * |
140 | 199 | * @note While called "visible" this check actually refers to the function |
141 | 200 | * SMWPropertyValue::isShown(). The name is kept for compatibility. |
| 201 | + * |
| 202 | + * @return boolean |
142 | 203 | */ |
143 | 204 | public function hasVisibleProperties() { |
144 | 205 | $this->unstubProperties(); |
145 | | - return $this->hasvisibleprops; |
| 206 | + return $this->mHasVisibleProps; |
146 | 207 | } |
147 | 208 | |
148 | 209 | /** |
149 | 210 | * Return true if there are any special properties that can |
150 | 211 | * be displayed. |
| 212 | + * |
151 | 213 | * @note While called "visible" this check actually refers to the function |
152 | 214 | * SMWPropertyValue::isShown(). The name is kept for compatibility. |
| 215 | + * |
| 216 | + * @return boolean |
153 | 217 | */ |
154 | 218 | public function hasVisibleSpecialProperties() { |
155 | 219 | $this->unstubProperties(); |
156 | | - return $this->hasvisiblespecs; |
| 220 | + return $this->mHasVisibleSpecs; |
157 | 221 | } |
158 | 222 | |
159 | 223 | /** |
160 | 224 | * Store a value for a property identified by its title object. Duplicate |
161 | 225 | * value entries are usually ignored. |
| 226 | + * |
162 | 227 | * @note Attention: there is no check whether the type of the given datavalue agrees |
163 | 228 | * with what SMWDataValueFactory is producing (based on predefined property records and |
164 | 229 | * the current DB content). Always use SMWDataValueFactory to produce fitting values! |
| 230 | + * |
| 231 | + * @param SMWPropertyValue $property |
| 232 | + * @param SMWDataValue $value |
165 | 233 | */ |
166 | 234 | public function addPropertyObjectValue( SMWPropertyValue $property, SMWDataValue $value ) { |
167 | 235 | if ( !$property->isValid() ) return; // nothing we can do |
168 | 236 | |
169 | | - if ( !array_key_exists( $property->getDBkey(), $this->propvals ) ) { |
170 | | - $this->propvals[$property->getDBkey()] = array(); |
171 | | - $this->properties[$property->getDBkey()] = $property; |
| 237 | + if ( !array_key_exists( $property->getDBkey(), $this->mPropVals ) ) { |
| 238 | + $this->mPropVals[$property->getDBkey()] = array(); |
| 239 | + $this->mProperties[$property->getDBkey()] = $property; |
172 | 240 | } |
173 | 241 | |
174 | | - if ( $this->m_noduplicates ) { |
175 | | - $this->propvals[$property->getDBkey()][$value->getHash()] = $value; |
| 242 | + if ( $this->mNoDuplicates ) { |
| 243 | + $this->mPropVals[$property->getDBkey()][$value->getHash()] = $value; |
176 | 244 | } else { |
177 | | - $this->propvals[$property->getDBkey()][] = $value; |
| 245 | + $this->mPropVals[$property->getDBkey()][] = $value; |
178 | 246 | } |
179 | 247 | |
180 | 248 | if ( !$property->isUserDefined() ) { |
181 | 249 | if ( $property->isShown() ) { |
182 | | - $this->hasvisiblespecs = true; |
183 | | - $this->hasvisibleprops = true; |
| 250 | + $this->mHasVisibleSpecs = true; |
| 251 | + $this->mHasVisibleProps = true; |
184 | 252 | } |
185 | 253 | } else { |
186 | | - $this->hasvisibleprops = true; |
| 254 | + $this->mHasVisibleProps = true; |
187 | 255 | } |
188 | 256 | } |
189 | 257 | |
190 | 258 | /** |
191 | 259 | * Store a value for a given property identified by its text label (without |
192 | 260 | * namespace prefix). Duplicate value entries are usually ignored. |
| 261 | + * |
| 262 | + * @param string $propertyName |
| 263 | + * @param SMWDataValue $value |
193 | 264 | */ |
194 | | - public function addPropertyValue( $propertyname, SMWDataValue $value ) { |
195 | | - $propertykey = smwfNormalTitleDBKey( $propertyname ); |
| 265 | + public function addPropertyValue( $propertyName, SMWDataValue $value ) { |
| 266 | + $propertykey = smwfNormalTitleDBKey( $propertyName ); |
196 | 267 | |
197 | | - if ( array_key_exists( $propertykey, $this->properties ) ) { |
198 | | - $property = $this->properties[$propertykey]; |
| 268 | + if ( array_key_exists( $propertykey, $this->mProperties ) ) { |
| 269 | + $property = $this->mProperties[$propertykey]; |
199 | 270 | } else { |
200 | | - if ( SMWSemanticData::$m_propertyprefix == false ) { |
| 271 | + if ( self::$mPropertyPrefix == false ) { |
201 | 272 | global $wgContLang; |
202 | | - SMWSemanticData::$m_propertyprefix = $wgContLang->getNsText( SMW_NS_PROPERTY ) . ':'; |
| 273 | + self::$mPropertyPrefix = $wgContLang->getNsText( SMW_NS_PROPERTY ) . ':'; |
203 | 274 | } // explicitly use prefix to cope with things like [[Property:User:Stupid::somevalue]] |
204 | 275 | |
205 | | - $property = SMWPropertyValue::makeUserProperty( SMWSemanticData::$m_propertyprefix . $propertyname ); |
| 276 | + $property = SMWPropertyValue::makeUserProperty( self::$mPropertyPrefix . $propertyName ); |
206 | 277 | |
207 | 278 | if ( !$property->isValid() ) { // error, maybe illegal title text |
208 | 279 | return; |
— | — | @@ -216,33 +287,33 @@ |
217 | 288 | * is the DB key (string) of a property value, whereas valuekeys is an array of DBkeys for |
218 | 289 | * the added value that will be used to initialize the value if needed at some point. |
219 | 290 | */ |
220 | | - public function addPropertyStubValue( $propertykey, $valuekeys ) { |
221 | | - // Catch built-in properties, since their internal key is not what is used as a key elsewhere in SMWSemanticData. |
222 | | - if ( $propertykey { 0 } == '_' ) { |
223 | | - $property = SMWPropertyValue::makeProperty( $propertykey ); |
224 | | - $propertykey = $property->getDBkey(); |
225 | | - $this->unstubProperty( $propertykey, $property ); |
| 291 | + public function addPropertyStubValue( $propertyKey, $valueKeys ) { |
| 292 | + // Catch built-in mProperties, since their internal key is not what is used as a key elsewhere in SMWSemanticData. |
| 293 | + if ( $propertyKey { 0 } == '_' ) { |
| 294 | + $property = SMWPropertyValue::makeProperty( $propertyKey ); |
| 295 | + $propertyKey = $property->getDBkey(); |
| 296 | + $this->unstubProperty( $propertyKey, $property ); |
226 | 297 | } |
227 | 298 | |
228 | | - $this->stubpropvals[$propertykey][] = $valuekeys; |
| 299 | + $this->mStubPropVals[$propertyKey][] = $valueKeys; |
229 | 300 | } |
230 | 301 | |
231 | 302 | /** |
232 | 303 | * Delete all data other than the subject. |
233 | 304 | */ |
234 | 305 | public function clear() { |
235 | | - $this->propvals = array(); |
236 | | - $this->properties = array(); |
237 | | - $this->stubpropvals = array(); |
238 | | - $this->hasvisibleprops = false; |
239 | | - $this->hasvisiblespecs = false; |
| 306 | + $this->mPropVals = array(); |
| 307 | + $this->mProperties = array(); |
| 308 | + $this->mStubPropVals = array(); |
| 309 | + $this->mHasVisibleProps = false; |
| 310 | + $this->mHasVisibleSpecs = false; |
240 | 311 | } |
241 | 312 | |
242 | 313 | /** |
243 | | - * Process all properties that have been added as stubs. Associated data may remain in stub form. |
| 314 | + * Process all mProperties that have been added as stubs. Associated data may remain in stub form. |
244 | 315 | */ |
245 | 316 | protected function unstubProperties() { |
246 | | - foreach ( $this->stubpropvals as $pname => $values ) { // unstub property values only, the value lists are still kept as stubs |
| 317 | + foreach ( $this->mStubPropVals as $pname => $values ) { // unstub property values only, the value lists are still kept as stubs |
247 | 318 | $this->unstubProperty( $pname ); |
248 | 319 | } |
249 | 320 | } |
— | — | @@ -251,22 +322,25 @@ |
252 | 323 | * Unstub a single property from the stub data array. If available, an existing object |
253 | 324 | * for that property might be provided, so we do not need to make a new one. It is not |
254 | 325 | * checked if the object matches the property name. |
| 326 | + * |
| 327 | + * @param string $propertyName |
| 328 | + * @param $propertyObject |
255 | 329 | */ |
256 | | - protected function unstubProperty( $pname, $propertyobj = null ) { |
257 | | - if ( !array_key_exists( $pname, $this->properties ) ) { |
258 | | - if ( $propertyobj === null ) { |
259 | | - $propertyobj = SMWPropertyValue::makeProperty( $pname ); |
| 330 | + protected function unstubProperty( $propertyName, $propertyObject = null ) { |
| 331 | + if ( !array_key_exists( $propertyName, $this->mProperties ) ) { |
| 332 | + if ( $propertyObject === null ) { |
| 333 | + $propertyObject = SMWPropertyValue::makeProperty( $propertyName ); |
260 | 334 | } |
261 | 335 | |
262 | | - $this->properties[$pname] = $propertyobj; |
| 336 | + $this->mProperties[$propertyName] = $propertyObject; |
263 | 337 | |
264 | | - if ( !$propertyobj->isUserDefined() ) { |
265 | | - if ( $propertyobj->isShown() ) { |
266 | | - $this->hasvisiblespecs = true; |
267 | | - $this->hasvisibleprops = true; |
| 338 | + if ( !$propertyObject->isUserDefined() ) { |
| 339 | + if ( $propertyObject->isShown() ) { |
| 340 | + $this->mHasVisibleSpecs = true; |
| 341 | + $this->mHasVisibleProps = true; |
268 | 342 | } |
269 | 343 | } else { |
270 | | - $this->hasvisibleprops = true; |
| 344 | + $this->mHasVisibleProps = true; |
271 | 345 | } |
272 | 346 | } |
273 | 347 | } |