18fce80b1SAndreas Gohr<?php 28fce80b1SAndreas Gohr// must be run within Dokuwiki 38fce80b1SAndreas Gohrif(!defined('DOKU_INC')) die(); 48fce80b1SAndreas Gohr 58fce80b1SAndreas Gohr// we inherit from the XHTML renderer instead directly of the base renderer 68fce80b1SAndreas Gohrrequire_once DOKU_INC.'inc/parser/renderer.php'; 78fce80b1SAndreas Gohr 88fce80b1SAndreas Gohr/** 98fce80b1SAndreas Gohr * The Renderer 108fce80b1SAndreas Gohr */ 118fce80b1SAndreas Gohrclass renderer_plugin_qc extends Doku_Renderer { 128fce80b1SAndreas Gohr /** 138fce80b1SAndreas Gohr * We store all our data in an array 148fce80b1SAndreas Gohr */ 158fce80b1SAndreas Gohr var $doc = array( 168fce80b1SAndreas Gohr // raw statistics 178fce80b1SAndreas Gohr 'header_count' => array(0,0,0,0,0,0), 188fce80b1SAndreas Gohr 'header_struct' => array(), 198fce80b1SAndreas Gohr 'linebreak' => 0, 208fce80b1SAndreas Gohr 'quote_nest' => 0, 218fce80b1SAndreas Gohr 'quote_count' => 0, 228fce80b1SAndreas Gohr 'fixme' => 0, 238fce80b1SAndreas Gohr 'hr' => 0, 248fce80b1SAndreas Gohr 25*4ea373cdSAndreas Gohr 'created' => 0, 26*4ea373cdSAndreas Gohr 'modified' => 0, 27*4ea373cdSAndreas Gohr 'changes' => 0, 28*4ea373cdSAndreas Gohr 'authors' => array(), 29*4ea373cdSAndreas Gohr 30*4ea373cdSAndreas Gohr 'chars' => 0, 31*4ea373cdSAndreas Gohr 'words' => 0, 32*4ea373cdSAndreas Gohr 338fce80b1SAndreas Gohr // calculated error scores 348fce80b1SAndreas Gohr 'err' => array( 358fce80b1SAndreas Gohr 'fixme' => 0, 368fce80b1SAndreas Gohr 'noh1' => 0, 378fce80b1SAndreas Gohr 'manyh1' => 0, 388fce80b1SAndreas Gohr 'headernest' => 0, 398fce80b1SAndreas Gohr 'manyhr' => 0, 408fce80b1SAndreas Gohr 'manybr' => 0, 418fce80b1SAndreas Gohr ), 428fce80b1SAndreas Gohr ); 438fce80b1SAndreas Gohr 448fce80b1SAndreas Gohr var $quotelevel = 0; 458fce80b1SAndreas Gohr 46*4ea373cdSAndreas Gohr function document_start() { 47*4ea373cdSAndreas Gohr global $ID; 48*4ea373cdSAndreas Gohr $meta = p_get_metadata($ID); 49*4ea373cdSAndreas Gohr 50*4ea373cdSAndreas Gohr // get some dates from meta data 51*4ea373cdSAndreas Gohr $this->doc['created'] = $meta['date']['created']; 52*4ea373cdSAndreas Gohr $this->doc['modified'] = $meta['date']['modified']; 53*4ea373cdSAndreas Gohr 54*4ea373cdSAndreas Gohr // get author info 55*4ea373cdSAndreas Gohr $revs = getRevisions($ID,0,0); 56*4ea373cdSAndreas Gohr array_push($revs,$meta['last_change']['date']); 57*4ea373cdSAndreas Gohr $this->doc['changes'] = count($revs); 58*4ea373cdSAndreas Gohr foreach($revs as $rev){ 59*4ea373cdSAndreas Gohr $info = getRevisionInfo($ID, $rev); 60*4ea373cdSAndreas Gohr if($info['user']){ 61*4ea373cdSAndreas Gohr $this->doc['authors'][$info['user']] += 1; 62*4ea373cdSAndreas Gohr }else{ 63*4ea373cdSAndreas Gohr $this->doc['authors']['*'] += 1; 64*4ea373cdSAndreas Gohr } 65*4ea373cdSAndreas Gohr } 66*4ea373cdSAndreas Gohr 67*4ea373cdSAndreas Gohr // work on raw text 68*4ea373cdSAndreas Gohr $text = rawWiki($ID); 69*4ea373cdSAndreas Gohr $this->doc['chars'] = utf8_strlen($text); 70*4ea373cdSAndreas Gohr $this->doc['words'] = count(preg_split('/[^\w\-_]/u',$text)); 71*4ea373cdSAndreas Gohr } 72*4ea373cdSAndreas Gohr 73*4ea373cdSAndreas Gohr 748fce80b1SAndreas Gohr /** 758fce80b1SAndreas Gohr * Here the score is calculated 768fce80b1SAndreas Gohr */ 778fce80b1SAndreas Gohr function document_end() { 788fce80b1SAndreas Gohr 798fce80b1SAndreas Gohr // 1 point for each FIXME 808fce80b1SAndreas Gohr $this->doc['err']['fixme'] += $this->doc['fixme']; 818fce80b1SAndreas Gohr 828fce80b1SAndreas Gohr // 5 points for missing H1 838fce80b1SAndreas Gohr if($this->doc['header_count'][1] == 0){ 848fce80b1SAndreas Gohr $this->doc['err']['noh1'] += 5; 858fce80b1SAndreas Gohr } 868fce80b1SAndreas Gohr // 1 point for each H1 too much 878fce80b1SAndreas Gohr if($this->doc['header_count'][1] > 1){ 888fce80b1SAndreas Gohr $this->doc['err']['manyh1'] += $this->doc['header'][1]; 898fce80b1SAndreas Gohr } 908fce80b1SAndreas Gohr 918fce80b1SAndreas Gohr // 1 point for each incorrectly nested headline 928fce80b1SAndreas Gohr $cnt = count($this->doc['header_struct']); 938fce80b1SAndreas Gohr for($i = 1; $i < $cnt; $i++){ 948fce80b1SAndreas Gohr if($this->doc['header_struct'][$i] - $this->doc['header_struct'][$i-1] > 1){ 958fce80b1SAndreas Gohr $this->doc['err']['headernest'] += 1; 968fce80b1SAndreas Gohr } 978fce80b1SAndreas Gohr } 988fce80b1SAndreas Gohr 998fce80b1SAndreas Gohr // 1/2 points for deeply nested quotations 1008fce80b1SAndreas Gohr if($this->doc['quote_nest'] > 2){ 1018fce80b1SAndreas Gohr $this->doc['err']['deepquote'] += $this->doc['quote_nest']/2; 1028fce80b1SAndreas Gohr } 1038fce80b1SAndreas Gohr 1048fce80b1SAndreas Gohr // FIXME points for many quotes? 1058fce80b1SAndreas Gohr 1068fce80b1SAndreas Gohr // 1/2 points for too many hr 1078fce80b1SAndreas Gohr if($this->doc['hr'] > 2){ 1088fce80b1SAndreas Gohr $this->doc['err']['manyhr'] = ($this->doc['hr'] - 2)/2; 1098fce80b1SAndreas Gohr } 1108fce80b1SAndreas Gohr 1118fce80b1SAndreas Gohr // 1 point for too many line breaks 1128fce80b1SAndreas Gohr if($this->doc['linebreak'] > 2){ 1138fce80b1SAndreas Gohr $this->doc['err']['manybr'] = $this->doc['linebreak'] - 2; 1148fce80b1SAndreas Gohr } 1158fce80b1SAndreas Gohr 116*4ea373cdSAndreas Gohr // 1 point for single author only 117*4ea373cdSAndreas Gohr if(count($this->doc['authors']) == 1){ 118*4ea373cdSAndreas Gohr $this->doc['err']['singleauthor'] = 1; 119*4ea373cdSAndreas Gohr } 120*4ea373cdSAndreas Gohr 121*4ea373cdSAndreas Gohr 1228fce80b1SAndreas Gohr //we're done here 1238fce80b1SAndreas Gohr $this->doc = serialize($this->doc); 1248fce80b1SAndreas Gohr } 1258fce80b1SAndreas Gohr 1268fce80b1SAndreas Gohr /** 1278fce80b1SAndreas Gohr * return some info 1288fce80b1SAndreas Gohr */ 1298fce80b1SAndreas Gohr function getInfo(){ 1308fce80b1SAndreas Gohr return confToHash(dirname(__FILE__).'/info.txt'); 1318fce80b1SAndreas Gohr } 1328fce80b1SAndreas Gohr 1338fce80b1SAndreas Gohr /** 1348fce80b1SAndreas Gohr * the format we produce 1358fce80b1SAndreas Gohr */ 1368fce80b1SAndreas Gohr function getFormat(){ 1378fce80b1SAndreas Gohr return 'qc'; 1388fce80b1SAndreas Gohr } 1398fce80b1SAndreas Gohr 1408fce80b1SAndreas Gohr 1418fce80b1SAndreas Gohr function header($text, $level, $pos){ 1428fce80b1SAndreas Gohr $this->doc['header_count'][$level]++; 1438fce80b1SAndreas Gohr $this->doc['header_struct'][] = $level; 1448fce80b1SAndreas Gohr } 1458fce80b1SAndreas Gohr 1468fce80b1SAndreas Gohr function smiley($smiley) { 1478fce80b1SAndreas Gohr if($smiley == 'FIXME') $this->doc['fixme']++; 1488fce80b1SAndreas Gohr } 1498fce80b1SAndreas Gohr 1508fce80b1SAndreas Gohr function linebreak() { 1518fce80b1SAndreas Gohr $this->doc['linebreak']++; 1528fce80b1SAndreas Gohr } 1538fce80b1SAndreas Gohr 1548fce80b1SAndreas Gohr function hr() { 1558fce80b1SAndreas Gohr $this->doc['hr']++; 1568fce80b1SAndreas Gohr } 1578fce80b1SAndreas Gohr 1588fce80b1SAndreas Gohr function quote_open() { 1598fce80b1SAndreas Gohr $this->doc['quote_count']++; 1608fce80b1SAndreas Gohr $this->quotelevel++; 1618fce80b1SAndreas Gohr $this->doc['quote_nest'] = max($this->quotelevel,$this->doc['quote_nest']); 1628fce80b1SAndreas Gohr } 1638fce80b1SAndreas Gohr 1648fce80b1SAndreas Gohr function quote_close() { 1658fce80b1SAndreas Gohr $this->quotelevel--; 1668fce80b1SAndreas Gohr } 1678fce80b1SAndreas Gohr 1688fce80b1SAndreas Gohr 1698fce80b1SAndreas Gohr} 1708fce80b1SAndreas Gohr 1718fce80b1SAndreas Gohr//Setup VIM: ex: et ts=4 enc=utf-8 : 172