Permalink
Browse files

Resets parameters after validating an API URL. Adds a convenience met…

…hod in Scripto to validate an API URL.
  • Loading branch information...
1 parent 4487446 commit b06ac45e88b9f39ce5b7f3c20c25f95a43d4ffe0 Jim Safley committed May 14, 2011
Showing with 18 additions and 6 deletions.
  1. +11 −0 lib/Scripto.php
  2. +7 −6 lib/Scripto/Service/MediaWiki.php
View
@@ -411,4 +411,15 @@ public function getRevision($revisionId)
'html' => $response['parse']['text']['*']);
return $revision;
}
+
+ /**
+ * Determine whether the provided MediaWiki API URL is valid.
+ *
+ * @param string $apiUrl
+ * @return bool
+ */
+ static public function isValidApiUrl($apiUrl)
+ {
+ return Scripto_Service_MediaWiki::isValidApiUrl($apiUrl);
+ }
}
@@ -586,13 +586,14 @@ static public function isValidApiUrl($apiUrl)
}
// Ping the API endpoint for a valid response.
- $response = self::getHttpClient()->setUri($apiUrl)
- ->setParameterPost('action', 'query')
- ->setParameterPost('meta', 'siteinfo')
- ->setParameterPost('format', 'json')
- ->request('POST')->getBody();
+ $body = self::getHttpClient()->setUri($apiUrl)
+ ->setParameterPost('action', 'query')
+ ->setParameterPost('meta', 'siteinfo')
+ ->setParameterPost('format', 'json')
+ ->request('POST')->getBody();
+ self::getHttpClient()->resetParameters(true);
- $response = json_decode($response, true);
+ $response = json_decode($body, true);
if (!is_array($response) || !isset($response['query']['general'])) {
return false;
}

0 comments on commit b06ac45

Please sign in to comment.