コード例 #1
0
ファイル: Misc.body.php プロジェクト: ErdemA/wikihow
 public static function adminPostTalkMessage($to_user, $from_user, $comment)
 {
     global $wgLang;
     $existing_talk = '';
     //make sure we have everything we need...
     if (empty($to_user) || empty($from_user) || empty($comment)) {
         return false;
     }
     $from = $from_user->getName();
     if (!$from) {
         return false;
     }
     //whoops
     $from_realname = $from_user->getRealName();
     $dateStr = $wgLang->date(wfTimestampNow());
     $formattedComment = wfMsg('postcomment_formatted_comment', $dateStr, $from, $from_realname, $comment);
     $talkPage = $to_user->getUserPage()->getTalkPage();
     if ($talkPage->getArticleId() > 0) {
         $r = Revision::newFromTitle($talkPage);
         $existing_talk = $r->getText() . "\n\n";
     }
     $text = $existing_talk . $formattedComment . "\n\n";
     $flags = EDIT_FORCE_BOT | EDIT_SUPPRESS_RC;
     $article = new Article($talkPage);
     $result = $article->doEdit($text, "", $flags);
     return $result;
 }
コード例 #2
0
ファイル: ApiSubmitSurvey.php プロジェクト: Tjorriemorrie/app
 public function execute()
 {
     global $wgUser;
     if (!$wgUser->isAllowed('surveysubmit') || $wgUser->isBlocked()) {
         $this->dieUsageMsg(array('badaccess-groups'));
     }
     $params = $this->extractRequestParams();
     if (!(isset($params['id']) xor isset($params['name']))) {
         $this->dieUsage(wfMsg('survey-err-id-xor-name'), 'id-xor-name');
     }
     if (isset($params['name'])) {
         $survey = Survey::newFromName($params['name'], null, false);
         if ($survey === false) {
             $this->dieUsage(wfMsgExt('survey-err-survey-name-unknown', 'parsemag', $params['name']), 'survey-name-unknown');
         }
     } else {
         $survey = Survey::newFromId($params['id'], null, false);
         if ($survey === false) {
             $this->dieUsage(wfMsgExt('survey-err-survey-id-unknown', 'parsemag', $params['id']), 'survey-id-unknown');
         }
     }
     $submission = new SurveySubmission(array('survey_id' => $survey->getId(), 'page_id' => 0, 'user_name' => $GLOBALS['wgUser']->getName(), 'time' => wfTimestampNow()));
     foreach (FormatJson::decode($params['answers']) as $answer) {
         $submission->addAnswer(SurveyAnswer::newFromArray((array) $answer));
     }
     $submission->writeToDB();
 }
コード例 #3
0
	public static function handleAFAction( $action, $parameters, $title, $vars, $rule_desc ) {
		global $wgUser;
		
		$dbw = wfGetDB( DB_MASTER );
		$dbQuery = array(
			'pmq_id' => '',
			'pmq_page_last_id' => $title->getLatestRevID(),
			'pmq_page_ns' => $title->getNamespace(),
			'pmq_page_title' => $title->getDBkey(),
			'pmq_user' => $wgUser->getID(),
			'pmq_user_text' => $wgUser->getName(),
			'pmq_timestamp' => $dbw->timestamp( wfTimestampNow() ),
			'pmq_minor' => $vars->getVar( 'minor_edit' )->toInt(),
			'pmq_summary' => $vars->getVar( 'summary' )->toString(),
			'pmq_len' => $title->getLength(),
			'pmq_text' => $vars->getVar( 'new_wikitext' )->toString(),
			'pmq_flags' => false,
			'pmq_ip' => wfGetIP(),
			'pmq_status' => 'new'
		);
		$dbw->insert( 'pm_queue', $dbQuery, __METHOD__ );
		$dbw->commit();
		
		return true;
	}
コード例 #4
0
 /**
  * (non-PHPdoc)
  * @see EPDBObject::loadSummaryFields()
  */
 public function loadSummaryFields($summaryFields = null)
 {
     if (is_null($summaryFields)) {
         $summaryFields = array('courses', 'terms', 'students', 'active');
     } else {
         $summaryFields = (array) $summaryFields;
     }
     $fields = array();
     if (in_array('courses', $summaryFields)) {
         $fields['courses'] = EPCourse::count(array('org_id' => $this->getId()));
     }
     if (in_array('terms', $summaryFields)) {
         $fields['terms'] = EPTerm::count(array('org_id' => $this->getId()));
     }
     $dbr = wfGetDB(DB_SLAVE);
     if (in_array('students', $summaryFields)) {
         $termIds = EPTerm::selectFields('id', array('org_id' => $this->getId()));
         if (count($termIds) > 0) {
             $fields['students'] = $dbr->select('ep_students_per_term', 'COUNT(*) AS rowcount', array('spt_term_id' => $termIds));
             $fields['students'] = $fields['students']->fetchObject()->rowcount;
         } else {
             $fields['students'] = 0;
         }
     }
     if (in_array('active', $summaryFields)) {
         $now = wfGetDB(DB_SLAVE)->addQuotes(wfTimestampNow());
         $fields['active'] = EPTerm::has(array('org_id' => $this->getId(), 'end >= ' . $now, 'start <= ' . $now));
     }
     $this->setFields($fields);
 }
