Robert Vogel has uploaded a new change for review. https://gerrit.wikimedia.org/r/278282
Change subject: [WiP] CountThings: GenericTagExtensionHandler impl. ...................................................................... [WiP] CountThings: GenericTagExtensionHandler impl. Now using new GenericTagExtensionHandler This is a follow up change to https://gerrit.wikimedia.org/r/#/c/278280/ and may not be merged beforehand. WORK IN PROGRESS - DO NOT MERGE! Change-Id: Ib368d9dfcd54cca93d473d7034fbf4d8e866d813 --- M CountThings/CountThings.class.php 1 file changed, 39 insertions(+), 49 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceExtensions refs/changes/82/278282/1 diff --git a/CountThings/CountThings.class.php b/CountThings/CountThings.class.php index b65543a..5571bbb 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,47 @@ protected function initExt() { wfProfileIn( 'BS::'.__METHOD__ ); - $this->setHook( 'ParserFirstCallInit' ); $this->setHook( 'BSInsertMagicAjaxGetData', 'onBSInsertMagicAjaxGetData' ); wfProfileOut( 'BS::'.__METHOD__ ); } - /** - * - * @param Parser $parser - * @return boolean - */ - 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 suff from "onBSInsertMagicAjaxGetData" like "code" + 'callback' => array( &$this, 'onMagicWordBsCountArticles' ), + 'inline' => true + ), + 'bs:countusers' => array( + 'descMsg' => 'bs-countthings-tag-countusers-desc', + 'callback' => array( &$this, 'onMagicWordBsCountUsers' ), + 'inline' => true + ), + 'bs:countcharacters' => array( + //Param definition for inner tag content + 'input' => array( + 'type' => 'TitleList', + 'required' => true, + //specific to type "TitleList" + 'namespaceblacklist' => array( NS_SPECIAL, NS_MEDIA ), + 'onlyexisting' => true + ), + //Param definitions for tag attributes + 'params' => array( + 'modes' => array( + 'type' => 'string', + 'values' => array( 'chars', 'words', 'pages', 'all' ), + 'default' => 'all', + 'tolower' => true, + 'errormsg' => 'bs-countthings-error-invalid-mode' + ) + ), + 'disableParserCache' => true, + 'descMsg' =>'bs-countthings-tag-countcharacters-desc', + 'callback' => array( &$this, 'onMagicWordBsCountCharacters' ) + ), + ); } /** @@ -138,13 +164,6 @@ $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; } /** @@ -155,37 +174,8 @@ * @return type */ 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' ); - - $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: newchange Gerrit-Change-Id: Ib368d9dfcd54cca93d473d7034fbf4d8e866d813 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions Gerrit-Branch: master Gerrit-Owner: Robert Vogel <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
