Exemplo n.º 1
0
 public function execute($subPage)
 {
     global $wgRequest, $wgUser;
     $zip = (int) $wgRequest->getVal('zip');
     $out = $this->getOutput();
     $this->setHeaders();
     $this->outputHeader();
     if ($wgRequest->getVal('store')) {
         $dbw = wfGetDb(DB_MASTER);
         $res = $dbw->insert('cl_errors', array('cle_zip' => $zip, 'cle_comment' => $wgRequest->getVal('comment')), __METHOD__, array());
         $out->addHtml('Thank you!');
     } else {
         $out->addHtml('<form method=post action="/wiki/Special:CongressFail">');
         $out->addHtml('<div>');
         $out->addHtml('<div>');
         if ($zip != 0) {
             $out->addHtml('ZIP Code (will be recorded): ' . $zip);
             $out->addHtml('<input type=hidden name=zip value=' . $zip . '>');
         } else {
             $out->addHtml('ZIP code: <input name=zip>');
         }
         $out->addHtml('</div>');
         $out->addHtml('Tell us what went wrong: <input type=text size=100 name=comment maxlength=255>');
         $out->addHtml('</div>');
         $out->addHtml('<div>');
         $out->addHtml('<input type=submit name=store value="Send Error Report">');
         $out->addHtml('</div>');
         $out->addHtml('</form>');
     }
 }
Exemplo n.º 2
0
 public function execute()
 {
     $dbw = wfGetDb(DB_MASTER);
     // Determining what groups the account was in before the change
     // would be difficult and unnecessary 99.9% of the time, so we just
     // assume the account was in no other groups
     $params = array('grant' => "\nbot", 'revoke' => "bot\n");
     $logrows = $dbw->select('logging', array('log_id', 'log_action'), array('log_type' => 'makebot', 'log_action' => array('grant', 'revoke')), __METHOD__);
     $count = $logrows->numRows();
     $this->output("Updating {$count} entries in the logging table\n");
     $batch = 0;
     foreach ($logrows as $row) {
         $dbw->update('logging', array('log_action' => 'rights', 'log_type' => 'rights', 'log_params' => $params[$row->log_action]), array('log_id' => $row->log_id), __METHOD__);
         $batch++;
         if ($batch == 100) {
             wfWaitForSlaves(5);
             $batch = 0;
         }
     }
     $rcrows = $dbw->select('recentchanges', array('rc_id', 'rc_log_action'), array('rc_log_type' => 'makebot', 'rc_log_action' => array('grant', 'revoke')), __METHOD__);
     $count = $rcrows->numRows();
     $this->output("Updating {$count} entries in the recentchanges table\n");
     foreach ($rcrows as $row) {
         $dbw->update('recentchanges', array('rc_log_action' => 'rights', 'rc_log_type' => 'rights', 'rc_params' => $params[$row->rc_log_action]), array('rc_id' => $row->rc_id), __METHOD__);
     }
     $this->output("Done!\n");
 }
Exemplo n.º 3
0
 /**
  * Extracts the title, token, and reason from the request parameters and invokes
  * the local delete() function with these as arguments. It does not make use of 
  * the delete function specified by Article.php. If the deletion succeeds, the 
  * details of the article deleted and the reason for deletion are added to the 
  * result object.
  */
 public function execute()
 {
     global $wgUser;
     $this->getMain()->requestWriteMode();
     $params = $this->extractRequestParams();
     $titleObj = NULL;
     if (!isset($params['title'])) {
         $this->dieUsageMsg(array('missingparam', 'title'));
     }
     if (!isset($params['token'])) {
         $this->dieUsageMsg(array('missingparam', 'token'));
     }
     $titleObj = Title::newFromText($params['title']);
     if (!$titleObj) {
         $this->dieUsageMsg(array('invalidtitle', $params['title']));
     }
     if (!$titleObj->exists()) {
         $this->dieUsageMsg(array('notanarticle'));
     }
     $articleObj = new Article($titleObj);
     $reason = isset($params['reason']) ? $params['reason'] : NULL;
     $dbw = wfGetDb(DB_MASTER);
     $dbw->begin();
     $retval = self::delete($articleObj, $params['token'], $reason);
     if (!empty($retval)) {
         // We don't care about multiple errors, just report one of them
         $this->dieUsageMsg(current($retval));
     }
     $dbw->commit();
     $r = array('title' => $titleObj->getPrefixedText(), 'reason' => $reason);
     $this->getResult()->addValue(null, $this->getModuleName(), $r);
 }
