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