Index: trunk/extensions/Wikidata/OmegaWiki/Utilities.php |
— | — | @@ -1,4 +1,5 @@ |
2 | 2 | <?php |
| 3 | +require_once("Wikidata.php"); |
3 | 4 | |
4 | 5 | function implodeFixed($values, $separator = ", ", $prefix = '"', $suffix = '"') { |
5 | 6 | $result = $prefix . $values[0] . $suffix; |
— | — | @@ -9,4 +10,14 @@ |
10 | 11 | return $result; |
11 | 12 | } |
12 | 13 | |
| 14 | + |
| 15 | +function wfMsg_sc($message) { |
| 16 | + $args=func_get_args(); |
| 17 | + array_shift($args); |
| 18 | + global |
| 19 | + $SiteContext; |
| 20 | + return wfMsgReal("${SiteContext}_${message}", $args, true); |
| 21 | +} |
| 22 | + |
| 23 | + |
13 | 24 | ?> |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php |
— | — | @@ -18,17 +18,13 @@ |
19 | 19 | * merging here. |
20 | 20 | * |
21 | 21 | * TODO: |
22 | | - * - The current model of a ton of hardcoded globals is highly inadequate |
23 | | - * and should be replaced with a more abstract schema description. |
24 | | - * -replacing with a single associative array. |
25 | | - * - Attribute names are in WikidataGlobals.php, but should really be |
26 | | - * localizable through MediaWiki's wfMsg() function. |
27 | | - * -this is step 2 |
28 | 22 | * - Records and RecordSets are currently capable of storing most (not all) |
29 | 23 | * data, but can't actually commit them to the database again. To achieve |
30 | 24 | * proper separation of architectural layers, the Records should learn |
31 | 25 | * to talk directly with the DB layer. |
32 | | - * -this is what RecordHelpers are for. |
| 26 | + # - This is not a pure singleton, because it relies on the existence of |
| 27 | + # of viewInformation, and a message cache. We now defer lookups in these |
| 28 | + # to as late as possible, to make sure these items are actually initialized. |
33 | 29 | */ |
34 | 30 | function initializeOmegaWikiAttributes(ViewInformation $viewInformation){ |
35 | 31 | $init_and_discard_this= OmegaWikiAttributes::getInstance($viewInformation); |
— | — | @@ -52,21 +48,52 @@ |
53 | 49 | return $instance["last"]; |
54 | 50 | } |
55 | 51 | |
| 52 | + |
56 | 53 | protected $attributes = array(); |
| 54 | + protected $setup_completed=False; |
| 55 | + protected $in_setup=False; # for use by functions doing the setup itself (currently hardValues) |
| 56 | + protected $viewInformation=null; |
57 | 57 | |
58 | 58 | function __construct(ViewInformation $viewInformation) { |
59 | | - $this->hardValues($viewInformation); |
| 59 | + $this->setup($viewInformation); |
60 | 60 | } |
61 | 61 | |
| 62 | + protected function setup(ViewInformation $viewInformation=null) { |
| 63 | + if ($this->in_setup or $this->setup_completed) |
| 64 | + return True; |
| 65 | + |
| 66 | + if (!is_null($viewInformation)) { |
| 67 | + $this->viewInformation=$viewInformation; |
| 68 | + } |
| 69 | + $viewInformation=$this->viewInformation; |
| 70 | + |
| 71 | + if (!is_null($viewInformation)) { |
| 72 | + global $messageCacheOK; |
| 73 | + var_dump($messageCacheOK); |
| 74 | + if (!$messageCacheOK) { |
| 75 | + #We're not ready to do this yet! |
| 76 | + return False; #so we get out, but with viewinfo cached |
| 77 | + } |
| 78 | + if (!$this->setup_completed) { |
| 79 | + $this->hardValues($viewInformation); |
| 80 | + } |
| 81 | + $this->setup_completed=True; |
| 82 | + return True; |
| 83 | + } |
| 84 | + return False; |
| 85 | + } |
| 86 | + |
62 | 87 | /** Hardcoded schema for now. Later refactor to load from file or DB |
63 | 88 | * |
64 | 89 | * Naming: keys are previous name minus -"Attribute" |
65 | 90 | * (-"Structure" is retained, -"Attributes" is retained) |
66 | 91 | */ |
67 | | - private function hardValues($viewInformation) { |
| 92 | + private function hardValues(viewInformation $viewInformation) { |
68 | 93 | |
| 94 | + assert (!is_null($viewInformation)); |
69 | 95 | $t=$this; #<-keep things short to declutter |
70 | 96 | |
| 97 | + $t->in_setup=True; |
71 | 98 | $t->language = new Attribute("language", wfMsg("Language"), "language"); |
72 | 99 | $t->spelling = new Attribute("spelling", wfMsg("Spelling"), "spelling"); |
73 | 100 | $t->text = new Attribute("text", wfMsg("Text"), "text"); |
— | — | @@ -261,14 +288,19 @@ |
262 | 289 | foreach ($t->annotatedAttributes as $annotatedAttribute) |
263 | 290 | $annotatedAttribute->type->addAttribute($attribute); |
264 | 291 | } |
| 292 | + $t->in_setup=False; |
265 | 293 | } |
266 | 294 | |
267 | 295 | protected function __set($key,$value) { |
| 296 | + if (!$this->setup()) |
| 297 | + throw new Exception("OmegaWikiAttributes accessed, but was not properly initialized"); |
268 | 298 | $attributes=&$this->attributes; |
269 | 299 | $attributes[$key]=$value; |
270 | 300 | } |
271 | 301 | |
272 | 302 | public function __get($key) { |
| 303 | + if (!$this->setup()) |
| 304 | + throw new Exception("OmegaWikiAttributes accessed, but was not properly initialized"); |
273 | 305 | $attributes=&$this->attributes; |
274 | 306 | if (!array_key_exists($key, $attributes)) { |
275 | 307 | throw new Exception("Key does not exist: " . $key); |
Index: trunk/extensions/Wikidata/OmegaWiki/Wikidata.php |
— | — | @@ -82,7 +82,7 @@ |
83 | 83 | |
84 | 84 | $this->viewInformation = $viewInformation; |
85 | 85 | |
86 | | - initializeOmegaWikiAttributes($viewInformation); |
| 86 | + initializeOmegaWikiAttributes($viewInformation); |
87 | 87 | initializeObjectAttributeEditors($viewInformation); |
88 | 88 | } |
89 | 89 | |
— | — | @@ -297,9 +297,9 @@ |
298 | 298 | |
299 | 299 | # overrides |
300 | 300 | if (!is_null($dc)) |
301 | | - return $dc; |
| 301 | + return $dc; #local override |
302 | 302 | if (!is_null($wdCurrentContext)) |
303 | | - return $wdCurrentContext; |
| 303 | + return $wdCurrentContext; #global override |
304 | 304 | |
305 | 305 | $datasets=wdGetDataSets(); |
306 | 306 | $groups=$wgUser->getGroups(); |
— | — | @@ -425,4 +425,4 @@ |
426 | 426 | return $this->getPrefix(); |
427 | 427 | } |
428 | 428 | |
429 | | -} |
\ No newline at end of file |
| 429 | +} |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php |
— | — | @@ -180,7 +180,7 @@ |
181 | 181 | |
182 | 182 | function initializeObjectAttributeEditors(ViewInformation $viewInformation) { |
183 | 183 | |
184 | | - $o=OmegaWikiAttributes::getInstance(); |
| 184 | + $o=OmegaWikiAttributes::getInstance($viewInformation); |
185 | 185 | global |
186 | 186 | |
187 | 187 | $textValueObjectAttributesEditors, |
Index: trunk/extensions/Wikidata/OmegaWiki/Alert.php |
— | — | @@ -1,194 +1,194 @@ |
2 | | -<?php
|
3 | | -
|
4 | | -require_once( "extensions/Wikidata/OmegaWiki/WikiDataAPI.php" );
|
5 | | -
|
6 | | -function ConvertIsoToEpoch( $iso ){
|
7 | | - // 01234567890123456789
|
8 | | - // 2007-05-01-T00:00:00
|
9 | | - return substr( $iso, 0, 4 ) . substr( $iso, 5, 2 ) . substr( $iso, 8, 2 ) . substr( $iso, 12, 2 ) . substr( $iso, 15, 2 ) . substr( $iso, 18, 2 );
|
10 | | -}
|
11 | | -
|
12 | | -function ConvertEpochToIso( $epoch ){
|
13 | | - // 01234567890123456789
|
14 | | - // 20070501000000
|
15 | | - return substr( $epoch, 0, 4 ) . "-" . substr( $epoch, 4, 2 ) . "-" . substr( $epoch, 6, 2 ) . "-T" . substr( $epoch, 8, 2 ) . ":" . substr( $epoch, 10, 2 ) . ":" . substr( $epoch, 12, 2 );
|
16 | | -}
|
17 | | -
|
18 | | -function getDefinedMeaning( $dc, $textId ){
|
19 | | - // translate the text id to a translated text id
|
20 | | - $dbr = &wfGetDB(DB_SLAVE);
|
21 | | - $queryResult = $dbr->query( "select translated_content_id from {$dc}_translated_content where text_id = $textId and remove_transaction_id is NULL" );
|
22 | | - if ( $row = $dbr->fetchObject( $queryResult ) ){
|
23 | | - $tcid = $row->translated_content_id;
|
24 | | - }
|
25 | | - else{
|
26 | | - return -1;
|
27 | | - }
|
28 | | -
|
29 | | - // try the definition first
|
30 | | - $queryResult = $dbr->query( "select defined_meaning_id from uw_defined_meaning where meaning_text_tcid = $tcid" );
|
31 | | - if ( $row = $dbr->fetchObject( $queryResult ) ){
|
32 | | - $definedMeaningId = $row->defined_meaning_id;
|
33 | | - return $definedMeaningId;
|
34 | | - }
|
35 | | -
|
36 | | - // try the translated text attributes
|
37 | | - $queryResult = $dbr->query( "select object_id from uw_translated_content_attribute_values where value_tcid = $tcid" );
|
38 | | - if ( $row = $dbr->fetchObject( $queryResult ) ){
|
39 | | - $definedMeaningId = $row->object_id;
|
40 | | - return $definedMeaningId;
|
41 | | - }
|
42 | | -
|
43 | | - // try the text attributes
|
44 | | - $queryResult = $dbr->query( "select object_id from uw_text_attribute_values where value_id = $tcid" );
|
45 | | - if ( $row = $dbr->fetchObject( $queryResult ) ){
|
46 | | - $definedMeaningId = $row->object_id;
|
47 | | - return $definedMeaningId;
|
48 | | - }
|
49 | | -
|
50 | | - return -1;
|
51 | | -}
|
52 | | -
|
53 | | -function getInternalIdentifier( $dc, $definedMeaningId, $languageId ){
|
54 | | - $collectionName = "uw";
|
55 | | -
|
56 | | - $dbr = &wfGetDB(DB_SLAVE);
|
57 | | - $query = "SELECT collection_id, internal_member_id FROM {$dc}_collection_contents where member_mid = $definedMeaningId";
|
58 | | - $queryResult = $dbr->query( "SELECT collection_id, internal_member_id FROM {$dc}_collection_contents where member_mid = $definedMeaningId" );
|
59 | | - if ( $row = $dbr->fetchObject( $queryResult ) ){
|
60 | | - $internalMemberId = $row->internal_member_id;
|
61 | | -
|
62 | | - $collectionDefinedMeaningId = getCollectionMeaningId( $row->collection_id );
|
63 | | - $queryResult = $dbr->query( "SELECT meaning_text_tcid FROM {$dc}_defined_meaning where defined_meaning_id = $collectionDefinedMeaningId" );
|
64 | | - if ( $row = $dbr->fetchObject( $queryResult ) ){
|
65 | | - $queryResult = $dbr->query( "SELECT text_id FROM {$dc}_translated_content where translated_content_id = $row->meaning_text_tcid" );
|
66 | | - if ( $row = $dbr->fetchObject( $queryResult ) ){
|
67 | | - $queryResult = $dbr->query( "SELECT text_text FROM {$dc}_text where text_id = $row->text_id" );
|
68 | | - if ( $row = $dbr->fetchObject( $queryResult ) ){
|
69 | | - if ( $row->text_text == "Swiss-Prot" ){
|
70 | | - $collectionName = "uniprot";
|
71 | | - }
|
72 | | - }
|
73 | | - }
|
74 | | - }
|
75 | | -
|
76 | | - return $collectionName . '/' . $internalMemberId;
|
77 | | - }
|
78 | | - else{
|
79 | | - return "";
|
80 | | - }
|
81 | | -
|
82 | | -}
|
83 | | -
|
84 | | -function getTextForId( $dc, $text_id ){
|
85 | | - $dbr = &wfGetDB(DB_SLAVE);
|
86 | | - $textResult = $dbr->query( "select text_text from {$dc}_text where text_id = $text_id" );
|
87 | | - if ( $textRecord = $dbr->fetchObject($textResult) ){
|
88 | | - return $textRecord->text_text;
|
89 | | - }
|
90 | | - else {
|
91 | | - return( "" );
|
92 | | - }
|
93 | | -}
|
94 | | -
|
95 | | -function getDefinedMeaningTitle( $dc, $definedMeaningId ){
|
96 | | - $dbr = &wfGetDB(DB_SLAVE);
|
97 | | - $result = $dbr->query( "SELECT meaning_text_tcid FROM {$dc}_defined_meaning where defined_meaning_id = $definedMeaningId" );
|
98 | | - if ( $record = $dbr->fetchObject($result) ){
|
99 | | - $result = $dbr->query( "SELECT text_id FROM {$dc}_translated_content where translated_content_id = $record->meaning_text_tcid and remove_transaction_id IS NULL" );
|
100 | | - if ( $record = $dbr->fetchObject($result) ){
|
101 | | - return getTextForId( $dc, $record->text_id ) . "_(" . $definedMeaningId . ")";
|
102 | | - }
|
103 | | - }
|
104 | | - return( "" );
|
105 | | -}
|
106 | | -
|
107 | | -function getUser( $user_id ){
|
108 | | - $dbr = &wfGetDB(DB_SLAVE);
|
109 | | - $queryResult = $dbr->query( "SELECT user_name FROM `user` u where user_id = $user_id" );
|
110 | | - if ( $row = $dbr->fetchObject( $queryResult ) ){
|
111 | | - return $row->user_name;
|
112 | | - }
|
113 | | - return "unknown";
|
114 | | -}
|
115 | | -
|
116 | | -// XML Entity Mandatory Escape Characters
|
117 | | -function xmlentities($string) {
|
118 | | - return str_replace ( array ( '&', '"', "'", '<', '>', '�' ), array ( '&' , '"', ''' , '<' , '>', ''' ), $string );
|
119 | | -}
|
120 | | -
|
121 | | -require (dirname(__FILE__) . '/includes/WebStart.php');
|
122 | | -global $wgSitename;
|
123 | | -
|
124 | | -// Verify that the API has not been disabled
|
125 | | -if (!$wgEnableAPI) {
|
126 | | - echo 'MediaWiki API is not enabled for this site. Add the following line to your LocalSettings.php';
|
127 | | - echo '<pre><b>$wgEnableAPI=true;</b></pre>';
|
128 | | - die(-1);
|
129 | | -}
|
130 | | -
|
131 | | -// indicate here the dataset that contains the community version
|
132 | | -$dc = "uw";
|
133 | | -
|
134 | | -// read the parameters passed as arguments to the alert program
|
135 | | -$responseType = $_GET["output"];
|
136 | | -$epochStartDate = $_GET["startDate"];
|
137 | | -$startDate = ConvertIsoToEpoch( $epochStartDate );
|
138 | | -$epochEndDate = $_GET["endDate"];
|
139 | | -
|
140 | | -if ( $epochStartDate == "" ){
|
141 | | - echo 'This alert utility requires a start date in ISO format to be specified as parameter<BR>';
|
142 | | - echo 'Usage: alert.php?startDate=2007-05-01-T00:00:00[&endDate=2007-06-31-T00:00:00][&output=(xml|raw)]<BR>';
|
143 | | - die(-1);
|
144 | | -}
|
145 | | -
|
146 | | -if ( $epochEndDate != "" ){
|
147 | | - $endDate = ConvertIsoToEpoch( $epochEndDate );
|
148 | | - $endClause = " AND timestamp <= $endDate ";
|
149 | | -}
|
150 | | -else {
|
151 | | - $endClause = "";
|
152 | | -}
|
153 | | -
|
154 | | -$dbr = &wfGetDB(DB_SLAVE);
|
155 | | -
|
156 | | -$queryResult = $dbr->query( "select language_id from language where wikimedia_key='en'" );
|
157 | | -$languageId = $dbr->fetchObject($queryResult)->language_id;
|
158 | | -
|
159 | | -$transactionResult = $dbr->query( "select transaction_id, user_id, timestamp from {$dc}_transactions where timestamp >= $startDate $endClause" );
|
160 | | -if ( $responseType == "xml" ){
|
161 | | - echo "<edits startdate='$epochStartDate'";
|
162 | | - if ( $epochEndDate != "" ){
|
163 | | - echo " enddate='$epochEndDate'";
|
164 | | - }
|
165 | | - echo ">";
|
166 | | -}
|
167 | | -
|
168 | | -while ($transactionRecord = $dbr->fetchObject($transactionResult)) {
|
169 | | - $transaction_id = $transactionRecord->transaction_id;
|
170 | | - $timestamp = $transactionRecord->timestamp;
|
171 | | - $user = getUser( $transactionRecord->user_id );
|
172 | | -
|
173 | | - $translatedContentResult = $dbr->query( "SELECT text_id FROM {$dc}_translated_content WHERE add_transaction_id = $transaction_id AND language_id=$languageId and remove_transaction_id IS NULL" );
|
174 | | - while ($tranlatedContentRecord = $dbr->fetchObject($translatedContentResult)) {
|
175 | | - $definedMeaningId = getDefinedMeaning( $dc, $tranlatedContentRecord->text_id );
|
176 | | - $text = xmlentities( getTextForId( $dc, $tranlatedContentRecord->text_id ) );
|
177 | | - $internalIdentifier = getInternalIdentifier( $dc, $definedMeaningId, $languageId );
|
178 | | - if ( $internalIdentifier != "" ){
|
179 | | - $definedMeaningTitle = getDefinedMeaningTitle( $dc, $definedMeaningId );
|
180 | | - $epochDate = ConvertEpochToIso($timestamp);
|
181 | | - if ( $responseType == "xml" ){
|
182 | | - echo "<record><knowletid>$internalIdentifier</knowletid><text>$text</text><user>$user</user><timestamp>$epochDate</timestamp><definedmeaning>$definedMeaningTitle</definedmeaning><site>$wgSitename</site></record>";
|
183 | | - }
|
184 | | - else {
|
185 | | - echo "$internalIdentifier|$text|$user|$epochDate|$definedMeaningTitle|$wgSitename\n";
|
186 | | - }
|
187 | | - }
|
188 | | - }
|
189 | | -}
|
190 | | -if ( $responseType == "xml" ){
|
191 | | - echo "</edits>";
|
192 | | -}
|
193 | | -
|
| 2 | +<?php |
194 | 3 | |
| 4 | +require_once( "extensions/Wikidata/OmegaWiki/WikiDataAPI.php" ); |
| 5 | + |
| 6 | +function ConvertIsoToEpoch( $iso ){ |
| 7 | + // 01234567890123456789 |
| 8 | + // 2007-05-01-T00:00:00 |
| 9 | + return substr( $iso, 0, 4 ) . substr( $iso, 5, 2 ) . substr( $iso, 8, 2 ) . substr( $iso, 12, 2 ) . substr( $iso, 15, 2 ) . substr( $iso, 18, 2 ); |
| 10 | +} |
| 11 | + |
| 12 | +function ConvertEpochToIso( $epoch ){ |
| 13 | + // 01234567890123456789 |
| 14 | + // 20070501000000 |
| 15 | + return substr( $epoch, 0, 4 ) . "-" . substr( $epoch, 4, 2 ) . "-" . substr( $epoch, 6, 2 ) . "-T" . substr( $epoch, 8, 2 ) . ":" . substr( $epoch, 10, 2 ) . ":" . substr( $epoch, 12, 2 ); |
| 16 | +} |
| 17 | + |
| 18 | +function getDefinedMeaning( $dc, $textId ){ |
| 19 | + // translate the text id to a translated text id |
| 20 | + $dbr = &wfGetDB(DB_SLAVE); |
| 21 | + $queryResult = $dbr->query( "select translated_content_id from {$dc}_translated_content where text_id = $textId and remove_transaction_id is NULL" ); |
| 22 | + if ( $row = $dbr->fetchObject( $queryResult ) ){ |
| 23 | + $tcid = $row->translated_content_id; |
| 24 | + } |
| 25 | + else{ |
| 26 | + return -1; |
| 27 | + } |
| 28 | + |
| 29 | + // try the definition first |
| 30 | + $queryResult = $dbr->query( "select defined_meaning_id from uw_defined_meaning where meaning_text_tcid = $tcid" ); |
| 31 | + if ( $row = $dbr->fetchObject( $queryResult ) ){ |
| 32 | + $definedMeaningId = $row->defined_meaning_id; |
| 33 | + return $definedMeaningId; |
| 34 | + } |
| 35 | + |
| 36 | + // try the translated text attributes |
| 37 | + $queryResult = $dbr->query( "select object_id from uw_translated_content_attribute_values where value_tcid = $tcid" ); |
| 38 | + if ( $row = $dbr->fetchObject( $queryResult ) ){ |
| 39 | + $definedMeaningId = $row->object_id; |
| 40 | + return $definedMeaningId; |
| 41 | + } |
| 42 | + |
| 43 | + // try the text attributes |
| 44 | + $queryResult = $dbr->query( "select object_id from uw_text_attribute_values where value_id = $tcid" ); |
| 45 | + if ( $row = $dbr->fetchObject( $queryResult ) ){ |
| 46 | + $definedMeaningId = $row->object_id; |
| 47 | + return $definedMeaningId; |
| 48 | + } |
| 49 | + |
| 50 | + return -1; |
| 51 | +} |
| 52 | + |
| 53 | +function getInternalIdentifier( $dc, $definedMeaningId, $languageId ){ |
| 54 | + $collectionName = "uw"; |
| 55 | + |
| 56 | + $dbr = &wfGetDB(DB_SLAVE); |
| 57 | + $query = "SELECT collection_id, internal_member_id FROM {$dc}_collection_contents where member_mid = $definedMeaningId"; |
| 58 | + $queryResult = $dbr->query( "SELECT collection_id, internal_member_id FROM {$dc}_collection_contents where member_mid = $definedMeaningId" ); |
| 59 | + if ( $row = $dbr->fetchObject( $queryResult ) ){ |
| 60 | + $internalMemberId = $row->internal_member_id; |
| 61 | + |
| 62 | + $collectionDefinedMeaningId = getCollectionMeaningId( $row->collection_id ); |
| 63 | + $queryResult = $dbr->query( "SELECT meaning_text_tcid FROM {$dc}_defined_meaning where defined_meaning_id = $collectionDefinedMeaningId" ); |
| 64 | + if ( $row = $dbr->fetchObject( $queryResult ) ){ |
| 65 | + $queryResult = $dbr->query( "SELECT text_id FROM {$dc}_translated_content where translated_content_id = $row->meaning_text_tcid" ); |
| 66 | + if ( $row = $dbr->fetchObject( $queryResult ) ){ |
| 67 | + $queryResult = $dbr->query( "SELECT text_text FROM {$dc}_text where text_id = $row->text_id" ); |
| 68 | + if ( $row = $dbr->fetchObject( $queryResult ) ){ |
| 69 | + if ( $row->text_text == "Swiss-Prot" ){ |
| 70 | + $collectionName = "uniprot"; |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + return $collectionName . '/' . $internalMemberId; |
| 77 | + } |
| 78 | + else{ |
| 79 | + return ""; |
| 80 | + } |
| 81 | + |
| 82 | +} |
| 83 | + |
| 84 | +function getTextForId( $dc, $text_id ){ |
| 85 | + $dbr = &wfGetDB(DB_SLAVE); |
| 86 | + $textResult = $dbr->query( "select text_text from {$dc}_text where text_id = $text_id" ); |
| 87 | + if ( $textRecord = $dbr->fetchObject($textResult) ){ |
| 88 | + return $textRecord->text_text; |
| 89 | + } |
| 90 | + else { |
| 91 | + return( "" ); |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +function getDefinedMeaningTitle( $dc, $definedMeaningId ){ |
| 96 | + $dbr = &wfGetDB(DB_SLAVE); |
| 97 | + $result = $dbr->query( "SELECT meaning_text_tcid FROM {$dc}_defined_meaning where defined_meaning_id = $definedMeaningId" ); |
| 98 | + if ( $record = $dbr->fetchObject($result) ){ |
| 99 | + $result = $dbr->query( "SELECT text_id FROM {$dc}_translated_content where translated_content_id = $record->meaning_text_tcid and remove_transaction_id IS NULL" ); |
| 100 | + if ( $record = $dbr->fetchObject($result) ){ |
| 101 | + return getTextForId( $dc, $record->text_id ) . "_(" . $definedMeaningId . ")"; |
| 102 | + } |
| 103 | + } |
| 104 | + return( "" ); |
| 105 | +} |
| 106 | + |
| 107 | +function getUser( $user_id ){ |
| 108 | + $dbr = &wfGetDB(DB_SLAVE); |
| 109 | + $queryResult = $dbr->query( "SELECT user_name FROM `user` u where user_id = $user_id" ); |
| 110 | + if ( $row = $dbr->fetchObject( $queryResult ) ){ |
| 111 | + return $row->user_name; |
| 112 | + } |
| 113 | + return "unknown"; |
| 114 | +} |
| 115 | + |
| 116 | +// XML Entity Mandatory Escape Characters |
| 117 | +function xmlentities($string) { |
| 118 | + return str_replace ( array ( '&', '"', "'", '<', '>', '�' ), array ( '&' , '"', ''' , '<' , '>', ''' ), $string ); |
| 119 | +} |
| 120 | + |
| 121 | +require (dirname(__FILE__) . '/includes/WebStart.php'); |
| 122 | +global $wgSitename; |
| 123 | + |
| 124 | +// Verify that the API has not been disabled |
| 125 | +if (!$wgEnableAPI) { |
| 126 | + echo 'MediaWiki API is not enabled for this site. Add the following line to your LocalSettings.php'; |
| 127 | + echo '<pre><b>$wgEnableAPI=true;</b></pre>'; |
| 128 | + die(-1); |
| 129 | +} |
| 130 | + |
| 131 | +// indicate here the dataset that contains the community version |
| 132 | +$dc = "uw"; |
| 133 | + |
| 134 | +// read the parameters passed as arguments to the alert program |
| 135 | +$responseType = $_GET["output"]; |
| 136 | +$epochStartDate = $_GET["startDate"]; |
| 137 | +$startDate = ConvertIsoToEpoch( $epochStartDate ); |
| 138 | +$epochEndDate = $_GET["endDate"]; |
| 139 | + |
| 140 | +if ( $epochStartDate == "" ){ |
| 141 | + echo 'This alert utility requires a start date in ISO format to be specified as parameter<BR>'; |
| 142 | + echo 'Usage: alert.php?startDate=2007-05-01-T00:00:00[&endDate=2007-06-31-T00:00:00][&output=(xml|raw)]<BR>'; |
| 143 | + die(-1); |
| 144 | +} |
| 145 | + |
| 146 | +if ( $epochEndDate != "" ){ |
| 147 | + $endDate = ConvertIsoToEpoch( $epochEndDate ); |
| 148 | + $endClause = " AND timestamp <= $endDate "; |
| 149 | +} |
| 150 | +else { |
| 151 | + $endClause = ""; |
| 152 | +} |
| 153 | + |
| 154 | +$dbr = &wfGetDB(DB_SLAVE); |
| 155 | + |
| 156 | +$queryResult = $dbr->query( "select language_id from language where wikimedia_key='en'" ); |
| 157 | +$languageId = $dbr->fetchObject($queryResult)->language_id; |
| 158 | + |
| 159 | +$transactionResult = $dbr->query( "select transaction_id, user_id, timestamp from {$dc}_transactions where timestamp >= $startDate $endClause" ); |
| 160 | +if ( $responseType == "xml" ){ |
| 161 | + echo "<edits startdate='$epochStartDate'"; |
| 162 | + if ( $epochEndDate != "" ){ |
| 163 | + echo " enddate='$epochEndDate'"; |
| 164 | + } |
| 165 | + echo ">"; |
| 166 | +} |
| 167 | + |
| 168 | +while ($transactionRecord = $dbr->fetchObject($transactionResult)) { |
| 169 | + $transaction_id = $transactionRecord->transaction_id; |
| 170 | + $timestamp = $transactionRecord->timestamp; |
| 171 | + $user = getUser( $transactionRecord->user_id ); |
| 172 | + |
| 173 | + $translatedContentResult = $dbr->query( "SELECT text_id FROM {$dc}_translated_content WHERE add_transaction_id = $transaction_id AND language_id=$languageId and remove_transaction_id IS NULL" ); |
| 174 | + while ($tranlatedContentRecord = $dbr->fetchObject($translatedContentResult)) { |
| 175 | + $definedMeaningId = getDefinedMeaning( $dc, $tranlatedContentRecord->text_id ); |
| 176 | + $text = xmlentities( getTextForId( $dc, $tranlatedContentRecord->text_id ) ); |
| 177 | + $internalIdentifier = getInternalIdentifier( $dc, $definedMeaningId, $languageId ); |
| 178 | + if ( $internalIdentifier != "" ){ |
| 179 | + $definedMeaningTitle = getDefinedMeaningTitle( $dc, $definedMeaningId ); |
| 180 | + $epochDate = ConvertEpochToIso($timestamp); |
| 181 | + if ( $responseType == "xml" ){ |
| 182 | + echo "<record><knowletid>$internalIdentifier</knowletid><text>$text</text><user>$user</user><timestamp>$epochDate</timestamp><definedmeaning>$definedMeaningTitle</definedmeaning><site>$wgSitename</site></record>"; |
| 183 | + } |
| 184 | + else { |
| 185 | + echo "$internalIdentifier|$text|$user|$epochDate|$definedMeaningTitle|$wgSitename\n"; |
| 186 | + } |
| 187 | + } |
| 188 | + } |
| 189 | +} |
| 190 | +if ( $responseType == "xml" ){ |
| 191 | + echo "</edits>"; |
| 192 | +} |
| 193 | + |
| 194 | + |
195 | 195 | ?> |
\ No newline at end of file |
Index: trunk/extensions/Wikidata/OmegaWiki/small/autoreplace.sh |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | #!/bin/bash |
3 | 3 | export myfile=$1; |
4 | 4 | |
5 | | -small/ra3.pl $myfile > $myfile.new && |
| 5 | +small/wfMsg.pl $myfile > $myfile.new && |
6 | 6 | mv $myfile.new $myfile |
Index: trunk/extensions/Wikidata/OmegaWiki/small/check.sh |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | #!/bin/bash |
3 | 3 | export myfile=$1; |
4 | 4 | |
5 | | -small/ra3.pl $myfile | |
| 5 | +small/wfMsg.pl $myfile | |
6 | 6 | diff -dy $myfile - | |
7 | 7 | less |