Ejemplo n.º 1
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");
     }
 }
Ejemplo n.º 2
0
 /**
  * Verifies the user submitted data to check it's valid
  * @param string $page
  * @param string $site
  * @return array
  */
 public static function verifyPFData($page, $site)
 {
     global $wgServer, $wgAllowGlobalMessaging;
     $data = array('site' => $site, 'title' => $page);
     if (trim($site) === '') {
         $site = MassMessage::getBaseUrl($wgServer);
         $data['site'] = $site;
         $data['wiki'] = wfWikiID();
     } elseif (filter_var('http://' . $site, FILTER_VALIDATE_URL) === false) {
         // Try and see if the site provided is not valid
         // We can just prefix http:// in front since it needs some kind of protocol
         //			return MassMessage::parserError( 'massmessage-parse-badurl', $site );
     }
     if (is_null(Title::newFromText($page))) {
         // Check if the page provided is not valid
         return MassMessage::parserError('massmessage-parse-badpage', $page);
     }
     if (!isset($data['wiki'])) {
         $data['wiki'] = MassMessage::getDBName($data['site']);
         if ($data['wiki'] === null) {
             //return MassMessage::parserError( 'massmessage-parse-badurl', $site );
         }
     }
     if (!$wgAllowGlobalMessaging && $data['wiki'] != wfWikiID()) {
         return MassMessage::parserError('massmessage-global-disallowed');
     }
     return $data;
 }
Ejemplo n.º 3
0
 public function execute()
 {
     $this->output("Looking for pages with page_latest set to 0...\n");
     $dbw = wfGetDB(DB_MASTER);
     $result = $dbw->select('page', array('page_id', 'page_namespace', 'page_title'), array('page_latest' => 0), __METHOD__);
     $n = 0;
     foreach ($result as $row) {
         $pageId = intval($row->page_id);
         $title = Title::makeTitle($row->page_namespace, $row->page_title);
         $name = $title->getPrefixedText();
         $latestTime = $dbw->selectField('revision', 'MAX(rev_timestamp)', array('rev_page' => $pageId), __METHOD__);
         if (!$latestTime) {
             $this->output(wfWikiID() . " {$pageId} [[{$name}]] can't find latest rev time?!\n");
             continue;
         }
         $revision = Revision::loadFromTimestamp($dbw, $title, $latestTime);
         if (is_null($revision)) {
             $this->output(wfWikiID() . " {$pageId} [[{$name}]] latest time {$latestTime}, can't find revision id\n");
             continue;
         }
         $id = $revision->getId();
         $this->output(wfWikiID() . " {$pageId} [[{$name}]] latest time {$latestTime}, rev id {$id}\n");
         if ($this->hasOption('fix')) {
             $article = new Article($title);
             $article->updateRevisionOn($dbw, $revision);
         }
         $n++;
     }
     $dbw->freeResult($result);
     $this->output("Done! Processed {$n} pages.\n");
     if (!$this->hasOption('fix')) {
         $this->output("This was a dry run; rerun with --fix to update page_latest.\n");
     }
 }
 public function execute()
 {
     // FIXME: This is horrible, no good, very bad hack. Only for testing,
     // and probably should be eventually replaced with something more sane.
     $updaterScript = "extensions/CirrusSearch/maintenance/updateSuggesterIndex.php";
     $this->getResult()->addValue(null, 'result', wfShellExecWithStderr("unset REQUEST_METHOD; /usr/local/bin/mwscript {$updaterScript} --wiki " . wfWikiID()));
 }
