Ejemplo n.º 1
0
 private static function lookForCategory(&$text, $outerTag)
 {
     self::$categories = array();
     self::$outerTag = $outerTag;
     $text = preg_replace_callback('/\\[\\[(' . self::$namespaces . '):([^]]+)]]\\n?/i', array('self', 'replaceCallback'), $text);
     $result = array('text' => $text, 'categories' => self::$categories);
     $maybeIndex = count(self::$maybeCategory);
     if ($maybeIndex) {
         //look for category ending
         //TODO: this will not catch [[Category:Abc<noinclude>]]</noinclude>
         if (self::$nodeLevel == self::$maybeCategory[$maybeIndex - 1]['level'] && preg_match('/^([^[]*?]])/', $text, $match)) {
             $text = preg_replace('/^[^[]*?]]/', '', $text, 1);
             self::$maybeCategory[$maybeIndex - 1]['end'] = $match[1];
             self::$maybeCategory[$maybeIndex - 1]['beginSibblingsBefore'] = self::$maybeCategoryBegin[self::$nodeLevel];
         }
     }
     if (preg_match('/(\\[\\[(?:' . self::$namespaces . '):.*$)/i', $text, $match)) {
         self::$maybeCategory[$maybeIndex] = array('namespace' => $match[1], 'begin' => $match[1], 'level' => self::$nodeLevel);
         self::$maybeCategoryBegin[self::$nodeLevel] = 0;
     }
     return $result;
 }