Exemplo n.º 4
0
 function send($recipients, $headers, $body)
 {
     $this->_sanitizeHeaders($headers);
     list($from, $textHeaders) = $this->prepareHeaders($headers);
     $priority = 0;
     if (isset($headers['X-Priority'])) {
         $priority = $headers['X-Priority'];
     }
     $category = '';
     if (isset($headers['X-Msg-Category'])) {
         $category = $headers['X-Msg-Category'];
     }
     global $wgCityId, $wgWikiaMailerDB;
     $wgCityId = $wgCityId == null ? 0 : $wgCityId;
     // fake city-id for contractor/staff.
     // FB:4431 Write mail to archive database now
     $dbw = wfGetDb(DB_MASTER, array(), $wgWikiaMailerDB);
     $dbw->begin(__METHOD__);
     foreach ($recipients as $recipient) {
         // TODO: SHOULD WE FILTER BASED ON BLOCKS / SPAMS HERE?  FOR NOW WE WILL LET SENDGRID HANDLE THAT.
         $dbw->insert(self::$MAIL_TABLE_NAME, array('src' => $from, 'subj' => $headers['Subject'], 'dst' => $recipient, 'hdr' => $textHeaders, 'msg' => $body, 'city_id' => $wgCityId, 'priority' => $priority, 'category' => $category), __METHOD__);
         // Add postback token so that we can verify that any postback actually comes from SendGrid.
         $emailId = $dbw->insertId();
         $postbackToken = wfGetEmailPostbackToken($emailId, $recipient);
         $textHeaders .= $this->sep . "X-CallbackToken: " . $postbackToken;
         $dbw->update(self::$MAIL_TABLE_NAME, array('hdr' => $textHeaders), array('id' => $emailId), __METHOD__);
         wfDebugLog("enotif", __METHOD__ . ": email added to database with data: {$recipient} {$from} {$headers['Subject']}", true);
     }
     $dbw->commit(__METHOD__);
 }
Exemplo n.º 5
0
 public function execute()
 {
     $params = $this->extractRequestParams();
     $dbw = wfGetDb(DB_MASTER);
     $dbw->insert('cl_errors', array('cle_zip' => $params['zip'], 'cc_comment' => $params['comment']), __METHOD__, array());
     $this->getResult()->addValue(null, $this->getModuleName(), 'OK');
 }
 /**
  * Constructor
  *
  * @var $resourceType String The calling application or type of resource, conceptually like a namespace
  * @var $user User object, the current user
  * @var $expirationTime Integer (optional) How long should a checkout last, in seconds
  */
 public function __construct($resourceType, $user, $expirationTime = null)
 {
     // All database calls are to the master, since the whole point of this class is maintaining
     // concurrency. Most reads should come from cache anyway.
     $this->dbw = wfGetDb(DB_MASTER);
     $this->user = $user;
     // TODO: create a registry of all valid resourceTypes that client app can add to.
     $this->resourceType = $resourceType;
     $this->setExpirationTime($expirationTime);
 }
Exemplo n.º 7
0
function getWikiArticles()
{
    $searchpages = array("'Spam-blacklist'", "'Spam-whitelist'", "'Spam_blacklist'", "'Spam_whitelist'", "'External_links_whitelist'");
    $db = wfGetDb(DB_SLAVE);
    $res = $db->select(array('page'), array('page_id', 'page_title'), array('page_namespace	= 8', 'page_title in (' . implode(',', $searchpages) . ')'), 'count_average_title', array('ORDER BY' => 'page_id DESC'));
    $articles = array();
    while ($article = $res->fetchObject()) {
        $articles[$article->page_id] = $article->page_title;
    }
    return $articles;
}
 /**
  * Creates and returns a new SWLChangeSet instance from a database result
  * obtained by doing a select on swl_sets. 
  * 
  * @since 0.1
  * 
  * @param $set
  * 
  * @return SWLChangeSet
  */
 public static function newFromDBResult($set)
 {
     $changeSet = new SWLChangeSet(SMWDIWikiPage::newFromTitle(Title::newFromID($set->edit_page_id)), null, null, null, $set->spe_set_id, new SWLEdit($set->edit_page_id, $set->edit_user_name, $set->edit_time, $set->edit_id));
     $dbr = wfGetDb(DB_SLAVE);
     $changes = $dbr->select('swl_changes', array('change_id', 'change_property', 'change_old_value', 'change_new_value'), array('change_set_id' => $set->spe_set_id));
     foreach ($changes as $change) {
         $property = SMWDIProperty::doUnserialize($change->change_property, '__pro');
         $changeSet->addChange($property, SWLPropertyChange::newFromSerialization($property, $change->change_old_value, $change->change_new_value));
     }
     return $changeSet;
 }
