r52744 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52743‎ | r52744 | r52745 >
Date:15:17, 3 July 2009
Author:thomasv
Status:deferred
Tags:
Comment:
replace the PageQuality template with a parser hook
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage.i18n.php (modified) (history)
  • /trunk/extensions/ProofreadPage/ProofreadPage.php (modified) (history)
  • /trunk/extensions/ProofreadPage/proofread.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage.i18n.php
@@ -39,6 +39,11 @@
4040 'proofreadpage_quality2_category' => 'Problematic',
4141 'proofreadpage_quality3_category' => 'Proofread',
4242 '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',
4348 'proofreadpage_index_listofpages' => 'List of pages',
4449 'proofreadpage_image_message' => 'Link to the index page',
4550 'proofreadpage_page_status' => 'Page status',
Index: trunk/extensions/ProofreadPage/ProofreadPage.php
@@ -36,7 +36,7 @@
3737 $wgDjvutxt = null;
3838
3939 # Bump the version number every time you change proofread.js
40 -$wgProofreadPageVersion = 22;
 40+$wgProofreadPageVersion = 23;
4141
4242 # Max width of zoomable image
4343 $wgProofreadPageMaxWidth = 2048;
@@ -68,6 +68,7 @@
6969 global $pr_page_namespace, $pr_index_namespace;
7070 $wgParser->setHook( "pagelist", "pr_renderPageList" );
7171 $wgParser->setHook( "pages", "pr_renderPages" );
 72+ $wgParser->setHook( "pagequality", "pr_pageQuality" );
7273 wfLoadExtensionMessages( 'ProofreadPage' );
7374 $pr_page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' );
7475 $pr_index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' );
@@ -575,6 +576,27 @@
576577
577578
578579 /*
 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+/*
579601 * Parser hook for index pages
580602 * Display a list of coloured links to pages
581603 */
@@ -729,11 +751,29 @@
730752 * Return -1 if the page cannot be parsed
731753 */
732754 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";
734759 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 );
736765 }
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 );
738778 }
739779
740780
@@ -747,7 +787,7 @@
748788
749789 $title = $editpage->mTitle;
750790
751 - //check that pages liste on an index are unique.
 791+ //check that pages listed on an index are unique.
752792 if ( preg_match( "/^$pr_index_namespace:(.*)$/", $title->getPrefixedText() ) ) {
753793 $text = $editpage->textbox1;
754794 list( $links, $params, $attributes ) = pr_parse_index_text($text);
@@ -763,18 +803,15 @@
764804 return true;
765805 }
766806
 807+ //replace deprecated template
767808 $text = $editpage->textbox1;
 809+ $text = preg_replace( "/\{\{PageQuality\|(0|1|2|3|4)\|(.*?)\}\}/is", "<pagequality level=\"\\1\" user=\"\\2\" />", $text );
 810+ $editpage->textbox1 = $text;
768811
769812 //parse the page
770 - list( $q , $username ) = pr_parse_page( $text );
 813+ list( $q , $username, $ptext ) = pr_parse_page( $text );
771814 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;
779816 return true;
780817 }
781818
@@ -782,7 +819,7 @@
783820 $rev = Revision::newFromTitle( $title );
784821 if( $rev ) {
785822 $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 );
787824 } else {
788825 if($q == 4) {
789826 $wgOut->showErrorPage( 'proofreadpage_notallowed', 'proofreadpage_notallowedtext' );
Index: trunk/extensions/ProofreadPage/proofread.js
@@ -114,8 +114,10 @@
115115 //find the PageQuality template
116116 //we do this separately from header detection,
117117 //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;
119119 var m4 = reg.exec(pageHeader);
 120+ var old_reg = /\{\{PageQuality\|(0|1|2|3|4)(\|(.*?|))\}\}/g;
 121+ var old_m4 = old_reg.exec(pageHeader);
120122 if( m4 ) {
121123 switch( m4[1] ) {
122124 case "0": self.proofreadpage_quality = 0; break;
@@ -125,15 +127,26 @@
126128 case "4": self.proofreadpage_quality = 4; break;
127129 default: self.proofreadpage_quality = 1;
128130 }
129 - self.proofreadpage_username = m4[3];
 131+ self.proofreadpage_username = m4[2];
130132 pageHeader = pageHeader.replace(reg,'');
131133 }
 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+ }
132146 else {
133147 self.proofreadpage_quality = 1;
134148 self.proofreadpage_username = "";
135149 }
136150
137 -
138151 //escape & character
139152 pageBody = pageBody.split("&").join("&amp;")
140153 pageHeader = pageHeader.split("&").join("&amp;")
@@ -769,7 +782,7 @@
770783 //}
771784 if(header){
772785 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>";
774787 var f = footer.value;
775788 if(f) f = "<noinclude>\n"+f+"</noinclude>";
776789 var ph = header.parentNode;

Status & tagging log