Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 53 additions & 11 deletions Wikimate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,7 +34,7 @@ class Wikimate
protected $debugMode = false;

/**
* Create a new Wikimate object.
* Creates a new Wikimate object.
*
* @return Wikimate
*/
Expand All @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand All @@ -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));
Comment thread
Xymph marked this conversation as resolved.
}
return unserialize($apiResult->body);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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;
Expand All @@ -376,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) {
Expand Down Expand Up @@ -405,6 +443,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);
}

Expand Down Expand Up @@ -466,7 +508,7 @@ public function __construct($title, $wikimate)
}

/**
* Forget all object properties.
* Forgets all object properties.
*
* @return <type> Destructor
*/
Expand Down Expand Up @@ -767,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
Expand Down Expand Up @@ -932,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
Expand Down Expand Up @@ -969,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
Expand Down Expand Up @@ -1042,7 +1084,7 @@ public function __construct($filename, $wikimate)
}

/**
* Forget all object properties.
* Forgets all object properties.
*
* @return <type> Destructor
*/
Expand Down Expand Up @@ -1784,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
Expand Down