コード例 #5
0
 public static function calcRecommendations($filename, $limit = false)
 {
     $f = fopen($filename, "w");
     $stubs = Recommendations::findStubs($limit);
     $r = new Recommendations();
     $r->excludeWorstRelated(250);
     $userScore = array();
     foreach ($stubs as $stub) {
         if ($stub) {
             $userScore = $r->getSuggestedUsers($stub);
             arsort($userScore);
             foreach ($userScore as $username => $score) {
                 if (Recommendations::isAvailableUser($username)) {
                     print wfTimestampNow() . " Adding recommendation to edit " . $stub->getText() . " for user " . $username . "\n";
                     $u = User::newFromId($username);
                     if ($u && $u->getId()) {
                         fwrite($f, $u->getId() . "\t" . $stub->getArticleId() . "\t" . $score);
                         $reasons = $r->getSuggestionReason($username, $stub->getArticleId());
                         foreach ($reasons as $reason) {
                             fwrite($f, "\t" . $reason);
                         }
                         fwrite($f, "\n");
                     }
                 }
             }
         }
     }
 }
コード例 #6
0
ファイル: SpecialCacheEpoch.php プロジェクト: yusufchang/app
 public function execute($subpage)
 {
     global $wgOut, $wgRequest, $wgUser, $wgCacheEpoch, $wgCityId;
     wfProfileIn(__METHOD__);
     $this->setHeaders();
     $this->mTitle = SpecialPage::getTitleFor('cacheepoch');
     if ($this->isRestricted() && !$this->userCanExecute($wgUser)) {
         $this->displayRestrictionError();
         wfProfileOut(__METHOD__);
         return;
     }
     //no WikiFactory (internal wikis)
     if (empty($wgCityId)) {
         $wgOut->addHTML(wfMsg('cacheepoch-no-wf'));
         wfProfileOut(__METHOD__);
         return;
     }
     if ($wgRequest->wasPosted()) {
         $wgCacheEpoch = wfTimestampNow();
         $status = WikiFactory::setVarByName('wgCacheEpoch', $wgCityId, $wgCacheEpoch, wfMsg('cacheepoch-wf-reason'));
         if ($status) {
             $wgOut->addHTML('<h2>' . wfMsg('cacheepoch-updated', $wgCacheEpoch) . '</h2>');
         } else {
             $wgOut->addHTML('<h2>' . wfMsg('cacheepoch-not-updated') . '</h2>');
         }
     } else {
         $wgOut->addHTML('<h2>' . wfMsg('cacheepoch-header') . '</h2>');
     }
     $wgOut->addHTML(Xml::openElement('form', array('action' => $this->mTitle->getFullURL(), 'method' => 'post')));
     $wgOut->addHTML(wfMsg('cacheepoch-value', $wgCacheEpoch) . '<br>');
     $wgOut->addHTML(Xml::submitButton(wfMsg('cacheepoch-submit')));
     $wgOut->addHTML(Xml::closeElement('form'));
     wfProfileOut(__METHOD__);
 }
コード例 #7
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");
     }
 }
コード例 #8
0
 /**
  * Adds this new notification object to the backend storage.
  */
 protected function insert()
 {
     global $wgEchoBackend, $wgEchoNotifications;
     $row = array('notification_event' => $this->event->getId(), 'notification_user' => $this->user->getId(), 'notification_anon_ip' => $this->user->isAnon() ? $this->user->getName() : $this->user->getId(), 'notification_timestamp' => $this->timestamp, 'notification_read_timestamp' => $this->readTimestamp, 'notification_bundle_hash' => '', 'notification_bundle_display_hash' => '');
     // Get the bundle key for this event if web bundling is enabled
     $bundleKey = '';
     if (!empty($wgEchoNotifications[$this->event->getType()]['bundle']['web'])) {
         wfRunHooks('EchoGetBundleRules', array($this->event, &$bundleKey));
     }
     if ($bundleKey) {
         $hash = md5($bundleKey);
         $row['notification_bundle_hash'] = $hash;
         $lastStat = $wgEchoBackend->getLastBundleStat($this->user, $hash);
         // Use a new display hash if:
         // 1. there was no last bundle notification
         // 2. last bundle notification with the same hash was read
         if ($lastStat && !$lastStat->notification_read_timestamp) {
             $row['notification_bundle_display_hash'] = $lastStat->notification_bundle_display_hash;
         } else {
             $row['notification_bundle_display_hash'] = md5($bundleKey . '-display-hash-' . wfTimestampNow());
         }
     }
     $wgEchoBackend->createNotification($row);
     wfRunHooks('EchoCreateNotificationComplete', array($this));
 }
