r59782 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59781‎ | r59782 | r59783 >
Date:11:13, 7 December 2009
Author:thomasv
Status:ok (Comments)
Tags:
Comment:
follow-up to r56353 : do not use from tag hooks
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage.php
@@ -192,7 +192,7 @@
193193 }
194194
195195 //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 );
197197
198198 if( $links==null ) {
199199 list($pagenum, $links, $mode) = pr_pageNumber($pagenr,$params);
@@ -246,9 +246,7 @@
247247 return pr_parse_index_text( $text );
248248 }
249249
250 -
251250 function pr_parse_index_text( $text ){
252 - global $wgParser;
253251
254252 $page_namespace = pr_page_ns();
255253 //check if it is using pagelist
@@ -266,19 +264,6 @@
267265 preg_match_all( $tag_pattern, $text, $links, PREG_PATTERN_ORDER );
268266 }
269267
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;
283268
284269 //read attributes
285270 $attributes = array();
@@ -293,11 +278,31 @@
294279 $attributes[$var] = '';
295280 }
296281 }
297 - return array( $text_links, $links, $params, $attributes );
 282+ return array( $links, $params, $attributes );
298283
299284 }
300285
 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 ){
301290
 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+
302307 /**
303308 * Append javascript variables and code to the page.
304309 */
@@ -607,11 +612,11 @@
608613 * add the pagequality category.
609614 * todo : display whether page has been proofread by the user or by someone else
610615 */
611 -function pr_pageQuality( $input, $args ) {
612 - global $wgUser, $wgParser;
 616+function pr_pageQuality( $input, $args, &$parser ) {
 617+ global $wgUser;
613618
614619 $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() ) ) {
616621 return "";
617622 }
618623
@@ -621,7 +626,7 @@
622627 }
623628 $message = "<div id=\"pagequality\" width=100% class=quality$q>".wfMsgForContent( "proofreadpage_quality{$q}_message" )."</div>";
624629 $out = "__NOEDITSECTION__[[Category:".wfMsgForContent( "proofreadpage_quality{$q}_category" )."]]";
625 - return $wgParser->recursiveTagParse( $out . $message);
 630+ return $parser->recursiveTagParse( $out . $message);
626631 }
627632
628633
@@ -629,12 +634,12 @@
630635 * Parser hook for index pages
631636 * Display a list of coloured links to pages
632637 */
633 -function pr_renderPageList( $input, $args ) {
634 - global $wgUser, $wgParser;
 638+function pr_renderPageList( $input, $args, &$parser ) {
 639+ global $wgUser;
635640
636641 $page_namespace = pr_page_ns();
637642 $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 ) ) {
639644 return "";
640645 }
641646
@@ -687,7 +692,7 @@
688693 $return .= "[[".$title->getPrefixedText()."|$view]] ";
689694 }
690695 }
691 - $return = $wgParser->recursiveTagParse($return);
 696+ $return = $parser->recursiveTagParse($return);
692697 return $return;
693698 }
694699
@@ -698,8 +703,7 @@
699704 * Parser hook that includes a list of pages.
700705 * parameters : index, from, to, header
701706 */
702 -function pr_renderPages( $input, $args ) {
703 - global $wgParser;
 707+function pr_renderPages( $input, $args, &$parser ) {
704708
705709 $page_namespace = pr_page_ns();
706710 $index_namespace = pr_index_ns();
@@ -709,7 +713,7 @@
710714 $header = $args['header'];
711715
712716 # 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() ) ) {
714718 return "";
715719 }
716720 if( ! $index ) {
@@ -722,7 +726,8 @@
723727
724728 $out = '';
725729
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 );
727732
728733 if( $links==null ) {
729734 $imageTitle = Title::makeTitleSafe( NS_IMAGE, $index );
@@ -806,7 +811,7 @@
807812 $h_out .= "|value=$header";
808813 //find next and previous pages in list
809814 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() ) {
811816 $current = $text_links[0][$i];
812817 break;
813818 }
@@ -833,7 +838,7 @@
834839 $out = $h_out . $out;
835840 }
836841
837 - $out = $wgParser->recursiveTagParse($out);
 842+ $out = $parser->recursiveTagParse($out);
838843 return $out;
839844 }
840845
@@ -922,7 +927,7 @@
923928 //check that pages listed on an index are unique.
924929 if ( preg_match( "/^$index_namespace:(.*)$/", $title->getPrefixedText() ) ) {
925930 $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);
927932 if( $links!=null && count($links[1]) != count( array_unique($links[1]))) {
928933 $wgOut->showErrorPage( 'proofreadpage_indexdupe', 'proofreadpage_indexdupetext' );
929934 return false;
@@ -1194,7 +1199,7 @@
11951200
11961201 //read the list of pages
11971202 $pages = array();
1198 - list( $text_links, $links, $params, $attributes ) = pr_parse_index( $index_title );
 1203+ list( $links, $params, $attributes ) = pr_parse_index( $index_title );
11991204 if( $links==null ) {
12001205 $imageTitle = Title::makeTitleSafe( NS_IMAGE, $index_title->getText() );
12011206 if ( $imageTitle ) {

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r56353using Parser::replaceVariables() to read links from pages transcluded in the ...thomasv09:04, 15 September 2009

Comments

#Comment by ThomasV (talk | contribs)   11:16, 7 December 2009

ahem... sorry, my shell ate the variable name: the comment should read "do not use $wgParser from tag hooks"

#Comment by Tim Starling (talk | contribs)   00:27, 9 December 2009

It's lucky you didn't have to mention `rm -rf ~` in your commit message isn't it?

OK except for pr_parse_index_links() which is changed in later commits.

Status & tagging log