当前位置: 首页>>代码示例>>PHP>>正文


PHP wfRandom函数代码示例

本文整理汇总了PHP中wfRandom函数的典型用法代码示例。如果您正苦于以下问题:PHP wfRandom函数的具体用法?PHP wfRandom怎么用?PHP wfRandom使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wfRandom函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: wfSpecialRandomredirect

/**
 * Main execution point
 * @param $par Namespace to select the redirect from
 */
function wfSpecialRandomredirect($par = NULL)
{
    global $wgOut, $wgExtraRandompageSQL, $wgContLang;
    $fname = 'wfSpecialRandomredirect';
    # Validate the namespace
    $namespace = $wgContLang->getNsIndex($par);
    if ($namespace === false || $namespace < NS_MAIN) {
        $namespace = NS_MAIN;
    }
    # Same logic as RandomPage
    $randstr = wfRandom();
    $dbr =& wfGetDB(DB_SLAVE);
    $use_index = $dbr->useIndexClause('page_random');
    $page = $dbr->tableName('page');
    $extra = $wgExtraRandompageSQL ? "AND ({$wgExtraRandompageSQL})" : '';
    $sql = "SELECT page_id,page_title\n\t\tFROM {$page} {$use_index}\n\t\tWHERE page_namespace = {$namespace} AND page_is_redirect = 1 {$extra}\n\t\tAND page_random > {$randstr}\n\t\tORDER BY page_random";
    $sql = $dbr->limitResult($sql, 1, 0);
    $res = $dbr->query($sql, $fname);
    $title = NULL;
    if ($row = $dbr->fetchObject($res)) {
        $title = Title::makeTitleSafe($namespace, $row->page_title);
    }
    # Catch dud titles and return to the main page
    if (is_null($title)) {
        $title = Title::newMainPage();
    }
    $wgOut->reportTime();
    $wgOut->redirect($title->getFullUrl('redirect=no'));
}
开发者ID:negabaro,项目名称:alfresco,代码行数:33,代码来源:SpecialRandomredirect.php

示例2: execute

 /**
  * main()
  */
 public function execute($par)
 {
     global $wgOut;
     $fname = 'SpecialAdvancedRandom::execute';
     wfProfileIn($fname);
     list($page, $namespace) = $this->extractParamaters($par);
     $ft = Title::newFromText($page);
     if (is_null($ft)) {
         $this->redirect(Title::newMainPage());
         wfProfileOut($fname);
         return;
     }
     $rand = wfRandom();
     $dbr = wfGetDB(DB_SLAVE);
     if ($ft->getNamespace() == NS_TEMPLATE) {
         $res = $dbr->selectRow(array('page', 'templatelinks'), array('page_namespace', 'page_title', 'page_random'), array('page_id = tl_from', 'tl_namespace' => NS_TEMPLATE, 'page_namespace' => $namespace, 'tl_title' => $ft->getDBkey(), "page_random > {$rand}"), $fname, array('ORDER BY' => 'page_random', 'USE INDEX' => array('page' => 'page_random')));
     } else {
         $res = $dbr->selectRow(array('page', 'pagelinks'), array('page_namespace', 'page_title', 'page_random'), array('page_id = pl_from', 'pl_namespace' => $ft->getNamespace(), 'page_namespace' => $namespace, 'pl_title' => $ft->getDBkey(), "page_random > {$rand}"), $fname, array('ORDER BY' => 'page_random', 'USE INDEX' => array('page' => 'page_random')));
     }
     $title =& Title::makeTitle(MWNamespace::getSubject($namespace), $res->page_title);
     if (is_null($title) || $title->getText() == '') {
         $title = Title::newMainPage();
     }
     $this->redirect($title);
     wfProfileOut($fname);
 }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:29,代码来源:AdvancedRandom_body.php

