r106572 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106571‎ | r106572 | r106573 >
Date:17:53, 18 December 2011
Author:kipcool
Status:ok
Tags:
Comment:
formatting { }
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/Controller.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/HTMLtable.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWiki.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/RecordSetQueries.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/HTMLtable.php
@@ -5,10 +5,11 @@
66 require_once( "RecordSet.php" );
77
88 function parityClass( $value ) {
9 - if ( $value % 2 == 0 )
 9+ if ( $value % 2 == 0 ) {
1010 return "even";
11 - else
 11+ } else {
1212 return "odd";
 13+ }
1314 }
1415
1516 /* Functions to create a hierarchical table header
@@ -69,9 +70,9 @@
7071 $columnIndex . ') } ); </script>'
7172 . EOL;
7273 $leftmost = False; # There can be only one.
 74+ } else {
 75+ $leftsort = "";
7376 }
74 - else
75 - $leftsort = "";
7677
7778 $class = ' class="' . $type . ' sortable"' . $onclick;
7879 }
@@ -80,7 +81,7 @@
8182 $sort = '';
8283 $leftsort = '';
8384 }
84 -
 85+
8586 $rowSpan = $height - $childNode->height;
8687 $rows[$currentDepth] .= '<th id="' . $idPath->getId() . '-h" ' . $class .
8788 ' colspan="' . $childNode->width . '" rowspan="' . $rowSpan .
@@ -95,19 +96,20 @@
9697 $rootNode = getTableHeaderNode( $structure );
9798 $result = array();
9899
99 - for ( $i = 0; $i < $rootNode->height - 1; $i++ )
 100+ for ( $i = 0; $i < $rootNode->height - 1; $i++ ) {
100101 $result[$i] = "";
101 -
 102+ }
102103 addChildNodesToRows( $rootNode, $result, 0, $columnOffset, $idPath );
103104
104105 return $result;
105106 }
106107
107108 function getHTMLClassForType( $type, Attribute $attribute ) {
108 - if ( $type instanceof Structure )
 109+ if ( $type instanceof Structure ) {
109110 return $attribute->id;
110 - else
 111+ } else {
111112 return $type;
 113+ }
112114 }
113115
114116 function getRecordAsTableCells( IdStack $idPath, Editor $editor, Structure $visibleStructure, Record $record, &$startColumn = 0 ) {
@@ -124,9 +126,9 @@
125127 $idPath->pushAttribute( $attribute );
126128 $attributeId = $idPath->getId();
127129
128 - if ( $childEditor instanceof RecordTableCellEditor )
 130+ if ( $childEditor instanceof RecordTableCellEditor ) {
129131 $result .= getRecordAsTableCells( $idPath, $childEditor, $visibleAttribute->type, $value, $startColumn );
130 - else {
 132+ } else {
131133 $displayValue = $childEditor->showsData( $value ) ? $childEditor->view( $idPath, $value ) : "";
132134 $result .= '<td class="' . getHTMLClassForType( $type, $attribute ) . ' column-' . parityClass( $startColumn ) . '">' . $displayValue . '</td>';
133135 $startColumn++;
@@ -134,10 +136,10 @@
135137
136138 $idPath->popAttribute();
137139 }
138 - else
 140+ else {
139141 $result .= '<td/>';
 142+ }
140143 }
141 -
142144 return $result;
143145 }
144146
@@ -154,14 +156,14 @@
155157 $value = $record->getAttributeValue( $attribute );
156158 $idPath->pushAttribute( $attribute );
157159
158 - if ( $childEditor instanceof RecordTableCellEditor )
 160+ if ( $childEditor instanceof RecordTableCellEditor ) {
159161 $result .= getRecordAsEditTableCells( $idPath, $childEditor, $visibleAttribute->type, $value, $startColumn );
160 - else {
161 - if ( $childEditor->showEditField( $idPath ) )
 162+ } else {
 163+ if ( $childEditor->showEditField( $idPath ) ) {
162164 $displayValue = $childEditor->edit( $idPath, $value );
163 - else
 165+ } else {
164166 $displayValue = "";
165 -
 167+ }
166168 $result .= '<td class="' . getHTMLClassForType( $type, $attribute ) . ' column-' . parityClass( $startColumn ) . '">' . $displayValue . '</td>';
167169
168170 $startColumn++;
@@ -169,10 +171,10 @@
170172
171173 $idPath->popAttribute();
172174 }
173 - else
 175+ else {
174176 $result .= "<td/>";
 177+ }
175178 }
176 -
177179 return $result;
178180 }
179181
Index: trunk/extensions/Wikidata/OmegaWiki/Controller.php
@@ -57,8 +57,9 @@
5858 $languageId = $record->language;
5959 $text = $record->text;
6060
61 - if ( $languageId != 0 && $text != "" )
 61+ if ( $languageId != 0 && $text != "" ) {
6262 addDefinedMeaningDefinition( $definedMeaningId, $languageId, $text );
 63+ }
6364 }
6465
6566 public function remove( $keyPath ) {
@@ -72,8 +73,9 @@
7374 $languageId = $keyPath->peek( 0 )->language;
7475 $text = $record->text;
7576
76 - if ( $text != "" )
 77+ if ( $text != "" ) {
7778 updateDefinedMeaningDefinition( $definedMeaningId, $languageId, $text );
 79+ }
7880 }
7981 }
8082
@@ -87,8 +89,9 @@
8890 public function update( $keyPath, $value ) {
8991 $definedMeaningId = $keyPath->peek( 0 )->definedMeaningId;
9092
91 - if ( $value != "" )
 93+ if ( $value != "" ) {
9294 updateOrAddDefinedMeaningDefinition( $definedMeaningId, $this->filterLanguageId, $value );
 95+ }
9396 }
9497 }
9598
@@ -134,8 +137,9 @@
135138 $languageId = $record->language;
136139 $text = $record->text;
137140
138 - if ( $languageId != 0 && $text != "" )
 141+ if ( $languageId != 0 && $text != "" ) {
139142 addTranslatedTextIfNotPresent( $definitionId, $languageId, $text );
 143+ }
140144 }
141145
142146 public function remove( $keyPath ) {
@@ -150,8 +154,9 @@
151155 $languageId = $keyPath->peek( 0 )->language;
152156 $text = $record->text;
153157
154 - if ( $text != "" )
 158+ if ( $text != "" ) {
155159 updateTranslatedText( $definitionId, $languageId, $text );
 160+ }
156161 }
157162 }
158163
@@ -165,8 +170,9 @@
166171 public function update( $keyPath, $value ) {
167172 $definitionId = $keyPath->peek( 0 )->definitionId;
168173
169 - if ( $value != "" )
 174+ if ( $value != "" ) {
170175 updateTranslatedText( $definitionId, $this->filterLanguageId, $value );
 176+ }
171177 }
172178 }
173179
@@ -218,8 +224,9 @@
219225 $attributeMeaningId = $record->classAttributeAttribute;
220226 $attributeType = $record->classAttributeType;
221227
222 - if ( ( $attributeLevelId != 0 ) && ( $attributeMeaningId != 0 ) )
 228+ if ( ( $attributeLevelId != 0 ) && ( $attributeMeaningId != 0 ) ) {
223229 addClassAttribute( $definedMeaningId, $attributeLevelId, $attributeMeaningId, $attributeType );
 230+ }
224231 }
225232
226233 public function remove( $keyPath ) {
@@ -233,8 +240,9 @@
234241 $definedMeaningId = $idPath->getKeyStack()->peek( 0 )->definedMeaningId;
235242 $classId = $record->class;
236243
237 - if ( $classId != 0 )
 244+ if ( $classId != 0 ) {
238245 addClassMembership( $definedMeaningId, $classId );
 246+ }
239247 }
240248
241249 public function remove( $keyPath ) {
@@ -248,8 +256,9 @@
249257 $collectionMeaningId = $record->collectionMeaning;
250258 $internalId = $record->sourceIdentifier;
251259
252 - if ( $collectionMeaningId != 0 )
 260+ if ( $collectionMeaningId != 0 ) {
253261 addDefinedMeaningToCollectionIfNotPresent( $definedMeaningId, $collectionMeaningId, $internalId );
 262+ }
254263 }
255264
256265 public function remove( $keyPath ) {
@@ -265,7 +274,7 @@
266275 $sourceId = $record->sourceIdentifier;
267276
268277 // if ($sourceId != "")
269 - updateDefinedMeaningInCollection( $definedMeaningId, $collectionId, $sourceId );
 278+ updateDefinedMeaningInCollection( $definedMeaningId, $collectionId, $sourceId );
270279 }
271280 }
272281
@@ -309,11 +318,12 @@
310319 }
311320
312321 public function add( IdStack $idPath, $record ) {
313 - if ( $this->filterLanguageId == 0 )
 322+ if ( $this->filterLanguageId == 0 ) {
314323 $expressionLanguageId = $record->expression->language;
315 - else
 324+ } else {
316325 $expressionLanguageId = $this->filterLanguageId;
317 -
 326+ }
 327+
318328 $expressionMeanings = $record->expressionMeanings->expressionExactMeanings;
319329
320330 if ( $expressionLanguageId != 0 && $expressionMeanings->getRecordCount() > 0 ) {
@@ -328,7 +338,7 @@
329339
330340 $text = $definitionRecord->text;
331341 $languageId = $definitionRecord->language;
332 -
 342+
333343 if ( $languageId != 0 && $text != "" ) {
334344 $expression = findOrCreateExpression( $this->spelling, $expressionLanguageId );
335345 createNewDefinedMeaning( $expression->id, $languageId, $text );
@@ -361,8 +371,9 @@
362372 $classAttributes = $idPath->getClassAttributes()->filterClassAttributesOnLevelAndType( $this->levelName, $annotationType );
363373 $classAttributes = $this->attributeIDFilter->filter( $classAttributes );
364374
365 - if ( count( $classAttributes ) == 1 )
 375+ if ( count( $classAttributes ) == 1 ) {
366376 $result = $classAttributes[0];
 377+ }
367378 }
368379
369380 return $result;
@@ -375,8 +386,9 @@
376387 $definedMeaningAttributeId = $this->determineAttributeId( $idPath, "DM", $record->relationType );
377388 $definedMeaningValue = $record->otherDefinedMeaning;
378389
379 - if ( $definedMeaningAttributeId != 0 && $definedMeaningValue != 0 )
 390+ if ( $definedMeaningAttributeId != 0 && $definedMeaningValue != 0 ) {
380391 addRelation( $objectId, $definedMeaningAttributeId, $definedMeaningValue );
 392+ }
381393 }
382394
383395 public function remove( $keyPath ) {
@@ -391,8 +403,9 @@
392404 $textAttributeId = $this->determineAttributeId( $idPath, "TEXT", $record->textAttribute );
393405 $text = $record->text;
394406
395 - if ( $textAttributeId != 0 && $text != '' )
 407+ if ( $textAttributeId != 0 && $text != '' ) {
396408 addTextAttributeValue( $objectId, $textAttributeId, $text );
 409+ }
397410 }
398411
399412 public function remove( $keyPath ) {
@@ -405,16 +418,17 @@
406419
407420 $text = $record->text;
408421
409 - if ( $text != "" )
 422+ if ( $text != "" ) {
410423 updateTextAttributeValue( $text, $textId );
 424+ }
411425 }
412426 }
413427
414428 class LinkAttributeValuesController extends ObjectAttributeValuesController {
415429 protected function validateURL( $url ) {
416 - if ( !strpos( $url, "://" ) )
 430+ if ( !strpos( $url, "://" ) ) {
417431 $url = "http://" . $url;
418 -
 432+ }
419433 return $url;
420434 }
421435
@@ -425,8 +439,9 @@
426440 $label = $linkValue->linkLabel;
427441 $url = $linkValue->linkURL;
428442
429 - if ( $linkAttributeId != 0 && $url != "" )
 443+ if ( $linkAttributeId != 0 && $url != "" ) {
430444 addLinkAttributeValue( $objectId, $linkAttributeId, $this->validateURL( $url ), $label );
 445+ }
431446 }
432447
433448 public function remove( $keyPath ) {
@@ -440,8 +455,9 @@
441456 $label = $linkValue->linkLabel;
442457 $url = $linkValue->linkURL;
443458
444 - if ( $url != "" )
 459+ if ( $url != "" ) {
445460 updateLinkAttributeValue( $linkId, $this->validateURL( $url ), $label );
 461+ }
446462 }
447463 }
448464
@@ -491,8 +507,9 @@
492508 $text = $record->text;
493509 $translatedTextAttribute = getTranslatedTextAttribute( $valueId );
494510
495 - if ( $languageId != 0 && $text != "" )
 511+ if ( $languageId != 0 && $text != "" ) {
496512 addTranslatedTextIfNotPresent( $translatedTextAttribute->value_tcid, $languageId, $text );
 513+ }
497514 }
498515
499516 public function remove( $keyPath ) {
@@ -509,8 +526,9 @@
510527 $text = $record->text;
511528 $translatedTextAttribute = getTranslatedTextAttribute( $valueId );
512529
513 - if ( $text != "" )
 530+ if ( $text != "" ) {
514531 updateTranslatedText( $translatedTextAttribute->value_tcid, $languageId, $text );
 532+ }
515533 }
516534 }
517535
@@ -525,8 +543,9 @@
526544 $valueId = $keyPath->peek( 0 )->translatedTextAttributeId;
527545 $translatedTextAttribute = getTranslatedTextAttribute( $valueId );
528546
529 - if ( $value != "" )
 547+ if ( $value != "" ) {
530548 updateTranslatedText( $translatedTextAttribute->value_tcid, $this->filterLanguageId, $value );
 549+ }
531550 }
532551 }
533552
@@ -535,8 +554,9 @@
536555 $objectId = $this->objectIdFetcher->fetch( $idPath->getKeyStack() );
537556 $optionId = $record->optionAttributeOption;
538557
539 - if ( $optionId )
 558+ if ( $optionId ) {
540559 addOptionAttributeValue( $objectId, $optionId );
 560+ }
541561 }
542562
543563 public function remove( $keyPath ) {
@@ -550,10 +570,12 @@
551571 $attributeId = $idPath->getKeyStack()->peek( 0 )->classAttributeId;
552572 $optionMeaningId = $record->optionAttributeOption;
553573 $languageId = $record->language;
554 - if ( $languageId == NULL ) $languageId = 0 ;
555 -
556 - if ( $optionMeaningId )
 574+ if ( $languageId == NULL ) {
 575+ $languageId = 0 ;
 576+ }
 577+ if ( $optionMeaningId ) {
557578 addOptionAttributeOption( $attributeId, $optionMeaningId, $languageId );
 579+ }
558580 }
559581
560582 public function remove( $keyPath ) {
@@ -581,5 +603,3 @@
582604 return $source == null || $source == 0;
583605 }
584606 }
585 -
586 -
Index: trunk/extensions/Wikidata/OmegaWiki/RecordSetQueries.php
@@ -1,6 +1,7 @@
22 <?php
33
44 require_once( 'Transaction.php' );
 5+require_once( 'WikiDataTables.php' );
56
67 class TableColumnsToAttribute {
78 protected $tableColumns;
@@ -24,28 +25,30 @@
2526 protected $tableColumnsToAttributes;
2627
2728 public function __construct( $tableColumnsToAttributes ) {
28 - if ( is_array( $tableColumnsToAttributes ) )
 29+ if ( is_array( $tableColumnsToAttributes ) ) {
2930 $this->tableColumnsToAttributes = $tableColumnsToAttributes;
30 - else
 31+ } else {
3132 $this->tableColumnsToAttributes = func_get_args();
 33+ }
3234 }
3335
3436 public function getSelectColumns() {
3537 $result = array();
3638
37 - foreach ( $this->tableColumnsToAttributes as $tableColumnToAttribute )
38 - foreach ( $tableColumnToAttribute->getTableColumns() as $tableColumn )
 39+ foreach ( $this->tableColumnsToAttributes as $tableColumnToAttribute ) {
 40+ foreach ( $tableColumnToAttribute->getTableColumns() as $tableColumn ) {
3941 $result[] = $tableColumn;
40 -
 42+ }
 43+ }
4144 return $result;
4245 }
4346
4447 public function getAttributes() {
4548 $result = array();
4649
47 - foreach ( $this->tableColumnsToAttributes as $tableColumnToAttribute )
 50+ foreach ( $this->tableColumnsToAttributes as $tableColumnToAttribute ) {
4851 $result[] = $tableColumnToAttribute->getAttribute();
49 -
 52+ }
5053 return $result;
5154 }
5255
@@ -68,25 +71,26 @@
6972 $groupBy = $transactionInformation->versioningGroupBy( $table );
7073 $selectFields = array_merge( $selectFields, $transactionInformation->versioningFields( $table->getIdentifier() ) );
7174 }
72 - else
 75+ else {
7376 $groupBy = array();
 77+ }
7478
7579 $query =
7680 "SELECT " . implode( ", ", $selectFields ) .
7781 " FROM " . implode( ", ", $tableNames );
7882
79 - if ( count( $restrictions ) > 0 )
 83+ if ( count( $restrictions ) > 0 ) {
8084 $query .= " WHERE " . implode( ' AND ', $restrictions );
81 -
82 - if ( count( $groupBy ) > 0 )
 85+ }
 86+ if ( count( $groupBy ) > 0 ) {
8387 $query .= " GROUP BY " . implode( ', ', $groupBy );
84 -
85 - if ( count( $orderBy ) > 0 )
 88+ }
 89+ if ( count( $orderBy ) > 0 ) {
8690 $query .= " ORDER BY " . implode( ', ', $orderBy );
87 -
88 - if ( $count != - 1 )
 91+ }
 92+ if ( $count != - 1 ) {
8993 $query .= " LIMIT " . $offset . ", " . $count;
90 -
 94+ }
9195 return $query;
9296 }
9397
@@ -107,18 +111,20 @@
108112 $selectFields = $tableColumnsToAttributeMapping->getSelectColumns();
109113 $attributes = $tableColumnsToAttributeMapping->getAttributes();
110114
111 - if ( $table->isVersioned )
 115+ if ( $table->isVersioned ) {
112116 $allAttributes = array_merge( $attributes, $transactionInformation->versioningAttributes() );
113 - else
 117+ } else {
114118 $allAttributes = $attributes;
 119+ }
115120
116121 $query = getTransactedSQL( $transactionInformation, $selectFields, $table, $restrictions, $orderBy, $count, $offset );
117122 $queryResult = $dbr->query( $query );
118123
119 - if ( !is_null( $recordSetStructureId ) )
 124+ if ( !is_null( $recordSetStructureId ) ) {
120125 $structure = new Structure( $recordSetStructureId, $allAttributes );
121 - else
 126+ } else {
122127 $structure = new Structure( $allAttributes );
 128+ }
123129
124130 $recordSet = new ArrayRecordSet( $structure, new Structure( $keyAttribute ) );
125131
@@ -131,10 +137,11 @@
132138 $attribute = $mapping->getAttribute();
133139 $tableColumns = $mapping->getTableColumns();
134140
135 - if ( count( $tableColumns ) == 1 )
 141+ if ( count( $tableColumns ) == 1 ) {
136142 $value = $row[$columnIndex];
137 - else
 143+ } else {
138144 $value = getRecordFromRow( $row, $columnIndex, $attribute->type );
 145+ }
139146
140147 $record->setAttributeValue( $attribute, $value );
141148 $columnIndex += count( $tableColumns );
@@ -153,8 +160,9 @@
154161 for ( $i = 0; $i < $recordSet->getRecordCount(); $i++ ) {
155162 $record = $recordSet->getRecord( $i );
156163
157 - foreach ( $idAttributes as $idAttribute )
 164+ foreach ( $idAttributes as $idAttribute ) {
158165 $ids[] = $record->getAttributeValue( $idAttribute );
 166+ }
159167 }
160168
161169 return array_unique( $ids );
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWiki.php
@@ -38,8 +38,7 @@
3939 }
4040
4141 public function history() {
42 - global
43 - $wgOut, $wgTitle;
 42+ global $wgOut, $wgTitle;
4443
4544 parent::history();
4645
@@ -57,8 +56,7 @@
5857 }
5958
6059 protected function save( $referenceQueryTransactionInformation ) {
61 - global
62 - $wgTitle;
 60+ global $wgTitle;
6361
6462 parent::save( $referenceQueryTransactionInformation );
6563
@@ -71,10 +69,11 @@
7270 }
7371
7472 public function edit() {
75 - global
76 - $wgOut, $wgTitle, $wgUser;
 73+ global $wgOut, $wgTitle, $wgUser;
7774
78 - if ( !parent::edit() ) return false;
 75+ if ( !parent::edit() ) {
 76+ return false;
 77+ }
7978 $this->outputEditHeader();
8079
8180 $spelling = $wgTitle->getText();
@@ -90,14 +89,13 @@
9190 }
9291
9392 public function getTitle() {
94 - global
95 - $wgTitle, $wgUseExpressionPageTitlePrefix;
 93+ global $wgTitle, $wgUseExpressionPageTitlePrefix;
9694
97 - if ( $wgUseExpressionPageTitlePrefix )
 95+ if ( $wgUseExpressionPageTitlePrefix ) {
9896 $title = wfMsg( 'ow_Multiple_meanings', $wgTitle->getText() );
99 - else
 97+ } else {
10098 $title = $wgTitle->getText();
101 -
 99+ }
102100 return $title;
103101 }
104102

Status & tagging log