/**
  * @param ListLogEventsOptions $options
  *
  * @return LogList
  */
 public function getLogList(ListLogEventsOptions $options = null)
 {
     if ($options == null) {
         $options = new ListLogEventsOptions();
     }
     $logList = new LogList();
     $continue = '';
     $limit = $options->getLimit();
     while (true) {
         $params = $this->getParamsFromOptions($options);
         if (!empty($continue)) {
             $params['lecontinue'] = $continue;
         }
         if ($limit === null) {
             $params['lelimit'] = 5000;
         } else {
             $params['lelimit'] = $limit;
         }
         $result = $this->api->getRequest(new SimpleRequest('query', $params));
         $limit = $limit - count($result['query']['logevents']);
         foreach ($result['query']['logevents'] as $logevent) {
             $logList->addLog(new Log($logevent['logid'], $logevent['type'], $logevent['action'], $logevent['timestamp'], $logevent['user'], new Page(new PageIdentifier(new Title($logevent['title'], $logevent['ns']), $logevent['pageid']), new Revisions()), $logevent['comment'], $this->getLogDetailsFromEvent($logevent)));
         }
         if ($limit !== null && $limit <= 0) {
             return $logList;
         }
         if (empty($result['query-continue']['logevents']['lecontinue'])) {
             return $logList;
         } else {
             $continue = $result['query-continue']['logevents']['lecontinue'];
         }
     }
 }
 /**
  * @see EntityDocumentLookup::getEntityDocumentsForIds
  */
 public function getEntityDocumentsForIds(array $entityIds)
 {
     if (empty($entityIds)) {
         return array();
     }
     return $this->parseResponse($this->api->getRequest($this->buildRequest($entityIds)));
 }
 /**
  * @param string $guid
  *
  * @return Statement
  */
 public function getFromGuid($guid)
 {
     $params = array('claim' => $guid);
     $result = $this->api->getRequest(new SimpleRequest('wbgetclaims', $params));
     $statementSerialization = array_shift(array_shift($result['claims']));
     return $this->statementDeserializer->deserialize($statementSerialization);
 }
 /**
  * @since 0.5
  * @return ItemId[]
  */
 public function get()
 {
     $result = $this->api->getRequest(new SimpleRequest('wbavailablebadges'));
     $ids = array();
     foreach ($result['badges'] as $badgeIdString) {
         $ids[] = new ItemId($badgeIdString);
     }
     return $ids;
 }
 /**
  * @since 0.2
  *
  * @param DataValue $value
  * @param string $dataTypeId
  * @param GenericOptions $options
  *
  * @returns string
  */
 public function format(DataValue $value, $dataTypeId, GenericOptions $options = null)
 {
     if ($options === null) {
         $options = new GenericOptions();
     }
     $params = array('datavalue' => json_encode($this->dataValueSerializer->serialize($value)), 'datatype' => $dataTypeId, 'options' => json_encode($options->getOptions()));
     $result = $this->api->getRequest(new SimpleRequest('wbformatvalue', $params));
     return $result['result'];
 }
 /**
  * Query the remote site for the list of namespaces in use, so that later we can tell what's a
  * category and what's not. This populates $this->namespaces, and will not re-request on
  * repeated invocations.
  * @return void
  */
 protected function retrieveNamespaces()
 {
     if (is_array($this->namespaces)) {
         return;
     }
     $params = ['meta' => 'siteinfo', 'siprop' => 'namespaces'];
     $namespaces = $this->api->getRequest(new SimpleRequest('query', $params));
     if (isset($namespaces['query']['namespaces'])) {
         $this->namespaces = $namespaces['query']['namespaces'];
     }
 }
 /**
  * @since 0.1
  *
  * @return SiteList
  */
 public function getSiteList()
 {
     $sitematrixResult = $this->api->getRequest(new SimpleRequest('sitematrix'));
     unset($sitematrixResult['sitematrix']['count']);
     $siteListArray = array();
     foreach ($sitematrixResult['sitematrix'] as $key => $siteGroup) {
         foreach ($siteGroup['site'] as $details) {
             $siteListArray[] = new Site($details['url'], $details['dbname'], $details['code'], $details['sitename']);
         }
     }
     $siteList = new SiteList($siteListArray);
     return $siteList;
 }
 /**
  * @param array $extraParams
  *
  * @return LogList
  */
 public function getLogList(array $extraParams = [])
 {
     $logList = new LogList();
     while (true) {
         $params = ['list' => 'logevents', 'leprop' => 'title|ids|type|user|timestamp|comment|details'];
         $newParams = array_merge($extraParams, $params);
         $result = $this->api->getRequest(new SimpleRequest('query', $newParams));
         foreach ($result['query']['logevents'] as $logevent) {
             $logList->addLog(new Log($logevent['logid'], $logevent['type'], $logevent['action'], $logevent['timestamp'], $logevent['user'], new Page(new PageIdentifier(new Title($logevent['title'], $logevent['ns']), $logevent['pageid']), new Revisions()), $logevent['comment'], $this->getLogDetailsFromEvent($logevent)));
         }
         return $logList;
     }
 }
 /**
  * @see EntityRedirectLookup::getRedirectForEntityId
  */
 public function getRedirectForEntityId(EntityId $entityId, $forUpdate = '')
 {
     $entityIdSerialization = $entityId->getSerialization();
     $params = array('ids' => $entityIdSerialization);
     $result = $this->api->getRequest(new SimpleRequest('wbgetentities', $params));
     $entitiesData = $result['entities'];
     if (!array_key_exists($entityIdSerialization, $entitiesData)) {
         throw new EntityRedirectLookupException($entityId, "Failed to get {$entityIdSerialization}");
     }
     $entityData = $entitiesData[$entityIdSerialization];
     if (!array_key_exists('redirects', $entityData)) {
         throw new EntityRedirectLookupException($entityId, "{$entityIdSerialization} is not a redirect");
     }
     $entityIdParser = new BasicEntityIdParser();
     return $entityIdParser->parse($entityData['redirects']['to']);
 }
