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


PHP Wiki::get_mw_version方法代码示例

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


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

示例1: get_text

 /**
  * Retrieves text from a page, or a cached copy unless $force is true
  *
  * @param bool $force Grab text from the API, don't use the cached copy (default: false)
  * @param string|int $section Section title or ID to retrieve
  * @return string|bool Page content
  */
 public function get_text($force = false, $section = null)
 {
     pecho("Getting page content for {$this->title}..\n\n", PECHO_NOTICE);
     if (!$this->exists) {
         return null;
     }
     if (!is_null($section)) {
         if (empty($this->content)) {
             $this->content = $this->history(1, "older", true);
             $this->content = $this->content[0]['*'];
         }
         $sections = $this->wiki->apiQuery(array('action' => 'parse', 'page' => $this->title, 'prop' => 'sections'));
         if (!is_numeric($section)) {
             foreach ($sections['parse']['sections'] as $section3) {
                 if ($section3['line'] == $section) {
                     $section = $section3['number'];
                 }
             }
         }
         if (!is_numeric($section)) {
             pecho("Warning: Section not found.\n\n", PECHO_WARN);
             return false;
         }
         $offsets = array('0' => '0');
         if ($this->wiki->get_mw_version() < '1.16') {
             //FIXME: Implement proper notice suppression
             $ids = array();
             foreach ($sections['parse']['sections'] as $section3) {
                 $ids[$section3['line']] = $section3['number'];
             }
             $regex = '/^(=+)\\s*(.*?)\\s*(\\1)\\s*/m';
             preg_match_all($regex, $this->content, $m, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
             foreach ($m as $id => $match) {
                 $offsets[$id + 1] = $match[0][1];
             }
         } else {
             foreach ($sections['parse']['sections'] as $section2) {
                 $offsets[$section2['number']] = $section2['byteoffset'];
             }
         }
         if (intval($section) != count($offsets) - 1) {
             $length = $offsets[$section + 1] - $offsets[$section];
         }
         if (isset($length)) {
             $substr = mb_substr($this->content, $offsets[$section], $length);
         } else {
             $substr = mb_substr($this->content, $offsets[$section]);
         }
         return $substr;
     } else {
         if (!$force && $this->content !== null) {
             return $this->content;
         }
         $this->content = $this->history(1, "older", true);
         $this->content = $this->content[0]['*'];
         return $this->content;
     }
 }
开发者ID:emijrp,项目名称:Peachy,代码行数:65,代码来源:Page.php


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