Index: trunk/extensions/QPoll/qp_user.php |
— | — | @@ -289,19 +289,19 @@ |
290 | 290 | * @param $input Text between <qpoll> and </qpoll> tags, in QPoll syntax. |
291 | 291 | * @param $argv An array containing any arguments passed to the extension |
292 | 292 | * @param &$parser The wikitext parser. |
293 | | - * |
| 293 | + * @param &$frame PPFrame object passed in MW 1.16+ |
294 | 294 | * @return An HTML poll. |
295 | 295 | */ |
296 | 296 | |
297 | 297 | /* @param $input Text between <qpoll> and </qpoll> tags, in QPoll syntax. */ |
298 | | - static function renderPoll( $input, $argv, $parser ) { |
| 298 | + static function renderPoll( $input, $argv, $parser, $frame = false ) { |
299 | 299 | if ( !self::$cache_control ) { |
300 | 300 | $parser->disableCache(); |
301 | 301 | } |
302 | 302 | if ( array_key_exists( 'address', $argv ) ) { |
303 | | - $qpoll = new qp_PollStats( $argv, $parser ); |
| 303 | + $qpoll = new qp_PollStats( $argv, $parser, $frame ); |
304 | 304 | } else { |
305 | | - $qpoll = new qp_Poll( $argv, $parser ); |
| 305 | + $qpoll = new qp_Poll( $argv, $parser, $frame ); |
306 | 306 | } |
307 | 307 | return $qpoll->parsePoll( $input ); |
308 | 308 | } |
— | — | @@ -323,6 +323,7 @@ |
324 | 324 | static $messagesLoaded = false; // check whether the extension localized messages are loaded |
325 | 325 | |
326 | 326 | var $parser; // parser for parsing tags content |
| 327 | + var $ppframe; // parser context passed in MW 1.16+; unused in MW 1.15 |
327 | 328 | var $username; |
328 | 329 | |
329 | 330 | # an ID of the poll on current page (used in declaration/voting mode) |
— | — | @@ -349,9 +350,10 @@ |
350 | 351 | * |
351 | 352 | * @public |
352 | 353 | */ |
353 | | - function __construct( $argv, &$parser ) { |
| 354 | + function __construct( $argv, &$parser, &$frame ) { |
354 | 355 | global $wgUser, $wgRequest, $wgLanguageCode; |
355 | 356 | $this->parser = &$parser; |
| 357 | + $this->ppframe = $frame; |
356 | 358 | $this->mRequest = &$wgRequest; |
357 | 359 | $this->mResponse = $wgRequest->response(); |
358 | 360 | # Determine which messages will be used, according to the language. |
— | — | @@ -545,8 +547,8 @@ |
546 | 548 | */ |
547 | 549 | class qp_PollStats extends qp_AbstractPoll { |
548 | 550 | |
549 | | - function __construct( $argv, &$parser ) { |
550 | | - parent::__construct( $argv, $parser ); |
| 551 | + function __construct( $argv, &$parser, &$frame ) { |
| 552 | + parent::__construct( $argv, $parser, $frame ); |
551 | 553 | $this->pollAddr = trim( $argv['address'] ); |
552 | 554 | # statistical mode is active, but qp_Setup::$global_showresults still can be false |
553 | 555 | if ( qp_Setup::$global_showresults == 0 ) { |
— | — | @@ -595,7 +597,7 @@ |
596 | 598 | unset( $unparsedAttributes[0] ); |
597 | 599 | # first pass: parse the headers |
598 | 600 | foreach ( $this->pollStore->Questions as &$qdata ) { |
599 | | - $question = new qp_QuestionStats( $this->parser, $qdata->type, $qdata->question_id, $this->showResults ); |
| 601 | + $question = new qp_QuestionStats( $this->parser, $this->ppframe, $qdata->type, $qdata->question_id, $this->showResults ); |
600 | 602 | if ( isset( $unparsedAttributes[$qdata->question_id] ) ) { |
601 | 603 | $attr_str = $unparsedAttributes[$qdata->question_id]; |
602 | 604 | } else { |
— | — | @@ -688,7 +690,7 @@ |
689 | 691 | 0=>array( '__tag'=>'div', '__end'=>"\n", 'class'=>'header', |
690 | 692 | 0=>array( '__tag'=>'span', 'class'=>'questionId', 0=>$question->mQuestionId ) |
691 | 693 | ), |
692 | | - 1=>$this->parser->recursiveTagParse( $question->mCommonQuestion . "\n" ) |
| 694 | + 1=>$this->parser->recursiveTagParse( $question->mCommonQuestion . "\n", $this->ppframe ) |
693 | 695 | ); |
694 | 696 | $tags[] = &$output_table; |
695 | 697 | return qp_Renderer::renderHTMLobject( $tags ); |
— | — | @@ -701,8 +703,8 @@ |
702 | 704 | */ |
703 | 705 | class qp_Poll extends qp_AbstractPoll { |
704 | 706 | |
705 | | - function __construct( $argv, &$parser ) { |
706 | | - parent::__construct( $argv, $parser ); |
| 707 | + function __construct( $argv, &$parser, &$frame ) { |
| 708 | + parent::__construct( $argv, $parser, $frame ); |
707 | 709 | # order_id is used to sort out polls on the Special:PollResults statistics page |
708 | 710 | $this->mOrderId = self::$sOrderId; |
709 | 711 | # Determine if this poll is being corrected or not, according to the pollId |
— | — | @@ -999,7 +1001,7 @@ |
1000 | 1002 | # $body : the text of question body (starting with body header which defines categories and spans, followed by proposal list) |
1001 | 1003 | # @return question object with parsed headers and no data loaded |
1002 | 1004 | function parseQuestionHeader( $header, $body ) { |
1003 | | - $question = new qp_Question( $this->parser, $this->mBeingCorrected, ++$this->mQuestionId, $this->showResults ); |
| 1005 | + $question = new qp_Question( $this->parser, $this->ppframe, $this->mBeingCorrected, ++$this->mQuestionId, $this->showResults ); |
1004 | 1006 | # parse questions common question and XML attributes |
1005 | 1007 | $question->parseMainHeader( $header ); |
1006 | 1008 | if ( $question->getState() != 'error' ) { |
— | — | @@ -1067,7 +1069,7 @@ |
1068 | 1070 | 0=>array( '__tag'=>'div', '__end'=>"\n", 'class'=>'header', |
1069 | 1071 | 0=>array( '__tag'=>'span', 'class'=>'questionId', 0=>$question->mQuestionId ) |
1070 | 1072 | ), |
1071 | | - 1=>$this->parser->recursiveTagParse( $question->mCommonQuestion . "\n" ) |
| 1073 | + 1=>$this->parser->recursiveTagParse( $question->mCommonQuestion . "\n", $this->ppframe ) |
1072 | 1074 | ); |
1073 | 1075 | $tags[] = &$output_table; |
1074 | 1076 | return qp_Renderer::renderHTMLobject( $tags ); |
Index: trunk/extensions/QPoll/qp_question.php |
— | — | @@ -7,6 +7,7 @@ |
8 | 8 | abstract class qp_AbstractQuestion { |
9 | 9 | |
10 | 10 | var $parser; // an instance of parser from parser tag hook |
| 11 | + var $ppframe; // an instance of PPFrame (parser context) |
11 | 12 | var $mState = ''; // current state of question parsing (no error) |
12 | 13 | # error message which occured during the question header parsing that will be output later at rendering stage |
13 | 14 | var $headerErrorMessage = 'Unknown error'; |
— | — | @@ -39,12 +40,14 @@ |
40 | 41 | # Constructor |
41 | 42 | # @public |
42 | 43 | # @param $parser an instance of parser from parser tag hook |
| 44 | + # @param $frame an instance of PPFrame (parser context) |
43 | 45 | # @param $beingCorrected boolean |
44 | 46 | # @param $questionId the identifier of the question used to gernerate input names |
45 | 47 | # @param $showResults poll's showResults (may be overriden in the question) |
46 | | - function __construct( &$parser, $beingCorrected, $questionId, $showResults ) { |
| 48 | + function __construct( &$parser, &$frame, $beingCorrected, $questionId, $showResults ) { |
47 | 49 | global $wgRequest; |
48 | 50 | $this->parser = &$parser; |
| 51 | + $this->ppframe = &$frame; |
49 | 52 | $this->mRequest = &$wgRequest; |
50 | 53 | $this->mQuestionId = $questionId; |
51 | 54 | $this->mBeingCorrected = $beingCorrected; |
— | — | @@ -214,11 +217,12 @@ |
215 | 218 | # Constructor |
216 | 219 | # @public |
217 | 220 | # @param $parser an instance of parser from parser tag hook |
| 221 | + # @param $frame an instance of PPFrame (parser context) |
218 | 222 | # @param $type type of question (taken from DB) |
219 | 223 | # @param $questionId the identifier of the question used to gernerate input names |
220 | 224 | # @param $showResults poll's showResults (may be overriden in the question) |
221 | | - function __construct( &$parser, $type, $questionId, $showResults ) { |
222 | | - parent::__construct( $parser, false, $questionId, $showResults ); |
| 225 | + function __construct( &$parser, &$frame, $type, $questionId, $showResults ) { |
| 226 | + parent::__construct( $parser, $frame, false, $questionId, $showResults ); |
223 | 227 | $this->mType = $type; |
224 | 228 | } |
225 | 229 | |
— | — | @@ -259,7 +263,7 @@ |
260 | 264 | $row[] = array( '__tag'=>'td', 0=>"", 'style'=>'border:none;', '__end'=>"\n" ); |
261 | 265 | } |
262 | 266 | foreach( $this->mCategories as &$cat ) { |
263 | | - $row[] = $this->parser->recursiveTagParse( $cat['name'] ); |
| 267 | + $row[] = $this->parser->recursiveTagParse( $cat['name'], $this->ppframe ); |
264 | 268 | } |
265 | 269 | if ( !$this->proposalsFirst ) { |
266 | 270 | // add empty <th> at the end of row to "compensate" proposal text |
— | — | @@ -277,7 +281,7 @@ |
278 | 282 | $row[] = array( '__tag'=>'td', 0=>"", 'style'=>'border:none;', '__end'=>"\n" ); |
279 | 283 | } |
280 | 284 | foreach( $this->mCategorySpans as &$span ) { |
281 | | - $row[] = array( "count"=>$span['count'], 0=>$this->parser->recursiveTagParse( $span['name'] ) ); |
| 285 | + $row[] = array( "count"=>$span['count'], 0=>$this->parser->recursiveTagParse( $span['name'], $this->ppframe ) ); |
282 | 286 | } |
283 | 287 | if ( !$this->proposalsFirst ) { |
284 | 288 | // add empty <th> at the end of row to "compensate" proposal text |
— | — | @@ -328,7 +332,7 @@ |
329 | 333 | $row[ $catId ][ 0 ] = ''; |
330 | 334 | } |
331 | 335 | } |
332 | | - $text = array( '__tag'=>'td', '__end'=>"\n", 'class'=>'proposaltext', 'style'=>$this->proposalTextStyle, 0=>$this->parser->recursiveTagParse( $text ) ); |
| 336 | + $text = array( '__tag'=>'td', '__end'=>"\n", 'class'=>'proposaltext', 'style'=>$this->proposalTextStyle, 0=>$this->parser->recursiveTagParse( $text, $this->ppframe ) ); |
333 | 337 | if ( $this->proposalsFirst ) { |
334 | 338 | # first element is proposaltext |
335 | 339 | array_unshift( $row, $text ); |
— | — | @@ -711,7 +715,7 @@ |
712 | 716 | $rawClass = 'proposalerror'; |
713 | 717 | } |
714 | 718 | if ( $text !== null ) { |
715 | | - $text = array( '__tag'=>'td', '__end'=>"\n", 'class'=>'proposaltext', 'style'=>$this->proposalTextStyle, 0=>$this->parser->recursiveTagParse( $text ) ); |
| 719 | + $text = array( '__tag'=>'td', '__end'=>"\n", 'class'=>'proposaltext', 'style'=>$this->proposalTextStyle, 0=>$this->parser->recursiveTagParse( $text, $this->ppframe ) ); |
716 | 720 | if ( $this->proposalsFirst ) { |
717 | 721 | # first element is proposaltext |
718 | 722 | array_unshift( $row, $text ); |
— | — | @@ -858,7 +862,7 @@ |
859 | 863 | throw new MWException( $e->getMessage() ); |
860 | 864 | } |
861 | 865 | } |
862 | | - $text = array( '__tag'=>'td', '__end'=>"\n", 'class'=>'proposaltext', 'style'=>$this->proposalTextStyle, 0=>$this->parser->recursiveTagParse( $text ) ); |
| 866 | + $text = array( '__tag'=>'td', '__end'=>"\n", 'class'=>'proposaltext', 'style'=>$this->proposalTextStyle, 0=>$this->parser->recursiveTagParse( $text, $this->ppframe ) ); |
863 | 867 | if ( $this->proposalsFirst ) { |
864 | 868 | # first element is proposaltext |
865 | 869 | array_unshift( $row, $text ); |
— | — | @@ -934,7 +938,7 @@ |
935 | 939 | $category = $this->bodyErrorMessage( wfMsg( 'qp_error_category_name_empty' ), 'error' ); |
936 | 940 | } |
937 | 941 | $this->mCategories[ $catkey ]["name"] = $category; |
938 | | - $row[] = $this->parser->recursiveTagParse( $category ); |
| 942 | + $row[] = $this->parser->recursiveTagParse( $category, $this->ppframe ); |
939 | 943 | } |
940 | 944 | |
941 | 945 | # cut unused categories rows which are presented in DB but were removed from article |
— | — | @@ -1016,7 +1020,9 @@ |
1017 | 1021 | } |
1018 | 1022 | # fill undefined spans with the last span value |
1019 | 1023 | $SpanCategDelta = count( $this->mCategories ) - count( $spans[0] ); |
1020 | | - $lastDefinedSpanKey = array_pop( array_diff( array_keys( $spans[1] ), array_keys( $spans[1], "", true ) ) ); |
| 1024 | + $diff = array_diff( array_keys( $spans[1] ), array_keys( $spans[1], "", true ) ); |
| 1025 | + $lastDefinedSpanKey = array_pop( $diff ); |
| 1026 | + unset( $diff ); |
1021 | 1027 | if ($lastDefinedSpanKey !== null) { |
1022 | 1028 | if ( $SpanCategDelta > 0 ) { |
1023 | 1029 | # increase the length of last defined span value to match total lenth of categories |
— | — | @@ -1049,7 +1055,7 @@ |
1050 | 1056 | if ( $spanCategory=="" ) { |
1051 | 1057 | $colspan++; |
1052 | 1058 | } else { |
1053 | | - $row[] = array( "count"=>$colspan + $colspanBase, 0=>$this->parser->recursiveTagParse( $spanCategory ) ); |
| 1059 | + $row[] = array( "count"=>$colspan + $colspanBase, 0=>$this->parser->recursiveTagParse( $spanCategory, $this->ppframe ) ); |
1054 | 1060 | if ( $spanType == "|") { // "!" is a comment header, not a real category span |
1055 | 1061 | $this->mCategorySpans[ $categorySpanId ]['name'] = $spanCategory; |
1056 | 1062 | $this->mCategorySpans[ $categorySpanId ]['count'] = $colspan; |