示例3: testGet

 /**
  * @param string $name
  * @param array $params
  * @dataProvider provideGet
  * @covers GlobalConfig::get
  */
 public function testGet($name, $params)
 {
     $rand = wfRandom();
     $old = isset($GLOBALS[$name]) ? $GLOBALS[$name] : null;
     $GLOBALS[$name] = $rand;
     $out = call_user_func_array(array($this->config, 'get'), $params);
     $this->assertEquals($rand, $out);
     if ($old) {
         $GLOBALS[$name] = $old;
     }
 }
开发者ID:biribogos,项目名称:wikihow-src,代码行数:17,代码来源:GlobalConfigTest.php

示例4: quickTestBackend

 private function quickTestBackend()
 {
     $dbr = wfGetDB(DB_SLAVE);
     try {
         $res = $dbr->selectField('page', 'page_id', array('page_is_redirect' => 0, 'page_namespace' => NS_MAIN, 'page_random >= ' . wfRandom()), __METHOD__, array('ORDER BY' => 'page_random', 'USE INDEX' => 'page_random'));
     } catch (DBError $e) {
         $res = null;
     }
     if (is_string($res) && intval($res) > 0) {
         return true;
     } else {
         return false;
     }
 }
开发者ID:ErdemA,项目名称:wikihow,代码行数:14,代码来源:Alien.body.php