Ejemplo n.º 5
0
 protected function setUp()
 {
     global $wgFileBackends;
     parent::setUp();
     # Forge a FSRepo object to not have to rely on local wiki settings
     $tmpPrefix = wfTempDir() . '/storebatch-test-' . time() . '-' . mt_rand();
     if ($this->getCliArg('use-filebackend=')) {
         $name = $this->getCliArg('use-filebackend=');
         $useConfig = array();
         foreach ($wgFileBackends as $conf) {
             if ($conf['name'] == $name) {
                 $useConfig = $conf;
             }
         }
         $useConfig['lockManager'] = LockManagerGroup::singleton()->get($useConfig['lockManager']);
         unset($useConfig['fileJournal']);
         $useConfig['name'] = 'local-testing';
         // swap name
         $class = $useConfig['class'];
         $backend = new $class($useConfig);
     } else {
         $backend = new FSFileBackend(array('name' => 'local-testing', 'wikiId' => wfWikiID(), 'containerPaths' => array('unittests-public' => "{$tmpPrefix}-public", 'unittests-thumb' => "{$tmpPrefix}-thumb", 'unittests-temp' => "{$tmpPrefix}-temp", 'unittests-deleted' => "{$tmpPrefix}-deleted")));
     }
     $this->repo = new FileRepo(array('name' => 'unittests', 'backend' => $backend));
     $this->date = gmdate("YmdHis");
     $this->createdFiles = array();
 }
Ejemplo n.º 6
0
 public function execute()
 {
     $username = $this->getArg(0);
     $password = $this->getArg(1);
     $this->output(wfWikiID() . ": Creating and promoting User:{$username}...");
     $user = User::newFromName($username);
     if (!is_object($user)) {
         $this->error("invalid username.", true);
     } elseif (0 != $user->idForName()) {
         $this->error("account exists.", true);
     }
     # Try to set the password
     try {
         $user->setPassword($password);
     } catch (PasswordError $pwe) {
         $this->error($pwe->getText(), true);
     }
     # Insert the account into the database
     $user->addToDatabase();
     $user->saveSettings();
     # Promote user
     if ($this->hasOption('sysop')) {
         $user->addGroup('sysop');
     }
     if ($this->hasOption('bureaucrat')) {
         $user->addGroup('bureaucrat');
     }
     # Increment site_stats.ss_users
     $ssu = new SiteStatsUpdate(0, 0, 0, 0, 1);
     $ssu->doUpdate();
     $this->output("done.\n");
 }
Ejemplo n.º 7
0
 protected function setUp()
 {
     global $wgFileBackends;
     parent::setUp();
     $uniqueId = time() . '-' . mt_rand();
     $tmpPrefix = wfTempDir() . '/filebackend-unittest-' . $uniqueId;
     if ($this->getCliArg('use-filebackend=')) {
         if (self::$backendToUse) {
             $this->singleBackend = self::$backendToUse;
         } else {
             $name = $this->getCliArg('use-filebackend=');
             $useConfig = array();
             foreach ($wgFileBackends as $conf) {
                 if ($conf['name'] == $name) {
                     $useConfig = $conf;
                     break;
                 }
             }
             $useConfig['name'] = 'localtesting';
             // swap name
             $useConfig['shardViaHashLevels'] = array('unittest-cont1' => array('levels' => 1, 'base' => 16, 'repeat' => 1));
             $class = $useConfig['class'];
             self::$backendToUse = new $class($useConfig);
             $this->singleBackend = self::$backendToUse;
         }
     } else {
         $this->singleBackend = new FSFileBackend(array('name' => 'localtesting', 'lockManager' => 'fsLockManager', 'wikiId' => wfWikiID() . $uniqueId, 'containerPaths' => array('unittest-cont1' => "{$tmpPrefix}-localtesting-cont1", 'unittest-cont2' => "{$tmpPrefix}-localtesting-cont2")));
     }
     $this->multiBackend = new FileBackendMultiWrite(array('name' => 'localtesting', 'lockManager' => 'fsLockManager', 'parallelize' => 'implicit', 'wikiId' => wfWikiId() . $uniqueId, 'backends' => array(array('name' => 'localmultitesting1', 'class' => 'FSFileBackend', 'lockManager' => 'nullLockManager', 'containerPaths' => array('unittest-cont1' => "{$tmpPrefix}-localtestingmulti1-cont1", 'unittest-cont2' => "{$tmpPrefix}-localtestingmulti1-cont2"), 'isMultiMaster' => false), array('name' => 'localmultitesting2', 'class' => 'FSFileBackend', 'lockManager' => 'nullLockManager', 'containerPaths' => array('unittest-cont1' => "{$tmpPrefix}-localtestingmulti2-cont1", 'unittest-cont2' => "{$tmpPrefix}-localtestingmulti2-cont2"), 'isMultiMaster' => true))));
     $this->filesToPrune = array();
 }
