function execute($par)
 {
     global $wgOut, $wgUser, $wgRequest;
     if ($wgUser->getID() == 0 || !($wgUser->isSysop() || in_array('newarticlepatrol', $wgUser->getRights()) || $wgUser->getName() == "Gloster flyer" || $wgUser->getName() == "Byankno1")) {
         $wgOut->setRobotpolicy('noindex,nofollow');
         $wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext');
         return;
     }
     wfLoadExtensionMessages('Spellchecker');
     $wgOut->setHTMLTitle('Spellchecker Proposed Whitelist');
     $wgOut->setPageTitle('Spellchecker Proposed Whitelist');
     $wgOut->addHTML("<style type='text/css' media='all'>/*<![CDATA[*/ @import '" . wfGetPad('/extensions/min/f/extensions/wikihow/spellchecker/spellchecker.css?') . WH_SITEREV . "'; /*]]>*/</style> ");
     $dbr = wfGetDB(DB_SLAVE);
     $wgOut->addHTML("<p>" . wfMsgWikiHtml('spch-proposedwhitelist') . "</p>");
     if ($wgRequest->wasPosted()) {
         $wordsAdded = array();
         $wordsRemoved = array();
         $dbw = wfGetDB(DB_MASTER);
         foreach ($wgRequest->getValues() as $key => $value) {
             $wordId = intval(substr($key, 5));
             // 5 = "word-"
             $word = $dbr->selectField(wikiHowDictionary::WHITELIST_TABLE, 'sw_word', array('sw_id' => $wordId), __METHOD__);
             $msg = "";
             switch ($value) {
                 case "lower":
                     $lWord = lcfirst($word);
                     $lWordId = $dbr->selectField(wikiHowDictionary::WHITELIST_TABLE, 'sw_id', array('sw_word' => $lWord), __METHOD__);
                     if ($lWordId == $wordId) {
                         //submitting the same word as was entered
                         $dbw->update(wikiHowDictionary::WHITELIST_TABLE, array('sw_active' => 1), array('sw_id' => $wordId));
                         $msg = "Accepted {$word} into the whitelist";
                     } else {
                         //they've chosen to make it lowercase, when it wasn't to start
                         if ($lWordId === false) {
                             //doesn't exist yet
                             $dbw->insert(wikiHowDictionary::WHITELIST_TABLE, array(wikiHowDictionary::WORD_FIELD => $lWord, wikiHowDictionary::USER_FIELD => $wgUser->getID(), wikiHowDictionary::ACTIVE_FIELD => 1), __METHOD__, "IGNORE");
                         } else {
                             //already exists, so update it
                             $dbw->update(wikiHowDictionary::WHITELIST_TABLE, array('sw_active' => 1), array('sw_id' => $lWordId));
                         }
                         $dbw->delete(wikiHowDictionary::WHITELIST_TABLE, array('sw_id' => $wordId));
                         $msg = "Put {$lWord} into whitelist as lowercase. Removed uppercase version.";
                     }
                     wikiHowDictionary::invalidateArticlesWithWord($dbr, $dbw, $lWord);
                     $wordsAdded[] = $lWord;
                     break;
                 case "reject":
                     $dbw->delete(wikiHowDictionary::WHITELIST_TABLE, array('sw_id' => $wordId));
                     $msg = "Removed {$word} from the whitelist";
                     $wordsRemoved[] = $word;
                     break;
                 case "caps":
                     $uWord = ucfirst($word);
                     $uWordId = $dbr->selectField(wikiHowDictionary::WHITELIST_TABLE, 'sw_id', array('sw_word' => $uWord), __METHOD__);
                     if ($uWordId == $wordId) {
                         //submitting the same word as was entered
                         $dbw->update(wikiHowDictionary::WHITELIST_TABLE, array('sw_active' => 1), array('sw_id' => $wordId));
                         $msg = "Accepted {$word} into the whitelist";
                     } else {
                         //they've chosen to make it lowercase, when it wasn't to start
                         if ($uWordId === false) {
                             //doesn't exist yet
                             $dbw->insert(wikiHowDictionary::WHITELIST_TABLE, array(wikiHowDictionary::WORD_FIELD => $uWord, wikiHowDictionary::USER_FIELD => $wgUser->getID(), wikiHowDictionary::ACTIVE_FIELD => 1), __METHOD__, "IGNORE");
                         } else {
                             //already exists, so update it
                             $dbw->update(wikiHowDictionary::WHITELIST_TABLE, array('sw_active' => 1), array('sw_id' => $uWordId));
                         }
                         $dbw->delete(wikiHowDictionary::WHITELIST_TABLE, array('sw_id' => $wordId));
                         $msg = "Put {$uWord} into whitelist as uppercase. Removed lowercase version.";
                     }
                     wikiHowDictionary::invalidateArticlesWithWord($dbr, $dbw, $uWord);
                     $wordsAdded[] = $uWord;
                     break;
                 case "ignore":
                 default:
                     break;
             }
             if ($msg != "") {
                 $log = new LogPage('whitelist', false);
                 // false - dont show in recentchanges
                 $t = Title::newFromText("Special:ProposedWhitelist");
                 $log->addEntry($value, $t, $msg);
             }
         }
         if (count($wordsAdded) > 0) {
             $wgOut->addHTML("<p><b>" . implode(", ", $wordsAdded) . "</b> " . (count($wordsAdded) > 1 ? "were" : "was") . " added to the whitelist.</p>");
         }
         if (count($wordsRemoved) > 0) {
             $wgOut->addHTML("<p><b>" . implode(", ", $wordsRemoved) . "</b> " . (count($wordsRemoved) > 1 ? "were" : "was") . " were removed from the whitelist.</p>");
         }
     }
     //show table
     list($limit, $offset) = wfCheckLimits(50, '');
     $res = $dbr->select(wikiHowDictionary::WHITELIST_TABLE, '*', array(wikiHowDictionary::ACTIVE_FIELD => 0), __METHOD__, array("LIMIT" => $limit, "OFFSET" => $offset));
     $num = $dbr->numRows($res);
     $words = array();
     foreach ($res as $item) {
         $words[] = $item;
     }
     $paging = wfViewPrevNext($offset, $limit, "Special:ProposedWhitelist", "", $num < $limit);
     $wgOut->addHTML("<p>{$paging}</p>");
     //ok, lets create the table
     $wgOut->addHTML("<form name='whitelistform' action='/Special:ProposedWhitelist' method='POST'>");
     $wgOut->addHTML("<table id='whitelistTable' cellspacing='0' cellpadding='0'><thead><tr>");
     $wgOut->addHTML("<td>Word</td><td class='wide'>Correctly spelled,<br /> always require that the first letter be capitalized</td><td class='wide'>Correctly spelled,<br /> do not require first letter to be capitalized</td><td>Reject - not a word</td><td>I'm not sure</td></tr></thead>");
     /////SAMPLES
     $wgOut->addHTML("<tr class='sample'><td class='word'>kiittens</td>");
     $wgOut->addHTML("<td><input type='radio' disabled='disabled' value='caps' name='sample-1'></td>");
     $wgOut->addHTML("<td><input type='radio' disabled='disabled' value='lower' name='sample-1'></td>");
     $wgOut->addHTML("<td><input type='radio' disabled='disabled' checked='checked' value='reject' name='sample-1'></td>");
     $wgOut->addHTML("<td><input type='radio' disabled='disabled' value='ignore' name='sample-1'></td>");
     $wgOut->addHTML("</tr>");
     $wgOut->addHTML("<tr class='sample'><td class='word'>hawaii</td>");
     $wgOut->addHTML("<td><input type='radio' disabled='disabled' checked='checked' value='caps' name='sample-2'></td>");
     $wgOut->addHTML("<td><input type='radio' disabled='disabled' value='lower' name='sample-2'></td>");
     $wgOut->addHTML("<td><input type='radio' disabled='disabled' value='reject' name='sample-2'></td>");
     $wgOut->addHTML("<td><input type='radio' disabled='disabled' value='ignore' name='sample-2'></td>");
     $wgOut->addHTML("</tr>");
     $wgOut->addHTML("<tr class='sample'><td class='word'>Dude</td>");
     $wgOut->addHTML("<td><input type='radio' disabled='disabled' value='caps' name='sample-3' /></td>");
     $wgOut->addHTML("<td><input type='radio' disabled='disabled' checked='checked' value='lower' name='sample-3' /></td>");
     $wgOut->addHTML("<td><input type='radio' disabled='disabled' value='reject' name='sample-3' /></td>");
     $wgOut->addHTML("<td><input type='radio' disabled='disabled' value='ignore' name='sample-3' /></td>");
     $wgOut->addHTML("</tr>");
     if (count($words) == 0) {
         //no words waiting to be approved
         $wgOut->addHTML("<tr><td colspan='5' class='word'>No words to approve right now. Please check back again later</td></tr>");
     } else {
         foreach ($words as $word) {
             $firstLetter = substr($word->{wikiHowDictionary::WORD_FIELD}, 0, 1);
             $wgOut->addHTML("<tr><td class='word'>" . $word->{wikiHowDictionary::WORD_FIELD} . " [<a target='_blank' href='http://www.google.com/search?q=" . $word->{wikiHowDictionary::WORD_FIELD} . "'>?</a>]</td>");
             $wgOut->addHTML("<td><input type='radio' value='caps' name='word-" . $word->sw_id . "'></td>");
             $wgOut->addHTML("<td><input type='radio' value='lower' name='word-" . $word->sw_id . "'></td>");
             $wgOut->addHTML("<td><input type='radio' value='reject' name='word-" . $word->sw_id . "'></td>");
             $wgOut->addHTML("<td><input type='radio' value='ignore' name='word-" . $word->sw_id . "' checked='checked'></td>");
             $wgOut->addHTML("</tr>");
         }
         $wgOut->addHTML("<tr><td colspan='5'><input type='button' onclick='document.whitelistform.submit();' value='Submit' class='guided-button' /></td></tr>");
     }
     $wgOut->addHTML("</table></form>");
 }
Example #2
0
function removeWordFile($fileName)
{
    echo "getting file " . $fileName . "\n";
    $fileContents = file_get_contents($fileName);
    $words = explode("\n", $fileContents);
    wikiHowDictionary::batchRemoveWordsFromDictionary($words);
}