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 { 2945a98659SAndreas Gohr global $INFO; 3045a98659SAndreas Gohr global $ID; 31*707aae1bSAndreas Gohr global $ACT; 3245a98659SAndreas Gohr 33ccbd11b2SAndreas Gohr $indexer = new Indexer(); 34ccbd11b2SAndreas Gohr $pages = $indexer->getPages(); 35ccbd11b2SAndreas Gohr 36b62e3d16SSzymon Olewniczak $action = plugin_load('action', 'renderrevisions_save'); 37ccbd11b2SAndreas Gohr [$skipRE, $matchRE] = $action->getRegexps(); 38ccbd11b2SAndreas Gohr 39ccbd11b2SAndreas Gohr foreach ($pages as $page) { 40ccbd11b2SAndreas Gohr if ( 41ccbd11b2SAndreas Gohr ($skipRE && preg_match($skipRE, ":$page")) || 42ccbd11b2SAndreas Gohr ($matchRE && !preg_match($matchRE, ":$page")) 43ccbd11b2SAndreas Gohr ) { 44ccbd11b2SAndreas Gohr $this->info("Skipping $page"); 45ccbd11b2SAndreas Gohr continue; 46ccbd11b2SAndreas Gohr } 47ccbd11b2SAndreas Gohr 48ccbd11b2SAndreas Gohr $this->notice("Processing $page"); 49ccbd11b2SAndreas Gohr $file = wikiFN($page); 50ccbd11b2SAndreas Gohr try { 5145a98659SAndreas Gohr $ID = $page; 5245a98659SAndreas Gohr $INFO = pageinfo(); 53*707aae1bSAndreas Gohr $ACT = 'show'; 5445a98659SAndreas Gohr 55ccbd11b2SAndreas Gohr p_cached_output($file, 'xhtml', $page); 56ccbd11b2SAndreas Gohr } catch (\Exception $e) { 57ccbd11b2SAndreas Gohr $this->error("Issues while rendering $page: " . $e->getMessage()); 58ccbd11b2SAndreas Gohr } 59ccbd11b2SAndreas Gohr } 60ccbd11b2SAndreas Gohr } 61ccbd11b2SAndreas Gohr} 62