function convert($newFormat, $pageName, $calName, $redirect, $go)
 {
     $search = "{$pageName}/{$calName}";
     $pages = PrefixSearch::titleSearch($search, 1000000);
     //search upto 1,000,000 events (no performace issue)
     $count = $erroredCount = 0;
     foreach ($pages as $page) {
         $retval = false;
         $newPage = $this->convertToNewPage($page, $newFormat);
         $article = new Article(Title::newFromText($page));
         if ($newPage != '') {
             $fromTitle = Title::newFromText($page);
             $toTitle = Title::newFromText($newPage);
             $articleNew = new Article(Title::newFromText($newPage));
             if (!$article->isRedirect() && !$articleNew->exists()) {
                 if ($go) {
                     $retval = $fromTitle->moveTo($toTitle, true, 'CalendarConversion', $redirect);
                 } else {
                     if ($count < 10) {
                         $testRun .= '&nbsp;&nbsp;' . $page . '  &rarr;&rarr;  ' . $newPage . '<br>';
                     }
                 }
             }
         }
     }
     unset($pages);
     if ($go) {
         $ret = "Conversion completed.";
     } else {
         $ret = "<b>Test Results, add '<i>go</i>' to the <i>dateConverter</i> tag to convert:</b><br>{$testRun}";
     }
     return $ret;
 }
 public function execute()
 {
     $params = $this->extractRequestParams();
     $search = $params['search'];
     $limit = $params['limit'];
     // Open search results may be stored for a very long time
     $this->getMain()->setCacheMaxAge(1200);
     $srchres = PrefixSearch::titleSearch($search, $limit);
     // Set top level elements
     $result = $this->getResult();
     $result->addValue(null, 0, $search);
     $result->addValue(null, 1, $srchres);
 }
 /**
  * Backend of categories autosuggest
  */
 public static function suggest()
 {
     global $wgContLang, $wgRequest;
     wfProfileIn(__METHOD__);
     $limit = 10;
     $query = $wgRequest->getVal('query');
     $ret = array('query' => $query, 'suggestions' => array());
     $results = PrefixSearch::titleSearch($query, $limit, array(NS_CATEGORY));
     $prefixLength = strlen($wgContLang->getNsText(NS_CATEGORY)) + 1;
     foreach ($results as $result) {
         $ret['suggestions'][] = substr($result, $prefixLength);
     }
     wfProfileOut(__METHOD__);
     return $ret;
 }
 public function execute()
 {
     global $wgEnableMWSuggest;
     $params = $this->extractRequestParams();
     $search = $params['search'];
     $limit = $params['limit'];
     $namespaces = $params['namespace'];
     $suggest = $params['suggest'];
     # $wgEnableMWSuggest hit incoming when $wgEnableMWSuggest is disabled
     if ($suggest && !$wgEnableMWSuggest) {
         return;
     }
     // Open search results may be stored for a very long time
     $this->getMain()->setCacheMaxAge(1200);
     $srchres = PrefixSearch::titleSearch($search, $limit, $namespaces);
     // Set top level elements
     $result = $this->getResult();
     $result->addValue(null, 0, $search);
     $result->addValue(null, 1, $srchres);
 }
 function convert($source, $target, $startdate)
 {
     $date = getdate(strtotime($startdate));
     $month = $date['mon'];
     $day = $date['mday'];
     $year = $date['year'];
     //$date = "$month-$day-$year";
     $search = $source;
     $pages = PrefixSearch::titleSearch($search, '10000');
     $count = 0;
     foreach ($pages as $page) {
         $article = new Article(Title::newFromText($page));
         $title = $article->getTitle()->getText();
         $body = $article->fetchContent(0, false, false);
         $titles .= $this->create_event($title, $body, $target);
         $count++;
     }
     return $titles;
     //return "$count records converted!";
 }
