• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wfRandom函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: getRelatedArticlesBox

 function getRelatedArticlesBox($e, $isBoxShape = false)
 {
     global $wgTitle, $wgContLang, $wgRequest, $wgMemc;
     if (!$wgTitle || $wgTitle->getNamespace() != NS_MAIN || $wgTitle->getFullText() == wfMessage('mainpage')->text() || $wgRequest->getVal('action') != '') {
         return '';
     }
     $cachekey = wfMemcKey('relarticles_box', intval($isBoxShape), $wgTitle->getArticleID());
     $val = $wgMemc->get($cachekey);
     if ($val) {
         return $val;
     }
     $cats = Categoryhelper::getCurrentParentCategories();
     $cat = '';
     if (is_array($cats) && sizeof($cats) > 0) {
         $keys = array_keys($cats);
         $templates = wfMessage('categories_to_ignore')->inContentLanguage()->text();
         $templates = explode("\n", $templates);
         $templates = str_replace("http://www.wikihow.com/Category:", "", $templates);
         $templates = array_flip($templates);
         // make the array associative.
         for ($i = 0; $i < sizeof($keys); $i++) {
             $t = Title::newFromText($keys[$i]);
             if (isset($templates[urldecode($t->getPartialURL())])) {
                 continue;
             } else {
                 $cat = $t->getDBKey();
                 break;
             }
         }
     }
     // Populate related articles box with other articles in the category,
     // displaying the featured articles first
     $result = "";
     if (!empty($cat)) {
         $dbr = wfGetDB(DB_SLAVE);
         $num = intval(wfMessage('num_related_articles_to_display')->inContentLanguage()->text());
         $res = $dbr->select(array('categorylinks', 'page'), array('cl_from', 'page_is_featured, page_title'), array('cl_from = page_id', 'cl_to' => $cat, 'page_namespace' => 0, 'page_is_redirect' => 0, '(page_is_featured = 1 OR page_random > ' . wfRandom() . ')'), __METHOD__, array('ORDER BY' => 'page_is_featured DESC'));
         if ($isBoxShape) {
             $result .= '<div class="related_square_row">';
         }
         $count = 0;
         foreach ($res as $row) {
             if ($count >= $num) {
                 break;
             }
             if ($row->cl_from == $wgTitle->getArticleID()) {
                 continue;
             }
             $t = Title::newFromDBkey($row->page_title);
             if (!$t || $this->needsFurtherEditing($t)) {
                 continue;
             }
             if ($isBoxShape) {
                 //exit if there's a word that will be too long
                 $word_array = explode(' ', $t->getText());
                 foreach ($word_array as $word) {
                     if (strlen($word) > 7) {
                         continue;
                     }
                 }
                 $data = self::featuredArticlesAttrs($t, $t->getFullText(), 200, 162);
                 $result .= $this->relatedArticlesBox($data, $num_cols);
                 if ($count == 1) {
                     $result .= '</div><div class="related_square_row">';
                 }
             } else {
                 //$data = self::featuredArticlesAttrs($t, $t->getFullText());
                 $result .= self::getArticleThumb($t, 127, 140);
             }
             $count++;
         }
         if ($isBoxShape) {
             $result .= '</div>';
         }
         if (!empty($result)) {
             if ($isBoxShape) {
                 $result = "<div id='related_squares'>{$result}\n</div>";
             } else {
                 $result = "<h3>" . wfMessage('relatedarticles')->text() . "</h3>{$result}<div class='clearall'></div>\n";
             }
         }
     }
     $wgMemc->set($cachekey, $result);
     return $result;
 }
开发者ID:biribogos,项目名称:wikihow-src,代码行数:85,代码来源:WikiHowSkin.php


