/**
  * Record a file upload in the upload log and the image table
  */
 function recordUpload2($oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null)
 {
     if (is_null($user)) {
         global $wgUser;
         $user = $wgUser;
     }
     $dbw = $this->repo->getMasterDB();
     $dbw->begin();
     if (!$props) {
         $props = $this->repo->getFileProps($this->getVirtualUrl());
     }
     $props['description'] = $comment;
     $props['user'] = $user->getId();
     $props['user_text'] = $user->getName();
     $props['timestamp'] = wfTimestamp(TS_MW);
     $this->setProps($props);
     // Delete thumbnails and refresh the metadata cache
     $this->purgeThumbnails();
     $this->saveToCache();
     SquidUpdate::purge(array($this->getURL()));
     /* Wikia change begin - @author: Marooned, see RT#44185 */
     global $wgLogo;
     if ($this->url == $wgLogo) {
         SquidUpdate::purge(array($this->url));
     }
     /* Wikia change end */
     // Fail now if the file isn't there
     if (!$this->fileExists) {
         wfDebug(__METHOD__ . ": File " . $this->getPath() . " went missing!\n");
         return false;
     }
     $reupload = false;
     if ($timestamp === false) {
         $timestamp = $dbw->timestamp();
     }
     # Test to see if the row exists using INSERT IGNORE
     # This avoids race conditions by locking the row until the commit, and also
     # doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
     $dbw->insert('image', array('img_name' => $this->getName(), 'img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->media_type, 'img_major_mime' => $this->major_mime, 'img_minor_mime' => $this->minor_mime, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $user->getId(), 'img_user_text' => $user->getName(), 'img_metadata' => $this->metadata, 'img_sha1' => $this->sha1), __METHOD__, 'IGNORE');
     if ($dbw->affectedRows() == 0) {
         $reupload = true;
         # Collision, this is an update of a file
         # Insert previous contents into oldimage
         $dbw->insertSelect('oldimage', 'image', array('oi_name' => 'img_name', 'oi_archive_name' => $dbw->addQuotes($oldver), 'oi_size' => 'img_size', 'oi_width' => 'img_width', 'oi_height' => 'img_height', 'oi_bits' => 'img_bits', 'oi_timestamp' => 'img_timestamp', 'oi_description' => 'img_description', 'oi_user' => 'img_user', 'oi_user_text' => 'img_user_text', 'oi_metadata' => 'img_metadata', 'oi_media_type' => 'img_media_type', 'oi_major_mime' => 'img_major_mime', 'oi_minor_mime' => 'img_minor_mime', 'oi_sha1' => 'img_sha1'), array('img_name' => $this->getName()), __METHOD__);
         # Update the current image row
         $dbw->update('image', array('img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->media_type, 'img_major_mime' => $this->major_mime, 'img_minor_mime' => $this->minor_mime, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $user->getId(), 'img_user_text' => $user->getName(), 'img_metadata' => $this->metadata, 'img_sha1' => $this->sha1), array('img_name' => $this->getName()), __METHOD__);
     } else {
         # This is a new file
         # Update the image count
         $site_stats = $dbw->tableName('site_stats');
         $dbw->query("UPDATE {$site_stats} SET ss_images=ss_images+1", __METHOD__);
     }
     # Commit the transaction now, in case something goes wrong later
     # The most important thing is that files don't get lost, especially archives
     $dbw->commit();
     # Invalidate cache for all pages using this file
     $update = new HTMLCacheUpdate($this->getTitle(), 'imagelinks');
     $update->doUpdate();
     return true;
 }
 /**
  * Function check if user is blocked, return true
  * user blocked status is passed to $ret
  * @param $parser Parser
  * @param $varCache ??
  * @param $index ??
  * @param $ret string?
  * @return bool
  */
 public static function parserGetVariable(&$parser, &$varCache, &$index, &$ret)
 {
     if ($index != 'USERBLOCKED') {
         return true;
     }
     $title = $parser->getTitle();
     if ($title->getNamespace() != NS_USER && $title->getNamespace() != NS_USER_TALK) {
         $ret = 'unknown';
         return true;
     }
     $user = User::newFromName($title->getBaseText());
     if ($user instanceof User) {
         if (!$user->isBlocked()) {
             $ret = 'false';
             return true;
         }
         // if user is blocked it's pretty much possible they will be unblocked one day :)
         // so we enable cache for shorter time only so that we can recheck later
         // if they weren't already unblocked - if there is a better way to do that, fix me
         $expiry = $user->getBlock()->mExpiry;
         if (is_numeric($expiry)) {
             // sometimes this is 'infinityinfinity'. in that case, use the default cache expiry time.
             $expiry = wfTimestamp(TS_UNIX, $expiry) - wfTimestamp(TS_UNIX);
             if ($expiry > 0) {
                 // just to make sure
                 $parser->getOutput()->updateCacheExpiry($expiry);
             }
         }
         $ret = 'true';
         return true;
     }
     $ret = 'unknown';
     return true;
 }
 function addDBData()
 {
     $user = User::newFromName('UTBlockee');
     if ($user->getID() == 0) {
         $user->addToDatabase();
         $user->setPassword('UTBlockeePassword');
         $user->saveSettings();
     }
     // Delete the last round's block if it's still there
     $oldBlock = Block::newFromTarget('UTBlockee');
     if ($oldBlock) {
         // An old block will prevent our new one from saving.
         $oldBlock->delete();
     }
     $this->block = new Block('UTBlockee', $user->getID(), 0, 'Parce que', 0, false, time() + 100500);
     $this->madeAt = wfTimestamp(TS_MW);
     $this->block->insert();
     // save up ID for use in assertion. Since ID is an autoincrement,
     // its value might change depending on the order the tests are run.
     // ApiBlockTest insert its own blocks!
     $newBlockId = $this->block->getId();
     if ($newBlockId) {
         $this->blockId = $newBlockId;
     } else {
         throw new MWException("Failed to insert block for BlockTest; old leftover block remaining?");
     }
     $this->addXffBlocks();
 }
 public static function onArticleViewHeader(&$article)
 {
     global $wgOut, $wgLang;
     if ($article->mTitle->getNamespace() == NS_DELETION) {
         $dqi = DeleteQueueItem::newFromDiscussion($article);
         if (!$dqi->isQueued()) {
             break;
         }
         $wgOut->addWikiMsg('deletequeue-deletediscuss-discussionpage', $dqi->getArticle()->mTitle->getPrefixedText(), count($dqi->getEndorsements()), count($dqi->getObjections()));
     }
     $dqi = DeleteQueueItem::newFromArticle($article);
     if (!($queue = $dqi->getQueue())) {
         return true;
     }
     $options = array("deletequeue-page-{$queue}");
     $options[] = $dqi->getReason();
     $expiry = wfTimestamp(TS_UNIX, $dqi->getExpiry());
     $options[] = $wgLang->timeanddate($expiry);
     $options[] = $wgLang->date($expiry);
     $options[] = $wgLang->time($expiry);
     if ($queue == 'deletediscuss') {
         $options[] = $dqi->getDiscussionPage()->mTitle->getPrefixedText();
     }
     call_user_func_array(array($wgOut, 'addWikiMsg'), $options);
     return true;
 }
 /**
  * @see FileJournal::logChangeBatch()
  * @return Status
  */
 protected function doLogChangeBatch(array $entries, $batchId)
 {
     $status = Status::newGood();
     try {
         $dbw = $this->getMasterDB();
     } catch (DBError $e) {
         $status->fatal('filejournal-fail-dbconnect', $this->backend);
         return $status;
     }
     $now = wfTimestamp(TS_UNIX);
     $data = array();
     foreach ($entries as $entry) {
         $data[] = array('fj_batch_uuid' => $batchId, 'fj_backend' => $this->backend, 'fj_op' => $entry['op'], 'fj_path' => $entry['path'], 'fj_new_sha1' => $entry['newSha1'], 'fj_timestamp' => $dbw->timestamp($now));
     }
     try {
         $dbw->insert('filejournal', $data, __METHOD__);
         if (mt_rand(0, 99) == 0) {
             $this->purgeOldLogs();
             // occasionally delete old logs
         }
     } catch (DBError $e) {
         $status->fatal('filejournal-fail-dbquery', $this->backend);
         return $status;
     }
     return $status;
 }
Example #6
0
 public function execute()
 {
     $params = $this->extractRequestParams();
     $strquery = $params['strquery'];
     $result = $this->getResult();
     if (isset($strquery) && $strquery != NULL) {
         $searchString = str_replace('%', '\\%', $strquery);
         $searchString = str_replace('_', '\\_', $searchString);
         $searchString = str_replace('|', '%', $searchString);
         $dbr = $this->getDB();
         $suggestStrings = array();
         $this->addTables('categorylinks');
         $this->addFields('DISTINCT cl_to');
         $this->addWhere(" UPPER(CONVERT(cl_to using latin1)) LIKE UPPER(CONVERT('{$searchString}%' using latin1)) ");
         $res = $this->select(__METHOD__);
         while ($row = $res->fetchObject()) {
             array_push($suggestStrings, $row->cl_to);
             $fit = $result->addValue(array('query', $this->getModuleName()), null, $row->cl_to);
             if (!$fit) {
                 $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->afl_timestamp));
                 break;
             }
         }
         $dbr->freeResult($res);
     }
     $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'category');
 }
Example #7
0
 function getArticleRequestTop()
 {
     global $wgTitle, $wgArticle, $wgRequest, $wgUser;
     $s = "";
     $sk = $wgUser->getSkin();
     $action = $wgRequest->getVal("action");
     if ($wgTitle->getNamespace() == NS_ARTICLE_REQUEST && $action == "" && $wgTitle->getArticleID() > 0) {
         $askedBy = $wgArticle->getUserText();
         $authors = $wgArticle->getContributors(1);
         //$askedBy = "hi" . $authors[0][0];
         //$id = $wgArticle->getUser();
         $real_name = User::whoIsReal($authors[0][0]);
         if ($real_name != "") {
             $askedBy = $real_name;
         } else {
             if ($authors[0][0] == 0) {
                 $askedBy = wfMsg('user_anonymous');
             } else {
                 $askedBy = $authors[0][1];
             }
         }
         $dateAsked = date("F d, Y", wfTimestamp(TS_UNIX, $wgArticle->getTimestamp()));
         $s .= "<div class=\"article_inner\"><table>\n\t\t\t<tr>\n\t\t\t<td width=\"20%\" valign=\"top\">" . wfMsg('request') . "</td><td><b>" . wfMsg('howto', $wgTitle->getText()) . "</b></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t<td>" . wfMsg('askedby') . "</td><td>" . $askedBy . "</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t<td>" . wfMsg('date') . ":</td>\n\t\t\t\t<td>" . $dateAsked . "</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t<td valign=\"middle\">" . wfMsg('details') . "</td>\n\t\t\t\t<td><b>\t";
     }
     return $s;
 }
 /**
  * Generate a new e-mail confirmation token and send a confirmation/invalidation
  * mail to the user's given address.
  *
  * @return Status object
  */
 public function sendConfirmAndMigrateMail()
 {
     global $wgLang;
     $tokenLife = 14 * 24 * 60 * 60;
     // 14 days
     $expiration = null;
     // gets passed-by-ref and defined in next line.
     $token = $this->confirmationToken($expiration);
     // we want this token to last a little bit longer since we are cold-emailing
     // users and we really want as many responses as possible
     $now = time();
     $expires = $now + $tokenLife;
     $expiration = wfTimestamp(TS_MW, $expires);
     $this->mEmailTokenExpires = $expiration;
     if ($this->isEmailConfirmed()) {
         // Hack to bypass localization of 'Special:'
         // @see User::getTokenUrl
         $mergeAccountUrl = Title::makeTitle(NS_MAIN, 'Special:MergeAccount')->getCanonicalURL();
     } else {
         // create a "token url" for MergeAccount since we have added email
         // confirmation there
         $mergeAccountUrl = $this->getTokenUrl('MergeAccount', $token);
     }
     $invalidateURL = $this->invalidationTokenUrl($token);
     $this->saveSettings();
     return $this->sendMail(wfMessage('centralauth-finishglobaliseemail_subject')->text(), wfMessage("centralauth-finishglobaliseemail_body", $this->getRequest()->getIP(), $this->getName(), $mergeAccountUrl, $wgLang->timeanddate($expiration, false), $invalidateURL, $wgLang->date($expiration, false), $wgLang->time($expiration, false))->text());
 }
 private function getCoordinator()
 {
     $clientWikis = array('dewiki' => 'dewikidb', 'enwiki' => 'enwikidb', 'nlwiki' => 'nlwikidb', 'ruwiki' => 'ruwikidb', 'zhwiki' => 'zhwikidb');
     $coordinator = new SqlChangeDispatchCoordinator(false, $clientWikis);
     $coordinator->setBatchSize(3);
     $coordinator->setRandomness(3);
     $coordinator->setLockGraceInterval(120);
     $coordinator->setDispatchInterval(60);
     $coordinator->setArrayRandOverride(function ($array) {
         $keys = array_keys($array);
         $last = end($keys);
         return $last;
     });
     $coordinator->setTimeOverride(function () {
         return wfTimestamp(TS_UNIX, '20140303000000');
     });
     $coordinator->setIsClientLockUsedOverride(function ($wikiDB, $lockName) {
         return $wikiDB === 'zhwikidb';
     });
     $coordinator->setEngageClientLockOverride(function ($wikiDB) {
         return $wikiDB !== 'zhwikidb';
     });
     $coordinator->setReleaseClientLockOverride(function ($wikiDB) {
         return true;
     });
     return $coordinator;
 }
 public function execute()
 {
     global $wgDBname;
     if ($this->hasOption('days')) {
         $inactivitydays = $this->getOption('days');
     } else {
         $inactivitydays = 30;
     }
     if ($this->hasOption('timezone')) {
         $timezone = $this->getOption('timezone');
     } else {
         $timezone = 'UTC';
     }
     # Generates a timestamp in yearmonthdayhourminutesecond format of the current time
     date_default_timezone_set($timezone);
     $date = date("YmdHis", strtotime("-{$inactivitydays} days"));
     $dbw = wfGetDB(DB_MASTER);
     $res = $dbw->select('recentchanges', 'rc_timestamp', 'rc_timestamp >= ' . $dbw->addQuotes($date), __METHOD__, array('ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => 1));
     if ($res->numRows() > 0) {
         if ($this->hasOption('display-active')) {
             foreach ($res as $row) {
                 $this->output("The wiki \"{$wgDBname}\" does NOT meet the inactivity requirements, date of last RecentChanges log entry: " . wfTimestamp(TS_DB, $row->rc_timestamp) . "\n");
             }
         }
     } else {
         $res = $dbw->select('recentchanges', 'rc_timestamp', 'rc_timestamp < ' . $dbw->addQuotes($date), __METHOD__, array('ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => 1));
         foreach ($res as $row) {
             $this->output("The wiki \"{$wgDBname}\" DOES meet the inactivity requirements, date of last RecentChanges log entry: " . wfTimeStamp(TS_DB, $row->rc_timestamp) . "\n");
         }
     }
 }
 public function execute()
 {
     $params = $this->extractRequestParams();
     $result = $this->getResult();
     $userName = $params['user'];
     $daysago = $params['daysago'];
     $basetimestamp = $params['basetimestamp'];
     $user = User::newFromName($userName);
     if (!$user) {
         $this->dieUsage('Invalid username', 'bad_user');
     }
     global $wgAuth, $wgUserDailyContributionsApiCheckAuthPlugin;
     if ($wgUserDailyContributionsApiCheckAuthPlugin && !$wgAuth->userExists($userName)) {
         $this->dieUsage('Specified user does not exist', 'bad_user');
     }
     // Defaults to 'now' if not given
     $totime = wfTimestamp(TS_UNIX, $basetimestamp);
     $fromtime = $totime - $daysago * 60 * 60 * 24;
     $result->addValue($this->getModuleName(), 'id', $user->getId());
     // Returns date of registration in YYYYMMDDHHMMSS format
     $result->addValue($this->getModuleName(), 'registration', $user->getRegistration() ? $user->getRegistration() : '0');
     // Returns number of edits between daysago date and basetimestamp (or today)
     $result->addValue($this->getModuleName(), 'timeFrameEdits', getUserEditCountSince($fromtime, $user, $totime));
     // Returns total number of edits
     $result->addValue($this->getModuleName(), 'totalEdits', $user->getEditCount() == NULL ? 0 : $user->getEditCount());
 }
 static function displayRecentChanges()
 {
     $html = '';
     $html .= '<table width="100%">';
     $changes = CustomTitleChangesLog::dbGetRecentChanges(10);
     $html .= "<tr><th>When</th><th>User</th><th>Summary</th></tr>\n";
     $users = array();
     foreach ($changes as $change) {
         $html .= '<tr>';
         $ts = wfTimestamp(TS_UNIX, $change['tcc_timestamp']);
         $html .= "<td>" . date('Y-m-d', $ts) . "</td>";
         $userid = $change['tcc_userid'];
         if (!isset($users[$userid])) {
             $users[$userid] = User::newFromId($userid);
         }
         $user = $users[$userid];
         $usertext = $user ? $user->getName() : '';
         $html .= "<td>{$usertext}</td>";
         $summary = substr($change['tcc_summary'], 0, 200);
         if ($summary != $change['tcc_summary']) {
             $summary .= '...';
         }
         $html .= "<td>{$summary}</td>";
         $html .= "</tr>\n";
     }
     $html .= '</table>';
     return $html;
 }
 public function execute()
 {
     global $wgContLang;
     $pageSet = $this->getPageSet();
     $pageids = array_keys($pageSet->getGoodTitles());
     if (!$pageids) {
         return true;
     }
     // Construct SQL Query
     $this->addTables('flaggedpages');
     $this->addFields(array('fp_page_id', 'fp_stable', 'fp_quality', 'fp_pending_since'));
     $this->addWhereFld('fp_page_id', $pageids);
     $res = $this->select(__METHOD__);
     $result = $this->getResult();
     foreach ($res as $row) {
         $data = array('stable_revid' => intval($row->fp_stable), 'level' => intval($row->fp_quality), 'level_text' => FlaggedRevs::getQualityLevelText($row->fp_quality));
         if ($row->fp_pending_since) {
             $data['pending_since'] = wfTimestamp(TS_ISO_8601, $row->fp_pending_since);
         }
         $result->addValue(array('query', 'pages', $row->fp_page_id), 'flagged', $data);
     }
     $this->resetQueryParams();
     $this->addTables('flaggedpage_config');
     $this->addFields(array('fpc_page_id', 'fpc_level', 'fpc_expiry'));
     $this->addWhereFld('fpc_page_id', $pageids);
     foreach ($this->select(__METHOD__) as $row) {
         $result->addValue(array('query', 'pages', $row->fpc_page_id, 'flagged'), 'protection_level', $row->fpc_level);
         $result->addValue(array('query', 'pages', $row->fpc_page_id, 'flagged'), 'protection_expiry', $wgContLang->formatExpiry($row->fpc_expiry, TS_ISO_8601));
     }
     return true;
 }
 public function execute()
 {
     global $wgUser;
     $result = $this->getResult();
     $params = $this->extractRequestParams();
     $token = array();
     if ($wgUser->isAnon()) {
         if (!isset($params['anontoken'])) {
             $this->dieUsageMsg(array('missingparam', 'anontoken'));
         } elseif (strlen($params['anontoken']) != 32) {
             $this->dieUsage('The anontoken is not 32 characters', 'invalidtoken');
         }
         $token = $params['anontoken'];
     } else {
         $token = '';
     }
     $dbr = wfGetDB(DB_SLAVE);
     $dbw = wfGetDB(DB_MASTER);
     // Check if the incoming survey is valid
     $surveyCount = $dbr->selectRow('research_tools_surveys', 'rts_id', array('rts_id' => $params['survey']), __METHOD__);
     if ($surveyCount === false) {
         $this->dieUsage('The survey is unknown', 'invalidsurvey');
     }
     // Find an existing response from this user for this survey
     $response = $dbr->selectRow('research_tools_survey_responses', 'rtsr_id', array('rtsr_user_text' => $wgUser->getName(), 'rtsr_user_anon_token' => $token, 'rtsr_survey' => $params['survey']), __METHOD__);
     if ($response !== false) {
         // Delete any of the previous answers (they questions may have changed)
         $dbw->delete('research_tools_survey_answers', array('rtsa_response' => $response->rtsr_id), __METHOD__);
     }
     // Decode JSON answer data
     $answers = FormatJson::decode($params['answers'], true);
     if (!is_array($answers)) {
         $this->dieUsage('Invalid answer data', 'invalidanswers');
     }
     // Verify questions exist
     foreach ($answers as $question => $answer) {
         $question = $dbr->selectRow('research_tools_survey_questions', 'rtsq_id', array('rtsq_survey' => $params['survey'], 'rtsq_id' => $question), __METHOD__);
         if ($question === false) {
             $this->dieUsage('A question is unknown', 'invalidquestion');
         }
     }
     if ($response === false) {
         // Insert a new response row
         $dbw->insert('research_tools_survey_responses', array('rtsr_time' => wfTimestamp(TS_MW), 'rtsr_user_text' => $wgUser->getName(), 'rtsr_user_anon_token' => $token, 'rtsr_survey' => $params['survey']), __METHOD__);
         $response = $dbw->insertId();
     } else {
         $response = $response->rtsr_id;
         // Update the timestamp of the existing response row
         $dbw->update('research_tools_survey_responses', array('rtsr_time' => wfTimestamp(TS_MW)), array('rtsr_id' => $response), __METHOD__);
     }
     // Insert answers for the response
     $answerRows = array();
     foreach ($answers as $question => $answer) {
         // Build row data
         $answerRows[] = array('rtsa_response' => $response, 'rtsa_question' => $question, 'rtsa_value_integer' => is_numeric($answer) ? intval($answer) : null, 'rtsa_value_text' => is_numeric($answer) ? '' : $answer);
     }
     $dbw->insert('research_tools_survey_answers', $answerRows, __METHOD__);
     // Add success to result
     $result->addValue(null, $this->getModuleName(), array('result' => 'Success'));
 }
Example #15
0
 private static function listFilesFlat($base_path)
 {
     #static $count=0;
     $results = array();
     foreach (new DirectoryIterator($base_path) as $fileinfo) {
         #$count++;if ($count>1000) break;
         if ($fileinfo->isDot()) {
             continue;
         } elseif ($fileinfo->isDir()) {
             $new_results = self::listFilesFlat($fileinfo->getPathname());
             $results = array_merge($results, $new_results);
         } else {
             $path = $fileinfo->getPathname();
             // a hack for filenames that have / in them
             $fn = preg_replace('@^/var/www/images_en/./../@', '', $path);
             $hash = md5($fn);
             if (isset($results[$hash])) {
                 print "error: dup hash for {$fn}\n";
             } else {
                 $results[$hash] = array('path' => $path, 'file' => $fn, 'size' => $fileinfo->getSize(), 'time' => wfTimestamp(TS_MW, $fileinfo->getMTime()));
             }
         }
     }
     return $results;
 }
 public function execute()
 {
     global $wgUser;
     $params = $this->extractRequestParams();
     if (!$wgUser->isAllowed('checkuser-log')) {
         $this->dieUsage('You need the checkuser-log right', 'permissionerror');
     }
     list($user, $limit, $target, $from, $to) = array($params['user'], $params['limit'], $params['target'], $params['from'], $params['to']);
     $this->addTables('cu_log');
     $this->addOption('LIMIT', $limit + 1);
     $this->addWhereRange('cul_timestamp', 'older', $from, $to);
     $this->addFields(array('cul_timestamp', 'cul_user_text', 'cul_reason', 'cul_type', 'cul_target_text'));
     if (isset($user)) {
         $this->addWhereFld('cul_user_text', $user);
     }
     if (isset($target)) {
         $this->addWhereFld('cul_target_text', $target);
     }
     $res = $this->select(__METHOD__);
     $result = $this->getResult();
     $log = array();
     foreach ($res as $row) {
         $log[] = array('timestamp' => wfTimestamp(TS_ISO_8601, $row->cul_timestamp), 'checkuser' => $row->cul_user_text, 'type' => $row->cul_type, 'reason' => $row->cul_reason, 'target' => $row->cul_target_text);
     }
     $result->addValue(array('query', $this->getModuleName()), 'entries', $log);
     $result->setIndexedTagName_internal(array('query', $this->getModuleName(), 'entries'), 'entry');
 }
Example #17
0
 function getFeedItems($user)
 {
     global $wgMemc;
     $fname = "Feed::getFeedItems";
     wfProfileIn($fname);
     $key = "feed_user_" . $user->getID();
     $feed = $wgMemc->get($key);
     if (!$feed || true) {
         $feed = array();
     }
     // was this feed updated in the last 30 minutes?
     $old = wfTimestamp(TS_MW, time() - 1800);
     if (isset($feed['updated']) && $feed['updated'] > $old) {
         return $feed;
     }
     // get what they are interested in
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select('follow', array('*'), array('fo_user' => $user->getID()), $fname, array("ORDER BY" => "fo_weight desc"));
     $follows = array();
     while ($row = $dbr->fetchObject($res)) {
         $feed[] = $row;
     }
     $wgMemc->set($key, $feed, 600);
     // store it for 2 days
     wfProfileOut($fname);
     return $feed;
 }
Example #18
0
 public static function merge(BloomCache $bcache, $domain, $virtualKey, array $status)
 {
     $limit = 1000;
     $dbr = wfGetDB(DB_SLAVE, array(), $domain);
     $res = $dbr->select('logging', array('log_namespace', 'log_title', 'log_id', 'log_timestamp'), array('log_id > ' . $dbr->addQuotes((int) $status['lastID'])), __METHOD__, array('ORDER BY' => 'log_id', 'LIMIT' => $limit));
     $updates = array();
     if ($res->numRows() > 0) {
         $members = array();
         foreach ($res as $row) {
             $members[] = "{$virtualKey}:{$row->log_namespace}:{$row->log_title}";
         }
         $lastID = $row->log_id;
         $lastTime = $row->log_timestamp;
         if (!$bcache->add('shared', $members)) {
             return false;
         }
         $updates['lastID'] = $lastID;
         $updates['asOfTime'] = wfTimestamp(TS_UNIX, $lastTime);
     } else {
         $updates['asOfTime'] = microtime(true);
     }
     $updates['epoch'] = $status['epoch'] ?: microtime(true);
     $bcache->setStatus($virtualKey, $updates);
     return $updates;
 }
 /**
  * alterHeaders
  *
  * Put the Memento headers in place for this directly accessed Memento.
  */
 public function alterHeaders()
 {
     global $wgMementoIncludeNamespaces;
     $out = $this->article->getContext()->getOutput();
     $request = $out->getRequest();
     $response = $request->response();
     $titleObj = $this->article->getTitle();
     $linkEntries = array();
     // if we exclude this Namespace, don't show folks Memento relations
     if (!in_array($titleObj->getNamespace(), $wgMementoIncludeNamespaces)) {
         $entry = '<http://mementoweb.org/terms/donotnegotiate>; rel="type"';
         $linkEntries[] = $entry;
     } else {
         $title = $this->getFullNamespacePageTitle($titleObj);
         $mementoTimestamp = $this->article->getRevisionFetched()->getTimestamp();
         // convert for display
         $mementoDatetime = wfTimestamp(TS_RFC2822, $mementoTimestamp);
         $uri = $titleObj->getFullURL();
         $tguri = $this->getTimeGateURI($title);
         $entry = $this->constructLinkRelationHeader($uri, 'original latest-version');
         $linkEntries[] = $entry;
         $entry = $this->constructLinkRelationHeader($tguri, 'timegate');
         $linkEntries[] = $entry;
         $first = $this->getFirstMemento($titleObj);
         $last = $this->getLastMemento($titleObj);
         // TODO: Throw a 400-status error message if
         // getFirstMemento/getLastMemento is null?
         // how would we have gotten here if titleObj was bad?
         $entries = $this->generateRecommendedLinkHeaderRelations($titleObj, $first, $last);
         $linkEntries = array_merge($linkEntries, $entries);
         $response->header("Memento-Datetime:  {$mementoDatetime}", true);
     }
     $linkEntries = implode(',', $linkEntries);
     $response->header("Link: {$linkEntries}", true);
 }
 private function getCoordinator()
 {
     $coordinator = new SqlChangeDispatchCoordinator(false, 'TestRepo');
     $coordinator->setBatchSize(3);
     $coordinator->setRandomness(3);
     $coordinator->setLockGraceInterval(120);
     $coordinator->setDispatchInterval(60);
     $coordinator->setArrayRandOverride(function ($array) {
         $keys = array_keys($array);
         $last = end($keys);
         return $last;
     });
     $coordinator->setTimeOverride(function () {
         return wfTimestamp(TS_UNIX, '20140303000000');
     });
     $coordinator->setIsClientLockUsedOverride(function ($db, $lockName) {
         return $lockName === 'Wikibase.TestRepo.dispatchChanges.zhwiki';
     });
     $coordinator->setEngageClientLockOverride(function ($db, $lockName) {
         return $lockName !== 'Wikibase.TestRepo.dispatchChanges.zhwiki';
     });
     $coordinator->setReleaseClientLockOverride(function ($db, $lockName) {
         return true;
     });
     return $coordinator;
 }
 /**
  * Add info on the user who uploaded the file and the date it was uploaded, and create thumb if it doesn't exist
  */
 protected function get_file_object($file_name)
 {
     // Create the thumb if it doesn't exist
     $thumb = $this->options['upload_dir'] . 'thumb/' . $file_name;
     if (!file_exists(jQueryUpload::thumbFilename($thumb))) {
         $this->create_scaled_image($file_name, $this->options['image_versions']['thumbnail']);
     }
     // Call the parent method to create the file object
     $file = parent::get_file_object($file_name);
     // Add the meta data to the object
     if (is_object($file)) {
         $meta = $this->options['upload_dir'] . 'meta/' . $file_name;
         $file->info = $file->desc = "";
         // If the meta data file exists, extract and render the content
         if (is_file($meta)) {
             $data = unserialize(file_get_contents($meta));
             $file->info = self::renderData($data);
             $file->desc = array_key_exists(2, $data) ? $data[2] : '';
         } elseif (is_link($this->options['upload_dir'] . $file_name)) {
             $title = Title::newFromText($file_name, NS_FILE);
             if (is_object($title) && $title->exists()) {
                 list($uid, $ts, $file->desc) = self::getUploadedFileInfo($title);
                 $file->info = self::renderData(array($uid, wfTimestamp(TS_UNIX, $ts)));
             }
         }
     }
     return $file;
 }
 /**
  * Rebuild pass 1: Insert `recentchanges` entries for page revisions.
  */
 private function rebuildRecentChangesTablePass1()
 {
     $dbw = $this->getDB(DB_MASTER);
     if ($this->hasOption('from') && $this->hasOption('to')) {
         $this->cutoffFrom = wfTimestamp(TS_UNIX, $this->getOption('from'));
         $this->cutoffTo = wfTimestamp(TS_UNIX, $this->getOption('to'));
         $sec = $this->cutoffTo - $this->cutoffFrom;
         $days = $sec / 24 / 3600;
         $this->output("Rebuilding range of {$sec} seconds ({$days} days)\n");
     } else {
         global $wgRCMaxAge;
         $days = $wgRCMaxAge / 24 / 3600;
         $this->output("Rebuilding \$wgRCMaxAge={$wgRCMaxAge} seconds ({$days} days)\n");
         $this->cutoffFrom = time() - $wgRCMaxAge;
         $this->cutoffTo = time();
     }
     $this->output("Clearing recentchanges table for time range...\n");
     $rcids = $dbw->selectFieldValues('recentchanges', 'rc_id', ['rc_timestamp > ' . $dbw->addQuotes($dbw->timestamp($this->cutoffFrom)), 'rc_timestamp < ' . $dbw->addQuotes($dbw->timestamp($this->cutoffTo))]);
     foreach (array_chunk($rcids, $this->mBatchSize) as $rcidBatch) {
         $dbw->delete('recentchanges', ['rc_id' => $rcidBatch], __METHOD__);
         wfGetLBFactory()->waitForReplication();
     }
     $this->output("Loading from page and revision tables...\n");
     $res = $dbw->select(['page', 'revision'], ['rev_timestamp', 'rev_user', 'rev_user_text', 'rev_comment', 'rev_minor_edit', 'rev_id', 'rev_deleted', 'page_namespace', 'page_title', 'page_is_new', 'page_id'], ['rev_timestamp > ' . $dbw->addQuotes($dbw->timestamp($this->cutoffFrom)), 'rev_timestamp < ' . $dbw->addQuotes($dbw->timestamp($this->cutoffTo)), 'rev_page=page_id'], __METHOD__, ['ORDER BY' => 'rev_timestamp DESC']);
     $this->output("Inserting from page and revision tables...\n");
     $inserted = 0;
     foreach ($res as $row) {
         $dbw->insert('recentchanges', ['rc_timestamp' => $row->rev_timestamp, 'rc_user' => $row->rev_user, 'rc_user_text' => $row->rev_user_text, 'rc_namespace' => $row->page_namespace, 'rc_title' => $row->page_title, 'rc_comment' => $row->rev_comment, 'rc_minor' => $row->rev_minor_edit, 'rc_bot' => 0, 'rc_new' => $row->page_is_new, 'rc_cur_id' => $row->page_id, 'rc_this_oldid' => $row->rev_id, 'rc_last_oldid' => 0, 'rc_type' => $row->page_is_new ? RC_NEW : RC_EDIT, 'rc_source' => $row->page_is_new ? $dbw->addQuotes(RecentChange::SRC_NEW) : $dbw->addQuotes(RecentChange::SRC_EDIT), 'rc_deleted' => $row->rev_deleted], __METHOD__);
         if (++$inserted % $this->mBatchSize == 0) {
             wfGetLBFactory()->waitForReplication();
         }
     }
 }
 /**
  * Gets the first time a user opened an edit page
  * @param $user User The User to check.
  * @return The timestamp of the first time the user opened an edit page.
  * false for an anonymous user, null for a user who has never opened an edit page.
  */
 public static function getFirstEditPage($user)
 {
     global $wgMemc;
     if (isset($user->mFirstEditPage)) {
         return $user->mFirstEditPage;
     }
     if ($user->isAnon()) {
         return false;
     }
     $cacheKey = wfMemcKey('first-edit-page', $user->getId());
     $cacheVal = $wgMemc->get($cacheKey);
     if ($cacheVal !== false) {
         $user->mFirstEditPage = $cacheVal;
         return $cacheVal;
     }
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select('edit_page_tracking', 'ept_timestamp', array('ept_user' => $user->getID()), __METHOD__, array('ORDER BY' => 'ept_timestamp asc'));
     if ($dbr->numRows($res) == 0) {
         $user->mFirstEditPage = null;
         $wgMemc->set($cacheKey, null, 86400);
         return null;
     }
     $row = $dbr->fetchObject($res);
     $user->mFirstEditPage = wfTimestamp(TS_MW, $row->ept_timestamp);
     $wgMemc->set($cacheKey, $user->mFirstEditPage, 86400);
     return $user->mFirstEditPage;
 }
	/**
	 * Modify results from Blogs
	 *
	 * Add likes count and render avatar
	 */
	static function getResults(&$results) {
		wfProfileIn(__METHOD__);

		/* @var $wgLang Language */
		global $wgLang;

		// get message for "read more" link
		$cutSign = wfMsg('blug-cut-sign');

		foreach($results as &$result) {
			$result['likes'] = false;
			$result['avatar'] = AvatarService::renderAvatar($result['username'], 48);
			$result['userpage'] = AvatarService::getUrl($result['username']);
			$result['date'] = $wgLang->date(wfTimestamp(TS_MW, $result['timestamp']));

			// "read more" handling
			if (strpos($result['text'], $cutSign) !== false) {
				$result['readmore'] = true;
			}
		}

		//print_pre($results);

		wfProfileOut(__METHOD__);
		return true;
	}
Example #25
0
 /**
  * Dates in Walloon are "1î d' <monthname>" for 1st of the month,
  * "<day> di <monthname>" for months starting by a consoun, and
  * "<day> d' <monthname>" for months starting with a vowel
  *
  * @param $ts string
  * @param $adj bool
  * @param $format bool
  * @param $tc bool
  * @return string
  */
 function date($ts, $adj = false, $format = true, $tc = false)
 {
     $ts = wfTimestamp(TS_MW, $ts);
     if ($adj) {
         $ts = $this->userAdjust($ts, $tc);
     }
     $datePreference = $this->dateFormat($format);
     # ISO (YYYY-mm-dd) format
     #
     # we also output this format for YMD (eg: 2001 January 15)
     if ($datePreference == 'ISO 8601') {
         $d = substr($ts, 0, 4) . '-' . substr($ts, 4, 2) . '-' . substr($ts, 6, 2);
         return $d;
     }
     # dd/mm/YYYY format
     if ($datePreference == 'walloon short') {
         $d = substr($ts, 6, 2) . '/' . substr($ts, 4, 2) . '/' . substr($ts, 0, 4);
         return $d;
     }
     # Walloon format
     #
     # we output this in all other cases
     $m = substr($ts, 4, 2);
     $n = substr($ts, 6, 2);
     if ($n == 1) {
         $d = "1î d' " . $this->getMonthName($m) . " " . substr($ts, 0, 4);
     } elseif ($n == 2 || $n == 3 || $n == 20 || $n == 22 || $n == 23) {
         $d = 0 + $n . " d' " . $this->getMonthName($m) . " " . substr($ts, 0, 4);
     } elseif ($m == 4 || $m == 8 || $m == 10) {
         $d = 0 + $n . " d' " . $this->getMonthName($m) . " " . substr($ts, 0, 4);
     } else {
         $d = 0 + $n . " di " . $this->getMonthName($m) . " " . substr($ts, 0, 4);
     }
     return $d;
 }
Example #26
0
 public function execute()
 {
     $offset = $this->getArg(0) * 3600;
     $start = $this->getArg(1);
     $end = $this->getArg(2);
     $grace = 60;
     // maximum normal clock offset
     # Find bounding revision IDs
     $dbw = wfGetDB(DB_MASTER);
     $revisionTable = $dbw->tableName('revision');
     $res = $dbw->query("SELECT MIN(rev_id) as minrev, MAX(rev_id) as maxrev FROM {$revisionTable} " . "WHERE rev_timestamp BETWEEN '{$start}' AND '{$end}'", __METHOD__);
     $row = $dbw->fetchObject($res);
     if (is_null($row->minrev)) {
         $this->error("No revisions in search period.", true);
     }
     $minRev = $row->minrev;
     $maxRev = $row->maxrev;
     # Select all timestamps and IDs
     $sql = "SELECT rev_id, rev_timestamp FROM {$revisionTable} " . "WHERE rev_id BETWEEN {$minRev} AND {$maxRev}";
     if ($offset > 0) {
         $sql .= " ORDER BY rev_id DESC";
         $expectedSign = -1;
     } else {
         $expectedSign = 1;
     }
     $res = $dbw->query($sql, __METHOD__);
     $lastNormal = 0;
     $badRevs = array();
     $numGoodRevs = 0;
     foreach ($res as $row) {
         $timestamp = wfTimestamp(TS_UNIX, $row->rev_timestamp);
         $delta = $timestamp - $lastNormal;
         $sign = $delta == 0 ? 0 : $delta / abs($delta);
         if ($sign == 0 || $sign == $expectedSign) {
             // Monotonic change
             $lastNormal = $timestamp;
             ++$numGoodRevs;
             continue;
         } elseif (abs($delta) <= $grace) {
             // Non-monotonic change within grace interval
             ++$numGoodRevs;
             continue;
         } else {
             // Non-monotonic change larger than grace interval
             $badRevs[] = $row->rev_id;
         }
     }
     $numBadRevs = count($badRevs);
     if ($numBadRevs > $numGoodRevs) {
         $this->error("The majority of revisions in the search interval are marked as bad.\n\n\t\tAre you sure the offset ({$offset}) has the right sign? Positive means the clock\n\t\twas incorrectly set forward, negative means the clock was incorrectly set back.\n\n\t\tIf the offset is right, then increase the search interval until there are enough\n\t\tgood revisions to provide a majority reference.", true);
     } elseif ($numBadRevs == 0) {
         $this->output("No bad revisions found.\n");
         exit(0);
     }
     $this->output(sprintf("Fixing %d revisions (%.2f%% of revisions in search interval)\n", $numBadRevs, $numBadRevs / ($numGoodRevs + $numBadRevs) * 100));
     $fixup = -$offset;
     $sql = "UPDATE {$revisionTable} " . "SET rev_timestamp=DATE_FORMAT(DATE_ADD(rev_timestamp, INTERVAL {$fixup} SECOND), '%Y%m%d%H%i%s') " . "WHERE rev_id IN (" . $dbw->makeList($badRevs) . ')';
     $dbw->query($sql, __METHOD__);
     $this->output("Done\n");
 }
 static function MarkIndexed($title, $status)
 {
     $dbr = wfGetDB(DB_SLAVE);
     $dbw = wfGetDB(DB_MASTER);
     if ($title == null) {
         return true;
     }
     $date = wfTimestamp(TS_MW);
     $indexed = $dbr->selectField(NewlyIndexed::TABLE_NAME, NewlyIndexed::INDEX_FIELD, array(NewlyIndexed::PAGE_FIELD => $title->getArticleID()), __FUNCTION__);
     if ($indexed === false) {
         //row doesn't exist yet
         if ($status == RobotPolicy::POLICY_INDEX_FOLLOW_STR) {
             //has now been indexed, so add the new row
             $dbw->insert(NewlyIndexed::TABLE_NAME, array(NewlyIndexed::PAGE_FIELD => $title->getArticleID(), NewlyIndexed::INDEX_FIELD => $date, NewlyIndexed::NAB_FIELD => 0), __METHOD__);
         }
     } else {
         if ($status != RobotPolicy::POLICY_INDEX_FOLLOW_STR) {
             $date = 0;
         }
         //either its already index and needs to be be-indexed OR it hasn't been indexed and now it is
         if ($indexed > 0 && $date == 0 || $indexed == 0 && $date > 0) {
             $dbw->update(NewlyIndexed::TABLE_NAME, array(NewlyIndexed::INDEX_FIELD => $date), array(NewlyIndexed::PAGE_FIELD => $title->getArticleID()), __METHOD__);
         }
     }
     return true;
 }
/**
 * Set $wgDebugLogGroups['UploadBlacklist'] to direct logging to a particular
 * file instead of the debug log.
 *
 * @param string $action
 * @param string $hash
 * @param string $saveName
 * @param string $tempName
 * @access private
 */
function ubLog( $action, $hash, $saveName, $tempName ) {
	global $wgUser;
	$user = $wgUser->getName();
	$ip = wfGetIP();
	$ts = wfTimestamp( TS_DB );
	wfDebugLog( 'UploadBlacklist', "$ts $action [$hash] name:$saveName file:$tempName user:$user ip:$ip" );
}
Example #29
0
 public function execute()
 {
     $posFile = $this->getOption('p', 'searchUpdate.' . wfWikiId() . '.pos');
     $end = $this->getOption('e', wfTimestampNow());
     if ($this->hasOption('s')) {
         $start = $this->getOption('s');
     } elseif (is_readable('searchUpdate.pos')) {
         # B/c to the old position file name which was hardcoded
         # We can safely delete the file when we're done though.
         $start = file_get_contents('searchUpdate.pos');
         unlink('searchUpdate.pos');
     } elseif (is_readable($posFile)) {
         $start = file_get_contents($posFile);
     } else {
         $start = wfTimestamp(TS_MW, time() - 86400);
     }
     $lockTime = $this->getOption('l', 20);
     $this->doUpdateSearchIndex($start, $end, $lockTime);
     if (is_writable(dirname(realpath($posFile)))) {
         $file = fopen($posFile, 'w');
         if ($file !== false) {
             fwrite($file, $end);
             fclose($file);
         } else {
             $this->error("*** Couldn't write to the {$posFile}!\n");
         }
     } else {
         $this->error("*** Couldn't write to the {$posFile}!\n");
     }
 }
/**
 * Get the number of revisions a user has made since a given time
 *
 * @param $fromtime: beginning timestamp
 * @param $user User: (optional) User object to get edit count for
 * @param $totime: (optional) ending timestamp
 * @return number of revsions this user has made
 */
function getUserEditCountSince( $fromtime = null, User $user = null, $totime = null ) {
	global $wgUser;

	// Fallback on current user
	if ( is_null( $user ) ) {
		$user = $wgUser;
	}

	// Round times down to a whole day, possibly letting a null value
	// pass to wfTimestamp which will give us today.
	$fromtime = gmdate( 'Y-m-d', wfTimestamp( TS_UNIX, $fromtime ) );
	$totime = gmdate( 'Y-m-d', wfTimestamp( TS_UNIX, $totime ) );

	// Query the user contribs table
	$dbr = wfGetDB( DB_SLAVE );
	$edits = $dbr->selectField(
		'user_daily_contribs',
		'SUM(contribs)',
		array(
			'user_id' => $user->getId(),
			'day >= ' . $dbr->addQuotes( $fromtime ),
			'day <= ' . $dbr->addQuotes( $totime )
		),
		__METHOD__
	);
	// Return edit count as an integer
	return is_null( $edits ) ? 0 : (integer) $edits;
}