Exemplo n.º 1
0
 public function testFromCache()
 {
     $instance = new Message();
     $instance->clear();
     $instance->registerCallbackHandler('SimpleText', function ($parameters, $language) {
         return 'Foo';
     });
     $instance->get('Foo', 'SimpleText');
     $this->assertEquals(array('inserts' => 1, 'deletes' => 0, 'max' => 1000, 'count' => 1, 'hits' => 0, 'misses' => 1), $instance->getCache()->getStats());
     $instance->get('Foo', 'SimpleText', 'ooo');
     $this->assertEquals(array('inserts' => 2, 'deletes' => 0, 'max' => 1000, 'count' => 2, 'hits' => 0, 'misses' => 2), $instance->getCache()->getStats());
     // Repeated request
     $instance->get('Foo', 'SimpleText');
     $this->assertEquals(array('inserts' => 2, 'deletes' => 0, 'max' => 1000, 'count' => 2, 'hits' => 1, 'misses' => 2), $instance->getCache()->getStats());
     $instance->deregisterHandlerFor('SimpleText');
 }
Exemplo n.º 2
0
 private function registerMessageCallbackHandler()
 {
     Message::registerCallbackHandler(Message::TEXT, function ($arguments, $language) {
         if ($language === Message::CONTENT_LANGUAGE) {
             $language = Localizer::getInstance()->getContentLanguage();
         }
         if ($language === Message::USER_LANGUAGE) {
             $language = Localizer::getInstance()->getUserLanguage();
         }
         return call_user_func_array('wfMessage', $arguments)->inLanguage($language)->text();
     });
     Message::registerCallbackHandler(Message::ESCAPED, function ($arguments, $language) {
         if ($language === Message::CONTENT_LANGUAGE) {
             $language = Localizer::getInstance()->getContentLanguage();
         }
         if ($language === Message::USER_LANGUAGE) {
             $language = Localizer::getInstance()->getUserLanguage();
         }
         return call_user_func_array('wfMessage', $arguments)->inLanguage($language)->escaped();
     });
     Message::registerCallbackHandler(Message::PARSE, function ($arguments, $language) {
         if ($language === Message::CONTENT_LANGUAGE) {
             $language = Localizer::getInstance()->getContentLanguage();
         }
         if ($language === Message::USER_LANGUAGE) {
             $language = Localizer::getInstance()->getUserLanguage();
         }
         // 1.27+
         // [GlobalTitleFail] MessageCache::parse called by ... Message::parseText/MessageCache::parse with no title set.
         return call_user_func_array('wfMessage', $arguments)->inLanguage($language)->title($GLOBALS['wgTitle'])->parse();
     });
 }