Beispiel #10
0
 /**
  * @since 0.2
  *
  * @param Revision $revision
  * @param array $extraParams
  *
  * @return Page
  */
 public function getFromRevision(Revision $revision, array $extraParams = [])
 {
     $result = $this->api->getRequest(new SimpleRequest('query', $this->getQuery(['revids' => $revision->getId()], $extraParams)));
     $revisions = $this->getRevisionsFromResult(array_shift($result['query']['pages']));
     $revisions->addRevision($revision);
     return new Page(new PageIdentifier(new Title($result['title'], $result['ns']), $result['pageid']), $revisions);
 }
Beispiel #11
0
 /**
  * @since 0.2
  *
  * @param Revision $revision
  * @param QueryOptions|null $options
  *
  * @return Page
  */
 public function getFromRevision(Revision $revision, QueryOptions $options = null)
 {
     if (is_null($options)) {
         $options = new QueryOptions();
     }
     $result = $this->api->getRequest(new SimpleRequest('query', $this->getQuery(array('revids' => $revision->getId()), $options)));
     $revisions = $this->getRevisionsFromResult(array_shift($result['query']['pages']));
     $revisions->addRevision($revision);
     return new Page(new PageIdentifier(new Title($result['title'], $result['ns']), $result['pageid']), $revisions);
 }
 /**
  * Get revisions for the entities identified using as few requests as possible.
  *
  * @param array $identifyingInfoArray Can include the following:
  *     EntityId EntityId objects
  *     SiteLink SiteLink objects
  *     string Serialized entity ids (these are not validated before passing to the api)
  *
  * @since 0.4
  *
  * @return Revisions
  */
 public function getRevisions(array $identifyingInfoArray)
 {
     $entityIdStrings = array();
     $siteLinksStringMapping = array();
     foreach ($identifyingInfoArray as $someInfo) {
         if ($someInfo instanceof EntityId) {
             $entityIdStrings[] = $someInfo->getSerialization();
         } elseif ($someInfo instanceof SiteLink) {
             $siteLinksStringMapping[$someInfo->getSiteId()][] = $someInfo->getPageName();
         } elseif (is_string($someInfo)) {
             $entityIdStrings[] = $someInfo;
         } else {
             throw new InvalidArgumentException('Unexpected $identifyingInfoArray in RevisionsGetter::getRevisions');
         }
     }
     // The below makes as few requests as possible to get the Revisions required!
     $gotRevisionsFromIds = false;
     $revisions = new Revisions();
     if (!empty($siteLinksStringMapping)) {
         foreach ($siteLinksStringMapping as $site => $siteLinkStrings) {
             $params = array('sites' => $site);
             if (!$gotRevisionsFromIds && !empty($entityIdStrings)) {
                 $params['ids'] = implode('|', $entityIdStrings);
                 $gotRevisionsFromIds = true;
             }
             $params['titles'] = implode('|', $siteLinkStrings);
             $result = $this->api->getRequest(new SimpleRequest('wbgetentities', $params));
             $resultRevisions = $this->newRevisionsFromResult($result['entities']);
             $revisions->addRevisions($resultRevisions);
         }
     } else {
         $params = array('ids' => implode('|', $entityIdStrings));
         $result = $this->api->getRequest(new SimpleRequest('wbgetentities', $params));
         $resultRevisions = $this->newRevisionsFromResult($result['entities']);
         $revisions->addRevisions($resultRevisions);
     }
     return $revisions;
 }
 /**
  * Run a query to completion.
  *
  * @param string[] $params Query parameters
  * @param string $contName Result subelement name for continue details
  * @param string $resName Result element name for main results array
  * @param string $pageIdName Result element name for page ID
  * @param boolean $cont Whether to continue the query, using multiple requests
  * @return Pages
  */
 protected function runQuery($params, $contName, $resName, $pageIdName = 'pageid', $cont = true)
 {
     $pages = new Pages();
     do {
         // Set up continue parameter if it's been set already.
         if (isset($result['continue'][$contName])) {
             $params[$contName] = $result['continue'][$contName];
         }
         // Run the actual query.
         $result = $this->api->getRequest(new SimpleRequest('query', $params));
         if (!array_key_exists('query', $result)) {
             return $pages;
         }
         // Add the results to the output page list.
         foreach ($result['query'][$resName] as $member) {
             $pageTitle = new Title($member['title'], $member['ns']);
             $page = new Page(new PageIdentifier($pageTitle, $member[$pageIdName]));
             $pages->addPage($page);
         }
     } while ($cont && isset($result['continue']));
     return $pages;
 }
 /**
  * @param ListRandomOptions $options
  */
 public function getRandom(ListRandomOptions $options = null)
 {
     if (is_null($options)) {
         $options = new ListRandomOptions();
     }
     $continue = '';
     $limit = $options->getLimit();
     $pages = new Pages();
     while (true) {
         $params = array('list' => 'random', 'rnlimit' => $options->getLimit(), 'rnnamespace' => implode('|', $options->getNamespaces()));
         if ($options->getRedirectsOnly() === true) {
             $params['rnredirect'] = 1;
         }
         if (!empty($continue)) {
             $params['rncontinue'] = $continue;
         }
         if ($limit === null) {
             $params['rnlimit'] = 5000;
         } else {
             $params['rnlimit'] = $limit;
         }
         $result = $this->api->getRequest(new SimpleRequest('query', $params));
         $limit = $limit - count($result['query']['random']);
         foreach ($result['query']['random'] 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']['random']['rncontinue'])) {
             return $pages;
         } else {
             $continue = $result['query-continue']['random']['rncontinue'];
         }
     }
 }
 /**
  * @see EntityIdsForTermLookup::getEntityIdsForTerm
  */
 public function getEntityIdsForTerm(Term $term, $entityType)
 {
     return $this->parseResult($this->api->getRequest($this->buildRequest($term, $entityType)), $term->getText());
 }
