コード例 #1
0
ファイル: Wiki.php プロジェクト: emijrp/Peachy
 /**
  * Generate a diff between two or three revision IDs
  *
  * @access public
  * @param string $method Revision method. Options: unified, inline, context, threeway, raw (default: 'unified')
  * @param mixed $rev1
  * @param mixed $rev2
  * @param mixed $rev3
  * @return string|bool False on failure
  * @see Diff::load
  *
  * @fixme: this uses Diff::load, which has been deprecated and Plugin removed from codebase
  */
 public function diff($method = 'unified', $rev1, $rev2, $rev3 = null)
 {
     $r1array = array('action' => 'query', 'prop' => 'revisions', 'revids' => $rev1, 'rvprop' => 'content');
     $r2array = array('action' => 'query', 'prop' => 'revisions', 'revids' => $rev2, 'rvprop' => 'content');
     $r3array = array('action' => 'query', 'prop' => 'revisions', 'revids' => $rev3, 'rvprop' => 'content');
     Hooks::runHook('PreDiff', array(&$r1array, &$r2array, &$r3array, &$method));
     $r1text = $r2text = $r3text = null;
     if (!is_null($rev3)) {
         pecho("Getting {$method} diff of revisions {$rev1}, {$rev2}, and {$rev3}...\n\n", PECHO_NORMAL);
         $r3 = $this->apiQuery($r3array);
         if (isset($r3['query']['badrevids'])) {
             pecho("A bad third revision ID was passed.\n\n", PECHO_FATAL);
             return false;
         }
         foreach ($r3['query']['pages'] as $r3pages) {
             $r3text = $r3pages['revisions'][0]['*'];
         }
     } else {
         pecho("Getting {$method} diff of revisions {$rev1} and {$rev2}...\n\n", PECHO_NORMAL);
     }
     $r1 = $this->apiQuery($r1array);
     $r2 = $this->apiQuery($r2array);
     if (isset($r1['query']['badrevids'])) {
         pecho("A bad first revision ID was passed.\n\n", PECHO_FATAL);
         return false;
     } elseif (isset($r2['query']['badrevids'])) {
         pecho("A bad second revision ID was passed.\n\n", PECHO_FATAL);
         return false;
     } else {
         foreach ($r1['query']['pages'] as $r1pages) {
             $r1text = $r1pages['revisions'][0]['*'];
         }
         foreach ($r2['query']['pages'] as $r2pages) {
             $r2text = $r2pages['revisions'][0]['*'];
         }
         if ($method == "raw") {
             return array($r1text, $r2text, $r3text);
         }
         return Diff::load($method, $r1text, $r2text, $r3text);
     }
 }