function execute($par) { global $wgOut, $wgRequest, $wgUser; $dbr = wfGetDB(DB_SLAVE); // just getting cats? if ($wgRequest->getVal('getusercats')) { $catmap = self::getCatMap(); $cats = self::getSubscribedCats(); $wgOut->setArticleBodyOnly(true); if (count($catmap) == count($cats) or empty($cats)) { $wgOut->addHTML('All'); return; } foreach ($catmap as $cat) { $key = strtolower(str_replace(" ", "-", $cat)); $safekey = str_replace("&", "and", $key); // hack for the ampersand in our db $checkkey = $safekey == 'cars-and-other-vehicles' ? 'cars-&-other-vehicles' : $safekey; // are we selecting it? if ($cats && in_array($checkkey, $cats)) { $usercats[] = $cat; } } $wgOut->addHTML(implode($usercats, ", ")); return; } // process any postings, saving the categories if ($wgRequest->wasPosted()) { $field = preg_replace("@ @", "", $wgRequest->getVal('cats')); // hack for ampersand in "cars & other vehicles" category $field = str_replace('cars-and-other-vehicles', 'cars-&-other-vehicles', $field); $cats = preg_split("@,@", $field, 0, PREG_SPLIT_NO_EMPTY); $cats = array_unique($cats); sort($cats); $dbw = wfGetDB(DB_MASTER); $sql = "INSERT INTO suggest_cats VALUES(" . $wgUser->getID() . ", " . $dbw->addQuotes(implode($cats, ",")) . ") ON DUPLICATE KEY UPDATE sc_cats = " . $dbw->addQuotes(implode($cats, ",")); $dbw->query($sql); $wgOut->addHTML("<br/><br/>Categories updated.<br/><br/>"); $type = $wgRequest->getVal('type'); if ($type) { $wgOut->redirect('/Special:EditFinder/' . urlencode($type)); } else { $wgOut->redirect('/Special:RecommendedArticles'); } } $wgOut->setArticleBodyOnly(true); $catmap = self::getCatMap(); $cats = self::getSubscribedCats(); $hiddencats = implode($cats, ","); $hiddencats = str_replace("&", "and", $hiddencats); // get top categories $theHTML .= "<form method='post' action='/Special:SuggestCategories' id='suggest_cats' name='suggest_cats'><input type='hidden' name='cats' value='" . $hiddencats . "'/>"; $theHTML .= "<table width='100%' class='categorytopics selecttopics'><tr>"; $index = 0; $select_count = 0; foreach ($catmap as $cat) { $key = strtolower(str_replace(" ", "-", $cat)); $safekey = str_replace("&", "and", $key); // hack for the ampersand in our db $safekey == 'cars-and-other-vehicles' ? $checkkey = 'cars-&-other-vehicles' : ($checkkey = $safekey); // are we selecting it? if ($cats && in_array($checkkey, $cats)) { $c = "chosen"; $s = "checked='checked'"; $select_count++; } else { $c = "not_chosen"; $s = ""; } $theHTML .= "<td id='{$safekey}' class='{$c} categorylink'><a class=''><input type='checkbox' id='check_{$safekey}' {$s} />" . ListRequestedTopics::getCategoryImage($cat) . "<br />{$cat}</a></td>"; $index++; if ($index % 6 == 0) { $theHTML .= "</tr><tr>"; } } $actual_count = $index; if ($index % 6 <= 5) { while ($index % 6 != 0) { $theHTML .= "<td></td>"; $index++; } } $theHTML .= '</tr></table> ' . '<a style="float: right; background-position: 0% 0pt;" class="button primary" onclick="document.suggest_cats.submit();" id="the_save_button">' . wfMsg('save') . '</a>'; // selected all? $s = $select_count == $actual_count ? "checked='checked'" : ""; // add checkbox at the top $theHTML = "<input type='checkbox' id='check_all_cats' " . $s . " /> <label for='check_all_cats'>All categories</label>" . $theHTML . "</form>"; $wgOut->addHTML($theHTML); }
public function getCount(&$dbr) { return ListRequestedTopics::getUnwrittenTopics(true); }