r18623 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r18622‎ | r18623 | r18624 >
Date:13:58, 28 December 2006
Author:proes
Status:old
Tags:
Comment:
Enhanced authoritative contribution view so that the community now also is an authority and can be filtered on.
Modified paths:
  • /trunk/extensions/Wikidata/WiktionaryZ/Transaction.php (modified) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/Wikidata.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/WiktionaryZ/Wikidata.php
@@ -49,27 +49,34 @@
5050 $wgOut->enableClientCache(false);
5151 $wgOut->addHTML($this->getLanguageSelector());
5252
53 - $authorities = array();
54 -
55 - if (count($this->availableAuthorities) > 0) {
56 - $authorityOptions = array();
 53+ $this->shouldShowAuthorities = count($this->availableAuthorities) > 0;
 54+
 55+ if ($this->shouldShowAuthorities) {
 56+ $showCommunityContribution = isset($_GET['authority-community']);
5757
 58+ $authoritiesToShow = array();
 59+ $authorityOptions = array(
 60+ "Show contribution by the community" => getCheckBox('authority-community', $showCommunityContribution)
 61+ );
 62+
5863 foreach($this->availableAuthorities as $authority) {
5964 $showAuthority = isset($_GET['authority-' . $authority]);
6065
6166 if ($showAuthority)
62 - $authorities[] = $authority;
 67+ $authoritiesToShow[] = $authority;
6368
64 - $authorityOptions["Show " . getUserName($authority) . " version"] = getCheckBox('authority-' . $authority, $showAuthority);
 69+ $authorityOptions["Show contribution by " . getUserName($authority)] = getCheckBox('authority-' . $authority, $showAuthority);
6570 }
6671
6772 $wgOut->addHTML(getOptionPanel($authorityOptions));
6873 }
 74+ else
 75+ $showCommunityContribution = false;
6976
70 - $this->shouldShowAuthorities = count($authorities) > 0;
 77+ $this->shouldShowAuthorities = count($authoritiesToShow) > 0 || $showCommunityContribution;
7178
7279 if ($this->shouldShowAuthorities)
73 - $this->viewQueryTransactionInformation = new QueryAuthoritativeTransactionInformation($authorities);
 80+ $this->viewQueryTransactionInformation = new QueryAuthoritativeContributorTransactionInformation($this->availableAuthorities, $authoritiesToShow, $showCommunityContribution);
7481 else
7582 $this->viewQueryTransactionInformation = new QueryLatestTransactionInformation();
7683 }
Index: trunk/extensions/Wikidata/WiktionaryZ/Transaction.php
@@ -138,11 +138,15 @@
139139 // }
140140 }
141141
142 -class QueryAuthoritativeTransactionInformation extends DefaultQueryTransactionInformation {
143 - protected $authorities;
 142+class QueryAuthoritativeContributorTransactionInformation extends DefaultQueryTransactionInformation {
 143+ protected $availableAuthorities;
 144+ protected $authoritiesToShow;
 145+ protected $showCommunityContribution;
144146
145 - public function __construct($authorities) {
146 - $this->authorities = $authorities;
 147+ public function __construct($availableAuthorities, $authoritiesToShow, $showCommunityContribution) {
 148+ $this->availableAuthorities = $availableAuthorities;
 149+ $this->authoritiesToShow = $authoritiesToShow;
 150+ $this->showCommunityContribution = $showCommunityContribution;
147151 }
148152
149153 protected function getKeyFieldRestrictions($table, $prefix) {
@@ -155,29 +159,68 @@
156160 }
157161
158162 public function getRestriction($table) {
159 - return
160 - $table->name . ".add_transaction_id=transactions.transaction_id" .
161 - " AND (" .
162 - getLatestTransactionRestriction($table->name) .
163 - " OR (" .
164 - " transactions.user_id IN (" . implode(", ", $this->authorities) . ") " .
165 - " AND " .$table->name . ".add_transaction_id=(" .
166 - " SELECT max(add_transaction_id) " .
167 - " FROM " . $table->name . " AS latest_" . $table->name . ", transactions as latest_transactions" .
168 - " WHERE " . $this->getKeyFieldRestrictions($table, 'latest_') .
169 - " AND latest_transactions.transaction_id=latest_" . $table->name . ".add_transaction_id" .
170 - " AND latest_transactions.user_id=transactions.user_id" .
171 - ")" .
172 - " AND NOT EXISTS (" .
173 - " SELECT * " .
174 - " FROM " . $table->name . " AS latest_" . $table->name . ", transactions as latest_transactions" .
175 - " WHERE " . $this->getKeyFieldRestrictions($table, 'latest_') .
176 - " AND latest_transactions.transaction_id=latest_" . $table->name . ".remove_transaction_id" .
177 - " AND latest_transactions.user_id=transactions.user_id" .
178 - " AND latest_" . $table->name . ".remove_transaction_id > " . $table->name . ".add_transaction_id" .
179 - ")" .
180 - " )" .
181 - " )";
 163+ $result =
 164+ $table->name . ".add_transaction_id=transactions.transaction_id";
 165+
 166+ $showAnyAuthorities = count($this->authoritiesToShow) > 0;
 167+
 168+ if ($this->showCommunityContribution || $showAnyAuthorities) {
 169+ $availableAuthoritiesSet = "(" . implode(", ", $this->availableAuthorities) . ")";
 170+
 171+ $result =
 172+ $table->name . ".add_transaction_id=transactions.transaction_id" .
 173+ " AND (";
 174+
 175+ if ($this->showCommunityContribution)
 176+ $result .=
 177+ "(" .
 178+ " transactions.user_id NOT IN " . $availableAuthoritiesSet .
 179+ " AND " .$table->name . ".add_transaction_id=(" .
 180+ " SELECT max(add_transaction_id) " .
 181+ " FROM " . $table->name . " AS latest_" . $table->name . ", transactions as latest_transactions" .
 182+ " WHERE " . $this->getKeyFieldRestrictions($table, 'latest_') .
 183+ " AND latest_transactions.transaction_id=latest_" . $table->name . ".add_transaction_id" .
 184+ " AND latest_transactions.user_id NOT IN (" . implode(", ", $this->availableAuthorities) . ")" .
 185+ ")" .
 186+ " AND NOT EXISTS (" .
 187+ " SELECT * " .
 188+ " FROM " . $table->name . " AS latest_" . $table->name . ", transactions as latest_transactions" .
 189+ " WHERE " . $this->getKeyFieldRestrictions($table, 'latest_') .
 190+ " AND latest_transactions.transaction_id=latest_" . $table->name . ".remove_transaction_id" .
 191+ " AND latest_transactions.user_id NOT IN " . $availableAuthoritiesSet .
 192+ " AND latest_" . $table->name . ".remove_transaction_id > " . $table->name . ".add_transaction_id" .
 193+ ")" .
 194+ " )";
 195+ else
 196+ $result .= " 0 ";
 197+
 198+ if ($showAnyAuthorities)
 199+ $result .=
 200+ " OR (" .
 201+ " transactions.user_id IN (" . implode(", ", $this->authoritiesToShow) . ") " .
 202+ " AND " .$table->name . ".add_transaction_id=(" .
 203+ " SELECT max(add_transaction_id) " .
 204+ " FROM " . $table->name . " AS latest_" . $table->name . ", transactions as latest_transactions" .
 205+ " WHERE " . $this->getKeyFieldRestrictions($table, 'latest_') .
 206+ " AND latest_transactions.transaction_id=latest_" . $table->name . ".add_transaction_id" .
 207+ " AND latest_transactions.user_id=transactions.user_id" .
 208+ ")" .
 209+ " AND NOT EXISTS (" .
 210+ " SELECT * " .
 211+ " FROM " . $table->name . " AS latest_" . $table->name . ", transactions as latest_transactions" .
 212+ " WHERE " . $this->getKeyFieldRestrictions($table, 'latest_') .
 213+ " AND latest_transactions.transaction_id=latest_" . $table->name . ".remove_transaction_id" .
 214+ " AND latest_transactions.user_id=transactions.user_id" .
 215+ " AND latest_" . $table->name . ".remove_transaction_id > " . $table->name . ".add_transaction_id" .
 216+ ")" .
 217+ " )";
 218+
 219+ $result .= " )";
 220+ }
 221+ else
 222+ $result .= " AND 0";
 223+
 224+ return $result;
182225 }
183226
184227 public function getTables() {
@@ -201,10 +244,10 @@
202245
203246 $userID = $row['user_id'];
204247
205 - if (in_array($userID, $this->authorities))
 248+ if (in_array($userID, $this->availableAuthorities))
206249 $userName = getUserName($userID);
207250 else
208 - $userName = "";
 251+ $userName = "Community";
209252
210253 $record->setAttributeValue($authorityAttribute, $userName);
211254 }