Ejemplo n.º 1
0
 function catSearch($q)
 {
     global $wgRequest;
     $dbr = wfGetDB(DB_SLAVE);
     $prefix = "Category ";
     $query = $dbr->strencode($prefix . $q);
     $suggestions = array();
     $count = 0;
     // Add an exact category match
     $t = Title::newFromText($q, NS_CATEGORY);
     if ($t && $t->exists() && !$this->ignoreCategory($t->getText())) {
         $suggestions[] = $t->getPartialUrl();
     }
     $l = new LSearch();
     $results = $l->googleSearchResultTitles($query, 0, 30, 0, LSearch::SEARCH_CATSEARCH);
     foreach ($results as $t) {
         if (!$this->ignoreCategory($t->getText())) {
             if ($t->getNamespace() == NS_CATEGORY) {
                 $suggestions[] = $t->getPartialUrl();
             } elseif ($t->getNameSpace() == NS_MAIN && $count < 3) {
                 $count++;
                 $suggestions = array_merge($suggestions, $this->getParentCats($t));
             }
         }
     }
     $suggestions = array_values(array_unique($suggestions));
     // Return the top 15
     return array_slice($suggestions, 0, 15);
 }
 /**
  * Fetch the Yahoo Boss results and add them to the input array
  */
 private static function fetchYBossResults(&$queries)
 {
     $search = new LSearch();
     foreach ($queries as &$query) {
         $titles = $search->googleSearchResultTitles($query['query'], 0, 10);
         foreach ($titles as $title) {
             $query['results'][] = $title ? 'http://www.wikihow.com/' . $title->getPartialURL() : '';
         }
     }
 }
Ejemplo n.º 3
0
 function getRelatedTopicsText($target)
 {
     global $wgOut, $wgUser, $wgLanguageCode;
     // INTL: Don't return related topics for non-english sites
     if ($wgLanguageCode != 'en') {
         return wfMsg('createpage_step1box_noresults', $s);
     }
     wfLoadExtensionMessages('CreatePage');
     $hits = array();
     $t = Title::newFromText(EditPageWrapper::formatTitle($target));
     $l = new LSearch();
     $hits = $l->googleSearchResultTitles($target, 0, 10);
     $count = 0;
     if ($t->getArticleID() > 0) {
         return $wgOut->parse(wfMsg('createpage-title-exists', $t->getFullText()) . "<br/><br/>") . "<a href='" . $t->getEditURL() . "'>" . wfMsg('createpage-edit-existing') . "</a><br/>";
     }
     if (sizeof($hits) > 0) {
         foreach ($hits as $hit) {
             $t1 = $hit;
             if ($count == 5) {
                 break;
             }
             if ($t1 == null) {
                 continue;
             }
             if ($t1->getNamespace() != NS_MAIN) {
                 continue;
             }
             // check if the result is a redirect
             $a = new Article($t1);
             if ($a && $a->isRedirect()) {
                 continue;
             }
             if ($wgUser->getID() > 0) {
                 $gatuser = '******';
             } else {
                 $gatuser = '******';
             }
             // check if the article exists
             if (strtolower($t1->getText()) == strtolower($target->getText())) {
                 return $wgOut->parse(wfMsg('createpage-title-exists', $t1->getFullText()) . "<br/><br/>") . "<a href='" . $t->getEditURL() . "'>" . wfMsg('createpage-edit-existing') . "</a><br/>";
             }
             $name = htmlspecialchars($target->getDBKey());
             $value = htmlspecialchars($t1->getDBKey());
             $s .= "<input type='radio' name='{$name}' value='{$value}' onchange='document.getElementById(\"cp_next\").disabled = false; gatTrack(\"{$gatuser}\",\"Create_redirect\");'>\n\t\t\t\t\t\t<a href='{$t1->getFullURL()}' target='new'>" . wfMsg('howto', $t1->getText()) . "</a><br/><br/>";
             $count++;
         }
         if ($count == 0) {
             return wfMsg('createpage_related_nomatches');
         }
         $html = wfMsg('createpage_related_head', $target->getText()) . "<div class='createpage_related_options'>" . $s . "<input type='radio' name='" . $target->getDBKey() . "' value='none' checked='checked' onchange='document.getElementById(\"cp_next\").disabled = false;' />\n\t\t\t\t\t<b>" . wfMsg('createpage_related_none') . "</b>" . "</div>";
         return $html;
     }
     return wfMsg('createpage_related_nomatches');
 }
