/** * @since 0.3 * * @param Page $page * @param string[] $protections where the 'key' is the action and the 'value' is the group * @param ProtectOptions $options * * @return bool * @throws InvalidArgumentException */ public function protect(Page $page, $protections, ProtectOptions $options = null) { if (!is_array($protections) || empty($protections)) { throw new InvalidArgumentException('$protections must be an array with keys and values'); } $params = array('pageid' => $page->getId(), 'token' => $this->api->getToken('protect')); $protectionsString = ''; foreach ($protections as $action => $value) { if (!is_string($action) || !is_string($value)) { throw new InvalidArgumentException('All keys and elements of $protections must be strings'); } $protectionsString = $action . '=' . $value . '|'; } $params['protections'] = rtrim($protectionsString, '|'); if ($options->getExpiry() !== 'infinite') { $params['expiry'] = $options->getExpiry(); } if ($options->getReason() !== '') { $params['reason'] = $options->getReason(); } if ($options->getCascade()) { $params['cascade'] = ''; } if ($options->getWatchlist() !== 'preferences') { $params['watchlist'] = $options->getWatchlist(); } $this->api->postRequest(new SimpleRequest('protect', $params)); return true; }
/** * @since 0.3 * * @brief Purge a single page * * Purges a single page by submitting a * 'purge' action to the mediawiki api * with the parameter 'pageids' set to * the singe page id * * @param Page $page the page that is going to be purged * * @return bool return true if the purge was successful */ public function purge(Page $page) { $responseArray = $this->api->postRequest(new SimpleRequest('purge', ['pageids' => $page->getId()])); // the purge response for the page $purgeResponse = $responseArray['purge'][0]; return array_key_exists('purged', $purgeResponse); }
/** * @since 0.3 * * @param Page $page * @param string[] $protections where the 'key' is the action and the 'value' is the group * @param array $extraParams * * @return bool * @throws InvalidArgumentException */ public function protect(Page $page, $protections, array $extraParams = []) { if (!is_array($protections) || empty($protections)) { throw new InvalidArgumentException('$protections must be an array with keys and values'); } $params = ['pageid' => $page->getId(), 'token' => $this->api->getToken('protect')]; $protectionsString = ''; foreach ($protections as $action => $value) { if (!is_string($action) || !is_string($value)) { throw new InvalidArgumentException('All keys and elements of $protections must be strings'); } $protectionsString = $action . '=' . $value . '|'; } $params['protections'] = rtrim($protectionsString, '|'); $this->api->postRequest(new SimpleRequest('protect', array_merge($extraParams, $params))); return true; }
/** * @since 0.2 * * @param Page $page * @param QueryOptions|null $options * * @return Page */ public function getFromPage(Page $page, QueryOptions $options = null) { if (is_null($options)) { $options = new QueryOptions(); } $result = $this->api->getRequest(new SimpleRequest('query', $this->getQuery(array('pageids' => $page->getId()), $options))); $revisions = $this->getRevisionsFromResult(array_shift($result['query']['pages'])); $revisions->addRevisions($page->getRevisions()); return new Page($page->getPageIdentifier(), $revisions); }
/** * @since 0.2 * * @param Page $page * @param Title $target * @param MoveOptions|null $options * * @return bool */ public function move(Page $page, Title $target, MoveOptions $options = null) { $this->api->postRequest(new SimpleRequest('move', $this->getMoveParams($page->getId(), $target, $options))); return true; }
/** * @since 0.2 * * @param Page $page * @param Title $target * @param array $extraParams * * @return bool */ public function move(Page $page, Title $target, array $extraParams = []) { $this->api->postRequest(new SimpleRequest('move', $this->getMoveParams($page->getId(), $target, $extraParams))); return true; }
/** * @since 0.2 * * @param Page $page * @param array $extraParams * * @return Page */ public function getFromPage(Page $page, array $extraParams = []) { $result = $this->api->getRequest(new SimpleRequest('query', $this->getQuery(['pageids' => $page->getId()], $extraParams))); $revisions = $this->getRevisionsFromResult(array_shift($result['query']['pages'])); $revisions->addRevisions($page->getRevisions()); return new Page($page->getPageIdentifier(), $revisions); }
/** * @param Page $page * * @return bool */ public function hasPage(Page $page) { return array_key_exists($page->getId(), $this->pages); }
/** * @since 0.3 * * @param Page $page * * @return bool */ public function purge(Page $page) { $this->api->postRequest(new SimpleRequest('purge', array('pageids' => $page->getId()))); return true; }