Exemple #1
0
 function execute($par)
 {
     global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgDBname;
     global $wgRequest, $wgSitename, $wgLanguageCode, $IP;
     global $wgScript, $wgParser, $wgFilterCallback, $wgScriptPath;
     $fname = "wfSpecialRequestTopic";
     $action = "";
     if ($wgUser->isBlocked()) {
         $wgOut->blockedPage();
         return;
     }
     if (!$wgRequest->wasPosted()) {
         $wgOut->addHTML("<b>" . wfMsg('lookingforhow') . "</b> <br/> " . wfMsg('requestarticleexdog') . "<br/><br/> ");
         $this->getForm();
     } else {
         // this is a post, accept the POST data and create the
         // Request article
         $topic = $wgRequest->getVal('topic');
         $details = $wgRequest->getVal('details');
         if ($wgUser->getID() == 0 && preg_match("@http://@i", $details)) {
             $wgOut->addHTML("Error: anonymous users are not allowed to include links in requests.");
             return;
         }
         if (!isset($_POST['override']) && $wgLanguageCode == 'en') {
             $l = new LSearch();
             $titles = $l->googleSearchResultTitles($topic, 0, 5);
             if (sizeof($titles) > 0) {
                 $wgOut->addHTML(wfMsg('already-related-topics') . "<br>\n\t\t\t\t\t<ul id=Things_You27ll_Need>");
                 $count = 0;
                 foreach ($titles as $t) {
                     if ($count == 10) {
                         break;
                     }
                     if ($t == null) {
                         continue;
                     }
                     $wgOut->addHTML("<li style='margin-bottom: 0px'><a href=" . $t->getFullURL() . ">How to " . $t->getText() . "</a></li>");
                     $count++;
                 }
                 $wgOut->addHTML("</ul>");
                 $wgOut->addHTML(wfMsg('no-submit-existing-topic'));
                 $this->getForm(true);
                 return;
             }
         }
         // cut off extra ?'s or whatever
         if ($wgLanguageCode == 'en') {
             while (!ereg('[a-zA-Z0-9)\\"]$', $topic)) {
                 $topic = substr($topic, 0, strlen($topic) - 1);
             }
         }
         if ($wgLanguageCode == 'en') {
             require_once 'EditPageWrapper.php';
             $topic = EditPageWrapper::formatTitle($topic);
         }
         $title = Title::newFromText($topic, NS_ARTICLE_REQUEST);
         $category = $wgRequest->getVal("category", "");
         if ($category == "") {
             $category = "Other";
         }
         $details .= "\n[[Category:{$category} Requests]]";
         // check if we can do this
         if ($wgUser->isBlocked()) {
             $wgOut->addWikiText(wfMsg('blocked-ip'));
             return;
         }
         if ($wgUser->pingLimiter()) {
             $wgOut->rateLimited();
             return;
         }
         if ($wgFilterCallback && $wgFilterCallback($title, $details, $tmp)) {
             // Error messages or other handling should be performed by
             // the filter function
             return;
         }
         // create a user
         $user = null;
         if ($wgUser->getID() == 0) {
             if ($wgRequest->getVal('email', null)) {
                 $user = WikihowUser::createTemporaryUser($wgRequest->getVal('name'), $wgRequest->getVal('email'));
                 $wgUser = $user;
             }
         }
         if ($title->getArticleID() <= 0) {
             // not yet created. good.
             $article = new Article($title);
             $ret = $article->insertNewArticle($details, "", false, false, false, $user);
             wfRunHooks('ArticleSaveComplete', array(&$article, &$user, $details, "", false, false, NULL));
             //clear the redirect that is set by insertNewArticle
             $wgOut->redirect('');
             $options = ParserOptions::newFromUser($wgUser);
             $wgParser->parse($details, $title, $options);
         } else {
             // TODO: what to do here? give error / warning? append details?
             // this question has already been asked, if you want to ask
             // a slightly different question, go here:
         }
         $wgOut->addWikiText(wfMsg('thank-you-requesting-topic'));
         $wgOut->returnToMain(false);
     }
 }
<?php