Exemplo n.º 9
0
 public function __construct($options)
 {
     // load command line options
     $this->options = $options;
     global $wgDBname;
     $this->force = isset($options['force']);
     $this->quick = isset($options['quick']);
     $this->databaseName = isset($options['database']) ? $options['database'] : $wgDBname;
     $this->db = wfGetDb(DB_SLAVE, array(), $this->databaseName);
     $this->walker = new DatabaseWalker_UsingShow($this->db);
     $this->script = new SqlScript();
 }
 /**
  * Displays some shorts statistics about the dictionary page.
  *
  * @since 0.4
  *
  * @param Article $article
  * @param Title $title
  */
 protected static function displayDictionaryPage(Article &$article, Title $title)
 {
     global $wgOut, $wgLang, $wgUser, $egLiveTranslateLanguages;
     $dbr = wfGetDb(DB_SLAVE);
     $res = $dbr->select('live_translate_memories', array('memory_lang_count', 'memory_tu_count'), array('memory_location' => $title->getFullText()), array('LIMIT' => 1));
     foreach ($res as $tm) {
         break;
     }
     if ($tm->memory_tu_count == 0) {
         $wgOut->addWikiMsg('livetranslate-dictionary-empty');
     } else {
         $wgOut->addWikiMsg('livetranslate-dictionary-count', $wgLang->formatNum($tm->memory_tu_count), $wgLang->formatNum($tm->memory_lang_count));
         /*
         $notAllowedLanguages = array();
         
         foreach ( $tus[0]->getVariants() as $languageCode => $translations ) {
         	$languageCode = strtolower( $languageCode );
         	$mappings = LiveTranslateFunctions::getInputLangMapping();
         
         	if ( array_key_exists( $languageCode, $mappings ) ) {
         		$languageCode = $mappings[$languageCode];
         	}
         
         	if ( !in_array( $languageCode, $egLiveTranslateLanguages ) ) {
         		$notAllowedLanguages[] = $languageCode;
         	}
         }
         
         if ( count( $notAllowedLanguages ) > 0 ) {
         	$languages = Language::getLanguageNames( false );
         
         	foreach ( $notAllowedLanguages as &$notAllowedLang ) {
         		if ( array_key_exists( $notAllowedLang, $languages ) ) {
         			$notAllowedLang = $languages[$notAllowedLang];
         		}
         	}
         
         	$wgOut->addHTML(
         		Html::element(
         			'span',
         			array( 'style' => 'color:darkred' ),
         			wfMsgExt( 'livetranslate-dictionary-unallowed-langs', 'parsemag', $wgLang->listToText( $notAllowedLanguages ), count( $notAllowedLanguages ) )
         		)
         	);
         }
         */
     }
     if ($wgUser->isAllowed('managetms')) {
         $wgOut->addHTML(Html::element('a', array('href' => Title::newFromText('Special:LiveTranslate')->getInternalURL()), wfMsg('livetranslate-dictionary-goto-edit')));
     }
 }
Exemplo n.º 11
0
 public function __construct($title)
 {
     global $wgUser;
     $this->title = $title;
     $this->dbr =& wfGetDb(DB_SLAVE);
     $this->skin = $wgUser->getSkin();
     $this->families = array();
     $this->numSpouseFamilies = 0;
     $this->selfTag = '';
     $this->spouseTag = '';
     $this->stdPlaces = null;
     $this->prevLastFamilyEndpoint = null;
     $this->loadPedigree();
 }
