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 global $INFO; 30 global $ID; 31 32 $indexer = new Indexer(); 33 $pages = $indexer->getPages(); 34 35 $action = plugin_load('action', 'renderrevisions_save'); 36 [$skipRE, $matchRE] = $action->getRegexps(); 37 38 foreach ($pages as $page) { 39 if ( 40 ($skipRE && preg_match($skipRE, ":$page")) || 41 ($matchRE && !preg_match($matchRE, ":$page")) 42 ) { 43 $this->info("Skipping $page"); 44 continue; 45 } 46 47 $this->notice("Processing $page"); 48 $file = wikiFN($page); 49 try { 50 $ID = $page; 51 $INFO = pageinfo(); 52 53 p_cached_output($file, 'xhtml', $page); 54 } catch (\Exception $e) { 55 $this->error("Issues while rendering $page: " . $e->getMessage()); 56 } 57 } 58 } 59} 60