require_once 'commandLine.inc';
require_once 'EditPageWrapper.php';
$rows = DatabaseHelper::batchSelect('page', array('page_id', 'page_title', 'page_is_redirect'), array('page_namespace' => NS_MAIN, 'page_is_redirect' => 0), __METHOD__);
foreach ($rows as $row) {
    $title = Title::newFromDBkey($row->page_title);
    if (!$title) {
        continue;
    }
    $text = $title->getText();
    $formatted = EditPageWrapper::formatTitle($text);
    if ($formatted != $text && strlen($formatted) != strlen($text)) {
        $redir = $row->page_is_redirect ? ' (redirect)' : '';
        print "{$title}{$redir} ->\n{$formatted}\n";
    }
}
 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]}\"/>&nbsp;<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'));
 }
Exemple #4
0
 function execute($par)
 {
     global $wgOut, $wgRequest, $wgUser, $wgTitle, $wgLanguageCode, $wgHooks;
     require_once 'Leaderboard.body.php';
     if ($wgLanguageCode != 'en') {
         $wgOut->errorpage('nosuchspecialpage', 'nospecialpagetext');
         return;
     }
     $map = SuggestCategories::getCatMap(true);
     $cats = SuggestCategories::getSubscribedCats();
     $dbr = wfGetDB(DB_SLAVE);
     wfLoadExtensionMessages('RecommendedArticles');
     $wgOut->setRobotPolicy('noindex,nofollow');
     $wgOut->setHTMLTitle('Manage Suggested Topics - wikiHow');
     $target = isset($par) ? $par : $wgRequest->getVal('target');
     if ($target == 'TopRow') {
         $wgOut->setArticleBodyOnly(true);
         $wgOut->addHTML($this->getTopLevelSuggestions($map, $cats));
         return;
     }
     $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>');
     ListRequestedTopics::setActiveWidget();
     ListRequestedTopics::setTopAuthorWidget();
     ListRequestedTopics::getNewArticlesWidget();
     $wgHooks["pageTabs"][] = array("wfRequestedTopicsTabs");
     //heading with link
     $request = '<a href="/Special:RequestTopic" class="edit">' . wfMsg('requesttopic') . '</a>';
     $heading = $request . '<h2>' . wfMsg('suggestedarticles_header') . '</h2>';
     $wgOut->addHTML($heading);
     $suggestions = "";
     if (count($cats) > 0) {
         foreach ($cats as $key) {
             $cat = $map[$key];
             $suggestionsArray = array();
             // grab some suggestions
             $randstr = wfRandom();
             $headerDone = false;
             $suggCount = 0;
             // grab 2 suggested articles that are NOT by ANON
             $resUser = $dbr->select('suggested_titles', array('st_title', 'st_user', 'st_user_text'), array('st_category' => $cat, 'st_used=0', "st_user > 0"), __METHOD__, array("ORDER BY" => "st_random", "LIMIT" => 2));
             foreach ($resUser as $userRow) {
                 $randSpot = mt_rand(0, 4);
                 while (!empty($suggestionsArray[$randSpot])) {
                     $randSpot = mt_rand(0, 4);
                 }
                 $suggestionsArray[$randSpot]->title = $userRow->st_title;
                 $suggestionsArray[$randSpot]->user = $userRow->st_user;
                 $suggCount++;
             }
             $res = $dbr->select('suggested_titles', array('st_title', 'st_user', 'st_user_text'), array('st_category' => $cat, 'st_used' => 0, 'st_traffic_volume' => 2, "st_random >= {$randstr}"), __METHOD__, array("ORDER BY" => "st_random", "LIMIT" => 5));
             if ($dbr->numRows($res) > 0) {
                 foreach ($res as $row) {
                     if ($suggCount >= 5) {
                         break;
                     }
                     $randSpot = mt_rand(0, 4);
                     while (!empty($suggestionsArray[$randSpot])) {
                         $randSpot = mt_rand(0, 4);
                     }
                     $suggestionsArray[$randSpot]->title = $row->st_title;
                     $suggestionsArray[$randSpot]->user = $row->st_user;
                     $suggCount++;
                 }
             }
             if ($cat != 'Other') {
                 $cat_class = 'cat_' . strtolower(str_replace(' ', '', $cat));
                 $cat_class = preg_replace('/&/', 'and', $cat_class);
                 $cat_icon = '<div class="cat_icon ' . $cat_class . '"></div>';
             } else {
                 $cat_icon = '';
             }
             if ($suggCount > 0) {
                 $suggestions .= "<table class='suggested_titles_list wh_block'>";
                 $suggestions .= "<tr class='st_top_row'><th class='st_icon'>{$cat_icon}</th><th class='st_title'><strong>{$cat}</strong></th><th>Requested By</th></tr>";
                 require_once 'EditPageWrapper.php';
                 foreach ($suggestionsArray as $suggestion) {
                     if (!empty($suggestionsArray)) {
                         $t = Title::newFromText(EditPageWrapper::formatTitle($suggestion->title));
                         if ($suggestion->user > 0) {
                             $u = User::newFromId($suggestion->user);
                             $u = "<a href='{$u->getUserPage()->getFullURL()}'>{$u->getName()}</a>";
                         } else {
                             $u = "Anonymous";
                         }
                         $suggestions .= "<tr><td class='st_write'><a href='/Special:CreatePage/{$t->getPartialURL()}'>Write</td><td class='st_title'>{$t->getText()}</td><td class='st_requestor'>{$u}</td></tr>";
                     }
                 }
                 $suggestions .= "</table>";
             }
         }
     }
     if ($wgRequest->getInt('surprise') == 1 || $suggestions == "") {
         $wgOut->addHTML("<div id='top_suggestions'>" . $this->getTopLevelSuggestions($map, $cats) . "</div>");
     }
     $wgOut->addHTML("<br class='clearall' /><div id='suggested_surprise_big'><a href='/Special:RecommendedArticles?surprise=1' class='button secondary'>" . wfMsg('suggested_list_button_surprise') . "</a></div><br class='clearall' />");
     if (sizeof($cats) == 0) {
         $wgOut->addHTML(wfMsg('suggested_nocats'));
         $wgOut->addHTML("<a href='#' id='choose_cats'>Choose which categories to display</a>");
         return;
     }
     if ($wgUser->getID() > 0) {
         $wgOut->addHTML($suggestions);
         $wgOut->addHTML("<a href='#' id='choose_cats'>Choose which categories to display</a>");
     } else {
         $rt = $wgTitle->getPrefixedURL();
         $q = "returnto={$rt}";
         $wgOut->addHTML(wfMsg('recommend_anon', $q));
     }
 }
 #echo $title; exit;
 $excluded = 0;
 if (preg_replace('/\\W/', '', $title) == '') {
     $updates[] = array($row->id, "", 1, "");
     continue;
 }
 #echo "checking bad_re for {$title}, {$row->id}\n";
 if (preg_match("/{$bad_re}/i", $title, $matches)) {
     #echo "excluding $title because of {$matches[0]}\n";
     $excluded = 1;
 }
 if (trim($title) == "") {
     continue;
 }
 #echo "formatting title bad_re for {$title}, {$row->id}\n";
 $title = EditPageWrapper::formatTitle($title);
 /*		try {
 			$title = 'How to ' . preg_replace($ac_re, $ac_re2,  $title);	
 		} catch (Exception $e) {
 			echo "caught e $e\n";
 			print_r($ac_re);
 			print_r($ac_re2);
 			exit;	
 		}*/
 #echo "generating key for for {$title}, {$row->id}\n";
 $key = generateSearchKey($title);
 $updates[] = array($row->id, $title, $excluded, $key);
 if ($count > 0 && $count % 100 == 0) {
     #echo "current at $count\n";
 }
 $count++;
require_once 'commandLine.inc';
require_once 'EditPageWrapper.php';
require_once 'Newarticleboost.body.php';
$name = "Wendy Weaver";
$lines = split("\n", file_get_contents($argv[0]));
$titles = array();
$wgUser = User::newFromName($name);
foreach ($lines as $line) {
    $line = trim($line);
    if ($line == "") {
        continue;
    }
    $tokens = split("\t", $line);
    $t = Title::newFromURL(preg_replace("@^/@", "", $tokens[0]));
    if (!$t) {
        echo "Can't make title out of {$tokens[0]}\n";
        continue;
    }
    $text = EditPageWrapper::formatTitle(trim(preg_replace("@how to@i", "", $tokens[1])));
    $titles[$text] = $t;
}
foreach ($titles as $text => $t) {
    if ($t->getArticleID() == 0) {
        echo "{$t->getFullText()} doesnt exist on this server\n";
        continue;
    }
    AddRelatedLinks::addLinkToRandomArticleInSameCategory($t, "sprinkling links", $text);
    echo "Doing {$t->getFullText()} ...\n";
}
$dbw = wfGetDB(DB_MASTER);
$dbw->update('recentchanges', array('rc_patrolled' => 1), array('rc_user_text' => $name));