Ejemplo n.º 4
0
 /**
  * Processes a search for users who are looking for an article to
  * add a video to
  */
 function doSearch($target, $orderby, $query, $search)
 {
     global $wgOut, $wgRequest;
     $me = Title::makeTitle(NS_SPECIAL, "Importvideo");
     $wgOut->addHTML(wfMsg('importvideo_searchinstructions') . "<br/><br/><form action='{$me->getFullURL()}'>\n\t\t\t\t\t<input type='hidden' name='target' value='" . htmlspecialchars($target) . "'/>\n\t\t\t\t\t<input type='hidden' name='orderby' value='{$orderby}'/>\n\t\t\t\t\t<input type='hidden' name='popup' value='{$wgRequest->getVal('popup')}'/>\n\t\t\t\t\t<input type='hidden' name='q' value='" . htmlspecialchars($query) . "' >\n\t\t\t\t\t<input type='text' name='dosearch' value='" . ($search != "1" ? htmlspecialchars($search) : "") . "' size='40'/>\n\t\t\t\t\t<input type='submit' value='" . wfMsg('importvideo_search') . "'/>\n\t\t\t\t</form>\n\t\t\t\t<br/>");
     if ($search != "1") {
         $l = new LSearch();
         $results = $l->googleSearchResultTitles($search);
         $base_url = $me->getFullURL() . "?&q=" . urlencode($query) . "&source={$source}";
         if (sizeof($results) == 0) {
             $wgOut->addHTML(wfMsg('importvideo_noarticlehits'));
             return;
         }
         #output the results
         $wgOut->addHTML(wfMsg("importvideo_articlesearchresults") . "<ul>");
         foreach ($results as $t) {
             $wgOut->addHTML("<li><a href='" . $base_url . "&target=" . urlencode($t->getText()) . "'>" . wfMsg('howto', $t->getText() . "</a></li>"));
         }
         $wgOut->addHTML("</ul>");
     }
 }
