Index: trunk/extensions/Wikidata/WiktionaryZ/WiktionaryZ.php |
— | — | @@ -50,6 +50,11 @@ |
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
| 54 | +function removeRelation($definedMeaning1Id, $relationTypeId, $definedMeaning2Id) { |
| 55 | + $dbr =& wfGetDB(DB_MASTER); |
| 56 | + $dbr->query("delete from uw_meaning_relations where meaning1_mid=$definedMeaning1Id and meaning2_mid=$definedMeaning2Id and ". |
| 57 | + "relationtype_mid=$relationTypeId AND is_latest_set=1 LIMIT 1"); |
| 58 | +} |
54 | 59 | |
55 | 60 | class SynonymTranslationController implements PageElementController { |
56 | 61 | protected $definedMeaningId; |
— | — | @@ -68,6 +73,10 @@ |
69 | 74 | $expression->assureIsBoundToDefinedMeaning($this->definedMeaningId, $endemicMeaning); |
70 | 75 | } |
71 | 76 | } |
| 77 | + |
| 78 | + public function remove($tuple) { |
| 79 | + |
| 80 | + } |
72 | 81 | } |
73 | 82 | |
74 | 83 | class DefinedMeaningRelationController implements PageElementController { |
— | — | @@ -84,6 +93,10 @@ |
85 | 94 | if ($relationTypeId != 0 && $otherDefinedMeaningId != 0) |
86 | 95 | addRelation($this->definedMeaningId, $relationTypeId, $otherDefinedMeaningId); |
87 | 96 | } |
| 97 | + |
| 98 | + public function remove($tuple) { |
| 99 | + removeRelation($this->definedMeaningId, $tuple['relation-type'], $tuple['other-defined-meaning']); |
| 100 | + } |
88 | 101 | } |
89 | 102 | |
90 | 103 | class DefinedMeaningAttributeController implements PageElementController { |
— | — | @@ -99,6 +112,10 @@ |
100 | 113 | if ($attributeId != 0) |
101 | 114 | addRelation($this->definedMeaningId, 0, $attributeId); |
102 | 115 | } |
| 116 | + |
| 117 | + public function remove($tuple) { |
| 118 | + removeRelation($this->definedMeaningId, 0, $tuple['attribute']); |
| 119 | + } |
103 | 120 | } |
104 | 121 | |
105 | 122 | /** |
— | — | @@ -168,17 +185,18 @@ |
169 | 186 | function editPageElement($pageElement) { |
170 | 187 | $inputRow = array(); |
171 | 188 | $addId = "add-".$pageElement->getId(); |
| 189 | + $removeId = "remove-".$pageElement->getId()."-"; |
172 | 190 | |
173 | | - foreach($pageElement->getRelationModel()->getAttributes() as $attribute) |
| 191 | + foreach($pageElement->getRelationModel()->getHeading()->attributes as $attribute) |
174 | 192 | $inputRow[] = getInputFieldForType($addId . "-" . $attribute->id, $attribute->type, ""); |
175 | 193 | |
176 | | - addWikiDataBlock($pageElement->getCaption(), getRelationAsEditHTML($pageElement->getRelationModel(), $addId, |
177 | | - $inputRow, $pageElement->repeatInput())); |
| 194 | + addWikiDataBlock($pageElement->getCaption(), getRelationAsEditHTML($pageElement->getRelationModel(), $addId, $removeId, |
| 195 | + $inputRow, $pageElement->repeatInput(), $pageElement->allowRemove())); |
178 | 196 | } |
179 | 197 | |
180 | 198 | function addRowForPageElement($pageElement, $postFix) { |
181 | 199 | $addId = "add-".$pageElement->getId(); |
182 | | - $attributes = $pageElement->getRelationModel()->getAttributes(); |
| 200 | + $attributes = $pageElement->getRelationModel()->getHeading()->attributes; |
183 | 201 | |
184 | 202 | if (array_key_exists($addId . "-" . $attributes[0]->id . $postFix, $_POST)) { |
185 | 203 | $values = array(); |
— | — | @@ -194,7 +212,9 @@ |
195 | 213 | global |
196 | 214 | $wgRequest; |
197 | 215 | |
198 | | - if ($pageElement->getController()) { |
| 216 | + $controller = $pageElement->getController(); |
| 217 | + |
| 218 | + if ($controller) { |
199 | 219 | $addId = "add-" . $pageElement->getId(); |
200 | 220 | $inputRow = array(); |
201 | 221 | $rowCount = $wgRequest->getInt($addId . '-RC'); |
— | — | @@ -203,6 +223,17 @@ |
204 | 224 | |
205 | 225 | for ($i = 2; $i <= $rowCount; $i++) |
206 | 226 | $this->addRowForPageElement($pageElement, '-' . $i); |
| 227 | + |
| 228 | + $removeId = "remove-".$pageElement->getId()."-"; |
| 229 | + $relationModel = $pageElement->getRelationModel(); |
| 230 | + $key = $relationModel->getKey(); |
| 231 | + |
| 232 | + for ($i = 0; $i < $relationModel->getTupleCount(); $i++) { |
| 233 | + $tuple = $relationModel->getTuple($i); |
| 234 | + |
| 235 | + if ($wgRequest->getCheck(removeCheckBoxName($tuple, $key, $removeId))) |
| 236 | + $controller->remove($tuple); |
| 237 | + } |
207 | 238 | } |
208 | 239 | } |
209 | 240 | |
— | — | @@ -217,7 +248,7 @@ |
218 | 249 | function getDefinedMeaningRelationsPageElement($definedMeaningId) { |
219 | 250 | return new DefaultPageElement("defined-meaning-relation-$definedMeaningId", "Relations", |
220 | 251 | $this->getDefinedMeaningRelationsRelation($definedMeaningId), |
221 | | - false, |
| 252 | + true, |
222 | 253 | false, |
223 | 254 | new DefinedMeaningRelationController($definedMeaningId)); |
224 | 255 | } |
— | — | @@ -225,7 +256,7 @@ |
226 | 257 | function getDefinedMeaningAttributesPageElement($definedMeaningId) { |
227 | 258 | return new DefaultPageElement("defined-meaning-attribute-$definedMeaningId", "Attributes", |
228 | 259 | $this->getDefinedMeaningAttributesRelation($definedMeaningId), |
229 | | - false, |
| 260 | + true, |
230 | 261 | false, |
231 | 262 | new DefinedMeaningAttributeController($definedMeaningId)); |
232 | 263 | } |
— | — | @@ -524,9 +555,11 @@ |
525 | 556 | |
526 | 557 | function getSynonymAndTranslationRelation($definedMeaningId, $skippedExpressionId) { |
527 | 558 | $dbr =& wfGetDB(DB_SLAVE); |
528 | | - $attributes = array(new Attribute("language", "Language", "language"), new Attribute("spelling", "Spelling", "spelling"), new Attribute("endemic_meaning", "Identical meaning?", "boolean")); |
529 | | - $relation = new ArrayRelation($attributes); |
530 | | - $queryResult = $dbr->query("SELECT expression_id, endemic_meaning from uw_syntrans where defined_meaning_id=$definedMeaningId and expression_id!=$skippedExpressionId"); |
| 559 | + $heading = new Heading(array(new Attribute("language", "Language", "language"), |
| 560 | + new Attribute("spelling", "Spelling", "spelling"), |
| 561 | + new Attribute("endemic_meaning", "Identical meaning?", "boolean"))); |
| 562 | + $relation = new ArrayRelation($heading, $heading); |
| 563 | + $queryResult = $dbr->query("SELECT expression_id, endemic_meaning FROM uw_syntrans WHERE defined_meaning_id=$definedMeaningId AND expression_id!=$skippedExpressionId"); |
531 | 564 | |
532 | 565 | while($synonymOrTranslation = $dbr->fetchObject($queryResult)) { |
533 | 566 | $spellingAndLanguage = $this->getSpellingAndLanguageForExpression($synonymOrTranslation->expression_id); |
— | — | @@ -539,28 +572,27 @@ |
540 | 573 | } |
541 | 574 | |
542 | 575 | function getDefinedMeaningRelationsRelation($definedMeaningId) { |
543 | | - $attributes = array(new Attribute("relation-type", "Relation type", "relation-type"), new Attribute("other-defined_meaning", "Other defined meaning", "defined-meaning")); |
544 | | - $relation = new ArrayRelation($attributes); |
| 576 | + $heading = new Heading(array(new Attribute("relation-type", "Relation type", "relation-type"), new Attribute("other-defined-meaning", "Other defined meaning", "defining-expression"))); |
| 577 | + $relation = new ArrayRelation($heading, $heading); |
545 | 578 | |
546 | 579 | $dbr =& wfGetDB(DB_SLAVE); |
547 | 580 | $queryResult = $dbr->query("SELECT relationtype_mid, meaning2_mid from uw_meaning_relations where meaning1_mid=$definedMeaningId and relationtype_mid!=0 and is_latest_set=1 ORDER BY relationtype_mid"); |
548 | 581 | |
549 | 582 | while($definedMeaningRelation = $dbr->fetchObject($queryResult)) |
550 | | - $relation->addTuple(array($this->getExpressionForMeaningId($definedMeaningRelation->relationtype_mid, 85), |
551 | | - $this->getDefiningExpressionForDefinedMeaningId($definedMeaningRelation->meaning2_mid))); |
| 583 | + $relation->addTuple(array($definedMeaningRelation->relationtype_mid, $definedMeaningRelation->meaning2_mid)); |
552 | 584 | |
553 | 585 | return $relation; |
554 | 586 | } |
555 | 587 | |
556 | 588 | function getDefinedMeaningAttributesRelation($definedMeaningId) { |
557 | | - $attributes = array(new Attribute("attribute", "Attribute", "attribute")); |
558 | | - $relation = new ArrayRelation($attributes); |
| 589 | + $heading = new Heading(array(new Attribute("attribute", "Attribute", "attribute"))); |
| 590 | + $relation = new ArrayRelation($heading, $heading); |
559 | 591 | |
560 | 592 | $dbr =& wfGetDB(DB_SLAVE); |
561 | 593 | $queryResult = $dbr->query("SELECT relationtype_mid, meaning2_mid from uw_meaning_relations where meaning1_mid=$definedMeaningId and relationtype_mid=0 and is_latest_set=1"); |
562 | 594 | |
563 | 595 | while($attribute = $dbr->fetchObject($queryResult)) |
564 | | - $relation->addTuple(array($this->getExpressionForMeaningId($attribute->meaning2_mid, 85))); |
| 596 | + $relation->addTuple(array($attribute->meaning2_mid)); |
565 | 597 | |
566 | 598 | return $relation; |
567 | 599 | } |
Index: trunk/extensions/Wikidata/WiktionaryZ/tmp/tables.css |
— | — | @@ -18,28 +18,39 @@ |
19 | 19 | |
20 | 20 | /* Wikidata tables */ |
21 | 21 | |
22 | | -.wiki-data-table td, .wiki-data-table th { |
23 | | - padding-top: 0px; |
24 | | - padding-bottom: 0px; |
25 | | - padding-left: 2px; |
26 | | - padding-right: 2px; |
27 | | - margin: 0px; |
28 | | - border: none; |
29 | | -} |
30 | | - |
31 | | -.wiki-data-table th { |
32 | | - background-color: #EEEEEE; |
33 | | - text-align: left; |
34 | | -} |
35 | | - |
36 | | -.wiki-data-table td.column-odd { |
37 | | - background-color: #F6F6F6; |
38 | | -} |
39 | | - |
40 | | -.boolean { |
41 | | - text-align: center; |
42 | | -} |
43 | | - |
44 | | -td.language { |
45 | | - font-style: italic; |
| 22 | +.wiki-data-table td, .wiki-data-table th {
|
| 23 | + padding-top: 0px;
|
| 24 | + padding-bottom: 0px;
|
| 25 | + padding-left: 2px;
|
| 26 | + padding-right: 2px;
|
| 27 | + margin: 0px;
|
| 28 | + border: none;
|
| 29 | +}
|
| 30 | +
|
| 31 | +.wiki-data-table th {
|
| 32 | + background-color: #EEEEEE;
|
| 33 | + text-align: left;
|
| 34 | +}
|
| 35 | +
|
| 36 | +.wiki-data-table td.column-odd {
|
| 37 | + background-color: #F6F6F6;
|
| 38 | +}
|
| 39 | +
|
| 40 | +.boolean {
|
| 41 | + text-align: center;
|
| 42 | +}
|
| 43 | +
|
| 44 | +td.language {
|
| 45 | + font-style: italic;
|
| 46 | +}
|
| 47 | +
|
| 48 | +.wiki-data-table td.remove {
|
| 49 | + text-align: center;
|
| 50 | + background-color: #EEEEEE;
|
| 51 | +}
|
| 52 | +
|
| 53 | +.wiki-data-table th.remove, .wiki-data-table th.add {
|
| 54 | + font-weight: normal;
|
| 55 | + padding-left: 4px;
|
| 56 | + padding-right: 4px;
|
46 | 57 | } |
\ No newline at end of file |
Index: trunk/extensions/Wikidata/WiktionaryZ/relation.php |
— | — | @@ -1,5 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
| 4 | +require_once('forms.php'); |
| 5 | + |
4 | 6 | class Attribute { |
5 | 7 | public $id = ""; |
6 | 8 | public $name = ""; |
— | — | @@ -12,34 +14,54 @@ |
13 | 15 | } |
14 | 16 | } |
15 | 17 | |
| 18 | +class Heading { |
| 19 | + public $attributes; |
| 20 | + |
| 21 | + public function __construct($attributes) { |
| 22 | + $this->attributes = $attributes; |
| 23 | + } |
| 24 | +} |
| 25 | + |
16 | 26 | interface RelationModel { |
17 | | - public function getAttributes(); |
| 27 | + public function getHeading(); |
| 28 | + public function getKey(); |
18 | 29 | public function getTupleCount(); |
19 | 30 | public function getTuple($tuple); |
20 | 31 | } |
21 | 32 | |
22 | 33 | class ArrayRelation implements RelationModel { |
23 | | - protected $attributes = array(); |
24 | | - protected $cells = array(); |
| 34 | + protected $heading; |
| 35 | + protected $key; |
| 36 | + protected $tuples = array(); |
25 | 37 | |
26 | | - public function __construct($attributes) { |
27 | | - $this->attributes = $attributes; |
| 38 | + public function __construct($heading, $key) { |
| 39 | + $this->heading = $heading; |
| 40 | + $this->key = $key; |
28 | 41 | } |
29 | 42 | |
30 | | - public function addTuple($tuple) { |
31 | | - $this->cells[] = $tuple; |
| 43 | + public function addTuple($values) { |
| 44 | + $tuple = array(); |
| 45 | + |
| 46 | + for ($i = 0; $i < count($this->heading->attributes); $i++) |
| 47 | + $tuple[$this->heading->attributes[$i]->id] = $values[$i]; |
| 48 | + |
| 49 | + $this->tuples[] = $tuple; |
32 | 50 | } |
33 | 51 | |
34 | | - public function getAttributes() { |
35 | | - return $this->attributes; |
| 52 | + public function getHeading() { |
| 53 | + return $this->heading; |
36 | 54 | } |
37 | 55 | |
| 56 | + public function getKey() { |
| 57 | + return $this->key; |
| 58 | + } |
| 59 | + |
38 | 60 | public function getTupleCount() { |
39 | | - return count($this->cells); |
| 61 | + return count($this->tuples); |
40 | 62 | } |
41 | 63 | |
42 | 64 | public function getTuple($tuple) { |
43 | | - return $this->cells[$tuple]; |
| 65 | + return $this->tuples[$tuple]; |
44 | 66 | } |
45 | 67 | } |
46 | 68 | |
— | — | @@ -53,7 +75,8 @@ |
54 | 76 | for ($i = 0; $i < $fieldCount; $i++) |
55 | 77 | $attributes[] = new Attribute($dbr->fieldName($queryResult, $i), "Text"); |
56 | 78 | |
57 | | - $result = new ArrayRelation($attributes); |
| 79 | + $heading = new Heading($attributes); |
| 80 | + $result = new ArrayRelation($heading); |
58 | 81 | |
59 | 82 | while ($row = $dbr->fetchRow($queryResult)) { |
60 | 83 | $tuple = array(); |
— | — | @@ -101,7 +124,7 @@ |
102 | 125 | |
103 | 126 | function getRelationAsHTML($relationModel) { |
104 | 127 | $result = '<table class="wiki-data-table"><tr>'; |
105 | | - $attributes = $relationModel->getAttributes(); |
| 128 | + $attributes = $relationModel->getHeading()->attributes; |
106 | 129 | |
107 | 130 | foreach($attributes as $attribute) |
108 | 131 | $result .= '<th class="'. $attribute->type .'">' . $attribute->name . '</th>'; |
— | — | @@ -116,43 +139,66 @@ |
117 | 140 | return $result; |
118 | 141 | } |
119 | 142 | |
120 | | -function getInputRowAsHTML($rowId, $attributes, $values, $repeatInput) { |
| 143 | +function getInputRowAsHTML($rowId, $attributes, $values, $repeatInput, $allowRemove) { |
121 | 144 | if ($repeatInput) |
122 | 145 | $rowClass = 'repeat'; |
123 | 146 | else |
124 | 147 | $rowClass = ''; |
125 | 148 | |
126 | | - $result = '<tr id="'. $rowId. '" class="' . $rowClass . '">' . |
127 | | - getTableCellsAsHTML($attributes, $values); |
| 149 | + $result = '<tr id="'. $rowId. '" class="' . $rowClass . '">'; |
| 150 | + |
| 151 | + if ($allowRemove) |
| 152 | + $result .= '<td/>'; |
| 153 | + |
| 154 | + $result .= getTableCellsAsHTML($attributes, $values); |
128 | 155 | |
129 | 156 | if ($repeatInput) |
130 | | - $result .= '<td/>'; |
| 157 | + $result .= '<td class="add"/>'; |
131 | 158 | |
132 | 159 | return $result . '</tr>'; |
133 | 160 | } |
134 | 161 | |
135 | | -function getRelationAsEditHTML($relationModel, $inputRowId, $inputRowFields, $repeatInput) { |
| 162 | +function removeCheckBoxName($tuple, $key, $removeId) { |
| 163 | + $ids = array(); |
| 164 | + |
| 165 | + foreach($key->attributes as $attribute) |
| 166 | + $ids[] = $tuple[$attribute->id]; |
| 167 | + |
| 168 | + return $removeId . implode("-", $ids); |
| 169 | +} |
| 170 | + |
| 171 | +function getRelationAsEditHTML($relationModel, $inputRowId, $removeId, $inputRowFields, $repeatInput, $allowRemove) { |
136 | 172 | $result = '<table class="wiki-data-table"><tr>'; |
137 | | - $attributes = $relationModel->getAttributes(); |
| 173 | + $attributes = $relationModel->getHeading()->attributes; |
| 174 | + $key = $relationModel->getKey(); |
138 | 175 | |
| 176 | + if ($allowRemove) |
| 177 | + $result .= '<th class="remove">Remove</th>'; |
| 178 | + |
139 | 179 | foreach($attributes as $attribute) |
140 | 180 | $result .= '<th class="'. $attribute->type .'">' . $attribute->name . '</th>'; |
141 | 181 | |
142 | 182 | if ($repeatInput) |
143 | | - $result .= '<th>Input rows</th>'; |
| 183 | + $result .= '<th class="add">Input rows</th>'; |
144 | 184 | |
145 | 185 | $result .= '</tr>'; |
146 | 186 | |
147 | | - for($i = 0; $i < $relationModel->getTupleCount(); $i++) { |
148 | | - $result .= '<tr>' . getTableCellsAsHTML($attributes, convertValuesToHTML($attributes, $relationModel->getTuple($i))); |
| 187 | + for ($i = 0; $i < $relationModel->getTupleCount(); $i++) { |
| 188 | + $result .= '<tr>'; |
| 189 | + $tuple = $relationModel->getTuple($i); |
149 | 190 | |
| 191 | + if ($allowRemove) |
| 192 | + $result .= '<td class="remove">' . getCheckBox(removeCheckBoxName($tuple, $key, $removeId), false) . '</td>'; |
| 193 | + |
| 194 | + $result .= getTableCellsAsHTML($attributes, convertValuesToHTML($attributes, $tuple)); |
| 195 | + |
150 | 196 | if ($repeatInput) |
151 | 197 | $result .= '<td/>'; |
152 | 198 | |
153 | 199 | $result .= '</tr>'; |
154 | 200 | } |
155 | 201 | |
156 | | - $result .= getInputRowAsHTML($inputRowId, $attributes, $inputRowFields, $repeatInput) . '</table>'; |
| 202 | + $result .= getInputRowAsHTML($inputRowId, $attributes, $inputRowFields, $repeatInput, $allowRemove) . '</table>'; |
157 | 203 | |
158 | 204 | return $result; |
159 | 205 | } |
Index: trunk/extensions/Wikidata/WiktionaryZ/wikidata.php |
— | — | @@ -20,6 +20,7 @@ |
21 | 21 | |
22 | 22 | interface PageElementController { |
23 | 23 | public function add($values); |
| 24 | + public function remove($tuple); |
24 | 25 | } |
25 | 26 | |
26 | 27 | class DefaultPageElement implements PageElement { |
Index: trunk/extensions/Wikidata/WiktionaryZ/type.php |
— | — | @@ -31,13 +31,40 @@ |
32 | 32 | return $wgLanguageNames[$languageId]; |
33 | 33 | } |
34 | 34 | |
| 35 | +function definingExpression($definedMeaningId) { |
| 36 | + $dbr =& wfGetDB(DB_SLAVE); |
| 37 | + $queryResult = $dbr->query("SELECT spelling from uw_defined_meaning, uw_expression_ns where uw_defined_meaning.defined_meaning_id=$definedMeaningId and uw_expression_ns.expression_id=uw_defined_meaning.expression_id and uw_defined_meaning.is_latest_ver=1 and uw_expression_ns.is_latest=1"); |
| 38 | + |
| 39 | + while ($spelling = $dbr->fetchObject($queryResult)) |
| 40 | + $result = $spelling->spelling; |
| 41 | + |
| 42 | + return $result; |
| 43 | +} |
| 44 | + |
| 45 | +function definedMeaningExpression($definedMeaningId) { |
| 46 | + $dbr =& wfGetDB(DB_SLAVE); |
| 47 | + $queryResult = $dbr->query("SELECT spelling from uw_syntrans, uw_expression_ns where defined_meaning_id=$definedMeaningId and uw_expression_ns.expression_id=uw_syntrans.expression_id and uw_expression_ns.language_id=85 limit 1"); |
| 48 | + $expression = $dbr->fetchObject($queryResult); |
| 49 | + |
| 50 | + return $expression->spelling; |
| 51 | +} |
| 52 | + |
| 53 | +function definingExpressionAsLink($definedMeaningId) { |
| 54 | + return spellingAsLink(definingExpression($definedMeaningId)); |
| 55 | +} |
| 56 | + |
| 57 | +function definedMeaningAsLink($definedMeaningId) { |
| 58 | + return spellingAsLink(definedMeaningExpression($definedMeaningId)); |
| 59 | +} |
| 60 | + |
35 | 61 | function convertToHTML($value, $type) { |
36 | 62 | switch($type) { |
37 | 63 | case "boolean": return booleanAsHTML($value); |
38 | 64 | case "spelling": return spellingAsLink($value); |
39 | | - case "defined-meaning": return spellingAsLink($value); |
40 | | - case "relation-type": return spellingAsLink($value); |
41 | | - case "attribute": return spellingAsLink($value); |
| 65 | + case "defined-meaning": return definedMeaningAsLink($value); |
| 66 | + case "defining-expression": return definingExpressionAsLink($value); |
| 67 | + case "relation-type": return definedMeaningAsLink($value); |
| 68 | + case "attribute": return definedMeaningAsLink($value); |
42 | 69 | case "language": return languageIdAsText($value); |
43 | 70 | default: return $value; |
44 | 71 | } |
— | — | @@ -48,7 +75,9 @@ |
49 | 76 | case "language": return getLanguageSelect($name); |
50 | 77 | case "spelling": return getTextBox($name); |
51 | 78 | case "boolean": return getCheckBox($name, true); |
52 | | - case "defined-meaning": return getSuggest($name, "defined-meaning"); |
| 79 | + case "defined-meaning": |
| 80 | + case "defining-expression": |
| 81 | + return getSuggest($name, "defined-meaning"); |
53 | 82 | case "relation-type": return getSuggest($name, "relation-type"); |
54 | 83 | case "attribute": return getSuggest($name, "attribute"); |
55 | 84 | } |