示例#1
0
 /**
  * @param $processor callback function to process a single PageNode.
  * Must have two parameters: WikiTitle and page source.
  */
 public function processSources($processor)
 {
     $logger = $this->logger;
     $callback = function ($path, $source) use(&$processor, $logger) {
         // cut off '#1.txt' or '.txt' if necessary
         $sep = strrpos($path, '#');
         if ($sep === false) {
             $sep = strrpos($path, '.');
             if ($sep === false) {
                 $sep = -1;
             }
         }
         $slash = strrpos($path, '/');
         if ($slash === false) {
             $slash = -1;
         }
         $pageName = $sep > $slash ? substr($path, 0, $sep) : $path;
         try {
             $title = WikiTitle::parse($pageName);
         } catch (\Exception $e) {
             $logger->warn('failed to get wiki title for path  ' . $path . ' / page name ' . $pageName . ': ' . $e->getMessage() . PHP_EOL . $e->getTraceAsString());
             return;
         }
         call_user_func($processor, $title, $source);
     };
     $this->processor->processFiles($callback);
 }
示例#2
0
 protected function processEndTag()
 {
     $this->currentTag = '';
     $this->isInsideData = false;
     if ($this->currentTitle && $this->currentSource) {
         try {
             $title = WikiTitle::parse($this->currentTitle);
         } catch (\Exception $e) {
             $this->logger->warn('Exception parsing title' . $this->currentTitle . PHP_EOL . $e->getTraceAsString());
             $this->currentTitle = null;
             $this->currentSource = null;
             return;
         }
         if (in_array($title->nsCode(), $this->namespaces)) {
             call_user_func($this->processor, $title, $this->currentSource);
         }
         $this->currentTitle = null;
         $this->currentSource = null;
     }
 }
示例#3
0
 public function process()
 {
     $this->action = @self::$actions[$_REQUEST['newarticle']];
     if ($this->action === null) {
         return $this->response(400, 'Missing action');
     }
     $this->rawTitle = @$_REQUEST['title'];
     if ($this->rawTitle === null) {
         return $this->response(400, 'Missing page title');
     }
     // TODO: source is not required when action is delete
     $this->rawPage = @$_REQUEST['source'];
     if ($this->rawPage === null) {
         return $this->response(400, 'Missing page source');
     }
     $this->revision = @$_REQUEST['revision'];
     // revision is optional
     $this->reply = @$_REQUEST['mode'] === 'reply';
     try {
         $this->parsedTitle = WikiTitle::parse($this->rawTitle);
     } catch (\Exception $e) {
         return $this->response(400, 'Invalid page title', 'Invalid page title - ' . $e->getMessage());
     }
     if (defined('dbpedia\\LocalConfiguration::ultraUser') && defined('dbpedia\\LocalConfiguration::ultraPassword')) {
         $this->logIn();
     }
     $this->log->info('received update for page ' . $this->parsedTitle);
     $this->configHandler = new ConfigHandler(LocalConfiguration::ontologyDir, LocalConfiguration::mappingDir, LocalConfiguration::configFile);
     if ($this->processOntology()) {
         return;
     }
     if ($this->processTemplateMapping()) {
         return;
     }
     if ($this->processTableMapping()) {
         return;
     }
     if ($this->processData()) {
         return;
     }
     $this->processOther();
 }