Exemplo n.º 12
0
 public function execute()
 {
     global $wgUser;
     $this->getMain()->requestWriteMode();
     $params = $this->extractRequestParams();
     $titleObj = NULL;
     if (!isset($params['title'])) {
         $this->dieUsageMsg(array('missingparam', 'title'));
     }
     if (!isset($params['token'])) {
         $this->dieUsageMsg(array('missingparam', 'token'));
     }
     if (!$wgUser->isAllowed('undelete')) {
         $this->dieUsageMsg(array('permdenied-undelete'));
     }
     if ($wgUser->isBlocked()) {
         $this->dieUsageMsg(array('blockedtext'));
     }
     if (wfReadOnly()) {
         $this->dieUsageMsg(array('readonlytext'));
     }
     if (!$wgUser->matchEditToken($params['token'])) {
         $this->dieUsageMsg(array('sessionfailure'));
     }
     $titleObj = Title::newFromText($params['title']);
     if (!$titleObj) {
         $this->dieUsageMsg(array('invalidtitle', $params['title']));
     }
     // Convert timestamps
     if (!is_array($params['timestamps'])) {
         $params['timestamps'] = array($params['timestamps']);
     }
     foreach ($params['timestamps'] as $i => $ts) {
         $params['timestamps'][$i] = wfTimestamp(TS_MW, $ts);
     }
     $pa = new PageArchive($titleObj);
     $dbw = wfGetDb(DB_MASTER);
     $dbw->begin();
     $retval = $pa->undelete(isset($params['timestamps']) ? $params['timestamps'] : array(), $params['reason']);
     if (!is_array($retval)) {
         $this->dieUsageMsg(array('cannotundelete'));
     }
     $dbw->commit();
     $info['title'] = $titleObj->getPrefixedText();
     $info['revisions'] = $retval[0];
     $info['fileversions'] = $retval[1];
     $info['reason'] = $retval[2];
     $this->getResult()->addValue(null, $this->getModuleName(), $info);
 }
 public function execute()
 {
     $start = intval($this->getOption('start', 0));
     $maxlag = intval($this->getOption('maxlag', 5));
     $dbr = wfGetDb(DB_SLAVE);
     $maxUserID = $dbr->selectField('user', 'MAX(user_id)', false);
     $this->output("Starting from user_id {$start} of {$maxUserID}\n");
     for ($i = $start; $i < $maxUserID; $i++) {
         $this->fixUser($i);
         if ($i % self::REPORTING_INTERVAL == 0) {
             $this->output("{$i}\n");
             wfWaitForSlaves($maxlag);
         }
     }
     $this->output("All done\n");
 }
Exemplo n.º 14
0
 public function execute()
 {
     if (!$this->hasArg()) {
         $this->error("No query specified. Specify the query as a command line parameter.", true);
     }
     $query = $this->getArg();
     $wait = $this->getOption('wait', 5);
     $n = 1;
     $dbw = wfGetDb(DB_MASTER);
     do {
         $this->output("Batch {$n}: ");
         $n++;
         $dbw->query($query, __METHOD__);
         $affected = $dbw->affectedRows();
         $this->output("{$affected} rows\n");
         wfWaitForSlaves($wait);
     } while ($affected > 0);
 }
Exemplo n.º 15
0
 public function __construct($options)
 {
     // load command line options
     $this->options = $options;
     global $wgDBname;
     //		$this->force = isset($options['force']);
     //		$this->quick = isset($options['quick']);
     $this->short = isset($options['short']);
     $this->verbose = isset($options['verbose']);
     $this->databaseName = isset($options['database']) ? $options['database'] : $wgDBname;
     $this->clusterName = isset($options['cluster']) ? $options['cluster'] : $this->databaseName;
     $this->db = wfGetDb(DB_SLAVE, array(), $this->clusterName);
     if (!$this->db->selectDB($this->databaseName)) {
         $this->db = false;
     }
     $this->walker = new DatabaseWalker_UsingShow($this->db);
     $this->script = new SqlScript();
 }
Exemplo n.º 16
0
function EditOwn($title, $user, $action, &$result)
{
    static $cache = array();
    global $wgEditOwnExcludedNamespaces, $wgEditOwnActions;
    if (!is_array($wgEditOwnExcludedNamespaces)) {
        // Prevent PHP from whining
        $wgEditOwnExcludedNamespaces = array();
    }
    if (!in_array($action, $wgEditOwnActions) || $user->isAllowed('editall') || in_array($title->getNamespace(), $wgEditOwnExcludedNamespaces)) {
        $result = null;
        return true;
    }
    if (isset($cache[$user->getName()][$title->getArticleId()])) {
        $result = $cache[$user->getName()][$title->getArticleId()];
        return is_null($result);
    }
    if (!$title->exists()) {
        // Creation is allowed
        $cache[$user->getName()][$title->getArticleId()] = null;
        $result = null;
        return true;
    }
    // Since there's no easy way to get the first revision,
    // we'll just do a DB query
    $dbr = wfGetDb(DB_SLAVE);
    $res = $dbr->select('revision', Revision::selectFields(), array('rev_page' => $title->getArticleId()), __METHOD__, array('ORDER BY' => 'rev_timestamp', 'LIMIT' => 1));
    $row = $dbr->fetchObject($res);
    if (!$row) {
        // Title with no revs, weird... allow creation
        $cache[$user->getName()][$title->getArticleId()] = null;
        $result = null;
        return true;
    }
    $rev = new Revision($row);
    if ($user->getName() == $rev->getRawUserText()) {
        $cache[$user->getName()][$title->getArticleId()] = null;
        $result = null;
        return true;
    }
    $cache[$user->getName()][$title->getArticleId()] = false;
    $result = false;
    return false;
}
 private function getPagesFrom($source)
 {
     $dbr = wfGetDb(DB_SLAVE);
     $className = "{$source}Page";
     if (!class_exists($className)) {
         return array();
     }
     $queryPage = new $className();
     $sql = $dbr->limitResult($queryPage->getSQL(), self::LIMIT, 0);
     $res = $dbr->query($sql, __METHOD__ . "::{$source}");
     $pages = array();
     foreach ($res as $row) {
         $title = Title::newFromText($row->title, $row->namespace);
         if ($title instanceof Title && $title->getNamespace() == NS_MAIN) {
             $pages[] = $title->getText();
         }
     }
     return $pages;
 }
