Skip to content

Commit

Permalink
Merge pull request #106 from hamstar/assorted-fixes
Browse files Browse the repository at this point in the history
Assorted fixes
  • Loading branch information
Xymph authored Jul 5, 2021
2 parents 12f25bc + a8bdcfa commit 1ed84e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ Since v0.10.0 this project adheres to [Semantic Versioning](http://semver.org/)

#### Added

* Added more debug logging of MediaWiki requests and responses ([#101])
* Added more debug logging of MediaWiki requests and responses ([#101], [#106])
* New GOVERNANCE.md file to explicitly codify the project management principles and provide guidelines for maintenance tasks ([#83], [#105])

#### Changed

* Modernize token handling for login and data-modifying actions ([#100])
* Modernize token handling for login and data-modifying actions ([#100], [#106])

#### Fixed

* Prevented PHP notice in `WikiFile::getInfo()` for moved or deleted file ([#85])
* Fixed capitalization of a built-in PHP class in a comment ([#106])

### Version 0.12.0 - 2017-02-03

Expand Down Expand Up @@ -107,3 +108,4 @@ Since v0.10.0 this project adheres to [Semantic Versioning](http://semver.org/)
[#100]: https://github.com/hamstar/Wikimate/pull/100
[#101]: https://github.com/hamstar/Wikimate/pull/101
[#105]: https://github.com/hamstar/Wikimate/pull/105
[#106]: https://github.com/hamstar/Wikimate/pull/106
3 changes: 1 addition & 2 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ print_r($page->getError());

For MediaWiki API errors, the array contains the 'code' and 'info' key/value pairs [defined by the API](https://www.mediawiki.org/wiki/API:Errors_and_warnings#Errors). For other errors, the following key/value pairs are returned:
* 'login' for Wikimate authentication problems
* 'token' for Wikimate token problems
* 'page' for WikiPage errors
* 'file' for WikiFile errors

Expand All @@ -309,7 +310,6 @@ You can use the edit and query commands in Wikimate:
```php
$data = array(
'prop' => 'info|revisions',
'intoken' => 'edit',
'titles' => 'this|that|other'
);

Expand All @@ -318,7 +318,6 @@ $array_result = $wiki->query($data);

$data = array(
'title' => 'this',
'token' => '+\\', // this is urlencoded automatically
'etc' => 'stuff'
);

Expand Down
12 changes: 7 additions & 5 deletions Wikimate.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ protected function initRequests()
* For now this method, in Wikimate tradition, is kept simple and supports
* only the two token types needed elsewhere in the library. It also
* doesn't support the option to request multiple tokens at once.
* See https://www.mediawiki.org/wiki/Special:MyLanguage/API:Tokens
* for more information.
*
* @param string $type The token type
* @return string The requested token
Expand All @@ -75,7 +77,7 @@ protected function token($type = self::TOKEN_DEFAULT)
// Check for supported token types
if ($type != self::TOKEN_DEFAULT && $type != self::TOKEN_LOGIN) {
$this->error = array();
$this->error['login'] = 'The API does not support the token type';
$this->error['token'] = 'The API does not support the token type';
return false;
}

Expand All @@ -91,15 +93,15 @@ protected function token($type = self::TOKEN_DEFAULT)
// Check if we got an API result or the API doc page (invalid request)
if (strpos($response->body, "This is an auto-generated MediaWiki API documentation page") !== false) {
$this->error = array();
$this->error['login'] = 'The API could not understand the token request';
$this->error['token'] = 'The API could not understand the token request';
return false;
}

$tokenResult = json_decode($response->body);
// Check if we got a JSON result
if ($tokenResult === null) {
$this->error = array();
$this->error['login'] = 'The API did not return the token response';
$this->error['token'] = 'The API did not return the token response';
return false;
}

Expand Down Expand Up @@ -299,7 +301,7 @@ public function parse($array)

if ($this->debugMode) {
echo "parse GET response:\n";
print_r(json_decode($apiResult->body));
print_r(unserialize($apiResult->body));
}
return unserialize($apiResult->body);
}
Expand Down Expand Up @@ -608,7 +610,7 @@ public function getNumSections()
/**
* Returns the sections offsets and lengths.
*
* @return StdClass Section class
* @return stdClass Section class
*/
public function getSectionOffsets()
{
Expand Down

0 comments on commit 1ed84e5

Please sign in to comment.