Ejemplo n.º 5
0
    private function displayNABConsole(&$dbw, &$dbr, $target)
    {
        global $wgOut, $wgRequest, $wgUser, $wgParser;
        $not_found = false;
        $title = Title::newFromURL($target);
        if (!$title || !$title->exists()) {
            $articleName = $title ? $title->getFullText() : $target;
            $wgOut->addHTML("<p>Error: Article &ldquo;{$articleName}&rdquo; not found. Return to <a href='/Special:Newarticleboost'>New Article Boost</a> instead.</p>");
            $not_found = true;
        }
        if (!$not_found) {
            $rev = Revision::newFromTitle($title);
            if (!$rev) {
                $wgOut->addHTML("<p>Error: No revision for &ldquo;{$title->getFullText()}&rdquo;. Return to <a href='/Special:Newarticleboost'>New Article Boost</a> instead.</p>");
                $not_found = true;
            }
        }
        if (!$not_found) {
            $in_nab = $dbr->selectField('newarticlepatrol', 'count(*)', array('nap_page' => $title->getArticleID()), __METHOD__) > 0;
            if (!$in_nab) {
                $wgOut->addHTML("<p>Error: This article is not in the NAB list.</p>");
                $not_found = true;
            }
        }
        if ($not_found) {
            $pageid = $wgRequest->getVal('page');
            if (strpos($target, ':') !== false && $pageid) {
                $wgOut->addHTML('<p>We can to try to <a href="/Special:NABClean/' . $pageid . '">delete this title</a> if you know this title exists in NAB yet is likely bad data.</p>');
            }
            return;
        }
        $locked = false;
        $min_timestamp = $dbr->selectField("revision", "min(rev_timestamp)", "rev_page=" . $title->getArticleId(), __METHOD__);
        $first_user = $dbr->selectField("revision", "rev_user_text", array("rev_page=" . $title->getArticleId(), 'rev_timestamp' => $min_timestamp), __METHOD__);
        $first_user_id = $dbr->selectField("revision", "rev_user", array("rev_page=" . $title->getArticleId(), 'rev_timestamp' => $min_timestamp), __METHOD__);
        $user = new User();
        if ($first_user_id) {
            $user->setId($first_user_id);
            $user->loadFromDatabase();
        } else {
            $user->setName($first_user);
        }
        $user_talk = $user->getTalkPage();
        $ut_id = $user_talk->getArticleID();
        $display_name = $user->getRealName() ? $user->getRealName() : $user->getName();
        $wgOut->setPageTitle(wfMsg('nap_title', $title->getFullText()));
        $count = $dbr->selectField('suggested_titles', array('count(*)'), array('st_title' => $title->getDBKey()), __METHOD__);
        $extra = $count > 0 ? ' - from Suggested Titles database' : '';
        $wgOut->addWikiText(wfMsg('nap_writtenby', $user->getName(), $display_name, $extra));
        $wgOut->addHTML(wfMsgExt('nap_quicklinks', 'parseinline', $this->me->getFullText() . "/" . $title->getFullText()));
        /// CHECK TO SEE IF ARTICLE IS LOCKED OR ALREADY PATROLLED
        $aid = $title->getArticleID();
        $half_hour_ago = wfTimestamp(TS_MW, time() - 30 * 60);
        $patrolled = $dbr->selectField('newarticlepatrol', 'nap_patrolled', array("nap_page={$aid}"), __METHOD__);
        if ($patrolled) {
            $locked = true;
            $wgOut->addHTML(wfMsgExt("nap_patrolled", 'parse'));
        } else {
            $user_co = $dbr->selectField('newarticlepatrol', 'nap_user_co', array("nap_page={$aid}", "nap_timestamp_co > '{$half_hour_ago}'"), __METHOD__);
            if ($user_co != '' && $user_co != 0 && $user_co != $wgUser->getId()) {
                $x = User::newFromId($user_co);
                $wgOut->addHTML(wfMsgExt("nap_usercheckedout", 'parse', $x->getName()));
                $locked = true;
            } else {
                // CHECK OUT THE ARTICLE TO THIS USER
                $ts = wfTimestampNow();
                $dbw->update('newarticlepatrol', array('nap_timestamp_co' => $ts, 'nap_user_co' => $wgUser->getId()), array("nap_page = {$aid}"), __METHOD__);
            }
        }
        $expandSpan = '<span class="nap_expand">&#9660;</span>';
        $externalLinkImg = '<img src="' . wfGetPad('/skins/common/images/external.png') . '"/>';
        /// SIMILAR RESULT
        $wgOut->addHTML("<div class='nap_section minor_section'>");
        $wgOut->addHTML("<h2 class='nap_header'>{$expandSpan} " . wfMsg('nap_similarresults') . "</h2>");
        $wgOut->addHTML("<div class='nap_body section_text'>");
        $count = 0;
        $l = new LSearch();
        $hits = $l->googleSearchResultTitles($title->getFullText(), 0, 5);
        if (sizeof($hits) > 0) {
            $html = "";
            foreach ($hits as $hit) {
                $t1 = $hit;
                $id = rand(0, 500);
                if ($t1 == null || $t1->getFullURL() == $title->getFullURL() || $t1->getNamespace() != NS_MAIN || !$t1->exists()) {
                    continue;
                }
                $safe_title = htmlspecialchars(str_replace("'", "&#39;", $t1->getText()));
                $html .= "<tr><td>" . $this->skin->makeLinkObj($t1, wfMsg('howto', $t1->getText())) . "</td><td style='text-align:right; width: 200px;'>[<a href='#action' onclick='nap_Merge(\"{$safe_title}\");'>" . wfMsg('nap_merge') . "</a>] " . " [<a href='#action' onclick='javascript:nap_Dupe(\"{$safe_title}\");'>" . wfMsg('nap_duplicate') . "</a>] " . " <span id='mr_{$id}'>[<a onclick='javascript:nap_MarkRelated({$id}, {$t1->getArticleID()}, {$title->getArticleID()});'>" . wfMsg('nap_related') . "</a>]</span> " . "</td></tr>";
                $count++;
            }
        }
        if ($count == 0) {
            $wgOut->addHTML(wfMsg('nap_no-related-topics'));
        } else {
            $wgOut->addHTML(wfMsg('nap_already-related-topics') . "<table style='width:100%;'>{$html}</table>");
        }
        $wgOut->addHTML(wfMsg('nap_othersearches', urlencode($title->getFullText())));
        $wgOut->addHTML("</div>");
        $wgOut->addHTML("</div>");
        /// COPYRIGHT CHECKER
        $cc_check = SpecialPage::getTitleFor('Copyrightchecker', $title->getText());
        $wgOut->addHTML("<script type='text/javascript'>window.onload = nap_cCheck; var nap_cc_url = \"{$cc_check->getFullURL()}\";</script>");
        $wgOut->addHTML("<div class='nap_section minor_section'>");
        $wgOut->addHTML("<h2 class='nap_header'>{$expandSpan} " . wfMsg('nap_copyrightchecker') . "</h2>");
        $wgOut->addHTML("<div class='nap_body section_text'>");
        $wgOut->addHTML("<div id='nap_copyrightresults'><center><img src='/extensions/wikihow/rotate.gif' alt='loading...'/></center></div>");
        $wgOut->addHTML("<center><input type='button' class='button primary' onclick='nap_cCheck();' value='Check'/></center>");
        $wgOut->addHTML("</div>");
        $wgOut->addHTML("</div>");
        /// ARTICLE PREVIEW
        $editUrl = Title::makeTitle(NS_SPECIAL, "QuickEdit")->getFullURL() . "?type=editform&target=" . urlencode($title->getFullText()) . "&fromnab=1";
        $wgOut->addHTML("<div class='nap_section minor_section'>");
        $wgOut->addHTML("<a name='article' id='anchor-article'></a>");
        $wgOut->addHTML("<h2 class='nap_header'>{$expandSpan} " . wfMsg('nap_articlepreview') . " - <a href=\"{$title->getFullURL()}\" target=\"new\">" . wfMsg('nap_articlelinktext') . "</a> {$externalLinkImg}" . " - <a href=\"{$title->getEditURL()}\" target=\"new\">" . wfMsg('edit') . "</a> {$externalLinkImg}" . " - <a href=\"{$title->getFullURL()}?action=history\" target=\"new\">" . wfMsg('history') . "</a> {$externalLinkImg}" . " - <a href=\"{$title->getTalkPage()->getFullURL()}\" target=\"new\">" . wfMsg('discuss') . "</a> {$externalLinkImg}" . "</h2>");
        $wgOut->addHTML("<div class='nap_body section_text'>");
        $wgOut->addHTML("<div id='article_contents' ondblclick='nap_editClick(\"{$editUrl}\");'>");
        $popts = $wgOut->parserOptions();
        $popts->setTidy(true);
        // $parserOutput = $wgOut->parse($rev->getText(), $title, $popts);
        $output = $wgParser->parse($rev->getText(), $title, $popts);
        $parserOutput = $output->getText();
        $magic = WikihowArticleHTML::grabTheMagic($rev->getText());
        $html = WikihowArticleHTML::processArticleHTML($parserOutput, array('no-ads' => true, 'ns' => $title->getNamespace(), 'magic-word' => $magic));
        $wgOut->addHTML($html);
        $wgOut->addHTML("</div>");
        $wgOut->addHTML("<center><input id='editButton' type='button' class='button primary' name='wpEdit' value='" . wfMsg('edit') . "' onclick='nap_editClick(\"{$editUrl}\");'/></center>");
        $wgOut->addHTML("</div>");
        $wgOut->addHTML("</div>");
        $wgOut->addHTML('<div style="clear: both;"></div>');
        /// DISCUSSION PREVIEW
        $talkPage = $title->getTalkPage();
        $wgOut->addHTML("<div class='nap_section minor_section'>");
        $wgOut->addHTML("<a name='talk' id='anchor-talk'></a>");
        $wgOut->addHTML("<h2 class='nap_header'>{$expandSpan} " . wfMsg('nap_discussion') . " - <a href=\"{$talkPage->getFullURL()}\" target=\"new\">" . wfMsg('nap_articlelinktext') . "</a> {$externalLinkImg}" . "</h2>");
        $wgOut->addHTML("<div class='nap_body section_text'>");
        $wgOut->addHTML("<div id='disc_page'>");
        if ($talkPage->getArticleID() > 0) {
            $rp = Revision::newFromTitle($talkPage);
            $wgOut->addHTML($wgOut->parse($rp->getText()));
        } else {
            $wgOut->addHTML(wfMsg('nap_discussionnocontent'));
        }
        $wgOut->addHTML(PostComment::getForm(true, $talkPage, true));
        $wgOut->addHTML("</div>");
        $wgOut->addHTML("</div>");
        $wgOut->addHTML("</div>");
        /// USER INFORMATION
        $wgOut->addHTML("<div class='nap_section minor_section'>");
        $wgOut->addHTML("<a name='user' id='anchor-user'></a>");
        $used_templates = array();
        if ($ut_id > 0) {
            $res = $dbr->select('templatelinks', array('tl_title'), array('tl_from=' . $ut_id), __METHOD__);
            while ($row = $dbr->fetchObject($res)) {
                $used_templates[] = strtolower($row->tl_title);
            }
            $dbr->freeResult($res);
        }
        $wgOut->addHTML("<h2 class='nap_header'>{$expandSpan} " . wfMsg('nap_userinfo') . " - <a href=\"{$user_talk->getFullURL()}\" target=\"new\">" . wfMsg('nap_articlelinktext') . "</a> {$externalLinkImg}" . "</h2>");
        $wgOut->addHTML("<div class='nap_body section_text'>");
        $contribs = SpecialPage::getTitleFor('Contributions', $user->getName());
        $regDateTxt = "";
        if ($user->getRegistration() > 0) {
            preg_match('/^(\\d{4})(\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)(\\d\\d)$/D', $user->getRegistration(), $da);
            $uts = gmmktime((int) $da[4], (int) $da[5], (int) $da[6], (int) $da[2], (int) $da[3], (int) $da[1]);
            $regdate = gmdate('F j, Y', $uts);
            $regDateTxt = wfMsg('nap_regdatetext', $regdate) . ' ';
        }
        $key = 'nap_userinfodetails_anon';
        if ($user->getID() != 0) {
            $key = 'nap_userinfodetails';
        }
        $wgOut->addWikiText(wfMsg($key, $user->getName(), number_format(WikihowUser::getAuthorStats($first_user), 0, "", ","), $title->getFullText(), $regDateTxt));
        if (WikihowUser::getAuthorStats($first_user) < 50) {
            if ($user_talk->getArticleId() == 0) {
                $wgOut->addHTML(wfMsg('nap_newwithouttalkpage'));
            } else {
                $rp = Revision::newFromTitle($user_talk);
                $xtra = "";
                if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE 8.0") === false) {
                    $xtra = "max-height: 300px; overflow: scroll;";
                }
                $output = $wgParser->parse($rp->getText(), $user_talk, $popts);
                $parserOutput = $output->getText();
                $wgOut->addHTML("<div style='border: 1px solid #eee; {$xtra}'>" . $parserOutput . "</div>");
            }
        }
        if ($user_talk->getArticleId() != 0 && sizeof($used_templates) > 0) {
            $wgOut->addHTML('<br />' . wfMsg('nap_usertalktemplates', implode($used_templates, ", ")));
        }
        $wgOut->addHTML(PostComment::getForm(true, $user_talk, true));
        $wgOut->addHTML("</div>");
        $wgOut->addHTML("</div>");
        /// ACTION INFORMATION
        $maxrcid = $dbr->selectField('recentchanges', 'max(rc_id)', array('rc_cur_id=' . $aid), __METHOD__);
        $wgOut->addHTML("<div class='nap_section minor_section'>");
        $wgOut->addHTML("<a name='action' id='anchor-action'></a>");
        $wgOut->addHTML("<h2 class='nap_header'> " . wfMsg('nap_action') . "</h2>");
        $wgOut->addHTML("<div class='nap_body section_text'>");
        $wgOut->addHTML("<form action='{$this->me->getFullURL()}' name='nap_form' method='post' onsubmit='return checkNap();'>");
        $wgOut->addHTML("<input type='hidden' name='target' value='" . htmlspecialchars($title->getText()) . "'/>");
        $wgOut->addHTML("<input type='hidden' name='page' value='{$aid}'/>");
        $wgOut->addHTML("<input type='hidden' name='newbie' value='" . $wgRequest->getVal('newbie', 0) . "'/>");
        $wgOut->addHTML("<input type='hidden' name='prevuser' value='" . $user->getName() . "'/>");
        $wgOut->addHTML("<input type='hidden' name='maxrcid' value='{$maxrcid}'/>");
        $wgOut->addHTML("<table>");
        $suggested = $dbr->selectField('suggested_titles', 'count(*)', array('st_title' => $title->getDBKey()), __METHOD__);
        if ($suggested > 0) {
            $wgOut->addHTML("<tr><td valign='top'>" . wfMsg('nap_suggested_warning') . "</td></tr>");
        }
        $wgOut->addHTML("</table>");
        $wgOut->addHTML(wfMsg('nap_actiontemplates'));
        if ($wgUser->isAllowed('delete') || $wgUser->isAllowed('move')) {
            $wgOut->addHTML(wfMsg('nap_actionmovedeleteheader'));
            if ($wgUser->isAllowed('move')) {
                $wgOut->addHTML(wfMsg('nap_actionmove', htmlspecialchars($title->getText())));
            }
            if ($wgUser->isAllowed('delete')) {
                $wgOut->addHTML(wfMsg('nap_actiondelete'));
            }
        }
        // BUTTONS
        $wgOut->addHTML("<input type='submit' value='" . wfMsg('nap_skip') . "' id='nap_skip' name='nap_skip' class='button secondary' />");
        if (!$locked) {
            $wgOut->addHTML("<input type='submit' value='" . wfMsg('nap_markaspatrolled') . "' id='nap_submit' name='nap_submit' class='button primary' />");
        }
        $wgOut->addHTML("</form>");
        $wgOut->addHTML("</div>");
        $wgOut->addHTML("</div>");
        $wgOut->addHTML(<<<END
<script type='text/javascript'>

var tabindex = 1;
for(i = 0; i < document.forms.length; i++) {
\tfor (j = 0; j < document.forms[i].elements.length; j++) {
\t\tswitch (document.forms[i].elements[j].type) {
\t\t\tcase 'submit':
\t\t\tcase 'text':
\t\t\tcase 'textarea':
\t\t\tcase 'checkbox':
\t\t\tcase 'button':
\t\t\t\tdocument.forms[i].elements[j].tabIndex = tabindex++;
\t\t\t\tbreak;
\t\t\tdefault:
\t\t\t\tbreak;
\t\t}
\t}
}

// Handlers for expand/contract arrows
(function (\$) {
\$('.nap_expand').click(function() {
\tvar thisSpan = \$(this);
\tvar body = thisSpan.parent().next();
\tvar footer = body.next();
\tif (body.css('display') != 'none') {
\t\tfooter.hide();
\t\tbody.css('overflow', 'hidden');
\t\tvar oldHeight = body.height();
\t\tbody.animate(
\t\t\t{ height: 0 },
\t\t\t200,
\t\t\t'swing',
\t\t\tfunction () {
\t\t\t\tthisSpan.html('&#9658;');
\t\t\t\tbody
\t\t\t\t\t.hide()
\t\t\t\t\t.height(oldHeight);
\t\t\t});
\t} else {
\t\tvar oldHeight = body.height();
\t\tbody.height(0);
\t\tbody.animate(
\t\t\t{ height: oldHeight },
\t\t\t200,
\t\t\t'swing',
\t\t\tfunction () {
\t\t\t\tthisSpan.html('&#9660;');
\t\t\t\tfooter.show();
\t\t\t\tbody.css('overflow', 'visible');
\t\t\t});
\t}
\treturn false;
});
})(jQuery);

</script>

END
);
    }
