/**
 * @param int   $level
 * @param Title $target
 * @param int   $limit
 * @param int   $offset
 * @access private
 */
function wfShowIndirectLinks($level, $target, $limit, $offset = 0)
{
    global $wgOut, $wgUser;
    $fname = 'wfShowIndirectLinks';
    $dbr =& wfGetDB(DB_READ);
    // Read one extra row as an at-end check
    $queryLimit = $limit + 1;
    $limitSql = $level == 0 ? "{$offset},{$queryLimit}" : $queryLimit;
    $res = $dbr->select(array('pagelinks', 'page'), array('page_id', 'page_namespace', 'page_title', 'page_is_redirect'), array('pl_from=page_id', 'pl_namespace' => $target->getNamespace(), 'pl_title' => $target->getDbKey()), $fname, array('LIMIT' => $limitSql));
    if (0 == $dbr->numRows($res)) {
        if (0 == $level) {
            $wgOut->addWikiText(wfMsg('nolinkshere'));
        }
        return;
    }
    if (0 == $level) {
        $wgOut->addWikiText(wfMsg('linkshere'));
    }
    $sk = $wgUser->getSkin();
    $isredir = ' (' . wfMsg('isredirect') . ")\n";
    if ($dbr->numRows($res) == 0) {
        return;
    }
    $atend = $dbr->numRows($res) <= $limit;
    if ($level == 0) {
        $specialTitle = Title::makeTitle(NS_SPECIAL, 'Whatlinkshere');
        $prevnext = wfViewPrevNext($offset, $limit, $specialTitle, 'target=' . urlencode($target->getPrefixedDbKey()), $atend);
        $wgOut->addHTML($prevnext);
    }
    $wgOut->addHTML('<ul>');
    $linksShown = 0;
    while ($row = $dbr->fetchObject($res)) {
        if (++$linksShown > $limit) {
            // Last row is for checks only; don't display it.
            break;
        }
        $nt = Title::makeTitle($row->page_namespace, $row->page_title);
        if ($row->page_is_redirect) {
            $extra = 'redirect=no';
        } else {
            $extra = '';
        }
        $link = $sk->makeKnownLinkObj($nt, '', $extra);
        $wgOut->addHTML('<li>' . $link);
        if ($row->page_is_redirect) {
            $wgOut->addHTML($isredir);
            if ($level < 2) {
                wfShowIndirectLinks($level + 1, $nt, 500);
            }
        }
        $wgOut->addHTML("</li>\n");
    }
    $wgOut->addHTML("</ul>\n");
    if ($level == 0) {
        $wgOut->addHTML($prevnext);
    }
}
	function getNavigationBar() {
		global $wgContLang;

		return wfViewPrevNext(
			$this->mOffset,
			$this->mLimit,
			$wgContLang->specialpage( 'WhosOnline' ),
			'',
			$this->countUsersOnline() < ( $this->mLimit + $this->mOffset ) // show next link
		);
	}
Exemple #3
0
 /**
  * As with QueryPage, this is the actual workhorse. It does everything
  * needed to make a real, honest-to-gosh query page.
  *
  * @param $offset database query offset
  * @param $limit database query limit
  * @param $shownavigation show navigation like "next 200"?
  */
 function doQuery($offset, $limit, $shownavigation = true)
 {
     global $wgUser, $wgOut, $wgContLang;
     $this->offset = $offset;
     $this->limit = $limit;
     $sname = $this->getName();
     $fname = get_class($this) . '::doQuery';
     $sk = $wgUser->getSkin();
     $wgOut->setSyndicated($this->isSyndicated());
     $query = MwRdf::Query($this->getQuery(), $this->getBaseUrl(), $this->getQueryLanguage());
     $librdf_res = $query->execute(MwRdf::StoredModel());
     # let's just dump the tuples into a normal php array shall
     # we?  This will avoid memory management hassels.
     $res = array();
     foreach ($librdf_res as $tuple) {
         $res[] = $tuple;
     }
     $num = count($res);
     $res = $this->preprocessResults($res);
     if ($shownavigation) {
         $wgOut->addHTML($this->getPageHeader());
         $top = wfShowingResults($offset, $num);
         $wgOut->addHTML("<p>{$top}\n");
         # often disable 'next' link when we reach the end
         $atend = $num < $limit;
         $sl = wfViewPrevNext($offset, $limit, $wgContLang->specialPage($sname), wfArrayToCGI($this->linkParameters()), $atend);
         $wgOut->addHTML("<br />{$sl}</p>\n");
     }
     if ($num > 0) {
         $s = array();
         if (!$this->listoutput) {
             $s[] = "<ol start='" . ($offset + 1) . "' class='special'>";
         }
         # here's where we do the offset and limit
         for ($i = $offset; $i < $num && $i < $offset + $limit; $i++) {
             $format = $this->formatResult($sk, $res[$i]);
             if ($format) {
                 $s[] = $this->listoutput ? $format : "<li>{$format}</li>\n";
             }
         }
         if (!$this->listoutput) {
             $s[] = '</ol>';
         }
         $str = $this->listoutput ? $wgContLang->listToText($s) : implode('', $s);
         $wgOut->addHTML($str);
     }
     if ($shownavigation) {
         $wgOut->addHTML("<p>{$sl}</p>\n");
     }
     return $num;
 }
Exemple #4
0
 /**
  * This is the actual workhorse. It does everything needed to make a
  * real, honest-to-gosh query page.
  * Alas, we need to overwrite the whole beast since we do not assume
  * an SQL-based storage backend.
  *
  * @param $offset database query offset
  * @param $limit database query limit
  */
 function doQuery($offset = false, $limit = false)
 {
     global $wgOut, $wgContLang;
     $options = new SMWRequestOptions();
     $options->limit = $limit;
     $options->offset = $offset;
     $options->sort = true;
     $res = $this->getResults($options);
     $num = count($res);
     $sk = $this->getSkin();
     $sname = $this->getName();
     $wgOut->addHTML($this->getPageHeader());
     // if list is empty, show it
     if ($num == 0) {
         $wgOut->addHTML('<p>' . wfMsgHTML('specialpage-empty') . '</p>');
         return;
     }
     $top = wfShowingResults($offset, $num);
     $wgOut->addHTML("<p>{$top}\n");
     // often disable 'next' link when we reach the end
     $atend = $num < $limit;
     $sl = wfViewPrevNext($offset, $limit, $wgContLang->specialPage($sname), wfArrayToCGI($this->linkParameters()), $atend);
     $wgOut->addHTML("<br />{$sl}</p>\n");
     if ($num > 0) {
         $s = array();
         if (!$this->listoutput) {
             $s[] = $this->openList($offset);
         }
         foreach ($res as $r) {
             $format = $this->formatResult($sk, $r);
             if ($format) {
                 $s[] = $this->listoutput ? $format : "<li>{$format}</li>\n";
             }
         }
         if (!$this->listoutput) {
             $s[] = $this->closeList();
         }
         $str = $this->listoutput ? $wgContLang->listToText($s) : implode('', $s);
         $wgOut->addHTML($str);
     }
     $wgOut->addHTML("<p>{$sl}</p>\n");
     return $num;
 }
 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>");
 }
 public function getBody()
 {
     $res = $this->reallyDoQuery();
     $this->preprocessResults($res);
     $prevnext = wfViewPrevNext($this->mOffset, $this->mLimit, SpecialPage::getTitleFor('AdvancedSearch'), wfArrayToCGI($this->getDefaultQuery()), $this->getNumRows() < $this->mLimit);
     $retval = $this->getStartBody();
     $row = $res->fetchObject();
     while ($row) {
         $retval .= $this->formatRow($row);
     }
     $retval .= $this->getEndBody();
     return $prevnext . $retval . $prevnext;
 }
 function showPrevNext(&$out)
 {
     global $wgContLang, $wgRequest;
     list($limit, $offset) = $wgRequest->getLimitOffset();
     $target = 'target=' . urlencode($wgRequest->getVal('target'));
     $mode = '&mode=' . urlencode($wgRequest->getVal('mode'));
     $html = wfViewPrevNext($offset, $limit, $wgContLang->specialpage('Regexblockstats'), $target . $mode, $this->numResults - $offset <= $limit);
     $out->addHTML('<p>' . $html . '</p>');
 }