示例5: execute

 public function execute()
 {
     $pages = $this->getOption('maxpages');
     $dbr = $this->getDB(DB_REPLICA);
     $totalsec = 0.0;
     $scanned = 0;
     $withcache = 0;
     $withdiff = 0;
     while ($pages-- > 0) {
         $row = $dbr->selectRow('page', '*', ['page_namespace' => $this->getOption('namespace'), 'page_is_redirect' => 0, 'page_random >= ' . wfRandom()], __METHOD__, ['ORDER BY' => 'page_random']);
         if (!$row) {
             continue;
         }
         ++$scanned;
         $title = Title::newFromRow($row);
         $page = WikiPage::factory($title);
         $revision = $page->getRevision();
         $content = $revision->getContent(Revision::RAW);
         $parserOptions = $page->makeParserOptions('canonical');
         $parserOutputOld = ParserCache::singleton()->get($page, $parserOptions);
         if ($parserOutputOld) {
             $t1 = microtime(true);
             $parserOutputNew = $content->getParserOutput($title, $revision->getId(), $parserOptions, false);
             $sec = microtime(true) - $t1;
             $totalsec += $sec;
             $this->output("Parsed '{$title->getPrefixedText()}' in {$sec} seconds.\n");
             $this->output("Found cache entry found for '{$title->getPrefixedText()}'...");
             $oldHtml = trim(preg_replace('#<!-- .+-->#Us', '', $parserOutputOld->getText()));
             $newHtml = trim(preg_replace('#<!-- .+-->#Us', '', $parserOutputNew->getText()));
             $diff = wfDiff($oldHtml, $newHtml);
             if (strlen($diff)) {
                 $this->output("differences found:\n\n{$diff}\n\n");
                 ++$withdiff;
             } else {
                 $this->output("No differences found.\n");
             }
             ++$withcache;
         } else {
             $this->output("No parser cache entry found for '{$title->getPrefixedText()}'.\n");
         }
     }
     $ave = $totalsec ? $totalsec / $scanned : 0;
     $this->output("Checked {$scanned} pages; {$withcache} had prior cache entries.\n");
     $this->output("Pages with differences found: {$withdiff}\n");
     $this->output("Average parse time: {$ave} sec\n");
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:46,代码来源:compareParserCache.php

示例6: getRandomTitle

 /**
  * Choose a random title.
  * @return Title object (or null if nothing to choose from)
  */
 public function getRandomTitle()
 {
     $randstr = wfRandom();
     $row = $this->selectRandomPageFromDB($randstr);
     /* If we picked a value that was higher than any in
      * the DB, wrap around and select the page with the
      * lowest value instead!  One might think this would
      * skew the distribution, but in fact it won't cause
      * any more bias than what the page_random scheme
      * causes anyway.  Trust me, I'm a mathematician. :)
      */
     if (!$row) {
         $row = $this->selectRandomPageFromDB("0");
     }
     if ($row) {
         return Title::makeTitleSafe($this->namespace, $row->page_title);
     } else {
         return null;
     }
 }
开发者ID:Jobava,项目名称:diacritice-meta-repo,代码行数:24,代码来源:SpecialRandompage.php

示例7: wfSpecialRandompage

/**
 * Constructor
 *
 * @param string $par the namespace to get a random page from (default NS_MAIN), 
 *               used as e.g. Special:Randompage/Category
 */
function wfSpecialRandompage($par = NS_MAIN)
{
    global $wgOut, $wgTitle, $wgArticle, $wgExtraRandompageSQL, $wgContLang;
    $fname = 'wfSpecialRandompage';
    # Determine the namespace to get a random page from.
    $namespace = $wgContLang->getNsIndex($par);
    if ($namespace === false || $namespace < NS_MAIN) {
        $namespace = NS_MAIN;
    }
    # NOTE! We use a literal constant in the SQL instead of the RAND()
    # function because RAND() will return a different value for every row
    # in the table. That's both very slow and returns results heavily
    # biased towards low values, as rows later in the table will likely
    # never be reached for comparison.
    #
    # Using a literal constant means the whole thing gets optimized on
    # the index, and the comparison is both fast and fair.
    # interpolation and sprintf() can muck up with locale-specific decimal separator
    $randstr = wfRandom();
    $db =& wfGetDB(DB_SLAVE);
    $use_index = $db->useIndexClause('page_random');
    $page = $db->tableName('page');
    $extra = $wgExtraRandompageSQL ? "AND ({$wgExtraRandompageSQL})" : '';
    $sql = "SELECT page_id,page_title\n\t\tFROM {$page} {$use_index}\n\t\tWHERE page_namespace={$namespace} AND page_is_redirect=0 {$extra}\n\t\tAND page_random>{$randstr}\n\t\tORDER BY page_random\n\t\tLIMIT 1";
    $res = $db->query($sql, $fname);
    $title = null;
    if ($s = $db->fetchObject($res)) {
        $title =& Title::makeTitle($namespace, $s->page_title);
    }
    if (is_null($title)) {
        # That's not supposed to happen :)
        $title =& Title::newFromText(wfMsg('mainpage'));
    }
    $wgOut->reportTime();
    # for logfile
    $wgOut->redirect($title->getFullUrl());
}
开发者ID:BackupTheBerlios,项目名称:blahtex,代码行数:43,代码来源:SpecialRandompage.php

示例8: shouldLog

 /**
 		Makes a decision as to if the event should be logged or not.
 */
 private function shouldLog()
 {
     $rnd = wfRandom();
     return $rnd < self::probLog ? true : false;
 }
开发者ID:clrh,项目名称:mediawiki,代码行数:8,代码来源:UserLoginLogoutLog.body.php

示例9: add_to_wiki

 function add_to_wiki()
 {
     self::text_size();
     $this->wDB->commit();
     $this->wDB->begin();
     $page_id = $this->wDB->nextSequenceValue('page_page_id_seq');
     $this->wDB->insert('page', array('page_id' => $page_id, 'page_namespace' => NS_AWC_FORUM, 'page_title' => "Special:AWCforum/st/id{$this->tID}/" . self::page_title(), 'page_counter' => 0, 'page_restrictions' => '', 'page_is_redirect' => 0, 'page_is_new' => 1, 'page_random' => wfRandom(), 'page_touched' => $this->time, 'page_latest' => 0, 'page_len' => $this->size));
     $this->pageID = $this->wDB->insertId();
     $this->wDB->commit();
     // die(">". $this->pageID);
     if ($this->pageID == 0) {
         return;
     }
     $this->wDB->begin();
     self::insert_text();
     self::insert_rev();
     /*        
             use the first text inserted and rev_id to "update" 
             when a post is added to the thread, this is used in the search options
     */
     $this->wDB->update('page', array('page_latest' => $this->insert_revID), array('page_id' => $this->pageID), '');
     /*insert text a second time
       use this second inputed text-rev_id as the Main Threads Posts text
       use first inputed text-rev_id for search resultes
       add 'rev_parent_id' so we can call this text later... if we want.*/
     /*
             self::insert_text();
             
             
                           
             $this->wDB->insert( 'revision', array(
                     'rev_page'        => $this->pageID,
                     'rev_len'        => $this->size,
                     'rev_text_id'       => $this->insert_textID,
                     'rev_comment'        => 'main_thread_post',
                     'rev_user'        => $this->mId,
                     'rev_user_text'       => $this->mName,
                     'rev_timestamp'        => $this->time,
                     'rev_minor_edit'        => 0,
                     'rev_deleted'       => 0,
                     'rev_len'        => $this->size,
                     'rev_parent_id'        => $this->pageID,
                 ) );
     */
     $this->wDB->insert('searchindex', array('si_page' => $this->pageID, 'si_title' => $this->title, 'si_text' => $this->text_to_save));
     $this->wDB->commit();
 }
开发者ID:BackupTheBerlios,项目名称:swahili-dict,代码行数:47,代码来源:to_wiki_dbase.php

示例10: insertOn

 /**
  * Insert a new empty page record for this article.
  * This *must* be followed up by creating a revision
  * and running $this->updateToLatest( $rev_id );
  * or else the record will be left in a funky state.
  * Best if all done inside a transaction.
  *
  * @param Database $dbw
  * @param string   $restrictions
  * @return int     The newly created page_id key
  * @private
  */
 function insertOn(&$dbw, $restrictions = '')
 {
     wfProfileIn(__METHOD__);
     $page_id = $dbw->nextSequenceValue('page_page_id_seq');
     $dbw->insert('page', array('page_id' => $page_id, 'page_namespace' => $this->mTitle->getNamespace(), 'page_title' => $this->mTitle->getDBkey(), 'page_counter' => 0, 'page_restrictions' => $restrictions, 'page_is_redirect' => 0, 'page_is_new' => 1, 'page_random' => wfRandom(), 'page_touched' => $dbw->timestamp(), 'page_latest' => 0, 'page_len' => 0), __METHOD__);
     $newid = $dbw->insertId();
     $this->mTitle->resetArticleId($newid);
     wfProfileOut(__METHOD__);
     return $newid;
 }
开发者ID:negabaro,项目名称:alfresco,代码行数:22,代码来源:Article.php

示例11: run

 public function run($resultPageSet = null)
 {
     $params = $this->extractRequestParams();
     $result = $this->getResult();
     $this->pageIDs = array();
     $this->prepareQuery(wfRandom(), $params['limit'], $params['namespace'], $resultPageSet, $params['redirect']);
     $count = $this->runQuery($resultPageSet);
     if ($count < $params['limit']) {
         /* We got too few pages, we probably picked a high value
          * for page_random. We'll just take the lowest ones, see
          * also the comment in Title::getRandomTitle()
          */
         $this->prepareQuery(0, $params['limit'] - $count, $params['namespace'], $resultPageSet, $params['redirect']);
         $this->runQuery($resultPageSet);
     }
     if (is_null($resultPageSet)) {
         $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'page');
     }
 }
