Index: trunk/extensions/ProofreadPage/ProofreadPage.i18n.php |
— | — | @@ -39,6 +39,11 @@ |
40 | 40 | 'proofreadpage_quality2_category' => 'Problematic', |
41 | 41 | 'proofreadpage_quality3_category' => 'Proofread', |
42 | 42 | 'proofreadpage_quality4_category' => 'Validated', |
| 43 | + 'proofreadpage_quality0_message' => 'This page does not need to be proofread', |
| 44 | + 'proofreadpage_quality1_message' => 'This page has not been proofread', |
| 45 | + 'proofreadpage_quality2_message' => 'There was a problem when proofreading this page', |
| 46 | + 'proofreadpage_quality3_message' => 'This page has been proofread', |
| 47 | + 'proofreadpage_quality4_message' => 'This page has been validated', |
43 | 48 | 'proofreadpage_index_listofpages' => 'List of pages', |
44 | 49 | 'proofreadpage_image_message' => 'Link to the index page', |
45 | 50 | 'proofreadpage_page_status' => 'Page status', |
Index: trunk/extensions/ProofreadPage/ProofreadPage.php |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | $wgDjvutxt = null; |
38 | 38 | |
39 | 39 | # Bump the version number every time you change proofread.js |
40 | | -$wgProofreadPageVersion = 22; |
| 40 | +$wgProofreadPageVersion = 23; |
41 | 41 | |
42 | 42 | # Max width of zoomable image |
43 | 43 | $wgProofreadPageMaxWidth = 2048; |
— | — | @@ -68,6 +68,7 @@ |
69 | 69 | global $pr_page_namespace, $pr_index_namespace; |
70 | 70 | $wgParser->setHook( "pagelist", "pr_renderPageList" ); |
71 | 71 | $wgParser->setHook( "pages", "pr_renderPages" ); |
| 72 | + $wgParser->setHook( "pagequality", "pr_pageQuality" ); |
72 | 73 | wfLoadExtensionMessages( 'ProofreadPage' ); |
73 | 74 | $pr_page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' ); |
74 | 75 | $pr_index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' ); |
— | — | @@ -575,6 +576,27 @@ |
576 | 577 | |
577 | 578 | |
578 | 579 | /* |
| 580 | + * add the pagequality category. |
| 581 | + * todo : display whether page has been proofread by the user or by someone else |
| 582 | + */ |
| 583 | +function pr_pageQuality( $input, $args ) { |
| 584 | + global $pr_page_namespace, $pr_index_namespace; |
| 585 | + global $wgUser, $wgTitle, $wgParser; |
| 586 | + |
| 587 | + if ( !preg_match( "/^$pr_page_namespace:(.*?)(\/([0-9]*)|)$/", $wgTitle->getPrefixedText() ) ) { |
| 588 | + return ""; |
| 589 | + } |
| 590 | + $q = $args['level']; |
| 591 | + if( ! in_array( $q, array('0','1','2','3','4') ) ) { |
| 592 | + return ""; |
| 593 | + } |
| 594 | + $message = "<div id=\"pagequality\" width=100% class=quality$q>".wfMsgForContent( "proofreadpage_quality{$q}_message" )."</div>"; |
| 595 | + $out = "__NOEDITSECTION__[[Category:".wfMsgForContent( "proofreadpage_quality{$q}_category" )."]]"; |
| 596 | + return $wgParser->recursiveTagParse( $out . $message); |
| 597 | +} |
| 598 | + |
| 599 | + |
| 600 | +/* |
579 | 601 | * Parser hook for index pages |
580 | 602 | * Display a list of coloured links to pages |
581 | 603 | */ |
— | — | @@ -729,11 +751,29 @@ |
730 | 752 | * Return -1 if the page cannot be parsed |
731 | 753 | */ |
732 | 754 | function pr_parse_page( $text ) { |
733 | | - $page_regexp = "/^<noinclude>\{\{PageQuality\|(0|1|2|3|4)\|(.*?)\}\}(.*?)<\/noinclude>(.*?)<noinclude>(.*?)<\/noinclude>$/s"; |
| 755 | + global $wgTitle, $wgUser; |
| 756 | + $username = $wgUser->getName(); |
| 757 | + |
| 758 | + $page_regexp = "/^<noinclude>(.*?)<\/noinclude>(.*?)<noinclude>(.*?)<\/noinclude>$/s"; |
734 | 759 | if( !preg_match( $page_regexp, $text, $m ) ) { |
735 | | - return array( -1, null ); |
| 760 | + pr_load_index( $wgTitle ); |
| 761 | + list( $index_url, $prev_url, $next_url, $header, $footer ) = pr_navigation( $wgTitle ); |
| 762 | + $new_text = "<noinclude><pagequality level=\"1\" user=\"$username\" />" |
| 763 | + ."$header\n\n\n</noinclude>$text<noinclude>\n$footer</noinclude>"; |
| 764 | + return array( -1, null, $new_text ); |
736 | 765 | } |
737 | | - return array( intval($m[1]), $m[2] ); |
| 766 | + |
| 767 | + $header_regexp = "/^<pagequality level=\"(0|1|2|3|4)\" user=\"(.*?)\" \/>/"; |
| 768 | + $header = $m[1]; |
| 769 | + $body = $m[2]; |
| 770 | + $footer = $m[3]; |
| 771 | + if( !preg_match( $header_regexp, $header, $m2 ) ) { |
| 772 | + $new_text = "<noinclude><pagequality level=\"1\" user=\"$username\" />" |
| 773 | + ."$header\n\n\n</noinclude>$body<noinclude>\n$footer</noinclude>"; |
| 774 | + return array( -1, null, $new_text ); |
| 775 | + } |
| 776 | + |
| 777 | + return array( intval($m2[1]), $m2[2], null ); |
738 | 778 | } |
739 | 779 | |
740 | 780 | |
— | — | @@ -747,7 +787,7 @@ |
748 | 788 | |
749 | 789 | $title = $editpage->mTitle; |
750 | 790 | |
751 | | - //check that pages liste on an index are unique. |
| 791 | + //check that pages listed on an index are unique. |
752 | 792 | if ( preg_match( "/^$pr_index_namespace:(.*)$/", $title->getPrefixedText() ) ) { |
753 | 793 | $text = $editpage->textbox1; |
754 | 794 | list( $links, $params, $attributes ) = pr_parse_index_text($text); |
— | — | @@ -763,18 +803,15 @@ |
764 | 804 | return true; |
765 | 805 | } |
766 | 806 | |
| 807 | + //replace deprecated template |
767 | 808 | $text = $editpage->textbox1; |
| 809 | + $text = preg_replace( "/\{\{PageQuality\|(0|1|2|3|4)\|(.*?)\}\}/is", "<pagequality level=\"\\1\" user=\"\\2\" />", $text ); |
| 810 | + $editpage->textbox1 = $text; |
768 | 811 | |
769 | 812 | //parse the page |
770 | | - list( $q , $username ) = pr_parse_page( $text ); |
| 813 | + list( $q , $username, $ptext ) = pr_parse_page( $text ); |
771 | 814 | if( $q == -1 ) { |
772 | | - //convert to page format |
773 | | - $username = $wgUser->getName(); |
774 | | - pr_load_index( $title ); |
775 | | - list( $index_url, $prev_url, $next_url, $header, $footer ) = pr_navigation( $title ); |
776 | | - $editpage->textbox1 = |
777 | | - "<noinclude>{{PageQuality|1|$username}}$header\n\n\n</noinclude>" |
778 | | - .$text."<noinclude>\n$footer</noinclude>"; |
| 815 | + $editpage->textbox1 = $ptext; |
779 | 816 | return true; |
780 | 817 | } |
781 | 818 | |
— | — | @@ -782,7 +819,7 @@ |
783 | 820 | $rev = Revision::newFromTitle( $title ); |
784 | 821 | if( $rev ) { |
785 | 822 | $old_text = $rev->getText(); |
786 | | - list( $old_q , $old_username ) = pr_parse_page( $old_text ); |
| 823 | + list( $old_q , $old_username, $old_ptext ) = pr_parse_page( $old_text ); |
787 | 824 | } else { |
788 | 825 | if($q == 4) { |
789 | 826 | $wgOut->showErrorPage( 'proofreadpage_notallowed', 'proofreadpage_notallowedtext' ); |
Index: trunk/extensions/ProofreadPage/proofread.js |
— | — | @@ -114,8 +114,10 @@ |
115 | 115 | //find the PageQuality template |
116 | 116 | //we do this separately from header detection, |
117 | 117 | //because the template might not be in the header |
118 | | - var reg = /\{\{PageQuality\|(0|1|2|3|4)(\|(.*?|))\}\}/g; |
| 118 | + var reg = /<pagequality level=\"(0|1|2|3|4)\" user=\"(.*?)\" \/>/g; |
119 | 119 | var m4 = reg.exec(pageHeader); |
| 120 | + var old_reg = /\{\{PageQuality\|(0|1|2|3|4)(\|(.*?|))\}\}/g; |
| 121 | + var old_m4 = old_reg.exec(pageHeader); |
120 | 122 | if( m4 ) { |
121 | 123 | switch( m4[1] ) { |
122 | 124 | case "0": self.proofreadpage_quality = 0; break; |
— | — | @@ -125,15 +127,26 @@ |
126 | 128 | case "4": self.proofreadpage_quality = 4; break; |
127 | 129 | default: self.proofreadpage_quality = 1; |
128 | 130 | } |
129 | | - self.proofreadpage_username = m4[3]; |
| 131 | + self.proofreadpage_username = m4[2]; |
130 | 132 | pageHeader = pageHeader.replace(reg,''); |
131 | 133 | } |
| 134 | + else if (old_m4 ) { |
| 135 | + switch( old_m4[1] ) { |
| 136 | + case "0": self.proofreadpage_quality = 0; break; |
| 137 | + case "1": self.proofreadpage_quality = 1; break; |
| 138 | + case "2": self.proofreadpage_quality = 2; break; |
| 139 | + case "3": self.proofreadpage_quality = 3; break; |
| 140 | + case "4": self.proofreadpage_quality = 4; break; |
| 141 | + default: self.proofreadpage_quality = 1; |
| 142 | + } |
| 143 | + self.proofreadpage_username = old_m4[3]; |
| 144 | + pageHeader = pageHeader.replace(old_reg,''); |
| 145 | + } |
132 | 146 | else { |
133 | 147 | self.proofreadpage_quality = 1; |
134 | 148 | self.proofreadpage_username = ""; |
135 | 149 | } |
136 | 150 | |
137 | | - |
138 | 151 | //escape & character |
139 | 152 | pageBody = pageBody.split("&").join("&") |
140 | 153 | pageHeader = pageHeader.split("&").join("&") |
— | — | @@ -769,7 +782,7 @@ |
770 | 783 | //} |
771 | 784 | if(header){ |
772 | 785 | var h = header.value.replace(/(\s*(\r?\n|\r))+$/, ''); |
773 | | - if(h) h = "<noinclude>{{PageQuality|"+self.proofreadpage_quality+"|"+self.proofreadpage_username+"}}"+h+"\n\n\n</noinclude>"; |
| 786 | + if(h) h = "<noinclude><pagequality level=\""+self.proofreadpage_quality+"\" user=\""+self.proofreadpage_username+"\" />"+h+"\n\n\n</noinclude>"; |
774 | 787 | var f = footer.value; |
775 | 788 | if(f) f = "<noinclude>\n"+f+"</noinclude>"; |
776 | 789 | var ph = header.parentNode; |