/** * Returns an array of all files with identical sha1 hashes * * @param int $limit Number of duplicates to get. Default null (all) * @param bool $force Force regeneration of the cache. Default false (use cache). * @return array Duplicate files */ public function get_duplicates($limit = null, $force = false) { if ($force || !count($this->duplicates)) { if (!$this->get_exists()) { return $this->duplicates; } $dArray = array('action' => 'query', 'prop' => 'duplicatefiles', 'dflimit' => is_null($limit) ? $this->wiki->get_api_limit() + 1 : $limit, 'titles' => $this->title); $continue = null; pecho("Getting duplicate images of {$this->title}..\n\n", PECHO_NORMAL); while (1) { if (!is_null($continue)) { $dArray['dfcontinue'] = $continue; } $dRes = $this->wiki->apiQuery($dArray); foreach ($dRes['query']['pages'] as $x) { if (isset($x['duplicatefiles'])) { foreach ($x['duplicatefiles'] as $y) { $this->duplicates[] = $y['name']; } } } if (isset($dRes['query-continue'])) { foreach ($dRes['query-continue'] as $z) { $continue = $z['dfcontinue']; } } else { break; } } } return $this->duplicates; }
/** * Returns page history. Can be specified to return content as well * * @param int $count Revisions to return (default: 1) * @param string $dir Direction to return revisions (default: "older") * @param bool $content Should content of that revision be returned as well (default: false) * @param int $revid Revision ID to start from (default: null) * @param bool $rollback_token Should a rollback token be returned (default: false) * @param bool $recurse Used internally to provide more results than can be returned with a single API query * @return array Revision data */ public function history($count = 1, $dir = "older", $content = false, $revid = null, $rollback_token = false, $recurse = false) { if (!$this->exists) { return array(); } $historyArray = array('action' => 'query', 'prop' => 'revisions', 'titles' => $this->title, 'rvprop' => 'timestamp|ids|user|comment', 'rawcontinue' => 1, 'rvdir' => $dir); if ($content) { $historyArray['rvprop'] .= "|content"; } if (!is_null($revid)) { $historyArray['rvstartid'] = $revid; } if (!is_null($count)) { $historyArray['rvlimit'] = $count; } if ($rollback_token) { $historyArray['rvtoken'] = 'rollback'; } if (!$recurse) { pecho("Getting page history for {$this->title}..\n\n", PECHO_NORMAL); } if (is_null($count)) { $history = $ei = $this->history($this->wiki->get_api_limit() + 1, $dir, $content, $revid, $rollback_token, true); while (!is_null($ei[1])) { $ei = $this->history($this->wiki->get_api_limit() + 1, $dir, $content, $ei[1], $rollback_token, true); foreach ($ei[0] as $eg) { $history[0][] = $eg; } } return $history[0]; } $historyResult = $this->wiki->apiQuery($historyArray); if ($recurse) { if (isset($historyResult['query-continue'])) { return array($historyResult['query']['pages'][$this->pageid]['revisions'], $historyResult['query-continue']['revisions']['rvcontinue']); } return array($historyResult['query']['pages'][$this->pageid]['revisions'], null); } return $historyResult['query']['pages'][$this->pageid]['revisions']; }