/** * Generate the feed items given a row from the database. * @param $rows DatabaseBase resource with recentchanges rows * @param $feed Feed object */ public static function generateFeed($rows, &$feed) { wfProfileIn(__METHOD__); $feed->outHeader(); # Merge adjacent edits by one user $sorted = array(); $n = 0; foreach ($rows as $obj) { if ($n > 0 && $obj->rc_namespace >= 0 && $obj->rc_cur_id == $sorted[$n - 1]->rc_cur_id && $obj->rc_user_text == $sorted[$n - 1]->rc_user_text) { $sorted[$n - 1]->rc_last_oldid = $obj->rc_last_oldid; } else { $sorted[$n] = $obj; $n++; } } foreach ($sorted as $obj) { $title = Title::makeTitle($obj->rc_namespace, $obj->rc_title); $talkpage = $title->getTalkPage(); // Skip items with deleted content (avoids partially complete/inconsistent output) if ($obj->rc_deleted) { continue; } $item = new FeedItem($title->getPrefixedText(), FeedUtils::formatDiff($obj), $obj->rc_this_oldid ? $title->getFullURL('diff=' . $obj->rc_this_oldid . '&oldid=prev') : $title->getFullURL(), $obj->rc_timestamp, $obj->rc_deleted & Revision::DELETED_USER ? wfMsgHtml('rev-deleted-user') : $obj->rc_user_text, $talkpage->getFullURL()); $feed->outItem($item); } $feed->outFooter(); wfProfileOut(__METHOD__); }
/** * Generate the feed items given a row from the database. * @param object $rows DatabaseBase resource with recentchanges rows * @return array */ public static function buildItems($rows) { $items = []; # Merge adjacent edits by one user $sorted = []; $n = 0; foreach ($rows as $obj) { if ($obj->rc_type == RC_EXTERNAL) { continue; } if ($n > 0 && $obj->rc_type == RC_EDIT && $obj->rc_namespace >= 0 && $obj->rc_cur_id == $sorted[$n - 1]->rc_cur_id && $obj->rc_user_text == $sorted[$n - 1]->rc_user_text) { $sorted[$n - 1]->rc_last_oldid = $obj->rc_last_oldid; } else { $sorted[$n] = $obj; $n++; } } foreach ($sorted as $obj) { $title = Title::makeTitle($obj->rc_namespace, $obj->rc_title); $talkpage = MWNamespace::canTalk($obj->rc_namespace) ? $title->getTalkPage()->getFullURL() : ''; // Skip items with deleted content (avoids partially complete/inconsistent output) if ($obj->rc_deleted) { continue; } if ($obj->rc_this_oldid) { $url = $title->getFullURL(['diff' => $obj->rc_this_oldid, 'oldid' => $obj->rc_last_oldid]); } else { // log entry or something like that. $url = $title->getFullURL(); } $items[] = new FeedItem($title->getPrefixedText(), FeedUtils::formatDiff($obj), $url, $obj->rc_timestamp, $obj->rc_deleted & Revision::DELETED_USER ? wfMessage('rev-deleted-user')->escaped() : $obj->rc_user_text, $talkpage); } return $items; }
/** * Generate the feed items given a row from the database. * @param $rows DatabaseBase resource with recentchanges rows * @param $feed Feed object */ public static function generateFeed($rows, &$feed) { wfProfileIn(__METHOD__); $feed->outHeader(); # Merge adjacent edits by one user $sorted = array(); $n = 0; foreach ($rows as $obj) { if ($n > 0 && $obj->rc_type == RC_EDIT && $obj->rc_namespace >= 0 && $obj->rc_cur_id == $sorted[$n - 1]->rc_cur_id && $obj->rc_user_text == $sorted[$n - 1]->rc_user_text) { $sorted[$n - 1]->rc_last_oldid = $obj->rc_last_oldid; } else { $sorted[$n] = $obj; $n++; } } foreach ($sorted as $obj) { $title = Title::makeTitle($obj->rc_namespace, $obj->rc_title); $talkpage = MWNamespace::canTalk($obj->rc_namespace) ? $title->getTalkPage()->getFullURL() : ''; // Skip items with deleted content (avoids partially complete/inconsistent output) if ($obj->rc_deleted) { continue; } if ($obj->rc_this_oldid) { $url = $title->getFullURL(array('diff' => $obj->rc_this_oldid, 'oldid' => $obj->rc_last_oldid)); } else { // log entry or something like that. $url = $title->getFullURL(); } $item = new FeedItem($title->getPrefixedText(), FeedUtils::formatDiff($obj), $url, $obj->rc_timestamp, $obj->rc_deleted & Revision::DELETED_USER ? wfMessage('rev-deleted-user')->escaped() : $obj->rc_user_text, $talkpage); $feed->outItem($item); } $feed->outFooter(); wfProfileOut(__METHOD__); }
public function buildRssOwn() { global $wgSitename, $wgRequest; $user = $wgRequest->getInt('u', 0); $dbr = wfGetDB(DB_SLAVE); $tbl_rc = $dbr->tableName('recentchanges'); $res = $dbr->query("SELECT rc_id\n\t\t\t\t\t\tFROM {$tbl_rc}\n\t\t\t\t\t\tWHERE rc_user = {$user}\n\t\t\t\t\t\t AND rc_timestamp > '" . $dbr->timestamp(time() - intval(7 * 86400)) . "'"); $ids = array(); while ($row = $res->fetchObject()) { $ids[] = $row->rc_id; } if (count($ids)) { $res = $dbr->query("SELECT *\n\t\t\t\t\t\t\tFROM {$tbl_rc}\n\t\t\t\t\t\t\tWHERE rc_id IN (" . implode(',', $ids) . ")\n\t\t\t\t\t\t\t AND rc_timestamp > '" . $dbr->timestamp(time() - intval(7 * 86400)) . "'\n\t\t\t\t\t\t\tORDER BY rc_timestamp DESC"); } else { $res = false; } $channel = RSSCreator::createChannel(RSSCreator::xmlEncode($wgSitename . ' - ' . wfMessage('bs-rssstandards-title-own')->plain()), 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], wfMessage('bs-rssstandards-desc-own')->plain()); if ($res) { while ($obj = $res->fetchObject()) { $title = Title::makeTitle($obj->rc_namespace, $obj->rc_title); $entry = RSSItemCreator::createItem(wfMessage('bs-rssstandards-changes-from', $obj->rc_user_text)->text(), $title->getFullURL('diff=' . $obj->rc_this_oldid . '&oldid=prev'), FeedUtils::formatDiff($obj)); $entry->setPubDate(wfTimestamp(TS_UNIX, $obj->rc_timestamp)); $channel->addItem($entry); } $dbr->freeResult($res); } return $channel->buildOutput(); }