r23680 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23679‎ | r23680 | r23681 >
Date:19:05, 3 July 2007
Author:erik
Status:old
Tags:
Comment:
add type hinting to policy
kill last remnants of the old authority code
bits of doc
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Transaction.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/ViewInformation.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Wikidata.php (modified) (history)
  • /trunk/extensions/Wikidata/POLICY (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/POLICY
@@ -65,6 +65,10 @@
6666 Other than initial hook functions and command-line scripts, all
6767 functions should exist in a class context.
6868
 69+== Function parameters ==
 70+
 71+Add type hints and default values where appropriate.
 72+
6973 == Variables ==
7074
7175 Variable names are generally written in CamelCase (lower case first
Index: trunk/extensions/Wikidata/OmegaWiki/ViewInformation.php
@@ -16,22 +16,20 @@
1717 public $possiblySynonymousRelationTypeId;
1818 public $queryTransactionInformation;
1919 public $showRecordLifeSpan;
20 - public $showAuthority;
21 -
 20+
2221 public function __construct() {
2322 $this->filterLanguageId = 0;
2423 $this->possiblySynonymousRelationTypeId = 0;
2524 $this->queryTransactionInformation;
2625 $this->showRecordLifeSpan = false;
27 - $this->showAuthority = false;
2826 }
2927
3028 public function hasMetaDataAttributes() {
31 - return $this->showRecordLifeSpan || $this->showAuthority;
 29+ return $this->showRecordLifeSpan;
3230 }
3331
3432 public function filterOnLanguage() {
35 - return $this->filterOnLanguage != 0;
 33+ return $this->filterLanguageId != 0;
3634 }
3735 }
3836
Index: trunk/extensions/Wikidata/OmegaWiki/Transaction.php
@@ -149,124 +149,7 @@
150150 // }
151151 }
152152
153 -class QueryAuthoritativeContributorTransactionInformation extends DefaultQueryTransactionInformation {
154 - protected $availableAuthorities;
155 - protected $authoritiesToShow;
156 - protected $showCommunityContribution;
157 -
158 - public function __construct($availableAuthorities, $authoritiesToShow, $showCommunityContribution) {
159 - $this->availableAuthorities = $availableAuthorities;
160 - $this->authoritiesToShow = $authoritiesToShow;
161 - $this->showCommunityContribution = $showCommunityContribution;
162 - }
163 -
164 - protected function getKeyFieldRestrictions(Table $table, $prefix) {
165 - $result = array();
166 -
167 - foreach ($table->keyFields as $keyField)
168 - $result[] = $table->identifier . "." . $keyField . "=" . $prefix . $table->identifier . "." . $keyField;
169 -
170 - return implode(" AND ", $result);
171 - }
172 -
173 - public function getRestriction(Table $table) {
174 - $dc=wdGetDataSetContext();
175 - $result =
176 - $table->identifier . ".add_transaction_id={$dc}_transactions.transaction_id";
177153
178 - $showAnyAuthorities = count($this->authoritiesToShow) > 0;
179 -
180 - if ($this->showCommunityContribution || $showAnyAuthorities) {
181 - $availableAuthorityIds = array_keys($this->availableAuthorities);
182 - $availableAuthoritiesSet = "(" . implode(", ", $availableAuthorityIds) . ")";
183 -
184 - $result =
185 - $table->identifier . ".add_transaction_id={$dc}_transactions.transaction_id" .
186 - " AND (";
187 -
188 - if ($this->showCommunityContribution)
189 - $result .=
190 - "(" .
191 - " {$dc}_transactions.user_id NOT IN " . $availableAuthoritiesSet .
192 - " AND " .$table->identifier . ".add_transaction_id=(" .
193 - " SELECT max(add_transaction_id) " .
194 - " FROM " . $table->identifier . " AS latest_" . $table->identifier . ", {$dc}_transactions as latest_transactions" .
195 - " WHERE " . $this->getKeyFieldRestrictions($table, 'latest_') .
196 - " AND latest_transactions.transaction_id=latest_" . $table->identifier . ".add_transaction_id" .
197 - " AND latest_transactions.user_id NOT IN (" . implode(", ", $availableAuthorityIds) . ")" .
198 - ")" .
199 - " AND NOT EXISTS (" .
200 - " SELECT * " .
201 - " FROM " . $table->identifier . " AS latest_" . $table->identifier . ", {$dc}_transactions as latest_transactions" .
202 - " WHERE " . $this->getKeyFieldRestrictions($table, 'latest_') .
203 - " AND latest_transactions.transaction_id=latest_" . $table->identifier . ".remove_transaction_id" .
204 - " AND latest_transactions.user_id NOT IN " . $availableAuthoritiesSet .
205 - " AND latest_" . $table->identifier . ".remove_transaction_id > " . $table->identifier . ".add_transaction_id" .
206 - ")" .
207 - " )";
208 - else
209 - $result .= " 0 ";
210 -
211 - if ($showAnyAuthorities)
212 - $result .=
213 - " OR (" .
214 - " {$dc}_transactions.user_id IN (" . implode(", ", $this->authoritiesToShow) . ") " .
215 - " AND " .$table->identifier . ".add_transaction_id=(" .
216 - " SELECT max(add_transaction_id) " .
217 - " FROM " . $table->identifier . " AS latest_" . $table->identifier . ", {$dc}_transactions as latest_transactions" .
218 - " WHERE " . $this->getKeyFieldRestrictions($table, 'latest_') .
219 - " AND latest_transactions.transaction_id=latest_" . $table->identifier . ".add_transaction_id" .
220 - " AND latest_transactions.user_id={$dc}_transactions.user_id" .
221 - ")" .
222 - " AND NOT EXISTS (" .
223 - " SELECT * " .
224 - " FROM " . $table->identifier . " AS latest_" . $table->identifier . ", {$dc}_transactions as latest_transactions" .
225 - " WHERE " . $this->getKeyFieldRestrictions($table, 'latest_') .
226 - " AND latest_transactions.transaction_id=latest_" . $table->identifier . ".remove_transaction_id" .
227 - " AND latest_transactions.user_id={$dc}_transactions.user_id" .
228 - " AND latest_" . $table->identifier . ".remove_transaction_id > " . $table->identifier . ".add_transaction_id" .
229 - ")" .
230 - " )";
231 -
232 - $result .= " )";
233 - }
234 - else
235 - $result .= " AND 0";
236 -
237 - return $result;
238 - }
239 -
240 - public function getTables() {
241 - $dc=wdGetDataSetContext();
242 - return array("{$dc}_transactions");
243 - }
244 -
245 - public function versioningAttributes() {
246 - global
247 - $authorityAttribute;
248 -
249 - return array($authorityAttribute);
250 - }
251 -
252 - public function versioningFields($tableName) {
253 - return array("{$dc}_transactions.user_id", $tableName . '.add_transaction_id');
254 - }
255 -
256 - public function setVersioningAttributes(Record $record, $row) {
257 - global
258 - $authorityAttribute;
259 -
260 - $userID = $row['user_id'];
261 -
262 - if (array_key_exists($userID, $this->availableAuthorities))
263 - $userName = $this->availableAuthorities[$userID]; //getUserName($userID);
264 - else
265 - $userName = "Community";
266 -
267 - $record->setAttributeValue($authorityAttribute, $userName);
268 - }
269 -}
270 -
271154 global
272155 $updateTransactionId;
273156
@@ -339,12 +222,10 @@
340223 $transactionIdAttribute, $userAttribute, $userIPAttribute, $timestampAttribute,
341224 $transactionStructure, $summaryAttribute,
342225 $addTransactionAttribute, $removeTransactionAttribute,
343 - $recordLifeSpanAttribute, $recordLifeSpanStructure,
344 - $authorityAttribute, $wgAuthorityAttributeName;
 226+ $recordLifeSpanAttribute, $recordLifeSpanStructure;