Exemplo n.º 18
0
 /**
  * Unblocks the specified user or provides the reason the unblock failed.
  */
 public function execute()
 {
     global $wgUser;
     $this->getMain()->requestWriteMode();
     $params = $this->extractRequestParams();
     if ($params['gettoken']) {
         $res['unblocktoken'] = $wgUser->editToken();
         $this->getResult()->addValue(null, $this->getModuleName(), $res);
         return;
     }
     if (is_null($params['id']) && is_null($params['user'])) {
         $this->dieUsageMsg(array('unblock-notarget'));
     }
     if (!is_null($params['id']) && !is_null($params['user'])) {
         $this->dieUsageMsg(array('unblock-idanduser'));
     }
     if (is_null($params['token'])) {
         $this->dieUsageMsg(array('missingparam', 'token'));
     }
     if (!$wgUser->matchEditToken($params['token'])) {
         $this->dieUsageMsg(array('sessionfailure'));
     }
     if (!$wgUser->isAllowed('block')) {
         $this->dieUsageMsg(array('cantunblock'));
     }
     if (wfReadOnly()) {
         $this->dieUsageMsg(array('readonlytext'));
     }
     $id = $params['id'];
     $user = $params['user'];
     $reason = is_null($params['reason']) ? '' : $params['reason'];
     $dbw = wfGetDb(DB_MASTER);
     $dbw->begin();
     $retval = IPUnblockForm::doUnblock($id, $user, $reason, $range);
     if (!empty($retval)) {
         $this->dieUsageMsg($retval);
     }
     $dbw->commit();
     $res['id'] = $id;
     $res['user'] = $user;
     $res['reason'] = $reason;
     $this->getResult()->addValue(null, $this->getModuleName(), $res);
 }
	/**
	 * Save a survey to the database
	 * @param $name string Survey name
	 * @param $survey array Survey configuration data
	 */
	public static function save( $name, $survey ) {
		global $wgRequest, $wgUser;
		$dbw = wfGetDb( DB_MASTER );
		$now = $dbw->timestamp();
		/*$cookieID = $wgRequest->getCookie( "vitals-survey" );
		if ( $cookieID == null ) {
			$cookieID = self::generateRandomCookieID();
			$wgRequest->response()->setcookie( "vitals-survey", $cookieID );
		}*/

		foreach ( $survey['questions'] as $question => $config ) {
			$dbw->insert(
				'prefswitch_survey',
				array_merge(
					array(
						'pss_user' => $wgUser->getId(),
						'pss_user_text' => $wgUser->getName(),
						'pss_timestamp' => $now,
						'pss_name' => $name,
						'pss_question' => $question,
					),
					call_user_func( array( self::$fieldTypes[$config['type']], 'save' ), $question, $wgRequest )
				),
				__METHOD__
			);
		}

		// pseudoquestion, logged in? IP address?
		$dbw->insert(
				'prefswitch_survey',
				array(
					'pss_user' => $wgUser->getId(),
					'pss_user_text' => $wgUser->getName(),
					'pss_timestamp' => $now,
					'pss_name' => $name,
					'pss_question' => "logged_in",
					'pss_answer' => $wgUser->isLoggedIn() ? "yes" : "no",
					'pss_answer_data' => wfGetIP(),
				),
				__METHOD__
			);
	}
