1af1904f9SAndreas Gohr<?php 2af1904f9SAndreas Gohr/** 3af1904f9SAndreas Gohr * Translation Plugin: Simple multilanguage plugin 4af1904f9SAndreas Gohr * 5af1904f9SAndreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6af1904f9SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 7af1904f9SAndreas Gohr */ 8af1904f9SAndreas Gohr 9af1904f9SAndreas Gohr// must be run within Dokuwiki 10af1904f9SAndreas Gohrif(!defined('DOKU_INC')) die(); 11af1904f9SAndreas Gohr 12af1904f9SAndreas Gohrclass helper_plugin_translation extends DokuWiki_Plugin { 13af1904f9SAndreas Gohr var $trans = array(); 14af1904f9SAndreas Gohr var $tns = ''; 157c54a0a6SAndreas Gohr var $defaultlang = ''; 16af1904f9SAndreas Gohr 17af1904f9SAndreas Gohr /** 18af1904f9SAndreas Gohr * Initialize 19af1904f9SAndreas Gohr */ 20af1904f9SAndreas Gohr function helper_plugin_translation(){ 217c54a0a6SAndreas Gohr global $conf; 22af1904f9SAndreas Gohr require_once(DOKU_INC.'inc/pageutils.php'); 23af1904f9SAndreas Gohr require_once(DOKU_INC.'inc/utf8.php'); 24af1904f9SAndreas Gohr 25af1904f9SAndreas Gohr // load wanted translation into array 26af1904f9SAndreas Gohr $this->trans = strtolower(str_replace(',',' ',$this->getConf('translations'))); 27af1904f9SAndreas Gohr $this->trans = array_unique(array_filter(explode(' ',$this->trans))); 28af1904f9SAndreas Gohr sort($this->trans); 297c54a0a6SAndreas Gohr 307c54a0a6SAndreas Gohr // get default translation 317c54a0a6SAndreas Gohr if(!$conf['lang_before_translation']){ 327c54a0a6SAndreas Gohr $dfl = $conf['lang']; 337c54a0a6SAndreas Gohr } else { 347c54a0a6SAndreas Gohr $dfl = $conf['lang_before_translation']; 357c54a0a6SAndreas Gohr } 367c54a0a6SAndreas Gohr if(in_array($dfl,$this->trans)){ 377c54a0a6SAndreas Gohr $this->defaultlang = $dfl; 387c54a0a6SAndreas Gohr }else{ 397c54a0a6SAndreas Gohr $this->defaultlang = ''; 40af1904f9SAndreas Gohr array_unshift($this->trans,''); 417c54a0a6SAndreas Gohr } 427c54a0a6SAndreas Gohr 43af1904f9SAndreas Gohr 44af1904f9SAndreas Gohr $this->tns = cleanID($this->getConf('translationns')); 45af1904f9SAndreas Gohr if($this->tns) $this->tns .= ':'; 46af1904f9SAndreas Gohr } 47af1904f9SAndreas Gohr 48af1904f9SAndreas Gohr /** 49af1904f9SAndreas Gohr * Check if the given ID is a translation and return the language code. 50af1904f9SAndreas Gohr */ 51af1904f9SAndreas Gohr function getLangPart($id){ 52af1904f9SAndreas Gohr $rx = '/^'.$this->tns.'('.join('|',$this->trans).'):/'; 53af1904f9SAndreas Gohr if(preg_match($rx,$id,$match)){ 54af1904f9SAndreas Gohr return $match[1]; 55af1904f9SAndreas Gohr } 56af1904f9SAndreas Gohr return ''; 57af1904f9SAndreas Gohr } 58af1904f9SAndreas Gohr 59af1904f9SAndreas Gohr /** 607053cd66SAndreas Gohr * Returns the browser language if it matches with one of the configured 617053cd66SAndreas Gohr * languages 627053cd66SAndreas Gohr */ 637053cd66SAndreas Gohr function getBrowserLang(){ 647053cd66SAndreas Gohr $rx = '/(^|,|:|;|-)('.join('|',$this->trans).')($|,|:|;|-)/i'; 657053cd66SAndreas Gohr if(preg_match($rx,$_SERVER['HTTP_ACCEPT_LANGUAGE'],$match)){ 667053cd66SAndreas Gohr return strtolower($match[2]); 677053cd66SAndreas Gohr } 687053cd66SAndreas Gohr return false; 697053cd66SAndreas Gohr } 707053cd66SAndreas Gohr 717053cd66SAndreas Gohr 727053cd66SAndreas Gohr /** 737c54a0a6SAndreas Gohr * Returns the ID and name to the wanted translation, empty 747c54a0a6SAndreas Gohr * $lng is default lang 75af1904f9SAndreas Gohr */ 76af1904f9SAndreas Gohr function buildTransID($lng,$idpart){ 77af1904f9SAndreas Gohr global $conf; 78af1904f9SAndreas Gohr global $saved_conf; 79af1904f9SAndreas Gohr if($lng){ 80af1904f9SAndreas Gohr $link = ':'.$this->tns.$lng.':'.$idpart; 81af1904f9SAndreas Gohr $name = $lng; 82af1904f9SAndreas Gohr }else{ 83af1904f9SAndreas Gohr $link = ':'.$this->tns.$idpart; 84af1904f9SAndreas Gohr if(!$conf['lang_before_translation']){ 85af1904f9SAndreas Gohr $name = $conf['lang']; 86af1904f9SAndreas Gohr } else { 87af1904f9SAndreas Gohr $name = $conf['lang_before_translation']; 88af1904f9SAndreas Gohr } 89af1904f9SAndreas Gohr } 90af1904f9SAndreas Gohr return array($link,$name); 91af1904f9SAndreas Gohr } 92af1904f9SAndreas Gohr 931469199dSAndreas Gohr /** 9484877e9bSAndreas Gohr * Check if current ID should be translated and any GUI 9584877e9bSAndreas Gohr * should be shown 9684877e9bSAndreas Gohr */ 9784877e9bSAndreas Gohr function istranslatable($id,$checkact=true){ 9884877e9bSAndreas Gohr global $ACT; 9984877e9bSAndreas Gohr 10084877e9bSAndreas Gohr if($checkact && $ACT != 'show') return false; 10184877e9bSAndreas Gohr if($this->tns && strpos($id,$this->tns) !== 0) return false; 10284877e9bSAndreas Gohr $skiptrans = trim($this->getConf('skiptrans')); 10384877e9bSAndreas Gohr if($skiptrans && preg_match('/'.$skiptrans.'/ui',':'.$id)) return false; 10484877e9bSAndreas Gohr $meta = p_get_metadata($id); 10584877e9bSAndreas Gohr if($meta['plugin']['translation']['notrans']) return false; 10684877e9bSAndreas Gohr 10784877e9bSAndreas Gohr return true; 10884877e9bSAndreas Gohr } 10984877e9bSAndreas Gohr 110*c9640767STomasz Tomasik function showAbout() 111*c9640767STomasz Tomasik { 112*c9640767STomasz Tomasik global $ID; 113*c9640767STomasz Tomasik global $conf; 114*c9640767STomasz Tomasik global $INFO; 115*c9640767STomasz Tomasik 116*c9640767STomasz Tomasik $this->checkage(); 117*c9640767STomasz Tomasik 118*c9640767STomasz Tomasik $LN = confToHash(dirname(__FILE__).'/lang/langnames.txt'); 119*c9640767STomasz Tomasik 120*c9640767STomasz Tomasik $rx = '/^'.$this->tns.'(('.join('|',$this->trans).'):)?/'; 121*c9640767STomasz Tomasik $idpart = preg_replace($rx,'',$ID); 122*c9640767STomasz Tomasik 123*c9640767STomasz Tomasik $out = ''; 124*c9640767STomasz Tomasik $out .= '<sup>'; 125*c9640767STomasz Tomasik if($this->getConf('localabout')){ 126*c9640767STomasz Tomasik 127*c9640767STomasz Tomasik //$out .= '<sup>'.html_wikilink($this->getConf('about'),'?').'</sup>'; 128*c9640767STomasz Tomasik 129*c9640767STomasz Tomasik //http://localhost/dokuwiki/doku.php?id=pl:test:podtest 130*c9640767STomasz Tomasik //$out .= '['; 131*c9640767STomasz Tomasik //$out .= getNS(cleanID(getID())); //pl:test 132*c9640767STomasz Tomasik //$out .= $INFO['namespace']; //pl:test 133*c9640767STomasz Tomasik //$out .= cleanID($ID); //pl:test:podtes 134*c9640767STomasz Tomasik //$out .= getID(); //pl:test:podtest 135*c9640767STomasz Tomasik //$out .= getNS($ID); //pl:test 136*c9640767STomasz Tomasik //$out .= ']'; 137*c9640767STomasz Tomasik 138*c9640767STomasz Tomasik $lc = ''; 139*c9640767STomasz Tomasik 140*c9640767STomasz Tomasik //try main lang namespace 141*c9640767STomasz Tomasik foreach($this->trans as $t){ 142*c9640767STomasz Tomasik list($link,$name) = $this->buildTransID($t,$idpart); 143*c9640767STomasz Tomasik $link = cleanID($link); 144*c9640767STomasz Tomasik if($ID == $link){ 145*c9640767STomasz Tomasik $lc = hsc($name); 146*c9640767STomasz Tomasik } 147*c9640767STomasz Tomasik if ($lc) break; 148*c9640767STomasz Tomasik } 149*c9640767STomasz Tomasik 150*c9640767STomasz Tomasik //try browser language 151*c9640767STomasz Tomasik if(!$lc) $lc = $this->getBrowserLang(); 152*c9640767STomasz Tomasik 153*c9640767STomasz Tomasik //try wiki language 154*c9640767STomasz Tomasik if(!$lc) $lc = $conf['lang']; 155*c9640767STomasz Tomasik 156*c9640767STomasz Tomasik if(!$lc) { //can't find language 157*c9640767STomasz Tomasik $localabout = $this->getConf('about'); //http://localhost/dokuwiki/doku.php?id=translation:about 158*c9640767STomasz Tomasik } else { //i found language! 159*c9640767STomasz Tomasik $localabout = $lc.':'.$this->getConf('about'); //http://localhost/dokuwiki/doku.php?id=en:translation:about 160*c9640767STomasz Tomasik } 161*c9640767STomasz Tomasik 162*c9640767STomasz Tomasik //make link 163*c9640767STomasz Tomasik $out .= html_wikilink($localabout,'?'); 164*c9640767STomasz Tomasik } else 165*c9640767STomasz Tomasik { 166*c9640767STomasz Tomasik $out .= html_wikilink($this->getConf('about'),'?'); 167*c9640767STomasz Tomasik } 168*c9640767STomasz Tomasik $out .= '</sup>'; 169*c9640767STomasz Tomasik 170*c9640767STomasz Tomasik return $out; 171*c9640767STomasz Tomasik } 172*c9640767STomasz Tomasik 17384877e9bSAndreas Gohr /** 1741469199dSAndreas Gohr * Displays the available and configured translations. Needs to be placed in the template. 1751469199dSAndreas Gohr */ 1761469199dSAndreas Gohr function showTranslations(){ 1771469199dSAndreas Gohr global $ID; 1781469199dSAndreas Gohr global $conf; 1791469199dSAndreas Gohr global $INFO; 1801469199dSAndreas Gohr 18184877e9bSAndreas Gohr if(!$this->istranslatable($ID)) return; 18284877e9bSAndreas Gohr 18384877e9bSAndreas Gohr $this->checkage(); 1841469199dSAndreas Gohr 18539ecab8bSAndreas Gohr $LN = confToHash(dirname(__FILE__).'/lang/langnames.txt'); 18639ecab8bSAndreas Gohr 1871469199dSAndreas Gohr $rx = '/^'.$this->tns.'(('.join('|',$this->trans).'):)?/'; 1881469199dSAndreas Gohr $idpart = preg_replace($rx,'',$ID); 1891469199dSAndreas Gohr 1901469199dSAndreas Gohr $out = '<div class="plugin_translation">'; 191*c9640767STomasz Tomasik 192*c9640767STomasz Tomasik //scx 193*c9640767STomasz Tomasik //show text 194*c9640767STomasz Tomasik if ($this->getConf('description')){ 1951469199dSAndreas Gohr $out .= '<span>'.$this->getLang('translations'); 196*c9640767STomasz Tomasik if ($this->getConf('showabout')) $out .= $this->showAbout(); 1971469199dSAndreas Gohr $out .= ':</span> '; 198*c9640767STomasz Tomasik } 1991469199dSAndreas Gohr 2001469199dSAndreas Gohr if($this->getConf('dropdown')){ // use dropdown 2011469199dSAndreas Gohr if($INFO['exists']){ 2021469199dSAndreas Gohr $class = 'wikilink1'; 2031469199dSAndreas Gohr }else{ 2041469199dSAndreas Gohr $class = 'wikilink2'; 2051469199dSAndreas Gohr } 206*c9640767STomasz Tomasik 207*c9640767STomasz Tomasik //scx 208*c9640767STomasz Tomasik //link to about (left) 209*c9640767STomasz Tomasik //if (!$this->getConf('description') && $this->getConf('showabout')) { 210*c9640767STomasz Tomasik // //$out .= ' '; 211*c9640767STomasz Tomasik // $out .= $this->showAbout(); 212*c9640767STomasz Tomasik // $out .= ' '; 213*c9640767STomasz Tomasik //} 214*c9640767STomasz Tomasik 215*c9640767STomasz Tomasik ////$out .= '<form action="'.wl().'" id="translation__dropdown">'; 216*c9640767STomasz Tomasik ////$out .= '<select name="id" class="'.$class.'">'; 217*c9640767STomasz Tomasik $out2 = ""; 2181469199dSAndreas Gohr foreach($this->trans as $t){ 2191469199dSAndreas Gohr list($link,$name) = $this->buildTransID($t,$idpart); 2201469199dSAndreas Gohr $link = cleanID($link); 2211469199dSAndreas Gohr if($ID == $link){ 2221469199dSAndreas Gohr $sel = ' selected="selected"'; 223*c9640767STomasz Tomasik if($this->getConf('dropdown2')) 224*c9640767STomasz Tomasik { 225*c9640767STomasz Tomasik $out .= $this->makecountrylink($LN, $idpart, $t, false); 226*c9640767STomasz Tomasik $out .= " "; 227*c9640767STomasz Tomasik } 2281469199dSAndreas Gohr }else{ 2291469199dSAndreas Gohr $sel = ''; 2301469199dSAndreas Gohr } 2311469199dSAndreas Gohr if(page_exists($link,'',false)){ 2321469199dSAndreas Gohr $class = 'wikilink1'; 2331469199dSAndreas Gohr }else{ 2341469199dSAndreas Gohr $class = 'wikilink2'; 2351469199dSAndreas Gohr } 236*c9640767STomasz Tomasik 237*c9640767STomasz Tomasik //scx 238*c9640767STomasz Tomasik //linktitle 239*c9640767STomasz Tomasik $linktitle = ''; 240*c9640767STomasz Tomasik if (strlen($LN[$name]) > 0){ 241*c9640767STomasz Tomasik $linktitle = $LN[$name]; 242*c9640767STomasz Tomasik } else{ 243*c9640767STomasz Tomasik $linktitle = hsc($name); 2441469199dSAndreas Gohr } 245*c9640767STomasz Tomasik 246*c9640767STomasz Tomasik $out2 .= '<option value="'.$link.'"'.$sel.' class="'.$class.'" title="'.$linktitle.'">'.hsc($name).'</option>'; 247*c9640767STomasz Tomasik } 248*c9640767STomasz Tomasik $out .= '<form action="'.wl().'" id="translation__dropdown">'; 249*c9640767STomasz Tomasik $out .= '<select name="id" class="'.$class.'">'; 250*c9640767STomasz Tomasik $out .= $out2; 2511469199dSAndreas Gohr $out .= '</select>'; 2521469199dSAndreas Gohr $out .= '<input name="go" type="submit" value="→" />'; 2531469199dSAndreas Gohr $out .= '</form>'; 254*c9640767STomasz Tomasik 255*c9640767STomasz Tomasik 256*c9640767STomasz Tomasik //scx 257*c9640767STomasz Tomasik //link to about (right) 258*c9640767STomasz Tomasik if (!$this->getConf('description') && $this->getConf('showabout')) { 259*c9640767STomasz Tomasik $out .= ' '; 260*c9640767STomasz Tomasik $out .= $this->showAbout(); 261*c9640767STomasz Tomasik //$out .= ' '; 26239ecab8bSAndreas Gohr } 263*c9640767STomasz Tomasik }else{ // use list 264*c9640767STomasz Tomasik //scx 265*c9640767STomasz Tomasik //require(DOKU_PLUGIN.'translation/flags/langnames.php'); 266*c9640767STomasz Tomasik $out .= '<ul>'; 267*c9640767STomasz Tomasik 268*c9640767STomasz Tomasik if (!$this->getConf('description') && $this->getConf('showabout')) { 269*c9640767STomasz Tomasik $out .= ' '; 270*c9640767STomasz Tomasik $out .= $this->showAbout(); 271*c9640767STomasz Tomasik //$out .= ' '; 272*c9640767STomasz Tomasik } 273*c9640767STomasz Tomasik 274*c9640767STomasz Tomasik foreach($this->trans as $t){ 275*c9640767STomasz Tomasik $out .= $this->makecountrylink($LN, $idpart, $t, true); 2761469199dSAndreas Gohr } 2771469199dSAndreas Gohr $out .= '</ul>'; 2781469199dSAndreas Gohr } 2791469199dSAndreas Gohr 2801469199dSAndreas Gohr $out .= '</div>'; 2811469199dSAndreas Gohr 2821469199dSAndreas Gohr return $out; 2831469199dSAndreas Gohr } 284af1904f9SAndreas Gohr 285*c9640767STomasz Tomasik 286*c9640767STomasz Tomasik function makecountrylink($LN, $idpart, $t, $div) 287*c9640767STomasz Tomasik { 288*c9640767STomasz Tomasik global $ID; 289*c9640767STomasz Tomasik global $conf; 290*c9640767STomasz Tomasik global $INFO; 291*c9640767STomasz Tomasik 292*c9640767STomasz Tomasik require(DOKU_PLUGIN.'translation/flags/langnames.php'); 293*c9640767STomasz Tomasik 294*c9640767STomasz Tomasik list($link,$name) = $this->buildTransID($t,$idpart); 295*c9640767STomasz Tomasik $link = cleanID($link); 296*c9640767STomasz Tomasik if(page_exists($link,'',false)){ 297*c9640767STomasz Tomasik $class = 'wikilink1'; 298*c9640767STomasz Tomasik }else{ 299*c9640767STomasz Tomasik $class = 'wikilink2'; 300*c9640767STomasz Tomasik } 301*c9640767STomasz Tomasik 302*c9640767STomasz Tomasik //linktitle 303*c9640767STomasz Tomasik $linktitle = ''; 304*c9640767STomasz Tomasik if (strlen($LN[$name]) > 0){ 305*c9640767STomasz Tomasik $linktitle = $LN[$name]; 306*c9640767STomasz Tomasik } else{ 307*c9640767STomasz Tomasik $linktitle = hsc($name); 308*c9640767STomasz Tomasik } 309*c9640767STomasz Tomasik 310*c9640767STomasz Tomasik //$out .= 'link='.$link; //link=de:start 311*c9640767STomasz Tomasik //$out .= 'wl(link)='.wl($link); //wl(link)=/dokuwiki/doku.php?id=de:start 312*c9640767STomasz Tomasik //$out .= 'class='.$class; //class=wikilink2 313*c9640767STomasz Tomasik //$out .= 'name='.$name; //name=de 314*c9640767STomasz Tomasik //$out .= 'LN[name]='.$LN[$name]; //LN[name]=Deutsch 315*c9640767STomasz Tomasik //$out .= 'hsc(name)='.hsc($name); //hsc(name)=de 316*c9640767STomasz Tomasik //$out .= 'linktitle='.$linktitle; //linktitle=Deutsch 317*c9640767STomasz Tomasik 318*c9640767STomasz Tomasik //if (show flag AND ((flag exist) OR (flag not exist AND show blank flag)) 319*c9640767STomasz Tomasik if (($langflag[hsc($name)] != NULL && strlen($langflag[hsc($name)]) > 0 && $this->getConf('flags')) || $this->getConf('flags') && $this->getConf('blankflag')) { 320*c9640767STomasz Tomasik //$out .= ' <li><div class="li"><a href="'.wl($link).'" class="'.$class.'" title="'.$LN[$name].'">'.hsc($name).'</a></div></li>'; 321*c9640767STomasz Tomasik 322*c9640767STomasz Tomasik resolve_pageid(getNS($ID),$link,$exists); 323*c9640767STomasz Tomasik if ($div) 324*c9640767STomasz Tomasik { 325*c9640767STomasz Tomasik if ($exists){ //solid box 326*c9640767STomasz Tomasik $out .= ' <li><div class="li">'; 327*c9640767STomasz Tomasik } else{ //50% transparent box (50% transparent flag) 328*c9640767STomasz Tomasik $out .= ' <li><div class="flag_not_exists">'; 329*c9640767STomasz Tomasik } 330*c9640767STomasz Tomasik } 331*c9640767STomasz Tomasik 332*c9640767STomasz Tomasik //html_wikilink works very slow for images 333*c9640767STomasz Tomasik //$flag['title'] = $langname[$name]; 334*c9640767STomasz Tomasik //$flag['src'] = DOKU_URL.'lib/plugins/translation/flags/'.$langflag[$name]; 335*c9640767STomasz Tomasik 336*c9640767STomasz Tomasik //$out .= html_wikilink($link,$flag); 337*c9640767STomasz Tomasik 338*c9640767STomasz Tomasik $out .= '<a href="'.wl($link).'"'; 339*c9640767STomasz Tomasik $out .= 'title="'.$linktitle.'"'; 340*c9640767STomasz Tomasik //class for image 341*c9640767STomasz Tomasik $out .= 'class="wikilink3"'; 342*c9640767STomasz Tomasik $out .= '>'; 343*c9640767STomasz Tomasik 344*c9640767STomasz Tomasik //show flag 345*c9640767STomasz Tomasik if ($langflag[hsc($name)] != NULL && strlen($langflag[hsc($name)]) > 0){ 346*c9640767STomasz Tomasik $out .= '<img src="'.DOKU_URL.'lib/plugins/translation/flags/'.$langflag[hsc($name)].'" alt='.$linktitle.'" border="0">'; 347*c9640767STomasz Tomasik } else{ //show blank flag 348*c9640767STomasz Tomasik //$out .= '<img src="'.DOKU_BASE.'lib/images/blank.gif'.'" width=15 height=11 alt="'.$linktitle.'" border="0">'; 349*c9640767STomasz Tomasik $out .= '<img src="'.DOKU_BASE.'lib/plugins/translation/flags/blankflag.gif'.'" width=15 height=11 alt="'.$linktitle.'" border="0">'; 350*c9640767STomasz Tomasik } 351*c9640767STomasz Tomasik $out .= '</a>'; 352*c9640767STomasz Tomasik 353*c9640767STomasz Tomasik } 354*c9640767STomasz Tomasik else{ //show text (also if flag not exist and blankflag=false) 355*c9640767STomasz Tomasik //$out .= ' <li><div class="li"><a href="'.wl($link).'" class="'.$class.'" title="'.$LN[$name].'">'.hsc($name).'</a></div></li>'; 356*c9640767STomasz Tomasik 357*c9640767STomasz Tomasik //$out .= '<a href="'.wl($link); 358*c9640767STomasz Tomasik //$out .= '" class="'.$class.'" title="'.$LN[$name].'">'; 359*c9640767STomasz Tomasik //$out .= hsc($name); 360*c9640767STomasz Tomasik //$out .= '</a>'; 361*c9640767STomasz Tomasik if ($div) 362*c9640767STomasz Tomasik { 363*c9640767STomasz Tomasik $out .= ' <li><div class="li">'; 364*c9640767STomasz Tomasik } 365*c9640767STomasz Tomasik $out .= html_wikilink($link,hsc($name)); 366*c9640767STomasz Tomasik } 367*c9640767STomasz Tomasik if ($div) 368*c9640767STomasz Tomasik { 369*c9640767STomasz Tomasik $out .= '</div></li>'; 370*c9640767STomasz Tomasik } 371*c9640767STomasz Tomasik 372*c9640767STomasz Tomasik return $out; 373*c9640767STomasz Tomasik } 374*c9640767STomasz Tomasik 375*c9640767STomasz Tomasik 376*c9640767STomasz Tomasik 37784877e9bSAndreas Gohr /** 37884877e9bSAndreas Gohr * Checks if the current page is a translation of a page 37984877e9bSAndreas Gohr * in the default language. Displays a notice when it is 38084877e9bSAndreas Gohr * older than the original page. Tries to lin to a diff 38184877e9bSAndreas Gohr * with changes on the original since the translation 38284877e9bSAndreas Gohr */ 38384877e9bSAndreas Gohr function checkage(){ 38484877e9bSAndreas Gohr global $ID; 38584877e9bSAndreas Gohr global $INFO; 38684877e9bSAndreas Gohr if(!$this->getConf('checkage')) return; 38784877e9bSAndreas Gohr if(!$INFO['exists']) return; 38884877e9bSAndreas Gohr $lng = $this->getLangPart($ID); 38984877e9bSAndreas Gohr if($lng == $this->defaultlang) return; 390af1904f9SAndreas Gohr 39184877e9bSAndreas Gohr $rx = '/^'.$this->tns.'(('.join('|',$this->trans).'):)?/'; 39284877e9bSAndreas Gohr $idpart = preg_replace($rx,'',$ID); 39384877e9bSAndreas Gohr 39484877e9bSAndreas Gohr // compare modification times 39584877e9bSAndreas Gohr list($orig,$name) = $this->buildTransID($this->defaultlang,$idpart); 39684877e9bSAndreas Gohr $origfn = wikiFN($orig); 39784877e9bSAndreas Gohr if($INFO['lastmod'] >= @filemtime($origfn) ) return; 39884877e9bSAndreas Gohr 39984877e9bSAndreas Gohr // get revision from before translation 40084877e9bSAndreas Gohr $orev = 0; 40184877e9bSAndreas Gohr $revs = getRevisions($orig,0,100); 40284877e9bSAndreas Gohr foreach($revs as $rev){ 40384877e9bSAndreas Gohr if($rev < $INFO['lastmod']){ 40484877e9bSAndreas Gohr $orev = $rev; 40584877e9bSAndreas Gohr break; 40684877e9bSAndreas Gohr } 40784877e9bSAndreas Gohr } 40884877e9bSAndreas Gohr 40944552920SAndreas Gohr // see if the found revision still exists 41044552920SAndreas Gohr if($orev && !page_exists($orig,$orev)) $orev=0; 41144552920SAndreas Gohr 41284877e9bSAndreas Gohr // build the message and display it 413dc3fbdb9SOleksiy Zagorskyi $orig = cleanID($orig); 41484877e9bSAndreas Gohr $msg = sprintf($this->getLang('outdated'),wl($orig)); 41584877e9bSAndreas Gohr if($orev){ 41684877e9bSAndreas Gohr $msg .= sprintf(' '.$this->getLang('diff'), 41784877e9bSAndreas Gohr wl($orig,array('do'=>'diff','rev'=>$orev))); 41884877e9bSAndreas Gohr } 41900431e1eSAndreas Gohr 42000431e1eSAndreas Gohr echo '<div class="notify">'.$msg.'</div>'; 42184877e9bSAndreas Gohr } 422af1904f9SAndreas Gohr} 423