コード例 #9
0
 /**
  * Get page configuration settings from a DB row
  */
 public static function getVisibilitySettingsFromRow($row)
 {
     if ($row) {
         # This code should be refactored, now that it's being used more generally.
         $expiry = Block::decodeExpiry($row->fpc_expiry);
         # Only apply the settings if they haven't expired
         if (!$expiry || $expiry < wfTimestampNow()) {
             $row = null;
             // expired
             self::purgeExpiredConfigurations();
         }
     }
     // Is there a non-expired row?
     if ($row) {
         $level = $row->fpc_level;
         if (!self::isValidRestriction($row->fpc_level)) {
             $level = '';
             // site default; ignore fpc_level
         }
         $config = array('override' => $row->fpc_override ? 1 : 0, 'autoreview' => $level, 'expiry' => Block::decodeExpiry($row->fpc_expiry));
         # If there are protection levels defined check if this is valid...
         if (FlaggedRevs::useProtectionLevels()) {
             $level = self::getProtectionLevel($config);
             if ($level == 'invalid' || $level == 'none') {
                 // If 'none', make sure expiry is 'infinity'
                 $config = self::getDefaultVisibilitySettings();
                 // revert to default (none)
             }
         }
     } else {
         # Return the default config if this page doesn't have its own
         $config = self::getDefaultVisibilitySettings();
     }
     return $config;
 }
コード例 #10
0
 function csvOutput($res)
 {
     global $wgOut, $wgRequest;
     $ts = wfTimestampNow();
     $filename = "community_applications_{$ts}.csv";
     $wgOut->disable();
     wfResetOutputBuffers();
     $wgRequest->response()->header("Content-disposition: attachment;filename={$filename}");
     $wgRequest->response()->header("Content-type: text/csv; charset=utf-8");
     $fh = fopen('php://output', 'w');
     $fields = null;
     foreach ($res as $row) {
         $data = FormatJson::decode($row->ch_data, true);
         $data = array('id' => $row->ch_id) + $data;
         if (!is_array($fields)) {
             $fields = array_keys($data);
             fputcsv($fh, $fields);
         }
         $outData = array();
         foreach ($fields as $k) {
             $outData[] = isset($data[$k]) ? $data[$k] : null;
             unset($data[$k]);
         }
         foreach ($data as $k => $v) {
             $outData[] = "{$k}: {$v}";
         }
         fputcsv($fh, $outData);
     }
     fclose($fh);
 }
コード例 #11
0
function ActivityFeedTag_render($content, $attributes, $parser, $frame)
{
    global $wgExtensionsPath, $wgEnableAchievementsInActivityFeed, $wgEnableAchievementsExt;
    if (!class_exists('ActivityFeedHelper')) {
        return '';
    }
    wfProfileIn(__METHOD__);
    $parameters = ActivityFeedHelper::parseParameters($attributes);
    $tagid = str_replace('.', '_', uniqid('activitytag_', true));
    //jQuery might have a problem with . in ID
    $jsParams = "size={$parameters['maxElements']}";
    if (!empty($parameters['includeNamespaces'])) {
        $jsParams .= "&ns={$parameters['includeNamespaces']}";
    }
    if (!empty($parameters['flags'])) {
        $jsParams .= '&flags=' . implode('|', $parameters['flags']);
    }
    $parameters['tagid'] = $tagid;
    $feedHTML = ActivityFeedHelper::getList($parameters);
    $style = empty($parameters['style']) ? '' : ' style="' . $parameters['style'] . '"';
    $timestamp = wfTimestampNow();
    $snippetsDependencies = array('/extensions/wikia/MyHome/ActivityFeedTag.js', '/extensions/wikia/MyHome/ActivityFeedTag.css');
    if (!empty($wgEnableAchievementsInActivityFeed) && !empty($wgEnableAchievementsExt)) {
        array_push($snippetsDependencies, '/extensions/wikia/AchievementsII/css/achievements_sidebar.css');
    }
    $snippets = F::build('JSSnippets')->addToStack($snippetsDependencies, null, 'ActivityFeedTag.initActivityTag', array('tagid' => $tagid, 'jsParams' => $jsParams, 'timestamp' => $timestamp));
    wfProfileOut(__METHOD__);
    return "<div{$style}>{$feedHTML}</div>{$snippets}";
}
コード例 #12
0
 function getDateCond()
 {
     if ($this->year || $this->month) {
         // Assume this year if only a month is given
         if ($this->year) {
             $year_start = $this->year;
         } else {
             $year_start = substr(wfTimestampNow(), 0, 4);
             $thisMonth = gmdate('n');
             if ($this->month > $thisMonth) {
                 // Future contributions aren't supposed to happen. :)
                 $year_start--;
             }
         }
         if ($this->month) {
             $month_end = str_pad($this->month + 1, 2, '0', STR_PAD_LEFT);
             $year_end = $year_start;
         } else {
             $month_end = 0;
             $year_end = $year_start + 1;
         }
         $ts_end = str_pad($year_end . $month_end, 14, '0');
         $this->mOffset = $ts_end;
     }
 }
