function doEdit($edit) { // create "fake" EditPage $editor = (object) array('textbox1' => isset($edit['text']) ? $edit['text'] : ''); // try to get section name MyHome::getSectionName($editor, '', !empty($edit['section']) ? $edit['section'] : false, $errno); // create "fake" RecentChange object $row = (object) array('rev_timestamp' => time(), 'rev_user' => 1, 'rev_user_text' => 'test', 'page_namespace' => NS_MAIN, 'page_title' => 'Test', 'rev_comment' => isset($edit['comment']) ? $edit['comment'] : '', 'rev_minor_edit' => true, 'page_is_new' => !empty($edit['is_new']), 'page_id' => 1, 'rev_id' => 1, 'rc_id' => 1, 'rc_patrolled' => 1, 'rc_old_len' => 1, 'rc_new_len' => 1, 'rc_deleted' => 1, 'rc_timestamp' => time()); $rc = RecentChange::newFromCurRow($row); // call MyHome to add its data to rc object and Wikia vars MyHome::storeInRecentChanges($rc); $data = Wikia::getVar('rc_data'); unset($data['articleComment']); return $data; }
/** * Entrypoint * @param string $par parent page we will look at */ function wfSpecialRecentchangeslinked($par = NULL) { global $wgUser, $wgOut, $wgLang, $wgContLang, $wgTitle, $wgRequest; $fname = 'wfSpecialRecentchangeslinked'; $days = $wgRequest->getInt('days'); $target = isset($par) ? $par : $wgRequest->getText('target'); $hideminor = $wgRequest->getBool('hideminor') ? 1 : 0; $wgOut->setPagetitle(wfMsg('recentchangeslinked')); $sk = $wgUser->getSkin(); if (is_null($target)) { $wgOut->errorpage('notargettitle', 'notargettext'); return; } $nt = Title::newFromURL($target); if (!$nt) { $wgOut->errorpage('notargettitle', 'notargettext'); return; } $id = $nt->getArticleId(); $wgOut->setSubtitle(htmlspecialchars(wfMsg('rclsub', $nt->getPrefixedText()))); if (!$days) { $days = $wgUser->getOption('rcdays'); if (!$days) { $days = 7; } } $days = (int) $days; list($limit, $offset) = wfCheckLimits(100, 'rclimit'); $dbr =& wfGetDB(DB_SLAVE); $cutoff = $dbr->timestamp(time() - $days * 86400); $hideminor = $hideminor ? 1 : 0; if ($hideminor) { $mlink = $sk->makeKnownLink($wgContLang->specialPage('Recentchangeslinked'), WfMsg('show'), 'target=' . htmlspecialchars($nt->getPrefixedURL()) . "&days={$days}&limit={$limit}&hideminor=0"); } else { $mlink = $sk->makeKnownLink($wgContLang->specialPage("Recentchangeslinked"), WfMsg("hide"), "target=" . htmlspecialchars($nt->getPrefixedURL()) . "&days={$days}&limit={$limit}&hideminor=1"); } if ($hideminor) { $cmq = 'AND rev_minor_edit=0'; } else { $cmq = ''; } extract($dbr->tableNames('categorylinks', 'pagelinks', 'revision', 'page')); // If target is a Category, use categorylinks and invert from and to if ($nt->getNamespace() == NS_CATEGORY) { $catkey = $dbr->addQuotes($nt->getDBKey()); $sql = "SELECT page_id,page_namespace,page_title,rev_id,rev_user,rev_comment,\n rev_user_text,rev_timestamp,rev_minor_edit,\n page_is_new\n FROM {$categorylinks}, {$revision}, {$page}\n WHERE rev_timestamp > '{$cutoff}'\n {$cmq}\n AND rev_page=page_id\n AND cl_from=page_id\n AND cl_to={$catkey}\nGROUP BY page_id,page_namespace,page_title,\n rev_user,rev_comment,rev_user_text,rev_timestamp,rev_minor_edit,\n page_is_new\nORDER BY rev_timestamp DESC\n LIMIT {$limit}"; } else { $sql = "SELECT page_id,page_namespace,page_title,\n rev_user,rev_comment,rev_user_text,rev_id,rev_timestamp,rev_minor_edit,\n page_is_new\n FROM {$pagelinks}, {$revision}, {$page}\n WHERE rev_timestamp > '{$cutoff}'\n {$cmq}\n AND rev_page=page_id\n AND pl_namespace=page_namespace\n AND pl_title=page_title\n AND pl_from={$id}\nGROUP BY page_id,page_namespace,page_title,\n rev_user,rev_comment,rev_user_text,rev_timestamp,rev_minor_edit,\n page_is_new\nORDER BY rev_timestamp DESC\n LIMIT {$limit}"; } $res = $dbr->query($sql, $fname); $wgOut->addHTML("< " . $sk->makeKnownLinkObj($nt, "", "redirect=no") . "<br />\n"); $note = wfMsg("rcnote", $limit, $days); $wgOut->addHTML("<hr />\n{$note}\n<br />"); $note = rcDayLimitlinks($days, $limit, "Recentchangeslinked", "target=" . $nt->getPrefixedURL() . "&hideminor={$hideminor}", false, $mlink); $wgOut->addHTML($note . "\n"); $list =& new ChangesList($sk); $s = $list->beginRecentChangesList(); $count = $dbr->numRows($res); $counter = 1; while ($limit) { if (0 == $count) { break; } $obj = $dbr->fetchObject($res); --$count; $rc = RecentChange::newFromCurRow($obj); $rc->counter = $counter++; $s .= $list->recentChangesLine($rc); --$limit; } $s .= $list->endRecentChangesList(); $dbr->freeResult($res); $wgOut->addHTML($s); }
/** * Constructor * @todo Document $par parameter. * @param $par String: FIXME */ function wfSpecialWatchlist($par) { global $wgUser, $wgOut, $wgLang, $wgMemc, $wgRequest, $wgContLang; global $wgUseWatchlistCache, $wgWLCacheTimeout, $wgDBname; global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker; global $wgEnotifWatchlist; $fname = 'wfSpecialWatchlist'; $skin =& $wgUser->getSkin(); $specialTitle = Title::makeTitle(NS_SPECIAL, 'Watchlist'); $wgOut->setRobotPolicy('noindex,nofollow'); # Anons don't get a watchlist if ($wgUser->isAnon()) { $wgOut->setPageTitle(wfMsg('watchnologin')); $llink = $skin->makeKnownLinkObj(Title::makeTitle(NS_SPECIAL, 'Userlogin'), wfMsgHtml('loginreqlink'), 'returnto=' . $specialTitle->getPrefixedUrl()); $wgOut->addHtml(wfMsgWikiHtml('watchlistanontext', $llink)); return; } else { $wgOut->setPageTitle(wfMsg('watchlist')); $wgOut->setSubtitle(wfMsgWikiHtml('watchlistfor', htmlspecialchars($wgUser->getName()))); } if (wlHandleClear($wgOut, $wgRequest, $par)) { return; } $defaults = array('days' => floatval($wgUser->getOption('watchlistdays')), 'hideOwn' => (int) $wgUser->getBoolOption('watchlisthideown'), 'hideBots' => (int) $wgUser->getBoolOption('watchlisthidebots'), 'namespace' => 'all'); extract($defaults); # Extract variables from the request, falling back to user preferences or # other default values if these don't exist $prefs['days'] = floatval($wgUser->getOption('watchlistdays')); $prefs['hideown'] = $wgUser->getBoolOption('watchlisthideown'); $prefs['hidebots'] = $wgUser->getBoolOption('watchlisthidebots'); # Get query variables $days = $wgRequest->getVal('days', $prefs['days']); $hideOwn = $wgRequest->getBool('hideOwn', $prefs['hideown']); $hideBots = $wgRequest->getBool('hideBots', $prefs['hidebots']); # Get namespace value, if supplied, and prepare a WHERE fragment $nameSpace = $wgRequest->getIntOrNull('namespace'); if (!is_null($nameSpace)) { $nameSpace = intval($nameSpace); $nameSpaceClause = " AND rc_namespace = {$nameSpace}"; } else { $nameSpace = ''; $nameSpaceClause = ''; } # Watchlist editing $action = $wgRequest->getVal('action'); $remove = $wgRequest->getVal('remove'); $id = $wgRequest->getArray('id'); $uid = $wgUser->getID(); if ($wgEnotifWatchlist && $wgRequest->getVal('reset') && $wgRequest->wasPosted()) { $wgUser->clearAllNotifications($uid); } # Deleting items from watchlist if ($action == 'submit' && isset($remove) && is_array($id)) { $wgOut->addWikiText(wfMsg('removingchecked')); $wgOut->addHTML('<p>'); foreach ($id as $one) { $t = Title::newFromURL($one); if (!is_null($t)) { // WERELATE - run UnwatchArticle hooks; fix UnwatchArticle hook below to UnwatchArticleComplete $article = new Article($t); if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$article))) { $wl = WatchedItem::fromUserTitle($wgUser, $t); if ($wl->removeWatch() === false) { $wgOut->addHTML("<br />\n" . wfMsg('couldntremove', htmlspecialchars($one))); } else { wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$article)); $wgOut->addHTML(' (' . htmlspecialchars($one) . ')'); } } } else { $wgOut->addHTML("<br />\n" . wfMsg('iteminvalidname', htmlspecialchars($one))); } } $wgOut->addHTML("<br />\n" . wfMsg('wldone') . "</p>\n"); } if ($wgUseWatchlistCache) { $memckey = "{$wgDBname}:watchlist:id:" . $wgUser->getId(); $cache_s = @$wgMemc->get($memckey); if ($cache_s) { $wgOut->addWikiText(wfMsg('wlsaved')); $wgOut->addHTML($cache_s); return; } } $dbr =& wfGetDB(DB_SLAVE); extract($dbr->tableNames('page', 'revision', 'watchlist', 'recentchanges')); $sql = "SELECT COUNT(*) AS n FROM {$watchlist} WHERE wl_user={$uid}"; $res = $dbr->query($sql, $fname); $s = $dbr->fetchObject($res); # Patch *** A1 *** (see A2 below) # adjust for page X, talk:page X, which are both stored separately, but treated together $nitems = floor($s->n / 2); # $nitems = $s->n; if ($nitems == 0) { $wgOut->addWikiText(wfMsg('nowatchlist')); return; } if (is_null($days) || !is_numeric($days)) { $big = 1000; /* The magical big */ // WERELATE - don't change default; pages don't change that often // if($nitems > $big) { # Set default cutoff shorter // $days = $defaults['days'] = (12.0 / 24.0); # 12 hours... // } else { $days = $defaults['days']; # default cutoff for shortlisters // } } else { $days = floatval($days); } // Dump everything here $nondefaults = array(); wfAppendToArrayIfNotDefault('days', $days, $defaults, $nondefaults); wfAppendToArrayIfNotDefault('hideOwn', (int) $hideOwn, $defaults, $nondefaults); wfAppendToArrayIfNotDefault('hideBots', (int) $hideBots, $defaults, $nondefaults); wfAppendToArrayIfNotDefault('namespace', $nameSpace, $defaults, $nondefaults); if ($days <= 0) { $docutoff = ''; $cutoff = false; $npages = wfMsg('watchlistall1'); } else { $docutoff = "AND rev_timestamp > '" . ($cutoff = $dbr->timestamp(time() - intval($days * 86400))) . "'"; /* $sql = "SELECT COUNT(*) AS n FROM $page, $revision WHERE rev_timestamp>'$cutoff' AND page_id=rev_page"; $res = $dbr->query( $sql, $fname ); $s = $dbr->fetchObject( $res ); $npages = $s->n; */ $npages = 40000 * $days; } /* Edit watchlist form */ if ($wgRequest->getBool('edit') || $par == 'edit') { $wgOut->addWikiText(wfMsg('watchlistcontains', $wgLang->formatNum($nitems)) . "\n\n" . wfMsg('watcheditlist')); $wgOut->addHTML('<form action=\'' . $specialTitle->escapeLocalUrl('action=submit') . "' method='post'>\n"); # Patch A2 # The following was proposed by KTurner 07.11.2004 to T.Gries # $sql = "SELECT distinct (wl_namespace & ~1),wl_title FROM $watchlist WHERE wl_user=$uid"; $sql = "SELECT wl_namespace, wl_title, page_is_redirect FROM {$watchlist} LEFT JOIN {$page} ON wl_namespace = page_namespace AND wl_title = page_title WHERE wl_user={$uid}"; $res = $dbr->query($sql, $fname); # Batch existence check $linkBatch = new LinkBatch(); while ($row = $dbr->fetchObject($res)) { $linkBatch->addObj(Title::makeTitleSafe($row->wl_namespace, $row->wl_title)); } $linkBatch->execute(); if ($dbr->numRows($res) > 0) { $dbr->dataSeek($res, 0); } # Let's do the time warp again! $sk = $wgUser->getSkin(); $list = array(); while ($s = $dbr->fetchObject($res)) { $list[$s->wl_namespace][$s->wl_title] = $s->page_is_redirect; } // TODO: Display a TOC foreach ($list as $ns => $titles) { if (Namespac::isTalk($ns)) { continue; } if ($ns != NS_MAIN) { $wgOut->addHTML('<h2>' . $wgContLang->getFormattedNsText($ns) . '</h2>'); } $wgOut->addHTML('<ul>'); foreach ($titles as $title => $redir) { $titleObj = Title::makeTitle($ns, $title); if (is_null($titleObj)) { $wgOut->addHTML('<!-- bad title "' . htmlspecialchars($s->wl_title) . '" in namespace ' . $s->wl_namespace . " -->\n"); } else { global $wgContLang; $toolLinks = array(); $titleText = $titleObj->getPrefixedText(); $pageLink = $sk->makeLinkObj($titleObj); $toolLinks[] = $sk->makeLinkObj($titleObj->getTalkPage(), $wgLang->getNsText(NS_TALK)); if ($titleObj->exists()) { $toolLinks[] = $sk->makeKnownLinkObj($titleObj, wfMsgHtml('history_short'), 'action=history'); } $toolLinks = '(' . implode(' | ', $toolLinks) . ')'; $checkbox = '<input type="checkbox" name="id[]" value="' . htmlspecialchars($titleObj->getPrefixedText()) . '" /> ' . ($wgContLang->isRTL() ? '‏' : '‎'); if ($redir) { $spanopen = '<span class="watchlistredir">'; $spanclosed = '</span>'; } else { $spanopen = $spanclosed = ''; } $wgOut->addHTML("<li>{$checkbox}{$spanopen}{$pageLink}{$spanclosed} {$toolLinks}</li>\n"); } } $wgOut->addHTML('</ul>'); } $wgOut->addHTML("<input type='submit' name='remove' value=\"" . htmlspecialchars(wfMsg("removechecked")) . "\" />\n" . "</form>\n"); return; } # If the watchlist is relatively short, it's simplest to zip # down its entirety and then sort the results. # If it's relatively long, it may be worth our while to zip # through the time-sorted page list checking for watched items. # Up estimate of watched items by 15% to compensate for talk pages... # Toggles $andHideOwn = $hideOwn ? "AND (rc_user <> {$uid})" : ''; $andHideBots = $hideBots ? "AND (rc_bot = 0)" : ''; # Show watchlist header $header = ''; if ($wgUser->getOption('enotifwatchlistpages') && $wgEnotifWatchlist) { $header .= wfMsg('wlheader-enotif') . "\n"; } if ($wgEnotifWatchlist && $wgShowUpdatedMarker) { $header .= wfMsg('wlheader-showupdated') . "\n"; } # Toggle watchlist content (all recent edits or just the latest) if ($wgUser->getOption('extendwatchlist')) { $andLatest = ''; $limitWatchlist = 'LIMIT ' . intval($wgUser->getOption('wllimit')); } else { $andLatest = 'AND rc_this_oldid=page_latest'; $limitWatchlist = ''; } # TODO: Consider removing the third parameter $header .= wfMsg('watchdetails', $wgLang->formatNum($nitems), $wgLang->formatNum($npages), '', $specialTitle->getFullUrl('edit=yes')); $wgOut->addWikiText($header); if ($wgEnotifWatchlist && $wgShowUpdatedMarker) { $wgOut->addHTML('<form action="' . $specialTitle->escapeLocalUrl() . '" method="post"><input type="submit" name="dummy" value="' . htmlspecialchars(wfMsg('enotif_reset')) . '" /><input type="hidden" name="reset" value="all" /></form>' . "\n\n"); } // WERELATE - handle changed view if ($wgRequest->getBool('changed') || $par == 'changed') { $wgOut->addHTML('<hr /><h2>All pages changed since last visited</h2><ul><li><a href="' . $specialTitle->getFullUrl() . '">Show recently-changed pages</a></li></ul>'); $sql = 'select wl_namespace, wl_title from watchlist where wl_user='******' and wl_notificationtimestamp > \'0\''; $res = $dbr->query($sql, $fname); $sk = $wgUser->getSkin(); $changed = ''; $count = 0; while ($obj = $dbr->fetchObject($res)) { $t = Title::makeTitle($obj->wl_namespace, $obj->wl_title); $historylink = $sk->makeKnownLinkObj($t, 'hist', wfArrayToCGI(array('action' => 'history'))); $articlelink = $sk->makeKnownLinkObj($t); $changed .= "<li> ( {$historylink} ) . . {$articlelink}</li>\n"; $count += 1; } $dbr->freeResult($res); $wgOut->addHTML("<h3>{$count} page(s)</h3>\n<ul>" . $changed . '</ul>'); return; } // WERELATE - remove join with page table $sql = "SELECT\n\t rc_namespace AS page_namespace, rc_title AS page_title,\n\t rc_comment AS rev_comment, rc_cur_id AS page_id,\n\t rc_user AS rev_user, rc_user_text AS rev_user_text,\n\t rc_timestamp AS rev_timestamp, rc_minor AS rev_minor_edit,\n\t rc_this_oldid AS rev_id,\n\t rc_last_oldid, rc_id, rc_patrolled,\n\t rc_new AS page_is_new,wl_notificationtimestamp\n\t FROM {$watchlist},{$recentchanges}\n\t WHERE wl_user={$uid}\n\t AND wl_namespace=rc_namespace\n\t AND wl_title=rc_title\n\t AND rc_timestamp > '{$cutoff}'\n\t {$andHideOwn}\n\t {$andHideBots}\n\t {$nameSpaceClause}\n\t ORDER BY rc_timestamp DESC\n\t {$limitWatchlist}"; $res = $dbr->query($sql, $fname); // WERELATE - moved up from below so we can calculate $numRows inside the loop // $numRows = $dbr->numRows( $res ); $numRows = 0; $list = ChangesList::newFromUser($wgUser); $rcs = $list->beginRecentChangesList(); $counter = 1; // WERELATE - added array of seen pagetitles $seen = array(); while ($obj = $dbr->fetchObject($res)) { $nsTitle = "{$obj->page_namespace}:{$obj->page_title}"; if (!$andLatest || !isset($seen[$nsTitle])) { $seen[$nsTitle] = 1; $numRows++; # Make fake RC entry $rc = RecentChange::newFromCurRow($obj, $obj->rc_last_oldid); $rc->counter = $counter++; if ($wgShowUpdatedMarker) { $updated = $obj->wl_notificationtimestamp; } else { // Same visual appearance as MW 1.4 $updated = true; } if ($wgRCShowWatchingUsers && $wgUser->getOption('shownumberswatching')) { $sql3 = "SELECT COUNT(*) AS n FROM {$watchlist} WHERE wl_title='" . wfStrencode($obj->page_title) . "' AND wl_namespace='{$obj->page_namespace}'"; $res3 = $dbr->query($sql3, DB_READ, $fname); $x = $dbr->fetchObject($res3); $rc->numberofWatchingusers = $x->n; } else { $rc->numberofWatchingusers = 0; } $rcs .= $list->recentChangesLine($rc, $updated); } } $rcs .= $list->endRecentChangesList(); $dbr->freeResult($res); /* Start bottom header */ // WERELATE - add link to changed view // $wgOut->addHTML( "<hr />\n<p>" ); $wgOut->addHTML('<hr /><h2>Recently-changed pages</h2><ul><li><a href="' . $specialTitle->getFullUrl('changed=yes') . '">Show all pages changed since last visited</a></li></ul><br/><p>'); if ($days >= 1) { $wgOut->addWikiText(wfMsg('rcnote', $wgLang->formatNum($numRows), $wgLang->formatNum($days), $wgLang->timeAndDate(wfTimestampNow(), true)) . '<br />', false); } elseif ($days > 0) { $wgOut->addWikiText(wfMsg('wlnote', $wgLang->formatNum($numRows), $wgLang->formatNum(round($days * 24))) . '<br />', false); } $wgOut->addHTML("\n" . wlCutoffLinks($days, 'Watchlist', $nondefaults) . "<br />\n"); # Spit out some control panel links $thisTitle = Title::makeTitle(NS_SPECIAL, 'Watchlist'); $skin = $wgUser->getSkin(); $linkElements = array('hideOwn' => 'wlhideshowown', 'hideBots' => 'wlhideshowbots'); # Problems encountered using the fancier method $label = $hideBots ? wfMsgHtml('show') : wfMsgHtml('hide'); $linkBits = wfArrayToCGI(array('hideBots' => 1 - (int) $hideBots), $nondefaults); $link = $skin->makeKnownLinkObj($thisTitle, $label, $linkBits); $links[] = wfMsgHtml('wlhideshowbots', $link); $label = $hideOwn ? wfMsgHtml('show') : wfMsgHtml('hide'); $linkBits = wfArrayToCGI(array('hideOwn' => 1 - (int) $hideOwn), $nondefaults); $link = $skin->makeKnownLinkObj($thisTitle, $label, $linkBits); $links[] = wfMsgHtml('wlhideshowown', $link); $wgOut->addHTML(implode(' | ', $links)); # Form for namespace filtering $thisAction = $thisTitle->escapeLocalUrl(); $nsForm = "<form method=\"post\" action=\"{$thisAction}\">\n"; $nsForm .= "<label for=\"namespace\">" . wfMsgExt('namespace', array('parseinline')) . "</label> "; $nsForm .= HTMLnamespaceselector($nameSpace, '') . "\n"; $nsForm .= $hideOwn ? "<input type=\"hidden\" name=\"hideown\" value=\"1\" />\n" : ""; $nsForm .= $hideBots ? "<input type=\"hidden\" name=\"hidebots\" value=\"1\" />\n" : ""; $nsForm .= "<input type=\"hidden\" name=\"days\" value=\"" . $days . "\" />\n"; $nsForm .= "<input type=\"submit\" name=\"submit\" value=\"" . wfMsgExt('allpagessubmit', array('escape')) . "\" />\n"; $nsForm .= "</form>\n"; $wgOut->addHTML($nsForm); if ($numRows == 0) { $wgOut->addWikitext("<br />" . wfMsg('watchnochange'), false); $wgOut->addHTML("</p>\n"); return; } $wgOut->addHTML("</p>\n"); /* End bottom header */ // WERELATE - change $s to $rcs $wgOut->addHTML($rcs); if ($wgUseWatchlistCache) { $wgMemc->set($memckey, $s, $wgWLCacheTimeout); } }
function revisionInfo($row) { global $wgUser; $changes = ChangesList::newFromContext(RequestContext::getMain()); $out = $changes->beginRecentChangesList(); $rc = RecentChange::newFromCurRow($row); $rc->counter = 0; // ??? $out .= $changes->recentChangesLine($rc); $out .= $changes->endRecentChangesList(); return $out; }