Ejemplo n.º 8
0
 public function execute()
 {
     if (count($this->mArgs) == 0) {
         $this->error("No revisions specified", true);
     }
     $this->output("Deleting revision(s) " . implode(',', $this->mArgs) . " from " . wfWikiID() . "...\n");
     $dbw = wfGetDB(DB_MASTER);
     $affected = 0;
     foreach ($this->mArgs as $revID) {
         $dbw->insertSelect('archive', array('page', 'revision'), array('ar_namespace' => 'page_namespace', 'ar_title' => 'page_title', 'ar_page_id' => 'page_id', 'ar_comment' => 'rev_comment', 'ar_user' => 'rev_user', 'ar_user_text' => 'rev_user_text', 'ar_timestamp' => 'rev_timestamp', 'ar_minor_edit' => 'rev_minor_edit', 'ar_rev_id' => 'rev_id', 'ar_text_id' => 'rev_text_id', 'ar_deleted' => 'rev_deleted', 'ar_len' => 'rev_len'), array('rev_id' => $revID, 'page_id = rev_page'), __METHOD__);
         if (!$dbw->affectedRows()) {
             $this->output("Revision {$revID} not found\n");
         } else {
             $affected += $dbw->affectedRows();
             $pageID = $dbw->selectField('revision', 'rev_page', array('rev_id' => $revID), __METHOD__);
             $pageLatest = $dbw->selectField('page', 'page_latest', array('page_id' => $pageID), __METHOD__);
             $dbw->delete('revision', array('rev_id' => $revID));
             if ($pageLatest == $revID) {
                 // Database integrity
                 $newLatest = $dbw->selectField('revision', 'rev_id', array('rev_page' => $pageID), __METHOD__, array('ORDER BY' => 'rev_timestamp DESC'));
                 $dbw->update('page', array('page_latest' => $newLatest), array('page_id' => $pageID), __METHOD__);
             }
         }
     }
     $this->output("Deleted {$affected} revisions\n");
 }
Ejemplo n.º 9
0
 function execute()
 {
     global $wgVersion, $wgTitle, $wgLang;
     $wgLang = Language::factory('en');
     $wgTitle = Title::newFromText("MediaWiki database updater");
     $this->output("MediaWiki {$wgVersion} Updater\n\n");
     if (!$this->hasOption('skip-compat-checks')) {
         $this->compatChecks();
     } else {
         $this->output("Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n");
         wfCountdown(5);
     }
     # Attempt to connect to the database as a privileged user
     # This will vomit up an error if there are permissions problems
     $db = wfGetDB(DB_MASTER);
     $this->output("Going to run database updates for " . wfWikiID() . "\n");
     $this->output("Depending on the size of your database this may take a while!\n");
     if (!$this->hasOption('quick')) {
         $this->output("Abort with control-c in the next five seconds (skip this countdown with --quick) ... ");
         wfCountDown(5);
     }
     $shared = $this->hasOption('doshared');
     $updates = array('core', 'extensions');
     if (!$this->hasOption('nopurge')) {
         $updates[] = 'purge';
     }
     $updater = DatabaseUpdater::newForDb($db, $shared, $this);
     $updater->doUpdates($updates);
     foreach ($updater->getPostDatabaseUpdateMaintenance() as $maint) {
         $child = $this->runChild($maint);
         $child->execute();
     }
     $this->output("\nDone.\n");
 }
 /**
  * Try to create and attach the user.
  * @throws Exception
  * @return bool Success
  */
 public function run()
 {
     $username = $this->params['name'];
     $from = $this->params['from'];
     $wiki = wfWikiID();
     if (isset($this->params['session'])) {
         // restore IP and other request data
         $this->params['session']['userId'] = 0;
         $this->params['session']['sessionId'] = '';
         $callback = RequestContext::importScopedSession($this->params['session']);
     }
     $user = User::newFromName($username);
     $centralUser = CentralAuthUser::getInstance($user);
     if ($user->getId() !== 0) {
         wfDebugLog('CentralAuth', __CLASS__ . ": tried to create local account for {$username} " . "on {$wiki} from {$from} but one already exists\n");
         return true;
     } elseif (!$centralUser->exists()) {
         wfDebugLog('CentralAuth', __CLASS__ . ": tried to create local account for {$username} " . "on {$wiki} from {$from} but no global account exists\n");
         return true;
     } elseif ($centralUser->attachedOn($wiki)) {
         wfDebugLog('CentralAuth', __CLASS__ . ": tried to create local account for {$username} " . "on {$wiki} from {$from} but an attached local account already exists\n");
         return true;
     }
     $success = CentralAuthHooks::attemptAddUser($user);
     if ($success) {
         $centralUser->invalidateCache();
     }
     return true;
 }
 public function refreshBatch(DatabaseBase $dbr, UUID $continue, $countableActions, UUID $stop)
 {
     $rows = $dbr->select('flow_revision', array('rev_id', 'rev_user_id'), array('rev_id > ' . $dbr->addQuotes($continue->getBinary()), 'rev_id <= ' . $dbr->addQuotes($stop->getBinary()), 'rev_user_id > 0', 'rev_user_wiki' => wfWikiID(), 'rev_change_type' => $countableActions), __METHOD__, array('ORDER BY' => 'rev_id ASC', 'LIMIT' => $this->mBatchSize));
     // end of data
     if (!$rows || $rows->numRows() === 0) {
         return false;
     }
     foreach ($rows as $row) {
         // User::incEditCount only allows for edit count to be increased 1
         // at a time. It'd be better to immediately be able to increase the
         // edit count by the exact number it should be increased with, but
         // I'd rather re-use existing code, especially in a run-once script,
         // where performance is not the most important thing ;)
         $user = User::newFromId($row->rev_user_id);
         $user->incEditCount();
         // save updates so we can print them when the script is done running
         if (!isset($this->updates[$user->getId()])) {
             $this->updates[$user->getId()] = 0;
         }
         $this->updates[$user->getId()]++;
         // set value for next batch to continue at
         $continue = $row->rev_id;
     }
     return UUID::create($continue);
 }
