r56353 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56352‎ | r56353 | r56354 >
Date:09:04, 15 September 2009
Author:thomasv
Status:resolved (Comments)
Tags:
Comment:
using Parser::replaceVariables() to read links from pages transcluded in the index page; minor fix for indexlink
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage.php
@@ -252,7 +252,8 @@
253253
254254
255255 function pr_parse_index_text( $text ){
256 -
 256+ global $wgParser;
 257+
257258 $page_namespace = pr_page_ns();
258259 //check if it is using pagelist
259260 preg_match_all( "/<pagelist([^<]*?)\/>/is", $text, $m, PREG_PATTERN_ORDER );
@@ -269,9 +270,13 @@
270271 preg_match_all( $tag_pattern, $text, $links, PREG_PATTERN_ORDER );
271272 }
272273
273 - //links in ns-0
274 - $text_links_pattern = "/\[\[([^:\|]*?)(\|(.*?)|)\]\]/i";
275 - preg_match_all( $text_links_pattern, $text, $text_links, PREG_PATTERN_ORDER );
 274+ //links in ns-0. Only if mOptions exist
 275+ if( $wgParser->mOptions ) {
 276+ $rtext = $wgParser->replaceVariables( $text );
 277+ $text_links_pattern = "/\[\[([^:\|]*?)(\|(.*?)|)\]\]/i";
 278+ preg_match_all( $text_links_pattern, $rtext, $text_links, PREG_PATTERN_ORDER );
 279+ }
 280+ else $text_links = null;
276281
277282 //read attributes
278283 $attributes = array();
@@ -788,6 +793,7 @@
789794
790795 if( $header ) {
791796 $h_out = '{{:MediaWiki:Proofreadpage_header_template';
 797+ $h_out .= "|value=$header";
792798 //find next and previous pages in list
793799 for( $i=1; $i < count( $text_links[1] ); $i++) {
794800 if( $text_links[1][$i] == $wgTitle->getPrefixedText() ) {
@@ -1326,9 +1332,11 @@
13271333 $row = $dbr->fetchObject( $res );
13281334 $title = $row->title;
13291335 $dbr->freeResult( $res );
1330 - }
1331 - $sk = $wgUser->getSkin();
1332 - $indexlink = $sk->makeKnownLink( "$index_namespace:$title", "[index]" );
 1336+ $sk = $wgUser->getSkin();
 1337+ $indexlink = $sk->makeKnownLink( "$index_namespace:$title", "[index]" );
 1338+ } else {
 1339+ $indexlink="";
 1340+ }
13331341 $output = wfMsgForContent( 'proofreadpage_quality_message', $n0*100/$n, $n1*100/$n, $n2*100/$n, $n3*100/$n, $n4*100/$n, $n, $indexlink );
13341342 $out->setSubtitle($output);
13351343 return true;

Follow-up revisions

RevisionCommit summaryAuthorDate
r59782follow-up to r56353 : do not use from tag hooksthomasv11:13, 7 December 2009

Comments

#Comment by Tim Starling (talk | contribs)   07:29, 1 December 2009

You should not be using $wgParser in this way. If you want to re-enter the parser from a tag hook, you need to use the parser object in the third parameter which is passed to the hook function. If I were you, I'd refactor the entire extension into a class, and store the passed Parser object as an object member variable.

Status & tagging log