r113262 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113261‎ | r113262 | r113263 >
Date:18:24, 7 March 2012
Author:jeroendedauw
Status:ok
Tags:
Comment:
stylize a bit
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Property.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Property.php
@@ -33,11 +33,13 @@
3434 * @var array
3535 */
3636 static protected $m_prop_types;
 37+
3738 /**
3839 * Array with entries "property id" => "property label"
3940 * @var array
4041 */
4142 static protected $m_prop_labels;
 43+
4244 /**
4345 * Array with entries "property alias" => "property id"
4446 * @var array
@@ -50,11 +52,13 @@
5153 * @var string
5254 */
5355 protected $m_key;
 56+
5457 /**
5558 * Whether to take the inverse of this property or not.
5659 * @var boolean
5760 */
5861 protected $m_inverse;
 62+
5963 /**
6064 * Cache for property type ID.
6165 * @var string
@@ -75,14 +79,16 @@
7680 if ( ( $key === '' ) || ( $key{0} == '-' ) ) {
7781 throw new SMWDataItemException( "Illegal property key \"$key\"." );
7882 }
 83+
7984 if ( $key{0} == '_' ) {
8085 SMWDIProperty::initPropertyRegistration();
8186 if ( !array_key_exists( $key, SMWDIProperty::$m_prop_types ) ) {
8287 throw new SMWDataItemException( "There is no predefined property with \"$key\"." );
8388 }
8489 }
85 - $this->m_key = $key;
86 - $this->m_inverse = ( $inverse == true );
 90+
 91+ $this->m_key = $key;
 92+ $this->m_inverse = $inverse;
8793 }
8894
8995 public function getDIType() {
@@ -115,6 +121,8 @@
116122 * Examples of properties that are not shown include Modificaiton date
117123 * (not available in time), and Has improper value for (errors are
118124 * shown directly on the page anyway).
 125+ *
 126+ * @return boolean
119127 */
120128 public function isShown() {
121129 return ( ( $this->isUserDefined() ) ||
@@ -125,6 +133,7 @@
126134 /**
127135 * Return true if this is a usual wiki property that is defined by a
128136 * wiki page, and not a property that is pre-defined in the wiki.
 137+ *
129138 * @return boolean
130139 */
131140 public function isUserDefined() {
@@ -134,6 +143,7 @@
135144 /**
136145 * Find a user-readable label for this property, or return '' if it is
137146 * a predefined property that has no label.
 147+ *
138148 * @return string
139149 */
140150 public function getLabel() {
@@ -158,12 +168,16 @@
159169 * @return SMWDIWikiPage or null
160170 */
161171 public function getDiWikiPage() {
162 - if ( $this->m_inverse ) return null;
 172+ if ( $this->m_inverse ) {
 173+ return null;
 174+ }
 175+
163176 if ( $this->isUserDefined() ) {
164177 $dbkey = $this->m_key;
165178 } else {
166179 $dbkey = str_replace( ' ', '_', $this->getLabel() );
167180 }
 181+
168182 try {
169183 return new SMWDIWikiPage( $dbkey, SMW_NS_PROPERTY, '' );
170184 } catch ( SMWDataItemException $e ) {
@@ -181,12 +195,15 @@
182196 */
183197 public function findPropertyTypeID() {
184198 global $smwgPDefaultType;
 199+
185200 if ( !isset( $this->m_proptypeid ) ) {
186201 if ( $this->isUserDefined() ) { // normal property
187202 $diWikiPage = new SMWDIWikiPage( $this->getKey(), SMW_NS_PROPERTY, '' );
188203 $typearray = smwfGetStore()->getPropertyValues( $diWikiPage, new SMWDIProperty( '_TYPE' ) );
 204+
189205 if ( count( $typearray ) >= 1 ) { // some types given, pick one (hopefully unique)
190206 $typeDataItem = reset( $typearray );
 207+
191208 if ( $typeDataItem instanceof SMWDIUri ) {
192209 $this->m_proptypeid = $typeDataItem->getFragment();
193210 } else {
@@ -199,25 +216,31 @@
200217 $this->m_proptypeid = self::getPredefinedPropertyTypeId( $this->m_key );
201218 }
202219 }
 220+
203221 return $this->m_proptypeid;
204222 }
205223
206224
207225 public function getSerialization() {
208 - return ( $this->m_inverse ? '-' : '' ) . $this->m_key ;
 226+ return ( $this->m_inverse ? '-' : '' ) . $this->m_key;
209227 }
210228
211229 /**
212230 * Create a data item from the provided serialization string and type
213231 * ID.
 232+ *
 233+ * @param string $serialization
 234+ *
214235 * @return SMWDIProperty
215236 */
216237 public static function doUnserialize( $serialization ) {
217238 $inverse = false;
 239+
218240 if ( $serialization{0} == '-' ) {
219241 $serialization = substr( $serialization, 1 );
220242 $inverse = true;
221243 }
 244+
222245 return new SMWDIProperty( $serialization, $inverse );
223246 }
224247
@@ -233,10 +256,12 @@
234257 *
235258 * @param $label string label for the property
236259 * @param $inverse boolean states if the inverse of the property is constructed
 260+ *
237261 * @return SMWDIProperty object
238262 */
239263 public static function newFromUserLabel( $label, $inverse = false ) {
240264 $id = SMWDIProperty::findPropertyID( $label );
 265+
241266 if ( $id === false ) {
242267 return new SMWDIProperty( str_replace( ' ', '_', $label ), $inverse );
243268 } else {
@@ -251,13 +276,16 @@
252277 *
253278 * This function is protected. The public way of getting this data is
254279 * to simply create a new property object and to get its ID (if any).
 280+ *
255281 * @param $label string normalized property label
256282 * @param $useAlias boolean determining whether to check if the label is an alias
 283+ *
257284 * @return mixed string property ID or false
258285 */
259286 protected static function findPropertyID( $label, $useAlias = true ) {
260287 SMWDIProperty::initPropertyRegistration();
261288 $id = array_search( $label, SMWDIProperty::$m_prop_labels );
 289+
262290 if ( $id !== false ) {
263291 return $id;
264292 } elseif ( ( $useAlias ) && ( array_key_exists( $label, SMWDIProperty::$m_prop_aliases ) ) ) {
@@ -274,6 +302,7 @@
275303 * properties where isUserDefined() returns false.
276304 *
277305 * @param $key string key of the property
 306+ *
278307 * @return string type ID
279308 */
280309 public static function getPredefinedPropertyTypeId( $key ) {
@@ -288,6 +317,10 @@
289318 * Get the translated user label for a given internal property ID.
290319 * Returns false for properties without a translation (these are
291320 * usually internal, generated by SMW but not shown to the user).
 321+ *
 322+ * @param string $id
 323+ *
 324+ * @return string|false
292325 */
293326 static protected function findPropertyLabel( $id ) {
294327 SMWDIProperty::initPropertyRegistration();
@@ -363,6 +396,7 @@
364397 */
365398 static public function registerProperty( $id, $typeid, $label = false, $show = false ) {
366399 SMWDIProperty::$m_prop_types[$id] = array( $typeid, $show );
 400+
367401 if ( $label != false ) {
368402 SMWDIProperty::$m_prop_labels[$id] = $label;
369403 }
@@ -376,6 +410,7 @@
377411 *
378412 * @param $id string id of a property
379413 * @param $label string alias label for the property
 414+ *
380415 * @note Always use registerProperty() for the first label. No property
381416 * that has used "false" for a label on registration should have an
382417 * alias.

Status & tagging log