summaryrefslogtreecommitdiff
path: root/includes/AjaxFunctions.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/AjaxFunctions.php')
-rw-r--r--includes/AjaxFunctions.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/includes/AjaxFunctions.php b/includes/AjaxFunctions.php
index 9f7a332f..eee2a1a4 100644
--- a/includes/AjaxFunctions.php
+++ b/includes/AjaxFunctions.php
@@ -129,4 +129,43 @@ function wfSajaxSearch( $term ) {
return $response;
}
+/**
+ * Called for AJAX watch/unwatch requests.
+ * @param $pageID Integer ID of the page to be watched/unwatched
+ * @param $watch String 'w' to watch, 'u' to unwatch
+ * @return String '<w#>' or '<u#>' on successful watch or unwatch, respectively, or '<err#>' on error (invalid XML in case we want to add HTML sometime)
+ */
+function wfAjaxWatch($pageID = "", $watch = "") {
+ if(wfReadOnly())
+ return '<err#>'; // redirect to action=(un)watch, which will display the database lock message
+
+ if(('w' !== $watch && 'u' !== $watch) || !is_numeric($pageID))
+ return '<err#>';
+ $watch = 'w' === $watch;
+ $pageID = intval($pageID);
+
+ $title = Title::newFromID($pageID);
+ if(!$title)
+ return '<err#>';
+ $article = new Article($title);
+ $watching = $title->userIsWatching();
+
+ if($watch) {
+ if(!$watching) {
+ $dbw =& wfGetDB(DB_MASTER);
+ $dbw->begin();
+ $article->doWatch();
+ $dbw->commit();
+ }
+ } else {
+ if($watching) {
+ $dbw =& wfGetDB(DB_MASTER);
+ $dbw->begin();
+ $article->doUnwatch();
+ $dbw->commit();
+ }
+ }
+
+ return $watch ? '<w#>' : '<u#>';
+}
?>