Ejemplo n.º 6
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);
     }
 }
Ejemplo n.º 7
0
 /**
  * Initialize the object to be known as $wgArticle for special cases
  */
 function initializeSpecialCases(&$title, &$output, $request)
 {
     global $wgRequest, $wgUseGoogleMini, $IP;
     wfProfileIn('MediaWiki::initializeSpecialCases');
     $action = $this->getVal('Action');
     $search = $request->getVal('search');
     if ($this->getVal('Server') != "http://" . $_SERVER['HTTP_HOST'] && !preg_match("@[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+@", $_SERVER['HTTP_HOST']) && !IS_SPARE_HOST && !IS_CLOUD_SITE) {
         $output->redirect($this->getVal('Server') . $_SERVER['REQUEST_URI'], 301);
         return;
     }
     if (!$title or $title->getDBkey() == '') {
         $title = SpecialPage::getTitleFor('Badtitle');
         # Die now before we mess up $wgArticle and the skin stops working
         throw new ErrorPageError('badtitle', 'badtitletext');
     } else {
         if (!is_null($search) && $search !== '' && $wgUseGoogleMini) {
             //XXCHANGED
             if ($wgRequest->getVal('advanced', null) == null && $wgUseGoogleMini) {
                 $title = Title::makeTitle(NS_SPECIAL, 'LSearch');
                 require_once "{$IP}/extensions/wikihow/LSearch.body.php";
                 $s = new LSearch();
                 $s->execute('');
             } else {
                 require_once "{$IP}/includes/SpecialSearch.php";
                 $title = Title::makeTitle(NS_SPECIAL, 'Search');
                 #$s = new SpecialSearch();
                 #$s->execute('');
                 wfSpecialSearch();
             }
         } else {
             if ($title->getInterwiki() != '') {
                 if ($rdfrom = $request->getVal('rdfrom')) {
                     $url = $title->getFullURL('rdfrom=' . urlencode($rdfrom));
                 } else {
                     $url = $title->getFullURL();
                 }
                 /* Check for a redirect loop */
                 if (!preg_match('/^' . preg_quote($this->getVal('Server'), '/') . '/', $url) && $title->isLocal()) {
                     $output->redirect($url);
                 } else {
                     $title = SpecialPage::getTitleFor('Badtitle');
                     throw new ErrorPageError('badtitle', 'badtitletext');
                 }
             } else {
                 if ($action == 'view' && !$wgRequest->wasPosted() && (!isset($this->GET['title']) || $title->getPrefixedDBKey() != $this->GET['title']) && !count(array_diff(array_keys($this->GET), array('action', 'title')))) {
                     $targetUrl = $title->getFullURL();
                     // Redirect to canonical url, make it a 301 to allow caching
                     global $wgUsePathInfo;
                     if ($targetUrl == $wgRequest->getFullRequestURL()) {
                         $message = "Redirect loop detected!\n\n" . "This means the wiki got confused about what page was " . "requested; this sometimes happens when moving a wiki " . "to a new server or changing the server configuration.\n\n";
                         if ($wgUsePathInfo) {
                             $message .= "The wiki is trying to interpret the page " . "title from the URL path portion (PATH_INFO), which " . "sometimes fails depending on the web server. Try " . "setting \"\$wgUsePathInfo = false;\" in your " . "LocalSettings.php, or check that \$wgArticlePath " . "is correct.";
                         } else {
                             $message .= "Your web server was detected as possibly not " . "supporting URL path components (PATH_INFO) correctly; " . "check your LocalSettings.php for a customized " . "\$wgArticlePath setting and/or toggle \$wgUsePathInfo " . "to true.";
                         }
                         wfHttpError(500, "Internal error", $message);
                         return false;
                     } else {
                         $output->setSquidMaxage(1200);
                         $output->redirect($targetUrl, '301');
                     }
                 } else {
                     if (NS_SPECIAL == $title->getNamespace()) {
                         /* actions that need to be made when we have a special pages */
                         SpecialPage::executePath($title);
                     } else {
                         /* No match to special cases */
                         wfProfileOut('MediaWiki::initializeSpecialCases');
                         return false;
                     }
                 }
             }
         }
     }
     /* Did match a special case */
     wfProfileOut('MediaWiki::initializeSpecialCases');
     return true;
 }
