Index: trunk/extensions/ProofreadPage/ProofreadPage.php |
— | — | @@ -192,7 +192,7 @@ |
193 | 193 | } |
194 | 194 | |
195 | 195 | //if the index page exists, find current page number, previous and next pages |
196 | | - list( $text_links, $links, $params, $attributes ) = pr_parse_index($index_title); |
| 196 | + list( $links, $params, $attributes ) = pr_parse_index( $index_title ); |
197 | 197 | |
198 | 198 | if( $links==null ) { |
199 | 199 | list($pagenum, $links, $mode) = pr_pageNumber($pagenr,$params); |
— | — | @@ -246,9 +246,7 @@ |
247 | 247 | return pr_parse_index_text( $text ); |
248 | 248 | } |
249 | 249 | |
250 | | - |
251 | 250 | function pr_parse_index_text( $text ){ |
252 | | - global $wgParser; |
253 | 251 | |
254 | 252 | $page_namespace = pr_page_ns(); |
255 | 253 | //check if it is using pagelist |
— | — | @@ -266,19 +264,6 @@ |
267 | 265 | preg_match_all( $tag_pattern, $text, $links, PREG_PATTERN_ORDER ); |
268 | 266 | } |
269 | 267 | |
270 | | - //links in ns-0. Only if mOptions exist |
271 | | - if( $wgParser->mOptions ) { |
272 | | - # We use Parser::replaceVariables to expand templates |
273 | | - # However this method has a side effect on wgParser->mOutput->mTemplates, |
274 | | - # To avoid this, we instanciate a temporary ParserOutput object |
275 | | - $saved_output = $wgParser->mOutput; |
276 | | - $wgParser->mOutput = new ParserOutput; |
277 | | - $rtext = $wgParser->replaceVariables( $text ); |
278 | | - $wgParser->mOutput = $saved_output; |
279 | | - $text_links_pattern = "/\[\[([^:\|]*?)(\|(.*?)|)\]\]/i"; |
280 | | - preg_match_all( $text_links_pattern, $rtext, $text_links, PREG_PATTERN_ORDER ); |
281 | | - } |
282 | | - else $text_links = null; |
283 | 268 | |
284 | 269 | //read attributes |
285 | 270 | $attributes = array(); |
— | — | @@ -293,11 +278,31 @@ |
294 | 279 | $attributes[$var] = ''; |
295 | 280 | } |
296 | 281 | } |
297 | | - return array( $text_links, $links, $params, $attributes ); |
| 282 | + return array( $links, $params, $attributes ); |
298 | 283 | |
299 | 284 | } |
300 | 285 | |
| 286 | +/** |
| 287 | + * Return the ordered list of links to ns-0 from an index page |
| 288 | + */ |
| 289 | +function pr_parse_index_links( $index_title, $parser ){ |
301 | 290 | |
| 291 | + $rev = Revision::newFromTitle( $index_title ); |
| 292 | + $text = $rev->getText(); |
| 293 | + |
| 294 | + # We use Parser::replaceVariables to expand templates |
| 295 | + # However this method has a side effect on wgParser->mOutput->mTemplates, |
| 296 | + # To avoid this, we instanciate a temporary ParserOutput object |
| 297 | + $saved_output = $parser->mOutput; |
| 298 | + $parser->mOutput = new ParserOutput; |
| 299 | + $rtext = $parser->replaceVariables( $text ); |
| 300 | + $parser->mOutput = $saved_output; |
| 301 | + $text_links_pattern = "/\[\[([^:\|]*?)(\|(.*?)|)\]\]/i"; |
| 302 | + preg_match_all( $text_links_pattern, $rtext, $text_links, PREG_PATTERN_ORDER ); |
| 303 | + |
| 304 | + return $text_links; |
| 305 | +} |
| 306 | + |
302 | 307 | /** |
303 | 308 | * Append javascript variables and code to the page. |
304 | 309 | */ |
— | — | @@ -607,11 +612,11 @@ |
608 | 613 | * add the pagequality category. |
609 | 614 | * todo : display whether page has been proofread by the user or by someone else |
610 | 615 | */ |
611 | | -function pr_pageQuality( $input, $args ) { |
612 | | - global $wgUser, $wgParser; |
| 616 | +function pr_pageQuality( $input, $args, &$parser ) { |
| 617 | + global $wgUser; |
613 | 618 | |
614 | 619 | $page_namespace = pr_page_ns(); |
615 | | - if ( !preg_match( "/^$page_namespace:(.*?)(\/([0-9]*)|)$/", $wgParser->Title()->getPrefixedText() ) ) { |
| 620 | + if ( !preg_match( "/^$page_namespace:(.*?)(\/([0-9]*)|)$/", $parser->Title()->getPrefixedText() ) ) { |
616 | 621 | return ""; |
617 | 622 | } |
618 | 623 | |
— | — | @@ -621,7 +626,7 @@ |
622 | 627 | } |
623 | 628 | $message = "<div id=\"pagequality\" width=100% class=quality$q>".wfMsgForContent( "proofreadpage_quality{$q}_message" )."</div>"; |
624 | 629 | $out = "__NOEDITSECTION__[[Category:".wfMsgForContent( "proofreadpage_quality{$q}_category" )."]]"; |
625 | | - return $wgParser->recursiveTagParse( $out . $message); |
| 630 | + return $parser->recursiveTagParse( $out . $message); |
626 | 631 | } |
627 | 632 | |
628 | 633 | |
— | — | @@ -629,12 +634,12 @@ |
630 | 635 | * Parser hook for index pages |
631 | 636 | * Display a list of coloured links to pages |
632 | 637 | */ |
633 | | -function pr_renderPageList( $input, $args ) { |
634 | | - global $wgUser, $wgParser; |
| 638 | +function pr_renderPageList( $input, $args, &$parser ) { |
| 639 | + global $wgUser; |
635 | 640 | |
636 | 641 | $page_namespace = pr_page_ns(); |
637 | 642 | $index_namespace = pr_index_ns(); |
638 | | - if ( !preg_match( "/^$index_namespace:(.*?)(\/([0-9]*)|)$/", $wgParser->Title()->getPrefixedText(), $m ) ) { |
| 643 | + if ( !preg_match( "/^$index_namespace:(.*?)(\/([0-9]*)|)$/", $parser->Title()->getPrefixedText(), $m ) ) { |
639 | 644 | return ""; |
640 | 645 | } |
641 | 646 | |
— | — | @@ -687,7 +692,7 @@ |
688 | 693 | $return .= "[[".$title->getPrefixedText()."|$view]] "; |
689 | 694 | } |
690 | 695 | } |
691 | | - $return = $wgParser->recursiveTagParse($return); |
| 696 | + $return = $parser->recursiveTagParse($return); |
692 | 697 | return $return; |
693 | 698 | } |
694 | 699 | |
— | — | @@ -698,8 +703,7 @@ |
699 | 704 | * Parser hook that includes a list of pages. |
700 | 705 | * parameters : index, from, to, header |
701 | 706 | */ |
702 | | -function pr_renderPages( $input, $args ) { |
703 | | - global $wgParser; |
| 707 | +function pr_renderPages( $input, $args, &$parser ) { |
704 | 708 | |
705 | 709 | $page_namespace = pr_page_ns(); |
706 | 710 | $index_namespace = pr_index_ns(); |
— | — | @@ -709,7 +713,7 @@ |
710 | 714 | $header = $args['header']; |
711 | 715 | |
712 | 716 | # abort if the tag is on an index page |
713 | | - if ( preg_match( "/^$index_namespace:(.*?)(\/([0-9]*)|)$/", $wgParser->Title()->getPrefixedText() ) ) { |
| 717 | + if ( preg_match( "/^$index_namespace:(.*?)(\/([0-9]*)|)$/", $parser->Title()->getPrefixedText() ) ) { |
714 | 718 | return ""; |
715 | 719 | } |
716 | 720 | if( ! $index ) { |
— | — | @@ -722,7 +726,8 @@ |
723 | 727 | |
724 | 728 | $out = ''; |
725 | 729 | |
726 | | - list( $text_links, $links, $params, $attributes ) = pr_parse_index( $index_title ); |
| 730 | + list( $links, $params, $attributes ) = pr_parse_index( $index_title ); |
| 731 | + $text_links = pr_parse_index_links( $index_title, $parser ); |
727 | 732 | |
728 | 733 | if( $links==null ) { |
729 | 734 | $imageTitle = Title::makeTitleSafe( NS_IMAGE, $index ); |
— | — | @@ -806,7 +811,7 @@ |
807 | 812 | $h_out .= "|value=$header"; |
808 | 813 | //find next and previous pages in list |
809 | 814 | for( $i=1; $i < count( $text_links[1] ); $i++) { |
810 | | - if( $text_links[1][$i] == $wgParser->Title()->getPrefixedText() ) { |
| 815 | + if( $text_links[1][$i] == $parser->Title()->getPrefixedText() ) { |
811 | 816 | $current = $text_links[0][$i]; |
812 | 817 | break; |
813 | 818 | } |
— | — | @@ -833,7 +838,7 @@ |
834 | 839 | $out = $h_out . $out; |
835 | 840 | } |
836 | 841 | |
837 | | - $out = $wgParser->recursiveTagParse($out); |
| 842 | + $out = $parser->recursiveTagParse($out); |
838 | 843 | return $out; |
839 | 844 | } |
840 | 845 | |
— | — | @@ -922,7 +927,7 @@ |
923 | 928 | //check that pages listed on an index are unique. |
924 | 929 | if ( preg_match( "/^$index_namespace:(.*)$/", $title->getPrefixedText() ) ) { |
925 | 930 | $text = $editpage->textbox1; |
926 | | - list( $text_links, $links, $params, $attributes ) = pr_parse_index_text($text); |
| 931 | + list( $links, $params, $attributes ) = pr_parse_index_text($text); |
927 | 932 | if( $links!=null && count($links[1]) != count( array_unique($links[1]))) { |
928 | 933 | $wgOut->showErrorPage( 'proofreadpage_indexdupe', 'proofreadpage_indexdupetext' ); |
929 | 934 | return false; |
— | — | @@ -1194,7 +1199,7 @@ |
1195 | 1200 | |
1196 | 1201 | //read the list of pages |
1197 | 1202 | $pages = array(); |
1198 | | - list( $text_links, $links, $params, $attributes ) = pr_parse_index( $index_title ); |
| 1203 | + list( $links, $params, $attributes ) = pr_parse_index( $index_title ); |
1199 | 1204 | if( $links==null ) { |
1200 | 1205 | $imageTitle = Title::makeTitleSafe( NS_IMAGE, $index_title->getText() ); |
1201 | 1206 | if ( $imageTitle ) { |