Ejemplo n.º 12
0
 function getFunctionReport()
 {
     global $wgUDPProfilerHost;
     global $wgUDPProfilerPort;
     if ($this->mCollated['-total']['real'] < $this->mMinimumTime) {
         # Less than minimum, ignore
         return;
     }
     $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
     $plength = 0;
     $packet = "";
     foreach ($this->mCollated as $entry => $pfdata) {
         $pfline = sprintf("%s %s %d %f %f %f %f %s\n", wfWikiID(), "-", $pfdata['count'], $pfdata['cpu'], $pfdata['cpu_sq'], $pfdata['real'], $pfdata['real_sq'], $entry);
         $length = strlen($pfline);
         /* printf("<!-- $pfline -->"); */
         if ($length + $plength > 1400) {
             socket_sendto($sock, $packet, $plength, 0, $wgUDPProfilerHost, $wgUDPProfilerPort);
             $packet = "";
             $plength = 0;
         }
         $packet .= $pfline;
         $plength += $length;
     }
     socket_sendto($sock, $packet, $plength, 0x100, $wgUDPProfilerHost, $wgUDPProfilerPort);
 }
 /**
  * Setup a fresh set of global users for each test.
  * Note: MediaWikiTestCase::resetDB() will delete all tables between
  * test runs, so no explicite tearDown() is needed.
  */
 protected function setUp()
 {
     parent::setUp();
     $u = new CentralAuthTestUser('GlobalUser', 'GUP@ssword', array('gu_id' => '1001'), array(array(wfWikiID(), 'primary'), array('enwiki', 'primary'), array('dewiki', 'login'), array('metawiki', 'password')));
     $u->save($this->db);
     $u = new CentralAuthTestUser('GlobalLockedUser', 'GLUP@ssword', array('gu_id' => '1003', 'gu_locked' => 1, 'gu_hidden' => CentralAuthUser::HIDDEN_NONE, 'gu_email' => 'testlocked@localhost', 'gu_home_db' => 'metawiki'), array(array('metawiki', 'primary')));
     $u->save($this->db);
 }
Ejemplo n.º 14
0
 /**
  * @param $wiki string Wiki ID
  * @return JobQueueGroup
  */
 public static function singleton($wiki = false)
 {
     $wiki = $wiki === false ? wfWikiID() : $wiki;
     if (!isset(self::$instances[$wiki])) {
         self::$instances[$wiki] = new self($wiki);
     }
     return self::$instances[$wiki];
 }
