r67054 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67053‎ | r67054 | r67055 >
Date:20:23, 29 May 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Code/doc/style improvements
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php
@@ -95,6 +95,8 @@
9696 * @param mixed $caption string or false
9797 * @param Parser $parser
9898 * @param boolean $storeAnnotation
 99+ *
 100+ * @return SMWDataValue
99101 */
100102 static public function addProperty( $propertyName, $value, $caption, Parser $parser, $storeAnnotation = true ) {
101103 wfProfileIn( "SMWParseData::addProperty (SMW)" );
@@ -111,7 +113,8 @@
112114 } elseif ( $storeAnnotation && ( self::getSMWData( $parser ) !== null ) ) {
113115 self::getSMWData( $parser )->addPropertyObjectValue( $property, $result );
114116
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() ) {
116119 self::getSMWData( $parser )->addPropertyObjectValue( SMWPropertyValue::makeProperty( '_ERRP' ), $property->getWikiPageValue() );
117120 }
118121 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php
@@ -331,11 +331,13 @@
332332 * | area = 396 km²
333333 * | sea = Adria
334334 * }}
 335+ *
335336 * This creates annotations with the properties as stated on the left side, and the
336337 * values on the right side.
337338 *
338 - * @param[in] &$parser Parser The current parser
339 - * @return nothing
 339+ * @param Parser &$parser The current parser
 340+ *
 341+ * @return empty string
340342 */
341343 static public function doSet( &$parser ) {
342344 $params = func_get_args();
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php
@@ -3,8 +3,10 @@
44 * The class in this file manages (special) properties that are
55 * associated with a certain subject (article). It is used as a
66 * container for chunks of subject-centred data.
 7+ *
78 * @file
89 * @ingroup SMW
 10+ *
911 * @author Markus Krötzsch
1012 */
1113
@@ -12,6 +14,7 @@
1315 * Class for representing chunks of semantic data for one given
1416 * article (subject), similar what is typically displayed in the factbox.
1517 * This is a light-weight data container.
 18+ *
1619 * @ingroup SMW
1720 */
1821 class SMWSemanticData {
@@ -79,21 +82,28 @@
8083
8184 /**
8285 * Get the array of all stored values for some property.
 86+ *
 87+ * @param SMWPropertyValue $property
8388 */
8489 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.
8692 $this->unstubProperty( $property->getDBkey(), $property );
 93+
8794 foreach ( $this->stubpropvals[$property->getDBkey()] as $dbkeys ) {
8895 $dv = SMWDataValueFactory::newPropertyObjectValue( $property );
8996 $dv->setDBkeys( $dbkeys );
 97+
9098 if ( $this->m_noduplicates ) {
9199 $this->propvals[$property->getDBkey()][$dv->getHash()] = $dv;
92100 } else {
93101 $this->propvals[$property->getDBkey()][] = $dv;
94102 }
95103 }
 104+
96105 unset( $this->stubpropvals[$property->getDBkey()] );
97106 }
 107+
98108 if ( array_key_exists( $property->getDBkey(), $this->propvals ) ) {
99109 return $this->propvals[$property->getDBkey()];
100110 } else {
@@ -108,15 +118,19 @@
109119 */
110120 public function getHash() {
111121 $ctx = hash_init( 'md5' );
 122+
112123 if ( $this->subject !== null ) { // here and below, use "_#_" to separate values; really not much care needed here
113124 hash_update( $ctx, '_#_' . $this->subject->getHash() );
114125 }
 126+
115127 foreach ( $this->getProperties() as $property ) {
116128 hash_update( $ctx, '_#_' . $property->getHash() . '##' );
 129+
117130 foreach ( $this->getPropertyValues( $property ) as $dv ) {
118131 hash_update( $ctx, '_#_' . $dv->getHash() );
119132 }
120133 }
 134+
121135 return hash_final( $ctx );
122136 }
123137
@@ -150,15 +164,18 @@
151165 */
152166 public function addPropertyObjectValue( SMWPropertyValue $property, SMWDataValue $value ) {
153167 if ( !$property->isValid() ) return; // nothing we can do
 168+
154169 if ( !array_key_exists( $property->getDBkey(), $this->propvals ) ) {
155170 $this->propvals[$property->getDBkey()] = array();
156171 $this->properties[$property->getDBkey()] = $property;
157172 }
 173+
158174 if ( $this->m_noduplicates ) {
159175 $this->propvals[$property->getDBkey()][$value->getHash()] = $value;
160176 } else {
161177 $this->propvals[$property->getDBkey()][] = $value;
162178 }
 179+
163180 if ( !$property->isUserDefined() ) {
164181 if ( $property->isShown() ) {
165182 $this->hasvisiblespecs = true;
@@ -175,6 +192,7 @@
176193 */
177194 public function addPropertyValue( $propertyname, SMWDataValue $value ) {
178195 $propertykey = smwfNormalTitleDBKey( $propertyname );
 196+
179197 if ( array_key_exists( $propertykey, $this->properties ) ) {
180198 $property = $this->properties[$propertykey];
181199 } else {
@@ -182,11 +200,14 @@
183201 global $wgContLang;
184202 SMWSemanticData::$m_propertyprefix = $wgContLang->getNsText( SMW_NS_PROPERTY ) . ':';
185203 } // explicitly use prefix to cope with things like [[Property:User:Stupid::somevalue]]
 204+
186205 $property = SMWPropertyValue::makeUserProperty( SMWSemanticData::$m_propertyprefix . $propertyname );
 206+
187207 if ( !$property->isValid() ) { // error, maybe illegal title text
188208 return;
189209 }
190210 }
 211+
191212 $this->addPropertyObjectValue( $property, $value );
192213 }
193214
@@ -196,12 +217,13 @@
197218 * the added value that will be used to initialize the value if needed at some point.
198219 */
199220 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.
201222 if ( $propertykey { 0 } == '_' ) {
202223 $property = SMWPropertyValue::makeProperty( $propertykey );
203224 $propertykey = $property->getDBkey();
204225 $this->unstubProperty( $propertykey, $property );
205226 }
 227+
206228 $this->stubpropvals[$propertykey][] = $valuekeys;
207229 }
208230
@@ -235,7 +257,9 @@
236258 if ( $propertyobj === null ) {
237259 $propertyobj = SMWPropertyValue::makeProperty( $pname );
238260 }
 261+
239262 $this->properties[$pname] = $propertyobj;
 263+
240264 if ( !$propertyobj->isUserDefined() ) {
241265 if ( $propertyobj->isShown() ) {
242266 $this->hasvisiblespecs = true;
@@ -247,5 +271,4 @@
248272 }
249273 }
250274
251 -}
252 -
 275+}
\ No newline at end of file

Status & tagging log