Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix watch and unwatch pages. Fix #12.

  • Loading branch information...
commit 51d3f237dc8b466a4efe0a1b22c4a5e10ccc7bfb 1 parent c6442c9
@jimsafley jimsafley authored
View
4 README.md
@@ -130,4 +130,6 @@ Changelog
-------------
* 1.1
- * Add option to retain specified HTML attributes.
+ * Add option to retain specified HTML attributes.
+* 1.1.1
+ * Fix watch and unwatch pages.
View
2  lib/Scripto.php
@@ -31,7 +31,7 @@ class Scripto
/**
* This Scripto version.
*/
- const VERSION = '1.1';
+ const VERSION = '1.1.1';
/**
* @var Scripto_Adapter_Interface The adapter object for the external
View
2  lib/Scripto/Document.php
@@ -543,7 +543,7 @@ public function unwatchPage()
if (is_null($this->_pageId)) {
throw new Scripto_Exception('The document page must be set before unwatching the page.');
}
- $this->_mediawiki->watch($this->_baseTitle, array('unwatch' => true));
+ $this->_mediawiki->watch($this->_baseTitle, null, array('unwatch' => true));
}
/**
View
28 lib/Scripto/Service/MediaWiki.php
@@ -64,7 +64,7 @@ class Scripto_Service_MediaWiki extends Zend_Service_Abstract
'title', 'token', 'protections', 'expiry', 'reason', 'cascade'
),
'watch' => array(
- 'title', 'unwatch'
+ 'title', 'unwatch', 'token'
),
'query' => array(
// title specifications
@@ -331,6 +331,25 @@ public function getProtectToken($title)
}
/**
+ * Gets the watch token for a given page.
+ *
+ * @link http://www.mediawiki.org/wiki/API:Watch#Token
+ * @param string $title
+ * @return string
+ */
+ public function getWatchToken($title)
+ {
+ $response = $this->getInfo($title, array('intoken' => 'watch'));
+ $page = current($response['query']['pages']);
+
+ $watchtoken = null;
+ if (isset($page['watchtoken'])) {
+ $watchtoken = $page['watchtoken'];
+ }
+ return $watchtoken;
+ }
+
+ /**
* Gets the protections for a given page.
*
* @link http://www.mediawiki.org/wiki/API:Properties#info_.2F_in
@@ -451,9 +470,14 @@ public function query(array $params = array())
* @param array $params
* @return array
*/
- public function watch($title, array $params = array())
+ public function watch($title, $watchtoken = null, array $params = array())
{
+ // Get the watch token if not passed.
+ if (is_null($watchtoken)) {
+ $watchtoken = $this->getWatchToken($title);
+ }
$params['title'] = $title;
+ $params['token'] = $watchtoken;
return $this->_request('watch', $params);
}
Please sign in to comment.
Something went wrong with that request. Please try again.