コード例 #13
0
 /**
  * Handles group notification.
  *
  * @since 0.1
  *
  * @param SWLGroup $group
  * @param array $userIDs
  * @param SMWChangeSet $changes
  *
  * @return true
  */
 public static function onGroupNotify(SWLGroup $group, array $userIDs, SWLChangeSet $changes)
 {
     global $egSWLMailPerChange, $egSWLMaxMails;
     foreach ($userIDs as $userID) {
         $user = User::newFromId($userID);
         if ($user->getOption('swl_email', false)) {
             if ($user->getName() != $changes->getEdit()->getUser()->getName() || $GLOBALS['egSWLEnableSelfNotify']) {
                 if (!method_exists('Sanitizer', 'validateEmail') || Sanitizer::validateEmail($user->getEmail())) {
                     $lastNotify = $user->getOption('swl_last_notify');
                     $lastWatch = $user->getOption('swl_last_watch');
                     if (is_null($lastNotify) || is_null($lastWatch) || $lastNotify < $lastWatch) {
                         $mailCount = $user->getOption('swl_mail_count', 0);
                         if ($egSWLMailPerChange || $mailCount < $egSWLMaxMails) {
                             SWLEmailer::notifyUser($group, $user, $changes, $egSWLMailPerChange);
                             $user->setOption('swl_last_notify', wfTimestampNow());
                             $user->setOption('swl_mail_count', $mailCount + 1);
                             $user->saveSettings();
                         }
                     }
                 }
             }
         }
     }
     return true;
 }
コード例 #14
0
 /**
  * Insert to the logging table
  * @param array $values Values to be entered to the DB
  * @return bool True/False on query success/fail
  */
 public static function insertLogRecord($values)
 {
     $logValues = array('pa_page_id' => $values['pa_page_id'], 'pa_user_id' => $values['pa_user'], 'pa_page_revision' => $values['pa_page_revision'], 'pa_project' => $values['pa_project'], 'pa_class' => $values['pa_class'], 'pa_importance' => $values['pa_importance'], 'pa_timestamp' => wfTimestampNow());
     $dbw = wfGetDB(DB_MASTER);
     $dbw->insert('page_assessments_log', $logValues, __METHOD__);
     return true;
 }
コード例 #15
0
ファイル: GedcomExportJob.php プロジェクト: k-hasan-19/wiki
 /**
  * Run a refreshLinks job
  * @return boolean success
  */
 function run()
 {
     global $wgTitle, $wgUser, $wgLang, $wrGedcomExportDirectory;
     $wgTitle = $this->title;
     // FakeTitle (the default) generates errors when accessed, and sometimes I log wgTitle, so set it to something else
     $wgUser = User::newFromName('WeRelate agent');
     // set the user
     $treeId = $this->params['tree_id'];
     $treeName = $this->params['name'];
     $treeUser = $this->params['user'];
     $filename = "{$wrGedcomExportDirectory}/{$treeId}.ged";
     $ge = new GedcomExporter();
     $error = $ge->exportGedcom($treeId, $filename);
     if ($error) {
         $this->error = $error;
         return false;
     }
     // leave a message for the tree requester
     $userTalkTitle = Title::newFromText($treeUser, NS_USER_TALK);
     $article = new Article($userTalkTitle, 0);
     if ($article->getID() != 0) {
         $text = $article->getContent();
     } else {
         $text = '';
     }
     $title = Title::makeTitle(NS_SPECIAL, 'Trees');
     $msg = wfMsg('GedcomExportReady', $wgLang->date(wfTimestampNow(), true, false), $treeName, $title->getFullURL(wfArrayToCGI(array('action' => 'downloadExport', 'user' => $treeUser, 'name' => $treeName))));
     $text .= "\n\n" . $msg;
     $success = $article->doEdit($text, 'GEDCOM export ready');
     if (!$success) {
         $this->error = 'Unable to edit user talk page: ' . $treeUser;
         return false;
     }
     return true;
 }
