Permalink
Browse files

Refs #12, adds watch and unwatch methods.

  • Loading branch information...
1 parent 141e5bd commit 62fb1a9b64381bce97e64f8fe10aa57aef4002de Jim Safley committed May 20, 2011
Showing with 95 additions and 0 deletions.
  1. +78 −0 lib/Scripto/Document.php
  2. +17 −0 lib/Scripto/Service/MediaWiki.php
View
@@ -425,6 +425,9 @@ public function editTalkPage($text)
*/
public function protectTranscriptionPage()
{
+ if (is_null($this->_pageId)) {
+ throw new Scripto_Exception('The document page must be set before protecting the transcription page.');
+ }
$this->_protectPage($this->_baseTitle, $this->_transcriptionPageInfo['protect_token']);
}
@@ -433,6 +436,9 @@ public function protectTranscriptionPage()
*/
public function protectTalkPage()
{
+ if (is_null($this->_pageId)) {
+ throw new Scripto_Exception('The document page must be set before protecting the talk page.');
+ }
$this->_protectPage('Talk:' . $this->_baseTitle, $this->_talkPageInfo['protect_token']);
}
@@ -441,6 +447,9 @@ public function protectTalkPage()
*/
public function unprotectTranscriptionPage()
{
+ if (is_null($this->_pageId)) {
+ throw new Scripto_Exception('The document page must be set before unprotecting the transcription page.');
+ }
$this->_unprotectPage($this->_baseTitle, $this->_transcriptionPageInfo['protect_token']);
}
@@ -449,9 +458,56 @@ public function unprotectTranscriptionPage()
*/
public function unprotectTalkPage()
{
+ if (is_null($this->_pageId)) {
+ throw new Scripto_Exception('The document page must be set before unprotecting the talk page.');
+ }
$this->_unprotectPage('Talk:' . $this->_baseTitle, $this->_talkPageInfo['protect_token']);
}
+ /**
+ * Watch the current transcription page.
+ */
+ public function watchTranscriptionPage()
+ {
+ if (is_null($this->_pageId)) {
+ throw new Scripto_Exception('The document page must be set before watching the transcription page.');
+ }
+ $this->_watchPage($this->_baseTitle);
+ }
+
+ /**
+ * Watch the current talk page.
+ */
+ public function watchTalkPage()
+ {
+ if (is_null($this->_pageId)) {
+ throw new Scripto_Exception('The document page must be set before watching the talk page.');
+ }
+ $this->_watchPage('Talk:' . $this->_baseTitle);
+ }
+
+ /**
+ * Unatch the current transcription page.
+ */
+ public function unwatchTranscriptionPage()
+ {
+ if (is_null($this->_pageId)) {
+ throw new Scripto_Exception('The document page must be set before unwatching the transcription page.');
+ }
+ $this->_unwatchPage($this->_baseTitle);
+ }
+
+ /**
+ * Unwatch the current talk page.
+ */
+ public function unwatchTalkPage()
+ {
+ if (is_null($this->_pageId)) {
+ throw new Scripto_Exception('The document page must be set before unwatching the talk page.');
+ }
+ $this->_unwatchPage('Talk:' . $this->_baseTitle);
+ }
+
/**
* Determine whether the current transcription page is edit protected.
*
@@ -669,6 +725,28 @@ protected function _unprotectPage($title, $protectToken)
$this->_mediawiki->protect($title, $protections, $protectToken);
}
+ /**
+ * Watch the specified page.
+ *
+ * @uses Scripto_Service_MediaWiki::watch()
+ * @param string $title
+ */
+ protected function _watchPage($title)
+ {
+ $this->_mediawiki->watch($title);
+ }
+
+ /**
+ * Unwatch the specified page.
+ *
+ * @uses Scripto_Service_MediaWiki::watch()
+ * @param string $title
+ */
+ protected function _unwatchPage($title)
+ {
+ $this->_mediawiki->watch($title, array('unwatch' => true));
+ }
+
/**
* Get information for the specified page.
*
@@ -64,6 +64,9 @@ class Scripto_Service_MediaWiki extends Zend_Service_Abstract
'protect' => array(
'title', 'token', 'protections', 'expiry', 'reason', 'cascade'
),
+ 'watch' => array(
+ 'title', 'unwatch'
+ ),
'query' => array(
// title specifications
'titles', 'revids', 'pageids',
@@ -415,6 +418,20 @@ public function query(array $params = array())
return $this->_request('query', $params);
}
+ /**
+ * Watch or unwatch pages.
+ *
+ * @link http://www.mediawiki.org/wiki/API:Watch
+ * @param string $title
+ * @param array $params
+ * @return array
+ */
+ public function watch($title, array $params = array())
+ {
+ $params['title'] = $title;
+ return $this->_request('watch', $params);
+ }
+
/**
* Applies protections to a given page.
*

0 comments on commit 62fb1a9

Please sign in to comment.