/**
  * Get the formatter output for the given input data
  * @param array $params Query parameters
  * @param array $data Data to encode
  * @param string $class Printer class to use instead of the normal one
  * @return string
  * @throws Exception
  */
 protected function encodeData(array $params, array $data, $class = null)
 {
     $context = new RequestContext();
     $context->setRequest(new FauxRequest($params, true));
     $main = new ApiMain($context);
     if ($class !== null) {
         $main->getModuleManager()->addModule($this->printerName, 'format', $class);
     }
     $result = $main->getResult();
     $result->addArrayType(null, 'default');
     foreach ($data as $k => $v) {
         $result->addValue(null, $k, $v);
     }
     $printer = $main->createPrinterByName($this->printerName);
     $printer->initPrinter();
     $printer->execute();
     ob_start();
     try {
         $printer->closePrinter();
         return ob_get_clean();
     } catch (Exception $ex) {
         ob_end_clean();
         throw $ex;
     }
 }
 /**
  * @see BaseDependencyContainer::registerDefinitions
  *
  * @since  1.9
  *
  * @return array
  */
 protected function getDefinitions()
 {
     return array('ParserData' => $this->getParserData(), 'NamespaceExaminer' => $this->getNamespaceExaminer(), 'JobFactory' => function (DependencyBuilder $builder) {
         return new \SMW\MediaWiki\Jobs\JobFactory();
     }, 'ContentParser' => function (DependencyBuilder $builder) {
         return new ContentParser($builder->getArgument('Title'));
     }, 'RequestContext' => function (DependencyBuilder $builder) {
         $instance = new \RequestContext();
         if ($builder->hasArgument('Title')) {
             $instance->setTitle($builder->getArgument('Title'));
         }
         if ($builder->hasArgument('Language')) {
             $instance->setLanguage($builder->getArgument('Language'));
         }
         return $instance;
     }, 'WikiPage' => function (DependencyBuilder $builder) {
         return \WikiPage::factory($builder->getArgument('Title'));
     }, 'TitleCreator' => function (DependencyBuilder $builder) {
         return new TitleCreator(new PageCreator());
     }, 'PageCreator' => function (DependencyBuilder $builder) {
         return new PageCreator();
     }, 'MessageFormatter' => function (DependencyBuilder $builder) {
         return new MessageFormatter($builder->getArgument('Language'));
     });
 }
