Esempio n. 1
0
 public function parseText($rawText)
 {
     global $wgEnableParserCache;
     $this->mRawtext = self::removeMetadataTag($rawText);
     $wgEnableParserCache = false;
     $parser = ParserPool::get();
     $parser->ac_metadata = [];
     // VOLDEV-68: Remove broken section edit links
     $opts = ParserOptions::newFromContext(RequestContext::getMain());
     $opts->setEditSection(false);
     $head = $parser->parse($rawText, $this->mTitle, $opts);
     $this->mText = wfFixMalformedHTML($head->getText());
     $this->mHeadItems = $head->getHeadItems();
     if (isset($parser->ac_metadata)) {
         $this->mMetadata = $parser->ac_metadata;
     } else {
         $this->mMetadata = [];
     }
     ParserPool::release($parser);
     return $this->mText;
 }
Esempio n. 2
0
 public static function onGalleryBeforeProduceHTML($data, &$out)
 {
     global $wgArticleAsJson;
     wfProfileIn(__METHOD__);
     if ($wgArticleAsJson) {
         $parser = ParserPool::get();
         $parserOptions = new ParserOptions();
         $title = F::app()->wg->Title;
         $media = [];
         foreach ($data['images'] as $image) {
             $details = WikiaFileHelper::getMediaDetail(Title::newFromText($image['name'], NS_FILE), self::$mediaDetailConfig);
             $details['context'] = self::MEDIA_CONTEXT_GALLERY_IMAGE;
             $caption = $image['caption'];
             if (!empty($caption)) {
                 $caption = $parser->parse($caption, $title, $parserOptions, false)->getText();
             }
             $linkHref = isset($image['linkhref']) ? $image['linkhref'] : null;
             $media[] = self::createMediaObject($details, $image['name'], $caption, $linkHref);
             self::addUserObj($details);
         }
         self::$media[] = $media;
         if (!empty($media)) {
             $out = self::createMarker($media[0]['width'], $media[0]['height'], true);
         } else {
             $out = '';
         }
         ParserPool::release($parser);
         wfProfileOut(__METHOD__);
         return false;
     }
     wfProfileOut(__METHOD__);
     return true;
 }
Esempio n. 3
0
 /**
  * Get Parser instance that's suitable for passing it to CoreParserFunctions
  * in MessageCache::transform()
  *
  * @author Władysław Bodzek <*****@*****.**>
  *
  * @param ParserOptions $popts
  * @return Parser
  */
 function getParserFor(ParserOptions $popts)
 {
     $interfaceMessage = $popts->getInterfaceMessage();
     $userLanguage = $popts->getUserLang();
     $hash = array();
     foreach (array($interfaceMessage, $userLanguage) as $obj) {
         if (is_object($obj)) {
             $hash[] = get_class($obj);
         } else {
             $hash[] = serialize($obj);
         }
     }
     $hash = implode('|', $hash);
     if (!isset(self::$parsersCache[$hash])) {
         if (count(self::$parsersCache) > 25) {
             foreach (self::$parsersCache as $parser) {
                 ParserPool::release($parser);
             }
         }
         $parser = ParserPool::get();
         $parser->startExternalParse(new Title('DoesntExistXYZ'), $popts, Parser::OT_PREPROCESS, true);
         self::$parsersCache[$hash] = $parser;
     }
     return self::$parsersCache[$hash];
 }