/** * Update the session and return the template * * @param $mode (type string) 'add', 'ban' or 'remove' * 'add' => add article to the book * 'ban' => ban article from the proposals * 'remove' => remove article from the book * 'addNum' => (type int) add the first $param articles to the collection * 'addVal' => (type float) add all propossals to the collection with * a value higher then $param * @param $param (type string) name of the article to be added, banned or removed * or a number of articles to add or a value (1 - 1.5) all articles with a * higher value will be added to the collection * @return the template for the wikipage */ private static function getCollectionSuggestTemplate($mode, $param) { global $wgCollectionMaxSuggestions; switch ($mode) { case 'add': SpecialCollection::addArticleFromName(NS_MAIN, $param); self::unban($param); break; case 'ban': $_SESSION['wsCollectionSuggestBan'][] = $param; break; case 'remove': SpecialCollection::removeArticleFromName(NS_MAIN, $param); $_SESSION['wsCollectionSuggestBan'][] = $param; break; case 'removeonly': // remove w/out banning (for undo) SpecialCollection::removeArticleFromName(NS_MAIN, $param); break; case 'unban': // for undo self::unban($param); break; } $template = new CollectionSuggestTemplate(); $proposals = new Proposals($_SESSION['wsCollection'], $_SESSION['wsCollectionSuggestBan'], $_SESSION['wsCollectionSuggestProp']); if ($mode == 'addAll') { self::addArticlesFromName($param, $proposals); } $template->set('collection', $_SESSION['wsCollection']); $template->set('proposals', $proposals->getProposals($wgCollectionMaxSuggestions)); $template->set('hasbans', $proposals->hasBans()); $template->set('num_pages', CollectionSession::countArticles()); $_SESSION['wsCollectionSuggestProp'] = $proposals->getLinkList(); return $template; }
static function addCategory($title) { global $wgCollectionMaxArticles, $wgCollectionArticleNamespaces; $limit = $wgCollectionMaxArticles - CollectionSession::countArticles(); if ($limit <= 0) { self::limitExceeded(); return; } $db = wfGetDB(DB_SLAVE); $tables = array('page', 'categorylinks'); $fields = array('page_namespace', 'page_title'); $options = array('USE INDEX' => 'cl_sortkey', 'ORDER BY' => 'cl_type, cl_sortkey', 'LIMIT' => $limit + 1); $where = array('cl_from=page_id', 'cl_to' => $title->getDBkey()); $res = $db->select($tables, $fields, $where, __METHOD__, $options); $count = 0; $limitExceeded = false; foreach ($res as $row) { if (++$count > $limit) { $limitExceeded = true; break; } if (in_array($row->page_namespace, $wgCollectionArticleNamespaces)) { $articleTitle = Title::makeTitle($row->page_namespace, $row->page_title); if (CollectionSession::findArticle($articleTitle->getPrefixedText()) == -1) { self::addArticle($articleTitle); } } } $db->freeResult($res); return $limitExceeded; }