Exemplo n.º 1
0
 private function purgePages(array $pagesToPurge, array $siteApis, CommandHelper $commandHelper, ApiUser $apiUser)
 {
     $allCount = 0;
     foreach ($siteApis as $siteId => $url) {
         if (!isset($pagesToPurge[$siteId])) {
             $commandHelper->writeln("\nNo pages found to purge for site {$siteId} ({$url})");
             continue;
         }
         $count = count($pagesToPurge[$siteId]);
         $commandHelper->writeln("\nPurging {$count} pages for site {$siteId} ({$url})");
         $api = new MediawikiApi($url);
         $api->login($apiUser);
         $progressBar = $commandHelper->getProgressBar($count);
         $progressBar->start();
         foreach (array_chunk($pagesToPurge[$siteId], 10) as $pages) {
             $params = array('titles' => implode('|', $pages), 'forcelinkupdate' => true);
             $api->postRequest(new SimpleRequest('purge', $params));
             $progressBar->advance(10);
         }
         $progressBar->finish();
         $allCount += $count;
     }
     $commandHelper->writeln("\nFinished purging {$allCount} pages");
 }
Exemplo n.º 2
0
    public function execute(CommandHelper $commandHelper)
    {
        $db = $commandHelper->getDatabase();
        $wikibaseFactory = $commandHelper->getWikibaseFactory();
        $revisionsGetter = $wikibaseFactory->newRevisionGetter();
        $siteLinkSetter = $wikibaseFactory->newSiteLinkSetter();
        $wiki = $commandHelper->getOption('wiki');
        $badgeId = new ItemId($commandHelper->getOption('badge'));
        $editInfo = new EditInfo($this->getSummary($commandHelper->getOption('summary'), $commandHelper->getOption('category'), $wiki, $badgeId->getSerialization()), false, $commandHelper->getOption('bot'));
        $results = $db->query('SELECT page_title FROM categorylinks
			JOIN page ON page_id = cl_from
			WHERE cl_to = "' . $db->escape_string($commandHelper->getOption('category')) . '"
			AND page_namespace = 0');
        $skipped = 0;
        $added = 0;
        $failed = 0;
        if ($results) {
            while ($row = $results->fetch_assoc()) {
                try {
                    /** @var Item $item */
                    $revision = $revisionsGetter->getFromSiteAndTitle($wiki, $row['page_title']);
                    if ($revision === false) {
                        $commandHelper->writeln("\nNo item found for {$wiki}:{$row['page_title']}");
                        $failed++;
                        continue;
                    }
                    $item = $revision->getContent()->getData();
                    $badges = $item->getSiteLinkList()->getBySiteId($wiki)->getBadges();
                    if (in_array($badgeId, $badges)) {
                        $commandHelper->write('.');
                        $skipped++;
                        continue;
                    }
                    $badges[] = $badgeId;
                    $siteLinkSetter->set(new SiteLink($wiki, $row['page_title'], $badges), new SiteLink($wiki, $row['page_title']), $editInfo);
                    $commandHelper->writeln("\nAdded badge for {$wiki}:{$row['page_title']}");
                    $added++;
                } catch (Exception $ex) {
                    $commandHelper->writeln("\nFailed to add badge for {$wiki}:{$row['page_title']} (" . $ex->getMessage() . ")");
                    $failed++;
                }
            }
        }
        $results->free();
        $commandHelper->writeln("Finished iterating through {$results->num_rows} site links.");
        $commandHelper->writeln("Added: {$added}");
        $commandHelper->writeln("Skipped: {$skipped}");
        $commandHelper->writeln("Failed: {$failed}");
    }