1<?php 2 3use dokuwiki\Extension\AdminPlugin; 4 5/** 6 * DokuWiki Plugin translation (Admin Component) 7 * 8 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 9 * @author Andreas Gohr <andi@splitbrain.org> 10 */ 11class admin_plugin_translation extends AdminPlugin 12{ 13 /** @inheritdoc */ 14 public function forAdminOnly() 15 { 16 return false; 17 } 18 19 /** @inheritdoc */ 20 public function handle() 21 { 22 } 23 24 /** @inheritdoc */ 25 public function html() 26 { 27 28 /** @var helper_plugin_translation $helper */ 29 $helper = plugin_load('helper', "translation"); 30 $default_language = $helper->defaultlang; 31 32 /** @var Doku_Renderer_xhtml $xhtml_renderer */ 33 $xhtml_renderer = p_get_renderer('xhtml'); 34 35 echo "<h1>" . $this->getLang("menu") . "</h1>"; 36 echo "<table id='outdated_translations' class=\"inline\">"; 37 echo "<tr><th>default: $default_language</th>"; 38 if ($this->getConf('show_path')) { 39 echo "<th>" . $this->getLang('path') . "</th>"; 40 } 41 foreach ($helper->translations as $t) { 42 if ($t === $default_language) { 43 continue; 44 } 45 echo "<th>$t</th>"; 46 } 47 echo "</tr>"; 48 49 $pages = $this->getAllPages(); 50 foreach ($pages as $page) { 51 if ( 52 $helper->getLangPart($page["id"]) !== $default_language || 53 !$helper->istranslatable($page["id"], false) || 54 !page_exists($page["id"]) 55 ) { 56 continue; 57 } 58 // We have an existing and translatable page in the default language 59 $showRow = false; 60 $row = "<tr><td>" . $xhtml_renderer->internallink($page['id'], null, null, true) . "</td>"; 61 if ($this->getConf('show_path')) { 62 $row .= "<td>" . $xhtml_renderer->internallink($page['id'], $page['id'], null, true) . "</td>"; 63 } 64 65 [, $idpart] = $helper->getTransParts($page["id"]); 66 67 foreach ($helper->translations as $t) { 68 if ($t === $default_language) { 69 continue; 70 } 71 72 [$translID, ] = $helper->buildTransID($t, $idpart); 73 74 $difflink = ''; 75 if (!page_exists($translID)) { 76 $class = "missing"; 77 $title = $this->getLang("missing"); 78 $showRow = true; 79 } else { 80 $translfn = wikiFN($translID); 81 if ($page['mtime'] > filemtime($translfn)) { 82 $class = "outdated"; 83 $difflink = " <a href='"; 84 $difflink .= $helper->getOldDiffLink($page["id"], $page['mtime']); 85 $difflink .= "'>(diff)</a>"; 86 $title = $this->getLang('old'); 87 $showRow = true; 88 } else { 89 $class = "current"; 90 $title = $this->getLang('current'); 91 } 92 } 93 $row .= "<td class='$class'>" . $xhtml_renderer->internallink( 94 $translID, 95 $title, 96 null, 97 true 98 ) . $difflink . "</td>"; 99 } 100 $row .= "</tr>"; 101 102 if ($showRow) { 103 echo $row; 104 } 105 } 106 echo "</table>"; 107 } 108 109 /** 110 * Get all pages in the translation namespace 111 * 112 * @return array 113 */ 114 protected function getAllPages() 115 { 116 $namespace = $this->getConf("translationns"); 117 $dir = dirname(wikiFN("$namespace:foo")); 118 $pages = []; 119 search($pages, $dir, 'search_allpages', []); 120 return $pages; 121 } 122} 123