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(); }
/** * Create a new RSS item from the given data and return a RSSItemCreator instance, * which hold this item. * * @param string $title the title of the item * @param string $link the link to the item * @param string $description the description of the item * @return RSSItemCreator returns false, when the given link don't pass the test for valid URLs */ public static function createItem($title, $link, $description) { $title = htmlentities($title, ENT_QUOTES, 'UTF-8', false); $description = htmlentities($description, ENT_QUOTES, 'UTF-8', false); if (RSSCreator::testURL($link)) { return new RSSItemCreator($title, $link, $description); } return false; }
/** * Diese Methode ist der Aufruf des Backends und managt alle Funktionen * die durch das Backend bereitgestellt werden. * */ function getBackend() { //Enable HTML Area $this->baseSmarty->assign("hta", 1); //Entering the backend function //This retrieves the url now we can simply add our own parametes $this->baseUri = "?module=ext&id=blog"; $url = $this->getCurrentURL(); //assign it to smarty $this->smarty->assign("url", $this->baseUri); //Fetch the extension configuration $config = $this->extConfig; $this->categories = explode(",", $config['params']['categories']); foreach ($this->categories as $k => $v) { $this->categories[$k] = stripslashes(trim($v)); } //Initialize blog class and send copy to the blog class include "ext/blog/blog.core.class.php"; $this->blogClass = new weblog("ext/blog/data/data.xml", $this->xpath); //handle post actions if ($_POST['action']) { //blog entry, settings, ... $part = $_POST['part']; //What to do $action = $_POST['action']; //call neede function call_user_method($action . $part, $this); } else { //Separate different views switch ($_GET['part']) { case "new": //Assing basic variables like config and categories $this->smarty->assign("config", $this->extConfig); $this->smarty->assign("cats", $this->categories); $this->smarty->assign("url", $this->baseUri); //Assing template $this->smarty->assign("content", "blog/tpl/new.tpl"); break; case 'list': //List all Entries or by cat $this->listBlogEntries($_POST['cname']); break; case 'edit': $this->openBlogEntry($_GET['nr']); break; case 'delete': $result = $this->blogClass->deleteBlogEntry($_GET['nr'] - 1); $this->smarty->assign("result", $result); $this->smarty->assign("content", "blog/tpl/newConfirmed.tpl"); break; case 'settings': //fetch available entry templates $entryTpls = $this->fetchTemplates("entry"); $commentTpls = $this->fetchTemplates("comment"); $mainTpls = $this->fetchTemplates("main"); $this->smarty->assign("eTpls", $entryTpls); $this->smarty->assign("cTpls", $commentTpls); $this->smarty->assign("mTpls", $mainTpls); //Assign Params to template $this->smarty->assign("params", $this->extConfig['params']); $this->smarty->assign("content", "blog/tpl/settings.tpl"); break; case 'rss': require_once "ext/blog/rsscreator.class.php"; $rss = RSSCreator::getInstance('2'); $channel['title'] = $this->extConfig['params']['blogTitle']; $channel['link'] = $this->extConfig['params']['blogURL']; $channel['description'] = $this->extConfig['params']['description']; $channel['language'] = "de"; $channel['date'] = date("d.m.Y H:i:s"); $channel['creator'] = $this->extConfig['params']['managingEditor']; $rss->addChannel($channel); $entries = $this->blogClass->getLastXEntries(10); foreach ($entries as $entry) { $item = array(); $item['category'] = $entry['attributes']['category']; $item['author'] = $entry['attributes']['author']; $item['title'] = $entry['attributes']['title']; $item['date'] = $entry['attributes']['date']; $item['content'] = $entry['teaser']; $item['link'] = $this->extConfig['params']['blogURL'] . "single/" . $entry['number']; $rss->addItem($item); } $xml = $rss->outputXML(); $h = fopen("index.xml", "w"); fwrite($h, $xml); fclose($h); $this->smarty->assign("content", "blog/tpl/rss.tpl"); break; default: //default action is to display welcome page $this->smarty->assign("content", "blog/tpl/default.tpl"); break; } } //This is the last part of this function do nothing beyond... return $this->smarty->fetch("blog/tpl/backend.tpl"); }