Esempio n. 3
0
    function testPreferences()
    {
        global $wgUser, $wgOut, $wgTitle;
        // This test makes call to the parser which requires valids Outputpage
        // and Title objects. Set them up there, they will be released at the
        // end of the test.
        $old_wgOut = $wgOut;
        $old_wgTitle = $wgTitle;
        $wgTitle = Title::newFromText('Parser test for Gadgets extension');
        // Proceed with test setup:
        $prefs = array();
        $context = new RequestContext();
        $wgOut = $context->getOutput();
        $wgOut->setTitle(Title::newFromText('test'));
        Gadget::loadStructuredList('* foo | foo.js
==keep-section1==
* bar| bar.js
==remove-section==
* baz [rights=embezzle] |baz.js
==keep-section2==
* quux [rights=read] | quux.js');
        $this->assertTrue(GadgetHooks::getPreferences($wgUser, $prefs), 'GetPrefences hook should return true');
        $options = $prefs['gadgets']['options'];
        $this->assertFalse(isset($options['<gadget-section-remove-section>']), 'Must not show empty sections');
        $this->assertTrue(isset($options['<gadget-section-keep-section1>']));
        $this->assertTrue(isset($options['<gadget-section-keep-section2>']));
        // Restore globals
        $wgOut = $old_wgOut;
        $wgTitle = $old_wgTitle;
    }
 public function getTestContext(User $user)
 {
     $context = new RequestContext();
     $context->setLanguage(Language::factory('en'));
     $context->setUser($user);
     return $context;
 }
 /**
  * @dataProvider titleDataProvider
  */
 public function testProcess($setup, $expected)
 {
     $skin = $this->getMockBuilder('\\Skin')->disableOriginalConstructor()->getMock();
     $context = new \RequestContext();
     $context->setTitle($setup['title']);
     $context->setLanguage(Language::factory('en'));
     $outputPage = new OutputPage($context);
     $instance = new BeforePageDisplay($outputPage, $skin);
     $result = $instance->process();
     $this->assertInternalType('boolean', $result);
     $this->assertTrue($result);
     $contains = false;
     if (method_exists($outputPage, 'getHeadLinksArray')) {
         foreach ($outputPage->getHeadLinksArray() as $key => $value) {
             if (strpos($value, 'ExportRDF')) {
                 $contains = true;
                 break;
             }
         }
     } else {
         // MW 1.19
         if (strpos($outputPage->getHeadLinks(), 'ExportRDF')) {
             $contains = true;
         }
     }
     $expected['result'] ? $this->assertTrue($contains) : $this->assertFalse($contains);
 }
Esempio n. 6
0
 public function testCrossDomainMangling()
 {
     $config = new HashConfig(array('MangleFlashPolicy' => false));
     $context = new RequestContext();
     $context->setConfig(new MultiConfig(array($config, $context->getConfig())));
     $main = new ApiMain($context);
     $main->getResult()->addValue(null, null, '< Cross-Domain-Policy >');
     if (!function_exists('wfOutputHandler')) {
         function wfOutputHandler($s)
         {
             return $s;
         }
     }
     $printer = $main->createPrinterByName('php');
     ob_start('wfOutputHandler');
     $printer->initPrinter();
     $printer->execute();
     $printer->closePrinter();
     $ret = ob_get_clean();
     $this->assertSame('a:1:{i:0;s:23:"< Cross-Domain-Policy >";}', $ret);
     $config->set('MangleFlashPolicy', true);
     $printer = $main->createPrinterByName('php');
     ob_start('wfOutputHandler');
     try {
         $printer->initPrinter();
         $printer->execute();
         $printer->closePrinter();
         ob_end_clean();
         $this->fail('Expected exception not thrown');
     } catch (UsageException $ex) {
         ob_end_clean();
         $this->assertSame('This response cannot be represented using format=php. See https://phabricator.wikimedia.org/T68776', $ex->getMessage(), 'Expected exception');
     }
 }
 function setUp()
 {
     global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList, $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo, $parserMemc, $wgThumbnailScriptPath, $wgScriptPath, $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
     $wgScript = '/index.php';
     $wgScriptPath = '/';
     $wgArticlePath = '/wiki/$1';
     $wgStyleSheetPath = '/skins';
     $wgStylePath = '/skins';
     $wgThumbnailScriptPath = false;
     $wgLocalFileRepo = array('class' => 'LocalRepo', 'name' => 'local', 'directory' => wfTempDir() . '/test-repo', 'url' => 'http://example.com/images', 'deletedDir' => wfTempDir() . '/test-repo/delete', 'hashLevels' => 2, 'transformVia404' => false);
     $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
     $wgNamespaceAliases['Image'] = NS_FILE;
     $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
     $wgEnableParserCache = false;
     $wgDeferredUpdateList = array();
     $wgMemc = wfGetMainCache();
     $messageMemc = wfGetMessageCacheStorage();
     $parserMemc = wfGetParserCacheStorage();
     // $wgContLang = new StubContLang;
     $wgUser = new User();
     $context = new RequestContext();
     $wgLang = $context->getLang();
     $wgOut = $context->getOutput();
     $wgParser = new StubObject('wgParser', $wgParserConf['class'], array($wgParserConf));
     $wgRequest = new WebRequest();
     if ($wgStyleDirectory === false) {
         $wgStyleDirectory = "{$IP}/skins";
     }
 }
 /**
  * @dataProvider provideGetDesktopUrl
  * @param string $class
  * @param string $subPage
  * @param array $params
  * @param string|null $expected
  */
 public function testGetDesktopUrl($class, $subPage, array $params, $expected)
 {
     $context = new RequestContext();
     $context->setRequest(new FauxRequest($params));
     $page = new $class();
     $page->setContext($context);
     $this->assertEquals($expected, $page->getDesktopUrl($subPage));
 }
Esempio n. 9
0
 /**
  * Updates the RequestContext information based on a HttpFoundation Request.
  *
  * @param RequestContext $requestContext
  *
  * @return $this The current instance, implementing a fluent interface
  *
  */
 public static function fromRequestContext(RequestContext $requestContext)
 {
     $Url = new static();
     $Url->setScheme($requestContext->getScheme());
     $Url->setHost($requestContext->getHost());
     $Url->setPath($requestContext->getPath());
     $Url->setParameters($requestContext->getParameters());
     return $Url;
 }
 function setUp()
 {
     $this->page = new MIMESearchPage();
     $context = new RequestContext();
     $context->setTitle(Title::makeTitle(NS_SPECIAL, 'MIMESearch'));
     $context->setRequest(new FauxRequest());
     $this->page->setContext($context);
     parent::setUp();
 }
 public function getTestContext(User $user)
 {
     $context = new RequestContext();
     $context->setLanguage('en');
     $context->setUser($user);
     $title = Title::newFromText('RecentChanges', NS_SPECIAL);
     $context->setTitle($title);
     return $context;
 }
Esempio n. 12
0
 public function testHandleNormalization()
 {
     $context = new RequestContext();
     $context->setRequest(new FauxRequest(['titles' => "a|B|å"]));
     $main = new ApiMain($context);
     $pageSet = new ApiPageSet($main);
     $pageSet->execute();
     $this->assertSame([0 => ['A' => -1, 'B' => -2, 'Å' => -3]], $pageSet->getAllTitlesByNamespace());
     $this->assertSame([['fromencoded' => true, 'from' => 'a%CC%8A', 'to' => 'å'], ['fromencoded' => false, 'from' => 'a', 'to' => 'A'], ['fromencoded' => false, 'from' => 'å', 'to' => 'Å']], $pageSet->getNormalizedTitlesAsResult());
 }
Esempio n. 13
0
 public function __construct()
 {
     parent::__construct();
     $this->prefUsers['noemail'] = new User();
     $this->prefUsers['notauth'] = new User();
     $this->prefUsers['notauth']->setEmail('*****@*****.**');
     $this->prefUsers['auth'] = new User();
     $this->prefUsers['auth']->setEmail('*****@*****.**');
     $this->prefUsers['auth']->setEmailAuthenticationTimestamp(1330946623);
     $this->context = new RequestContext();
     $this->context->setTitle(Title::newFromText('PreferencesTest'));
 }
 protected function setUp()
 {
     parent::setUp();
     global $wgLang;
     $this->setMwGlobals(array('wgLogTypes' => array('phpunit'), 'wgLogActionsHandlers' => array('phpunit/test' => 'LogFormatter', 'phpunit/param' => 'LogFormatter'), 'wgUser' => User::newFromName('Testuser'), 'wgExtensionMessagesFiles' => array('LogTests' => __DIR__ . '/LogTests.i18n.php')));
     Language::getLocalisationCache()->recache($wgLang->getCode());
     $this->user = User::newFromName('Testuser');
     $this->title = Title::newMainPage();
     $this->context = new RequestContext();
     $this->context->setUser($this->user);
     $this->context->setTitle($this->title);
     $this->context->setLanguage($wgLang);
 }
 /** helper to test SpecialRecentchanges::buildMainQueryConds() */
 private function assertConditions($expected, $requestOptions = null, $message = '')
 {
     $context = new RequestContext();
     $context->setRequest(new FauxRequest($requestOptions));
     # setup the rc object
     $this->rc = new SpecialRecentChanges();
     $this->rc->setContext($context);
     $formOptions = $this->rc->setup(null);
     #  Filter out rc_timestamp conditions which depends on the test runtime
     # This condition is not needed as of march 2, 2011 -- hashar
     # @todo FIXME: Find a way to generate the correct rc_timestamp
     $queryConditions = array_filter($this->rc->buildMainQueryConds($formOptions), 'SpecialRecentchangesTest::filterOutRcTimestampCondition');
     $this->assertEquals($expected, $queryConditions, $message);
 }
Esempio n. 16
0
 /**
  * 获得requset对象实例
  */
 public static function getRequest()
 {
     if (is_null(self::$instance) || !isset(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
 public function execute()
 {
     global $wgUser;
     $wgUser = User::newFromName('Maintenance script');
     RequestContext::getMain()->setUser($wgUser);
     $dbr = CentralAuthUser::getCentralSlaveDB();
     if ($this->getOption('fix', false) !== false) {
         $this->fix = true;
     }
     if ($this->getOption('safe-migrate', false) !== false) {
         $this->safe = true;
         $this->migrate = true;
     }
     if ($this->getOption('migrate', false) !== false) {
         $this->migrate = true;
     }
     if ($this->getOption('suppressrc', false) !== false) {
         $this->suppressRC = true;
     }
     $end = $dbr->selectField('globaluser', 'MAX(gu_id)');
     for ($cur = 0; $cur <= $end; $cur += $this->mBatchSize) {
         $this->output("PROGRESS: {$cur} / {$end}\n");
         $result = $dbr->select(array('globaluser', 'localuser'), array('gu_name'), array('lu_name' => null, "gu_id >= {$cur}", 'gu_id < ' . ($cur + $this->mBatchSize)), __METHOD__, array('ORDER BY' => 'gu_id'), array('localuser' => array('LEFT JOIN', 'gu_name=lu_name')));
         foreach ($result as $row) {
             $this->process($row->gu_name);
         }
         if ($this->fix) {
             CentralAuthUser::waitForSlaves();
         }
     }
     $this->output("done.\n");
 }
Esempio n. 18
0
 function execute($par)
 {
     /**
      * Some satellite ISPs use broken precaching schemes that log people out straight after
      * they're logged in (bug 17790). Luckily, there's a way to detect such requests.
      */
     if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '&amp;') !== false) {
         wfDebug("Special:Userlogout request {$_SERVER['REQUEST_URI']} looks suspicious, denying.\n");
         throw new HttpError(400, $this->msg('suspicious-userlogout'), $this->msg('loginerror'));
     }
     $this->setHeaders();
     $this->outputHeader();
     // Make sure it's possible to log out
     $session = MediaWiki\Session\SessionManager::getGlobalSession();
     if (!$session->canSetUser()) {
         throw new ErrorPageError('cannotlogoutnow-title', 'cannotlogoutnow-text', [$session->getProvider()->describe(RequestContext::getMain()->getLanguage())]);
     }
     $user = $this->getUser();
     $oldName = $user->getName();
     $user->logout();
     $loginURL = SpecialPage::getTitleFor('Userlogin')->getFullURL($this->getRequest()->getValues('returnto', 'returntoquery'));
     $out = $this->getOutput();
     $out->addWikiMsg('logouttext', $loginURL);
     // Hook.
     $injected_html = '';
     Hooks::run('UserLogoutComplete', [&$user, &$injected_html, $oldName]);
     $out->addHTML($injected_html);
     $out->returnToMain();
 }
Esempio n. 19
0
 /**
  * @param string $id Session ID
  * @param array|mixed $blob Session metadata and data
  * @param int $expiry Expiry
  */
 public function setRawSession($id, $blob, $expiry = 0)
 {
     if ($expiry <= 0) {
         $expiry = \RequestContext::getMain()->getConfig()->get('ObjectCacheSessionExpiry');
     }
     $this->set(wfMemcKey('MWSession', $id), $blob, $expiry);
 }
 /**
  * @dataProvider provideValidate
  */
 public function testForm($text, $value)
 {
     $form = HTMLForm::factory('ooui', ['restrictions' => ['class' => HTMLRestrictionsField::class]]);
     $request = new FauxRequest(['wprestrictions' => $text], true);
     $context = new DerivativeContext(RequestContext::getMain());
     $context->setRequest($request);
     $form->setContext($context);
     $form->setTitle(Title::newFromText('Main Page'))->setSubmitCallback(function () {
         return true;
     })->prepareForm();
     $status = $form->trySubmit();
     if ($status instanceof StatusValue) {
         $this->assertEquals($value !== false, $status->isGood());
     } elseif ($value === false) {
         $this->assertNotSame(true, $status);
     } else {
         $this->assertSame(true, $status);
     }
     if ($value !== false) {
         $restrictions = $form->mFieldData['restrictions'];
         $this->assertInstanceOf(MWRestrictions::class, $restrictions);
         $this->assertEquals($value, $restrictions->toArray()['IPAddresses']);
     }
     // sanity
     $form->getHTML($status);
 }
Esempio n. 21
0
 /**
  * Does the API request and returns the result.
  *
  * The returned value is an array containing
  * - the result data (array)
  * - the request (WebRequest)
  * - the session data of the request (array)
  * - if $appendModule is true, the Api module $module
  *
  * @param array $params
  * @param array|null $session
  * @param bool $appendModule
  * @param User|null $user
  *
  * @return array
  */
 protected function doApiRequest(array $params, array $session = null, $appendModule = false, User $user = null)
 {
     global $wgRequest, $wgUser;
     if (is_null($session)) {
         // re-use existing global session by default
         $session = $wgRequest->getSessionArray();
     }
     // set up global environment
     if ($user) {
         $wgUser = $user;
     }
     $wgRequest = new FauxRequest($params, true, $session);
     RequestContext::getMain()->setRequest($wgRequest);
     RequestContext::getMain()->setUser($wgUser);
     // set up local environment
     $context = $this->apiContext->newTestContext($wgRequest, $wgUser);
     $module = new ApiMain($context, true);
     // run it!
     $module->execute();
     // construct result
     $results = array($module->getResult()->getResultData(null, array('Strip' => 'all')), $context->getRequest(), $context->getRequest()->getSessionArray());
     if ($appendModule) {
         $results[] = $module;
     }
     return $results;
 }
 public function execute($params = false)
 {
     $sEditLinkText = wfMessage('bs-widget-edit')->text();
     $oTitle = Title::makeTitle(NS_USER, RequestContext::getMain()->getUser()->getName() . '/Widgetbar');
     $sEditLink = Linker::link($oTitle, Html::rawElement('span', array(), $sEditLinkText), array('id' => 'bs-widgetbar-edit', 'class' => 'icon-pencil clearfix'), array('action' => 'edit', 'preload' => ''));
     $aOut = array();
     $aOut[] = '<div id="bs-widget-container" >';
     $aOut[] = '  <div class="icon-plus" id="bs-widget-tab" title="' . wfMessage('bs-widget-container-tooltip')->text() . '" tabindex="100">[+/-]</div>';
     $aOut[] = '  <div id="bs-flyout">';
     $aOut[] = '    <h4 id="bs-flyout-heading">' . wfMessage('bs-widget-flyout-heading')->text() . '</h4>';
     $aOut[] = '    <div id="bs-flyout-content">';
     $aOut[] = '      <div id="bs-flyout-content-widgets">';
     $aOut[] = '        <h4 id="bs-flyout-content-widgets-header">' . wfMessage("bs-widget-flyout-heading")->plain() . $sEditLink . '</h4>';
     foreach ($this->_mWidgets as $oWidgetView) {
         if ($oWidgetView instanceof ViewWidget) {
             $aOut[] = $oWidgetView->execute();
         } else {
             wfDebug(__METHOD__ . ': Invalid widget.');
         }
     }
     $aOut[] = '      </div>';
     $aOut[] = '    </div>';
     $aOut[] = '  </div>';
     $aOut[] = '</div>';
     return implode("\n", $aOut);
 }
Esempio n. 23
0
 function buildContent()
 {
     $harmoni = Harmoni::Instance();
     $basket = Basket::instance();
     $basket->removeAllItems();
     RequestContext::locationHeader($harmoni->request->quickURL("basket", "view"));
 }
Esempio n. 24
0
 /**
  * Returns a block of XHTML-valid code that contains markup for this specific
  * component. 
  * @param string $fieldName The field name to use when outputting form data or
  * similar parameters/information.
  * @access public
  * @return string
  */
 function getMarkup($fieldName)
 {
     $name = RequestContext::name($fieldName);
     $m = "<input type='text' \n\t\t\t\tname='{$name}' \n\t\t\t\tid='{$fieldName}' \n\t\t\t\tsize='" . $this->_size . "' maxlength='" . $this->_maxlength . "'" . (!$this->isEnabled() ? " readonly='readonly'" : "");
     if ($this->_value != null && $this->_value != $this->_startingDisplay) {
         $m .= " value='" . htmlspecialchars($this->_value, ENT_QUOTES) . "'";
     } else {
         if ($this->_startingDisplay) {
             $v = htmlspecialchars($this->_startingDisplay, ENT_QUOTES);
             $m .= "\n\t\t\t\tvalue='{$v}' style='color: #888' ";
             $m .= "\n\t\t\t\tonfocus='if (this.value == \"{$v}\") { this.value=\"\";  this.style.color=\"#000\";}'";
             $m .= "\n\t\t\t\tonblur='if (this.value == \"\") { this.value=\"{$v}\"; this.style.color=\"#888\";}'";
         }
     }
     if ($this->_style) {
         $m .= "\n\t\t\t\tstyle=\"" . str_replace("\"", "\\\"", $this->_style) . "\"";
     }
     if ($this->_onchange) {
         $m .= "\n\t\t\t\tonchange=\"" . str_replace("\"", "\\\"", $this->_onchange) . "\"";
     }
     $m .= " />";
     $errText = $this->getErrorText();
     $errRule = $this->getErrorRule();
     $errStyle = $this->getErrorStyle();
     if ($errText && $errRule) {
         $m .= "\n\t\t<span id='" . $fieldName . "_error' style=\"padding-left: 10px; {$errStyle}\">&laquo; {$errText}</span>";
         $m .= Wizard::getValidationJavascript($fieldName, $errRule, $fieldName . "_error", $this->_showError);
         $this->_showError = false;
     }
     return $m;
 }
Esempio n. 25
0
 /**
  * @return EventRelayerGroup
  */
 public static function singleton()
 {
     if (!self::$instance) {
         self::$instance = new self(RequestContext::getMain()->getConfig());
     }
     return self::$instance;
 }
Esempio n. 26
0
 /**
  * @param IContextSource|null $context
  */
 public function __construct(IContextSource $context = null)
 {
     if (!$context) {
         $context = RequestContext::getMain();
     }
     $this->context = $context;
 }
Esempio n. 27
0
 /**
  * Hook function for RecentChange_save
  * Saves user data into the cu_changes table
  */
 public static function updateCheckUserData(RecentChange $rc)
 {
     global $wgRequest;
     // Extract params
     extract($rc->mAttribs);
     // Get IP
     $ip = wfGetIP();
     // Get XFF header
     $xff = $wgRequest->getHeader('X-Forwarded-For');
     list($xff_ip, $isSquidOnly) = IP::getClientIPfromXFF($xff);
     // Get agent
     $agent = $wgRequest->getHeader('User-Agent');
     // Store the log action text for log events
     // $rc_comment should just be the log_comment
     // BC: check if log_type and log_action exists
     // If not, then $rc_comment is the actiontext and comment
     if (isset($rc_log_type) && $rc_type == RC_LOG) {
         $target = Title::makeTitle($rc_namespace, $rc_title);
         $context = RequestContext::newExtraneousContext($target);
         $formatter = LogFormatter::newFromRow($rc->mAttribs);
         $formatter->setContext($context);
         $actionText = $formatter->getPlainActionText();
     } else {
         $actionText = '';
     }
     $dbw = wfGetDB(DB_MASTER);
     $cuc_id = $dbw->nextSequenceValue('cu_changes_cu_id_seq');
     $rcRow = array('cuc_id' => $cuc_id, 'cuc_namespace' => $rc_namespace, 'cuc_title' => $rc_title, 'cuc_minor' => $rc_minor, 'cuc_user' => $rc_user, 'cuc_user_text' => $rc_user_text, 'cuc_actiontext' => $actionText, 'cuc_comment' => $rc_comment, 'cuc_this_oldid' => $rc_this_oldid, 'cuc_last_oldid' => $rc_last_oldid, 'cuc_type' => $rc_type, 'cuc_timestamp' => $rc_timestamp, 'cuc_ip' => IP::sanitizeIP($ip), 'cuc_ip_hex' => $ip ? IP::toHex($ip) : null, 'cuc_xff' => !$isSquidOnly ? $xff : '', 'cuc_xff_hex' => $xff_ip && !$isSquidOnly ? IP::toHex($xff_ip) : null, 'cuc_agent' => $agent);
     # On PG, MW unsets cur_id due to schema incompatibilites. So it may not be set!
     if (isset($rc_cur_id)) {
         $rcRow['cuc_page_id'] = $rc_cur_id;
     }
     $dbw->insert('cu_changes', $rcRow, __METHOD__);
     return true;
 }
Esempio n. 28
0
 /**
  * Build the content for this action
  * 
  * @return boolean
  * @access public
  * @since 4/26/05
  */
 function buildContent()
 {
     $actionRows = $this->getActionRows();
     $harmoni = Harmoni::instance();
     ob_start();
     CollectionsPrinter::printFunctionLinks();
     $layout = new Block(ob_get_contents(), STANDARD_BLOCK);
     ob_end_clean();
     $actionRows->add($layout, null, null, CENTER, CENTER);
     $type = HarmoniType::fromString(urldecode(RequestContext::value('type')));
     $repositoryManager = Services::getService("Repository");
     // Get the Repositories
     $allRepositories = $repositoryManager->getRepositoriesByType($type);
     // put the repositories into an array and order them.
     // @todo, do authorization checking
     $repositoryArray = array();
     while ($allRepositories->hasNext()) {
         $repository = $allRepositories->next();
         $repositoryArray[$repository->getDisplayName()] = $repository;
     }
     ksort($repositoryArray);
     // print the Results
     $resultPrinter = new ArrayResultPrinter($repositoryArray, 2, 20, "printrepositoryShort", $harmoni);
     $resultPrinter->addLinksStyleProperty(new MarginTopSP("10px"));
     $resultLayout = $resultPrinter->getLayout();
     $actionRows->add($resultLayout, null, null, CENTER, CENTER);
 }
Esempio n. 29
0
 public static function onArticleViewAfterParser(Article $article, ParserOutput $parserOutput)
 {
     global $wgCityId, $wgDBname;
     // we collect production data from Oasis only
     /*
     $app = F::app();
     if ( !$app->checkSkin( 'oasis', $app->wg->Skin )
     		|| $app->wg->DevelEnvironment || $app->wg->StagingEnvironment ) {
     	return true;
     }
     */
     if (class_exists('WScribeClient')) {
         try {
             $title = $article->getTitle();
             $fields = array('wikiId' => intval($wgCityId), 'databaseName' => $wgDBname, 'articleId' => $title->getArticleID(), 'namespaceId' => $title->getNamespace(), 'articleTitle' => $title->getText(), 'parserTime' => $parserOutput->getPerformanceStats('time'), 'wikitextSize' => $parserOutput->getPerformanceStats('wikitextSize'), 'htmlSize' => $parserOutput->getPerformanceStats('htmlSize'), 'expFuncCount' => $parserOutput->getPerformanceStats('expFuncCount'), 'nodeCount' => $parserOutput->getPerformanceStats('nodeCount'), 'postExpandSize' => $parserOutput->getPerformanceStats('postExpandSize'), 'tempArgSize' => $parserOutput->getPerformanceStats('tempArgSize'));
             $data = json_encode($fields);
             WScribeClient::singleton(self::SCRIBE_KEY)->send($data);
         } catch (TException $e) {
             Wikia::log(__METHOD__, 'scribeClient exception', $e->getMessage());
         }
     }
     // Logging parser activity for monitoring
     // wiki and article info are sent to logstash anyways so no need to repeat them here
     WikiaLogger::instance()->info("Parser execution", ['parser-time' => round($parserOutput->getPerformanceStats('time') * 1000), 'node-count' => (int) $parserOutput->getPerformanceStats('nodeCount'), 'wikitext-size' => (int) $parserOutput->getPerformanceStats('wikitextSize'), 'skin-name' => RequestContext::getMain()->getSkin()->getSkinName()]);
     return true;
 }
 protected function setUp()
 {
     parent::setUp();
     $langObj = Language::factory('en');
     $localZone = 'UTC';
     $localOffset = date('Z') / 60;
     $this->setMwGlobals(array('wgMemc' => new EmptyBagOStuff(), 'wgContLang' => $langObj, 'wgLanguageCode' => 'en', 'wgLang' => $langObj, 'wgLocaltimezone' => $localZone, 'wgLocalTZoffset' => $localOffset, 'wgNamespaceProtection' => array(NS_MEDIAWIKI => 'editinterface')));
     // Without this testUserBlock will use a non-English context on non-English MediaWiki
     // installations (because of how Title::checkUserBlock is implemented) and fail.
     RequestContext::resetMain();
     $this->userName = '******';
     $this->altUserName = '******';
     date_default_timezone_set($localZone);
     $this->title = Title::makeTitle(NS_MAIN, "Main Page");
     if (!isset($this->userUser) || !$this->userUser instanceof User) {
         $this->userUser = User::newFromName($this->userName);
         if (!$this->userUser->getID()) {
             $this->userUser = User::createNew($this->userName, array("email" => "*****@*****.**", "real_name" => "Test User"));
             $this->userUser->load();
         }
         $this->altUser = User::newFromName($this->altUserName);
         if (!$this->altUser->getID()) {
             $this->altUser = User::createNew($this->altUserName, array("email" => "*****@*****.**", "real_name" => "Test User Alt"));
             $this->altUser->load();
         }
         $this->anonUser = User::newFromId(0);
         $this->user = $this->userUser;
     }
 }