r56442 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56441‎ | r56442 | r56443 >
Date:21:02, 16 September 2009
Author:mkroetzsch
Status:deferred
Tags:
Comment:
some code cleanup
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_String.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
@@ -88,11 +88,7 @@
8989 $this->m_hasssearchlink = false;
9090 $this->m_hasservicelinks = false;
9191 $this->m_stubvalues = false;
92 - if ( is_string($caption) ) {
93 - $this->m_caption = trim($caption);
94 - } else {
95 - $this->m_caption = false;
96 - }
 92+ $this->m_caption = is_string($caption)?trim($caption):false;
9793 // The following checks for markers generated by MediaWiki to handle special content,
9894 // e.g. math. In general, we are not prepared to handle such content properly, and we
9995 // also have no means of obtaining the user input at this point. Hence the assignement
@@ -458,12 +454,7 @@
459455 * normalised first)
460456 */
461457 public function getHash() {
462 - $this->unstub();
463 - if ($this->isValid()) {
464 - return implode("\t", $this->getDBkeys());
465 - } else {
466 - return implode("\t", $this->m_errors);
467 - }
 458+ return $this->isValid()?implode("\t", $this->getDBkeys()):implode("\t", $this->m_errors);
468459 }
469460
470461 /**
@@ -509,7 +500,6 @@
510501 * If the value is empty or invalid, NULL is returned.
511502 */
512503 public function getExportData() { // default implementation: encode values as untyped string
513 - $this->unstub();
514504 if ($this->isValid()) {
515505 $lit = new SMWExpLiteral(smwfHTMLtoUTF8(implode(';',$this->getDBkeys())), $this);
516506 return new SMWExpData($lit);
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_String.php
@@ -21,7 +21,7 @@
2222 wfLoadExtensionMessages('SemanticMediaWiki');
2323 if ($value!='') {
2424 $this->m_value = $value;
25 - if ( (strlen($this->m_value) > 255) && ($this->m_typeid != '_txt') && ($this->m_typeid != '_cod') ) { // limit size (for DB indexing)
 25+ if ( ($this->m_typeid != '_txt') && ($this->m_typeid != '_cod') && (strlen($this->m_value) > 255) ) { // limit size (for DB indexing)
2626 $this->addError(wfMsgForContent('smw_maxstring', mb_substr($value, 0, 42) . ' <span class="smwwarning">[&hellip;]</span> ' . mb_substr($value, mb_strlen($this->m_value) - 42)));
2727 }
2828 } else {
@@ -52,22 +52,14 @@
5353 }
5454
5555 public function getLongWikiText($linked = NULL) {
56 - if (!$this->isValid()) {
57 - return $this->getErrorText();
58 - } else {
59 - return $this->getAbbValue($linked,$this->m_value);
60 - }
 56+ return $this->isValid()?$this->getAbbValue($linked,$this->m_value):$this->getErrorText();
6157 }
6258
6359 /**
6460 * @todo Rather parse input to obtain properly formatted HTML.
6561 */
6662 public function getLongHTMLText($linker = NULL) {
67 - if (!$this->isValid()) {
68 - return $this->getErrorText();
69 - } else {
70 - return $this->getAbbValue($linker,smwfXMLContentEncode($this->m_value));
71 - }
 63+ return $this->isValid()?$this->getAbbValue($linker,smwfXMLContentEncode($this->m_value)):$this->getErrorText();
7264 }
7365
7466 public function getDBkeys() {
@@ -84,8 +76,9 @@
8577 $this->unstub();
8678 if ( ($this->m_typeid != '_txt') && ($this->m_typeid != '_cod') ) {
8779 return SMWDataValue::getInfolinks();
 80+ } else {
 81+ return $this->m_infolinks;
8882 }
89 - return $this->m_infolinks;
9083 }
9184
9285 protected function getServiceLinkParams() {
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php
@@ -139,12 +139,10 @@
140140 if ( ($linker !== NULL) && ($this->m_caption !== '') && ($this->m_outformat != '-') ) { $this->getTitle(); } // init the Title object, may reveal hitherto unnoticed errors
141141 if ( ($linker === NULL) || (!$this->isValid()) || ($this->m_outformat == '-') || ($this->m_caption === '') ) {
142142 return htmlspecialchars($this->getCaption());
 143+ } elseif ($this->getNamespace() == NS_MEDIA) { /// NOTE: this extra case is indeed needed
 144+ return $linker->makeMediaLinkObj($this->getTitle(), $this->getCaption());
143145 } else {
144 - if ($this->getNamespace() == NS_MEDIA) { /// NOTE: this extra case is indeed needed
145 - return $linker->makeMediaLinkObj($this->getTitle(), $this->getCaption());
146 - } else {
147 - return $linker->makeLinkObj($this->getTitle(), $this->getCaption());
148 - }
 146+ return $linker->makeLinkObj($this->getTitle(), $this->getCaption());
149147 }
150148 }
151149
@@ -175,12 +173,10 @@
176174 }
177175 if ( ($linker === NULL) || ($this->m_outformat == '-') ) {
178176 return htmlspecialchars($this->getPrefixedText());
179 - } else {
180 - if ($this->getNamespace() == NS_MEDIA) { // this extra case is really needed
181 - return $linker->makeMediaLinkObj($this->getTitle(), $this->m_textform);
182 - } else { // all others use default linking, no embedding of images here
183 - return $linker->makeLinkObj($this->getTitle(), $this->m_textform);
184 - }
 177+ } elseif ($this->getNamespace() == NS_MEDIA) { // this extra case is really needed
 178+ return $linker->makeMediaLinkObj($this->getTitle(), $this->m_textform);
 179+ } else { // all others use default linking, no embedding of images here
 180+ return $linker->makeLinkObj($this->getTitle(), $this->m_textform);
185181 }
186182 }
187183
@@ -202,12 +198,7 @@
203199 }
204200
205201 public function getHash() {
206 - $this->unstub();
207 - if ($this->isValid()) {
208 - return $this->getPrefixedText();
209 - } else {
210 - return implode("\t", $this->getErrors());
211 - }
 202+ return $this->isValid()?$this->getPrefixedText():implode("\t", $this->getErrors());
212203 }
213204
214205 protected function getServiceLinkParams() {
@@ -219,7 +210,6 @@
220211 }
221212
222213 public function getExportData() {
223 - $this->unstub();
224214 if (!$this->isValid()) return NULL;
225215 switch ($this->getNamespace()) {
226216 case NS_MEDIA: // special handling for linking media files directly
@@ -247,14 +237,13 @@
248238
249239 /**
250240 * Return according Title object or NULL if no valid value was set.
251 - * NULL can be returned even if this object returns TRUE for isValue(),
 241+ * NULL can be returned even if this object returns TRUE for isValid(),
252242 * since the latter function does not check whether MediaWiki can really
253243 * make a Title out of the given data.
254244 * However, isValid() will return FALSE *after* this function failed in
255245 * trying to create a title.
256246 */
257247 public function getTitle() {
258 - $this->unstub();
259248 if ( ($this->isValid()) && ($this->m_title === NULL) ) {
260249 if ($this->m_interwiki == '') {
261250 $this->m_title = Title::makeTitle($this->m_namespace, $this->m_dbkeyform);
@@ -276,11 +265,7 @@
277266 public function getArticleID() {
278267 $this->unstub();
279268 if ($this->m_id === false) {
280 - if ($this->getTitle() !== NULL) {
281 - $this->m_id = $this->m_title->getArticleID();
282 - } else {
283 - $this->m_id = 0;
284 - }
 269+ $this->m_id = ($this->getTitle() !== NULL)?$this->m_title->getArticleID():0;
285270 }
286271 return $this->m_id;
287272 }
@@ -290,11 +275,7 @@
291276 * return FALSE.
292277 */
293278 public function getNamespace() {
294 - $this->unstub();
295 - if (!$this->isValid()) {
296 - return false;
297 - }
298 - return $this->m_namespace;
 279+ return $this->isValid()?$this->m_namespace:false;
299280 }
300281
301282 /**
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php
@@ -245,11 +245,8 @@
246246 */
247247 public function getTypeLabels() {
248248 $this->initTypeData();
249 - if ($this->m_typelabels === false) {
250 - return array(); // fallback for unary callers
251 - } else {
252 - return $this->m_typelabels;
253 - }
 249+ // fallback to array() for unary callers
 250+ return ($this->m_typelabels === false)?array():$this->m_typelabels;
254251 }
255252
256253 /**
@@ -258,11 +255,8 @@
259256 */
260257 public function getTypeCaptions() {
261258 $this->initTypeData();
262 - if ($this->m_typecaptions === false) {
263 - return array(); // fallback for unary callers
264 - } else {
265 - return $this->m_typecaptions;
266 - }
 259+ // fallback to array() for unary callers
 260+ return ($this->m_typecaptions === false)?array():$this->m_typecaptions;
267261 }
268262
269263 /**

Status & tagging log