From 6674d672f130db2d4749b023dcbf07cb98724878 Mon Sep 17 00:00:00 2001 From: Xymph Date: Mon, 28 Jun 2021 20:28:46 +0200 Subject: [PATCH 1/4] Added debug logging of MediaWiki requests and responses --- CHANGELOG.md | 1 + Wikimate.php | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 393aa3f..00d09f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Since v0.10.0 this project adheres to [Semantic Versioning](http://semver.org/) #### Added +* Added more debug logging of MediaWiki requests and responses ([#101]) * New GOVERNANCE.md file to explicitly codify the project management principles and provide guidelines for maintenance tasks ([#83]) #### Changed diff --git a/Wikimate.php b/Wikimate.php index c5bc72c..e3bc1b2 100644 --- a/Wikimate.php +++ b/Wikimate.php @@ -267,8 +267,16 @@ public function query($array) $array['action'] = 'query'; $array['format'] = 'php'; + if ($this->debugMode) { + echo "query GET parameters:\n"; + echo http_build_query($array) . "\n"; + } $apiResult = $this->session->get($this->api.'?'.http_build_query($array)); + if ($this->debugMode) { + echo "query GET response:\n"; + print_r(unserialize($apiResult->body)); + } return unserialize($apiResult->body); } @@ -283,8 +291,16 @@ public function parse($array) $array['action'] = 'parse'; $array['format'] = 'php'; + if ($this->debugMode) { + echo "parse GET parameters:\n"; + echo http_build_query($array) . "\n"; + } $apiResult = $this->session->get($this->api.'?'.http_build_query($array)); + if ($this->debugMode) { + echo "parse GET response:\n"; + print_r(json_decode($apiResult->body)); + } return unserialize($apiResult->body); } @@ -309,8 +325,16 @@ public function edit($array) $array['format'] = 'php'; $array['token'] = $edittoken; + if ($this->debugMode) { + echo "edit POST parameters:\n"; + print_r($array); + } $apiResult = $this->session->post($this->api, $headers, $array); + if ($this->debugMode) { + echo "edit POST response:\n"; + print_r(unserialize($apiResult->body)); + } return unserialize($apiResult->body); } @@ -335,8 +359,16 @@ public function delete($array) $array['format'] = 'php'; $array['token'] = $deletetoken; + if ($this->debugMode) { + echo "delete POST parameters:\n"; + print_r($array); + } $apiResult = $this->session->post($this->api, $headers, $array); + if ($this->debugMode) { + echo "delete POST response:\n"; + print_r(unserialize($apiResult->body)); + } return unserialize($apiResult->body); } @@ -351,6 +383,10 @@ public function download($url) $getResult = $this->session->get($url); if (!$getResult->success) { + if ($this->debugMode) { + echo "download GET response:\n"; + print_r($getResult); + } $this->error = array(); $this->error['file'] = 'Download error (HTTP status: ' . $getResult->status_code . ')'; $this->error['http'] = $getResult->status_code; @@ -405,6 +441,10 @@ public function upload($array) $apiResult = $this->session->post($this->api, $headers, $body); + if ($this->debugMode) { + echo "upload POST response:\n"; + print_r(unserialize($apiResult->body)); + } return unserialize($apiResult->body); } From d146bb248caaec870b0ad5da3dda44d7a27ea763 Mon Sep 17 00:00:00 2001 From: Xymph Date: Mon, 28 Jun 2021 21:01:15 +0200 Subject: [PATCH 2/4] Use archive links for multipart body info --- Wikimate.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Wikimate.php b/Wikimate.php index e3bc1b2..633d206 100644 --- a/Wikimate.php +++ b/Wikimate.php @@ -412,7 +412,9 @@ public function upload($array) $array['format'] = 'php'; $array['token'] = $uploadtoken; - // Construct multipart body: https://www.mediawiki.org/wiki/API:Upload#Sample_Raw_Upload + // Construct multipart body: + // https://www.mediawiki.org/w/index.php?title=API:Upload&oldid=2293685#Sample_Raw_Upload + // https://www.mediawiki.org/w/index.php?title=API:Upload&oldid=2339771#Sample_Raw_POST_of_a_single_chunk $boundary = '---Wikimate-' . md5(microtime()); $body = ''; foreach ($array as $fieldName => $fieldData) { From 61c9dcac25537c9d2e4743d2040c5ad7678d949c Mon Sep 17 00:00:00 2001 From: Xymph Date: Mon, 28 Jun 2021 21:02:29 +0200 Subject: [PATCH 3/4] Use consistent conjugations in method descriptions --- Wikimate.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Wikimate.php b/Wikimate.php index 633d206..4317247 100644 --- a/Wikimate.php +++ b/Wikimate.php @@ -34,7 +34,7 @@ class Wikimate protected $debugMode = false; /** - * Create a new Wikimate object. + * Creates a new Wikimate object. * * @return Wikimate */ @@ -49,7 +49,7 @@ public function __construct($api, $headers = array(), $data = array(), $options } /** - * Set up a Requests_Session with appropriate user agent. + * Sets up a Requests_Session with appropriate user agent. * * @return void */ @@ -215,7 +215,7 @@ public function debugCurlConfig($echo = false) } /** - * Get or print the Requests configuration. + * Gets or prints the Requests configuration. * * @param boolean $echo Whether to echo the options * @return array Options if $echo is false @@ -508,7 +508,7 @@ public function __construct($title, $wikimate) } /** - * Forget all object properties. + * Forgets all object properties. * * @return Destructor */ @@ -809,7 +809,7 @@ public function getSection($section, $includeHeading = false, $includeSubsection } /** - * Return all the sections of the page in an array - the key names can be + * Returns all the sections of the page in an array - the key names can be * set to name or index by using the following for the second param: * - self::SECTIONLIST_BY_NAME * - self::SECTIONLIST_BY_INDEX @@ -974,7 +974,7 @@ public function newSection($name, $text) } /** - * Delete the page. + * Deletes the page. * * @param string $reason Reason for the deletion * @return boolean True if page was deleted successfully @@ -1011,7 +1011,7 @@ public function delete($reason = null) */ /** - * Find a section's index by name. + * Finds a section's index by name. * If a section index or 'new' is passed, it is returned directly. * * @param mixed $section The section name or index to find @@ -1084,7 +1084,7 @@ public function __construct($filename, $wikimate) } /** - * Forget all object properties. + * Forgets all object properties. * * @return Destructor */ @@ -1826,7 +1826,7 @@ public function getArchivename($revision) } /** - * Delete the file, or only an older revision of it. + * Deletes the file, or only an older revision of it. * * @param string $reason Reason for the deletion * @param string $archivename The archive name of the older revision From 0f2ee8cb96eaaa4339bdbab4f9aa225a6e3835dc Mon Sep 17 00:00:00 2001 From: Xymph Date: Tue, 29 Jun 2021 23:31:15 +0200 Subject: [PATCH 4/4] Mention files in Wikimate header --- Wikimate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Wikimate.php b/Wikimate.php index 4317247..087f7be 100644 --- a/Wikimate.php +++ b/Wikimate.php @@ -7,7 +7,7 @@ /// ============================================================================= /** - * Provides an interface over wiki API objects such as pages. + * Provides an interface over wiki API objects such as pages and files. * * @author Robert McLeod * @since December 2010