コード例 #16
0
 /**
  * Inserts a filter into stub database.
  *
  * @param string $pattern
  * @param string[optional] $action
  */
 protected function createFilter($pattern, $action = 'disallow')
 {
     global $wgFlowAbuseFilterGroup;
     $user = User::newFromName('UTSysop');
     $this->db->replace('abuse_filter', array('af_id'), array('af_pattern' => $pattern, 'af_user' => $user->getId(), 'af_user_text' => $user->getName(), 'af_timestamp' => wfTimestampNow(), 'af_enabled' => 1, 'af_comments' => null, 'af_public_comments' => 'Test filter', 'af_hidden' => 0, 'af_hit_count' => 0, 'af_throttled' => 0, 'af_deleted' => 0, 'af_actions' => $action, 'af_group' => $wgFlowAbuseFilterGroup), __METHOD__);
     $this->db->replace('abuse_filter_action', array('afa_filter'), array('afa_filter' => $this->db->insertId(), 'afa_consequence' => $action, 'afa_parameters' => ''), __METHOD__);
 }
コード例 #17
0
ファイル: QuizImport.php プロジェクト: biribogos/wikihow-src
 private function saveQuizAsBlob($name, $icon, $quiz)
 {
     if (empty($name) || empty($quiz)) {
         return;
     }
     $quiz_array = array('quiz_name' => $name, 'quiz_icon' => $icon, 'quiz_data' => json_encode($quiz), 'quiz_stamp' => wfTimestampNow());
     $dbr = wfGetDB(DB_SLAVE);
     $dbw = wfGetDB(DB_MASTER);
     //is that quiz already in there?
     $count = $dbr->selectField('quizzes', 'count(*) as count', array('quiz_name' => $name), __METHOD);
     if ($count > 0) {
         //it's there. update it...
         $res = $dbw->update('quizzes', $quiz_array, array('quiz_name' => $name), __METHOD__);
         self::$import_array[] = 'UPDATED: http://www.wikihow.com/Quiz/' . $name;
     } else {
         //brand spanking new (so to speak)
         $res = $dbw->insert('quizzes', $quiz_array, __METHOD__);
         self::$import_array[] = 'NEW: http://www.wikihow.com/Quiz/' . $name;
     }
     //delete any cached version of these exists just to be safe
     global $wgMemc;
     $memkey = wfMemcKey('quiz', $name);
     $wgMemc->delete($memkey);
     print 'QUIZ: ' . $name . "\n";
 }
コード例 #18
0
ファイル: ThreadRevision.php プロジェクト: Rikuforever/wiki
 static function create($thread, $change_type, $change_object = null, $comment = '', $user = null, $timestamp = null)
 {
     if (is_null($user)) {
         global $wgUser;
         $user = $wgUser;
     }
     if (is_null($timestamp)) {
         $timestamp = wfTimestampNow();
     }
     if (is_null($comment)) {
         $comment = '';
     }
     $rev = new ThreadRevision();
     $rev->mThreadId = $thread->topmostThread()->id();
     $rev->mTimestamp = $timestamp;
     $rev->mUser = $user;
     $rev->mUserId = $user->getId();
     $rev->mUserText = $user->getName();
     $rev->mChangeType = $change_type;
     if ($change_object instanceof Thread) {
         $rev->mChangeObjectId = $change_object->id();
         $rev->mChangeObject = $change_object;
     } elseif (is_null($change_object)) {
         $rev->mChangeObjectId = $thread->id();
         $rev->mChangeObject = $thread;
     } else {
         $rev->mChangeObjectId = $change_object;
     }
     $rev->mChangeComment = $comment;
     $rev->mThreadObj = $thread->topmostThread();
     $rev->mObjSer = serialize($rev->mThreadObj);
     $rev->insert();
     return $rev;
 }
コード例 #19
0
 function saveContent()
 {
     if (wfReadOnly()) {
         return false;
     }
     global $wgUser;
     $fname = 'LogPage::saveContent';
     $dbw = wfGetDB(DB_MASTER);
     $uid = $wgUser->getID();
     $log_id = $dbw->nextSequenceValue('log_log_id_seq');
     $this->timestamp = $now = wfTimestampNow();
     $data = array('log_type' => $this->type, 'log_action' => $this->action, 'log_timestamp' => $dbw->timestamp($now), 'log_user' => $uid, 'log_namespace' => $this->target->getNamespace(), 'log_title' => $this->target->getDBkey(), 'log_comment' => $this->comment, 'log_params' => $this->params);
     # log_id doesn't exist on Wikimedia servers yet, and it's a tricky
     # schema update to do. Hack it for now to ignore the field on MySQL.
     if (!is_null($log_id)) {
         $data['log_id'] = $log_id;
     }
     $dbw->insert('logging', $data, $fname);
     # And update recentchanges
     if ($this->updateRecentChanges) {
         $titleObj = SpecialPage::getTitleFor('Log', $this->type);
         $rcComment = $this->getRcComment();
         RecentChange::notifyLog($now, $titleObj, $wgUser, $rcComment, '', $this->type, $this->action, $this->target, $this->comment, $this->params);
     }
     return true;
 }
