コード例 #1
0
ファイル: Page.php プロジェクト: emijrp/Peachy
 /**
  * Moves a page to a new location.
  *
  * @param string $newTitle The new title to which to move the page.
  * @param string $reason A descriptive reason for the move.
  * @param bool $movetalk Whether or not to move any associated talk (discussion) page.
  * @param bool $movesubpages Whether or not to move any subpages.
  * @param bool $noredirect Whether or not to suppress the leaving of a redirect to the new title at the old title.
  * @param string|bool $watch Unconditionally add or remove the page from your watchlist, use preferences or do not change watch. Default: go by user preference.
  * @param bool $nowarnings Ignore any warnings. Default false.
  * @return bool True on success
  */
 public function move($newTitle, $reason = '', $movetalk = true, $movesubpages = true, $noredirect = false, $watch = null, $nowarnings = false)
 {
     global $pgNotag, $pgTag;
     $tokens = $this->wiki->get_tokens();
     if ($tokens['move'] == '+\\') {
         pecho("User has logged out.\n\n", PECHO_FATAL);
         return false;
     } elseif ($tokens['move'] == '') {
         pecho("User is not allowed to move {$this->title}\n\n", PECHO_FATAL);
         return false;
     }
     if (mb_strlen($reason, '8bit') > 255) {
         pecho("Reason is over 255 bytes, the maximum allowed.\n\n", PECHO_FATAL);
         return false;
     }
     try {
         $this->preEditChecks("Move");
     } catch (EditError $e) {
         pecho("Error: {$e}\n\n", PECHO_FATAL);
         return false;
     }
     pecho("Moving {$this->title} to {$newTitle}...\n\n", PECHO_NOTICE);
     $editarray = array('from' => $this->title, 'to' => $newTitle, 'action' => 'move', 'token' => $tokens['move']);
     if (!is_null($watch)) {
         if ($watch) {
             $editarray['watchlist'] = 'watch';
         } elseif (!$watch) {
             $editarray['watchlist'] = 'nochange';
         } elseif (in_array($watch, array('watch', 'unwatch', 'preferences', 'nochange'))) {
             $editarray['watchlist'] = $watch;
         } else {
             pecho("Watch parameter set incorrectly.  Omitting...\n\n", PECHO_WARN);
         }
     }
     if ($nowarnings) {
         $editarray['ignorewarnings'] = 'yes';
     }
     if (!$pgNotag) {
         $reason .= $pgTag;
     }
     if (!empty($reason)) {
         $editarray['reason'] = $reason;
     }
     if ($movetalk) {
         $editarray['movetalk'] = 'yes';
     }
     if ($movesubpages) {
         $editarray['movesubpages'] = 'yes';
     }
     if ($noredirect) {
         $editarray['noredirect'] = 'yes';
     }
     if ($this->wiki->get_maxlag()) {
         $editarray['maxlag'] = $this->wiki->get_maxlag();
     }
     Hooks::runHook('StartMove', array(&$editarray));
     $result = $this->wiki->apiQuery($editarray, true);
     if (isset($result['move'])) {
         if (isset($result['move']['to'])) {
             $this->__construct($this->wiki, null, $this->pageid);
             return true;
         } else {
             pecho("Move error...\n\n" . print_r($result['move'], true) . "\n\n", PECHO_FATAL);
             return false;
         }
     } else {
         pecho("Move error...\n\n" . print_r($result, true), PECHO_FATAL);
         return false;
     }
 }