Exemple #6
0
 public function execute()
 {
     global $wgEnableOpenSearchSuggest, $wgSearchSuggestCacheExpiry;
     $params = $this->extractRequestParams();
     $search = $params['search'];
     $limit = $params['limit'];
     $namespaces = $params['namespace'];
     $suggest = $params['suggest'];
     // MWSuggest or similar hit
     if ($suggest && !$wgEnableOpenSearchSuggest) {
         $searches = array();
     } else {
         // Open search results may be stored for a very long time
         $this->getMain()->setCacheMaxAge($wgSearchSuggestCacheExpiry);
         $this->getMain()->setCacheMode('public');
         $searches = PrefixSearch::titleSearch($search, $limit, $namespaces);
         // if the content language has variants, try to retrieve fallback results
         $fallbackLimit = $limit - count($searches);
         if ($fallbackLimit > 0) {
             global $wgContLang;
             $fallbackSearches = $wgContLang->autoConvertToAllVariants($search);
             $fallbackSearches = array_diff(array_unique($fallbackSearches), array($search));
             foreach ($fallbackSearches as $fbs) {
                 $fallbackSearchResult = PrefixSearch::titleSearch($fbs, $fallbackLimit, $namespaces);
                 $searches = array_merge($searches, $fallbackSearchResult);
                 $fallbackLimit -= count($fallbackSearchResult);
                 if ($fallbackLimit == 0) {
                     break;
                 }
             }
         }
     }
     // Wikia change - begin
     wfRunHooks('ApiOpenSearchExecute', array($this, $params, &$srchres));
     // Wikia change - end
     // Set top level elements
     $result = $this->getResult();
     $result->addValue(null, 0, $search);
     $result->addValue(null, 1, $searches);
 }
 public function execute()
 {
     if (!$this->inXmlMode()) {
         // Pass back to the JSON defaults
         parent::execute();
         return;
     }
     $params = $this->extractRequestParams();
     $search = $params['search'];
     $limit = $params['limit'];
     $namespaces = $params['namespace'];
     // Open search results may be stored for a very long time
     $this->getMain()->setCacheMaxAge(1200);
     $srchres = PrefixSearch::titleSearch($search, $limit, $namespaces);
     $items = array_filter(array_map(array($this, 'formatItem'), $srchres));
     $result = $this->getResult();
     $result->addValue(null, 'version', '2.0');
     $result->addValue(null, 'xmlns', 'http://opensearch.org/searchsuggest2');
     $result->addValue(null, 'Query', array('*' => strval($search)));
     $result->setIndexedTagName($items, 'Item');
     $result->addValue(null, 'Section', $items);
 }
Exemple #8
0
 public function execute()
 {
     global $wgEnableOpenSearchSuggest, $wgSearchSuggestCacheExpiry;
     $params = $this->extractRequestParams();
     $search = $params['search'];
     $limit = $params['limit'];
     $namespaces = $params['namespace'];
     $suggest = $params['suggest'];
     // MWSuggest or similar hit
     if ($suggest && !$wgEnableOpenSearchSuggest) {
         $srchres = array();
     } else {
         // Open search results may be stored for a very long
         // time
         $this->getMain()->setCacheMaxAge($wgSearchSuggestCacheExpiry);
         $this->getMain()->setCacheMode('public');
         $srchres = PrefixSearch::titleSearch($search, $limit, $namespaces);
     }
     // Set top level elements
     $result = $this->getResult();
     $result->addValue(null, 0, $search);
     $result->addValue(null, 1, $srchres);
 }
 function buildArticlesForDay($month, $day, $year)
 {
     //$date = "$month-$day-$year";
     $date = $this->userDateFormat($month, $day, $year);
     $search = "{$this->calendarPageName}/{$date}";
     $pages = PrefixSearch::titleSearch($search, '100');
     foreach ($pages as $page) {
         $this->addArticle($month, $day, $year, $page);
     }
     unset($pages);
     // subscribed events
     foreach ($this->subscribedPages as $subscribedPage) {
         $search = "{$subscribedPage}/{$date}";
         $pages = PrefixSearch::titleSearch($search, '100');
         foreach ($pages as $page) {
             $this->addArticle($month, $day, $year, $page);
         }
     }
     // depreciated (around 1/1/2009)
     // old format: ** name (12-15-2008) - Event 1 **
     if ($this->setting('enablelegacy')) {
         $date = "{$month}-{$day}-{$year}";
         $name = $this->setting('name');
         $search = "{$this->namespace}:{$name} ({$date})";
         $pages = PrefixSearch::titleSearch($search, '100');
         foreach ($pages as $page) {
             $this->addArticle($month, $day, $year, $page);
         }
         unset($pages);
     }
 }