Beispiel #16
0
 /**
  * @param string $username
  *
  * @returns User
  */
 public function getFromUsername($username)
 {
     $result = $this->api->getRequest(new SimpleRequest('query', array('list' => 'users', 'ususers' => $username, 'usprop' => 'gender|emailable|registration|editcount|rights|implicitgroups|groups|blockinfo')));
     return $this->newUserFromListUsersResult(array_shift($result['query']['users']));
 }
 /**
  * Get the number of jobs currently in the queue.
  * @todo This and TestEnvironment::runJobs() should probably not live here.
  * @param MediawikiApi $api
  * @return integer
  */
 public function getJobQueueLength(MediawikiApi $api)
 {
     $req = new SimpleRequest('query', ['meta' => 'siteinfo', 'siprop' => 'statistics']);
     $out = $api->getRequest($req);
     return (int) $out['query']['statistics']['jobs'];
 }
 /**
  * @dataProvider provideActionsParamsResults
  */
 public function testGetActionReturnsResult($expectedResult, $action, $params = array())
 {
     $client = $this->getMockClient();
     $client->expects($this->once())->method('get')->with(null, $this->getExpectedOptsForGetParams(array_merge(array('action' => $action), $params)))->will($this->returnValue($this->getMockResponse($expectedResult)));
     $api = new MediawikiApi($client);
     $result = $api->getRequest(new SimpleRequest($action, $params));
     $this->assertEquals($expectedResult, $result);
 }
 /**
  * @since 0.1
  * @param string $siteId
  * @param string $title
  * @returns Revision
  */
 public function getFromSiteAndTitle($siteId, $title)
 {
     $result = $this->api->getRequest(new SimpleRequest('wbgetentities', array('sites' => $siteId, 'titles' => $title)));
     return $this->newRevisionFromResult(array_shift($result['entities']));
 }