コード例 #20
0
 /**
  * @param Title $pageTitle Title instance of the categorized page
  * @param Revision $revision Latest Revision instance of the categorized page
  *
  * @throws MWException
  */
 public function __construct(Title $pageTitle, Revision $revision = null)
 {
     $this->pageTitle = $pageTitle;
     $this->timestamp = wfTimestampNow();
     $this->revision = $revision;
     $this->newForCategorizationCallback = array('RecentChange', 'newForCategorization');
 }
コード例 #21
0
ファイル: LogPage.php プロジェクト: puring0815/OpenKore
 function saveContent()
 {
     if (wfReadOnly()) {
         return false;
     }
     global $wgUser;
     $fname = 'LogPage::saveContent';
     $dbw =& wfGetDB(DB_MASTER);
     $uid = $wgUser->getID();
     $this->timestamp = $now = wfTimestampNow();
     $dbw->insert('logging', array('log_type' => $this->type, 'log_action' => $this->action, 'log_timestamp' => $dbw->timestamp($now), 'log_user' => $uid, 'log_namespace' => $this->target->getNamespace(), 'log_title' => $this->target->getDBkey(), 'log_comment' => $this->comment, 'log_params' => $this->params), $fname);
     # And update recentchanges
     if ($this->updateRecentChanges) {
         $titleObj = Title::makeTitle(NS_SPECIAL, 'Log/' . $this->type);
         $rcComment = $this->actionText;
         if ('' != $this->comment) {
             if ($rcComment == '') {
                 $rcComment = $this->comment;
             } else {
                 $rcComment .= ': ' . $this->comment;
             }
         }
         RecentChange::notifyLog($now, $titleObj, $wgUser, $rcComment, '', $this->type, $this->action, $this->target, $this->comment, $this->params);
     }
     return true;
 }
コード例 #22
0
ファイル: LogPage.php プロジェクト: eFFemeer/seizamcore
 /**
  * @return bool|int|null
  */
 protected function saveContent()
 {
     global $wgLogRestrictions;
     $dbw = wfGetDB(DB_MASTER);
     $log_id = $dbw->nextSequenceValue('logging_log_id_seq');
     $this->timestamp = $now = wfTimestampNow();
     $data = array('log_id' => $log_id, 'log_type' => $this->type, 'log_action' => $this->action, 'log_timestamp' => $dbw->timestamp($now), 'log_user' => $this->doer->getId(), 'log_user_text' => $this->doer->getName(), 'log_namespace' => $this->target->getNamespace(), 'log_title' => $this->target->getDBkey(), 'log_page' => $this->target->getArticleId(), 'log_comment' => $this->comment, 'log_params' => $this->params);
     $dbw->insert('logging', $data, __METHOD__);
     $newId = !is_null($log_id) ? $log_id : $dbw->insertId();
     # And update recentchanges
     if ($this->updateRecentChanges) {
         $titleObj = SpecialPage::getTitleFor('Log', $this->type);
         RecentChange::notifyLog($now, $titleObj, $this->doer, $this->getRcComment(), '', $this->type, $this->action, $this->target, $this->comment, $this->params, $newId);
     } elseif ($this->sendToUDP) {
         # Don't send private logs to UDP
         if (isset($wgLogRestrictions[$this->type]) && $wgLogRestrictions[$this->type] != '*') {
             return true;
         }
         # Notify external application via UDP.
         # We send this to IRC but do not want to add it the RC table.
         $titleObj = SpecialPage::getTitleFor('Log', $this->type);
         $rc = RecentChange::newLogEntry($now, $titleObj, $this->doer, $this->getRcComment(), '', $this->type, $this->action, $this->target, $this->comment, $this->params, $newId);
         $rc->notifyRC2UDP();
     }
     return $newId;
 }
コード例 #23
0
 /**
  * Initialiser for new MBFeedbackItems
  * @param $info Associative array of values
  * @see MBFeedbackItem::create
  */
 protected function initialiseNew($info)
 {
     global $wgUser;
     $template = array('user' => $wgUser, 'timestamp' => wfTimestampNow());
     $this->setProperties($template);
     $this->setProperties($info);
 }