Ejemplo n.º 15
0
 function getProfileID()
 {
     if ($this->mProfileID === false) {
         return wfWikiID();
     } else {
         return $this->mProfileID;
     }
 }
 protected function getMocks()
 {
     $dbMock = $this->getMockBuilder('DatabaseMysql')->disableOriginalConstructor()->getMock();
     $backendMock = $this->getMock('FSFileBackend', [], [['name' => $this->backendName, 'wikiId' => wfWikiID()]]);
     $wrapperMock = $this->getMock('FileBackendDBRepoWrapper', ['getDB'], [['backend' => $backendMock, 'repoName' => $this->repoName, 'dbHandleFactory' => null]]);
     $wrapperMock->expects($this->any())->method('getDB')->will($this->returnValue($dbMock));
     return [$dbMock, $backendMock, $wrapperMock];
 }
Ejemplo n.º 17
0
 /**
  * @dataProvider provider_queueLists
  * @covers JobQueue::getWiki
  */
 public function testGetWiki($queue, $recycles, $desc)
 {
     $queue = $this->{$queue};
     if (!$queue) {
         $this->markTestSkipped($desc);
     }
     $this->assertEquals(wfWikiID(), $queue->getWiki(), "Proper wiki ID ({$desc})");
 }
 function execute($par)
 {
     global $wgMemc;
     $tempToken = $this->getRequest()->getVal('token');
     $logout = $this->getRequest()->getBool('logout');
     # Don't cache error messages
     $this->getOutput()->enableClientCache(false);
     if (strlen($tempToken) == 0) {
         $this->setHeaders();
         $this->getOutput()->addWikiMsg('centralauth-autologin-desc');
         return;
     }
     $key = CentralAuthUser::memcKey('login-token', $tempToken);
     $data = $wgMemc->get($key);
     $wgMemc->delete($key);
     if (!$data) {
         $msg = 'Token is invalid or has expired';
         wfDebug(__METHOD__ . ": {$msg}\n");
         $this->setHeaders();
         $this->getOutput()->addWikiText($msg);
         return;
     }
     $userName = $data['userName'];
     $token = $data['token'];
     $remember = $data['remember'];
     if ($data['wiki'] != wfWikiID()) {
         $msg = 'Bad token (wrong wiki)';
         wfDebug(__METHOD__ . ": {$msg}\n");
         $this->setHeaders();
         $this->getOutput()->addWikiText($msg);
         return;
     }
     $centralUser = new CentralAuthUser($userName);
     $loginResult = $centralUser->authenticateWithToken($token);
     if ($loginResult != 'ok') {
         $msg = "Bad token: {$loginResult}";
         wfDebug(__METHOD__ . ": {$msg}\n");
         $this->setHeaders();
         $this->getOutput()->addWikiText($msg);
         return;
     }
     // Auth OK.
     if ($logout) {
         $centralUser->deleteGlobalCookies();
     } else {
         $centralUser->setGlobalCookies($remember);
     }
     $this->getOutput()->disable();
     wfResetOutputBuffers();
     header('Cache-Control: no-cache');
     header('Content-Type: image/png');
     global $wgCentralAuthLoginIcon;
     if ($wgCentralAuthLoginIcon) {
         readfile($wgCentralAuthLoginIcon);
     } else {
         readfile(dirname(__FILE__) . '/1x1.png');
     }
 }
 public function testLoadByRevisionId_notFound()
 {
     if (!defined('WB_VERSION')) {
         $this->markTestSkipped("Skipping because WikibaseClient doesn't have a local wb_changes table.");
     }
     $lookup = new ChangeLookup(array('wikibase-item~remove' => 'Wikibase\\EntityChange'), wfWikiID());
     $changes = $lookup->loadByRevisionId(PHP_INT_MAX);
     $this->assertNull($changes);
 }