Exemplo n.º 20
0
 public function execute()
 {
     global $wgUser;
     $this->getMain()->requestWriteMode();
     $params = $this->extractRequestParams();
     $titleObj = NULL;
     if (!isset($params['title'])) {
         $this->dieUsageMsg(array('missingparam', 'title'));
     }
     if (!isset($params['user'])) {
         $this->dieUsageMsg(array('missingparam', 'user'));
     }
     if (!isset($params['token'])) {
         $this->dieUsageMsg(array('missingparam', 'token'));
     }
     $titleObj = Title::newFromText($params['title']);
     if (!$titleObj) {
         $this->dieUsageMsg(array('invalidtitle', $params['title']));
     }
     if (!$titleObj->exists()) {
         $this->dieUsageMsg(array('notanarticle'));
     }
     $username = User::getCanonicalName($params['user']);
     if (!$username) {
         $this->dieUsageMsg(array('invaliduser', $params['user']));
     }
     $articleObj = new Article($titleObj);
     $summary = isset($params['summary']) ? $params['summary'] : "";
     $details = null;
     $dbw = wfGetDb(DB_MASTER);
     $dbw->begin();
     $retval = $articleObj->doRollback($username, $summary, $params['token'], $params['markbot'], $details);
     if (!empty($retval)) {
         // We don't care about multiple errors, just report one of them
         $this->dieUsageMsg(current($retval));
     }
     $dbw->commit();
     $current = $target = $summary = NULL;
     extract($details);
     $info = array('title' => $titleObj->getPrefixedText(), 'pageid' => $current->getPage(), 'summary' => $summary, 'revid' => $titleObj->getLatestRevID(), 'old_revid' => $current->getID(), 'last_revid' => $target->getID());
     $this->getResult()->addValue(null, $this->getModuleName(), $info);
 }
	/**
	 * Save a survey to the database
	 * @param $name string Survey name
	 * @param $survey array Survey configuration data
	 */
	public static function save( $name, $survey ) {
		global $wgRequest, $wgUser;
		$dbw = wfGetDb( DB_MASTER );
		$now = $dbw->timestamp();
		foreach ( $survey['questions'] as $question => $config ) {
			$dbw->insert(
				'prefswitch_survey',
				array_merge(
					array(
						'pss_user' => $wgUser->getId(),
						'pss_user_text' => $wgUser->getName(),
						'pss_timestamp' => $now,
						'pss_name' => $name,
						'pss_question' => $question,
					),
					call_user_func( array( self::$fieldTypes[$config['type']], 'save' ), $question, $wgRequest )
				),
				__METHOD__
			);
		}
	}
 public static function save($user, &$options)
 {
     global $wgPrefStatsEnable, $wgPrefStatsTrackPrefs;
     if (!$wgPrefStatsEnable) {
         return;
     }
     $dbw = wfGetDb(DB_MASTER);
     foreach ($wgPrefStatsTrackPrefs as $pref => $value) {
         $start = $dbw->selectField('prefstats', 'ps_start', array('ps_user' => $user->getId(), 'ps_pref' => $pref, 'ps_end IS NULL'), __METHOD__);
         if (isset($options[$pref]) && $options[$pref] == $value && !$start) {
             $dbw->insert('prefstats', array('ps_user' => $user->getId(), 'ps_pref' => $pref, 'ps_value' => $value, 'ps_start' => $dbw->timestamp(wfTimestamp()), 'ps_end' => null, 'ps_duration' => null), __METHOD__, array('IGNORE'));
         } else {
             if ((!isset($options[$pref]) || $options[$pref] != $value) && $start) {
                 if ($start) {
                     $duration = wfTimestamp(TS_UNIX) - wfTimestamp(TS_UNIX, $start);
                     $dbw->update('prefstats', array('ps_end' => $dbw->timestamp(wfTimestamp()), 'ps_duration' => $duration), array('ps_user' => $user->getId(), 'ps_pref' => $pref, 'ps_start' => $dbw->timestamp($start)), __METHOD__);
                 }
             }
         }
     }
     return true;
 }
	public function execute() {
		$result = $this->getResult();
		$params = $this->extractRequestParams();

		$this->addTables( array( 'research_tools_surveys' ) );
		$this->addFields( array(
			'rts_id as id',
			'rts_title as title',
			'rts_description as description',
		) );
		if ( $params['survey'] ) {
			$this->addWhereFld( 'rts_id', $params['survey'] );
		} else {
			$this->addOption( 'OFFSET', $params['offset'] );
			$this->addOption( 'LIMIT', $params['limit'] );
		}

		$dbr = wfGetDb( DB_SLAVE );
		foreach ( $this->select( __METHOD__ ) as $surveyRow ) {
			$survey = (array)$surveyRow;
			$questionRows = $dbr->select(
				'research_tools_survey_questions',
				array(
					'rtsq_id as id',
					'rtsq_type as type',
					'rtsq_text as text',
					'rtsq_example as example',
					'rtsq_help as help'
				),
				array( 'rtsq_survey' => $params['survey'] ),
				__METHOD__
			);
			$survey['questions'] = array();
			foreach ( $questionRows as $row ) {
				$survey['questions'][] = $row;
			}
			$result->addValue( array( 'query', $this->getModuleName() ), null, $survey );
		}
	}
