1ccbd11b2SAndreas Gohr<?php 2ccbd11b2SAndreas Gohr 3ccbd11b2SAndreas Gohruse dokuwiki\Search\Indexer; 4ccbd11b2SAndreas Gohruse splitbrain\phpcli\Options; 5ccbd11b2SAndreas Gohr 6ccbd11b2SAndreas Gohr/** 7ccbd11b2SAndreas Gohr * DokuWiki Plugin renderrevisions (CLI Component) 8ccbd11b2SAndreas Gohr * 9ccbd11b2SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 10ccbd11b2SAndreas Gohr * @author Andreas Gohr <dokuwiki@cosmocode.de> 11ccbd11b2SAndreas Gohr */ 12ccbd11b2SAndreas Gohrclass cli_plugin_renderrevisions extends \dokuwiki\Extension\CLIPlugin 13ccbd11b2SAndreas Gohr{ 14ccbd11b2SAndreas Gohr /** @inheritDoc */ 15ccbd11b2SAndreas Gohr protected function setup(Options $options) 16ccbd11b2SAndreas Gohr { 17ccbd11b2SAndreas Gohr $options->setHelp( 18ccbd11b2SAndreas Gohr "Re-render pages if necessary\n" . 19ccbd11b2SAndreas Gohr "\n" . 20ccbd11b2SAndreas Gohr "This command will go through all pages in the wiki (adhering to the skipRegex and matchRegex settings) " . 21ccbd11b2SAndreas Gohr "and re-render them if necessary. This will trigger the renderrevisions plugin mechanism to create " . 22ccbd11b2SAndreas Gohr "a new revision of the page if the content changed." 23ccbd11b2SAndreas Gohr ); 24ccbd11b2SAndreas Gohr } 25ccbd11b2SAndreas Gohr 26ccbd11b2SAndreas Gohr /** @inheritDoc */ 27ccbd11b2SAndreas Gohr protected function main(Options $options) 28ccbd11b2SAndreas Gohr { 29ccbd11b2SAndreas Gohr $indexer = new Indexer(); 30ccbd11b2SAndreas Gohr $pages = $indexer->getPages(); 31ccbd11b2SAndreas Gohr 32*b62e3d16SSzymon Olewniczak $action = plugin_load('action', 'renderrevisions_save'); 33ccbd11b2SAndreas Gohr [$skipRE, $matchRE] = $action->getRegexps(); 34ccbd11b2SAndreas Gohr 35ccbd11b2SAndreas Gohr foreach ($pages as $page) { 36ccbd11b2SAndreas Gohr if ( 37ccbd11b2SAndreas Gohr ($skipRE && preg_match($skipRE, ":$page")) || 38ccbd11b2SAndreas Gohr ($matchRE && !preg_match($matchRE, ":$page")) 39ccbd11b2SAndreas Gohr ) { 40ccbd11b2SAndreas Gohr $this->info("Skipping $page"); 41ccbd11b2SAndreas Gohr continue; 42ccbd11b2SAndreas Gohr } 43ccbd11b2SAndreas Gohr 44ccbd11b2SAndreas Gohr $this->notice("Processing $page"); 45ccbd11b2SAndreas Gohr $file = wikiFN($page); 46ccbd11b2SAndreas Gohr try { 47ccbd11b2SAndreas Gohr p_cached_output($file, 'xhtml', $page); 48ccbd11b2SAndreas Gohr } catch (\Exception $e) { 49ccbd11b2SAndreas Gohr $this->error("Issues while rendering $page: " . $e->getMessage()); 50ccbd11b2SAndreas Gohr } 51ccbd11b2SAndreas Gohr } 52ccbd11b2SAndreas Gohr } 53ccbd11b2SAndreas Gohr} 54