function wfSajaxSearch($term)
{
    global $wgContLang, $wgOut, $wgUser, $wgCapitalLinks, $wgMemc;
    $limit = 16;
    $sk = $wgUser->getSkin();
    $output = '';
    $term = trim($term);
    $term = $wgContLang->checkTitleEncoding($wgContLang->recodeInput(js_unescape($term)));
    if ($wgCapitalLinks) {
        $term = $wgContLang->ucfirst($term);
    }
    $term_title = Title::newFromText($term);
    $memckey = $term_title ? wfMemcKey('ajaxsearch', md5($term_title->getFullText())) : wfMemcKey('ajaxsearch', md5($term));
    $cached = $wgMemc->get($memckey);
    if (is_array($cached) && $cached['version'] == AJAX_SEARCH_VERSION) {
        $response = new AjaxResponse($cached['html']);
        $response->setCacheDuration(30 * 60);
        return $response;
    }
    $r = $more = '';
    $canSearch = true;
    $results = PrefixSearch::titleSearch($term, $limit + 1);
    foreach (array_slice($results, 0, $limit) as $titleText) {
        $r .= '<li>' . $sk->makeKnownLink($titleText) . "</li>\n";
    }
    // Hack to check for specials
    if ($results) {
        $t = Title::newFromText($results[0]);
        if ($t && $t->getNamespace() == NS_SPECIAL) {
            $canSearch = false;
            if (count($results) > $limit) {
                $more = '<i>' . $sk->makeKnownLinkObj(SpecialPage::getTitleFor('Specialpages'), wfMsgHtml('moredotdotdot')) . '</i>';
            }
        } else {
            if (count($results) > $limit) {
                $more = '<i>' . $sk->makeKnownLinkObj(SpecialPage::getTitleFor("Allpages", $term), wfMsgHtml('moredotdotdot')) . '</i>';
            }
        }
    }
    $valid = (bool) $term_title;
    $term_url = urlencode($term);
    $term_diplay = htmlspecialchars($valid ? $term_title->getFullText() : $term);
    $subtitlemsg = $valid ? 'searchsubtitle' : 'searchsubtitleinvalid';
    $subtitle = wfMsgWikiHtml($subtitlemsg, $term_diplay);
    $html = '<div id="searchTargetHide"><a onclick="Searching_Hide_Results();">' . wfMsgHtml('hideresults') . '</a></div>' . '<h1 class="firstHeading">' . wfMsgHtml('search') . '</h1><div id="contentSub">' . $subtitle . '</div>';
    if ($canSearch) {
        $html .= '<ul><li>' . $sk->makeKnownLink($wgContLang->specialPage('Search'), wfMsgHtml('searchcontaining', $term_diplay), "search={$term_url}&fulltext=Search") . '</li><li>' . $sk->makeKnownLink($wgContLang->specialPage('Search'), wfMsgHtml('searchnamed', $term_diplay), "search={$term_url}&go=Go") . "</li></ul>";
    }
    if ($r) {
        $html .= "<h2>" . wfMsgHtml('articletitles', $term_diplay) . "</h2>" . '<ul>' . $r . '</ul>' . $more;
    }
    $wgMemc->set($memckey, array('version' => AJAX_SEARCH_VERSION, 'html' => $html), 30 * 60);
    $response = new AjaxResponse($html);
    $response->setCacheDuration(30 * 60);
    return $response;
}
Exemple #11
0
 function buildArticlesForDay($month, $day, $year)
 {
     //$date = "$month-$day-$year";
     $date = $this->userDateFormat($month, $day, $year);
     $search = "{$this->calendarPageName}/{$date}";
     $pages = PrefixSearch::titleSearch($search, '100');
     $category = Category::newFromName("Event");
     foreach ($category->getMembers() as $eventTitle) {
         if ($eventTitle->getNamespace() == NS_CATEGORY) {
             // TODO
             // This is a sub-category. We should recusre into it.
         } else {
             if ($eventTitle->isContentPage()) {
                 $event = Event::newFromTitle($eventTitle);
             }
         }
     }
     foreach ($pages as $page) {
         $this->addArticle($month, $day, $year, $page);
     }
     unset($pages);
     // subscribed events
     foreach ($this->subscribedPages as $subscribedPage) {
         $search = "{$subscribedPage}/{$date}";
         $pages = PrefixSearch::titleSearch($search, '100');
         foreach ($pages as $page) {
             $this->addArticle($month, $day, $year, $page);
         }
     }
 }
Exemple #12
0
 function buildArticlesForDay($month, $day, $year)
 {
     //$date = "$month-$day-$year";
     $date = $this->userDateFormat($month, $day, $year);
     $search = "{$this->calendarPageName}/{$date}";
     $pages = PrefixSearch::titleSearch($search, '100');
     foreach ($pages as $page) {
         $this->addArticle($month, $day, $year, $page);
     }
     unset($pages);
 }