Index: trunk/extensions/Wikidata/WiktionaryZ/Wikidata.php |
— | — | @@ -49,27 +49,34 @@ |
50 | 50 | $wgOut->enableClientCache(false);
|
51 | 51 | $wgOut->addHTML($this->getLanguageSelector());
|
52 | 52 |
|
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']);
|
57 | 57 |
|
| 58 | + $authoritiesToShow = array();
|
| 59 | + $authorityOptions = array(
|
| 60 | + "Show contribution by the community" => getCheckBox('authority-community', $showCommunityContribution)
|
| 61 | + );
|
| 62 | +
|
58 | 63 | foreach($this->availableAuthorities as $authority) {
|
59 | 64 | $showAuthority = isset($_GET['authority-' . $authority]);
|
60 | 65 |
|
61 | 66 | if ($showAuthority)
|
62 | | - $authorities[] = $authority;
|
| 67 | + $authoritiesToShow[] = $authority;
|
63 | 68 |
|
64 | | - $authorityOptions["Show " . getUserName($authority) . " version"] = getCheckBox('authority-' . $authority, $showAuthority);
|
| 69 | + $authorityOptions["Show contribution by " . getUserName($authority)] = getCheckBox('authority-' . $authority, $showAuthority);
|
65 | 70 | }
|
66 | 71 |
|
67 | 72 | $wgOut->addHTML(getOptionPanel($authorityOptions));
|
68 | 73 | }
|
| 74 | + else
|
| 75 | + $showCommunityContribution = false;
|
69 | 76 |
|
70 | | - $this->shouldShowAuthorities = count($authorities) > 0;
|
| 77 | + $this->shouldShowAuthorities = count($authoritiesToShow) > 0 || $showCommunityContribution;
|
71 | 78 |
|
72 | 79 | if ($this->shouldShowAuthorities)
|
73 | | - $this->viewQueryTransactionInformation = new QueryAuthoritativeTransactionInformation($authorities);
|
| 80 | + $this->viewQueryTransactionInformation = new QueryAuthoritativeContributorTransactionInformation($this->availableAuthorities, $authoritiesToShow, $showCommunityContribution);
|
74 | 81 | else
|
75 | 82 | $this->viewQueryTransactionInformation = new QueryLatestTransactionInformation();
|
76 | 83 | }
|
Index: trunk/extensions/Wikidata/WiktionaryZ/Transaction.php |
— | — | @@ -138,11 +138,15 @@ |
139 | 139 | // }
|
140 | 140 | }
|
141 | 141 |
|
142 | | -class QueryAuthoritativeTransactionInformation extends DefaultQueryTransactionInformation {
|
143 | | - protected $authorities;
|
| 142 | +class QueryAuthoritativeContributorTransactionInformation extends DefaultQueryTransactionInformation {
|
| 143 | + protected $availableAuthorities;
|
| 144 | + protected $authoritiesToShow;
|
| 145 | + protected $showCommunityContribution;
|
144 | 146 |
|
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;
|
147 | 151 | }
|
148 | 152 |
|
149 | 153 | protected function getKeyFieldRestrictions($table, $prefix) {
|
— | — | @@ -155,29 +159,68 @@ |
156 | 160 | }
|
157 | 161 |
|
158 | 162 | 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;
|
182 | 225 | }
|
183 | 226 |
|
184 | 227 | public function getTables() {
|
— | — | @@ -201,10 +244,10 @@ |
202 | 245 |
|
203 | 246 | $userID = $row['user_id'];
|
204 | 247 |
|
205 | | - if (in_array($userID, $this->authorities))
|
| 248 | + if (in_array($userID, $this->availableAuthorities))
|
206 | 249 | $userName = getUserName($userID);
|
207 | 250 | else
|
208 | | - $userName = "";
|
| 251 | + $userName = "Community";
|
209 | 252 |
|
210 | 253 | $record->setAttributeValue($authorityAttribute, $userName);
|
211 | 254 | }
|