Exemple #8
0
 /**
  * This is the actual workhorse. It does everything needed to make a
  * real, honest-to-gosh query page.
  */
 function execute($par)
 {
     global $wgUser, $wgOut, $wgLang, $wgRequest;
     if (!$this->userCanExecute($wgUser)) {
         $this->displayRestrictionError();
         return;
     }
     if ($this->limit == 0 && $this->offset == 0) {
         list($this->limit, $this->offset) = $wgRequest->getLimitOffset();
     }
     $dbr = wfGetDB(DB_SLAVE);
     $this->setHeaders();
     $wgOut->setSyndicated($this->isSyndicated());
     if ($this->isCached() && !$this->isCacheable()) {
         $wgOut->setSyndicated(false);
         $wgOut->addWikiMsg('querypage-disabled');
         return 0;
     }
     // TODO: Use doQuery()
     // $res = null;
     if (!$this->isCached()) {
         $res = $this->reallyDoQuery($this->limit, $this->offset);
     } else {
         # Get the cached result
         $res = $this->fetchFromCache($this->limit, $this->offset);
         if (!$this->listoutput) {
             # Fetch the timestamp of this update
             $ts = $this->getCachedTimestamp();
             if ($ts) {
                 $updated = $wgLang->timeanddate($ts, true, true);
                 $updateddate = $wgLang->date($ts, true, true);
                 $updatedtime = $wgLang->time($ts, true, true);
                 $wgOut->addMeta('Data-Cache-Time', $ts);
                 $wgOut->addInlineScript("var dataCacheTime = '{$ts}';");
                 $wgOut->addWikiMsg('perfcachedts', $updated, $updateddate, $updatedtime);
             } else {
                 $wgOut->addWikiMsg('perfcached');
             }
             # If updates on this page have been disabled, let the user know
             # that the data set won't be refreshed for now
             global $wgDisableQueryPageUpdate;
             if (is_array($wgDisableQueryPageUpdate) && in_array($this->getName(), $wgDisableQueryPageUpdate)) {
                 $wgOut->addWikiMsg('querypage-no-updates');
             }
         }
     }
     $this->numRows = $dbr->numRows($res);
     $this->preprocessResults($dbr, $res);
     $wgOut->addHTML(Xml::openElement('div', array('class' => 'mw-spcontent')));
     # Top header and navigation
     if ($this->shownavigation) {
         $wgOut->addHTML($this->getPageHeader());
         if ($this->numRows > 0) {
             $wgOut->addHTML('<p>' . wfShowingResults($this->offset, $this->numRows) . '</p>');
             # Disable the "next" link when we reach the end
             $paging = wfViewPrevNext($this->offset, $this->limit, $this->getTitle($par), wfArrayToCGI($this->linkParameters()), $this->numRows < $this->limit);
             $wgOut->addHTML('<p>' . $paging . '</p>');
         } else {
             # No results to show, so don't bother with "showing X of Y" etc.
             # -- just let the user know and give up now
             $wgOut->addHTML('<p>' . wfMsgHtml('specialpage-empty') . '</p>');
             $wgOut->addHTML(Xml::closeElement('div'));
             return;
         }
     }
     # The actual results; specialist subclasses will want to handle this
     # with more than a straight list, so we hand them the info, plus
     # an OutputPage, and let them get on with it
     $this->outputResults($wgOut, $this->getSkin(), $dbr, $res, $this->numRows, $this->offset);
     # Repeat the paging links at the bottom
     if ($this->shownavigation) {
         $wgOut->addHTML('<p>' . $paging . '</p>');
     }
     $wgOut->addHTML(Xml::closeElement('div'));
     return $this->numRows;
 }
 /**
  * @param $fieldSet String
  */
 public function showResults($fieldSet)
 {
     global $wgOut, $wgUser, $wgContLang, $wgScript, $wgSolrShowRelated, $wgSolrDebug;
     wfProfileIn(__METHOD__);
     $sk = $wgUser->getSkin();
     $this->searchEngine = SearchEngine::create();
     $search =& $this->searchEngine;
     $search->setLimitOffset($this->limit, $this->offset);
     $this->setupPage($fieldSet);
     $t = Title::newFromText($fieldSet->getName());
     //Do we have Title matches
     $fields = $fieldSet->getFields();
     //Build Solr query string form the fields
     if (isset($fields['solrsearch'])) {
         $query = $fields['solrsearch'];
     } else {
         $query = '';
     }
     $firsttime = true;
     $fieldSeperator = $fieldSet->getFieldSeperator();
     foreach ($fields as $key => $value) {
         if ($key != 'solrsearch' && !empty($value)) {
             if ($firsttime) {
                 $query = trim($query) . ' ' . trim(substr($key, 4)) . ':' . '(' . $value . ')';
                 $firsttime = false;
             } else {
                 $query = trim($query) . " {$fieldSeperator} " . trim(substr($key, 4)) . ':' . '(' . $value . ')';
             }
         }
     }
     if (!empty($query)) {
         $query .= $fieldSet->getQuery();
     }
     // TODO: More Exception Handling for Format Exceptions
     try {
         $titleMatches = $search->searchTitle($query);
         if (!$titleMatches instanceof SearchResultTooMany) {
             $textMatches = $search->searchText($query);
         }
         // did you mean... suggestions
         if ($textMatches && $textMatches->hasSuggestion()) {
             $st = SpecialPage::getTitleFor('SolrSearch');
             # mirror Go/Search behaviour of original request ..
             $didYouMeanParams = array('solrsearch' => $textMatches->getSuggestionQuery());
             $stParams = $didYouMeanParams;
             $suggestionSnippet = $textMatches->getSuggestionSnippet();
             if ($suggestionSnippet == '') {
                 $suggestionSnippet = null;
             }
             $suggestLink = $sk->linkKnown($st, $suggestionSnippet, array(), $stParams);
             $this->didYouMeanHtml = '<div class="searchdidyoumean">' . wfMsg('search-suggest', $suggestLink) . '</div>';
         }
     } catch (Exception $exc) {
         #Todo: Catch different Exceptions not just one for all
         $textMatches = false;
         $titleMatches = false;
         $wgOut->addHTML('<p class="solr-error">' . wfMsg('solrstore-error') . '<p\\>');
         if ($wgSolrDebug) {
             $wgOut->addHTML('<p class="solr-error">' . $exc . '<p\\>');
         }
     }
     // start rendering the page
     $wgOut->addHtml(Xml::openElement('form', array('id' => 'solrsearch', 'method' => 'get', 'action' => $wgScript)));
     $wgOut->addHtml(Xml::openElement('table', array('id' => 'mw-search-top-table', 'border' => 0, 'cellpadding' => 0, 'cellspacing' => 0)) . Xml::openElement('tr') . Xml::openElement('td') . "\n" . $this->shortDialog($fieldSet) . Xml::closeElement('td') . Xml::closeElement('tr') . Xml::closeElement('table'));
     // Sometimes the search engine knows there are too many hits
     if ($titleMatches instanceof SearchResultTooMany) {
         $wgOut->addWikiText('==' . wfMsg('toomanymatches') . "==\n");
         wfProfileOut(__METHOD__);
         return;
     }
     $filePrefix = $wgContLang->getFormattedNsText(NS_FILE) . ':';
     if (trim($query) === '' || $filePrefix === trim($query)) {
         $wgOut->addHTML($this->formHeader(0, 0));
         $wgOut->addHTML('</form>');
         // Empty query -- straight view of search form
         wfProfileOut(__METHOD__);
         return;
     }
     // Get number of results
     $titleMatchesNum = $titleMatches ? $titleMatches->numRows() : 0;
     $textMatchesNum = $textMatches ? $textMatches->numRows() : 0;
     // Total initial query matches (possible false positives)
     $num = $titleMatchesNum + $textMatchesNum;
     // Get total actual results (after second filtering, if any)
     $numTitleMatches = $titleMatches && !is_null($titleMatches->getTotalHits()) ? $titleMatches->getTotalHits() : $titleMatchesNum;
     $numTextMatches = $textMatches && !is_null($textMatches->getTotalHits()) ? $textMatches->getTotalHits() : $textMatchesNum;
     // get total number of results if backend can calculate it
     $totalRes = 0;
     if ($titleMatches && !is_null($titleMatches->getTotalHits())) {
         $totalRes += $titleMatches->getTotalHits();
     }
     if ($textMatches && !is_null($textMatches->getTotalHits())) {
         $totalRes += $textMatches->getTotalHits();
     }
     // show number of results and current offset
     $wgOut->addHTML($this->formHeader($num, $totalRes));
     $wgOut->addHtml(Xml::closeElement('form'));
     $wgOut->addHtml("<div class='searchresults'>");
     // prev/next links
     if ($num || $this->offset) {
         // Show the create link ahead
         if ($wgSolrShowRelated) {
             $this->showCreateLink($t);
         }
         $prevnext = wfViewPrevNext($this->offset, $this->limit, SpecialPage::getTitleFor('SolrSearch/' . $fieldSet->mName), wfArrayToCGI($fieldSet->mFields), max($titleMatchesNum, $textMatchesNum) < $this->limit);
         wfRunHooks('SpecialSolrSearchResults', array($fieldSet, &$titleMatches, &$textMatches));
     } else {
         wfRunHooks('SpecialSolrSearchNoResults', array($fieldSet));
     }
     if ($titleMatches) {
         if ($numTitleMatches > 0) {
             $wgOut->wrapWikiMsg("==\$1==\n", 'titlematches');
             $wgOut->addHTML($this->showMatches($titleMatches));
         }
         $titleMatches->free();
     }
     if ($textMatches) {
         // output appropriate heading
         if ($numTextMatches > 0 && $numTitleMatches > 0) {
             // if no title matches the heading is redundant
             $wgOut->wrapWikiMsg("==\$1==\n", 'textmatches');
         } elseif ($totalRes == 0) {
             # Don't show the 'no text matches' if we received title matches
             $wgOut->wrapWikiMsg("==\$1==\n", 'notextmatches');
         }
         // show results
         if ($numTextMatches > 0) {
             $wgOut->addHTML($this->showMatches($textMatches));
         }
         $textMatches->free();
     }
     $wgOut->addHtml("</div>");
     if ($num || $this->offset) {
         $wgOut->addHTML("<p class='mw-search-pager-bottom'>{$prevnext}</p>\n");
     }
     wfProfileOut(__METHOD__);
 }
 /**
  * @param OutputPage &$out where to send output
  * @private
  */
 function showPrevNext(&$out)
 {
     global $wgContLang, $wgRequest;
     $pieces = array();
     $pieces[] = 'type=' . urlencode($this->reader->queryType());
     $pieces[] = 'user='******'page=' . urlencode($this->reader->queryTitle());
     $pieces[] = 'pattern=' . urlencode($this->reader->queryPattern());
     $bits = implode('&', $pieces);
     list($limit, $offset) = $wgRequest->getLimitOffset();
     # TODO: use timestamps instead of offsets to make it more natural
     # to go huge distances in time
     $html = wfViewPrevNext($offset, $limit, $wgContLang->specialpage('Log'), $bits, $this->numResults < $limit);
     $out->addHTML('<p>' . $html . '</p>');
 }
 /**
  * This is the actual workhorse. It does everything needed to make a
  * real, honest-to-gosh query page.
  *
  * @param $offset database query offset
  * @param $limit database query limit
  * @param $shownavigation show navigation like "next 200"?
  */
 function doQuery($offset, $limit, $shownavigation = true)
 {
     global $wgUser, $wgOut, $wgLang, $wgRequest, $wgContLang;
     global $wgMiserMode;
     $sname = $this->getName();
     $fname = get_class($this) . '::doQuery';
     $sql = $this->getSQL();
     $dbr =& wfGetDB(DB_SLAVE);
     $dbw =& wfGetDB(DB_MASTER);
     $querycache = $dbr->tableName('querycache');
     $wgOut->setSyndicated($this->isSyndicated());
     if ($this->isExpensive()) {
         // Disabled recache parameter due to retry problems -- TS
         if ($wgMiserMode) {
             $type = $dbr->strencode($sname);
             $sql = "SELECT qc_type as type, qc_namespace as namespace,qc_title as title, qc_value as value\n\t\t\t\t\t FROM {$querycache} WHERE qc_type='{$type}'";
             $wgOut->addWikiText(wfMsg('perfcached'));
         }
     }
     $res = $dbr->query($sql . $this->getOrder() . $dbr->limitResult($limit, $offset), $fname);
     $num = $dbr->numRows($res);
     $sk = $wgUser->getSkin();
     if ($shownavigation) {
         $wgOut->addHTML($this->getPageHeader());
         $top = wfShowingResults($offset, $num);
         $wgOut->addHTML("<p>{$top}\n");
         # often disable 'next' link when we reach the end
         if ($num < $limit) {
             $atend = true;
         } else {
             $atend = false;
         }
         $sl = wfViewPrevNext($offset, $limit, $wgContLang->specialPage($sname), wfArrayToCGI($this->linkParameters()), $atend);
         $wgOut->addHTML("<br />{$sl}</p>\n");
     }
     if ($num > 0) {
         $s = "<ol start='" . ($offset + 1) . "' class='special'>";
         # Only read at most $num rows, because $res may contain the whole 1000
         for ($i = 0; $i < $num && ($obj = $dbr->fetchObject($res)); $i++) {
             $format = $this->formatResult($sk, $obj);
             if ($format) {
                 $attr = isset($obj->usepatrol) && $obj->usepatrol && $obj->patrolled == 0 ? ' class="not-patrolled"' : '';
                 $s .= "<li{$attr}>{$format}</li>\n";
             }
         }
         if ($this->tryLastResult()) {
             // flush the very last result
             $obj = null;
             $format = $this->formatResult($sk, $obj);
             if ($format) {
                 $attr = isset($obj->usepatrol) && $obj->usepatrol && $obj->patrolled == 0 ? ' class="not-patrolled"' : '';
                 $s .= "<li{$attr}>{$format}</li>\n";
             }
         }
         $dbr->freeResult($res);
         $s .= '</ol>';
         $wgOut->addHTML($s);
     }
     if ($shownavigation) {
         $wgOut->addHTML("<p>{$sl}</p>\n");
     }
     return $num;
 }
 /**
  * @param string $term
  * @public
  */
 function showResults($term)
 {
     $fname = 'SpecialSearch::showResults';
     wfProfileIn($fname);
     $this->setupPage($term);
     global $wgOut;
     $wgOut->addWikiMsg('searchresulttext');
     if ('' === trim($term)) {
         // Empty query -- straight view of search form
         $wgOut->setSubtitle('');
         $wgOut->addHTML($this->powerSearchBox($term));
         $wgOut->addHTML($this->powerSearchFocus());
         wfProfileOut($fname);
         return;
     }
     global $wgDisableTextSearch;
     if ($wgDisableTextSearch) {
         global $wgForwardSearchUrl;
         if ($wgForwardSearchUrl) {
             $url = str_replace('$1', urlencode($term), $wgForwardSearchUrl);
             $wgOut->redirect($url);
             return;
         }
         global $wgInputEncoding;
         $wgOut->addHTML(wfMsg('searchdisabled'));
         $wgOut->addHTML(wfMsg('googlesearch', htmlspecialchars($term), htmlspecialchars($wgInputEncoding), htmlspecialchars(wfMsg('searchbutton'))));
         wfProfileOut($fname);
         return;
     }
     $search = SearchEngine::create();
     $search->setLimitOffset($this->limit, $this->offset);
     $search->setNamespaces($this->namespaces);
     $search->showRedirects = $this->searchRedirects;
     $titleMatches = $search->searchTitle($term);
     // Sometimes the search engine knows there are too many hits
     if ($titleMatches instanceof SearchResultTooMany) {
         $wgOut->addWikiText('==' . wfMsg('toomanymatches') . "==\n");
         $wgOut->addHTML($this->powerSearchBox($term));
         $wgOut->addHTML($this->powerSearchFocus());
         wfProfileOut($fname);
         return;
     }
     $textMatches = $search->searchText($term);
     $num = ($titleMatches ? $titleMatches->numRows() : 0) + ($textMatches ? $textMatches->numRows() : 0);
     if ($num > 0) {
         if ($num >= $this->limit) {
             $top = wfShowingResults($this->offset, $this->limit);
         } else {
             $top = wfShowingResultsNum($this->offset, $this->limit, $num);
         }
         $wgOut->addHTML("<p>{$top}</p>\n");
     }
     if ($num || $this->offset) {
         $prevnext = wfViewPrevNext($this->offset, $this->limit, SpecialPage::getTitleFor('Search'), wfArrayToCGI($this->powerSearchOptions(), array('search' => $term)), $num < $this->limit);
         $wgOut->addHTML("<br />{$prevnext}\n");
     }
     if ($titleMatches) {
         if ($titleMatches->numRows()) {
             $wgOut->wrapWikiMsg("==\$1==\n", 'titlematches');
             $wgOut->addHTML($this->showMatches($titleMatches));
         } else {
             $wgOut->wrapWikiMsg("==\$1==\n", 'notitlematches');
         }
         $titleMatches->free();
     }
     if ($textMatches) {
         if ($textMatches->numRows()) {
             $wgOut->wrapWikiMsg("==\$1==\n", 'textmatches');
             $wgOut->addHTML($this->showMatches($textMatches));
         } elseif ($num == 0) {
             # Don't show the 'no text matches' if we received title matches
             $wgOut->wrapWikiMsg("==\$1==\n", 'notextmatches');
         }
         $textMatches->free();
     }
     if ($num == 0) {
         $wgOut->addWikiMsg('nonefound');
     }
     if ($num || $this->offset) {
         $wgOut->addHTML("<p>{$prevnext}</p>\n");
     }
     $wgOut->addHTML($this->powerSearchBox($term));
     wfProfileOut($fname);
 }