Ejemplo n.º 20
0
 /**
  * @param bool|string $domain Domain (usually wiki ID). Default: false.
  * @return LockManagerGroup
  */
 public static function singleton($domain = false)
 {
     $domain = $domain === false ? wfWikiID() : $domain;
     if (!isset(self::$instances[$domain])) {
         self::$instances[$domain] = new self($domain);
         self::$instances[$domain]->initFromGlobals();
     }
     return self::$instances[$domain];
 }
Ejemplo n.º 21
0
 /**
  * @dataProvider provider_queueLists
  */
 function testProperties($queue, $recycles, $desc)
 {
     $queue = $this->{$queue};
     if (!$queue) {
         $this->markTestSkipped($desc);
     }
     $this->assertEquals(wfWikiID(), $queue->getWiki(), "Proper wiki ID ({$desc})");
     $this->assertEquals('null', $queue->getType(), "Proper job type ({$desc})");
 }
Ejemplo n.º 22
0
 public function execute()
 {
     $username = $this->getArg(0);
     $password = $this->getArg(1);
     $force = $this->hasOption('force');
     $inGroups = array();
     $user = User::newFromName($username);
     if (!is_object($user)) {
         $this->error("invalid username.", true);
     }
     $exists = 0 !== $user->idForName();
     if ($exists && !$force) {
         $this->error("Account exists. Perhaps you want the --force option?", true);
     } elseif (!$exists && !$password) {
         $this->error("Argument <password> required!", false);
         $this->maybeHelp(true);
     } elseif ($exists) {
         $inGroups = $user->getGroups();
     }
     $promotions = array_diff(array_filter(self::$permitRoles, array($this, 'hasOption')), $inGroups);
     if ($exists && !$password && count($promotions) === 0) {
         $this->output("Account exists and nothing to do.\n");
         return;
     } elseif (count($promotions) !== 0) {
         $promoText = "User:{$username} into " . implode(', ', $promotions) . "...\n";
         if ($exists) {
             $this->output(wfWikiID() . ": Promoting {$promoText}");
         } else {
             $this->output(wfWikiID() . ": Creating and promoting {$promoText}");
         }
     }
     if ($password) {
         # Try to set the password
         try {
             $user->setPassword($password);
             if ($exists) {
                 $this->output("Password set.\n");
                 $user->saveSettings();
             }
         } catch (PasswordError $pwe) {
             $this->error($pwe->getText(), true);
         }
     }
     if (!$exists) {
         # Insert the account into the database
         $user->addToDatabase();
         $user->saveSettings();
     }
     # Promote user
     array_map(array($user, 'addGroup'), $promotions);
     if (!$exists) {
         # Increment site_stats.ss_users
         $ssu = new SiteStatsUpdate(0, 0, 0, 0, 1);
         $ssu->doUpdate();
     }
     $this->output("done.\n");
 }
Ejemplo n.º 23
0
 /**
  * @param $params array
  */
 public function __construct($params)
 {
     global $wgDBAhandler;
     if (!isset($params['dir'])) {
         $params['dir'] = wfTempDir();
     }
     $this->mFile = $params['dir'] . '/mw-cache-' . wfWikiID() . '.db';
     wfDebug(__CLASS__ . ": using cache file {$this->mFile}\n");
     $this->mHandler = $wgDBAhandler;
 }
Ejemplo n.º 24
0
 public function execute()
 {
     $dbw = wfGetDB(DB_MASTER);
     // Load the current value from the master
     $count = $dbw->selectField('site_stats', 'ss_images');
     $this->output(wfWikiID() . ": forcing ss_images to {$count}\n");
     // First set to NULL so that it changes on the master
     $dbw->update('site_stats', array('ss_images' => null), array('ss_row_id' => 1));
     // Now this update will be forced to go out
     $dbw->update('site_stats', array('ss_images' => $count), array('ss_row_id' => 1));
 }