示例17: buildSQL

 function buildSQL()
 {
     global $wgUser;
     $dbr =& wfGetDB(DB_SLAVE);
     $sPageTable = $dbr->tableName('page');
     $categorylinks = $dbr->tableName('categorylinks');
     $sSqlSelectFrom = "SELECT distinct(page_id),page_namespace,page_title, page_counter,UNIX_TIMESTAMP(page_touched),page_id, IFNULL(comment_count,0) as comment_count, IFNULL(vote_count,0) as vote_count,  IFNULL(vote_avg,0) as vote_avg ";
     if ($this->Order == 'EDITS') {
         $sSqlSelectFrom .= ",(select count(*) from {$dbr->tableName('revision')} where page_id=rev_page ";
         $sSqlSelectFrom .= ") as Num_Edits ";
     }
     if ($this->ShowUser == 1) {
         $WhereVote = " and username = '" . $wgUser->mName . "' ";
         $WhereComment = " and Comment_Username = '" . $wgUser->mName . "' ";
     }
     if ($this->Order == 'VOTEDON') {
         $sSqlSelectFrom .= " ,(select vote_date from Vote WHERE vote_page_id = page_id " . $WhereVote . " order BY vote_date DESC limit 1) as LastDate ";
     }
     if ($this->Order == 'COMMENTEDON') {
         $sSqlSelectFrom .= " ,(select Comment_date from Comments WHERE Comment_page_id = page_id " . $WhereComment . " order BY Comment_date DESC limit 1) as LastDate ";
     }
     $sSqlSelectFrom .= "FROM {$sPageTable}";
     if ($this->ShowPublished == 1) {
         $sSqlSelectFrom .= " INNER JOIN published_page  ";
         $sSqlSelectFrom .= " ON page_id = published_page_id  ";
     }
     if (count($this->Categories) > 0) {
         $sSqlSelectFrom .= " INNER JOIN {$categorylinks} AS c";
         $sSqlSelectFrom .= ' ON page_id = c.cl_from';
     }
     if ($this->ShowPublished == -1) {
         $sSqlSelectFrom .= " LEFT JOIN published_page ";
         $sSqlSelectFrom .= ' ON page_id = published_page_id and published_type= ' . $this->Level . ' ';
     }
     $sSqlSelectFrom .= ' LEFT JOIN page_stats ON page_id=ps_page_id ';
     //BUILD WHERE CLAUSE
     $sSqlWhere = " WHERE 1=1";
     $sCtgSQL = "";
     if (count($this->Categories) > 0) {
         $sSqlWhere .= ' AND UPPER(c.cl_to) in (';
         for ($i = 0; $i < count($this->Categories); $i++) {
             if ($i > 0) {
                 $sCtgSQL .= ",";
             }
             $sCtgSQL .= strtoupper($dbr->addQuotes($this->Categories[$i]->getDbKey()));
         }
         $sSqlWhere .= $sCtgSQL . ')';
     }
     if ($this->ShowPublished == 1) {
         $sSqlWhere .= " AND published_type=" . $this->Level . " ";
     }
     if ($this->ShowPublished == -1) {
         $sSqlWhere .= " AND ( published_page_id IS NULL  ) ";
     }
     if ($this->random == 1) {
         $randstr = wfRandom();
         $sSqlWhere .= " AND page_random>{$randstr} ";
     }
     if ($this->ratingMin > 0) {
         $sSqlWhere .= " AND vote_count >= " . $this->ratingMin;
     }
     // Only Show Main Pages in lists
     $sSqlWhere .= " AND page_namespace in ( " . NS_MAIN . "," . NS_USER . "," . NS_IMAGE . ")";
     // BUILD ORDER BY CLAUSE
     $sSqlOrder = " ORDER BY ";
     if ($this->Order == 'LASTEDIT') {
         $sSqlOrder .= 'page_touched ';
     } else {
         if ($this->Order == 'PAGEVIEWS') {
             $sSqlOrder .= 'page_counter ';
         } else {
             if ($this->Order == 'VOTES') {
                 $sSqlOrder .= 'vote_count ';
             } else {
                 if ($this->Order == 'VOTE AVERAGE') {
                     $sSqlOrder .= 'vote_avg ';
                 } else {
                     if ($this->Order == 'COMMENTS') {
                         $sSqlOrder .= 'comment_count ';
                     } else {
                         if ($this->Order == 'NEW') {
                             $sSqlOrder .= 'page_id ';
                         } else {
                             if ($this->Order == 'EDITS') {
                                 $sSqlOrder .= 'Num_Edits ';
                             } else {
                                 if ($this->Order == 'PUBLISHEDDATE' && $this->ShowPublished == 1) {
                                     $sSqlOrder .= 'published_date ';
                                 } else {
                                     if ($this->Order == 'VOTEDON' || $this->Order == 'COMMENTEDON') {
                                         $sSqlOrder .= 'LastDate ';
                                     } else {
                                         if ($this->random == 1) {
                                             $sSqlOrder .= ' page_random ';
                                             $this->SortBy = 'ASCENDING';
                                         } else {
                                             $sSqlOrder .= 'page_title ';
                                         }
                                     }
                                 }
//.........这里部分代码省略.........
开发者ID:schwarer2006,项目名称:wikia,代码行数:101,代码来源:ListPagesClass.php


示例18: moveToNewTitle

 /**
  * Move page to non-existing title.
  * @param Title &$nt the new Title
  * @private
  */
 function moveToNewTitle(&$nt, $reason = '')
 {
     global $wgUseSquid;
     $fname = 'MovePageForm::moveToNewTitle';
     $comment = wfMsgForContent('1movedto2', $this->getPrefixedText(), $nt->getPrefixedText());
     if ($reason) {
         $comment .= ": {$reason}";
     }
     $newid = $nt->getArticleID();
     $oldid = $this->getArticleID();
     $dbw =& wfGetDB(DB_MASTER);
     $now = $dbw->timestamp();
     $rand = wfRandom();
     $linkCache =& LinkCache::singleton();
     # Save a null revision in the page's history notifying of the move
     $nullRevision = Revision::newNullRevision($dbw, $oldid, $comment, true);
     $nullRevId = $nullRevision->insertOn($dbw);
     # Rename cur entry
     $dbw->update('page', array('page_touched' => $now, 'page_namespace' => $nt->getNamespace(), 'page_title' => $nt->getDBkey(), 'page_latest' => $nullRevId), array('page_id' => $oldid), $fname);
     $linkCache->clearLink($nt->getPrefixedDBkey());
     # Insert redirect
     $mwRedir = MagicWord::get(MAG_REDIRECT);
     $redirectText = $mwRedir->getSynonym(0) . ' [[' . $nt->getPrefixedText() . "]]\n";
     $redirectArticle = new Article($this);
     $newid = $redirectArticle->insertOn($dbw);
     $redirectRevision = new Revision(array('page' => $newid, 'comment' => $comment, 'text' => $redirectText));
     $revid = $redirectRevision->insertOn($dbw);
     $redirectArticle->updateRevisionOn($dbw, $redirectRevision, 0);
     $linkCache->clearLink($this->getPrefixedDBkey());
     # Log the move
     $log = new LogPage('move');
     $log->addEntry('move', $this, $reason, array(1 => $nt->getPrefixedText()));
     # Purge caches as per article creation
     Article::onArticleCreate($nt);
     # Record the just-created redirect's linking to the page
     $dbw->insert('pagelinks', array('pl_from' => $newid, 'pl_namespace' => $nt->getNamespace(), 'pl_title' => $nt->getDBkey()), $fname);
     # Purge old title from squid
     # The new title, and links to the new title, are purged in Article::onArticleCreate()
     $this->purgeSquid();
 }
开发者ID:k-hasan-19,项目名称:wiki,代码行数:45,代码来源:Title.php


示例19: createQuizGame

	function createQuizGame() {
		global $wgRequest, $wgUser, $wgMemc, $wgQuizLogs;

		$key = $wgRequest->getText( 'key' );
		$chain = $wgRequest->getText( 'chain' );

		$max_answers = 8;

		if( $key != md5( $this->SALT . $chain ) ) {
			header( 'Location: ' . $this->getTitle()->getFullURL() );
			return;
		}

		$question = $wgRequest->getText( 'quizgame-question' );
		$imageName = $wgRequest->getText( 'quizGamePictureName' );

		// Add quiz question
		$dbw = wfGetDB( DB_MASTER );
		$dbw->insert(
			'quizgame_questions',
			array(
				'q_user_id' => $wgUser->getID(),
				'q_user_name' => $wgUser->getName(),
				'q_text' => strip_tags( $question ), // make sure nobody inserts malicious code
				'q_picture' => $imageName,
				'q_date' => date( 'Y-m-d H:i:s' ),
				'q_random' => wfRandom()
			),
			__METHOD__
		);
		$questionId = $dbw->insertId();

		// Add Quiz Choices
		for( $x = 1; $x <= $max_answers; $x++ ) {
			if( $wgRequest->getVal( "quizgame-answer-{$x}" ) ) {
				if( $wgRequest->getVal( "quizgame-isright-{$x}" ) == 'on' ) {
					$is_correct = 1;
				} else {
					$is_correct = 0;
				}
				$dbw->insert(
					'quizgame_choice',
					array(
						'choice_q_id' => $questionId,
						'choice_text' => strip_tags( $wgRequest->getVal( "quizgame-answer-{$x}" ) ), // make sure nobody inserts malicious code
						'choice_order' => $x,
						'choice_is_correct' => $is_correct
					),
					__METHOD__
				);
				$dbw->commit();
			}
		}
		$stats = new UserStatsTrack( $wgUser->getID(), $wgUser->getName() );
		$stats->incStatField( 'quiz_created' );

		// Add a log entry if quiz logging is enabled
		if( $wgQuizLogs ) {
			$message = wfMsgForContent(
				'quiz-questions-log-create-text',
				"Special:QuizGameHome/{$questionId}"
			);
			$log = new LogPage( 'quiz' );
			$log->addEntry( 'create', $wgUser->getUserPage(), $message );
		}

		// Delete memcached key
		$key = wfMemcKey( 'user', 'profile', 'quiz', $wgUser->getID() );
		$wgMemc->delete( $key );

		// Redirect the user
		header( 'Location: ' . $this->getTitle()->getFullURL( "questionGameAction=renderPermalink&permalinkID={$questionId}" ) );
	}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:73,代码来源:QuestionGameHome.body.php


示例20: run

 /**
  * @param ApiPageSet|null $resultPageSet
  */
 public function run($resultPageSet = null)
 {
     $params = $this->extractRequestParams();
     // Since 'filterredir" will always be set in $params, we have to dig
     // into the WebRequest to see if it was actually passed.
     $request = $this->getMain()->getRequest();
     if ($request->getCheck($this->encodeParamName('filterredir'))) {
         $this->requireMaxOneParameter($params, 'filterredir', 'redirect');
     }
     if (isset($params['continue'])) {
         $cont = explode('|', $params['continue']);
         $this->dieContinueUsageIf(count($cont) != 4);
         $rand = $cont[0];
         $start = $cont[1];
         $startId = (int) $cont[2];
         $end = $cont[3] ? $rand : null;
         $this->dieContinueUsageIf(!preg_match('/^0\\.\\d+$/', $rand));
         $this->dieContinueUsageIf(!preg_match('/^0\\.\\d+$/', $start));
         $this->dieContinueUsageIf($cont[2] !== (string) $startId);
         $this->dieContinueUsageIf($cont[3] !== '0' && $cont[3] !== '1');
     } else {
         $rand = wfRandom();
         $start = $rand;
         $startId = null;
         $end = null;
     }
     list($left, $continue) = $this->runQuery($resultPageSet, $params['limit'], $start, $startId, $end);
     if ($end === null && $continue === null) {
         // Wrap around. We do this even if $left === 0 for continuation
         // (saving a DB query in this rare case probably isn't worth the
         // added code complexity it would require).
         $end = $rand;
         list($left, $continue) = $this->runQuery($resultPageSet, $left, null, null, $end);
     }
     if ($continue !== null) {
         $endFlag = $end === null ? 0 : 1;
         $this->setContinueEnumParameter('continue', "{$rand}|{$continue}|{$endFlag}");
     }
     if (is_null($resultPageSet)) {
         $this->getResult()->addIndexedTagName(array('query', $this->getModuleName()), 'page');
     }
 }
                      

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wfRandomString函数代码示例发布时间:2022-05-23
下一篇:
PHP wfProfileOut函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap