From 757d238cf6d306f9daf8276f620415cf09f4afe6 Mon Sep 17 00:00:00 2001
From: Magnus Manske " ; print_r ( $command ) ; print "
" ;
}
// TODO proper error handling
From 5175807fcf7468cc9387f60035ac5411d7221837 Mon Sep 17 00:00:00 2001
From: jmformenti Here, you can generate a token to use when submitting bat
For this to work, you need to have run a batch (server side) before manually, so your OAuth details can be filled in.
curl https://quickstatements.toolforge.org/api.php \ -d action=import \ -d submit=1 \ + -d format=FORMAT \ -d username={{encodeURIComponent(user.getUserName().replace(/ /g,'_'))}} \ -d "batchname=THE NAME OF THE BATCH" \ --data-raw 'token={{token}}' \ From b0163e741c80d711b9da6bdb974d7f3922282b5a Mon Sep 17 00:00:00 2001 From: addshoreDate: Fri, 17 Feb 2023 15:57:15 +0000 Subject: [PATCH 08/17] api.php, ignore E_DEPRECATED errors These break the API when using later verisons of PHP8 as deprecation warnings are printed. https://github.com/wmde/wikibase-release-pipeline/pull/398#issuecomment-1434823727 As this is hardcoded and can't be overwritten by the php.ini file it's probably worth having a default that is less broken --- public_html/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public_html/api.php b/public_html/api.php index 20b6909..2e0a59b 100644 --- a/public_html/api.php +++ b/public_html/api.php @@ -1,6 +1,6 @@ Date: Mon, 27 Feb 2023 20:45:23 +0100 Subject: [PATCH 09/17] Fix statement creation in CSV mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was broken by 8d516dea58. The new $statement field 'new_statement' is checked via isset() in getStatementID(), but unconditionally assumed to exist in compressCommands(). However, only importDataFromV1() was taught to create this field, while importDataFromCSV() wasn’t. This meant that parsing CSV statements would produce a PHP warning, which is included in the web response and thus breaks the JSON output. Fixes #38. An alternative would be to guard the access in compressCommands(); the easiest option would be the `??` operator, but that was only added in PHP 7.0 and I don’t really want to risk breaking sites that use QuickStatements on older PHP (even though PHP 7.0 has been out for a while already). --- public_html/quickstatements.php | 1 + 1 file changed, 1 insertion(+) diff --git a/public_html/quickstatements.php b/public_html/quickstatements.php index d137d23..2f47abc 100644 --- a/public_html/quickstatements.php +++ b/public_html/quickstatements.php @@ -1382,6 +1382,7 @@ protected function importDataFromCSV ( $data, &$ret ) { if ( $instruction[0] === 'P' ) { $command += [ 'what' => 'statement', + 'new_statement' => 0, 'property' => $instruction ]; $this->parseValueV1( $value, $command ); From 2af6eeb30a4284039773b1115bbc4563ed6d3ed4 Mon Sep 17 00:00:00 2001 From: Lucas Werkmeister Date: Mon, 27 Feb 2023 21:05:58 +0100 Subject: [PATCH 10/17] =?UTF-8?q?Don=E2=80=99t=20try=20to=20send=20incompl?= =?UTF-8?q?ete=20values=20to=20the=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If parseValueV1() can’t parse the value, the $cmd it returns will still have a 'datavalue', but there won’t be a 'value' inside it (but rather a 'text', along with 'type'=>'unknown'). This is apparently not checked at any intervening point (neither in the V1 nor CSV formats), and eventually the commandAdd*() methods would try to send the incomplete data to the API, after producing several PHP warnings due to the missing value (several of them inside getSnakType()), which would also break the JSON response as usual. Work around this by checking if we have a value just before sending the API request. This means that the bad values will still be shown in the batch view in a weird format (raw JSON), but I don’t know how that should be fixed instead. This at least fixes the server-side warnings and makes the batch not stuck indefinitely. --- public_html/quickstatements.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/public_html/quickstatements.php b/public_html/quickstatements.php index d137d23..8a97fef 100644 --- a/public_html/quickstatements.php +++ b/public_html/quickstatements.php @@ -907,6 +907,7 @@ protected function getPrefixedID ( $q ) { protected function commandAddStatement ( $command , $i , $statement_id ) { // Paranoia if ( isset($statement_id) ) return $this->commandDone ( $command , "Statement already exists as $statement_id" ) ; + if ( !isset($command->datavalue->value) ) return $this->commandError ( $command, "Incomplete command parameters" ) ; // Execute! $action = array ( @@ -931,6 +932,7 @@ protected function commandAddQualifier ( $command , $i , $statement_id ) { if ( !isset($command->qualifier) ) return $this->commandError ( $command , "Incomplete command parameters" ) ; if ( !isset($command->qualifier->prop) ) return $this->commandError ( $command , "Incomplete command parameters" ) ; if ( !preg_match ( '/^P\d+$/' , $command->qualifier->prop ) ) return $this->commandError ( $command , "Invalid qualifier property {$command->qualifier->prop}" ) ; + if ( !isset($command->qualifier->value->value) ) return $this->commandError ( $command, "Incomplete command parameters" ) ; // Execute! $action = array ( @@ -957,6 +959,7 @@ protected function commandAddSources ( $command , $i , $statement_id ) { // Prep $snaks = array() ; foreach ( $command->sources AS $source ) { + if ( !isset($source->value->value) ) return $this->commandError ( $command, "Incomplete command parameters" ) ; $s = array( 'snaktype' => $this->getSnakType ( $source->value ) , 'property' => $source->prop , From 8fb6cf24c181bfcd45bde3d5263f4edee125ca74 Mon Sep 17 00:00:00 2001 From: Magnus Manske Date: Tue, 11 Apr 2023 12:12:02 +0000 Subject: [PATCH 11/17] weird message default text --- public_html/quickstatements.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public_html/quickstatements.php b/public_html/quickstatements.php index 4ff9e0f..7e26252 100644 --- a/public_html/quickstatements.php +++ b/public_html/quickstatements.php @@ -165,7 +165,7 @@ public function addBatch ( $commands , $user_id , $name = '' , $site = '' ) { if ( $this->use_command_compression ) $commands = $this->compressCommands ( $commands ) ; $db = $this->getDB() ; $ts = $this->getCurrentTimestamp() ; - $sql = "INSERT INTO batch (name,user,site,ts_created,ts_last_change,status) VALUES ('".$db->real_escape_string($name)."',$user_id,'".$db->real_escape_string($site)."','$ts','$ts','LOADING')" ; + $sql = "INSERT INTO batch (name,user,site,ts_created,ts_last_change,status,message) VALUES ('".$db->real_escape_string($name)."',$user_id,'".$db->real_escape_string($site)."','$ts','$ts','LOADING','')" ; if(!$result = $db->query($sql)) return $this->setErrorMessage ( 'There was an error running the query [' . $db->error . ']'."\n$sql" ) ; $batch_id = $db->insert_id ; $serialized = serialize($this->getOA()) ; @@ -181,7 +181,7 @@ public function addBatch ( $commands , $user_id , $name = '' , $site = '' ) { if ( trim($cs) == '' ) continue ; // Paranoia $status = 'INIT' ; if ( isset($c->status) and trim($c->status) != '' ) $status = strtoupper(trim($c->status)) ; - $sql = "INSERT INTO command (batch_id,num,json,status,ts_change) VALUES ($batch_id,$k,'".$db->real_escape_string($cs)."','".$db->real_escape_string($status)."','$ts')" ; + $sql = "INSERT INTO command (batch_id,num,json,status,ts_change,message) VALUES ($batch_id,$k,'".$db->real_escape_string($cs)."','".$db->real_escape_string($status)."','$ts','')" ; if(!$result = $db->query($sql)) return $this->setErrorMessage ( 'There was an error running the query [' . $db->error . ']'."\n$sql" ) ; } $sql = "UPDATE batch SET status='INIT' WHERE id=$batch_id" ; From d7c084d9bec73510a244cb3c60ec14d44283969c Mon Sep 17 00:00:00 2001 From: Lucas Werkmeister Date: Wed, 21 Jun 2023 20:13:09 +0200 Subject: [PATCH 12/17] Fix setting sitelinks Basically the same as commit 4622f78d55, just for another API action. No Wikibase API needs entity IDs with namespaces ("Item:Q24"). --- public_html/quickstatements.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/public_html/quickstatements.php b/public_html/quickstatements.php index 7e26252..7705eca 100644 --- a/public_html/quickstatements.php +++ b/public_html/quickstatements.php @@ -894,16 +894,6 @@ protected function getSnakType ( $datavalue ) { return 'value' ; } - protected function getPrefixedID ( $q ) { - $q = trim ( strtoupper ( $q ) ) ; - - foreach ( $this->getSite()->types AS $char => $data ) { - if ( !isset($data->ns_prefix) or $data->ns_prefix == '' ) continue ; - if ( preg_match ( '/^'.$char.'\d+$/' , $q ) ) return $data->ns_prefix.$q ; - } - return $q ; - } - protected function commandAddStatement ( $command , $i , $statement_id ) { // Paranoia if ( isset($statement_id) ) return $this->commandDone ( $command , "Statement already exists as $statement_id" ) ; @@ -1055,7 +1045,7 @@ protected function commandSetSitelink ( $command , $i ) { // Execute! $this->runAction ( array ( 'action' => 'wbsetsitelink' , - 'id' => $this->getPrefixedID ( $command->item ) , + 'id' => $command->item , 'linksite' => $command->site , 'linktitle' => $command->value , 'summary' => '' , From 8ed0601d447e26c45bee27056c221b9761c790a1 Mon Sep 17 00:00:00 2001 From: Magnus Manske Date: Wed, 21 Jun 2023 19:37:04 +0000 Subject: [PATCH 13/17] misc --- public_html/quickstatements.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public_html/quickstatements.php b/public_html/quickstatements.php index 7e26252..7e06318 100644 --- a/public_html/quickstatements.php +++ b/public_html/quickstatements.php @@ -746,7 +746,7 @@ protected function getBotAPI ( $force_login = false ) { } - public function runBotAction ( $params_orig , $attempts_left = 1000 , $lag = 0 ) { + public function runBotAction ( $params_orig , $attempts_left = 10 , $lag = 0 ) { if ( $attempts_left <= 0 ) return false ; if ( $lag == 0 ) $lag = $this->maxlag ; $params = array() ; From 549be5e961b95d6b2aa59c99f2eb9ec41d1b8c1d Mon Sep 17 00:00:00 2001 From: Magnus Manske Date: Mon, 8 Jul 2024 11:02:38 +0100 Subject: [PATCH 14/17] reset bugfix --- public_html/vue_components/batch.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/public_html/vue_components/batch.html b/public_html/vue_components/batch.html index 7222b87..e82440c 100644 --- a/public_html/vue_components/batch.html +++ b/public_html/vue_components/batch.html @@ -287,11 +287,12 @@ var me = this ; if ( me.meta.batch.id == 0 ) { // In browser $.each ( me.meta.batch.data.commands , function ( k , cmd ) { - if ( typeof cmd.meta == 'undefined' || typeof cmd.meta.status == 'undefined' || cmd.meta.status != 'ERROR' ) return ; + if ( typeof cmd.meta == 'undefined' || typeof cmd.meta.status == 'undefined' || (cmd.meta.status != 'ERROR' && cmd.meta.status != 'RUN') ) return ; if ( cmd.action == 'CREATE' && typeof cmd.data == 'undefined' ) return ; if ( typeof cmd.item != 'undefined' && cmd.item == 'LAST' ) return ; + let old_status = cmd.meta.status; cmd.meta.status = 'INIT' ; - Vue.set ( me.meta.commands , 'ERROR' , (me.meta.commands.ERROR||0)-1 ) ; + Vue.set ( me.meta.commands , old_status , (me.meta.commands.ERROR||0)-1 ) ; Vue.set ( me.meta.commands , 'INIT' , (me.meta.commands.INIT||0)+1 ) ; } ) ; } else { From 994f57c195a388452d42044e86ba3b33088cbe71 Mon Sep 17 00:00:00 2001 From: Magnus Manske Date: Mon, 8 Jul 2024 17:20:51 +0000 Subject: [PATCH 15/17] bugfix --- public_html/vue_components/batch.html | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/public_html/vue_components/batch.html b/public_html/vue_components/batch.html index e82440c..ce57810 100644 --- a/public_html/vue_components/batch.html +++ b/public_html/vue_components/batch.html @@ -351,6 +351,10 @@ else j.summary = me.run.temp_id + "; " + j.summary ; $('#working').show() ; + me.actuallyRunCommand(j,original_summary,cmdnum,5); + }, + actuallyRunCommand: function ( j , original_summary , cmdnum , attempts_left ) { + let me = this; $.post ( me.api , { action:'run_single_command', command : JSON.stringify(j) , @@ -374,7 +378,14 @@ setTimeout ( function () { me.runNextCommand() } , me.direct_command_delay_ms ) ; me.run.last_ts = me.getTimestampNow() ; } , 'json' ) - . fail ( function () { + . fail ( function(xhr, status, error) { + if ( attempts_left > 0 ) { + // Try again after two seconds + setTimeout ( function() { + me.actuallyRunCommand( j , original_summary , cmdnum , attempts_left-1 ); + } , 2000 ); + return; + } $('#working').hide() ; if ( typeof d.command.message != 'undefined' ) d.command.meta.message = d.command.message ; // d.command.summary = original_summary ; // To remove the temporary_batch From 83b9fe3534a606662fd6dceb152041796bd9fbc4 Mon Sep 17 00:00:00 2001 From: dena Date: Fri, 31 Jan 2025 12:03:11 +0100 Subject: [PATCH 16/17] avoid float to int conversion --- public_html/quickstatements.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public_html/quickstatements.php b/public_html/quickstatements.php index 8ea6add..1849b59 100644 --- a/public_html/quickstatements.php +++ b/public_html/quickstatements.php @@ -1116,7 +1116,7 @@ public function getTemporaryBatchSummary () { } public function runSingleCommand ( $command ) { - if ( $this->sleep != 0 ) sleep ( $this->sleep ) ; + if ( $this->sleep != 0 ) sleep ( $this->usleep * 1000 ) ; if ( !isset($command) ) return $this->commandError ( $command , "Empty command" ) ; $command->status = 'working' ; if ( isset($command->error) ) unset ( $command->error ) ; From d8ab836bbd1386f9bcbf9993314894fbd112d7a5 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 11 Feb 2025 14:26:10 +0100 Subject: [PATCH 17/17] add pending upstream fix https://github.com/magnusmanske/quickstatements/pull/60 --- public_html/quickstatements.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public_html/quickstatements.php b/public_html/quickstatements.php index 34cfe51..fca7bbf 100644 --- a/public_html/quickstatements.php +++ b/public_html/quickstatements.php @@ -1141,7 +1141,7 @@ public function getTemporaryBatchSummary () { } public function runSingleCommand ( $command ) { - if ( $this->sleep != 0 ) sleep ( $this->usleep * 1000 ) ; + if ( $this->sleep != 0 ) usleep ( $this->sleep * 1000 ) ; if ( !isset($command) ) return $this->commandError ( $command , "Empty command" ) ; $command->status = 'working' ; if ( isset($command->error) ) unset ( $command->error ) ;