Ejemplo n.º 25
0
 /**
  * Create a new backend instance from configuration.
  * This should only be called from within FileBackendGroup.
  * 
  * $config includes:
  *     'name'        : The unique name of this backend.
  *                     This should consist of alphanumberic, '-', and '_' characters.
  *                     This name should not be changed after use.
  *     'wikiId'      : Prefix to container names that is unique to this wiki.
  *                     This should consist of alphanumberic, '-', and '_' characters.
  *     'lockManager' : Registered name of a file lock manager to use.
  *     'readOnly'    : Write operations are disallowed if this is a non-empty string.
  *                     It should be an explanation for the backend being read-only.
  * 
  * @param $config Array
  */
 public function __construct(array $config)
 {
     $this->name = $config['name'];
     if (!preg_match('!^[a-zA-Z0-9-_]{1,255}$!', $this->name)) {
         throw new MWException("Backend name `{$this->name}` is invalid.");
     }
     $this->wikiId = isset($config['wikiId']) ? $config['wikiId'] : wfWikiID();
     // e.g. "my_wiki-en_"
     $this->lockManager = $config['lockManager'] instanceof LockManager ? $config['lockManager'] : LockManagerGroup::singleton()->get($config['lockManager']);
     $this->readOnly = isset($config['readOnly']) ? (string) $config['readOnly'] : '';
 }
Ejemplo n.º 26
0
	/**
	 * Construct a new instance from configuration
	 *
	 * $config paramaters include:
	 *   - domain  : Domain (usually wiki ID) that all resources are relative to [optional]
	 *   - lockTTL : Age (in seconds) at which resource locks should expire.
	 *               This only applies if locks are not tied to a connection/process.
	 *
	 * @param $config Array
	 */
	public function __construct( array $config ) {
		$this->domain = isset( $config['domain'] ) ? $config['domain'] : wfWikiID();
		if ( isset( $config['lockTTL'] ) ) {
			$this->lockTTL = max( 1, $config['lockTTL'] );
		} elseif ( PHP_SAPI === 'cli' ) {
			$this->lockTTL = 2 * 3600;
		} else {
			$met = ini_get( 'max_execution_time' ); // this is 0 in CLI mode
			$this->lockTTL = max( 5 * 60, 2 * (int)$met );
		}
	}
Ejemplo n.º 27
0
 function execute()
 {
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select('user', array('user_id', 'user_name'), null, __METHOD__);
     foreach ($res as $row) {
         if (!User::isValidUserName($row->user_name)) {
             $this->error(sprintf("%s: %6d: '%s'\n", wfWikiID(), $row->user_id, $row->user_name));
             wfDebugLog('checkUsernames', $out);
         }
     }
 }
Ejemplo n.º 28
0
 protected function setUp()
 {
     parent::setUp();
     $this->setMwGlobals('wgCapitalLinks', true);
     $info = ['name' => 'test', 'directory' => '/testdir', 'url' => '/testurl', 'hashLevels' => 2, 'transformVia404' => false, 'backend' => new FSFileBackend(['name' => 'local-backend', 'wikiId' => wfWikiID(), 'containerPaths' => ['cont1' => "/testdir/local-backend/tempimages/cont1", 'cont2' => "/testdir/local-backend/tempimages/cont2"]])];
     $this->repo_hl0 = new LocalRepo(['hashLevels' => 0] + $info);
     $this->repo_hl2 = new LocalRepo(['hashLevels' => 2] + $info);
     $this->repo_lc = new LocalRepo(['initialCapital' => false] + $info);
     $this->file_hl0 = $this->repo_hl0->newFile('test!');
     $this->file_hl2 = $this->repo_hl2->newFile('test!');
     $this->file_lc = $this->repo_lc->newFile('test!');
 }
Ejemplo n.º 29
0
 public function __construct($params)
 {
     global $wgDBAhandler;
     if (!isset($params['dir'])) {
         global $wgTmpDirectory;
         $params['dir'] = $wgTmpDirectory;
     }
     $this->mFile = $params['dir'] . "/mw-cache-" . wfWikiID();
     $this->mFile .= '.db';
     wfDebug(__CLASS__ . ": using cache file {$this->mFile}\n");
     $this->mHandler = $wgDBAhandler;
 }
Ejemplo n.º 30
0
 public function __construct($dir = false)
 {
     global $wgDBAhandler;
     if ($dir === false) {
         global $wgTmpDirectory;
         $dir = $wgTmpDirectory;
     }
     $this->mFile = "{$dir}/mw-cache-" . wfWikiID();
     $this->mFile .= '.db';
     wfDebug(__CLASS__ . ": using cache file {$this->mFile}\n");
     $this->mHandler = $wgDBAhandler;
 }