1<?php 2 3use dokuwiki\Extension\RemotePlugin; 4use dokuwiki\plugin\translation\OutdatedTranslationApiResponse; 5use dokuwiki\Remote\AccessDeniedException; 6 7/** 8 * DokuWiki Plugin translation (Action Component) 9 * 10 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 11 * @author Andreas Gohr <andi@splitbrain.org> 12 */ 13class remote_plugin_translation extends RemotePlugin 14{ 15 /** 16 * Get outdated or missing translations 17 * 18 * This function returns a list of all pages that are either missing or are older than their 19 * corresponding page in the default language. 20 * 21 * Only available to managers and superusers. 22 * 23 * @param string $namespace The namespace to check, empty for all 24 * @return OutdatedTranslationApiResponse[] 25 */ 26 public function getOutdated($namespace = '') 27 { 28 if (!auth_ismanager()) { 29 throw new AccessDeniedException('You are not allowed to access this endpoint', 111); 30 } 31 32 /** @var helper_plugin_translation $helper */ 33 $helper = plugin_load('helper', 'translation'); 34 35 $namespace = cleanID($namespace); 36 $pages = $helper->getAllTranslatablePages($namespace); 37 38 $result = []; 39 foreach ($pages as $page) { 40 [, $idpart] = $helper->getTransParts($page["id"]); 41 foreach ($helper->translations as $t) { 42 if ($t === $helper->defaultlang) continue; 43 [$translID,] = $helper->buildTransID($t, $idpart); 44 45 if (!page_exists($translID)) { 46 $status = 'missing'; 47 } else if ($page['mtime'] > filemtime(wikiFN($translID))) { 48 $status = 'outdated'; 49 } else { 50 $status = ''; 51 } 52 53 if ($status) { 54 $result[] = new OutdatedTranslationApiResponse( 55 $page, 56 cleanID($translID), 57 filemtime(wikiFN($translID)), 58 $t, 59 $status 60 ); 61 } 62 } 63 } 64 65 return $result; 66 } 67} 68