Cicalese has uploaded a new change for review.
https://gerrit.wikimedia.org/r/172594
Change subject: CSS selector, path, coding style
......................................................................
CSS selector, path, coding style
Change-Id: I52b92b865ab83c276b0b049e20daaf78d475bb42
---
A SemanticRating.class.php
M SemanticRating.i18n.magic.php
M SemanticRating.php
M SemanticRatingFormInput.php
M SemanticRatingHtmlRenderer.php
M scripts/SemanticRating.js
6 files changed, 160 insertions(+), 117 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticRating
refs/changes/94/172594/1
diff --git a/SemanticRating.class.php b/SemanticRating.class.php
new file mode 100644
index 0000000..5ebf33d
--- /dev/null
+++ b/SemanticRating.class.php
@@ -0,0 +1,60 @@
+<?php
+/*
+ * Copyright (c) 2014 The MITRE Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+
+class SemanticRating {
+
+ public static function setup( \Parser &$parser ) {
+
+ if ( !array_key_exists( 'SemanticRating_DefaultMax', $GLOBALS )
) {
+ $GLOBALS['SemanticRating_DefaultMax'] = 5;
+ }
+
+ if ( !array_key_exists( 'SemanticRating_CSSSelector', $GLOBALS
) ) {
+ $GLOBALS['SemanticRating_CSSSelector'] =
"#firstHeading";
+ }
+
+ $imagepath = $GLOBALS['wgServer'] . $GLOBALS['wgScriptPath'] .
+ "/extensions/SemanticRating/images/";
+ $renderer = new SemanticRatingHtmlRenderer( $imagepath );
+
+ $parser->setFunctionHook( 'rating', function( $parser ) use(
$renderer ) {
+ return $renderer->renderInline( $parser,
func_get_args() );
+ } );
+
+ $parser->setFunctionHook( 'ratingBeforeTitle', function(
$parser )
+ use( $renderer ) {
+ return $renderer->renderBeforeTitle( $parser,
func_get_args() );
+ } );
+
+ $parser->setFunctionHook( 'ratingAfterTitle', function( $parser
)
+ use( $renderer ) {
+ return $renderer->renderAfterTitle( $parser,
func_get_args() );
+ } );
+
+ SemanticRatingFormInput::setImagePath( $imagepath );
+ $GLOBALS['sfgFormPrinter']->registerInputType(
'SemanticRatingFormInput' );
+
+ return true;
+ }
+}
diff --git a/SemanticRating.i18n.magic.php b/SemanticRating.i18n.magic.php
index 10c90d0..e5071a0 100644
--- a/SemanticRating.i18n.magic.php
+++ b/SemanticRating.i18n.magic.php
@@ -25,7 +25,7 @@
$magicWords = array();
$magicWords['en'] = array(
- 'rating' => array (0, 'rating'),
- 'ratingBeforeTitle' => array (0, 'ratingBeforeTitle'),
- 'ratingAfterTitle' => array (0, 'ratingAfterTitle')
+ 'rating' => array ( 0, 'rating' ),
+ 'ratingBeforeTitle' => array ( 0, 'ratingBeforeTitle' ),
+ 'ratingAfterTitle' => array ( 0, 'ratingAfterTitle' )
);
diff --git a/SemanticRating.php b/SemanticRating.php
index 6211264..cfa24f6 100644
--- a/SemanticRating.php
+++ b/SemanticRating.php
@@ -21,25 +21,26 @@
* DEALINGS IN THE SOFTWARE.
*/
-if (!defined('MEDIAWIKI')) {
- die('<b>Error:</b> This file is part of a MediaWiki extension and
cannot be run standalone.');
+if ( !defined( 'MEDIAWIKI' ) ) {
+ die( '<b>Error:</b> This file is part of a MediaWiki extension and
cannot be run standalone.' );
}
-if (version_compare($GLOBALS['wgVersion'], '1.21', 'lt')) {
- die('<b>Error:</b> This version of SemanticRating is only compatible
with MediaWiki 1.21 or above.');
+if ( version_compare( $GLOBALS['wgVersion'], '1.21', 'lt' ) ) {
+ die( '<b>Error:</b> This version of SemanticRating is only compatible
with MediaWiki 1.21 or above.' );
}
-if (!defined('SF_VERSION')) {
- die('<b>Error:</b> SemanticRating is a Semantic Forms extension so must
be included after Semantic Forms.');
+if ( !defined( 'SF_VERSION' ) ) {
+ die( '<b>Error:</b> SemanticRating is a Semantic Forms extension so
must be included after Semantic Forms.' );
}
-if (version_compare(SF_VERSION, '2.5.2', 'lt')) {
- die('<b>Error:</b> This version of SemanticRating is only compatible
with Semantic Forms 2.5.2 or above.');
+if ( version_compare( SF_VERSION, '2.5.2', 'lt' ) ) {
+ die( '<b>Error:</b> This version of SemanticRating is only compatible
with Semantic Forms 2.5.2 or above.' );
}
$GLOBALS['wgExtensionCredits']['semantic'][] = array (
+ 'path' => __FILE__,
'name' => 'SemanticRating',
- 'version' => '2.1',
+ 'version' => '2.2',
'author' => array(
'[https://www.mediawiki.org/wiki/User:Cindy.cicalese Cindy
Cicalese]'
),
@@ -51,6 +52,9 @@
// [https://www.mediawiki.org/wiki/User:Bernadette Bernadette Clemente]
// for the original idea that inspired this extension and to Kelly Hatfield
// for an early implementation of this extension.
+
+$GLOBALS['wgAutoloadClasses']['SemanticRating'] =
+ __DIR__ . '/SemanticRating.class.php';
$GLOBALS['wgAutoloadClasses']['SemanticRatingHtmlRenderer'] =
__DIR__ . '/SemanticRatingHtmlRenderer.php';
@@ -71,32 +75,4 @@
'scripts' => 'scripts/SemanticRating.js'
);
-$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function (\Parser &$parser) {
-
- if (!array_key_exists('SemanticRating_DefaultMax', $GLOBALS)) {
- $GLOBALS['SemanticRating_DefaultMax'] = 5;
- }
-
- $imagepath = $GLOBALS['wgServer'] . $GLOBALS['wgScriptPath'] .
- "/extensions/SemanticRating/images/";
- $renderer = new SemanticRatingHtmlRenderer($imagepath);
-
- $parser->setFunctionHook('rating', function($parser) use($renderer) {
- return $renderer->renderInline($parser, func_get_args());
- });
-
- $parser->setFunctionHook('ratingBeforeTitle', function($parser)
- use($renderer) {
- return $renderer->renderBeforeTitle($parser, func_get_args());
- });
-
- $parser->setFunctionHook('ratingAfterTitle', function($parser)
- use($renderer) {
- return $renderer->renderAfterTitle($parser, func_get_args());
- });
-
- SemanticRatingFormInput::setImagePath($imagepath);
-
$GLOBALS['sfgFormPrinter']->registerInputType('SemanticRatingFormInput');
-
- return true;
-};
+$GLOBALS['wgHooks']['ParserFirstCallInit'][] = 'SemanticRating::setup';
diff --git a/SemanticRatingFormInput.php b/SemanticRatingFormInput.php
index 7035a30..a2798f1 100644
--- a/SemanticRatingFormInput.php
+++ b/SemanticRatingFormInput.php
@@ -25,15 +25,15 @@
private static $imagepath = null;
- public static function setImagePath($value) {
+ public static function setImagePath( $value ) {
self::$imagepath = $value;
}
- public function __construct($input_number, $cur_value, $input_name,
- $disabled, $other_args) {
- parent::__construct($input_number, $cur_value, $input_name,
$disabled,
- $other_args);
- if (array_key_exists('max', $this->mOtherArgs)) {
+ public function __construct( $input_number, $cur_value, $input_name,
+ $disabled, $other_args ) {
+ parent::__construct( $input_number, $cur_value, $input_name,
$disabled,
+ $other_args );
+ if ( array_key_exists( 'max', $this->mOtherArgs ) ) {
$this->mMax = $this->mOtherArgs['max'];
} else {
$this->mMax = $GLOBALS['SemanticRating_DefaultMax'];
@@ -46,50 +46,50 @@
public function getHtmlText() {
- if (!is_numeric($this->mCurrentValue) || $this->mCurrentValue <
0 ||
- $this->mCurrentValue > $this->mMax) {
+ if ( !is_numeric( $this->mCurrentValue ) ||
$this->mCurrentValue < 0 ||
+ $this->mCurrentValue > $this->mMax ) {
$this->mCurrentValue = 0;
}
$output =
- Html::openElement('table', array('style' =>
'display:inline;')) .
- Html::openElement('td');
+ Html::openElement( 'table', array( 'style' =>
'display:inline;' ) ) .
+ Html::openElement( 'td' );
$input_id = "input_" . $GLOBALS['sfgFieldNum'];
- $output .= Html::element('input', array(
+ $output .= Html::element( 'input', array(
'type' => 'hidden',
'id' => $input_id,
'name' => $this->mInputName,
'value' => $this->mCurrentValue
- ));
+ ) );
$i = 1;
$src = self::$imagepath . 'yellowstar.png';
- while ($i < $this->mCurrentValue + 1) {
- $output .= Html::element('img', array(
+ while ( $i < $this->mCurrentValue + 1 ) {
+ $output .= Html::element( 'img', array(
'src' => $src,
'id' => $input_id . '_s_' . $i,
'onclick' => 'semanticRating.setrating(' . $i .
",'" . $input_id . "'," .
$this->mMax . ');'
- ));
+ ) );
$i++;
}
$src = self::$imagepath . 'greystar.png';
- while ($i <= $this->mMax) {
- $output .= Html::element('img', array(
+ while ( $i <= $this->mMax ) {
+ $output .= Html::element( 'img', array(
'src' => $src,
'id' => $input_id . '_s_' . $i,
'onclick' => 'semanticRating.setrating(' . $i .
",'" . $input_id . "'," .
$this->mMax . ');'
- ));
+ ) );
$i++;
}
$output .=
- Html::closeElement('td') .
- Html::closeElement('table');
+ Html::closeElement( 'td' ) .
+ Html::closeElement( 'table' );
return $output;
}
@@ -99,7 +99,7 @@
$params[] = array(
'name' => 'max',
'type' => 'int',
- 'description' => wfMessage('semanticrating-max')->text()
+ 'description' => wfMessage( 'semanticrating-max'
)->text()
);
return $params;
}
diff --git a/SemanticRatingHtmlRenderer.php b/SemanticRatingHtmlRenderer.php
index 7527d82..56d78a3 100644
--- a/SemanticRatingHtmlRenderer.php
+++ b/SemanticRatingHtmlRenderer.php
@@ -24,90 +24,96 @@
class SemanticRatingHtmlRenderer {
- var $imagepath = null;
+ private $imagepath = null;
- public function __construct($imagepath) {
+ public function __construct( $imagepath ) {
$this->imagepath = $imagepath;
}
- private function render($parser, $params) {
+ private function render( $parser, $params ) {
- if (count($params) > 1) {
+ if ( count( $params ) > 1 ) {
$rating = $params[1];
} else {
$rating = 0;
}
- if (count($params) > 2) {
+ if ( count( $params ) > 2 ) {
$max = $params[2];
} else {
$max = $GLOBALS['SemanticRating_DefaultMax'];
}
- $output = Html::openElement('span', array(
+ $output = Html::openElement( 'span', array(
'style' => 'white-space:nowrap;'
- ));
+ ) );
- if ($rating < 0) {
+ if ( $rating < 0 ) {
$rating = 0;
- } else if ($rating > $max) {
+ } elseif ( $rating > $max ) {
$rating = $max;
}
$i = 1;
- while ($i <= $rating) {
+ while ( $i <= $rating ) {
$output .=
- Html::element('img',
- array('src' => $this->imagepath .
'yellowstar.png'));
+ Html::element( 'img',
+ array( 'src' => $this->imagepath .
'yellowstar.png' ) );
$i++;
}
- if ($rating - $i + 1 != 0) {
+ if ( $rating - $i + 1 != 0 ) {
$output .=
- Html::element('img',
- array('src' => $this->imagepath .
'halfstar.png'));
+ Html::element( 'img',
+ array( 'src' => $this->imagepath .
'halfstar.png' ) );
$i++;
}
- while ($i <= $max) {
+ while ( $i <= $max ) {
$output .=
- Html::element('img',
- array('src' => $this->imagepath .
'greystar.png'));
+ Html::element( 'img',
+ array( 'src' => $this->imagepath .
'greystar.png' ) );
$i++;
}
- $output .= Html::closeElement('span');
+ $output .= Html::closeElement( 'span' );
return $output;
}
- public function renderInline($parser, $params) {
- $output = $this->render($parser, $params);
- return array($parser->insertStripItem($output,
$parser->mStripState),
- 'noparse' => false, 'isHTML' => true);
+ public function renderInline( $parser, $params ) {
+ $output = $this->render( $parser, $params );
+ return array( $parser->insertStripItem( $output,
$parser->mStripState ),
+ 'noparse' => false, 'isHTML' => true );
}
- public function renderBeforeTitle($parser, $params) {
- $output = $this->render($parser, $params);
- $script =<<<END
-jQuery(document).ready(function() {
- var title = jQuery('#firstHeading').html();
- jQuery('#firstHeading').html('$output' + ' ' + title);
-});
+ public function renderBeforeTitle( $parser, $params ) {
+ $output = $this->render( $parser, $params );
+ $cssSelector = $GLOBALS['SemanticRating_CSSSelector'];
+ $script = <<<END
+jQuery( document ).ready( function() {
+ jQuery( '$cssSelector' ).each( function( index ) {
+ var title = jQuery( this ).html();
+ jQuery( this ).html( '$output' + title );
+ } );
+} );
END;
- $script = Html::inlineScript($script);
- $GLOBALS['wgOut']->addScript($script);
+ $script = Html::inlineScript( $script );
+ $GLOBALS['wgOut']->addScript( $script );
return "";
}
- public function renderAfterTitle($parser, $params) {
- $output = $this->render($parser, $params);
- $script =<<<END
-jQuery(document).ready(function() {
- var title = jQuery('#firstHeading').html();
- jQuery('#firstHeading').html(title + ' ' + '$output');
-});
+ public function renderAfterTitle( $parser, $params ) {
+ $output = $this->render( $parser, $params );
+ $cssSelector = $GLOBALS['SemanticRating_CSSSelector'];
+ $script = <<<END
+jQuery( document ).ready( function() {
+ jQuery( '$cssSelector' ).each( function( index ) {
+ var title = jQuery( this ).html();
+ jQuery( this ).html( title + '$output' );
+ } );
+} );
END;
- $script = Html::inlineScript($script);
- $GLOBALS['wgOut']->addScript($script);
+ $script = Html::inlineScript( $script );
+ $GLOBALS['wgOut']->addScript( $script );
return "";
}
}
diff --git a/scripts/SemanticRating.js b/scripts/SemanticRating.js
index 0d0c204..f233d5a 100644
--- a/scripts/SemanticRating.js
+++ b/scripts/SemanticRating.js
@@ -20,30 +20,31 @@
* DEALINGS IN THE SOFTWARE.
*/
-var semanticRating = (function($) {
+var semanticRating = ( function( $ ) {
'use strict';
return {
- setrating: function(rating, input_id, max) {
- $("#" + input_id).attr('value', rating);
+ setrating: function( rating, input_id, max ) {
+ $( "#" + input_id )
+ .attr( 'value', rating );
var i = 1;
- while (i <= rating) {
- var star = $("#" + input_id + "_s_" + i);
- var src = star.attr('src');
- src = src.replace("grey", "yellow");
- star.attr('src', src);
+ while ( i <= rating ) {
+ var star = $( "#" + input_id + "_s_" + i );
+ var src = star.attr( 'src' );
+ src = src.replace( "grey", "yellow" );
+ star.attr( 'src', src );
i++;
}
- while (i <= max) {
- var star = $("#" + input_id + "_s_" + i);
- var src = star.attr('src');
- src = src.replace("yellow", "grey");
- star.attr('src', src);
+ while ( i <= max ) {
+ var star = $( "#" + input_id + "_s_" + i );
+ var src = star.attr( 'src' );
+ src = src.replace( "yellow", "grey" );
+ star.attr( 'src', src );
i++;
}
}
};
-}(jQuery));
+}( jQuery ) );
window.semanticRating = semanticRating;
--
To view, visit https://gerrit.wikimedia.org/r/172594
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I52b92b865ab83c276b0b049e20daaf78d475bb42
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticRating
Gerrit-Branch: master
Gerrit-Owner: Cicalese <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits