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 254ea373cdSAndreas Gohr 'created' => 0, 264ea373cdSAndreas Gohr 'modified' => 0, 274ea373cdSAndreas Gohr 'changes' => 0, 284ea373cdSAndreas Gohr 'authors' => array(), 294ea373cdSAndreas Gohr 304ea373cdSAndreas Gohr 'chars' => 0, 314ea373cdSAndreas Gohr 'words' => 0, 324ea373cdSAndreas Gohr 33*9068e431SAndreas Gohr 'score' => 0, 34*9068e431SAndreas Gohr 358fce80b1SAndreas Gohr // calculated error scores 368fce80b1SAndreas Gohr 'err' => array( 378fce80b1SAndreas Gohr 'fixme' => 0, 388fce80b1SAndreas Gohr 'noh1' => 0, 398fce80b1SAndreas Gohr 'manyh1' => 0, 408fce80b1SAndreas Gohr 'headernest' => 0, 418fce80b1SAndreas Gohr 'manyhr' => 0, 428fce80b1SAndreas Gohr 'manybr' => 0, 438fce80b1SAndreas Gohr ), 448fce80b1SAndreas Gohr ); 458fce80b1SAndreas Gohr 468fce80b1SAndreas Gohr var $quotelevel = 0; 478fce80b1SAndreas Gohr 484ea373cdSAndreas Gohr function document_start() { 494ea373cdSAndreas Gohr global $ID; 504ea373cdSAndreas Gohr $meta = p_get_metadata($ID); 514ea373cdSAndreas Gohr 524ea373cdSAndreas Gohr // get some dates from meta data 534ea373cdSAndreas Gohr $this->doc['created'] = $meta['date']['created']; 544ea373cdSAndreas Gohr $this->doc['modified'] = $meta['date']['modified']; 554ea373cdSAndreas Gohr 564ea373cdSAndreas Gohr // get author info 574ea373cdSAndreas Gohr $revs = getRevisions($ID,0,0); 584ea373cdSAndreas Gohr array_push($revs,$meta['last_change']['date']); 594ea373cdSAndreas Gohr $this->doc['changes'] = count($revs); 604ea373cdSAndreas Gohr foreach($revs as $rev){ 614ea373cdSAndreas Gohr $info = getRevisionInfo($ID, $rev); 624ea373cdSAndreas Gohr if($info['user']){ 634ea373cdSAndreas Gohr $this->doc['authors'][$info['user']] += 1; 644ea373cdSAndreas Gohr }else{ 654ea373cdSAndreas Gohr $this->doc['authors']['*'] += 1; 664ea373cdSAndreas Gohr } 674ea373cdSAndreas Gohr } 684ea373cdSAndreas Gohr 694ea373cdSAndreas Gohr // work on raw text 704ea373cdSAndreas Gohr $text = rawWiki($ID); 714ea373cdSAndreas Gohr $this->doc['chars'] = utf8_strlen($text); 724ea373cdSAndreas Gohr $this->doc['words'] = count(preg_split('/[^\w\-_]/u',$text)); 734ea373cdSAndreas Gohr } 744ea373cdSAndreas Gohr 754ea373cdSAndreas Gohr 768fce80b1SAndreas Gohr /** 778fce80b1SAndreas Gohr * Here the score is calculated 788fce80b1SAndreas Gohr */ 798fce80b1SAndreas Gohr function document_end() { 808fce80b1SAndreas Gohr 818fce80b1SAndreas Gohr // 1 point for each FIXME 828fce80b1SAndreas Gohr $this->doc['err']['fixme'] += $this->doc['fixme']; 838fce80b1SAndreas Gohr 848fce80b1SAndreas Gohr // 5 points for missing H1 858fce80b1SAndreas Gohr if($this->doc['header_count'][1] == 0){ 868fce80b1SAndreas Gohr $this->doc['err']['noh1'] += 5; 878fce80b1SAndreas Gohr } 888fce80b1SAndreas Gohr // 1 point for each H1 too much 898fce80b1SAndreas Gohr if($this->doc['header_count'][1] > 1){ 908fce80b1SAndreas Gohr $this->doc['err']['manyh1'] += $this->doc['header'][1]; 918fce80b1SAndreas Gohr } 928fce80b1SAndreas Gohr 938fce80b1SAndreas Gohr // 1 point for each incorrectly nested headline 948fce80b1SAndreas Gohr $cnt = count($this->doc['header_struct']); 958fce80b1SAndreas Gohr for($i = 1; $i < $cnt; $i++){ 968fce80b1SAndreas Gohr if($this->doc['header_struct'][$i] - $this->doc['header_struct'][$i-1] > 1){ 978fce80b1SAndreas Gohr $this->doc['err']['headernest'] += 1; 988fce80b1SAndreas Gohr } 998fce80b1SAndreas Gohr } 1008fce80b1SAndreas Gohr 1018fce80b1SAndreas Gohr // 1/2 points for deeply nested quotations 1028fce80b1SAndreas Gohr if($this->doc['quote_nest'] > 2){ 1038fce80b1SAndreas Gohr $this->doc['err']['deepquote'] += $this->doc['quote_nest']/2; 1048fce80b1SAndreas Gohr } 1058fce80b1SAndreas Gohr 1068fce80b1SAndreas Gohr // FIXME points for many quotes? 1078fce80b1SAndreas Gohr 1088fce80b1SAndreas Gohr // 1/2 points for too many hr 1098fce80b1SAndreas Gohr if($this->doc['hr'] > 2){ 1108fce80b1SAndreas Gohr $this->doc['err']['manyhr'] = ($this->doc['hr'] - 2)/2; 1118fce80b1SAndreas Gohr } 1128fce80b1SAndreas Gohr 1138fce80b1SAndreas Gohr // 1 point for too many line breaks 1148fce80b1SAndreas Gohr if($this->doc['linebreak'] > 2){ 1158fce80b1SAndreas Gohr $this->doc['err']['manybr'] = $this->doc['linebreak'] - 2; 1168fce80b1SAndreas Gohr } 1178fce80b1SAndreas Gohr 1184ea373cdSAndreas Gohr // 1 point for single author only 1194ea373cdSAndreas Gohr if(count($this->doc['authors']) == 1){ 1204ea373cdSAndreas Gohr $this->doc['err']['singleauthor'] = 1; 1214ea373cdSAndreas Gohr } 1224ea373cdSAndreas Gohr 123*9068e431SAndreas Gohr // add up all scores 124*9068e431SAndreas Gohr foreach($this->doc['err'] as $err => $val) $this->doc['score'] += $val; 125*9068e431SAndreas Gohr 1264ea373cdSAndreas Gohr 1278fce80b1SAndreas Gohr //we're done here 1288fce80b1SAndreas Gohr $this->doc = serialize($this->doc); 1298fce80b1SAndreas Gohr } 1308fce80b1SAndreas Gohr 1318fce80b1SAndreas Gohr /** 1328fce80b1SAndreas Gohr * return some info 1338fce80b1SAndreas Gohr */ 1348fce80b1SAndreas Gohr function getInfo(){ 1358fce80b1SAndreas Gohr return confToHash(dirname(__FILE__).'/info.txt'); 1368fce80b1SAndreas Gohr } 1378fce80b1SAndreas Gohr 1388fce80b1SAndreas Gohr /** 1398fce80b1SAndreas Gohr * the format we produce 1408fce80b1SAndreas Gohr */ 1418fce80b1SAndreas Gohr function getFormat(){ 1428fce80b1SAndreas Gohr return 'qc'; 1438fce80b1SAndreas Gohr } 1448fce80b1SAndreas Gohr 1458fce80b1SAndreas Gohr 1468fce80b1SAndreas Gohr function header($text, $level, $pos){ 1478fce80b1SAndreas Gohr $this->doc['header_count'][$level]++; 1488fce80b1SAndreas Gohr $this->doc['header_struct'][] = $level; 1498fce80b1SAndreas Gohr } 1508fce80b1SAndreas Gohr 1518fce80b1SAndreas Gohr function smiley($smiley) { 1528fce80b1SAndreas Gohr if($smiley == 'FIXME') $this->doc['fixme']++; 1538fce80b1SAndreas Gohr } 1548fce80b1SAndreas Gohr 1558fce80b1SAndreas Gohr function linebreak() { 1568fce80b1SAndreas Gohr $this->doc['linebreak']++; 1578fce80b1SAndreas Gohr } 1588fce80b1SAndreas Gohr 1598fce80b1SAndreas Gohr function hr() { 1608fce80b1SAndreas Gohr $this->doc['hr']++; 1618fce80b1SAndreas Gohr } 1628fce80b1SAndreas Gohr 1638fce80b1SAndreas Gohr function quote_open() { 1648fce80b1SAndreas Gohr $this->doc['quote_count']++; 1658fce80b1SAndreas Gohr $this->quotelevel++; 1668fce80b1SAndreas Gohr $this->doc['quote_nest'] = max($this->quotelevel,$this->doc['quote_nest']); 1678fce80b1SAndreas Gohr } 1688fce80b1SAndreas Gohr 1698fce80b1SAndreas Gohr function quote_close() { 1708fce80b1SAndreas Gohr $this->quotelevel--; 1718fce80b1SAndreas Gohr } 1728fce80b1SAndreas Gohr 1738fce80b1SAndreas Gohr 1748fce80b1SAndreas Gohr} 1758fce80b1SAndreas Gohr 1768fce80b1SAndreas Gohr//Setup VIM: ex: et ts=4 enc=utf-8 : 177