Ejemplo n.º 8
0
 function getSuggestedTitles($tweet)
 {
     if (strlen($tweet) > 0) {
         // clean up tweet
         $tweet = str_replace("\n", "", $tweet);
         $tweet = trim($tweet);
         // remove search word
         //$tweet = preg_replace('/<b>(.*?)<\/b> /is', '', $tweet);
         // $tweet = $this->removeStopWords( $tweet );
         $emoticons = array(':)', '=O');
         foreach ($emoticons as $emoticon) {
             $tweet = str_replace($emoticon, "", $tweet);
         }
         // attmp to get search words + x number of words after
         //		el( $eTweet, '1st explode' );
         //		$eTweet = $this->removeStopWords( $eTweet );
         //		el( $eTweet, 'Removed stop words' );
         $data = array();
         $data['tweet'] = null;
         $data['results'] = array();
         // parse the sentences into questions/senteces
         /*
         			  $eTweet = array( );
         			  $eTweet = preg_split( "/(?<!\..)([\?\!\.]+)\s(?!.\.)/", $tweet, -1, PREG_SPLIT_DELIM_CAPTURE );
          if ( is_array( $eTweet ) && count( $eTweet ) > 0 ) {
         			  $questions = array( );
         			  $sentences = array( );
          for ( $i = 0; $i < count( $eTweet ); $i++ ) {
          $piece = trim( $eTweet[$i] );
          if ( strlen( $piece ) > 0 ) {
         			  // remove non alpha characters
         			  $piece = preg_replace( "/[^a-zA-Z0-9\s]/", "", $piece );
         			  $nextKey = $i + 1;
         			  el( $piece . " - " . substr_count( $piece, ' ' ), __LINE__ );
          if ( $eTweet[$nextKey] == '?' && substr_count( $piece, ' ' ) >= self::MIN_WORDS ) {
         			  $questions[] = $piece;
         			  }
         			  else if ( substr_count( $piece, ' ' ) >= self::MIN_WORDS ) {
         			  $sentences[] = $piece;
         			  }
         			  }
         			  // skip over sentence ender
         			  $i++;
         			  }
         			  }
          // search for questions first
         			  $eTweet = array_merge( $questions, $sentences );
          if ( is_array( $eTweet ) && count( $eTweet ) > 0 ) {
         			  foreach ( $eTweet as $tweet ) {
          $search = new LSearch();
         			  $results = $search->googleSearchResultTitles( $tweet, 0, self::NUM_WH_SEARCH_RESULTS );
          $data['tweet'] = !empty( $data['tweet'] ) ? $data['tweet'] . '; ' . $tweet : $tweet;
         			  $data['results'] = array_merge( $data['results'], $results );
         			  el( $results, $tweet );
         			  }
         			  }
         */
         // single search string, ie user types in search string
         $search = new LSearch();
         $results = $search->googleSearchResultTitles($tweet, 0, self::NUM_WH_SEARCH_RESULTS);
         $data['tweet'] = !empty($data['tweet']) ? $data['tweet'] . '; ' . $tweet : $tweet;
         $data['results'] = array_merge($data['results'], $results);
         return $data;
     } else {
         throw new InvalidArgumentException('tweet cannot be null');
     }
 }
