r78545 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78544‎ | r78545 | r78546 >
Date:19:50, 17 December 2010
Author:questpc
Status:deferred
Tags:
Comment:
Use MW 1.16+ setHook() and recursiveTagParse() PPFrame support for extension's tag
Modified paths:
  • /trunk/extensions/QPoll/qp_question.php (modified) (history)
  • /trunk/extensions/QPoll/qp_user.php (modified) (history)

Diff [purge]

Index: trunk/extensions/QPoll/qp_user.php
@@ -289,19 +289,19 @@
290290 * @param $input Text between <qpoll> and </qpoll> tags, in QPoll syntax.
291291 * @param $argv An array containing any arguments passed to the extension
292292 * @param &$parser The wikitext parser.
293 - *
 293+ * @param &$frame PPFrame object passed in MW 1.16+
294294 * @return An HTML poll.
295295 */
296296
297297 /* @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 ) {
299299 if ( !self::$cache_control ) {
300300 $parser->disableCache();
301301 }
302302 if ( array_key_exists( 'address', $argv ) ) {
303 - $qpoll = new qp_PollStats( $argv, $parser );
 303+ $qpoll = new qp_PollStats( $argv, $parser, $frame );
304304 } else {
305 - $qpoll = new qp_Poll( $argv, $parser );
 305+ $qpoll = new qp_Poll( $argv, $parser, $frame );
306306 }
307307 return $qpoll->parsePoll( $input );
308308 }
@@ -323,6 +323,7 @@
324324 static $messagesLoaded = false; // check whether the extension localized messages are loaded
325325
326326 var $parser; // parser for parsing tags content
 327+ var $ppframe; // parser context passed in MW 1.16+; unused in MW 1.15
327328 var $username;
328329
329330 # an ID of the poll on current page (used in declaration/voting mode)
@@ -349,9 +350,10 @@
350351 *
351352 * @public
352353 */
353 - function __construct( $argv, &$parser ) {
 354+ function __construct( $argv, &$parser, &$frame ) {
354355 global $wgUser, $wgRequest, $wgLanguageCode;
355356 $this->parser = &$parser;
 357+ $this->ppframe = $frame;
356358 $this->mRequest = &$wgRequest;
357359 $this->mResponse = $wgRequest->response();
358360 # Determine which messages will be used, according to the language.
@@ -545,8 +547,8 @@
546548 */
547549 class qp_PollStats extends qp_AbstractPoll {
548550
549 - function __construct( $argv, &$parser ) {
550 - parent::__construct( $argv, $parser );
 551+ function __construct( $argv, &$parser, &$frame ) {
 552+ parent::__construct( $argv, $parser, $frame );
551553 $this->pollAddr = trim( $argv['address'] );
552554 # statistical mode is active, but qp_Setup::$global_showresults still can be false
553555 if ( qp_Setup::$global_showresults == 0 ) {
@@ -595,7 +597,7 @@
596598 unset( $unparsedAttributes[0] );
597599 # first pass: parse the headers
598600 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 );
600602 if ( isset( $unparsedAttributes[$qdata->question_id] ) ) {
601603 $attr_str = $unparsedAttributes[$qdata->question_id];
602604 } else {
@@ -688,7 +690,7 @@
689691 0=>array( '__tag'=>'div', '__end'=>"\n", 'class'=>'header',
690692 0=>array( '__tag'=>'span', 'class'=>'questionId', 0=>$question->mQuestionId )
691693 ),
692 - 1=>$this->parser->recursiveTagParse( $question->mCommonQuestion . "\n" )
 694+ 1=>$this->parser->recursiveTagParse( $question->mCommonQuestion . "\n", $this->ppframe )
693695 );
694696 $tags[] = &$output_table;
695697 return qp_Renderer::renderHTMLobject( $tags );
@@ -701,8 +703,8 @@
702704 */
703705 class qp_Poll extends qp_AbstractPoll {
704706
705 - function __construct( $argv, &$parser ) {
706 - parent::__construct( $argv, $parser );
 707+ function __construct( $argv, &$parser, &$frame ) {
 708+ parent::__construct( $argv, $parser, $frame );
707709 # order_id is used to sort out polls on the Special:PollResults statistics page
708710 $this->mOrderId = self::$sOrderId;
709711 # Determine if this poll is being corrected or not, according to the pollId
@@ -999,7 +1001,7 @@
10001002 # $body : the text of question body (starting with body header which defines categories and spans, followed by proposal list)
10011003 # @return question object with parsed headers and no data loaded
10021004 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 );
10041006 # parse questions common question and XML attributes
10051007 $question->parseMainHeader( $header );
10061008 if ( $question->getState() != 'error' ) {
@@ -1067,7 +1069,7 @@
10681070 0=>array( '__tag'=>'div', '__end'=>"\n", 'class'=>'header',
10691071 0=>array( '__tag'=>'span', 'class'=>'questionId', 0=>$question->mQuestionId )
10701072 ),
1071 - 1=>$this->parser->recursiveTagParse( $question->mCommonQuestion . "\n" )
 1073+ 1=>$this->parser->recursiveTagParse( $question->mCommonQuestion . "\n", $this->ppframe )
10721074 );
10731075 $tags[] = &$output_table;
10741076 return qp_Renderer::renderHTMLobject( $tags );
Index: trunk/extensions/QPoll/qp_question.php
@@ -7,6 +7,7 @@
88 abstract class qp_AbstractQuestion {
99
1010 var $parser; // an instance of parser from parser tag hook
 11+ var $ppframe; // an instance of PPFrame (parser context)
1112 var $mState = ''; // current state of question parsing (no error)
1213 # error message which occured during the question header parsing that will be output later at rendering stage
1314 var $headerErrorMessage = 'Unknown error';
@@ -39,12 +40,14 @@
4041 # Constructor
4142 # @public
4243 # @param $parser an instance of parser from parser tag hook
 44+ # @param $frame an instance of PPFrame (parser context)
4345 # @param $beingCorrected boolean
4446 # @param $questionId the identifier of the question used to gernerate input names
4547 # @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 ) {
4749 global $wgRequest;
4850 $this->parser = &$parser;
 51+ $this->ppframe = &$frame;
4952 $this->mRequest = &$wgRequest;
5053 $this->mQuestionId = $questionId;
5154 $this->mBeingCorrected = $beingCorrected;
@@ -214,11 +217,12 @@
215218 # Constructor
216219 # @public
217220 # @param $parser an instance of parser from parser tag hook
 221+ # @param $frame an instance of PPFrame (parser context)
218222 # @param $type type of question (taken from DB)
219223 # @param $questionId the identifier of the question used to gernerate input names
220224 # @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 );
223227 $this->mType = $type;
224228 }
225229
@@ -259,7 +263,7 @@
260264 $row[] = array( '__tag'=>'td', 0=>"", 'style'=>'border:none;', '__end'=>"\n" );
261265 }
262266 foreach( $this->mCategories as &$cat ) {
263 - $row[] = $this->parser->recursiveTagParse( $cat['name'] );
 267+ $row[] = $this->parser->recursiveTagParse( $cat['name'], $this->ppframe );
264268 }
265269 if ( !$this->proposalsFirst ) {
266270 // add empty <th> at the end of row to "compensate" proposal text
@@ -277,7 +281,7 @@
278282 $row[] = array( '__tag'=>'td', 0=>"", 'style'=>'border:none;', '__end'=>"\n" );
279283 }
280284 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 ) );
282286 }
283287 if ( !$this->proposalsFirst ) {
284288 // add empty <th> at the end of row to "compensate" proposal text
@@ -328,7 +332,7 @@
329333 $row[ $catId ][ 0 ] = '';
330334 }
331335 }
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 ) );
333337 if ( $this->proposalsFirst ) {
334338 # first element is proposaltext
335339 array_unshift( $row, $text );
@@ -711,7 +715,7 @@
712716 $rawClass = 'proposalerror';
713717 }
714718 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 ) );
716720 if ( $this->proposalsFirst ) {
717721 # first element is proposaltext
718722 array_unshift( $row, $text );
@@ -858,7 +862,7 @@
859863 throw new MWException( $e->getMessage() );
860864 }
861865 }
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 ) );
863867 if ( $this->proposalsFirst ) {
864868 # first element is proposaltext
865869 array_unshift( $row, $text );
@@ -934,7 +938,7 @@
935939 $category = $this->bodyErrorMessage( wfMsg( 'qp_error_category_name_empty' ), 'error' );
936940 }
937941 $this->mCategories[ $catkey ]["name"] = $category;
938 - $row[] = $this->parser->recursiveTagParse( $category );
 942+ $row[] = $this->parser->recursiveTagParse( $category, $this->ppframe );
939943 }
940944
941945 # cut unused categories rows which are presented in DB but were removed from article
@@ -1016,7 +1020,9 @@
10171021 }
10181022 # fill undefined spans with the last span value
10191023 $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 );
10211027 if ($lastDefinedSpanKey !== null) {
10221028 if ( $SpanCategDelta > 0 ) {
10231029 # increase the length of last defined span value to match total lenth of categories
@@ -1049,7 +1055,7 @@
10501056 if ( $spanCategory=="" ) {
10511057 $colspan++;
10521058 } 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 ) );
10541060 if ( $spanType == "|") { // "!" is a comment header, not a real category span
10551061 $this->mCategorySpans[ $categorySpanId ]['name'] = $spanCategory;
10561062 $this->mCategorySpans[ $categorySpanId ]['count'] = $colspan;

Status & tagging log