/** * Saves the form submit for globalWatchlistSettings. * * @access public * @param array Valid site keys. * @return array List of visible site keys. */ public function globalWatchlistSettingsSave($siteKeys = []) { $gwl = globalWatchlist::newFromUser($this->wgUser); $success = false; if ($this->wgRequest->wasPosted()) { $sites = $this->wgRequest->getArray('sites'); foreach ($sites as $key => $siteKey) { if (!in_array($siteKey, $siteKeys)) { unset($sites[$key]); } } $gwl->setVisibleSites($sites); $success = true; } return ['visibleSites' => $gwl->getVisibleSites(), 'success' => $success]; }
/** * Handles removed watched articles to the global watch list. * * @access public * @param object User object of the user who unwatched this page. * @param object Article object of the unwatched page. * @return boolean True */ public static function onUnwatchArticleComplete(User $user, WikiPage $article) { if (!$article->mDataLoaded) { $article->loadPageData(); } $curseUser = \CurseAuthUser::getInstance($user); if (!$curseUser->getId() || $article->mTitle->mArticleID < 1) { return true; } //The newFromUser function will check if the user is valid. False will be return if not. $gwl = globalWatchlist::newFromUser($user); if ($gwl !== false && $gwl->removeArticle($article) === true) { //If removing the specific page the user requested to unwatch was successful then we need to remove the associated namespace page. $title = Title::newFromText($article->mTitle->getText(), MWNamespace::getAssociated($article->mTitle->mNamespace)); $associated = new WikiPage($title); if (!$associated->mDataLoaded) { $associated->loadPageData(); } $gwl->removeArticle($associated); //Save since at least the requested page to unwatch was successful lets save it. If the $associated page is not removed successfully we do not want it to stop the process. $success = $gwl->save(); } return true; }