开发者ID:ui-libraries,项目名称:TIRW,代码行数:19,代码来源:ApiQueryRandom.php

示例12: pickFromDatabase

 /**
  * Select a random image from the database
  *
  * @return Title
  */
 protected function pickFromDatabase()
 {
     wfProfileIn(__METHOD__);
     $dbr = wfGetDB(DB_SLAVE);
     list($table, $conds, $opts) = $this->getExtraSelectOptions($dbr);
     $res = $dbr->select($table, array('page_namespace', 'page_title'), array('page_namespace' => NS_IMAGE, 'page_is_redirect' => 0, 'page_random > ' . $dbr->addQuotes(wfRandom())) + $conds, __METHOD__, array('ORDER BY' => 'page_random', 'LIMIT' => 1) + $opts);
     wfProfileOut(__METHOD__);
     if ($dbr->numRows($res) > 0) {
         $row = $dbr->fetchObject($res);
         $dbr->freeResult($res);
         return Title::makeTitleSafe($row->page_namespace, $row->page_title);
     }
     return null;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:19,代码来源:RandomImage.class.php

示例13: getRandomPollID

	/**
	 * Gets a random poll ID from the database.
	 * The poll ID will be the ID of a poll to which the user hasn't answered
	 * yet.
	 *
	 * @param $user_name Mixed: current user's username
	 * @return Integer: random poll ID number
	 */
	public function getRandomPollID( $user_name ) {
		$dbr = wfGetDB( DB_MASTER );
		$poll_page_id = 0;
		$use_index = $dbr->useIndexClause( 'poll_random' );
		$randstr = wfRandom();
		$sql = "SELECT poll_page_id FROM {$dbr->tableName( 'poll_question' )} {$use_index}
			INNER JOIN {$dbr->tableName( 'page' )} ON page_id=poll_page_id WHERE poll_id NOT IN
				(SELECT pv_poll_id FROM {$dbr->tableName( 'poll_user_vote' )} WHERE pv_user_name = '" . $dbr->strencode( $user_name ) . "')
				AND poll_status=1 AND poll_random>$randstr ORDER BY poll_random LIMIT 0,1";
		$res = $dbr->query( $sql, __METHOD__ );
		$row = $dbr->fetchObject( $res );
		// random fallback
		if( !$row ) {
			$sql = "SELECT poll_page_id FROM {$dbr->tableName( 'poll_question' )} {$use_index}
				INNER JOIN {$dbr->tableName( 'page' )} ON page_id=poll_page_id WHERE poll_id NOT IN
					(SELECT pv_poll_id FROM {$dbr->tableName( 'poll_user_vote' )} WHERE pv_user_name = '" . $dbr->strencode( $user_name ) . "')
					AND poll_status=1 AND poll_random<$randstr ORDER BY poll_random LIMIT 0,1";
			wfDebugLog( 'PollNY', $sql );
			$res = $dbr->query( $sql, __METHOD__ );
			$row = $dbr->fetchObject( $res );
		}
		if( $row ) {
			$poll_page_id = $row->poll_page_id;
		}

		return $poll_page_id;
	}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:35,代码来源:PollClass.php

示例14: wfGetSuggestedTitles

function wfGetSuggestedTitles($t)
{
    global $wgUser, $wgMemc;
    $html = "";
    if (!$t) {
        return $html;
    }
    // use memcached to store results
    $key = wfGetSuggTitlesMemcKey($t->getArticleID());
    $result = $wgMemc->get($key);
    if ($result) {
        return $result;
    }
    wfProfileIn(__METHOD__);
    $dbr = wfGetDB(DB_SLAVE);
    $group = date("W") % 5;
    $res = $dbr->select('suggested_links', array('sl_sugg'), array('sl_page' => $t->getArticleID()), array('ORDER BY' => 'sl_sort'), __METHOD__);
    $ids = array();
    while ($row = $dbr->fetchObject($res)) {
        $ids[] = $row->sl_sugg;
    }
    $randStr = wfRandom();
    if (sizeof($ids) == 0) {
        $top = wfGetTopCategory($t);
        if ($top) {
            $sql = "SELECT st_title FROM suggested_titles\n\t\t\t\tWHERE st_used = 0 and st_patrolled = 1 \n\t\t\t\t\tand st_group = {$group}\n\t\t\t\t\tand st_category = " . $dbr->addQuotes($top->getText()) . " \n\t\t\t\t\tand st_random > {$randStr} limit 5";
            $res = $dbr->query($sql, __METHOD__);
        }
    } else {
        $sql = "(" . implode(", ", $ids) . ")";
        $sql = "SELECT st_title FROM suggested_titles\n\t\t\tWHERE st_used = 0 and st_patrolled = 1 \n\t\t\t\tand st_group = {$group} and st_id\n\t\t\t\tin {$sql} limit 5";
        $res = $dbr->query($sql, __METHOD__);
    }
    if ($dbr->numRows($res) == 0) {
        $top = wfGetTopCategory($t);
        if ($top) {
            $sql = "SELECT st_title FROM suggested_titles\n\t\t\t\tWHERE st_used = 0 and st_patrolled = 1 \n\t\t\t\t\tand st_group = {$group}\n\t\t\t\t\tand st_category = " . $dbr->addQuotes($top->getText()) . "\n\t\t\t\t\tand st_random > {$randStr} limit 5";
            $res = $dbr->query($sql, __METHOD__);
        }
    }
    while ($row = $dbr->fetchObject($res)) {
        $title = Title::newFromText($row->st_title);
        if (!$title) {
            continue;
        }
        $sp = SpecialPage::getTitleFor('CreatePage', $title->getText());
        $html .= "<li><a onclick='clickshare(46);' href='{$sp->getLocalUrl()}' class='new'>" . wfMsg('howto', $title->getText()) . "</a></li>\n";
    }
    if ($html != "") {
        $html = "<h2>" . wfMsg('suggested_titles_section') . "</h2><div id='suggested_titles'>" . wfMsg('suggested_titles_section_description') . "<br/><br/><ul id='gatSuggestedTitle'>{$html}</ul></div>";
    }
    $wgMemc->set($key, $html);
    wfProfileOut(__METHOD__);
    return $html;
}
开发者ID:ErdemA,项目名称:wikihow,代码行数:55,代码来源:CreatePage.php

示例15: getSearchForm2

 /**
  * Generate search form version 2
  */
 public function getSearchForm2()
 {
     // Use button label fallbacks
     if (!$this->mButtonLabel) {
         $this->mButtonLabel = wfMessage('inputbox-tryexact')->text();
     }
     if ($this->mID !== '') {
         $unescapedID = $this->mID;
     } else {
         // The label element needs a unique id, use
         // random number to avoid multiple input boxes
         // having conflicts.
         $unescapedID = wfRandom();
     }
     $id = Sanitizer::escapeId($unescapedID, 'noninitial');
     $htmlLabel = '';
     if (isset($this->mLabelText) && strlen(trim($this->mLabelText))) {
         $this->mLabelText = $this->mParser->recursiveTagParse($this->mLabelText);
         $htmlLabel = Xml::openElement('label', array('for' => 'bodySearchInput' . $id));
         $htmlLabel .= $this->mLabelText;
         $htmlLabel .= Xml::closeElement('label');
     }
     $htmlOut = Xml::openElement('form', array('name' => 'bodySearch' . $id, 'id' => 'bodySearch' . $id, 'class' => 'bodySearch' . ($this->mInline ? ' mw-inputbox-inline' : ''), 'action' => SpecialPage::getTitleFor('Search')->getLocalUrl()));
     $htmlOut .= Xml::openElement('div', array('class' => 'bodySearchWrap' . ($this->mInline ? ' mw-inputbox-inline' : ''), 'style' => $this->bgColorStyle()));
     $htmlOut .= $htmlLabel;
     $htmlOut .= Xml::element('input', array('type' => $this->mHidden ? 'hidden' : 'text', 'name' => 'search', 'size' => $this->mWidth, 'id' => 'bodySearchInput' . $id, 'dir' => $this->mDir));
     $htmlOut .= Xml::element('input', array('type' => 'submit', 'name' => 'go', 'value' => $this->mButtonLabel, 'class' => 'bodySearchBtnGo'));
     // Better testing needed here!
     if (!empty($this->mFullTextButton)) {
         $htmlOut .= Xml::element('input', array('type' => 'submit', 'name' => 'fulltext', 'class' => 'bodySearchBtnSearch', 'value' => $this->mSearchButtonLabel));
     }
     $htmlOut .= Xml::closeElement('div');
     $htmlOut .= Xml::closeElement('form');
     // Return HTML
     return $htmlOut;
 }
开发者ID:whysasse,项目名称:kmwiki,代码行数:39,代码来源:InputBox.classes.php


注:本文中的wfRandom函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。