* Populate $this->limit */ function generateLimit($namespace) { $title = Title::makeTitle($namespace, str_repeat("𨮁", 63) . "喃"); $this->limit = array(strlen($this->openFile()), strlen($this->fileEntry($title->getFullUrl(), wfTimestamp(TS_ISO_8601, wfTimestamp()), $this->priority($namespace))), strlen($this->closeFile())); } } if (in_array('--help', $argv)) { echo <<<EOT Usage: php generateSitemap.php [options] \t--help\t\t\tshow this message \t--fspath=<path>\t\tThe file system path to save to, e.g /tmp/sitemap \t--server=<server>\tThe protocol and server name to use in URLs, e.g. \t\thttp://en.wikipedia.org. This is sometimes necessary because \t\tserver name detection may fail in command line scripts. \t--compress=[yes|no]\tcompress the sitemap files, default yes EOT; die(-1); } $optionsWithArgs = array('fspath', 'server', 'compress'); require_once dirname(__FILE__) . '/commandLine.inc'; if (isset($options['server'])) { $wgServer = $options['server']; } $gs = new GenerateSitemap(@$options['fspath'], @$options['compress'] !== 'no'); $gs->main();
$url = $sitemap->createElement('url'); $href = trim($baseUrl, '/') . '/discussion/' . $post->id . '/' . $post->slug; $url->appendChild($sitemap->createElement('loc', $href)); $valuePriority = $postKarma > 0.7 ? sprintf("%0.1f", $postKarma) : sprintf("%0.1f", $postKarma + 0.25); $url->appendChild($sitemap->createElement('priority', $valuePriority)); $url->appendChild($sitemap->createElement('lastmod', $modifiedAt->format('Y-m-d\\TH:i:s\\Z'))); $urlset->appendChild($url); } $sitemap->appendChild($urlset); $adapter = new Local(dirname(dirname(__FILE__)) . '/public'); $filesystem = new Filesystem($adapter); if ($filesystem->has('sitemap.xml')) { $result = $filesystem->update('sitemap.xml', $sitemap->saveXML() . PHP_EOL); } else { $result = $filesystem->write('sitemap.xml', $sitemap->saveXML() . PHP_EOL); } if ($result) { $log->info('The sitemap.xml was successfully updated'); } else { $log->error('Failed to update the sitemap.xml file'); } } } try { $task = new GenerateSitemap(); $task->run(); } catch (Exception $e) { fwrite(STDERR, 'ERROR: ' . $e->getMessage() . PHP_EOL); fwrite(STDERR, $e->getTraceAsString() . PHP_EOL); exit(1); }