Exemple #13
0
 /**
  * @param string $term
  * @public
  */
 function showResults($term)
 {
     wfProfileIn(__METHOD__);
     global $wgOut, $wgUser;
     $sk = $wgUser->getSkin();
     $search = SearchEngine::create();
     $search->setLimitOffset($this->limit, $this->offset);
     $search->setNamespaces($this->namespaces);
     $search->showRedirects = $this->searchRedirects;
     $search->prefix = $this->mPrefix;
     $term = $search->transformSearchTerm($term);
     $this->setupPage($term);
     $rewritten = $search->replacePrefixes($term);
     $titleMatches = $search->searchTitle($rewritten);
     $textMatches = $search->searchText($rewritten);
     // did you mean... suggestions
     if ($textMatches && $textMatches->hasSuggestion()) {
         $st = SpecialPage::getTitleFor('Search');
         $stParams = wfArrayToCGI(array('search' => $textMatches->getSuggestionQuery(), 'fulltext' => wfMsg('search')), $this->powerSearchOptions());
         $suggestLink = $sk->makeKnownLinkObj($st, $textMatches->getSuggestionSnippet(), $stParams);
         $wgOut->addHTML('<div class="searchdidyoumean">' . wfMsg('search-suggest', $suggestLink) . '</div>');
     }
     $wgOut->addWikiMsg('searchresulttext');
     if ('' === trim($term)) {
         // Empty query -- straight view of search form
         $wgOut->setSubtitle('');
         $wgOut->addHTML($this->powerSearchBox($term));
         $wgOut->addHTML($this->powerSearchFocus());
         wfProfileOut(__METHOD__);
         return;
     }
     global $wgDisableTextSearch;
     if ($wgDisableTextSearch) {
         global $wgSearchForwardUrl;
         if ($wgSearchForwardUrl) {
             $url = str_replace('$1', urlencode($term), $wgSearchForwardUrl);
             $wgOut->redirect($url);
             wfProfileOut(__METHOD__);
             return;
         }
         global $wgInputEncoding;
         $wgOut->addHTML(Xml::openElement('fieldset') . Xml::element('legend', null, wfMsg('search-external')) . Xml::element('p', array('class' => 'mw-searchdisabled'), wfMsg('searchdisabled')) . wfMsg('googlesearch', htmlspecialchars($term), htmlspecialchars($wgInputEncoding), htmlspecialchars(wfMsg('searchbutton'))) . Xml::closeElement('fieldset'));
         wfProfileOut(__METHOD__);
         return;
     }
     $wgOut->addHTML($this->shortDialog($term));
     // Sometimes the search engine knows there are too many hits
     if ($titleMatches instanceof SearchResultTooMany) {
         $wgOut->addWikiText('==' . wfMsg('toomanymatches') . "==\n");
         $wgOut->addHTML($this->powerSearchBox($term));
         $wgOut->addHTML($this->powerSearchFocus());
         wfProfileOut(__METHOD__);
         return;
     }
     // show number of results
     $num = ($titleMatches ? $titleMatches->numRows() : 0) + ($textMatches ? $textMatches->numRows() : 0);
     $totalNum = 0;
     if ($titleMatches && !is_null($titleMatches->getTotalHits())) {
         $totalNum += $titleMatches->getTotalHits();
     }
     if ($textMatches && !is_null($textMatches->getTotalHits())) {
         $totalNum += $textMatches->getTotalHits();
     }
     if ($num > 0) {
         if ($totalNum > 0) {
             $top = wfMsgExt('showingresultstotal', array('parseinline'), $this->offset + 1, $this->offset + $num, $totalNum, $num);
         } elseif ($num >= $this->limit) {
             $top = wfShowingResults($this->offset, $this->limit);
         } else {
             $top = wfShowingResultsNum($this->offset, $this->limit, $num);
         }
         $wgOut->addHTML("<p class='mw-search-numberresults'>{$top}</p>\n");
     }
     // prev/next links
     if ($num || $this->offset) {
         $prevnext = wfViewPrevNext($this->offset, $this->limit, SpecialPage::getTitleFor('Search'), wfArrayToCGI($this->powerSearchOptions(), array('search' => $term)), $num < $this->limit);
         $wgOut->addHTML("<p class='mw-search-pager-top'>{$prevnext}</p>\n");
         wfRunHooks('SpecialSearchResults', array($term, &$titleMatches, &$textMatches));
     } else {
         wfRunHooks('SpecialSearchNoResults', array($term));
     }
     if ($titleMatches) {
         if ($titleMatches->numRows()) {
             $wgOut->wrapWikiMsg("==\$1==\n", 'titlematches');
             $wgOut->addHTML($this->showMatches($titleMatches));
         }
         $titleMatches->free();
     }
     if ($textMatches) {
         // output appropriate heading
         if ($textMatches->numRows()) {
             if ($titleMatches) {
                 $wgOut->wrapWikiMsg("==\$1==\n", 'textmatches');
             } else {
                 // if no title matches the heading is redundant
                 $wgOut->addHTML("<hr/>");
             }
         } elseif ($num == 0) {
             # Don't show the 'no text matches' if we received title matches
             $wgOut->wrapWikiMsg("==\$1==\n", 'notextmatches');
         }
         // show interwiki results if any
         if ($textMatches->hasInterwikiResults()) {
             $wgOut->addHTML($this->showInterwiki($textMatches->getInterwikiResults(), $term));
         }
         // show results
         if ($textMatches->numRows()) {
             $wgOut->addHTML($this->showMatches($textMatches));
         }
         $textMatches->free();
     }
     if ($num == 0) {
         $wgOut->addWikiMsg('nonefound');
     }
     if ($num || $this->offset) {
         $wgOut->addHTML("<p class='mw-search-pager-bottom'>{$prevnext}</p>\n");
     }
     $wgOut->addHTML($this->powerSearchBox($term));
     wfProfileOut(__METHOD__);
 }
