Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
splitbrain committed Nov 18, 2018
1 parent a007d3b commit d27d215
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions syntax.php
Expand Up @@ -6,34 +6,45 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/

// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();

class syntax_plugin_talkpage extends DokuWiki_Syntax_Plugin {
public function getType() {
/** @inheritdoc */
class syntax_plugin_talkpage extends DokuWiki_Syntax_Plugin
{
/** @inheritdoc */
public function getType()
{
return 'substition';
}

public function getPType() {
/** @inheritdoc */
public function getPType()
{
return 'normal';
}

public function getSort() {
/** @inheritdoc */
public function getSort()
{
return 444;
}

public function connectTo($mode) {
/** @inheritdoc */
public function connectTo($mode)
{
$this->Lexer->addSpecialPattern('~~TALKPAGE~~', $mode, 'plugin_talkpage');
}

public function handle($match, $state, $pos, Doku_Handler $handler) {
/** @inheritdoc */
public function handle($match, $state, $pos, Doku_Handler $handler)
{
$data = array();

return $data;
}

public function render($mode, Doku_Renderer $renderer, $data) {
if($mode != 'xhtml') return false;
/** @inheritdoc */
public function render($mode, Doku_Renderer $renderer, $data)
{
if ($mode != 'xhtml') return false;
$renderer->info['cache'] = false;

$data = $this->getLink();
Expand All @@ -44,33 +55,32 @@ public function render($mode, Doku_Renderer $renderer, $data) {
/**
* @return array text and attributes for the link
*/
public function getLink() {
public function getLink()
{
global $INFO;
$talkns = cleanID($this->getConf('talkns'));

$attr = array();
if(substr($INFO['id'], 0, strlen($talkns) + 1) === "$talkns:") {
if (substr($INFO['id'], 0, strlen($talkns) + 1) === "$talkns:") {
// we're on the talk page
$goto = substr($INFO['id'], strlen($talkns) + 1);
$text = 'back';
} else {
// we want to the talk page
$goto = $talkns . ':' . $INFO['id'];
if(page_exists($goto)) {
if (page_exists($goto)) {
$text = 'talk';
} else {
$text = 'add';
$attr['rel'] = 'nofollow';
}
}
$attr['href'] = wl($goto);
$attr['class'] = 'talkpage talkpag-' . $text;
$attr['href'] = wl($goto);
$attr['class'] = 'talkpage talkpage-' . $text;

return array(
'text' => $this->getLang($text),
'attr' => $attr
'attr' => $attr,
);
}
}

// vim:ts=4:sw=4:et:

0 comments on commit d27d215

Please sign in to comment.