public function testLimit()
 {
     $obj = new ListEmbededInOptions();
     $this->assertEquals(null, $obj->getLimit());
     $this->assertEquals($obj, $obj->setLimit(100));
     $this->assertEquals(100, $obj->getLimit());
 }
Esempio n. 2
0
 /**
  * @param string $pageName
  * @param ListEmbededInOptions $options
  *
  * @return Pages
  */
 public function getPageListFromPageTransclusions($pageName, ListEmbededInOptions $options = null)
 {
     if (is_null($options)) {
         $options = new ListEmbededInOptions();
     }
     $continue = '';
     $limit = $options->getLimit();
     $pages = new Pages();
     while (true) {
         $params = array('list' => 'embeddedin', 'eititle' => $pageName, 'einamespace' => implode('|', $options->getNamespaces()));
         if (!empty($continue)) {
             $params['eicontinue'] = $continue;
         }
         if ($limit === null) {
             $params['eilimit'] = 5000;
         } else {
             $params['eilimit'] = $limit;
         }
         $result = $this->api->getRequest(new SimpleRequest('query', $params));
         if (!array_key_exists('query', $result)) {
             return $pages;
         }
         $limit = $limit - count($result['query']['embeddedin']);
         foreach ($result['query']['embeddedin'] as $member) {
             $pages->addPage(new Page(new PageIdentifier(new Title($member['title'], $member['ns']), $member['pageid']), new Revisions()));
         }
         if ($limit !== null && $limit <= 0) {
             return $pages;
         }
         if (empty($result['query-continue']['embeddedin']['eicontinue'])) {
             return $pages;
         } else {
             $continue = $result['query-continue']['embeddedin']['eicontinue'];
         }
     }
 }