jenkins-bot has submitted this change and it was merged.

Change subject: CountThings: GenericTagExtensionHandler impl.
......................................................................


CountThings: GenericTagExtensionHandler impl.

Now using new GenericTagExtensionHandler

ATTENTION: This is a follow up change to 
https://gerrit.wikimedia.org/r/#/c/278280/
and may not be merged beforehand!

Patch Set 2: typo

Change-Id: Ib368d9dfcd54cca93d473d7034fbf4d8e866d813
---
M CountThings/CountThings.class.php
1 file changed, 57 insertions(+), 54 deletions(-)

Approvals:
  Mglaser: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/CountThings/CountThings.class.php 
b/CountThings/CountThings.class.php
index b65543a..71f5510 100644
--- a/CountThings/CountThings.class.php
+++ b/CountThings/CountThings.class.php
@@ -54,7 +54,7 @@
                        EXTINFO::STATUS      => 'default',
                        EXTINFO::PACKAGE     => 'default',
                        EXTINFO::URL => 
'https://help.bluespice.com/index.php/CountThings',
-                       EXTINFO::DEPS => array( 'bluespice' => '2.22.0' )
+                       EXTINFO::DEPS => array( 'bluespice' => '2.23.0' )
                );
                $this->mExtensionKey = 'MW::CountThings';
 
@@ -63,21 +63,51 @@
 
        protected function initExt() {
                wfProfileIn( 'BS::'.__METHOD__ );
-               $this->setHook( 'ParserFirstCallInit' );
                $this->setHook( 'BSInsertMagicAjaxGetData', 
'onBSInsertMagicAjaxGetData' );
                wfProfileOut( 'BS::'.__METHOD__ );
        }
 
        /**
-        *
-        * @param Parser $parser
-        * @return boolean
+        * Creates the tag definitions for 'CountThings' extension
+        * @return array
         */
-       public function onParserFirstCallInit( &$parser ) {
-               $parser->setHook( 'bs:countarticles', array( &$this, 
'onMagicWordBsCountArticles' ) );
-               $parser->setHook( 'bs:countusers', array( &$this, 
'onMagicWordBsCountUsers' ) );
-               $parser->setHook( 'bs:countcharacters', array( &$this, 
'onMagicWordBsCountCharacters' ) );
-               return true;
+       public function makeTagExtensionDefinitions() {
+               return array(
+                       'bs:countarticles' => array(
+                               'descMsg' => 
'bs-countthings-tag-countarticles-desc',
+                               //TODO: Maybe add other stuff from 
"onBSInsertMagicAjaxGetData" like "code"
+                               'callback' => array( $this, 
'onMagicWordBsCountArticles' ),
+                               'element' => 'span'
+                       ),
+                       'bs:countusers' => array(
+                               'descMsg' => 
'bs-countthings-tag-countusers-desc',
+                               'callback' => array( $this, 
'onMagicWordBsCountUsers' ),
+                               'element' => 'span'
+                       ),
+                       'bs:countcharacters' => array(
+                               //Param definition for inner tag content
+                               'input' => array(
+                                       'type' => 'titlelist',
+                                       'required' => true,
+                                       //specific to type "TitleList"
+                                       'hastoexist' => true
+                               ),
+                               //Param definitions for tag attributes
+                               'params' => array(
+                                       'modes' => array(
+                                               'type' => 'string',
+                                               'islist' => true,
+                                               'values'  => array( 'chars', 
'words', 'pages', 'all' ),
+                                               'default' => array( 'all' ),
+                                               'tolower' => true,
+                                               'errormsg' => 
'bs-countthings-error-invalid-mode'
+                                       )
+                               ),
+                               'disableParserCache' => true,
+                               'descMsg' 
=>'bs-countthings-tag-countcharacters-desc',
+                               'callback' => array( $this, 
'onMagicWordBsCountCharacters' )
+                       ),
+               );
        }
 
        /**
@@ -116,6 +146,13 @@
                return true;
        }
 
+       /**
+        * Handles <bs:countarticles /> tag
+        * @param string $input
+        * @param array $args
+        * @param Parser $parser
+        * @return string
+        */
        public function onMagicWordBsCountArticles( $input, $args, $parser ) {
                $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->select( 'page', 'page_id' );
@@ -126,11 +163,11 @@
        }
 
        /**
-        *
-        * @param type $input
-        * @param type $args
+        * Handles <bs:countusers /> tag
+        * @param string $input
+        * @param array $args
         * @param Parser $parser
-        * @return type
+        * @return string
         */
        public function onMagicWordBsCountUsers( $input, $args, $parser ) {
                $dbr = wfGetDB( DB_SLAVE );
@@ -138,54 +175,20 @@
                $out = $dbr->numRows( $res );
                $dbr->freeResult( $res );
 
-               //This is a bugfix for the case that somebody writes a wrong 
empty tag.
-               // <bs:countusers> instead of <bs:countusers />
-               //TODO: Do we really need to catch errors like this?
-               if( !empty($input) ){
-                       $out .= $parser->recursiveTagParse( $input );
-               }
-
                return $out;
        }
        /**
-        *
-        * @param type $input
-        * @param type $args
+        * Handles <bs:countcharacters /> tag
+        * @param Title[] $input
+        * @param array $args
         * @param Parser $parser
-        * @return type
+        * @return string
         */
        public function onMagicWordBsCountCharacters( $input, $args, $parser ) {
-               $parser->disableCache();
-               if ( empty( $input ) ) {
-                       $oErrorView = new ViewTagError( wfMessage( 
'bs-countthings-error-no-input' )->plain() );
-                       return $oErrorView->execute();
-               }
-
-               $sMode = isset($args['mode']) ? str_replace( ' ', '', 
$args['mode'] ) : 'all';
-               $aModes = explode( ',', $sMode );
-               $aAvailableModes = array( 'chars', 'words', 'pages', 'all' );
-
                $sOut = '';
-               $bValidModeProvided = false;
-               foreach( $aModes as $sMode ) {
-                       if( !in_array( $sMode, $aAvailableModes ) ){
-                               $oErrorView = new ViewTagError( wfMessage( 
'bs-countthings-error-invalid-mode', $sMode )->plain() );
-                               $sOut .= $oErrorView->execute();
-                               continue;
-                       }
-                       $bValidModeProvided = true;
-               }
-               if( $bValidModeProvided == false ) $aModes = array( 'all' );
+               $aModes = $args['modes'];
 
-               $aTitleTexts = explode( ',', $input );
-               foreach( $aTitleTexts as $sTitleText ) {
-                       $oTitle = Title::newFromText( trim( $sTitleText ) );
-                       if( $oTitle == null || $oTitle->exists() == false ) {
-                               $oErrorView = new ViewTagError( wfMessage( 
'bs-countthings-error-not-exist', $sTitleText )->plain() );
-                               $sOut .= $oErrorView->execute();
-                               continue;
-                       }
-
+               foreach( $input as $oTitle ) {
                        $sContent = 
BsPageContentProvider::getInstance()->getContentFromTitle( $oTitle ); //Old: 
last revision
 
                        $oCountView = new ViewCountCharacters();

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib368d9dfcd54cca93d473d7034fbf4d8e866d813
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: master
Gerrit-Owner: Robert Vogel <[email protected]>
Gerrit-Reviewer: Dvogel hallowelt <[email protected]>
Gerrit-Reviewer: Ljonka <[email protected]>
Gerrit-Reviewer: Mglaser <[email protected]>
Gerrit-Reviewer: Pwirth <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to