From b1af90141d42f8844159ff4fad76968a8ee78687 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Thu, 1 Aug 2013 16:32:28 +0200 Subject: Improve nofollow behaviour for ?do=index In response to FS#2766 - make namespace links in the browser sitemap nofollow - remove nofollow from browser sitemap link on the wiki start page when sitemap.xml generation is disabled --- inc/html.php | 3 ++- inc/template.php | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'inc') diff --git a/inc/html.php b/inc/html.php index 53f4c45ff..53a100ec7 100644 --- a/inc/html.php +++ b/inc/html.php @@ -859,7 +859,8 @@ function html_list_index($item){ $base = ':'.$item['id']; $base = substr($base,strrpos($base,':')+1); if($item['type']=='d'){ - $ret .= ''; + // FS#2766, no need for search bots to follow namespace links in the index + $ret .= ''; $ret .= $base; $ret .= ''; }else{ diff --git a/inc/template.php b/inc/template.php index b8129f914..54407c2ab 100644 --- a/inc/template.php +++ b/inc/template.php @@ -541,6 +541,7 @@ function tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = fals * @var string $accesskey * @var string $id * @var string $method + * @var bool $nofollow * @var array $params */ extract($data); @@ -555,10 +556,11 @@ function tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = fals $akey = 'accesskey="'.$accesskey.'" '; $addTitle = ' ['.strtoupper($accesskey).']'; } + $rel = $nofollow ? 'rel="nofollow" ' : ''; $out = tpl_link( $linktarget, $pre.(($inner) ? $inner : $caption).$suf, 'class="action '.$type.'" '. - $akey.'rel="nofollow" '. + $akey.$rel. 'title="'.hsc($caption).$addTitle.'"', 1 ); } @@ -595,6 +597,7 @@ function tpl_get_action($type) { global $INFO; global $REV; global $ACT; + global $conf; // check disabled actions and fix the badly named ones if($type == 'history') $type = 'revisions'; @@ -604,6 +607,7 @@ function tpl_get_action($type) { $id = $ID; $method = 'get'; $params = array('do' => $type); + $nofollow = true; switch($type) { case 'edit': // most complicated type - we need to decide on current action @@ -641,6 +645,10 @@ function tpl_get_action($type) { break; case 'index': $accesskey = 'x'; + // allow searchbots to get to the sitemap from the homepage (when dokuwiki isn't providing a sitemap.xml) + if ($conf['start'] == $ID && !$conf['sitemap']) { + $nofollow = false; + } break; case 'top': $accesskey = 't'; @@ -711,7 +719,7 @@ function tpl_get_action($type) { return '[unknown %s type]'; break; } - return compact('accesskey', 'type', 'id', 'method', 'params'); + return compact('accesskey', 'type', 'id', 'method', 'params', 'nofollow'); } /** -- cgit v1.2.3 From 74ef17786eb9ce751a8dd7c66ab7523efa92c79f Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Thu, 1 Aug 2013 22:46:16 +0200 Subject: include namespace links when index access from the wiki start page and no automatic sitemap.xml is being generated. --- inc/html.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/html.php b/inc/html.php index 53a100ec7..5f94d7dce 100644 --- a/inc/html.php +++ b/inc/html.php @@ -854,13 +854,17 @@ function html_index($ns){ * @author Andreas Gohr */ function html_list_index($item){ - global $ID; + global $ID, $conf; + + // prevent searchbots needlessly following links - only necessary when accessed from the homepage and no sitemap.xml is being generated + $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? ' rel="nofollow"' : ''; + $ret = ''; $base = ':'.$item['id']; $base = substr($base,strrpos($base,':')+1); if($item['type']=='d'){ // FS#2766, no need for search bots to follow namespace links in the index - $ret .= ''; + $ret .= ''; $ret .= $base; $ret .= ''; }else{ -- cgit v1.2.3 From b8bc53ce8da2f0fb9cfedb01df6507b29f32daaa Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Thu, 1 Aug 2013 23:06:57 +0200 Subject: simplify comment --- inc/html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/html.php b/inc/html.php index 5f94d7dce..d43611940 100644 --- a/inc/html.php +++ b/inc/html.php @@ -856,7 +856,7 @@ function html_index($ns){ function html_list_index($item){ global $ID, $conf; - // prevent searchbots needlessly following links - only necessary when accessed from the homepage and no sitemap.xml is being generated + // prevent searchbots needlessly following links $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? ' rel="nofollow"' : ''; $ret = ''; -- cgit v1.2.3