当前位置: 首页>>代码示例>>PHP>>正文


PHP ParserOutput::getSections方法代码示例

本文整理汇总了PHP中ParserOutput::getSections方法的典型用法代码示例。如果您正苦于以下问题:PHP ParserOutput::getSections方法的具体用法?PHP ParserOutput::getSections怎么用?PHP ParserOutput::getSections使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ParserOutput的用法示例。


在下文中一共展示了ParserOutput::getSections方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: headings

 /**
  * Get headings on the page.
  * @return string[]
  * First strip out things that look like references.  We can't use HTML filtering because
  * the references come back as <sup> tags without a class.  To keep from breaking stuff like
  *  ==Applicability of the strict mass–energy equivalence formula, ''E'' = ''mc''<sup>2</sup>==
  * we don't remove the whole <sup> tag.  We also don't want to strip the <sup> tag and remove
  * everything that looks like [2] because, I dunno, maybe there is a band named Word [2] Foo
  * or something.  Whatever.  So we only strip things that look like <sup> tags wrapping a
  * reference.  And since the data looks like:
  *      Reference in heading <sup>&#91;1&#93;</sup><sup>&#91;2&#93;</sup>
  * we can not really use HtmlFormatter as we have no suitable selector.
  */
 public function headings()
 {
     $headings = [];
     $ignoredHeadings = $this->getIgnoredHeadings();
     foreach ($this->parserOutput->getSections() as $heading) {
         $heading = $heading['line'];
         // Some wikis wrap the brackets in a span:
         // https://en.wikipedia.org/wiki/MediaWiki:Cite_reference_link
         $heading = preg_replace('/<\\/?span>/', '', $heading);
         // Normalize [] so the following regexp would work.
         $heading = preg_replace(['/&#91;/', '/&#93;/'], ['[', ']'], $heading);
         $heading = preg_replace('/<sup>\\s*\\[\\s*\\d+\\s*\\]\\s*<\\/sup>/is', '', $heading);
         // Strip tags from the heading or else we'll display them (escaped) in search results
         $heading = trim(Sanitizer::stripAllTags($heading));
         // Note that we don't take the level of the heading into account - all headings are equal.
         // Except the ones we ignore.
         if (!in_array($heading, $ignoredHeadings)) {
             $headings[] = $heading;
         }
     }
     return $headings;
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:35,代码来源:WikiTextStructure.php

示例2: execute


//.........这里部分代码省略.........
                 $result_array['wikitext'] = array();
                 $result->setContent($result_array['wikitext'], $this->text);
             }
             $result->addValue(null, $this->getModuleName(), $result_array);
             return;
         }
         // Not cached (save or load)
         $p_result = $wgParser->parse($params['pst'] ? $this->pstText : $this->text, $titleObj, $popts);
     }
     $result_array = array();
     $result_array['title'] = $titleObj->getPrefixedText();
     if (!is_null($oldid)) {
         $result_array['revid'] = intval($oldid);
     }
     if ($params['redirects'] && !is_null($redirValues)) {
         $result_array['redirects'] = $redirValues;
     }
     /* Wikia Change Starts */
     if (!$p_result instanceof ParserOutput) {
         \Wikia\Logger\WikiaLogger::instance()->error('ApiParse no ParserOutput', ['pageTitle' => $title]);
         // generate empty parser output to support code working on it
         $p_result = new ParserOutput('');
     }
     /* Wikia Change Ends */
     if (isset($prop['text'])) {
         $result_array['text'] = array();
         $result->setContent($result_array['text'], $p_result->getText());
     }
     if (!is_null($params['summary'])) {
         $result_array['parsedsummary'] = array();
         $result->setContent($result_array['parsedsummary'], Linker::formatComment($params['summary'], $titleObj));
     }
     if (isset($prop['langlinks'])) {
         $result_array['langlinks'] = $this->formatLangLinks($p_result->getLanguageLinks());
     }
     if (isset($prop['languageshtml'])) {
         $languagesHtml = $this->languagesHtml($p_result->getLanguageLinks());
         $result_array['languageshtml'] = array();
         $result->setContent($result_array['languageshtml'], $languagesHtml);
     }
     if (isset($prop['categories'])) {
         $result_array['categories'] = $this->formatCategoryLinks($p_result->getCategories());
     }
     if (isset($prop['categorieshtml'])) {
         $categoriesHtml = $this->categoriesHtml($p_result->getCategories());
         $result_array['categorieshtml'] = array();
         $result->setContent($result_array['categorieshtml'], $categoriesHtml);
     }
     if (isset($prop['links'])) {
         $result_array['links'] = $this->formatLinks($p_result->getLinks());
     }
     if (isset($prop['templates'])) {
         $result_array['templates'] = $this->formatLinks($p_result->getTemplates());
     }
     if (isset($prop['images'])) {
         $result_array['images'] = array_keys($p_result->getImages());
     }
     if (isset($prop['externallinks'])) {
         $result_array['externallinks'] = array_keys($p_result->getExternalLinks());
     }
     if (isset($prop['sections'])) {
         $result_array['sections'] = $p_result->getSections();
     }
     if (isset($prop['displaytitle'])) {
         $result_array['displaytitle'] = $p_result->getDisplayTitle() ? $p_result->getDisplayTitle() : $titleObj->getPrefixedText();
     }
     if (isset($prop['headitems']) || isset($prop['headhtml'])) {
         $context = $this->getContext();
         $context->setTitle($titleObj);
         $context->getOutput()->addParserOutputNoText($p_result);
         if (isset($prop['headitems'])) {
             $headItems = $this->formatHeadItems($p_result->getHeadItems());
             $css = $this->formatCss($context->getOutput()->buildCssLinksArray());
             $scripts = array($context->getOutput()->getHeadScripts());
             $result_array['headitems'] = array_merge($headItems, $css, $scripts);
         }
         if (isset($prop['headhtml'])) {
             $result_array['headhtml'] = array();
             $result->setContent($result_array['headhtml'], $context->getOutput()->headElement($context->getSkin()));
         }
     }
     if (isset($prop['iwlinks'])) {
         $result_array['iwlinks'] = $this->formatIWLinks($p_result->getInterwikiLinks());
     }
     if (isset($prop['wikitext'])) {
         $result_array['wikitext'] = array();
         $result->setContent($result_array['wikitext'], $this->text);
         if (!is_null($this->pstText)) {
             $result_array['psttext'] = array();
             $result->setContent($result_array['psttext'], $this->pstText);
         }
     }
     $result_mapping = array('redirects' => 'r', 'langlinks' => 'll', 'categories' => 'cl', 'links' => 'pl', 'templates' => 'tl', 'images' => 'img', 'externallinks' => 'el', 'iwlinks' => 'iw', 'sections' => 's', 'headitems' => 'hi');
     $this->setIndexedTagNames($result_array, $result_mapping);
     $result->addValue(null, $this->getModuleName(), $result_array);
     if (!is_null($oldLang)) {
         $wgLang = $oldLang;
         // Reset $wgLang to $oldLang
     }
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:101,代码来源:ApiParse.php


注:本文中的ParserOutput::getSections方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。