public function buildRssNsBlog()
 {
     global $wgSitename, $wgContLang;
     $oRequest = $this->getRequest();
     $sTitle = $oRequest->getVal('p', '');
     $iNSid = $oRequest->getInt('ns', 0);
     $aNamespaces = $wgContLang->getNamespaces();
     if ($iNSid != 0) {
         $sPageName = $aNamespaces[$iNSid] . ':' . $sTitle;
     } else {
         $sPageName = $sTitle;
     }
     /*$dbr = wfGetDB( DB_SLAVE );
     		$res = $dbr->select(
     			array( 'page', 'recentchanges' ),
     			'*',
     			array(
     				'page_title'     => $sTitle,
     				'page_namespace' => $iNSid,
     				'rc_timestamp > '. $dbr->timestamp( time() - intval( 7 * 86400 ) )
     			),
     			__METHOD__,
     			array( 'ORDER BY' => 'rc_timestamp DESC' ),
     			array(
     				'page'=> array( 'LEFT JOIN', 'rc_cur_id = page_id' )
     			)
     		);*/
     $oChannel = RSSCreator::createChannel(RSSCreator::xmlEncode($wgSitename . ' - ' . $sPageName), 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], wfMessage('bs-rssstandards-description_page')->plain());
     $oTitle = Title::makeTitle($iNSid, 'Blog');
     $aSubpages = $oTitle->getSubpages();
     foreach ($aSubpages as $oSubpage) {
         //			$oPageCP = new BsPageContentProvider();
         if ($oSubpage instanceof Title) {
         }
         $entry = RSSItemCreator::createItem($oSubpage->getText(), $oSubpage->getFullURL(), BsPageContentProvider::getInstance()->getContentFromTitle($oSubpage));
         $entry->setPubDate(wfTimestamp(TS_UNIX, $oSubpage->getTouched()));
         $oChannel->addItem($entry);
     }
     return $oChannel->buildOutput();
 }
 public function buildRssWatch($par)
 {
     // TODO SU (04.07.11 10:35): Globals
     global $wgUser, $wgOut, $wgRequest, $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker, $wgEnotifWatchlist, $wgSitename;
     $skin = RequestContext::getMain()->getSkin();
     $specialTitle = SpecialPage::getTitleFor('Watchlist');
     $wgOut->setRobotPolicy('noindex,nofollow');
     # Anons don't get a watchlist
     if ($wgUser->isAnon()) {
         $_user = $wgRequest->getVal('u', '');
         $user = User::newFromName($_user);
         $_hash = $wgRequest->getVal('h', '');
         if (!($user && $_hash == md5($_user . $user->getToken() . $user->getId())) || $user->isAnon()) {
             $oTitle = SpecialPage::getTitleFor('Userlogin');
             $sLink = Linker::link($oTitle, wfMessage('loginreqlink')->plain(), array(), array('returnto' => $specialTitle->getLocalUrl()));
             throw new ErrorPageError('bs-rssstandards-watchnologin', 'watchlistanontext', array($sLink));
         }
     } else {
         $user = $wgUser;
     }
     $wgOut->setPageTitle(wfMessage('bs-rssstandards-watchlist')->plain());
     $sub = wfMessage('watchlistfor', $user->getName())->parse();
     $sub .= '<br />' . WatchlistEditor::buildTools($user->getSkin());
     $wgOut->setSubtitle($sub);
     if (($mode = WatchlistEditor::getMode($wgRequest, $par)) !== false) {
         $editor = new WatchlistEditor();
         $editor->execute($user, $wgOut, $wgRequest, $mode);
         return;
     }
     $uid = $user->getId();
     if (($wgEnotifWatchlist || $wgShowUpdatedMarker) && $wgRequest->getVal('reset') && $wgRequest->wasPosted()) {
         $user->clearAllNotifications($uid);
         $wgOut->redirect($specialTitle->getFullUrl());
         return;
     }
     $defaults = array('days' => floatval($user->getOption('watchlistdays')), 'hideOwn' => (int) $user->getBoolOption('watchlisthideown'), 'hideBots' => (int) $user->getBoolOption('watchlisthidebots'), 'hideMinor' => (int) $user->getBoolOption('watchlisthideminor'), '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($user->getOption('watchlistdays'));
     $prefs['hideown'] = $user->getBoolOption('watchlisthideown');
     $prefs['hidebots'] = $user->getBoolOption('watchlisthidebots');
     $prefs['hideminor'] = $user->getBoolOption('watchlisthideminor');
     # Get query variables
     $days = $wgRequest->getVal('days', $prefs['days']);
     $hideOwn = $wgRequest->getBool('hideOwn', $prefs['hideown']);
     $hideBots = $wgRequest->getBool('hideBots', $prefs['hidebots']);
     $hideMinor = $wgRequest->getBool('hideMinor', $prefs['hideminor']);
     # 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 = '';
     }
     $dbr = wfGetDB(DB_SLAVE, 'watchlist');
     list($page, $watchlist, $recentchanges) = $dbr->tableNamesN('page', 'watchlist', 'recentchanges');
     $watchlistCount = $dbr->selectField('watchlist', 'COUNT(*)', array('wl_user' => $uid), __METHOD__);
     // Adjust for page X, talk:page X, which are both stored separately,
     // but treated together
     $nitems = floor($watchlistCount / 2);
     if (is_null($days) || !is_numeric($days)) {
         $big = 1000;
         /* The magical big */
         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('hideMinor', (int) $hideMinor, $defaults, $nondefaults);
     wfAppendToArrayIfNotDefault('namespace', $nameSpace, $defaults, $nondefaults);
     $hookSql = "";
     if (!wfRunHooks('BeforeWatchlist', array($nondefaults, $user, &$hookSql))) {
         return;
     }
     /*if ( $nitems == 0 ) {
     			$wgOut->addWikiMsg( 'nowatchlist' );
     			return;
     		}*/
     if ($days <= 0) {
         $andcutoff = '';
     } else {
         $andcutoff = "AND rc_timestamp > '" . $dbr->timestamp(time() - intval($days * 86400)) . "'";
     }
     # 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)" : '';
     $andHideMinor = $hideMinor ? 'AND rc_minor = 0' : '';
     # Toggle watchlist content (all recent edits or just the latest)
     if ($user->getOption('extendwatchlist')) {
         $andLatest = '';
         $limitWatchlist = 'LIMIT ' . intval($user->getOption('wllimit'));
     } else {
         # Top log Ids for a page are not stored
         $andLatest = 'AND (rc_this_oldid=page_latest OR rc_type=' . RC_LOG . ') ';
         $limitWatchlist = '';
     }
     if ($wgShowUpdatedMarker) {
         $wltsfield = ", {$watchlist}.wl_notificationtimestamp ";
     } else {
         $wltsfield = '';
     }
     $sql = "SELECT {$recentchanges}.* {$wltsfield}\n\t  FROM {$watchlist},{$recentchanges}\n\t  LEFT JOIN {$page} ON rc_cur_id=page_id\n\t  WHERE wl_user={$uid}\n\t  AND wl_namespace=rc_namespace\n\t  AND wl_title=rc_title\n\t\t\t{$andcutoff}\n\t\t\t{$andLatest}\n\t\t\t{$andHideOwn}\n\t\t\t{$andHideBots}\n\t\t\t{$andHideMinor}\n\t\t\t{$nameSpaceClause}\n\t\t\t{$hookSql}\n\t  ORDER BY rc_timestamp DESC\n\t\t\t{$limitWatchlist}";
     $res = $dbr->query($sql, __METHOD__);
     $numRows = $dbr->numRows($res);
     /*# If there's nothing to show, stop here
     		if( $numRows == 0 ) {
     			$wgOut->addWikiMsg( 'watchnochange' );
     			return;
     		}*/
     /* End bottom header */
     if ($numRows > 0) {
         /* Do link batch query */
         $linkBatch = new LinkBatch();
         while ($row = $dbr->fetchObject($res)) {
             $userNameUnderscored = str_replace(' ', '_', $row->rc_user_text);
             if ($row->rc_user != 0) {
                 $linkBatch->add(NS_USER, $userNameUnderscored);
             }
             $linkBatch->add(NS_USER_TALK, $userNameUnderscored);
         }
         $linkBatch->execute();
         $dbr->dataSeek($res, 0);
     }
     $list = ChangesList::newFromContext($skin->getContext());
     //Thanks to Bartosz Dziewoński (https://gerrit.wikimedia.org/r/#/c/94082/)
     $channel = RSSCreator::createChannel(SpecialPage::getTitleFor('Watchlist') . ' (' . $user->getName() . ')', 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], wfMessage('bs-rssstandards-desc-watch')->plain());
     $html = $list->beginRecentChangesList();
     $counter = 1;
     $items = array();
     while ($obj = $dbr->fetchObject($res)) {
         $title = Title::newFromText($obj->rc_title, $obj->rc_namespace);
         $items[] = array('title' => $title->getPrefixedText(), 'link' => $title->getFullURL(), 'date' => wfTimestamp(TS_UNIX, $obj->rc_timestamp), 'comments' => $title->getTalkPage()->getFullURL());
         # Make RC entry
         $rc = RecentChange::newFromRow($obj);
         $rc->counter = $counter++;
         if ($wgShowUpdatedMarker) {
             $updated = $obj->wl_notificationtimestamp;
         } else {
             $updated = false;
         }
         if ($wgRCShowWatchingUsers && $user->getOption('shownumberswatching')) {
             $rc->numberofWatchingusers = $dbr->selectField('watchlist', 'COUNT(*)', array('wl_namespace' => $obj->rc_namespace, 'wl_title' => $obj->rc_title), __METHOD__);
         } else {
             $rc->numberofWatchingusers = 0;
         }
         $rc->mAttribs['rc_timestamp'] = 0;
         $html .= $list->recentChangesLine($rc, false);
     }
     $html .= $list->endRecentChangesList();
     $lines = array();
     preg_match_all('%<li.*?>(.*?)</li>%', $html, $lines, PREG_SET_ORDER);
     foreach ($lines as $key => $line) {
         $item = $items[$key];
         $entry = RSSItemCreator::createItem($item['title'], $item['link'], RSSCreator::xmlEncode($line[1]));
         if ($entry == false) {
             wfDebugLog('BS::RSSStandards::buildRssWatch', 'Invalid item: ' . var_export($item, true));
             continue;
         }
         $entry->setPubDate($item['date']);
         $entry->setComments($item['comments']);
         $channel->addItem($entry);
     }
     $dbr->freeResult($res);
     return $channel->buildOutput();
 }