示例#1
0
 /**
  * @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;
 }
示例#2
0
 /**
  * @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);
 }
示例#3
0
 /**
  * @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;
 }
示例#4
0
 /**
  * @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);
 }
示例#5
0
 /**
  * @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;
 }
示例#6
0
 /**
  * @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;
 }
示例#7
0
 /**
  * @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);
 }
示例#8
0
 /**
  * @param Page $page
  *
  * @return bool
  */
 public function hasPage(Page $page)
 {
     return array_key_exists($page->getId(), $this->pages);
 }
示例#9
0
 /**
  * @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;
 }