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