/**
 *
 */
function wfSpecialMissingLanguageLinks()
{
    global $wgUser, $wgOut, $wgContLang, $wgTitle, $wgRequest;
    $fname = 'wfSpecialMissingLanguageLinks';
    $thelang = $wgRequest->getText('thelang');
    if ($thelang == 'w') {
        $thelang = 'en';
    }
    # Fix for international wikis
    list($limit, $offset) = wfCheckLimits();
    $dbr =& wfGetDB(DB_SLAVE);
    $cur = $dbr->tableName('cur');
    $sql = "SELECT cur_title FROM {$cur} " . "WHERE cur_namespace=" . NS_MAIN . " AND cur_is_redirect=0 " . "AND cur_title NOT LIKE '%/%' AND cur_text NOT LIKE '%[[" . wfStrencode($thelang) . ":%' " . "LIMIT {$offset}, {$limit}";
    $res = $dbr->query($sql, $fname);
    $mll = wfMsg('missinglanguagelinkstext', $wgContLang->getLanguageName($thelang));
    $top = getMaintenancePageBacklink('missinglanguagelinks');
    $top .= "<p>{$mll}</p><br />";
    $top .= wfShowingResults($offset, $limit);
    $wgOut->addHTML("<p>{$top}\n");
    $sl = wfViewPrevNext($offset, $limit, 'REPLACETHIS');
    $sl = str_replace('REPLACETHIS', sns() . ":Maintenance&subfunction=missinglanguagelinks&thelang=" . htmlspecialchars($thelang), $sl);
    $wgOut->addHTML("<br />{$sl}\n");
    $sk = $wgUser->getSkin();
    $s = '<ol start=' . ($offset + 1) . '>';
    while ($obj = $dbr->fetchObject($res)) {
        $s .= "<li>" . $sk->makeKnownLink($obj->cur_title) . "</li>\n";
    }
    $dbr->freeResult($res);
    $s .= '</ol>';
    $wgOut->addHTML($s);
    $wgOut->addHTML("<p>{$sl}\n");
}
    /**
     * Display some statistics when a user clicks stats link (&action=stats)
     *
     * @param $blckid Int: ID number of the block
     */
    private function showStatsList($blckid)
    {
        global $wgOut, $wgLang, $wgUser, $wgContLang;
        wfProfileIn(__METHOD__);
        $action = $this->mTitle->escapeLocalURL($this->makeListUrlParams(true));
        $skin = $wgUser->getSkin();
        $regexData = new RegexBlockData();
        $this->numStatResults = $regexData->fetchNbrStatResults($blckid);
        $filter = 'action=stats&filter=' . urlencode($this->mFilter) . '&blckid=' . urlencode($blckid);
        $pager = wfViewPrevNext($this->mOffset, $this->mLimit, $wgContLang->specialpage('RegexBlock'), $filter, $this->numStatResults - $this->mOffset <= $this->mLimit);
        /* allow display by specific blockers only */
        $blockInfo = $regexData->getRegexBlockById($blckid);
        $stats_list = array();
        if (!empty($blockInfo) && is_object($blockInfo)) {
            $stats_list = $regexData->getStatsData($blckid, $this->mLimit, $this->mOffset);
        }
        $blocker_link = $skin->makeKnownLinkObj($this->mTitle, $blockInfo->blckby_blocker, 'filter=' . urlencode($blockInfo->blckby_blocker));
        $blockername_link = $skin->makeKnownLinkObj($this->mTitle, $blockInfo->blckby_name, 'rfilter=' . urlencode($blockInfo->blckby_name));
        $blockReason = $blockInfo->blckby_reason ? wfMsg('regexblock-form-reason') . $blockInfo->blckby_reason : wfMsg('regexblock-view-reason-default');
        $wgOut->addHTML('<h5>' . wfMsg('regexblock-stats-title') . ' <strong> ' . $blockername_link . '</strong> (' . wfMsg('regexblock-view-block-by') . ' <b>' . $blocker_link . '</b>,&#160;<i>' . $blockReason . '</i>)</h5><br />');
        if (!empty($stats_list)) {
            $wgOut->addHTML('<p>' . $pager . '</p><br /><ul>');
            foreach ($stats_list as $id => $row) {
                $wgOut->addHTML('<li style="border-bottom:1px dashed #778899; padding-bottom:2px;font-size:11px">
					' . wfMsg('regexblock-match-stats-record', array($row->stats_match, $row->stats_user, htmlspecialchars($row->stats_dbname), $wgLang->timeanddate(wfTimestamp(TS_MW, $row->stats_timestamp), true), $row->stats_ip, $wgLang->date(wfTimestamp(TS_MW, $row->stats_timestamp), true), $wgLang->time(wfTimestamp(TS_MW, $row->stats_timestamp), true))) . '
					</li>');
            }
            $wgOut->addHTML('</ul><br />
				<p>' . $pager . '</p>');
        } else {
            $wgOut->addWikiMsg('regexblock-nodata-found');
        }
        wfProfileOut(__METHOD__);
    }
 function showList($msg)
 {
     global $wgOut;
     $wgOut->setPagetitle(wfMsg("ipblocklist"));
     if ("" != $msg) {
         $wgOut->setSubtitle($msg);
     }
     global $wgRequest;
     list($this->limit, $this->offset) = $wgRequest->getLimitOffset();
     $this->counter = 0;
     $paging = '<p>' . wfViewPrevNext($this->offset, $this->limit, Title::makeTitle(NS_SPECIAL, 'Ipblocklist'), 'ip=' . urlencode($this->ip)) . "</p>\n";
     $wgOut->addHTML($paging);
     $search = $this->searchForm();
     $wgOut->addHTML($search);
     $wgOut->addHTML("<ul>");
     if (!Block::enumBlocks(array(&$this, "addRow"), 0)) {
         // FIXME hack to solve #bug 1487
         $wgOut->addHTML('<li>' . wfMsgHtml('ipblocklistempty') . '</li>');
     }
     $wgOut->addHTML("</ul>\n");
     $wgOut->addHTML($paging);
 }
 /**
  * @param string $term
  * @access public
  */
 function showResults($term)
 {
     $fname = 'SpecialSearch::showResults';
     wfProfileIn($fname);
     $this->setupPage($term);
     global $wgUser, $wgOut;
     $sk = $wgUser->getSkin();
     $wgOut->addWikiText(wfMsg('searchresulttext'));
     #if ( !$this->parseQuery() ) {
     if ('' === trim($term)) {
         $wgOut->setSubtitle('');
         $wgOut->addHTML($this->powerSearchBox($term));
         wfProfileOut($fname);
         return;
     }
     global $wgDisableTextSearch;
     if ($wgDisableTextSearch) {
         global $wgForwardSearchUrl;
         if ($wgForwardSearchUrl) {
             $url = str_replace('$1', urlencode($term), $wgForwardSearchUrl);
             $wgOut->redirect($url);
             return;
         }
         global $wgInputEncoding;
         $wgOut->addHTML(wfMsg('searchdisabled'));
         $wgOut->addHTML(wfMsg('googlesearch', htmlspecialchars($term), htmlspecialchars($wgInputEncoding), htmlspecialchars(wfMsg('search'))));
         wfProfileOut($fname);
         return;
     }
     $search =& SearchEngine::create();
     $search->setLimitOffset($this->limit, $this->offset);
     $search->setNamespaces($this->namespaces);
     $titleMatches = $search->searchTitle($term);
     $textMatches = $search->searchText($term);
     $num = ($titleMatches ? $titleMatches->numRows() : 0) + ($textMatches ? $textMatches->numRows() : 0);
     if ($num >= $this->limit) {
         $top = wfShowingResults($this->offset, $this->limit);
     } else {
         $top = wfShowingResultsNum($this->offset, $this->limit, $num);
     }
     $wgOut->addHTML("<p>{$top}</p>\n");
     if ($num || $this->offset) {
         $prevnext = wfViewPrevNext($this->offset, $this->limit, 'Special:Search', wfArrayToCGI($this->powerSearchOptions(), array('search' => $term)));
         $wgOut->addHTML("<br />{$prevnext}\n");
     }
     if ($titleMatches) {
         if ($titleMatches->numRows()) {
             $wgOut->addWikiText('==' . wfMsg('titlematches') . "==\n");
             $wgOut->addHTML($this->showMatches($titleMatches));
         } else {
             $wgOut->addWikiText('==' . wfMsg('notitlematches') . "==\n");
         }
     }
     if ($textMatches) {
         if ($textMatches->numRows()) {
             $wgOut->addWikiText('==' . wfMsg('textmatches') . "==\n");
             $wgOut->addHTML($this->showMatches($textMatches));
         } elseif ($num == 0) {
             # Don't show the 'no text matches' if we received title matches
             $wgOut->addWikiText('==' . wfMsg('notextmatches') . "==\n");
         }
     }
     if ($num == 0) {
         $wgOut->addWikiText(wfMsg('nonefound'));
     }
     if ($num || $this->offset) {
         $wgOut->addHTML("<p>{$prevnext}</p>\n");
     }
     $wgOut->addHTML($this->powerSearchBox($term));
     wfProfileOut($fname);
 }
Exemple #18
0
 function doQuery($offset, $limit, $shownavigation = true)
 {
     global $wgOut, $wgContLang;
     $res = $this->getIntervalResults($offset, $limit);
     $num = count($res);
     if ($shownavigation) {
         $wgOut->addHTML($this->getPageHeader());
         // if list is empty, display a warning
         if ($num == 0) {
             $wgOut->addHTML('<p>' . wfMsgHTML('specialpage-empty') . '</p>');
             return;
         }
         $top = wfShowingResults($offset, $num);
         $wgOut->addHTML("<p>{$top}\n");
         // often disable 'next' link when we reach the end
         $atend = $num < $limit;
         $sl = wfViewPrevNext($offset, $limit, $wgContLang->specialPage($this->queryPageName()), wfArrayToCGI($this->linkParameters()), $atend);
         $wgOut->addHTML("<br />{$sl}</p>\n");
     }
     if ($num > 0) {
         $s = array();
         if (!$this->listoutput) {
             $s[] = $this->openList($offset);
         }
         foreach ($res as $r) {
             $format = $this->formatResult($r);
             if ($format) {
                 $s[] = $this->listoutput ? $format : "<li>{$format}</li>\n";
             }
         }
         if (!$this->listoutput) {
             $s[] = $this->closeList();
         }
         $str = $this->listoutput ? $wgContLang->listToText($s) : implode('', $s);
         $wgOut->addHTML($str);
     }
     if ($shownavigation) {
         $wgOut->addHTML("<p>{$sl}</p>\n");
     }
     return $num;
 }
Exemple #19
0
 /**
  * This is the actual workhorse. It does everything needed to make a
  * real, honest-to-gosh query page.
  *
  * @param $offset database query offset
  * @param $limit database query limit
  * @param $shownavigation show navigation like "next 200"?
  */
 function doQuery($offset, $limit, $shownavigation = true)
 {
     global $wgUser, $wgOut, $wgLang, $wgContLang;
     $this->offset = $offset;
     $this->limit = $limit;
     $sname = $this->getName();
     $fname = get_class($this) . '::doQuery';
     $sql = $this->getSQL();
     $dbr =& wfGetDB(DB_SLAVE);
     $querycache = $dbr->tableName('querycache');
     $wgOut->setSyndicated($this->isSyndicated());
     if ($this->isCached()) {
         $type = $dbr->strencode($sname);
         $sql = "SELECT qc_type as type, qc_namespace as namespace,qc_title as title, qc_value as value\n\t\t\t\t FROM {$querycache} WHERE qc_type='{$type}'";
         if (!$this->listoutput) {
             # Fetch the timestamp of this update
             $tRes = $dbr->select('querycache_info', array('qci_timestamp'), array('qci_type' => $type), $fname);
             $tRow = $dbr->fetchObject($tRes);
             if ($tRow) {
                 $updated = $wgLang->timeAndDate($tRow->qci_timestamp, true, true);
                 $cacheNotice = wfMsg('perfcachedts', $updated);
                 $wgOut->addMeta('Data-Cache-Time', $tRow->qci_timestamp);
                 $wgOut->addScript('<script language="JavaScript">var dataCacheTime = \'' . $tRow->qci_timestamp . '\';</script>');
             } else {
                 $cacheNotice = wfMsg('perfcached');
             }
             $wgOut->addWikiText($cacheNotice);
         }
     }
     $sql .= $this->getOrder();
     $sql = $dbr->limitResult($sql, $limit, $offset);
     $res = $dbr->query($sql);
     $num = $dbr->numRows($res);
     $this->preprocessResults($dbr, $res);
     $sk = $wgUser->getSkin();
     if ($shownavigation) {
         $wgOut->addHTML($this->getPageHeader());
         $top = wfShowingResults($offset, $num);
         $wgOut->addHTML("<p>{$top}\n");
         # often disable 'next' link when we reach the end
         $atend = $num < $limit;
         $sl = wfViewPrevNext($offset, $limit, $wgContLang->specialPage($sname), wfArrayToCGI($this->linkParameters()), $atend);
         $wgOut->addHTML("<br />{$sl}</p>\n");
     }
     if ($num > 0) {
         $s = array();
         if (!$this->listoutput) {
             $s[] = "<ol start='" . ($offset + 1) . "' class='special'>";
         }
         # Only read at most $num rows, because $res may contain the whole 1000
         for ($i = 0; $i < $num && ($obj = $dbr->fetchObject($res)); $i++) {
             $format = $this->formatResult($sk, $obj);
             if ($format) {
                 $attr = isset($obj->usepatrol) && $obj->usepatrol && $obj->patrolled == 0 ? ' class="not-patrolled"' : '';
                 $s[] = $this->listoutput ? $format : "<li{$attr}>{$format}</li>\n";
             }
         }
         if ($this->tryLastResult()) {
             // flush the very last result
             $obj = null;
             $format = $this->formatResult($sk, $obj);
             if ($format) {
                 $attr = isset($obj->usepatrol) && $obj->usepatrol && $obj->patrolled == 0 ? ' class="not-patrolled"' : '';
                 $s[] = "<li{$attr}>{$format}</li>\n";
             }
         }
         $dbr->freeResult($res);
         if (!$this->listoutput) {
             $s[] = '</ol>';
         }
         $str = $this->listoutput ? $wgContLang->listToText($s) : implode('', $s);
         $wgOut->addHTML($str);
     }
     if ($shownavigation) {
         $wgOut->addHTML("<p>{$sl}</p>\n");
     }
     return $num;
 }
 function showPrevNext(&$out)
 {
     global $wgContLang, $wgRequest;
     list($limit, $offset) = $wgRequest->getLimitOffset();
     $filter = 'filter=' . urlencode($wgRequest->getVal('filter'));
     $html = wfViewPrevNext($offset, $limit, $wgContLang->specialpage('Regexblock'), $filter, $this->numResults - $offset <= $limit);
     $out->addHTML('<p>' . $html . '</p>');
 }
 /**
  * @param string $term
  */
 public function showResults($term)
 {
     global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang, $wgScript;
     wfProfileIn(__METHOD__);
     $sk = $wgUser->getSkin();
     $this->searchEngine = SearchEngine::create();
     $search =& $this->searchEngine;
     $search->setLimitOffset($this->limit, $this->offset);
     $search->setNamespaces($this->namespaces);
     $search->showRedirects = $this->searchRedirects;
     $search->prefix = $this->mPrefix;
     $term = $search->transformSearchTerm($term);
     $this->setupPage($term);
     if ($wgDisableTextSearch) {
         global $wgSearchForwardUrl;
         if ($wgSearchForwardUrl) {
             $url = str_replace('$1', urlencode($term), $wgSearchForwardUrl);
             $wgOut->redirect($url);
             wfProfileOut(__METHOD__);
             return;
         }
         global $wgInputEncoding;
         $wgOut->addHTML(Xml::openElement('fieldset') . Xml::element('legend', null, wfMsg('search-external')) . Xml::element('p', array('class' => 'mw-searchdisabled'), wfMsg('searchdisabled')) . wfMsg('googlesearch', htmlspecialchars($term), htmlspecialchars($wgInputEncoding), htmlspecialchars(wfMsg('searchbutton'))) . Xml::closeElement('fieldset'));
         wfProfileOut(__METHOD__);
         return;
     }
     $t = Title::newFromText($term);
     // fetch search results
     $rewritten = $search->replacePrefixes($term);
     $titleMatches = $search->searchTitle($rewritten);
     if (!$titleMatches instanceof SearchResultTooMany) {
         $textMatches = $search->searchText($rewritten);
     }
     // did you mean... suggestions
     if ($textMatches && $textMatches->hasSuggestion()) {
         $st = SpecialPage::getTitleFor('Search');
         # mirror Go/Search behaviour of original request ..
         $didYouMeanParams = array('search' => $textMatches->getSuggestionQuery());
         if ($this->fulltext != null) {
             $didYouMeanParams['fulltext'] = $this->fulltext;
         }
         $stParams = array_merge($didYouMeanParams, $this->powerSearchOptions());
         $suggestionSnippet = $textMatches->getSuggestionSnippet();
         if ($suggestionSnippet == '') {
             $suggestionSnippet = null;
         }
         $suggestLink = $sk->linkKnown($st, $suggestionSnippet, array(), $stParams);
         $this->didYouMeanHtml = '<div class="searchdidyoumean">' . wfMsg('search-suggest', $suggestLink) . '</div>';
     }
     // start rendering the page
     $wgOut->addHtml(Xml::openElement('form', array('id' => $this->searchAdvanced ? 'powersearch' : 'search', 'method' => 'get', 'action' => $wgScript)));
     $wgOut->addHtml(Xml::openElement('table', array('id' => 'mw-search-top-table', 'border' => 0, 'cellpadding' => 0, 'cellspacing' => 0)) . Xml::openElement('tr') . Xml::openElement('td') . "\n" . $this->shortDialog($term) . Xml::closeElement('td') . Xml::closeElement('tr') . Xml::closeElement('table'));
     // Sometimes the search engine knows there are too many hits
     if ($titleMatches instanceof SearchResultTooMany) {
         $wgOut->addWikiText('==' . wfMsg('toomanymatches') . "==\n");
         wfProfileOut(__METHOD__);
         return;
     }
     $filePrefix = $wgContLang->getFormattedNsText(NS_FILE) . ':';
     if (trim($term) === '' || $filePrefix === trim($term)) {
         $wgOut->addHTML($this->searchFocus());
         $wgOut->addHTML($this->formHeader($term, 0, 0));
         if ($this->searchAdvanced) {
             $wgOut->addHTML($this->powerSearchBox($term));
         }
         $wgOut->addHTML('</form>');
         // Empty query -- straight view of search form
         wfProfileOut(__METHOD__);
         return;
     }
     // Get number of results
     $titleMatchesNum = $titleMatches ? $titleMatches->numRows() : 0;
     $textMatchesNum = $textMatches ? $textMatches->numRows() : 0;
     // Total initial query matches (possible false positives)
     $num = $titleMatchesNum + $textMatchesNum;
     // Get total actual results (after second filtering, if any)
     $numTitleMatches = $titleMatches && !is_null($titleMatches->getTotalHits()) ? $titleMatches->getTotalHits() : $titleMatchesNum;
     $numTextMatches = $textMatches && !is_null($textMatches->getTotalHits()) ? $textMatches->getTotalHits() : $textMatchesNum;
     // get total number of results if backend can calculate it
     $totalRes = 0;
     if ($titleMatches && !is_null($titleMatches->getTotalHits())) {
         $totalRes += $titleMatches->getTotalHits();
     }
     if ($textMatches && !is_null($textMatches->getTotalHits())) {
         $totalRes += $textMatches->getTotalHits();
     }
     // show number of results and current offset
     $wgOut->addHTML($this->formHeader($term, $num, $totalRes));
     if ($this->searchAdvanced) {
         $wgOut->addHTML($this->powerSearchBox($term));
     }
     $wgOut->addHtml(Xml::closeElement('form'));
     $wgOut->addHtml("<div class='searchresults'>");
     // prev/next links
     if ($num || $this->offset) {
         // Show the create link ahead
         $this->showCreateLink($t);
         $prevnext = wfViewPrevNext($this->offset, $this->limit, SpecialPage::getTitleFor('Search'), wfArrayToCGI($this->powerSearchOptions(), array('search' => $term)), max($titleMatchesNum, $textMatchesNum) < $this->limit);
         //$wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
         wfRunHooks('SpecialSearchResults', array($term, &$titleMatches, &$textMatches));
     } else {
         wfRunHooks('SpecialSearchNoResults', array($term));
     }
     if ($titleMatches) {
         if ($numTitleMatches > 0) {
             $wgOut->wrapWikiMsg("==\$1==\n", 'titlematches');
             $wgOut->addHTML($this->showMatches($titleMatches));
         }
         $titleMatches->free();
     }
     if ($textMatches) {
         // output appropriate heading
         if ($numTextMatches > 0 && $numTitleMatches > 0) {
             // if no title matches the heading is redundant
             $wgOut->wrapWikiMsg("==\$1==\n", 'textmatches');
         } elseif ($totalRes == 0) {
             # Don't show the 'no text matches' if we received title matches
             # $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
         }
         // show interwiki results if any
         if ($textMatches->hasInterwikiResults()) {
             $wgOut->addHTML($this->showInterwiki($textMatches->getInterwikiResults(), $term));
         }
         // show results
         if ($numTextMatches > 0) {
             $wgOut->addHTML($this->showMatches($textMatches));
         }
         $textMatches->free();
     }
     if ($num === 0) {
         $wgOut->addWikiMsg('search-nonefound', wfEscapeWikiText($term));
         $this->showCreateLink($t);
     }
     $wgOut->addHtml("</div>");
     if ($num === 0) {
         $wgOut->addHTML($this->searchFocus());
     }
     if ($num || $this->offset) {
         $wgOut->addHTML("<p class='mw-search-pager-bottom'>{$prevnext}</p>\n");
     }
     wfProfileOut(__METHOD__);
 }
 function doQuery($offset, $limit, $shownavigation = true)
 {
     global $wgUser, $wgOut, $wgLang, $wgContLang;
     $res = $this->getIntervalResults($offset, $limit);
     $num = count($res);
     $sk = $wgUser->getSkin();
     $sname = $this->getName();
     if ($shownavigation) {
         $wgOut->addHTML($this->getPageHeader());
         // if list is empty, display a warning
         if ($num == 0) {
             $wgOut->addWikiMsg('specialpage-empty');
             return;
         }
         $wgOut->addHTML(wfMsgExt('showingresults', 'parse', $wgLang->formatNum($num), $wgLang->formatNum($offset + 1)));
         // often disable 'next' link when we reach the end
         $atend = $num < $limit;
         $sl = wfViewPrevNext($offset, $limit, SpecialPage::getTitleFor('CurrentEdits'), wfArrayToCGI($this->linkParameters()), $atend);
         $wgOut->addHTML("<p>{$sl}</p>\n");
     }
     if ($num > 0) {
         $s = array();
         if (!$this->listoutput) {
             $s[] = $this->openList($offset);
         }
         foreach ($res as $r) {
             $format = $this->formatResult($sk, $r);
             if ($format) {
                 $s[] = $this->listoutput ? $format : "<li>{$format}</li>\n";
             }
         }
         if (!$this->listoutput) {
             $s[] = $this->closeList();
         }
         $str = $this->listoutput ? $wgContLang->listToText($s) : implode('', $s);
         $wgOut->addHTML($str);
     }
     if ($shownavigation) {
         $wgOut->addHTML("<p>{$sl}</p>\n");
     }
     return $num;
 }
Exemple #23
0
 /**
  * This is the actual workhorse. It does everything needed to make a
  * real, honest-to-gosh query page.
  *
  * @param $offset database query offset
  * @param $limit database query limit
  * @param $shownavigation show navigation like "next 200"?
  */
 function doQuery($offset, $limit, $shownavigation = true)
 {
     global $wgUser, $wgOut, $wgLang, $wgContLang;
     $this->offset = $offset;
     $this->limit = $limit;
     $sname = $this->getName();
     $fname = get_class($this) . '::doQuery';
     $dbr = wfGetDB(DB_SLAVE);
     $wgOut->setSyndicated($this->isSyndicated());
     if (!$this->isCached()) {
         $sql = $this->getSQL();
     } else {
         # Get the cached result
         $querycache = $dbr->tableName('querycache');
         $type = $dbr->strencode($sname);
         $sql = "SELECT qc_type as type, qc_namespace as namespace,qc_title as title, qc_value as value\n\t\t\t\t FROM {$querycache} WHERE qc_type='{$type}'";
         if (!$this->listoutput) {
             # Fetch the timestamp of this update
             $tRes = $dbr->select('querycache_info', array('qci_timestamp'), array('qci_type' => $type), $fname);
             $tRow = $dbr->fetchObject($tRes);
             if ($tRow) {
                 $updated = $wgLang->timeanddate($tRow->qci_timestamp, true, true);
                 $updateddate = $wgLang->date($tRow->qci_timestamp, true, true);
                 $updatedtime = $wgLang->time($tRow->qci_timestamp, true, true);
                 $wgOut->addMeta('Data-Cache-Time', $tRow->qci_timestamp);
                 $wgOut->addInlineScript("var dataCacheTime = '{$tRow->qci_timestamp}';");
                 $wgOut->addWikiMsg('perfcachedts', $updated, $updateddate, $updatedtime);
             } else {
                 $wgOut->addWikiMsg('perfcached');
             }
             # If updates on this page have been disabled, let the user know
             # that the data set won't be refreshed for now
             global $wgDisableQueryPageUpdate;
             if (is_array($wgDisableQueryPageUpdate) && in_array($this->getName(), $wgDisableQueryPageUpdate)) {
                 $wgOut->addWikiMsg('querypage-no-updates');
             }
         }
     }
     $sql .= $this->getOrder();
     $sql = $dbr->limitResult($sql, $limit, $offset);
     $res = $dbr->query($sql);
     $num = $dbr->numRows($res);
     $this->preprocessResults($dbr, $res);
     $wgOut->addHTML(Xml::openElement('div', array('class' => 'mw-spcontent')));
     # Top header and navigation
     if ($shownavigation) {
         $wgOut->addHTML($this->getPageHeader());
         if ($num > 0) {
             $wgOut->addHTML('<p>' . wfShowingResults($offset, $num) . '</p>');
             # Disable the "next" link when we reach the end
             $paging = wfViewPrevNext($offset, $limit, $wgContLang->specialPage($sname), wfArrayToCGI($this->linkParameters()), $num < $limit);
             $wgOut->addHTML('<p>' . $paging . '</p>');
         } else {
             # No results to show, so don't bother with "showing X of Y" etc.
             # -- just let the user know and give up now
             $wgOut->addHTML('<p>' . wfMsgHtml('specialpage-empty') . '</p>');
             $wgOut->addHTML(Xml::closeElement('div'));
             return;
         }
     }
     # The actual results; specialist subclasses will want to handle this
     # with more than a straight list, so we hand them the info, plus
     # an OutputPage, and let them get on with it
     $this->outputResults($wgOut, $wgUser->getSkin(), $dbr, $res, $dbr->numRows($res), $offset);
     # Repeat the paging links at the bottom
     if ($shownavigation) {
         $wgOut->addHTML('<p>' . $paging . '</p>');
     }
     $wgOut->addHTML(Xml::closeElement('div'));
     return $num;
 }
 function showPrevNext(&$out)
 {
     global $wgContLang, $wgRequest;
     list($limit, $offset) = $wgRequest->getLimitOffset();
     $html = wfViewPrevNext($offset, $limit, $wgContLang->specialpage('SpamRegex'), '', $this->numResults - $offset <= $limit);
     $out->addHTML('<p>' . $html . '</p>');
 }