10cecf9d5Sandi<?php 261faf446Schris/** 35587e44cSchris * Renderer output base class 461faf446Schris * 561faf446Schris * @author Harry Fuecks <hfuecks@gmail.com> 661faf446Schris * @author Andreas Gohr <andi@splitbrain.org> 761faf446Schris */ 861faf446Schris 9e1d9dcc8SAndreas Gohruse dokuwiki\Extension\Plugin; 10e1d9dcc8SAndreas Gohruse dokuwiki\Extension\SyntaxPlugin; 11e1d9dcc8SAndreas Gohr 12863befa1SAndreas Gohr/** 1356bd9509SPhy * Allowed chars in $language for code highlighting 1456bd9509SPhy * @see GeSHi::set_language() 1556bd9509SPhy */ 1656bd9509SPhydefine('PREG_PATTERN_VALID_LANGUAGE', '#[^a-zA-Z0-9\-_]#'); 1756bd9509SPhy 1856bd9509SPhy/** 19863befa1SAndreas Gohr * An empty renderer, produces no output 20863befa1SAndreas Gohr * 21*51ee2399SGerrit Uitslag * Inherits from dokuwiki\Extension\Plugin for giving additional functions to render plugins 228e3a5477SAndreas Gohr * 238e3a5477SAndreas Gohr * The renderer transforms the syntax instructions created by the parser and handler into the 248e3a5477SAndreas Gohr * desired output format. For each instruction a corresponding method defined in this class will 258e3a5477SAndreas Gohr * be called. That method needs to produce the desired output for the instruction and add it to the 268e3a5477SAndreas Gohr * $doc field. When all instructions are processed, the $doc field contents will be cached by 278e3a5477SAndreas Gohr * DokuWiki and sent to the user. 28863befa1SAndreas Gohr */ 29faf3f01bSAndreas Gohrabstract class Doku_Renderer extends Plugin 30faf3f01bSAndreas Gohr{ 31cfa2b40eSAndreas Gohr /** @var array Settings, control the behavior of the renderer */ 32faf3f01bSAndreas Gohr public $info = [ 33faf3f01bSAndreas Gohr 'cache' => true, 34faf3f01bSAndreas Gohr // may the rendered result cached? 35faf3f01bSAndreas Gohr 'toc' => true, 36faf3f01bSAndreas Gohr ]; 379dc2c2afSandi 38cfa2b40eSAndreas Gohr /** @var array contains the smiley configuration, set in p_render() */ 39faf3f01bSAndreas Gohr public $smileys = []; 40cfa2b40eSAndreas Gohr /** @var array contains the entity configuration, set in p_render() */ 41faf3f01bSAndreas Gohr public $entities = []; 42cfa2b40eSAndreas Gohr /** @var array contains the acronym configuration, set in p_render() */ 43faf3f01bSAndreas Gohr public $acronyms = []; 44cfa2b40eSAndreas Gohr /** @var array contains the interwiki configuration, set in p_render() */ 45faf3f01bSAndreas Gohr public $interwiki = []; 4678b498a7SAndreas Gohr /** @var string|int link pages and media against this revision */ 4778b498a7SAndreas Gohr public $date_at = ''; 48e41c4da9SAndreas Gohr 49de369923SAndreas Gohr /** @var array the list of headers used to create unique link ids */ 50faf3f01bSAndreas Gohr protected $headers = []; 51de369923SAndreas Gohr 525f70445dSAndreas Gohr /** 53cfa2b40eSAndreas Gohr * @var string the rendered document, this will be cached after the renderer ran through 545f70445dSAndreas Gohr */ 55cfa2b40eSAndreas Gohr public $doc = ''; 56cfa2b40eSAndreas Gohr 57cfa2b40eSAndreas Gohr /** 58cfa2b40eSAndreas Gohr * clean out any per-use values 59cfa2b40eSAndreas Gohr * 60cfa2b40eSAndreas Gohr * This is called before each use of the renderer object and should be used to 61cfa2b40eSAndreas Gohr * completely reset the state of the renderer to be reused for a new document 62cfa2b40eSAndreas Gohr */ 63faf3f01bSAndreas Gohr public function reset() 64faf3f01bSAndreas Gohr { 65faf3f01bSAndreas Gohr $this->headers = []; 66abaaba9aSSatoshi Sahara $this->doc = ''; 67abaaba9aSSatoshi Sahara $this->info['cache'] = true; 68abaaba9aSSatoshi Sahara $this->info['toc'] = true; 695f70445dSAndreas Gohr } 705f70445dSAndreas Gohr 71f6ec8df8SAdrian Lang /** 72f6ec8df8SAdrian Lang * Allow the plugin to prevent DokuWiki from reusing an instance 73f6ec8df8SAdrian Lang * 74cfa2b40eSAndreas Gohr * Since most renderer plugins fail to implement Doku_Renderer::reset() we default 75cfa2b40eSAndreas Gohr * to reinstantiating the renderer here 76cfa2b40eSAndreas Gohr * 77f6ec8df8SAdrian Lang * @return bool false if the plugin has to be instantiated 78f6ec8df8SAdrian Lang */ 79faf3f01bSAndreas Gohr public function isSingleton() 80faf3f01bSAndreas Gohr { 81f6ec8df8SAdrian Lang return false; 82f6ec8df8SAdrian Lang } 83f6ec8df8SAdrian Lang 848cc41db0SAndreas Gohr /** 85cfa2b40eSAndreas Gohr * Returns the format produced by this renderer. 86cfa2b40eSAndreas Gohr * 87cfa2b40eSAndreas Gohr * Has to be overidden by sub classes 88cfa2b40eSAndreas Gohr * 89cfa2b40eSAndreas Gohr * @return string 90cfa2b40eSAndreas Gohr */ 91de369923SAndreas Gohr abstract public function getFormat(); 92cfa2b40eSAndreas Gohr 93cfa2b40eSAndreas Gohr /** 94cfa2b40eSAndreas Gohr * Disable caching of this renderer's output 95cfa2b40eSAndreas Gohr */ 96faf3f01bSAndreas Gohr public function nocache() 97faf3f01bSAndreas Gohr { 98cfa2b40eSAndreas Gohr $this->info['cache'] = false; 99cfa2b40eSAndreas Gohr } 100cfa2b40eSAndreas Gohr 101cfa2b40eSAndreas Gohr /** 102cfa2b40eSAndreas Gohr * Disable TOC generation for this renderer's output 103cfa2b40eSAndreas Gohr * 104cfa2b40eSAndreas Gohr * This might not be used for certain sub renderer 105cfa2b40eSAndreas Gohr */ 106faf3f01bSAndreas Gohr public function notoc() 107faf3f01bSAndreas Gohr { 108cfa2b40eSAndreas Gohr $this->info['toc'] = false; 109cfa2b40eSAndreas Gohr } 110cfa2b40eSAndreas Gohr 111cfa2b40eSAndreas Gohr /** 112cfa2b40eSAndreas Gohr * Handle plugin rendering 113cfa2b40eSAndreas Gohr * 114cfa2b40eSAndreas Gohr * Most likely this needs NOT to be overwritten by sub classes 1158cc41db0SAndreas Gohr * 1168cc41db0SAndreas Gohr * @param string $name Plugin name 1178cc41db0SAndreas Gohr * @param mixed $data custom data set by handler 1188cc41db0SAndreas Gohr * @param string $state matched state if any 1198cc41db0SAndreas Gohr * @param string $match raw matched syntax 1208cc41db0SAndreas Gohr */ 121faf3f01bSAndreas Gohr public function plugin($name, $data, $state = '', $match = '') 122faf3f01bSAndreas Gohr { 123e1d9dcc8SAndreas Gohr /** @var SyntaxPlugin $plugin */ 124e8b5a4f9SAndreas Gohr $plugin = plugin_load('syntax', $name); 12561faf446Schris if ($plugin != null) { 1265f70445dSAndreas Gohr $plugin->render($this->getFormat(), $this, $data); 12761faf446Schris } 12861faf446Schris } 12961faf446Schris 1305587e44cSchris /** 1315587e44cSchris * handle nested render instructions 1325587e44cSchris * this method (and nest_close method) should not be overloaded in actual renderer output classes 133cfa2b40eSAndreas Gohr * 134cfa2b40eSAndreas Gohr * @param array $instructions 1355587e44cSchris */ 136faf3f01bSAndreas Gohr public function nest($instructions) 137faf3f01bSAndreas Gohr { 1385587e44cSchris foreach ($instructions as $instruction) { 1395587e44cSchris // execute the callback against ourself 140c2122b83SChristopher Smith if (method_exists($this, $instruction[0])) { 141faf3f01bSAndreas Gohr call_user_func_array([$this, $instruction[0]], $instruction[1] ?: []); 142c2122b83SChristopher Smith } 1435587e44cSchris } 1445587e44cSchris } 1455587e44cSchris 146cfa2b40eSAndreas Gohr /** 147cfa2b40eSAndreas Gohr * dummy closing instruction issued by Doku_Handler_Nest 148cfa2b40eSAndreas Gohr * 149cfa2b40eSAndreas Gohr * normally the syntax mode should override this instruction when instantiating Doku_Handler_Nest - 150cfa2b40eSAndreas Gohr * however plugins will not be able to - as their instructions require data. 151cfa2b40eSAndreas Gohr */ 152faf3f01bSAndreas Gohr public function nest_close() 153faf3f01bSAndreas Gohr { 1542c2835c2SAndreas Gohr } 1555587e44cSchris 156cfa2b40eSAndreas Gohr #region Syntax modes - sub classes will need to implement them to fill $doc 157cfa2b40eSAndreas Gohr 158cfa2b40eSAndreas Gohr /** 159cfa2b40eSAndreas Gohr * Initialize the document 160cfa2b40eSAndreas Gohr */ 161faf3f01bSAndreas Gohr public function document_start() 162faf3f01bSAndreas Gohr { 1632c2835c2SAndreas Gohr } 1640cecf9d5Sandi 165cfa2b40eSAndreas Gohr /** 166cfa2b40eSAndreas Gohr * Finalize the document 167cfa2b40eSAndreas Gohr */ 168faf3f01bSAndreas Gohr public function document_end() 169faf3f01bSAndreas Gohr { 1702c2835c2SAndreas Gohr } 1710cecf9d5Sandi 172cfa2b40eSAndreas Gohr /** 173cfa2b40eSAndreas Gohr * Render the Table of Contents 174cfa2b40eSAndreas Gohr * 175cfa2b40eSAndreas Gohr * @return string 176cfa2b40eSAndreas Gohr */ 177faf3f01bSAndreas Gohr public function render_TOC() 178faf3f01bSAndreas Gohr { 1792c2835c2SAndreas Gohr return ''; 1802c2835c2SAndreas Gohr } 1810cecf9d5Sandi 182cfa2b40eSAndreas Gohr /** 183cfa2b40eSAndreas Gohr * Add an item to the TOC 184cfa2b40eSAndreas Gohr * 185cfa2b40eSAndreas Gohr * @param string $id the hash link 186cfa2b40eSAndreas Gohr * @param string $text the text to display 187cfa2b40eSAndreas Gohr * @param int $level the nesting level 188cfa2b40eSAndreas Gohr */ 189faf3f01bSAndreas Gohr public function toc_additem($id, $text, $level) 190faf3f01bSAndreas Gohr { 1912c2835c2SAndreas Gohr } 192e7856beaSchris 193cfa2b40eSAndreas Gohr /** 194cfa2b40eSAndreas Gohr * Render a heading 195cfa2b40eSAndreas Gohr * 196cfa2b40eSAndreas Gohr * @param string $text the text to display 197cfa2b40eSAndreas Gohr * @param int $level header level 198cfa2b40eSAndreas Gohr * @param int $pos byte position in the original source 199cfa2b40eSAndreas Gohr */ 200faf3f01bSAndreas Gohr public function header($text, $level, $pos) 201faf3f01bSAndreas Gohr { 2022c2835c2SAndreas Gohr } 2030cecf9d5Sandi 204cfa2b40eSAndreas Gohr /** 205cfa2b40eSAndreas Gohr * Open a new section 206cfa2b40eSAndreas Gohr * 207cfa2b40eSAndreas Gohr * @param int $level section level (as determined by the previous header) 208cfa2b40eSAndreas Gohr */ 209faf3f01bSAndreas Gohr public function section_open($level) 210faf3f01bSAndreas Gohr { 2112c2835c2SAndreas Gohr } 2120cecf9d5Sandi 213cfa2b40eSAndreas Gohr /** 214cfa2b40eSAndreas Gohr * Close the current section 215cfa2b40eSAndreas Gohr */ 216faf3f01bSAndreas Gohr public function section_close() 217faf3f01bSAndreas Gohr { 2182c2835c2SAndreas Gohr } 2190cecf9d5Sandi 220cfa2b40eSAndreas Gohr /** 221cfa2b40eSAndreas Gohr * Render plain text data 222cfa2b40eSAndreas Gohr * 22342ea7f44SGerrit Uitslag * @param string $text 224cfa2b40eSAndreas Gohr */ 225faf3f01bSAndreas Gohr public function cdata($text) 226faf3f01bSAndreas Gohr { 2272c2835c2SAndreas Gohr } 2280cecf9d5Sandi 229cfa2b40eSAndreas Gohr /** 230cfa2b40eSAndreas Gohr * Open a paragraph 231cfa2b40eSAndreas Gohr */ 232faf3f01bSAndreas Gohr public function p_open() 233faf3f01bSAndreas Gohr { 2342c2835c2SAndreas Gohr } 2350cecf9d5Sandi 236cfa2b40eSAndreas Gohr /** 237cfa2b40eSAndreas Gohr * Close a paragraph 238cfa2b40eSAndreas Gohr */ 239faf3f01bSAndreas Gohr public function p_close() 240faf3f01bSAndreas Gohr { 2412c2835c2SAndreas Gohr } 2420cecf9d5Sandi 243cfa2b40eSAndreas Gohr /** 2443dd5c225SAndreas Gohr * Create a line break 245cfa2b40eSAndreas Gohr */ 246faf3f01bSAndreas Gohr public function linebreak() 247faf3f01bSAndreas Gohr { 2482c2835c2SAndreas Gohr } 2490cecf9d5Sandi 250cfa2b40eSAndreas Gohr /** 251cfa2b40eSAndreas Gohr * Create a horizontal line 252cfa2b40eSAndreas Gohr */ 253faf3f01bSAndreas Gohr public function hr() 254faf3f01bSAndreas Gohr { 2552c2835c2SAndreas Gohr } 2560cecf9d5Sandi 257cfa2b40eSAndreas Gohr /** 258cfa2b40eSAndreas Gohr * Start strong (bold) formatting 259cfa2b40eSAndreas Gohr */ 260faf3f01bSAndreas Gohr public function strong_open() 261faf3f01bSAndreas Gohr { 2622c2835c2SAndreas Gohr } 2630cecf9d5Sandi 264cfa2b40eSAndreas Gohr /** 265cfa2b40eSAndreas Gohr * Stop strong (bold) formatting 266cfa2b40eSAndreas Gohr */ 267faf3f01bSAndreas Gohr public function strong_close() 268faf3f01bSAndreas Gohr { 2692c2835c2SAndreas Gohr } 2700cecf9d5Sandi 271cfa2b40eSAndreas Gohr /** 272cfa2b40eSAndreas Gohr * Start emphasis (italics) formatting 273cfa2b40eSAndreas Gohr */ 274faf3f01bSAndreas Gohr public function emphasis_open() 275faf3f01bSAndreas Gohr { 2762c2835c2SAndreas Gohr } 2770cecf9d5Sandi 278cfa2b40eSAndreas Gohr /** 279cfa2b40eSAndreas Gohr * Stop emphasis (italics) formatting 280cfa2b40eSAndreas Gohr */ 281faf3f01bSAndreas Gohr public function emphasis_close() 282faf3f01bSAndreas Gohr { 2832c2835c2SAndreas Gohr } 2840cecf9d5Sandi 285cfa2b40eSAndreas Gohr /** 286cfa2b40eSAndreas Gohr * Start underline formatting 287cfa2b40eSAndreas Gohr */ 288faf3f01bSAndreas Gohr public function underline_open() 289faf3f01bSAndreas Gohr { 2902c2835c2SAndreas Gohr } 2910cecf9d5Sandi 292cfa2b40eSAndreas Gohr /** 293cfa2b40eSAndreas Gohr * Stop underline formatting 294cfa2b40eSAndreas Gohr */ 295faf3f01bSAndreas Gohr public function underline_close() 296faf3f01bSAndreas Gohr { 2972c2835c2SAndreas Gohr } 2980cecf9d5Sandi 299cfa2b40eSAndreas Gohr /** 300cfa2b40eSAndreas Gohr * Start monospace formatting 301cfa2b40eSAndreas Gohr */ 302faf3f01bSAndreas Gohr public function monospace_open() 303faf3f01bSAndreas Gohr { 3042c2835c2SAndreas Gohr } 3050cecf9d5Sandi 306cfa2b40eSAndreas Gohr /** 307cfa2b40eSAndreas Gohr * Stop monospace formatting 308cfa2b40eSAndreas Gohr */ 309faf3f01bSAndreas Gohr public function monospace_close() 310faf3f01bSAndreas Gohr { 3112c2835c2SAndreas Gohr } 3120cecf9d5Sandi 313cfa2b40eSAndreas Gohr /** 314cfa2b40eSAndreas Gohr * Start a subscript 315cfa2b40eSAndreas Gohr */ 316faf3f01bSAndreas Gohr public function subscript_open() 317faf3f01bSAndreas Gohr { 3182c2835c2SAndreas Gohr } 3190cecf9d5Sandi 320cfa2b40eSAndreas Gohr /** 321cfa2b40eSAndreas Gohr * Stop a subscript 322cfa2b40eSAndreas Gohr */ 323faf3f01bSAndreas Gohr public function subscript_close() 324faf3f01bSAndreas Gohr { 3252c2835c2SAndreas Gohr } 3260cecf9d5Sandi 327cfa2b40eSAndreas Gohr /** 328cfa2b40eSAndreas Gohr * Start a superscript 329cfa2b40eSAndreas Gohr */ 330faf3f01bSAndreas Gohr public function superscript_open() 331faf3f01bSAndreas Gohr { 3322c2835c2SAndreas Gohr } 3330cecf9d5Sandi 334cfa2b40eSAndreas Gohr /** 335cfa2b40eSAndreas Gohr * Stop a superscript 336cfa2b40eSAndreas Gohr */ 337faf3f01bSAndreas Gohr public function superscript_close() 338faf3f01bSAndreas Gohr { 3392c2835c2SAndreas Gohr } 3400cecf9d5Sandi 341cfa2b40eSAndreas Gohr /** 342cfa2b40eSAndreas Gohr * Start deleted (strike-through) formatting 343cfa2b40eSAndreas Gohr */ 344faf3f01bSAndreas Gohr public function deleted_open() 345faf3f01bSAndreas Gohr { 3462c2835c2SAndreas Gohr } 3470cecf9d5Sandi 348cfa2b40eSAndreas Gohr /** 349cfa2b40eSAndreas Gohr * Stop deleted (strike-through) formatting 350cfa2b40eSAndreas Gohr */ 351faf3f01bSAndreas Gohr public function deleted_close() 352faf3f01bSAndreas Gohr { 3532c2835c2SAndreas Gohr } 3540cecf9d5Sandi 355cfa2b40eSAndreas Gohr /** 356cfa2b40eSAndreas Gohr * Start a footnote 357cfa2b40eSAndreas Gohr */ 358faf3f01bSAndreas Gohr public function footnote_open() 359faf3f01bSAndreas Gohr { 3602c2835c2SAndreas Gohr } 3610cecf9d5Sandi 362cfa2b40eSAndreas Gohr /** 363cfa2b40eSAndreas Gohr * Stop a footnote 364cfa2b40eSAndreas Gohr */ 365faf3f01bSAndreas Gohr public function footnote_close() 366faf3f01bSAndreas Gohr { 3672c2835c2SAndreas Gohr } 3680cecf9d5Sandi 369cfa2b40eSAndreas Gohr /** 370cfa2b40eSAndreas Gohr * Open an unordered list 371cfa2b40eSAndreas Gohr */ 372faf3f01bSAndreas Gohr public function listu_open() 373faf3f01bSAndreas Gohr { 3742c2835c2SAndreas Gohr } 3750cecf9d5Sandi 376cfa2b40eSAndreas Gohr /** 377cfa2b40eSAndreas Gohr * Close an unordered list 378cfa2b40eSAndreas Gohr */ 379faf3f01bSAndreas Gohr public function listu_close() 380faf3f01bSAndreas Gohr { 3812c2835c2SAndreas Gohr } 3820cecf9d5Sandi 383cfa2b40eSAndreas Gohr /** 384cfa2b40eSAndreas Gohr * Open an ordered list 385cfa2b40eSAndreas Gohr */ 386faf3f01bSAndreas Gohr public function listo_open() 387faf3f01bSAndreas Gohr { 3882c2835c2SAndreas Gohr } 3890cecf9d5Sandi 390cfa2b40eSAndreas Gohr /** 391cfa2b40eSAndreas Gohr * Close an ordered list 392cfa2b40eSAndreas Gohr */ 393faf3f01bSAndreas Gohr public function listo_close() 394faf3f01bSAndreas Gohr { 3952c2835c2SAndreas Gohr } 3960cecf9d5Sandi 397cfa2b40eSAndreas Gohr /** 398cfa2b40eSAndreas Gohr * Open a list item 399cfa2b40eSAndreas Gohr * 400cfa2b40eSAndreas Gohr * @param int $level the nesting level 401e3a24861SChristopher Smith * @param bool $node true when a node; false when a leaf 402cfa2b40eSAndreas Gohr */ 403faf3f01bSAndreas Gohr public function listitem_open($level, $node = false) 404faf3f01bSAndreas Gohr { 4052c2835c2SAndreas Gohr } 4060cecf9d5Sandi 407cfa2b40eSAndreas Gohr /** 408cfa2b40eSAndreas Gohr * Close a list item 409cfa2b40eSAndreas Gohr */ 410faf3f01bSAndreas Gohr public function listitem_close() 411faf3f01bSAndreas Gohr { 4122c2835c2SAndreas Gohr } 4130cecf9d5Sandi 414cfa2b40eSAndreas Gohr /** 415cfa2b40eSAndreas Gohr * Start the content of a list item 416cfa2b40eSAndreas Gohr */ 417faf3f01bSAndreas Gohr public function listcontent_open() 418faf3f01bSAndreas Gohr { 4192c2835c2SAndreas Gohr } 4200cecf9d5Sandi 421cfa2b40eSAndreas Gohr /** 422cfa2b40eSAndreas Gohr * Stop the content of a list item 423cfa2b40eSAndreas Gohr */ 424faf3f01bSAndreas Gohr public function listcontent_close() 425faf3f01bSAndreas Gohr { 4262c2835c2SAndreas Gohr } 4270cecf9d5Sandi 428cfa2b40eSAndreas Gohr /** 429cfa2b40eSAndreas Gohr * Output unformatted $text 430cfa2b40eSAndreas Gohr * 431cfa2b40eSAndreas Gohr * Defaults to $this->cdata() 432cfa2b40eSAndreas Gohr * 433cfa2b40eSAndreas Gohr * @param string $text 434cfa2b40eSAndreas Gohr */ 435faf3f01bSAndreas Gohr public function unformatted($text) 436faf3f01bSAndreas Gohr { 437cfa2b40eSAndreas Gohr $this->cdata($text); 4382c2835c2SAndreas Gohr } 4390cecf9d5Sandi 440cfa2b40eSAndreas Gohr /** 441cfa2b40eSAndreas Gohr * Output preformatted text 442cfa2b40eSAndreas Gohr * 443cfa2b40eSAndreas Gohr * @param string $text 444cfa2b40eSAndreas Gohr */ 445faf3f01bSAndreas Gohr public function preformatted($text) 446faf3f01bSAndreas Gohr { 4472c2835c2SAndreas Gohr } 4480cecf9d5Sandi 449cfa2b40eSAndreas Gohr /** 450cfa2b40eSAndreas Gohr * Start a block quote 451cfa2b40eSAndreas Gohr */ 452faf3f01bSAndreas Gohr public function quote_open() 453faf3f01bSAndreas Gohr { 4542c2835c2SAndreas Gohr } 4550cecf9d5Sandi 456cfa2b40eSAndreas Gohr /** 457cfa2b40eSAndreas Gohr * Stop a block quote 458cfa2b40eSAndreas Gohr */ 459faf3f01bSAndreas Gohr public function quote_close() 460faf3f01bSAndreas Gohr { 4612c2835c2SAndreas Gohr } 4620cecf9d5Sandi 463cfa2b40eSAndreas Gohr /** 464cfa2b40eSAndreas Gohr * Display text as file content, optionally syntax highlighted 465cfa2b40eSAndreas Gohr * 466cfa2b40eSAndreas Gohr * @param string $text text to show 467cfa2b40eSAndreas Gohr * @param string $lang programming language to use for syntax highlighting 468cfa2b40eSAndreas Gohr * @param string $file file path label 469cfa2b40eSAndreas Gohr */ 470faf3f01bSAndreas Gohr public function file($text, $lang = null, $file = null) 471faf3f01bSAndreas Gohr { 4722c2835c2SAndreas Gohr } 4733d491f75SAndreas Gohr 474cfa2b40eSAndreas Gohr /** 475cfa2b40eSAndreas Gohr * Display text as code content, optionally syntax highlighted 476cfa2b40eSAndreas Gohr * 477cfa2b40eSAndreas Gohr * @param string $text text to show 478cfa2b40eSAndreas Gohr * @param string $lang programming language to use for syntax highlighting 479cfa2b40eSAndreas Gohr * @param string $file file path label 480cfa2b40eSAndreas Gohr */ 481faf3f01bSAndreas Gohr public function code($text, $lang = null, $file = null) 482faf3f01bSAndreas Gohr { 4832c2835c2SAndreas Gohr } 4840cecf9d5Sandi 485cfa2b40eSAndreas Gohr /** 486cfa2b40eSAndreas Gohr * Format an acronym 487cfa2b40eSAndreas Gohr * 488cfa2b40eSAndreas Gohr * Uses $this->acronyms 489cfa2b40eSAndreas Gohr * 490cfa2b40eSAndreas Gohr * @param string $acronym 491cfa2b40eSAndreas Gohr */ 492faf3f01bSAndreas Gohr public function acronym($acronym) 493faf3f01bSAndreas Gohr { 4942c2835c2SAndreas Gohr } 4950cecf9d5Sandi 496cfa2b40eSAndreas Gohr /** 497cfa2b40eSAndreas Gohr * Format a smiley 498cfa2b40eSAndreas Gohr * 499cfa2b40eSAndreas Gohr * Uses $this->smiley 500cfa2b40eSAndreas Gohr * 501cfa2b40eSAndreas Gohr * @param string $smiley 502cfa2b40eSAndreas Gohr */ 503faf3f01bSAndreas Gohr public function smiley($smiley) 504faf3f01bSAndreas Gohr { 5052c2835c2SAndreas Gohr } 5060cecf9d5Sandi 507cfa2b40eSAndreas Gohr /** 508cfa2b40eSAndreas Gohr * Format an entity 509cfa2b40eSAndreas Gohr * 510cfa2b40eSAndreas Gohr * Entities are basically small text replacements 511cfa2b40eSAndreas Gohr * 512cfa2b40eSAndreas Gohr * Uses $this->entities 513cfa2b40eSAndreas Gohr * 514cfa2b40eSAndreas Gohr * @param string $entity 515cfa2b40eSAndreas Gohr */ 516faf3f01bSAndreas Gohr public function entity($entity) 517faf3f01bSAndreas Gohr { 5182c2835c2SAndreas Gohr } 5190cecf9d5Sandi 520cfa2b40eSAndreas Gohr /** 521cfa2b40eSAndreas Gohr * Typographically format a multiply sign 522cfa2b40eSAndreas Gohr * 523cfa2b40eSAndreas Gohr * Example: ($x=640, $y=480) should result in "640×480" 524cfa2b40eSAndreas Gohr * 525cfa2b40eSAndreas Gohr * @param string|int $x first value 526cfa2b40eSAndreas Gohr * @param string|int $y second value 527cfa2b40eSAndreas Gohr */ 528faf3f01bSAndreas Gohr public function multiplyentity($x, $y) 529faf3f01bSAndreas Gohr { 5302c2835c2SAndreas Gohr } 5310cecf9d5Sandi 532cfa2b40eSAndreas Gohr /** 533cfa2b40eSAndreas Gohr * Render an opening single quote char (language specific) 534cfa2b40eSAndreas Gohr */ 535faf3f01bSAndreas Gohr public function singlequoteopening() 536faf3f01bSAndreas Gohr { 5372c2835c2SAndreas Gohr } 5380cecf9d5Sandi 539cfa2b40eSAndreas Gohr /** 540cfa2b40eSAndreas Gohr * Render a closing single quote char (language specific) 541cfa2b40eSAndreas Gohr */ 542faf3f01bSAndreas Gohr public function singlequoteclosing() 543faf3f01bSAndreas Gohr { 5442c2835c2SAndreas Gohr } 5450cecf9d5Sandi 546cfa2b40eSAndreas Gohr /** 547cfa2b40eSAndreas Gohr * Render an apostrophe char (language specific) 548cfa2b40eSAndreas Gohr */ 549faf3f01bSAndreas Gohr public function apostrophe() 550faf3f01bSAndreas Gohr { 5512c2835c2SAndreas Gohr } 55257d757d1SAndreas Gohr 553cfa2b40eSAndreas Gohr /** 554cfa2b40eSAndreas Gohr * Render an opening double quote char (language specific) 555cfa2b40eSAndreas Gohr */ 556faf3f01bSAndreas Gohr public function doublequoteopening() 557faf3f01bSAndreas Gohr { 5582c2835c2SAndreas Gohr } 5590cecf9d5Sandi 560cfa2b40eSAndreas Gohr /** 561cfa2b40eSAndreas Gohr * Render an closinging double quote char (language specific) 562cfa2b40eSAndreas Gohr */ 563faf3f01bSAndreas Gohr public function doublequoteclosing() 564faf3f01bSAndreas Gohr { 5652c2835c2SAndreas Gohr } 5660cecf9d5Sandi 567cfa2b40eSAndreas Gohr /** 568cfa2b40eSAndreas Gohr * Render a CamelCase link 569cfa2b40eSAndreas Gohr * 570cfa2b40eSAndreas Gohr * @param string $link The link name 571cfa2b40eSAndreas Gohr * @see http://en.wikipedia.org/wiki/CamelCase 572cfa2b40eSAndreas Gohr */ 573faf3f01bSAndreas Gohr public function camelcaselink($link) 574faf3f01bSAndreas Gohr { 5752c2835c2SAndreas Gohr } 5760cecf9d5Sandi 577cfa2b40eSAndreas Gohr /** 578cfa2b40eSAndreas Gohr * Render a page local link 579cfa2b40eSAndreas Gohr * 580cfa2b40eSAndreas Gohr * @param string $hash hash link identifier 581cfa2b40eSAndreas Gohr * @param string $name name for the link 582cfa2b40eSAndreas Gohr */ 583faf3f01bSAndreas Gohr public function locallink($hash, $name = null) 584faf3f01bSAndreas Gohr { 5852c2835c2SAndreas Gohr } 586a939d432SAndreas Gohr 587cfa2b40eSAndreas Gohr /** 588cfa2b40eSAndreas Gohr * Render a wiki internal link 589cfa2b40eSAndreas Gohr * 590cfa2b40eSAndreas Gohr * @param string $link page ID to link to. eg. 'wiki:syntax' 591cfa2b40eSAndreas Gohr * @param string|array $title name for the link, array for media file 592cfa2b40eSAndreas Gohr */ 593faf3f01bSAndreas Gohr public function internallink($link, $title = null) 594faf3f01bSAndreas Gohr { 5952c2835c2SAndreas Gohr } 5960cecf9d5Sandi 597cfa2b40eSAndreas Gohr /** 598cfa2b40eSAndreas Gohr * Render an external link 599cfa2b40eSAndreas Gohr * 600cfa2b40eSAndreas Gohr * @param string $link full URL with scheme 601cfa2b40eSAndreas Gohr * @param string|array $title name for the link, array for media file 602cfa2b40eSAndreas Gohr */ 603faf3f01bSAndreas Gohr public function externallink($link, $title = null) 604faf3f01bSAndreas Gohr { 6052c2835c2SAndreas Gohr } 6060cecf9d5Sandi 607cfa2b40eSAndreas Gohr /** 608cfa2b40eSAndreas Gohr * Render the output of an RSS feed 609cfa2b40eSAndreas Gohr * 610cfa2b40eSAndreas Gohr * @param string $url URL of the feed 611cfa2b40eSAndreas Gohr * @param array $params Finetuning of the output 612cfa2b40eSAndreas Gohr */ 613faf3f01bSAndreas Gohr public function rss($url, $params) 614faf3f01bSAndreas Gohr { 6152c2835c2SAndreas Gohr } 616c5cfca61SAndreas Gohr 617cfa2b40eSAndreas Gohr /** 618cfa2b40eSAndreas Gohr * Render an interwiki link 619cfa2b40eSAndreas Gohr * 620cfa2b40eSAndreas Gohr * You may want to use $this->_resolveInterWiki() here 621cfa2b40eSAndreas Gohr * 622cfa2b40eSAndreas Gohr * @param string $link original link - probably not much use 623cfa2b40eSAndreas Gohr * @param string|array $title name for the link, array for media file 624cfa2b40eSAndreas Gohr * @param string $wikiName indentifier (shortcut) for the remote wiki 625cfa2b40eSAndreas Gohr * @param string $wikiUri the fragment parsed from the original link 626cfa2b40eSAndreas Gohr */ 627faf3f01bSAndreas Gohr public function interwikilink($link, $title, $wikiName, $wikiUri) 628faf3f01bSAndreas Gohr { 6292c2835c2SAndreas Gohr } 6300cecf9d5Sandi 631cfa2b40eSAndreas Gohr /** 632cfa2b40eSAndreas Gohr * Link to file on users OS 633cfa2b40eSAndreas Gohr * 634cfa2b40eSAndreas Gohr * @param string $link the link 635cfa2b40eSAndreas Gohr * @param string|array $title name for the link, array for media file 636cfa2b40eSAndreas Gohr */ 637faf3f01bSAndreas Gohr public function filelink($link, $title = null) 638faf3f01bSAndreas Gohr { 6392c2835c2SAndreas Gohr } 6400cecf9d5Sandi 641cfa2b40eSAndreas Gohr /** 642cfa2b40eSAndreas Gohr * Link to windows share 643cfa2b40eSAndreas Gohr * 644cfa2b40eSAndreas Gohr * @param string $link the link 645cfa2b40eSAndreas Gohr * @param string|array $title name for the link, array for media file 646cfa2b40eSAndreas Gohr */ 647faf3f01bSAndreas Gohr public function windowssharelink($link, $title = null) 648faf3f01bSAndreas Gohr { 6492c2835c2SAndreas Gohr } 6500cecf9d5Sandi 651cfa2b40eSAndreas Gohr /** 652cfa2b40eSAndreas Gohr * Render a linked E-Mail Address 653cfa2b40eSAndreas Gohr * 654cfa2b40eSAndreas Gohr * Should honor $conf['mailguard'] setting 655cfa2b40eSAndreas Gohr * 656cfa2b40eSAndreas Gohr * @param string $address Email-Address 6573dd5c225SAndreas Gohr * @param string|array $name name for the link, array for media file 658cfa2b40eSAndreas Gohr */ 659faf3f01bSAndreas Gohr public function emaillink($address, $name = null) 660faf3f01bSAndreas Gohr { 6612c2835c2SAndreas Gohr } 6620cecf9d5Sandi 663cfa2b40eSAndreas Gohr /** 664cfa2b40eSAndreas Gohr * Render an internal media file 665cfa2b40eSAndreas Gohr * 666cfa2b40eSAndreas Gohr * @param string $src media ID 667cfa2b40eSAndreas Gohr * @param string $title descriptive text 668cfa2b40eSAndreas Gohr * @param string $align left|center|right 669cfa2b40eSAndreas Gohr * @param int $width width of media in pixel 670cfa2b40eSAndreas Gohr * @param int $height height of media in pixel 671cfa2b40eSAndreas Gohr * @param string $cache cache|recache|nocache 672cfa2b40eSAndreas Gohr * @param string $linking linkonly|detail|nolink 673cfa2b40eSAndreas Gohr */ 674de369923SAndreas Gohr public function internalmedia($src, $title = null, $align = null, $width = null, 675faf3f01bSAndreas Gohr $height = null, $cache = null, $linking = null) 676faf3f01bSAndreas Gohr { 6772c2835c2SAndreas Gohr } 678a939d432SAndreas Gohr 679cfa2b40eSAndreas Gohr /** 680cfa2b40eSAndreas Gohr * Render an external media file 681cfa2b40eSAndreas Gohr * 682cfa2b40eSAndreas Gohr * @param string $src full media URL 683cfa2b40eSAndreas Gohr * @param string $title descriptive text 684cfa2b40eSAndreas Gohr * @param string $align left|center|right 685cfa2b40eSAndreas Gohr * @param int $width width of media in pixel 686cfa2b40eSAndreas Gohr * @param int $height height of media in pixel 687cfa2b40eSAndreas Gohr * @param string $cache cache|recache|nocache 688cfa2b40eSAndreas Gohr * @param string $linking linkonly|detail|nolink 689cfa2b40eSAndreas Gohr */ 690de369923SAndreas Gohr public function externalmedia($src, $title = null, $align = null, $width = null, 691faf3f01bSAndreas Gohr $height = null, $cache = null, $linking = null) 692faf3f01bSAndreas Gohr { 6932c2835c2SAndreas Gohr } 694a939d432SAndreas Gohr 695cfa2b40eSAndreas Gohr /** 696cfa2b40eSAndreas Gohr * Render a link to an internal media file 697cfa2b40eSAndreas Gohr * 698cfa2b40eSAndreas Gohr * @param string $src media ID 699cfa2b40eSAndreas Gohr * @param string $title descriptive text 700cfa2b40eSAndreas Gohr * @param string $align left|center|right 701cfa2b40eSAndreas Gohr * @param int $width width of media in pixel 702cfa2b40eSAndreas Gohr * @param int $height height of media in pixel 703cfa2b40eSAndreas Gohr * @param string $cache cache|recache|nocache 704cfa2b40eSAndreas Gohr */ 705de369923SAndreas Gohr public function internalmedialink($src, $title = null, $align = null, 706faf3f01bSAndreas Gohr $width = null, $height = null, $cache = null) 707faf3f01bSAndreas Gohr { 7082c2835c2SAndreas Gohr } 7090cecf9d5Sandi 710cfa2b40eSAndreas Gohr /** 711cfa2b40eSAndreas Gohr * Render a link to an external media file 712cfa2b40eSAndreas Gohr * 713cfa2b40eSAndreas Gohr * @param string $src media ID 714cfa2b40eSAndreas Gohr * @param string $title descriptive text 715cfa2b40eSAndreas Gohr * @param string $align left|center|right 716cfa2b40eSAndreas Gohr * @param int $width width of media in pixel 717cfa2b40eSAndreas Gohr * @param int $height height of media in pixel 718cfa2b40eSAndreas Gohr * @param string $cache cache|recache|nocache 719cfa2b40eSAndreas Gohr */ 720de369923SAndreas Gohr public function externalmedialink($src, $title = null, $align = null, 721faf3f01bSAndreas Gohr $width = null, $height = null, $cache = null) 722faf3f01bSAndreas Gohr { 7232c2835c2SAndreas Gohr } 7240cecf9d5Sandi 725cfa2b40eSAndreas Gohr /** 726cfa2b40eSAndreas Gohr * Start a table 727cfa2b40eSAndreas Gohr * 728cfa2b40eSAndreas Gohr * @param int $maxcols maximum number of columns 729cfa2b40eSAndreas Gohr * @param int $numrows NOT IMPLEMENTED 730cfa2b40eSAndreas Gohr * @param int $pos byte position in the original source 731cfa2b40eSAndreas Gohr */ 732faf3f01bSAndreas Gohr public function table_open($maxcols = null, $numrows = null, $pos = null) 733faf3f01bSAndreas Gohr { 7342c2835c2SAndreas Gohr } 7350cecf9d5Sandi 736cfa2b40eSAndreas Gohr /** 737cfa2b40eSAndreas Gohr * Close a table 738cfa2b40eSAndreas Gohr * 739cfa2b40eSAndreas Gohr * @param int $pos byte position in the original source 740cfa2b40eSAndreas Gohr */ 741faf3f01bSAndreas Gohr public function table_close($pos = null) 742faf3f01bSAndreas Gohr { 7432c2835c2SAndreas Gohr } 7440cecf9d5Sandi 745cfa2b40eSAndreas Gohr /** 746cfa2b40eSAndreas Gohr * Open a table header 747cfa2b40eSAndreas Gohr */ 748faf3f01bSAndreas Gohr public function tablethead_open() 749faf3f01bSAndreas Gohr { 7502c2835c2SAndreas Gohr } 751f05a1cc5SGerrit Uitslag 752cfa2b40eSAndreas Gohr /** 753cfa2b40eSAndreas Gohr * Close a table header 754cfa2b40eSAndreas Gohr */ 755faf3f01bSAndreas Gohr public function tablethead_close() 756faf3f01bSAndreas Gohr { 7572c2835c2SAndreas Gohr } 758f05a1cc5SGerrit Uitslag 759cfa2b40eSAndreas Gohr /** 7605a93f869SAnika Henke * Open a table body 7615a93f869SAnika Henke */ 762faf3f01bSAndreas Gohr public function tabletbody_open() 763faf3f01bSAndreas Gohr { 7645a93f869SAnika Henke } 7655a93f869SAnika Henke 7665a93f869SAnika Henke /** 7675a93f869SAnika Henke * Close a table body 7685a93f869SAnika Henke */ 769faf3f01bSAndreas Gohr public function tabletbody_close() 770faf3f01bSAndreas Gohr { 7715a93f869SAnika Henke } 7725a93f869SAnika Henke 7735a93f869SAnika Henke /** 774d2a99739SAndreas Gohr * Open a table footer 775d2a99739SAndreas Gohr */ 776faf3f01bSAndreas Gohr public function tabletfoot_open() 777faf3f01bSAndreas Gohr { 778d2a99739SAndreas Gohr } 779d2a99739SAndreas Gohr 780d2a99739SAndreas Gohr /** 781d2a99739SAndreas Gohr * Close a table footer 782d2a99739SAndreas Gohr */ 783faf3f01bSAndreas Gohr public function tabletfoot_close() 784faf3f01bSAndreas Gohr { 785d2a99739SAndreas Gohr } 786d2a99739SAndreas Gohr 787d2a99739SAndreas Gohr /** 788cfa2b40eSAndreas Gohr * Open a table row 789cfa2b40eSAndreas Gohr */ 790faf3f01bSAndreas Gohr public function tablerow_open() 791faf3f01bSAndreas Gohr { 7922c2835c2SAndreas Gohr } 7930cecf9d5Sandi 794cfa2b40eSAndreas Gohr /** 795cfa2b40eSAndreas Gohr * Close a table row 796cfa2b40eSAndreas Gohr */ 797faf3f01bSAndreas Gohr public function tablerow_close() 798faf3f01bSAndreas Gohr { 7992c2835c2SAndreas Gohr } 8000cecf9d5Sandi 801cfa2b40eSAndreas Gohr /** 802cfa2b40eSAndreas Gohr * Open a table header cell 803cfa2b40eSAndreas Gohr * 804cfa2b40eSAndreas Gohr * @param int $colspan 805cfa2b40eSAndreas Gohr * @param string $align left|center|right 806cfa2b40eSAndreas Gohr * @param int $rowspan 807cfa2b40eSAndreas Gohr */ 808faf3f01bSAndreas Gohr public function tableheader_open($colspan = 1, $align = null, $rowspan = 1) 809faf3f01bSAndreas Gohr { 8102c2835c2SAndreas Gohr } 8110cecf9d5Sandi 812cfa2b40eSAndreas Gohr /** 813cfa2b40eSAndreas Gohr * Close a table header cell 814cfa2b40eSAndreas Gohr */ 815faf3f01bSAndreas Gohr public function tableheader_close() 816faf3f01bSAndreas Gohr { 8172c2835c2SAndreas Gohr } 8180cecf9d5Sandi 819cfa2b40eSAndreas Gohr /** 820cfa2b40eSAndreas Gohr * Open a table cell 821cfa2b40eSAndreas Gohr * 822cfa2b40eSAndreas Gohr * @param int $colspan 823cfa2b40eSAndreas Gohr * @param string $align left|center|right 824cfa2b40eSAndreas Gohr * @param int $rowspan 825cfa2b40eSAndreas Gohr */ 826faf3f01bSAndreas Gohr public function tablecell_open($colspan = 1, $align = null, $rowspan = 1) 827faf3f01bSAndreas Gohr { 8282c2835c2SAndreas Gohr } 8290cecf9d5Sandi 830cfa2b40eSAndreas Gohr /** 831cfa2b40eSAndreas Gohr * Close a table cell 832cfa2b40eSAndreas Gohr */ 833faf3f01bSAndreas Gohr public function tablecell_close() 834faf3f01bSAndreas Gohr { 8352c2835c2SAndreas Gohr } 8362ea4044fSAndreas Gohr 837cfa2b40eSAndreas Gohr #endregion 838cfa2b40eSAndreas Gohr 839cfa2b40eSAndreas Gohr #region util functions, you probably won't need to reimplement them 8402ea4044fSAndreas Gohr 8412ea4044fSAndreas Gohr /** 842de369923SAndreas Gohr * Creates a linkid from a headline 843de369923SAndreas Gohr * 844de369923SAndreas Gohr * @param string $title The headline title 845de369923SAndreas Gohr * @param boolean $create Create a new unique ID? 846de369923SAndreas Gohr * @return string 847faf3f01bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 848de369923SAndreas Gohr */ 849faf3f01bSAndreas Gohr public function _headerToLink($title, $create = false) 850faf3f01bSAndreas Gohr { 851de369923SAndreas Gohr if ($create) { 852de369923SAndreas Gohr return sectionID($title, $this->headers); 853de369923SAndreas Gohr } else { 854de369923SAndreas Gohr $check = false; 855de369923SAndreas Gohr return sectionID($title, $check); 856de369923SAndreas Gohr } 857de369923SAndreas Gohr } 858de369923SAndreas Gohr 859de369923SAndreas Gohr /** 8602ea4044fSAndreas Gohr * Removes any Namespace from the given name but keeps 8612ea4044fSAndreas Gohr * casing and special chars 8622ea4044fSAndreas Gohr * 86342ea7f44SGerrit Uitslag * @param string $name 86442ea7f44SGerrit Uitslag * @return string 865faf3f01bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 866faf3f01bSAndreas Gohr * 8672ea4044fSAndreas Gohr */ 868faf3f01bSAndreas Gohr public function _simpleTitle($name) 869faf3f01bSAndreas Gohr { 8702ea4044fSAndreas Gohr global $conf; 8712ea4044fSAndreas Gohr 8722ea4044fSAndreas Gohr //if there is a hash we use the ancor name only 873faf3f01bSAndreas Gohr [$name, $hash] = sexplode('#', $name, 2); 8742ea4044fSAndreas Gohr if ($hash) return $hash; 8752ea4044fSAndreas Gohr 8762ea4044fSAndreas Gohr if ($conf['useslash']) { 8773755fc25STom N Harris $name = strtr($name, ';/', ';:'); 8783755fc25STom N Harris } else { 8793755fc25STom N Harris $name = strtr($name, ';', ':'); 8802ea4044fSAndreas Gohr } 8812ea4044fSAndreas Gohr 8829708106bSAdrian Lang return noNSorNS($name); 8832ea4044fSAndreas Gohr } 8842ea4044fSAndreas Gohr 8851f82fabeSAndreas Gohr /** 8861f82fabeSAndreas Gohr * Resolve an interwikilink 88742ea7f44SGerrit Uitslag * 88842ea7f44SGerrit Uitslag * @param string $shortcut identifier for the interwiki link 88942ea7f44SGerrit Uitslag * @param string $reference fragment that refers the content 89042ea7f44SGerrit Uitslag * @param null|bool $exists reference which returns if an internal page exists 89142ea7f44SGerrit Uitslag * @return string interwikilink 8921f82fabeSAndreas Gohr */ 893faf3f01bSAndreas Gohr public function _resolveInterWiki(&$shortcut, $reference, &$exists = null) 894faf3f01bSAndreas Gohr { 8951f82fabeSAndreas Gohr //get interwiki URL 8961f82fabeSAndreas Gohr if (isset($this->interwiki[$shortcut])) { 8971f82fabeSAndreas Gohr $url = $this->interwiki[$shortcut]; 898768be5a3SPhy } elseif (isset($this->interwiki['default'])) { 899768be5a3SPhy $shortcut = 'default'; 900768be5a3SPhy $url = $this->interwiki[$shortcut]; 9011f82fabeSAndreas Gohr } else { 902abde5980SPhy // not parsable interwiki outputs '' to make sure string manipluation works 903abde5980SPhy $shortcut = ''; 904abde5980SPhy $url = ''; 9051f82fabeSAndreas Gohr } 9062ea4044fSAndreas Gohr 9071f82fabeSAndreas Gohr //split into hash and url part 90817e17ae2SPatrick Brown $hash = strrchr($reference, '#'); 90917e17ae2SPatrick Brown if ($hash) { 91017e17ae2SPatrick Brown $reference = substr($reference, 0, -strlen($hash)); 91117e17ae2SPatrick Brown $hash = substr($hash, 1); 91217e17ae2SPatrick Brown } 9131f82fabeSAndreas Gohr 9141f82fabeSAndreas Gohr //replace placeholder 9151f82fabeSAndreas Gohr if (preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#', $url)) { 9161f82fabeSAndreas Gohr //use placeholders 9171f82fabeSAndreas Gohr $url = str_replace('{URL}', rawurlencode($reference), $url); 91817e17ae2SPatrick Brown //wiki names will be cleaned next, otherwise urlencode unsafe chars 919faf3f01bSAndreas Gohr $url = str_replace( 920faf3f01bSAndreas Gohr '{NAME}', 921faf3f01bSAndreas Gohr ($url[0] === ':') ? $reference : preg_replace_callback( 922faf3f01bSAndreas Gohr '/[[\\\\\]^`{|}#%]/', static fn($match) => rawurlencode($match[0]), $reference 923faf3f01bSAndreas Gohr ), 924faf3f01bSAndreas Gohr $url 925faf3f01bSAndreas Gohr ); 9261f82fabeSAndreas Gohr $parsed = parse_url($reference); 9278f34cf3dSMichael Große if (empty($parsed['scheme'])) $parsed['scheme'] = ''; 9288f34cf3dSMichael Große if (empty($parsed['host'])) $parsed['host'] = ''; 9298f34cf3dSMichael Große if (empty($parsed['port'])) $parsed['port'] = 80; 9308f34cf3dSMichael Große if (empty($parsed['path'])) $parsed['path'] = ''; 9318f34cf3dSMichael Große if (empty($parsed['query'])) $parsed['query'] = ''; 9328f34cf3dSMichael Große $url = strtr($url, [ 9338f34cf3dSMichael Große '{SCHEME}' => $parsed['scheme'], 9348f34cf3dSMichael Große '{HOST}' => $parsed['host'], 9358f34cf3dSMichael Große '{PORT}' => $parsed['port'], 9368f34cf3dSMichael Große '{PATH}' => $parsed['path'], 9378f34cf3dSMichael Große '{QUERY}' => $parsed['query'], 9388f34cf3dSMichael Große ]); 939abde5980SPhy } elseif ($url != '') { 940abde5980SPhy // make sure when no url is defined, we keep it null 9411f82fabeSAndreas Gohr // default 942faf3f01bSAndreas Gohr $url .= rawurlencode($reference); 9431f82fabeSAndreas Gohr } 944f379edc2SGerrit Uitslag //handle as wiki links 945056bf31fSDamien Regad if ($url && $url[0] === ':') { 946ac1d8211SAndreas Gohr $urlparam = ''; 947c55b109cSMichael Große $id = $url; 948c55b109cSMichael Große if (strpos($url, '?') !== false) { 949faf3f01bSAndreas Gohr [$id, $urlparam] = sexplode('?', $url, 2, ''); 950c55b109cSMichael Große } 9516496c33fSGerrit Uitslag $url = wl(cleanID($id), $urlparam); 9526496c33fSGerrit Uitslag $exists = page_exists($id); 9532345e871SGerrit Uitslag } 9541f82fabeSAndreas Gohr if ($hash) $url .= '#' . rawurlencode($hash); 9551f82fabeSAndreas Gohr 9561f82fabeSAndreas Gohr return $url; 9571f82fabeSAndreas Gohr } 958cfa2b40eSAndreas Gohr 959cfa2b40eSAndreas Gohr #endregion 9600cecf9d5Sandi} 9610cecf9d5Sandi 962340756e4Sandi 963e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 964