function newSearchKeyRow($dbr, $row) { $t = Title::newFromDBKey($row->page_title); if (!$t) { print "Got null title for {$row->page_title}\n"; return null; } $search_key = generateSearchKey($t->getText()); $featured = intval($row->tl_from != null); return array('tsk_title' => $row->page_title, 'tsk_namespace' => NS_MAIN, 'tsk_key' => $search_key, 'tsk_wasfeatured' => $featured); }
function updateSearchIndex($new, $old) { $dbw = wfGetDB(DB_MASTER); if ($new != null && ($new->getNamespace() == 0 || $new->getNamespace() == 16)) { $dbw->delete('title_search_key', array('tsk_title' => $new->getDBKey(), 'tsk_namespace' => $new->getNamespace()), __METHOD__); $dbw->insert('title_search_key', array('tsk_title' => $new->getDBKey(), 'tsk_namespace' => $new->getNamespace(), 'tsk_key' => generateSearchKey($new->getText())), __METHOD__); } if ($old != null) { $dbw->delete('title_search_key', array('tsk_title' => $old->getDBKey(), 'tsk_namespace' => $old->getNamespace()), __METHOD__); } }
function matchKeyTitles($text, $limit = 10) { global $wgMemc; $text = trim($text); if (!$text) { return array(); } // remove stop words $key = generateSearchKey($text); if (!$key || strlen($key) < 3) { return array(); } $cacheKey = wfMemcKey('title_search', $limit, $key); $result = $wgMemc->get($cacheKey); if ($result) { return $result; } $gotit = array(); $result = array(); $base = "SELECT tsk_title, page_counter, page_len, page_is_featured\n\t\t\t\tFROM title_search_key \n\t\t\t\tLEFT JOIN page ON tsk_title = page_title\n\t\t\t\t\tAND tsk_namespace = page_namespace\n\t\t\t\tWHERE page_is_redirect = 0\n\t\t\t\t\tAND tsk_namespace = 0"; $sql = $base . "\n\t\t\t\t\tAND tsk_key LIKE '%" . str_replace(" ", "%", $key) . "%'\n\t\t\t\t\tAND tsk_namespace = 0\n\t\t\t\tGROUP BY page_id\n\t\t\t\tLIMIT {$limit}"; $db = wfGetDB(DB_MASTER); $res = $db->query($sql, __METHOD__); if ($res->numRows()) { while ($row = $res->fetchObject()) { $con = array($row->tsk_title, $row->page_counter, $row->page_len, $row->page_is_featured); $result[] = $con; $gotit[$row->tsk_title] = 1; } } if (count($result) < $limit) { $sql = $base . " AND ( tsk_key LIKE '%" . str_replace(" ", "%", $key) . "%' "; $ksplit = split(" ", $key); if (count($ksplit) > 1) { foreach ($ksplit as $k) { $sql .= " OR tsk_key LIKE '%{$k}%'"; } } $sql .= " ) "; $sql .= " LIMIT {$limit};"; $res = $db->query($sql, __METHOD__); while (count($result) < $limit && ($row = $res->fetchObject())) { if (!isset($gotit[$row->tsk_title])) { $con = array($row->tsk_title, $row->page_counter, $row->page_len, $row->page_is_featured); $result[] = $con; } } } $wgMemc->set($cacheKey, $result); return $result; }
function wfCheckSuggestionOnSave($article, $user, $text, $summary, $p5, $p6, $p7) { try { $dbr = wfGetDB(DB_SLAVE); $t = $article->getTitle(); if (!$t || $t->getNamespace() != NS_MAIN) { return true; } $num_revisions = $dbr->selectField('revision', 'count(*)', array('rev_page=' . $article->getId()), __METHOD__); // < 2 for race conditions if ($num_revisions < 2) { $dbw = wfGetDB(DB_MASTER); $key = generateSearchKey(trim($t)); $dbw->update('suggested_titles', array('st_used' => 1, 'st_created' => wfTimestampNow(TS_MW)), array('st_key' => $key), __METHOD__); wfClearSuggestionsCache($t); } if ($num_revisions == 1) { $email = $dbw->selectField('suggested_titles', array('st_notify'), array('st_title' => $t->getDBKey()), __METHOD__); if ($email) { $dbw->insert('suggested_notify', array('sn_page' => $article->getId(), 'sn_notify' => $email, 'sn_timestamp' => wfTimestampNow(TS_MW)), __METHOD__); } } } catch (Exception $e) { return true; } return true; }
function execute($par) { global $wgOut, $wgRequest, $wgUser, $wgLanguageCode, $wgScriptPath; $fname = "wfManageSuggestions"; wfLoadExtensionMessages('CreatePage'); if (!in_array('sysop', $wgUser->getGroups())) { $wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext'); return; } $this->setHeaders(); $wgOut->addHTML("<style type='text/css' media='all'>/*<![CDATA[*/ @import '" . wfGetPad('/extensions/min/f/extensions/wikihow/createpage/createpage.css?') . WH_SITEREV . "'; /*]]>*/</style> "); if ($wgRequest->wasPosted() && $wgRequest->getVal('q') != null) { $matches = SuggestionSearch::matchKeyTitles($wgRequest->getVal('q'), 30); if (count($matches) == 0) { $wgOut->addHTML(wfMsg('createpage_nomatches')); return; } $wgOut->addHTML(wfMsg('createpage_matches')); $wgOut->addHTML("<div class='wh_block'><form method='POST'><table class='cpresults'><tr>"); for ($i = 0; $i < count($matches); $i++) { $t = Title::newFromDBkey($matches[$i][0]); if (!$t) { continue; } if ($t) { $name = htmlspecialchars($t->getDBKey()); } $wgOut->addHTML("<td><!--id {$matches[$i][1]} --><input type='checkbox' name=\"{$matches[$i][1]}\"/> <a href='{$t->getEditURL()}' class='new'>{$t->getFullText()}</a><input type='hidden' name='title_{$matches[$i][1]}' value='{$name}'/></td>"); if ($i % 3 == 2) { $wgOut->addHTML("</tr><tr>"); } } $wgOut->addHTML("</tr></table><br/>To delete any of these, select the checkbox and hit the delete button.<br/>\n\t\t\t<input type='hidden' name='delete' value='1'/>\n\t\t\t<input type='submit' value='Delete'/></form></div>\n\t\t\t"); return; } else { if ($wgRequest->wasPosted() && $wgRequest->getVal('delete') != null) { $dbw = wfGetDB(DB_MASTER); $log = new LogPage('suggestion', true); foreach ($wgRequest->getValues() as $key => $value) { if ($value != 'on') { continue; } $xx = $wgRequest->getVal("title_" . $key); if ($dbw->delete('suggested_titles', array('st_id' => $key))) { $wgOut->addHTML("The suggestion \"{$xx}\" has been removed.<br/>"); $msg = wfMsg('managesuggestions_log_remove', $wgUser->getName(), $xx); $t = Title::makeTitle(NS_SPECIAL, "ManageSuggstions"); $log->addEntry('removed', $t, $msg); } else { $wgOut->addHTML("Could not remove \"{$key}\", report this to Travis.<br/>"); } } $wgOut->addHTML("<br/><br/>"); } else { if ($wgRequest->wasPosted() && $wgRequest->getVal('new_suggestions') != null) { $dbw = wfGetDB(DB_MASTER); $sugg = $wgRequest->getVal('new_suggestions'); $format = $wgRequest->getVal('formatted') != 'on'; $lines = split("\n", $sugg); require_once "EditPageWrapper.php"; $log = new LogPage('suggestion', true); foreach ($lines as $line) { $title = trim($line); if ($format) { $title = EditPageWrapper::formatTitle($title); } $key = generateSearchKey($title); $count = $dbw->selectField('suggested_titles', array('count(*)'), array('st_key' => $key)); if ($count > 0) { $wgOut->addHTML("Suggestion \"{$title}\" <b>not</b> added - duplicate suggestion.<br/>"); continue; } $t = Title::newFromText($title); if ($t->getArticleID() > 0) { $wgOut->addHTML("Suggestion \"{$title}\" <b>not</b> added - article exists. <br/>"); continue; } $count = $dbw->selectField('title_search_key', array('count(*)'), array('tsk_key' => $key)); if ($count > 0) { $wgOut->addHTML("Suggestion \"{$title}\" <b>not</b> added - duplicate article key.<br/>"); continue; } $dbw->insert('suggested_titles', array('st_title' => $title, 'st_key' => $key)); $msg = wfMsg('managesuggestions_log_add', $wgUser->getName(), $title); $log->addEntry('added', $t, $msg); $wgOut->addHTML("Suggestion \"{$title}\" added (key {$key}) <br/>"); } $wgOut->addHTML("<br/><br/>"); } else { if ($wgRequest->wasPosted() && $wgRequest->getVal('remove_suggestions') != null) { $dbw = wfGetDB(DB_MASTER); $sugg = $wgRequest->getVal('remove_suggestions'); $lines = split("\n", $sugg); $wgOut->addHTML("<ul>"); foreach ($lines as $line) { $title = trim($line); if ($title == "") { continue; } $t = Title::newFromText($title); if (!$t) { $wgOut->addHTML("<li>Can't make title out of {$title}</li>"); continue; } if ($dbw->delete('suggested_titles', array('st_title' => $t->getDBKey()))) { $wgOut->addHTML("<li>{$t->getText()} deleted</li>"); } else { $wgOut->addHTML("<li>{$t->getText()} NOT deleted, is that the right title?</li>"); } } $wgOut->addHTML("</ul>"); } } } } $wgOut->addHTML(wfMsg('managesuggestions_boxes')); }
function execute($par) { global $wgRequest, $wgUser, $wgOut, $wgHooks; require_once 'Leaderboard.body.php'; $wgOut->setHTMLTitle('List Requested Topics - wikiHow'); $wgOut->setRobotPolicy('noindex,nofollow'); $this->setActiveWidget(); $this->setTopAuthorWidget(); $this->getNewArticlesWidget(); wfLoadExtensionMessages('RequestTopic'); list($limit, $offset) = wfCheckLimits(); $dbr = wfGetDB(DB_SLAVE); $wgOut->addHTML('<style type="text/css" media="all">/*<![CDATA[*/ @import "' . wfGetPad('/extensions/min/f/extensions/wikihow/suggestedtopics.css?rev=') . WH_SITEREV . '"; /*]]>*/</style>'); $wgOut->addScript('<script type="text/javascript" src="' . wfGetPad('/extensions/min/f/extensions/wikihow/suggestedtopics.js?rev=') . WH_SITEREV . '"></script>'); $wgHooks["pageTabs"][] = array("wfRequestedTopicsTabs"); $category = $wgRequest->getVal('category'); $st_search = $wgRequest->getVal('st_search'); //heading with link $request = '<a href="/Special:RequestTopic" class="edit">' . wfMsg('requesttopic') . '</a>'; $heading = $request . '<h2>' . wfMsg('suggested_list_topics_title') . '</h2>'; //add surpise button $heading .= "<a href='/Special:RecommendedArticles?surprise=1' class='button buttonright secondary' id='suggested_surprise'>" . wfMsg('suggested_list_button_surprise') . "</a>"; $wgOut->addHTML($heading); if (!$st_search && !$category) { global $wgCategoryNames; //add search box $html = $this->getSearchBox(); //add the cats (meow) $isColumned = false; $count = 0; $link = '/Special:ListRequestedTopics'; $html .= '<div class="catboxes">' . '<div class="catbox_column">'; foreach ($wgCategoryNames as $cat) { $cat_class = 'cat_' . strtolower(str_replace(' ', '', $cat)); $cat_class = preg_replace('/&/', 'and', $cat_class); $html .= '<div class="catbox ' . $cat_class . '"><a href="' . $link . '?category=' . urlencode($cat) . '">' . $cat . '</a></div>'; if ($count >= count($wgCategoryNames) / 2 && $isColumned == false) { $html .= '</div><div class="catbox_column">'; $isColumned = true; } $count++; } $html .= '<div class="catbox_misc"><a href="' . $link . '?st_search=all">' . wfMsg('suggested_list_cat_all') . '</a></div>' . '<div class="catbox_misc"><a href="' . $link . '?category=Other">' . wfMsg('suggested_list_cat_other') . '</a></div>' . '</div></div>'; $wgOut->addHTML($html); } else { if ($st_search && $st_search != "all") { $key = generateSearchKey($st_search); $sql = "SELECT st_title, st_user_text, st_user FROM suggested_titles WHERE st_used = 0 " . "AND st_category = " . $dbr->addQuotes($category) . " " . "AND st_key like " . $dbr->addQuotes("%" . str_replace(" ", "%", $key) . "%") . " " . "LIMIT {$offset}, {$limit};"; } else { $sql = "SELECT st_title, st_user_text, st_user FROM suggested_titles WHERE st_used= 0" . ($category ? " AND st_category = " . $dbr->addQuotes($category) : '') . " AND st_patrolled=1 ORDER BY st_suggested DESC LIMIT {$offset}, {$limit}"; } $res = $dbr->query($sql, __METHOD__); $wgOut->addHTML($this->getSearchBox($key, $category)); if ($dbr->numRows($res) > 0) { if ($key) { $col_header = 'Requests for <strong>"' . htmlentities($key) . '"</strong>'; } elseif ($category) { $col_header = str_replace(" and ", " & ", $category); } else { $col_header = wfMsg('suggested_list_all'); } if ($category && $category != 'Other') { $cat_class = preg_replace('/&/', 'and', $category); $cat_class = 'cat_' . strtolower(preg_replace('@[^A-Za-z0-9]@', '', $cat_class)); $cat_icon = '<div class="cat_icon ' . $cat_class . '"></div>'; } $wgOut->addHTML("<table class='suggested_titles_list wh_block'>"); $wgOut->addHTML("<tr class='st_top_row'><th class='st_icon'>{$cat_icon}</th><th class='st_title'>{$col_header}</th><th>Requested By</th></tr>"); $count = 0; foreach ($res as $row) { $t = Title::newFromDBKey($row->st_title); if (!$t) { continue; } $c = ""; if ($count % 2 == 1) { $c = "class='st_on'"; } if ($row->st_user == 0) { $wgOut->addHTML("<tr><td class='st_write'><a href='/Special:CreatePage/{$t->getPartialURL()}'>Write</td><td class='st_title'>{$t->getText()}</td><td class='st_requestor'>Anonymous</td>\n\t\t\t\t\t\t\t</tr>"); } else { $u = User::newFromName($row->st_user_text); $wgOut->addHTML("<tr><td class='st_write'><a href='/Special:CreatePage/{$t->getPartialURL()}'>Write</td><td class='st_title'>{$t->getText()}</td><td class='st_requestor'><a href='{$u->getUserPage()->getFullURL()}'>{$u->getName()}</a>\n\t\t\t\t\t\t\t</tr>"); } $count++; } $wgOut->addHTML("</table>"); $key = $st_search; if ($offset != 0) { $url = $_SERVER['SCRIPT_URI']; if ($key) { $url .= "?st_search=" . urlencode($key); } elseif ($category) { $url .= "?category=" . urlencode($category); } $wgOut->addHTML("<a class='pagination' style='float: left;' href='" . $url . "&offset=" . max($offset - $limit, 0) . "'>Previous {$limit}</a>"); } if ($count == $limit) { $url = $_SERVER['SCRIPT_URI']; if ($key) { $url .= "?st_search=" . urlencode($key); } elseif ($category) { $url .= "?category=" . urlencode($category); } $wgOut->addHTML("<a class='pagination' style='float: right;' href='" . $url . "&offset=" . ($offset + $limit) . "'>Next {$limit}</a>"); } $wgOut->addHTML("<br class='clearall' />"); } else { if ($key) { $wgOut->addHTML(wfMsg('suggest_noresults', htmlentities($key))); } else { $wgOut->addHTML(wfMsg('suggest_noresults', htmlentities($category))); } } } }
| st_created | varchar(14) | NO | | | | +-----------------+------------------+------+-----+---------+----------------+ */ $f = file_get_contents($argv[2]); $lines = split("\n", $f); $keys = array(); foreach ($lines as $line) { $tokens = split("\t", $line); if (sizeof($tokens) < 2) { echo "too few tokens for {$line}\n"; continue; } $title = preg_replace('@^"how to @i', '', $tokens[1]); $title = preg_replace('@"@', '', $title); $title = preg_replace("@\r@", '', $title); $key = generateSearchKey($title); $t = Title::makeTitle(NS_MAIN, $title); if (!$t) { echo "no object {$title}\n"; exit; continue; } if (isset($keys[$key])) { echo "already have a key for {$key}\n"; continue; } $keys[$key] = 1; # check for bad words if (preg_match("/{$bad_re}/i", $title, $matches)) { echo "excluding {$title} because of bad word {$matches[0]}\n"; continue;