r81306 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81305‎ | r81306 | r81307 >
Date:11:22, 1 February 2011
Author:questpc
Status:deferred
Tags:
Comment:
Do not render space named single category (user request). New way of registering ResourceLoader modules.
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
@@ -66,6 +66,20 @@
6767 'descriptionmsg' => 'qp_desc-sp',
6868 );
6969
 70+if ( isset( $wgResourceModules ) ) {
 71+ $wgResourceModules['ext.qpoll'] = array(
 72+ 'scripts' => 'qp_user.js',
 73+ 'styles' => 'qp_user.css',
 74+ 'localBasePath' => dirname( __FILE__ ),
 75+ 'remoteExtPath' => 'QPoll'
 76+ );
 77+ $wgResourceModules['ext.qpoll.special.pollresults'] = array(
 78+ 'styles' => 'qp_results.css',
 79+ 'localBasePath' => dirname( __FILE__ ),
 80+ 'remoteExtPath' => 'QPoll'
 81+ );
 82+}
 83+
7084 /**
7185 * Extension's global settings and initializiers
7286 * should be purely static and preferrably have no constructor
@@ -151,12 +165,10 @@
152166 $wgSpecialPages['PollResults'] = array('PollResults');
153167 // TODO: Use the new technique for i18n of magic words
154168 // instantiating fake instance for PHP < 5.2.3, which does not support 'Class::method' type of callbacks
155 - $qp_Setup = new qp_Setup;
156169 $wgHooks['LanguageGetMagic'][] =
157170 $wgHooks['MediaWikiPerformAction'][] =
158171 $wgHooks['ParserFirstCallInit'][] =
159 - $wgHooks['LoadAllMessages'][] =
160 - $wgHooks['ResourceLoaderRegisterModules'][] = $qp_Setup;
 172+ $wgHooks['LoadAllMessages'][] = new qp_Setup;
161173 }
162174
163175 static function onLoadAllMessages() {
@@ -273,35 +285,6 @@
274286 }
275287
276288 /**
277 - * MW 1.17+ ResourceLoader module hook (JS,CSS)
278 - */
279 - static function onResourceLoaderRegisterModules( $resourceLoader ) {
280 - global $wgExtensionAssetsPath;
281 - $localpath = dirname( __FILE__ );
282 - $remotepath = "$wgExtensionAssetsPath/QPoll";
283 - $resourceLoader->register(
284 - array(
285 - 'ext.qpoll' => new ResourceLoaderFileModule(
286 - array(
287 - 'scripts' => 'qp_user.js',
288 - 'styles' => 'qp_user.css'
289 - ),
290 - $localpath,
291 - $remotepath
292 - ),
293 - 'ext.qpoll.special.pollresults' => new ResourceLoaderFileModule(
294 - array(
295 - 'styles' => 'qp_results.css'
296 - ),
297 - $localpath,
298 - $remotepath
299 - )
300 - )
301 - );
302 - return true;
303 - }
304 -
305 - /**
306289 * Call the poll parser on an input text.
307290 *
308291 * @param $input Text between <qpoll> and </qpoll> tags, in QPoll syntax.
Index: trunk/extensions/QPoll/qp_question.php
@@ -562,10 +562,11 @@
563563 #
564564 function parseBodyHeader( $input ) {
565565 $this->raws = preg_split( '`\n`su', $input, -1, PREG_SPLIT_NO_EMPTY );
566 - if ( array_key_exists( 1, $this->raws ) ) {
 566+ $categorySpans = false;
 567+ if ( isset( $this->raws[1] ) ) {
567568 $categorySpans = preg_match( $this->mCategoryPattern, $this->raws[1]."\n", $matches );
568569 }
569 - if ( !$categorySpans && array_key_exists( 0, $this->raws ) ) {
 570+ if ( !$categorySpans && isset( $this->raws[0] ) ) {
570571 preg_match( $this->mCategoryPattern, $this->raws[0]."\n", $matches );
571572 }
572573 # parse the header - spans and categories
@@ -582,6 +583,12 @@
583584 }
584585 $this->addRow( $spansRow, array( 'class'=>'spans' ), 'th', array( 'count'=>$this->spanType, 'name'=>0 ) );
585586 }
 587+ # do not render single empty category at all (on user's request)
 588+ if ( count( $this->mCategories ) == 1 &&
 589+ $this->mCategories[0]['name'] == '&#160;' ) {
 590+ return;
 591+ }
 592+ # render category table row
586593 if ( $this->categoriesStyle != '' ) {
587594 qp_Renderer::applyAttrsToRow( $catRow, array( 'style'=>$this->categoriesStyle ) );
588595 }

Status & tagging log