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