Exemplo n.º 24
0
 /**
  * Count the number of edits of a user
  *
  * It should not be static and some day should be merged as proper member function / deprecated -- domas
  * 
  * @param int $uid The user ID to check
  * @return int
  * @static
  */
 static function edits($uid)
 {
     wfProfileIn(__METHOD__);
     $dbr = wfGetDB(DB_SLAVE);
     // check if the user_editcount field has been initialized
     $field = $dbr->selectField('user', 'user_editcount', array('user_id' => $uid), __METHOD__);
     if ($field === null) {
         // it has not been initialized. do so.
         $dbw = wfGetDb(DB_MASTER);
         $count = $dbr->selectField('revision', 'count(*)', array('rev_user' => $uid), __METHOD__);
         $dbw->update('user', array('user_editcount' => $count), array('user_id' => $uid), __METHOD__);
     } else {
         $count = $field;
     }
     wfProfileOut(__METHOD__);
     return $count;
 }
Exemplo n.º 25
0
 /**
  * Called by maintenance script.
  */
 static function initTable()
 {
     wfProfileIn(__METHOD__);
     // create db handler
     $dbr = wfGetDb(DB_MASTER);
     if (!$dbr->tableExists(self::TABLE_NAME)) {
         try {
             $source = dirname(__FILE__) . "patch-create-wikia_page_backlinks.sql";
             $db->sourceFile($source);
         } catch (Exception $e) {
             wfProfileOut(__METHOD__);
             return $e;
         }
         wfProfileOut(__METHOD__);
         return "Table " . self::TABLE_NAME . " created.";
     }
     wfProfileOut(__METHOD__);
     return "Table " . self::TABLE_NAME . " already exists.";
 }
Exemplo n.º 26
0
 /**
  * Loads a string into mRestrictions array
  * @param resource $res restrictions as an SQL result.
  */
 private function loadRestrictionsFromRow($res, $oldFashionedRestrictions = NULL)
 {
     $dbr = wfGetDb(DB_SLAVE);
     $this->mRestrictions['edit'] = array();
     $this->mRestrictions['move'] = array();
     # Backwards-compatibility: also load the restrictions from the page record (old format).
     if ($oldFashionedRestrictions == NULL) {
         $oldFashionedRestrictions = $dbr->selectField('page', 'page_restrictions', array('page_id' => $this->getArticleId()), __METHOD__);
     }
     if ($oldFashionedRestrictions != '') {
         foreach (explode(':', trim($oldFashionedRestrictions)) as $restrict) {
             $temp = explode('=', trim($restrict));
             if (count($temp) == 1) {
                 // old old format should be treated as edit/move restriction
                 $this->mRestrictions["edit"] = explode(',', trim($temp[0]));
                 $this->mRestrictions["move"] = explode(',', trim($temp[0]));
             } else {
                 $this->mRestrictions[$temp[0]] = explode(',', trim($temp[1]));
             }
         }
         $this->mOldRestrictions = true;
         $this->mCascadeRestriction = false;
         $this->mRestrictionsExpiry = Block::decodeExpiry('');
     }
     if ($dbr->numRows($res)) {
         # Current system - load second to make them override.
         $now = wfTimestampNow();
         $purgeExpired = false;
         while ($row = $dbr->fetchObject($res)) {
             # Cycle through all the restrictions.
             // This code should be refactored, now that it's being used more generally,
             // But I don't really see any harm in leaving it in Block for now -werdna
             $expiry = Block::decodeExpiry($row->pr_expiry);
             // Only apply the restrictions if they haven't expired!
             if (!$expiry || $expiry > $now) {
                 $this->mRestrictionsExpiry = $expiry;
                 $this->mRestrictions[$row->pr_type] = explode(',', trim($row->pr_level));
                 $this->mCascadeRestriction |= $row->pr_cascade;
             } else {
                 // Trigger a lazy purge of expired restrictions
                 $purgeExpired = true;
             }
         }
         if ($purgeExpired) {
             Title::purgeExpiredRestrictions();
         }
     }
     $this->mRestrictionsLoaded = true;
 }