Ejemplo n.º 9
0
    function execute($par)
    {
        global $wgRequest, $wgUser, $wgOut, $wgEmbedVideoServiceList;
        $fname = "AddRelatedLinks::execute";
        wfProfileIn($fname);
        if (!in_array('staff', $wgUser->getGroups())) {
            $wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext');
            return;
        }
        $wgOut->addHTML(<<<END
\t\t\t<form action='/Special:AddRelatedLinks' method='post' enctype="multipart/form-data" >
\t\t\tPages to add links to (Urls) : <textarea name='xml'></textarea>
\t\t\t<input type='submit'>
\t\t\t</form>
END
);
        if (!$wgRequest->wasPosted()) {
            wfProfileOut($fname);
            return;
        }
        set_time_limit(3000);
        require_once 'Newarticleboost.body.php';
        $dbr = wfGetDB(DB_SLAVE);
        $urls = array_unique(split("\n", $wgRequest->getVal('xml')));
        $olduser = $wgUser;
        $wgUser = User::newFromName("Wendy Weaver");
        $wgOut->addHTML("Started at " . date("r") . "<ul>");
        foreach ($urls as $url) {
            $url = trim($url);
            if ($url == "") {
                continue;
            }
            $url = preg_replace("@http://www.wikihow.com/@im", "", $url);
            $t = Title::newFromURL($url);
            if (!$t) {
                $wgOut->addHTML("<li>Can't make title out of {$url}</li>\n");
                continue;
            }
            $r = Revision::newFromTitle($t);
            if (!$r) {
                $wgOut->addHTML("<li>Can't make revision out of {$url}</li>\n");
                continue;
            }
            $text = $r->getText();
            $search = new LSearch();
            $results = $search->googleSearchResultTitles($t->getText(), 0, 30, 7);
            $good = array();
            foreach ($results as $r) {
                if ($r->getText() == $t->getText()) {
                    continue;
                }
                if ($r->getNamespace() != NS_MAIN) {
                    continue;
                }
                if (preg_match("@\\[\\[{$t->getText()}@", $text)) {
                    continue;
                }
                $good[] = $r;
                if (sizeof($good) >= 4) {
                    break;
                }
            }
            if (sizeof($good) == 0) {
                $src = self::addLinkToRandomArticleInSameCategory($t);
                if ($src) {
                    $wgOut->addHTML("<li>Linked from <b><a href='{$src->getFullURL()}?action=history' target='new'>{$src->getText()}</a></b> to <b><a href='{$t->getFullURL()}' target='new'>{$t->getText()}</a></b> (random)</li>\n");
                } else {
                    $wgOut->addHTML("<li>Could not find appropriate links for <b><a href='{$t->getFullURL()}' target='new'>{$t->getText()}</a></b></li>\n");
                }
            } else {
                $x = rand(0, min(4, sizeof($good) - 1));
                $src = $good[$x];
                $wgOut->addHTML("<li>Linked from <b><a href='{$src->getFullURL()}?action=history' target='new'>{$src->getText()}</a></b> to <b><a href='{$t->getFullURL()}' target='new'>{$t->getText()}</a></b> (search)</li>\n");
                MarkRelated::addRelated($src, $t, "Weaving the web of links", true);
            }
        }
        $wgOut->addHTML("</ul>Finished at " . date("r"));
        wfProfileOut($fname);
        return;
    }
