'') ? MakePageName($pagename, $pn) : $pagename; return (boolean)WatchPageVars($pn, "status"); } function WatchPageVars($pagename, $var) { global $Author, $AuthorPage, $WatchlistTrailFmt, $AuthorWatchlist; if(!$Author) { switch ($var) { case 'action' : return 'watch'; case 'status' : return '0'; case 'text' : return XL('Watch'); } return ''; # case 'trail' or some error } if(! isset($AuthorWatchlist)) { $AuthorListPage = FmtPageName($WatchlistTrailFmt, $AuthorPage); $AuthorWatchlist = array('~'=>$AuthorListPage); $trail = ReadTrail($AuthorListPage, $AuthorListPage); foreach($trail as $ar) $AuthorWatchlist[ $ar['pagename'] ] = 1; } switch ($var) { case 'trail' : return $AuthorWatchlist['~']; case 'action' : return (@$AuthorWatchlist[$pagename])? 'unwatch' : 'watch'; case 'status' : return (@$AuthorWatchlist[$pagename])? '1' : '0'; case 'text' : return (@$AuthorWatchlist[$pagename])? XL('Unwatch') : XL('Watch'); } return ''; # shouldn't happen } function HandleWatchUnwatch($pagename, $auth="edit") { global $Author, $AuthorPage, $AuthorRequiredFmt, $AuthorPromptFmt, $action, $ChangeSummary, $Now, $WatchlistTrailFmt, $WatchlistRedirectFmt, $WatchRedirectFunction, $EnablePost, $MessagesFmt, $WatchMultiplePages; $goto = (@$_REQUEST['goto']>'') ? MakePageName($pagename, @$_REQUEST['goto']) : ''; $action = strtolower($action); # we need an author name if(!$Author) { SDV($AuthorPromptFmt,array(&$PageStartFmt, $AuthorRequiredFmt, @"
$[Author]:
", &$PageEndFmt)); PrintFmt($pagename,$AuthorPromptFmt); exit; } $AuthorListPage = FmtPageName($WatchlistTrailFmt, $AuthorPage); if(!$goto) $goto = FmtPageName($WatchlistRedirectFmt, $AuthorPage); # we only watch pages if we can edit our watchlist trail $list = $new = RetrieveAuthPage($AuthorListPage, $auth, true); $trail = ReadTrail($AuthorListPage, $AuthorListPage); foreach(array_reverse($WatchMultiplePages) as $pn) { $new['text'] = WatchUnwatchSinglePage(FmtPageName($pn, $pagename), $action, $new['text'], $trail); } if($new['text']!=$list['text']) { $ChangeSummary = $_POST['csum'] = $new['csum'] = $new["csum:$Now"] = "$action $pagename"; UpdatePage($AuthorListPage, $list, $new); if(!$EnablePost) Abort(implode('', $MessagesFmt) . " $[Watchlist not saved]"); } $WatchRedirectFunction($goto); } function WatchUnwatchSinglePage($pagename, $action, $text, $trail) { $found = ''; foreach($trail as $ar) { if($ar['pagename']!=$pagename) continue; $found = preg_quote($ar['markup'].$ar['detail'], '/'); break; } if($action=='watch') { if(! $found) { $line = "\n* [[{$pagename}]] ([[{$pagename}?action=unwatch | $[Unwatch] ]])"; $anchor = "[[#AddToWatchlist]]"; $tparts = explode($anchor, $text, 2); array_splice($tparts, 1, 0, "$anchor$line"); $text = implode('', $tparts); } # else it already is in the list } elseif($action=='unwatch') { if($found) { $text = preg_replace("/(^|\n)\\s*([#*:]+)\\s*$found(\n|$)/", "\n", $text); } # else it already is NOT in the list } return $text; }