345227
346228 $transactionIdAttribute = new Attribute('transaction-id', 'Transaction ID', 'integer');
347229 $userAttribute = new Attribute('user', 'User', 'user');
348 -$authorityAttribute = new Attribute('authority', $wgAuthorityAttributeName, 'authority');
349230 $userIPAttribute = new Attribute('user-ip', 'User IP', 'IP');
350231 $timestampAttribute = new Attribute('timestamp', 'Time', 'timestamp');
351232 $summaryAttribute = new Attribute('summary', 'Summary', 'text');
Index: trunk/extensions/Wikidata/OmegaWiki/Wikidata.php
@@ -9,12 +9,9 @@
1010 protected $showRecordLifeSpan;
1111 protected $transaction;
1212 protected $queryTransactionInformation;
13 - protected $shouldShowAuthorities;
1413 protected $showCommunityContribution;
15 - protected $authoritiesToShow;
1614
1715 // The following member variables control some application specific preferences
18 - protected $availableAuthorities = array(); // A map containing (userId => displayName) combination for authoritative contribution view
1916 protected $filterLanguageId = 0; // Filter pages on this languageId, set to 0 to show all languages
2017 protected $possiblySynonymousRelationTypeId = 0; // Put this relation type in a special section "Possibly synonymous"
2118 protected $showLanguageSelector = true; // Show language selector at the top of each wiki data page
@@ -27,12 +24,9 @@
2825
2926 public function __construct() {
3027 global
31 - $wgAvailableAuthorities, $wgFilterLanguageId, $wgShowLanguageSelector,
 28+ $wgFilterLanguageId, $wgShowLanguageSelector,
3229 $wgShowClassicPageTitles, $wgPossiblySynonymousRelationTypeId;
3330
34 - if (isset($wgAvailableAuthorities))
35 - $this->availableAuthorities = $wgAvailableAuthorities;
36 -
3731 if (isset($wgFilterLanguageId))
3832 $this->filterLanguageId = $wgFilterLanguageId;
3933
@@ -94,7 +88,6 @@
9589 $viewInformation->filterLanguageId = $this->filterLanguageId;
9690 $viewInformation->possiblySynonymousRelationTypeId = $this->possiblySynonymousRelationTypeId;
9791 $viewInformation->showRecordLifeSpan = false;
98 - $viewInformation->showAuthority = $this->shouldShowAuthorities;
9992 $viewInformation->queryTransactionInformation = $this->queryTransactionInformation;
10093
10194 $this->viewInformation = $viewInformation;
@@ -183,7 +176,6 @@
184177 $viewInformation->filterLanguageId = $this->filterLanguageId;
185178 $viewInformation->possiblySynonymousRelationTypeId = $this->possiblySynonymousRelationTypeId;
186179 $viewInformation->showRecordLifeSpan = false;
187 - $viewInformation->showAuthority = false;
188180 $viewInformation->queryTransactionInformation = new QueryLatestTransactionInformation();
189181
190182 $this->viewInformation = $viewInformation;
@@ -240,7 +232,6 @@
241233 $viewInformation->filterLanguageId = $this->filterLanguageId;
242234 $viewInformation->possiblySynonymousRelationTypeId = $this->possiblySynonymousRelationTypeId;
243235 $viewInformation->showRecordLifeSpan = $this->showRecordLifeSpan;
244 - $viewInformation->showAuthority = false;
245236 $viewInformation->queryTransactionInformation = $this->queryTransactionInformation;
246237
247238 $this->viewInformation = $viewInformation;
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php
@@ -7,7 +7,6 @@
88 $wgAlternativeDefinitionsAttributeName,
99 $wgAnnotationAttributeName,
1010 $wgApproximateMeaningsAttributeName,
11 - $wgAuthorityAttributeName,
1211 $wgClassAttributeAttributeAttributeName,
1312 $wgClassAttributesAttributeName,
1413 $wgClassAttributeLevelAttributeName,
@@ -56,7 +55,6 @@
5756 $wgAlternativeDefinitionsAttributeName = "Alternative definitions";
5857 $wgAnnotationAttributeName = "Annotation";
5958 $wgApproximateMeaningsAttributeName = "Approximate meanings";
60 -$wgAuthorityAttributeName = "Authority";
6159 $wgClassAttributeAttributeAttributeName = "Attribute";
6260 $wgClassAttributesAttributeName = "Class attributes";
6361 $wgClassAttributeLevelAttributeName = "Level";
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php
@@ -75,14 +75,6 @@
7676 $editor->addEditor(createTableLifeSpanEditor($recordLifeSpanAttribute));
7777 }
7878
79 -function addTableAuthorityEditor(Editor $editor, $showAuthority) {
80 - global
81 - $authorityAttribute;
82 -
83 - if ($showAuthority)
84 - $editor->addEditor(createShortTextViewer($authorityAttribute));
85 -}
86 -
8779 function addTableMetadataEditors($editor, ViewInformation $viewInformation) {
8880 addTableLifeSpanEditor($editor, $viewInformation->showRecordLifeSpan);
8981 }
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php
@@ -4,6 +4,27 @@
55 require_once("WikiDataGlobals.php");
66 require_once("ViewInformation.php");
77
 8+/**
 9+ *
 10+ * This file models the structure of the OmegaWiki database in a
 11+ * database-independent fashion. To do so, it follows a simplified
 12+ * relational model, consisting of Attribute objects which are hierarchically
 13+ * grouped together using Structure objects. See Attribute.php for details.
 14+ *
 15+ * The actual data is stored in Records, grouped together as RecordSets.
 16+ * See Record.php and RecordSet.php for details.
 17+ *
 18+ * TODO:
 19+ * - The current model of a ton of hardcoded globals is highly inadequate
 20+ * and should be replaced with a more abstract schema description.
 21+ * - Attribute names are in WikidataGlobals.php, but should really be
 22+ * localizable through MediaWiki's wfMsg() function.
 23+ * - Records and RecordSets are currently capable of storing most (not all)
 24+ * data, but can't actually commit them to the database again. To achieve
 25+ * proper separation of architectural layers, the Records should learn
 26+ * to talk directly with the DB layer.
 27+ *
 28+ */
829 function initializeOmegaWikiAttributes(ViewInformation $viewInformation) {
930 global
1031 $languageAttribute, $spellingAttribute, $textAttribute,
@@ -281,6 +302,10 @@
282303
283304 global $wdDefinedMeaningAttributesOrder;
284305
 306+ /**
 307+ * This global determines the order of the different
 308+ * attributes in the user interface.
 309+ */
285310 $wdDefinedMeaningAttributesOrder=array(
286311 $definitionAttribute->id,
287312 $classAttributesAttribute->id,

Status & tagging log