Pastakhov has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/257920

Change subject: Add Link widget (v 1.5.0)
......................................................................

Add Link widget (v 1.5.0)

Change-Id: I0689e421c9bd27b150f2bb950bbc9d73cbab55dd
---
M PhpTagsWidgets.json
M PhpTagsWidgets.php
M includes/GenericWidget.php
A includes/WidgetLink.php
M includes/WidgetSlick.php
M resources/ext.pw.onReady.js
6 files changed, 82 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PhpTagsWidgets 
refs/changes/20/257920/1

diff --git a/PhpTagsWidgets.json b/PhpTagsWidgets.json
index dea74e6..4ec738b 100644
--- a/PhpTagsWidgets.json
+++ b/PhpTagsWidgets.json
@@ -34,6 +34,21 @@
                                }
                        }
                },
+               "Link": {
+                       "class": "WidgetLink",
+                       "parent": "GenericWidget",
+                       "METHODS": {
+                               "__construct" : {
+                                       "parameters": [
+                                               { "type": "mixed", "name": 
"title", "default": "null" },
+                                               { "type": "string", "name": 
"text", "default": "null" },
+                                               { "type": "array", "name": 
"properties", "default": "null" }
+                                       ],
+                                       "return": "Link",
+                                       "desc": "Returns new Link object"
+                               }
+                       }
+               },
                "Slick": {
                        "class": "WidgetSlick",
                        "parent": "GenericWidget",
diff --git a/PhpTagsWidgets.php b/PhpTagsWidgets.php
index 6cfcc0b..864d401 100644
--- a/PhpTagsWidgets.php
+++ b/PhpTagsWidgets.php
@@ -15,7 +15,7 @@
        die( 'This file is an extension to MediaWiki and thus not a valid entry 
point.' );
 }
 
-const PHPTAGS_WIDGETS_VERSION = '1.4.5';
+const PHPTAGS_WIDGETS_VERSION = '1.5.0';
 
 // Register this extension on Special:Version
 $wgExtensionCredits['phptags'][] = array(
@@ -45,6 +45,7 @@
 $wgAutoloadClasses['PhpTagsObjects\\WidgetFontAwesome'] = __DIR__ . 
'/includes/WidgetFontAwesome.php';
 $wgAutoloadClasses['PhpTagsObjects\\WidgetFontAwesomeIcon'] = __DIR__ . 
'/includes/WidgetFontAwesomeIcon.php';
 $wgAutoloadClasses['PhpTagsObjects\\WidgetVega'] = __DIR__ . 
'/includes/WidgetVega.php';
+$wgAutoloadClasses['PhpTagsObjects\\WidgetLink'] = __DIR__ . 
'/includes/WidgetLink.php';
 
 
 $tpl = array(
diff --git a/includes/GenericWidget.php b/includes/GenericWidget.php
index 2af85f5..7a452a6 100644
--- a/includes/GenericWidget.php
+++ b/includes/GenericWidget.php
@@ -4,7 +4,8 @@
 /**
  * Description of GenericWidget
  *
- * @author pastakhov
+ * @author Pavel Astakhov <[email protected]>
+ * @licence GNU General Public Licence 2.0 or later
  */
 class GenericWidget extends GenericObject {
 
diff --git a/includes/WidgetLink.php b/includes/WidgetLink.php
new file mode 100644
index 0000000..7eea129
--- /dev/null
+++ b/includes/WidgetLink.php
@@ -0,0 +1,54 @@
+<?php
+namespace PhpTagsObjects;
+
+/**
+ * Description of WidgetLink
+ *
+ * @author Pavel Astakhov <[email protected]>
+ * @licence GNU General Public Licence 2.0 or later
+ */
+class WidgetLink extends \PhpTags\GenericWidget {
+
+       protected $element = 'a';
+
+       public function m___construct( $title = null, $text = null, $properties 
= null ) {
+               if ( $title instanceof \PhpTags\GenericObject ) {
+                       if ( $title->value instanceof \Title ) {
+                               $title = $title->value;
+                       } else {
+                               throw new \PhpTags\HookException( 'Title object 
expected' );
+                       }
+               } else if ( $title !== false ) {
+                       $t = \PhpTags\Hooks::createObject( array($title), 
'WTitle', 'wtitle' );
+                       if ( $t->value instanceof \Title ) {
+                               $title = $t->value;
+                       } else {
+                               $title = false;
+                       }
+               }
+
+               if ( $title ) {
+                       $this->value[self::GENERAL_ATTRIBS]['href'] = 
$title->getInternalURL();
+               } else {
+                       $this->value[self::GENERAL_ATTRIBS]['href'] = '#';
+               }
+
+               $this->value[self::DATA]['title'] = $title;
+               $this->value[self::DATA] = $text;
+               return parent::m___construct( $properties );
+       }
+
+       public function getString() {
+               $parser = \PhpTags\Renderer::getParser();
+               $frame = \PhpTags\Renderer::getFrame();
+
+               return $parser->recursiveTagParse( $this->value[self::DATA], 
$frame );
+       }
+
+       public function toString() {
+               $html = parent::toString();
+               return \PhpTags\Renderer::insertStripItem( $html );
+       }
+
+
+}
diff --git a/includes/WidgetSlick.php b/includes/WidgetSlick.php
index 123ce0d..51f88c9 100644
--- a/includes/WidgetSlick.php
+++ b/includes/WidgetSlick.php
@@ -4,8 +4,8 @@
 /**
  * Description of WidgetsSlick
  * @see http://kenwheeler.github.io/slick/
- *
- * @author pastakhov
+ * @author Pavel Astakhov <[email protected]>
+ * @licence GNU General Public Licence 2.0 or later
  */
 class WidgetSlick extends \PhpTags\GenericWidget {
 
diff --git a/resources/ext.pw.onReady.js b/resources/ext.pw.onReady.js
index 5c072ae..e27c187 100644
--- a/resources/ext.pw.onReady.js
+++ b/resources/ext.pw.onReady.js
@@ -1,12 +1,14 @@
 /* global window, mw, $ */
 if(window.mw){
-       var $phptagsWidgets = mw.config.get( 'ext.phptags.Widgets' );
-       var $prefix = $phptagsWidgets.prefix;
-       var $whenReady = $phptagsWidgets.whenReady;
-       var mwPhpTagsWidgetsDoIt = function ( $fn ) {
+       var $phptagsWidgets = mw.config.get( 'ext.phptags.Widgets' ),
+               $prefix = $phptagsWidgets.prefix,
+               $whenReady = $phptagsWidgets.whenReady,
+               $data,
+               mwPhpTagsWidgetsDoIt = function ( $fn ) {
                for ( var $k in $fn ) {
                        if ( $fn.hasOwnProperty($k) ) {
-                               $.fn[ $fn[$k] ].apply( $( '.' + $prefix + $k ) 
, $phptagsWidgets.data[$k] );
+                               $data = ( $phptagsWidgets.data && 
$phptagsWidgets.data[$k] ) || {};
+                               $.fn[ $fn[$k] ].apply( $( '.' + $prefix + $k ) 
, $data );
                        }
                }
        };

-- 
To view, visit https://gerrit.wikimedia.org/r/257920
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0689e421c9bd27b150f2bb950bbc9d73cbab55dd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PhpTagsWidgets
Gerrit-Branch: master
Gerrit-Owner: Pastakhov <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to