コード例 #24
0
 /**
  * Monitors edit page usage
  */
 public static function onEditForm(EditPage $editPage)
 {
     global $wgUser, $wgEditPageTrackingRegistrationCutoff, $wgMemc;
     // Anonymous users
     if ($wgUser->isAnon()) {
         return true;
     }
     if ($wgEditPageTrackingRegistrationCutoff && $wgUser->getRegistration() < $wgEditPageTrackingRegistrationCutoff) {
         // User registered before the cutoff
         return true;
     }
     if (EditPageTracking::getFirstEditPage($wgUser)) {
         // Already stored.
         return true;
     }
     // Record it
     $dbw = wfGetDB(DB_MASTER);
     $title = $editPage->getArticle()->getTitle();
     $timestamp = wfTimestampNow();
     $row = array('ept_user' => $wgUser->getId(), 'ept_namespace' => $title->getNamespace(), 'ept_title' => $title->getDBkey(), 'ept_timestamp' => $dbw->timestamp($timestamp));
     $dbw->insert('edit_page_tracking', $row, __METHOD__);
     $wgUser->mFirstEditPage = $timestamp;
     $cacheKey = wfMemcKey('first-edit-page', $wgUser->getId());
     $wgMemc->set($cacheKey, $timestamp, 86400);
     return true;
 }
コード例 #25
0
 public function execute()
 {
     $out = $this->mSpecial->getOutput();
     $dbw = wfGetDB(DB_MASTER);
     $row = $dbw->selectRow('moderation', array('mod_user AS user', 'mod_user_text AS user_text'), array('mod_id' => $this->id), __METHOD__);
     if (!$row) {
         throw new ModerationError('moderation-edit-not-found');
     }
     $dbw = wfGetDB(DB_MASTER);
     if ($this->actionName == 'block') {
         $dbw->replace('moderation_block', array('mb_address'), array('mb_address' => $row->user_text, 'mb_user' => $row->user, 'mb_by' => $this->moderator->getId(), 'mb_by_text' => $this->moderator->getName(), 'mb_timestamp' => $dbw->timestamp(wfTimestampNow())), __METHOD__);
         $logEntry = new ManualLogEntry('moderation', 'block');
     } else {
         $dbw->delete('moderation_block', array('mb_address' => $row->user_text), __METHOD__);
         $logEntry = new ManualLogEntry('moderation', 'unblock');
     }
     $nrows = $dbw->affectedRows();
     if ($nrows > 0) {
         $logEntry->setPerformer($this->moderator);
         $logEntry->setTarget(Title::makeTitle(NS_USER, $row->user_text));
         $logid = $logEntry->insert();
         $logEntry->publish($logid);
     }
     $out->addWikiMsg('moderation-' . ($this->actionName == 'unblock' ? 'un' : '') . 'block-' . ($nrows ? 'ok' : 'fail'), $row->user_text);
 }
コード例 #26
0
 protected function parseWikitext($title, $newRevId)
 {
     $apiParams = array('action' => 'parse', 'page' => $title->getPrefixedDBkey(), 'oldid' => $newRevId, 'prop' => 'text|revid|categorieshtml|displaytitle|modules|jsconfigvars');
     $api = new ApiMain(new DerivativeRequest($this->getRequest(), $apiParams, false), true);
     $api->execute();
     if (defined('ApiResult::META_CONTENT')) {
         $result = $api->getResult()->getResultData(null, array('BC' => array(), 'Types' => array(), 'Strip' => 'all'));
     } else {
         $result = $api->getResultData();
     }
     $content = isset($result['parse']['text']['*']) ? $result['parse']['text']['*'] : false;
     $categorieshtml = isset($result['parse']['categorieshtml']['*']) ? $result['parse']['categorieshtml']['*'] : false;
     $links = isset($result['parse']['links']) ? $result['parse']['links'] : array();
     $revision = Revision::newFromId($result['parse']['revid']);
     $timestamp = $revision ? $revision->getTimestamp() : wfTimestampNow();
     $displaytitle = isset($result['parse']['displaytitle']) ? $result['parse']['displaytitle'] : false;
     $modules = isset($result['parse']['modules']) ? $result['parse']['modules'] : array();
     $jsconfigvars = isset($result['parse']['jsconfigvars']) ? $result['parse']['jsconfigvars'] : array();
     if ($content === false || strlen($content) && $revision === null) {
         return false;
     }
     if ($displaytitle !== false) {
         // Escape entities as in OutputPage::setPageTitle()
         $displaytitle = Sanitizer::normalizeCharReferences(Sanitizer::removeHTMLtags($displaytitle));
     }
     return array('content' => $content, 'categorieshtml' => $categorieshtml, 'basetimestamp' => $timestamp, 'starttimestamp' => wfTimestampNow(), 'displayTitleHtml' => $displaytitle, 'modules' => $modules, 'jsconfigvars' => $jsconfigvars);
 }
