Esempio n. 1
0
 /**
  * Get input variables and create a move plan from them
  *
  * @return bool
  */
 protected function createPlanFromInput()
 {
     global $INPUT;
     global $ID;
     if ($this->plan->isCommited()) {
         return false;
     }
     $this->plan->setOption('autoskip', $INPUT->bool('autoskip'));
     $this->plan->setOption('autorewrite', $INPUT->bool('autorewrite'));
     if ($ID && $INPUT->has('dst')) {
         $dst = trim($INPUT->str('dst'));
         if ($dst == '') {
             msg($this->getLang('nodst'), -1);
             return false;
         }
         // input came from form
         if ($INPUT->str('class') == 'namespace') {
             $src = getNS($ID);
             if ($INPUT->str('type') == 'both') {
                 $this->plan->addPageNamespaceMove($src, $dst);
                 $this->plan->addMediaNamespaceMove($src, $dst);
             } else {
                 if ($INPUT->str('type') == 'page') {
                     $this->plan->addPageNamespaceMove($src, $dst);
                 } else {
                     if ($INPUT->str('type') == 'media') {
                         $this->plan->addMediaNamespaceMove($src, $dst);
                     }
                 }
             }
         } else {
             $this->plan->addPageMove($ID, $INPUT->str('dst'));
         }
         $this->plan->commit();
         return true;
     } elseif ($INPUT->has('json')) {
         // input came via JSON from tree manager
         $json = new JSON(JSON_LOOSE_TYPE);
         $data = $json->decode($INPUT->str('json'));
         foreach ((array) $data as $entry) {
             if ($entry['class'] == 'ns') {
                 if ($entry['type'] == 'page') {
                     $this->plan->addPageNamespaceMove($entry['src'], $entry['dst']);
                 } elseif ($entry['type'] == 'media') {
                     $this->plan->addMediaNamespaceMove($entry['src'], $entry['dst']);
                 }
             } elseif ($entry['class'] == 'doc') {
                 if ($entry['type'] == 'page') {
                     $this->plan->addPageMove($entry['src'], $entry['dst']);
                 } elseif ($entry['type'] == 'media') {
                     $this->plan->addMediaMove($entry['src'], $entry['dst']);
                 }
             }
         }
         $this->plan->commit();
         return true;
     }
     return false;
 }