Ejemplo n.º 10
0
    if (!$dest) {
        echo "cant get it from {$line}\n";
        exit;
    }
    $words = split(",", $tokens[1]);
    foreach ($words as $w) {
        $w = trim(str_replace('"', '', $w));
        $kw[$w] = $dest->getFullText();
        $count[$w] = 0;
        $linked[$dest->getFullText()] = 0;
    }
}
$titles = array();
$used = array();
foreach ($kw as $k => $text) {
    $l = new LSearch();
    $hits = $l->googleSearchResultTitles('"' . $k . '"', 0, 30);
    foreach ($hits as $h) {
        if ($h->getNamespace() == NS_MAIN && !isset($used[$h->getText()])) {
            $used[$h->getText()] = 1;
            $titles[] = $h;
        }
    }
}
/*
$res = $dbr->select('page', array("page_namespace", "page_title"), 
	array("page_namespace"=>NS_MAIN, "page_is_redirect=0", "page_id not in (5)" ), "sprinkle_links", 
	array("ORDER BY"=>"page_counter desc", "LIMIT"=>20000));

$titles = array();
while ($row = $dbr->fetchObject($res)) {
Ejemplo n.º 11
0
<?php

require_once 'commandLine.inc';
$dbw = wfGetDB(DB_MASTER);
$sql = "SELECT page_title, page_namespace FROM templatelinks left join page on tl_from=page_id WHERE page_namespace=0 and tl_title in ('Copyedit', 'Stub', 'Cleanup') ";
//$sql .= " ORDER BY rand() LIMIT 100";
$res = $dbw->query($sql);
while ($row = $dbw->fetchObject($res)) {
    $t = Title::makeTitle($row->page_namespace, $row->page_title);
    $l = new LSearch();
    $results = $l->googleSearchResultTitles($t->getFullText(), 0, 30, 5);
    //echo "{$t->getFullText()} size of results ". sizeof($results) . "\n";
    $x = strtolower(str_replace(" ", "", $t->getText()));
    foreach ($results as $r) {
        $y = strtolower(str_replace(" ", "", $r->getText()));
        if ($x == $y) {
            continue;
        }
        $dbw->insert('improve_links', array('il_from' => $r->getArticleID(), 'il_namespace' => $t->getNamespace(), 'il_title' => $t->getDBKey()));
        echo "{$t->getFullText()}\t{$r->getFullText()}\n";
    }
}
     continue;
 }
 $titleObj = Title::newFromText($title);
 if (!$titleObj) {
     $errs .= "<li>Could not generate at title for '{$title}'</li>";
     continue;
 }
 if ($titleObj->getArticleID() == 0) {
     $titleObj = Title::newFromURL($title);
 }
 if (!$titleObj || $titleObj->getArticleID() == 0) {
     $errs .= "<li>The article for '{$title}' does not exist</li>";
     continue;
 }
 # get results from the Google Mini
 $l = new LSearch();
 $results = $l->googleSearchResultTitles('"' . $phrase . '"');
 $newresults = array();
 # filter out some of the results (links to their own pages, videos, etc)
 foreach ($results as $r) {
     if (strtolower($r->getText()) == strtolower($title)) {
         continue;
     }
     if ($r->getNamespace() != NS_MAIN || strpos($r->getText(), "Video/") !== false) {
         continue;
     }
     $a = new Article($r);
     if ($a->isRedirect()) {
         continue;
     }
     if (in_array(strtolower($r->getText()), $ignore_pages)) {