コード例 #27
0
ファイル: ImageFeedback.body.php プロジェクト: ErdemA/wikihow
 private function showAdminForm()
 {
     global $wgOut;
     EasyTemplate::set_path(dirname(__FILE__));
     $vars['ts'] = wfTimestampNow();
     $wgOut->addHtml(EasyTemplate::html('imagefeedback_admin'));
 }
コード例 #28
0
 function showList()
 {
     global $wgOut, $wgScript;
     $errors = array();
     // Validate search IP
     $ip = $this->mSearchIP;
     if (!IP::isIPAddress($ip) && strlen($ip)) {
         $errors[] = array('globalblocking-list-ipinvalid', $ip);
         $ip = '';
     }
     $wgOut->addWikiMsg('globalblocking-list-intro');
     // Build the search form
     $searchForm = '';
     $searchForm .= Xml::openElement('fieldset') . Xml::element('legend', null, wfMsg('globalblocking-search-legend'));
     $searchForm .= Xml::openElement('form', array('method' => 'get', 'action' => $wgScript, 'name' => 'globalblocklist-search'));
     $searchForm .= Html::hidden('title', SpecialPage::getTitleFor('GlobalBlockList')->getPrefixedText());
     if (is_array($errors) && count($errors) > 0) {
         $errorstr = '';
         foreach ($errors as $error) {
             if (is_array($error)) {
                 $msg = array_shift($error);
             } else {
                 $msg = $error;
                 $error = array();
             }
             $errorstr .= Xml::tags('li', null, wfMsgExt($msg, array('parseinline'), $error));
         }
         $wgOut->addWikiMsg('globalblocking-unblock-errors', count($errors));
         $wgOut->addHTML(Xml::tags('ul', array('class' => 'error'), $errorstr));
     }
     $fields = array();
     $fields['globalblocking-search-ip'] = Xml::input('ip', 45, $ip);
     $searchForm .= Xml::buildForm($fields, 'globalblocking-search-submit');
     $searchForm .= Xml::closeElement('form') . Xml::closeElement('fieldset');
     $wgOut->addHTML($searchForm);
     // Build a list of blocks.
     $conds = array();
     if (strlen($ip)) {
         list($range_start, $range_end) = IP::parseRange($ip);
         if ($range_start != $range_end) {
             // They searched for a range. Match that exact range only
             $conds = array('gb_address' => $ip);
         } else {
             // They searched for an IP. Match any range covering that IP
             $hex_ip = IP::toHex($ip);
             $ip_pattern = substr($hex_ip, 0, 4) . '%';
             // Don't bother checking blocks out of this /16.
             $dbr = wfGetDB(DB_SLAVE);
             $conds = array('gb_range_end>=' . $dbr->addQuotes($hex_ip), 'gb_range_start<=' . $dbr->addQuotes($hex_ip), 'gb_range_start like ' . $dbr->addQuotes($ip_pattern), 'gb_expiry>' . $dbr->addQuotes($dbr->timestamp(wfTimestampNow())));
         }
     }
     $pager = new GlobalBlockListPager($this, $conds);
     $body = $pager->getBody();
     if ($body != '') {
         $wgOut->addHTML($pager->getNavigationBar() . Html::rawElement('ul', array(), $body) . $pager->getNavigationBar());
     } else {
         $wgOut->wrapWikiMsg("<div class='mw-globalblocking-noresults'>\n\$1</div>\n", array('globalblocking-list-noresults'));
     }
 }
コード例 #29
0
 public static function log($type, $action, $userId, $userName, $userdstId, $userNamedst, $comment = "")
 {
     global $wgSitename, $wgCityId, $wgExternalDatawareDB;
     $dbw = wfGetDB(DB_MASTER, array(), $wgExternalDatawareDB);
     $now = wfTimestampNow();
     $data = array('slog_type' => $type, 'slog_action' => $action, 'slog_timestamp' => $dbw->timestamp($now), 'slog_user' => $userId, 'slog_user_namedst' => $userNamedst, 'slog_user_name' => $userName, 'slog_userdst' => $userdstId, 'slog_comment' => $comment, 'slog_site' => $wgSitename, 'slog_city' => $wgCityId);
     $dbw->insert('wikiastaff_log', $data, __METHOD__);
 }
コード例 #30
0
 function useItem($itemId = 0)
 {
     global $wgUser;
     $dbw = wfGetDB(DB_MASTER);
     if ($this->checkoutTimeField != ToolSkip::DEFAULT_VALUE && $this->checkoutUserField != ToolSkip::DEFAULT_VALUE && $this->toolTable != ToolSkip::DEFAULT_VALUE) {
         $dbw->update($this->toolTable, array($this->checkoutTimeField => wfTimestampNow(), $this->checkoutUserField => $wgUser->getID()), array($this->checkoutItemField => $itemId));
     }
 }