Exemplo n.º 27
0
 private function saveSurvey($survey, $type)
 {
     global $wgRequest, $wgUser;
     $dbw = wfGetDb(DB_MASTER);
     $now = $dbw->timestamp(wfTimestamp());
     foreach ($survey as $id => $question) {
         $insert = array('ois_user' => $wgUser->getId(), 'ois_timestamp' => $now, 'ois_type' => $type, 'ois_question' => $id);
         switch ($question['type']) {
             case 'dropdown':
             case 'radios':
                 $answer = $wgRequest->getVal("survey-{$id}", '');
                 if ($answer === 'other') {
                     $insert['ois_answer'] = null;
                     $insert['ois_answer_data'] = $wgRequest->getVal("survey-{$id}-other");
                 } else {
                     if ($answer === '') {
                         $insert['ois_answer'] = null;
                         $insert['ois_answer_data'] = null;
                     } else {
                         $insert['ois_answer'] = $answer;
                         $insert['ois_answer_data'] = null;
                     }
                 }
                 break;
             case 'checkboxes':
                 $checked = $wgRequest->getArray("survey-{$id}", array());
                 $insert['ois_answer'] = count($checked) ? implode(',', $checked) : null;
                 $insert['ois_answer_data'] = in_array('other', $checked) ? $wgRequest->getVal("survey-{$id}-other") : null;
                 break;
             case 'yesno':
                 $insert['ois_answer'] = $wgRequest->getVal("survey-{$id}", null);
                 $data = '';
                 if ($insert['ois_answer'] == 'yes') {
                     $data .= $wgRequest->getVal("survey-{$id}-ifyes", '');
                 }
                 if ($insert['ois_answer'] == 'no') {
                     $data .= $wgRequest->getVal("survey-{$id}-ifno", '');
                 }
                 $insert['ois_answer_data'] = $data ? $data : null;
                 break;
             case 'resolution':
                 $x = $wgRequest->getVal("survey-{$id}-x");
                 $y = $wgRequest->getVal("survey-{$id}-y");
                 if ($x === '' && $y === '') {
                     $insert['ois_answer'] = null;
                     $insert['ois_answer_data'] = null;
                 } else {
                     $insert['ois_answer'] = null;
                     $insert['ois_answer_data'] = $x . 'x' . $y;
                 }
                 break;
             case 'textarea':
                 $answer = $wgRequest->getVal("survey-{$id}");
                 if ($answer === '') {
                     $insert['ois_answer'] = null;
                     $insert['ois_answer_data'] = null;
                 } else {
                     $insert['ois_answer'] = null;
                     $insert['ois_answer_data'] = $answer;
                 }
                 break;
         }
         $dbw->insert('optin_survey', $insert, __METHOD__);
     }
 }
Exemplo n.º 28
0
 protected function renameAccount()
 {
     global $wgExternalSharedDB;
     wfProfileIn(__METHOD__);
     $dbw = wfGetDb(DB_MASTER, array(), $wgExternalSharedDB);
     $table = '`user`';
     $this->addLog("Changing user {$this->mOldUsername} to {$this->mNewUsername} in {$wgExternalSharedDB}");
     if ($dbw->tableExists($table)) {
         $dbw->update($table, array('user_name' => $this->mNewUsername), array('user_id' => $this->mUserId), __METHOD__);
         $affectedRows = $dbw->affectedRows();
         $this->addLog('Running query: ' . $dbw->lastQuery() . " resulted in {$affectedRows} row(s) being affected.");
         if ($affectedRows) {
             $dbw->commit();
             $this->addLog("Changed user {$this->mOldUsername} to {$this->mNewUsername} in {$wgExternalSharedDB}");
             wfProfileOut(__METHOD__);
             return true;
         } else {
             $this->addLog("No changes in {$wgExternalSharedDB} for user {$this->mOldUsername}");
         }
     } else {
         $this->addLog("Table \"{$table}\" not found in {$wgExternalSharedDB}");
     }
     wfProfileOut(__METHOD__);
     return false;
 }
 /**
  * Returns the type of a translation memory when given it's location.
  * If the memory is not found, -1 is returned.
  * 
  * @since 0.4
  * 
  * @param string $location
  * 
  * @return integer
  */
 public static function getMemoryType($location)
 {
     $dbr = wfGetDb(DB_MASTER);
     $res = $dbr->select('live_translate_memories', array('memory_type'), array('memory_location' => $location), __METHOD__, array('LIMIT' => '5000'));
     $type = -1;
     foreach ($res as $row) {
         $type = $row->memory_type;
         break;
     }
     return $type;
 }
Exemplo n.º 30
0
 /**
  * Check whether this external user id is already linked with
  * a local user.
  * @return Mixed User if the account is linked, Null otherwise.
  */
 public final function getLocalUser()
 {
     $dbr = wfGetDb(DB_SLAVE);
     $row = $dbr->selectRow('external_user', '*', array('eu_external_id' => $this->getId()));
     return $row ? User::newFromId($row->eu_local_id) : null;
 }