https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114428
Revision: 114428
Author: danwe
Date: 2012-03-22 19:00:08 +0000 (Thu, 22 Mar 2012)
Log Message:
-----------
"?!" parser function and moved parser hook files into sub directory
Modified Paths:
--------------
trunk/extensions/SemanticExpressiveness/SemanticExpressiveness.php
Added Paths:
-----------
trunk/extensions/SemanticExpressiveness/includes/parserhooks/
trunk/extensions/SemanticExpressiveness/includes/parserhooks/SemExExpressiveStringPF.php
trunk/extensions/SemanticExpressiveness/includes/parserhooks/SemExPlainQueryPF.php
trunk/extensions/SemanticExpressiveness/includes/parserhooks/SemExQueryPF.php
Removed Paths:
-------------
trunk/extensions/SemanticExpressiveness/includes/SemExExpressiveStringPF.php
trunk/extensions/SemanticExpressiveness/includes/SemExQueryPF.php
Modified: trunk/extensions/SemanticExpressiveness/SemanticExpressiveness.php
===================================================================
--- trunk/extensions/SemanticExpressiveness/SemanticExpressiveness.php
2012-03-22 18:17:36 UTC (rev 114427)
+++ trunk/extensions/SemanticExpressiveness/SemanticExpressiveness.php
2012-03-22 19:00:08 UTC (rev 114428)
@@ -50,7 +50,6 @@
$wgAutoloadClasses['SemExExpressiveStringPieceSQResult'] = $incDir .
'SemExExpressiveStringPieceSQResult.php';
$wgAutoloadClasses['SemExExpressiveStringPieceWikiLink'] = $incDir .
'SemExExpressiveStringPieceWikiLink.php';
$wgAutoloadClasses['SemExExpressiveStringOutputOptions'] = $incDir .
'SemExExpressiveStringOutputOptions.php';
-$wgAutoloadClasses['SemExQueryPF' ] = $incDir .
'SemExQueryPF.php';
$wgAutoloadClasses['SemExShortQuery' ] = $incDir .
'SemExShortQuery.php';
$wgAutoloadClasses['SemExShortQueryProcessor' ] = $incDir .
'SemExShortQueryProcessor.php';
$wgAutoloadClasses['SemExShortQueryResult' ] = $incDir .
'SemExShortQueryResult.php';
@@ -65,8 +64,9 @@
$wgAutoloadClasses['SemExParamManipulationQuerySource'] = $incDir .
'validation/SemExParamManipulationQuerySource.php';
// Parser function initializations:
-$wgAutoloadClasses['SemExQueryPF' ] = $incDir . 'SemExQueryPF.php';
-$wgAutoloadClasses['SemExExpressiveStringPF' ] = $incDir .
'SemExExpressiveStringPF.php';
+$wgAutoloadClasses['SemExQueryPF' ] = $incDir .
'parserhooks/SemExQueryPF.php';
+$wgAutoloadClasses['SemExPlainQueryPF' ] = $incDir .
'parserhooks/SemExPlainQueryPF.php';
+$wgAutoloadClasses['SemExExpressiveStringPF'] = $incDir .
'parserhooks/SemExExpressiveStringPF.php';
$wgHooks['ParserFirstCallInit'][] = 'SemExExpressiveStringPF::staticInit';
@@ -85,8 +85,8 @@
static function init( &$parser ) {
$parser->setFunctionHook( '?', array( 'SemExQueryPF', 'render'
), SFH_NO_HASH );
- //$parser->setFunctionHook( '?!', array( 'SemExPlainQueryPF',
'render' ), SFH_NO_HASH );
- $parser->setFunctionHook( '?to?!', __CLASS__ .
'::parserFunc_QueryToPlainQuery', SFH_NO_HASH );
+ $parser->setFunctionHook( '?!', array( 'SemExPlainQueryPF',
'render' ), SFH_NO_HASH );
+ //$parser->setFunctionHook( '?to?!', array( __CLASS__,
'parserFunc_QueryToPlainQuery' ), SFH_NO_HASH );
return true;
}
Deleted:
trunk/extensions/SemanticExpressiveness/includes/SemExExpressiveStringPF.php
===================================================================
---
trunk/extensions/SemanticExpressiveness/includes/SemExExpressiveStringPF.php
2012-03-22 18:17:36 UTC (rev 114427)
+++
trunk/extensions/SemanticExpressiveness/includes/SemExExpressiveStringPF.php
2012-03-22 19:00:08 UTC (rev 114428)
@@ -1,132 +0,0 @@
-<?php
-
-/**
- * Class for the '?to?!' parser function, basically a limited converter for
expressive strings.
- *
- * @since 0.1
- *
- * @file SemExExpressiveStringPF.php
- * @ingroup SemanticExpressiveness
- *
- * @author Daniel Werner < [email protected] >
- */
-class SemExExpressiveStringPF extends ParserHook {
-
- public function __construct() {
- // make this a parser function extension (no tag extension)
only:
- parent::__construct( false, true, ParserHook::FH_NO_HASH );
- }
-
- /**
- * No LSB in pre-5.3 PHP, to be refactored later
- */
- public static function staticInit( Parser &$parser ) {
- $instance = new self;
- $instance->init( $parser );
- return true;
- }
-
- /**
- * Gets the name of the parser hook.
- * @see ParserHook::getName
- *
- * @return string
- */
- protected function getName() {
- return '?to?!';
- }
-
- /**
- * Returns an array containing the parameter info.
- * @see ParserHook::getParameterInfo
- *
- * @return array
- */
- protected function getParameterInfo( $type ) {
- $params = SemExExpressiveStringOutputOptions::getPFParams();
-
- # input text.
- # since 0.1
- $params['text'] = new Parameter( 'text' );
-
- $pieceTypesCriteria = new CriterionInArray(
- array_values(
SemExExpressiveString::getRegisteredPieceTypeNames() )
- );
-
- $params['detect'] = new ListParameter( 'detect' );
- $params['detect']->addCriteria( $pieceTypesCriteria );
- $params['detect']->setDefault( array( '' ), false );
-
- $params['ignore'] = new ListParameter( 'ignore' );
- $params['ignore']->addCriteria( $pieceTypesCriteria );
- $params['ignore']->setDefault( array(), false );
-
- return $params;
- }
-
- /**
- * Returns the list of default parameters.
- * @see ParserHook::getDefaultParameters
- *
- * @return array
- */
- protected function getDefaultParameters( $type ) {
- return array(
- array( 'text', Validator::PARAM_UNNAMED ),
- );
- }
-
- /**
- * Returns the parser function options.
- * @see ParserHook::getFunctionOptions
- *
- * @return array
- */
- protected function getFunctionOptions() {
- return array(
- 'noparse' => true,
- 'isHTML' => false
- );
- }
-
- /**
- * Renders and returns the output.
- * @see ParserHook::renderTag
- *
- * @param array $parameters
- * @return string
- */
- public function render( array $parameters ) {
- // get all types that should be handled by this
- $enabledTypes = array();
-
- if( implode( '', $parameters['detect'] ) !== '' ) { // ''
counts as if parameter not set
- foreach( $parameters['detect'] as $typeName ) {
- $type =
SemExExpressiveString::getRegisteredPieceTypeByName( $typeName );
- if( $type !== null ) {
- $enabledTypes[] = $type;
- }
- }
- } elseif( empty( $parameters['ignore'] ) ) {
- $enabledTypes = null; // same as next but constructor
will process this faster
- } else {
- $enabledTypes =
SemExExpressiveString::getRegisteredPieceTypeNames();
- }
-
- if( $enabledTypes !== null ) {
- $enabledTypes = array_flip( $enabledTypes );
- foreach( $parameters['ignore'] as $typeName ) {
- unset( $enabledTypes[
SemExExpressiveString::getRegisteredPieceTypeByName( $typeName ) ] );
- }
- $enabledTypes = array_flip( $enabledTypes );
- }
-
- // build expressive string from input with enabled types:
- $exprString = new SemExExpressiveString( $parameters['text'],
$this->parser, $enabledTypes );
-
- /** @ToDo: Make it possible to define options per piece type
per parameter prefixes */
- $options =
SemExExpressiveStringOutputOptions::newFromValidatedParams( $parameters );
- return $exprString->getOutput( $options );
- }
-
-}
Deleted: trunk/extensions/SemanticExpressiveness/includes/SemExQueryPF.php
===================================================================
--- trunk/extensions/SemanticExpressiveness/includes/SemExQueryPF.php
2012-03-22 18:17:36 UTC (rev 114427)
+++ trunk/extensions/SemanticExpressiveness/includes/SemExQueryPF.php
2012-03-22 19:00:08 UTC (rev 114428)
@@ -1,90 +0,0 @@
-<?php
-
-/**
- * Class for '?' short query parser function
- *
- * @since 0.1
- *
- * @file SemExQueryPF.php
- * @ingroup SemanticExpressiveness
- *
- * @author Daniel Werner < [email protected] >
- */
-
-class SemExQueryPF {
-
- public static function render( Parser &$parser ) {
- global $smwgQEnabled, $smwgIQRunningNumber;
-
- if ( $smwgQEnabled ) {
- $smwgIQRunningNumber++;
-
- $params = func_get_args();
- array_shift( $params ); // remove $parser
- $params = static::validateParams( $params );
-
- $query = SemExShortQuery::newFromValidatedParams(
$params );
- $options =
SemExShortQueryOutputOptions::newFromValidatedParams( $params );
-
- if( ! $query || ! $options ) {
- // @ToDo: real error message (anyway, in what
case can this happen?)
- return 'FALSE';
- }
-
- $result = SemExShortQueryProcessor::getResultFromQuery(
$parser, $query, $options );
-
- if( $result === '' ) {
- $result = $params['default'];
- } else {
- $result = // allow ' ' in form of '_' around
the result
- preg_replace( '/_$/', ' ',
$params['intro'] ) .
- $result .
- preg_replace( '/^_/', ' ',
$params['outro'] );
- }
- }
- else {
- $result = smwfEncodeMessages( array( wfMsgForContent(
'smw_iq_disabled' ) ) );
- }
-
- return $result;
- }
-
- protected static function validateParams( array $rawParams, &$validator
= null ) {
- $validator = new Validator();
- $validator->setFunctionParams(
- $rawParams,
- static::getParameters(),
- array( 'property', Validator::PARAM_UNNAMED )
// 'property' is parameter 1
- );
- $validator->validateParameters();
-
- return $validator->getParameterValues();
- }
-
- /**
- * Returns a description of all allowed function Parameters.
- *
- * @return array
- */
- public static function getParameters() {
- $params = array();
-
- $params['intro'] = new Parameter( 'intro' );
- $params['intro']->setDefault( '' );
-
- $params['outro'] = new Parameter( 'outro' );
- $params['outro']->setDefault( '' );
-
- $params['default'] = new Parameter( 'default' );
- $params['default']->setDefault( '' );
-
- // add function parameters describing the querry and its
options:
- $params = array_merge(
- $params,
- SemExShortQuery::getPFParams(),
- SemExShortQueryOutputOptions::getPFParams()
- );
-
- return $params;
- }
-}
Copied:
trunk/extensions/SemanticExpressiveness/includes/parserhooks/SemExExpressiveStringPF.php
(from rev 114427,
trunk/extensions/SemanticExpressiveness/includes/SemExExpressiveStringPF.php)
===================================================================
---
trunk/extensions/SemanticExpressiveness/includes/parserhooks/SemExExpressiveStringPF.php
(rev 0)
+++
trunk/extensions/SemanticExpressiveness/includes/parserhooks/SemExExpressiveStringPF.php
2012-03-22 19:00:08 UTC (rev 114428)
@@ -0,0 +1,132 @@
+<?php
+
+/**
+ * Class for the '?to?!' parser function, basically a limited converter for
expressive strings.
+ *
+ * @since 0.1
+ *
+ * @file SemExExpressiveStringPF.php
+ * @ingroup SemanticExpressiveness
+ *
+ * @author Daniel Werner < [email protected] >
+ */
+class SemExExpressiveStringPF extends ParserHook {
+
+ public function __construct() {
+ // make this a parser function extension (no tag extension)
only:
+ parent::__construct( false, true, ParserHook::FH_NO_HASH );
+ }
+
+ /**
+ * No LSB in pre-5.3 PHP, to be refactored later
+ */
+ public static function staticInit( Parser &$parser ) {
+ $instance = new self;
+ $instance->init( $parser );
+ return true;
+ }
+
+ /**
+ * Gets the name of the parser hook.
+ * @see ParserHook::getName
+ *
+ * @return string
+ */
+ protected function getName() {
+ return '?to?!';
+ }
+
+ /**
+ * Returns an array containing the parameter info.
+ * @see ParserHook::getParameterInfo
+ *
+ * @return array
+ */
+ protected function getParameterInfo( $type ) {
+ $params = SemExExpressiveStringOutputOptions::getPFParams();
+
+ # input text.
+ # since 0.1
+ $params['text'] = new Parameter( 'text' );
+
+ $pieceTypesCriteria = new CriterionInArray(
+ array_values(
SemExExpressiveString::getRegisteredPieceTypeNames() )
+ );
+
+ $params['detect'] = new ListParameter( 'detect' );
+ $params['detect']->addCriteria( $pieceTypesCriteria );
+ $params['detect']->setDefault( array( '' ), false );
+
+ $params['ignore'] = new ListParameter( 'ignore' );
+ $params['ignore']->addCriteria( $pieceTypesCriteria );
+ $params['ignore']->setDefault( array(), false );
+
+ return $params;
+ }
+
+ /**
+ * Returns the list of default parameters.
+ * @see ParserHook::getDefaultParameters
+ *
+ * @return array
+ */
+ protected function getDefaultParameters( $type ) {
+ return array(
+ array( 'text', Validator::PARAM_UNNAMED ),
+ );
+ }
+
+ /**
+ * Returns the parser function options.
+ * @see ParserHook::getFunctionOptions
+ *
+ * @return array
+ */
+ protected function getFunctionOptions() {
+ return array(
+ 'noparse' => true,
+ 'isHTML' => false
+ );
+ }
+
+ /**
+ * Renders and returns the output.
+ * @see ParserHook::renderTag
+ *
+ * @param array $parameters
+ * @return string
+ */
+ public function render( array $parameters ) {
+ // get all types that should be handled by this
+ $enabledTypes = array();
+
+ if( implode( '', $parameters['detect'] ) !== '' ) { // ''
counts as if parameter not set
+ foreach( $parameters['detect'] as $typeName ) {
+ $type =
SemExExpressiveString::getRegisteredPieceTypeByName( $typeName );
+ if( $type !== null ) {
+ $enabledTypes[] = $type;
+ }
+ }
+ } elseif( empty( $parameters['ignore'] ) ) {
+ $enabledTypes = null; // same as next but constructor
will process this faster
+ } else {
+ $enabledTypes =
SemExExpressiveString::getRegisteredPieceTypeNames();
+ }
+
+ if( $enabledTypes !== null ) {
+ $enabledTypes = array_flip( $enabledTypes );
+ foreach( $parameters['ignore'] as $typeName ) {
+ unset( $enabledTypes[
SemExExpressiveString::getRegisteredPieceTypeByName( $typeName ) ] );
+ }
+ $enabledTypes = array_flip( $enabledTypes );
+ }
+
+ // build expressive string from input with enabled types:
+ $exprString = new SemExExpressiveString( $parameters['text'],
$this->parser, $enabledTypes );
+
+ /** @ToDo: Make it possible to define options per piece type
per parameter prefixes */
+ $options =
SemExExpressiveStringOutputOptions::newFromValidatedParams( $parameters );
+ return $exprString->getOutput( $options );
+ }
+
+}
Added:
trunk/extensions/SemanticExpressiveness/includes/parserhooks/SemExPlainQueryPF.php
===================================================================
---
trunk/extensions/SemanticExpressiveness/includes/parserhooks/SemExPlainQueryPF.php
(rev 0)
+++
trunk/extensions/SemanticExpressiveness/includes/parserhooks/SemExPlainQueryPF.php
2012-03-22 19:00:08 UTC (rev 114428)
@@ -0,0 +1,19 @@
+<?php
+
+/**
+ * Class for ?!' short query parser function
+ *
+ * @since 0.1
+ *
+ * @file SemExPlainQueryPF.php
+ * @ingroup SemanticExpressiveness
+ *
+ * @author Daniel Werner < [email protected] >
+ */
+class SemExPlainQueryPF extends SemExQueryPF {
+ public static function getParameters() {
+ $params = parent::getParameters();
+ $params['format']->setDefault( 'raw' );
+ return $params;
+ }
+}
Property changes on:
trunk/extensions/SemanticExpressiveness/includes/parserhooks/SemExPlainQueryPF.php
___________________________________________________________________
Added: svn:eol-style
+ native
Copied:
trunk/extensions/SemanticExpressiveness/includes/parserhooks/SemExQueryPF.php
(from rev 114427,
trunk/extensions/SemanticExpressiveness/includes/SemExQueryPF.php)
===================================================================
---
trunk/extensions/SemanticExpressiveness/includes/parserhooks/SemExQueryPF.php
(rev 0)
+++
trunk/extensions/SemanticExpressiveness/includes/parserhooks/SemExQueryPF.php
2012-03-22 19:00:08 UTC (rev 114428)
@@ -0,0 +1,89 @@
+<?php
+
+/**
+ * Class for '?' short query parser function
+ *
+ * @since 0.1
+ *
+ * @file SemExQueryPF.php
+ * @ingroup SemanticExpressiveness
+ *
+ * @author Daniel Werner < [email protected] >
+ */
+class SemExQueryPF {
+
+ public static function render( Parser &$parser ) {
+ global $smwgQEnabled, $smwgIQRunningNumber;
+
+ if ( $smwgQEnabled ) {
+ $smwgIQRunningNumber++;
+
+ $params = func_get_args();
+ array_shift( $params ); // remove $parser
+ $params = static::validateParams( $params );
+
+ $query = SemExShortQuery::newFromValidatedParams(
$params );
+ $options =
SemExShortQueryOutputOptions::newFromValidatedParams( $params );
+
+ if( ! $query || ! $options ) {
+ // @ToDo: real error message (anyway, in what
case can this happen?)
+ return 'FALSE';
+ }
+
+ $result = SemExShortQueryProcessor::getResultFromQuery(
$parser, $query, $options );
+
+ if( $result === '' ) {
+ $result = $params['default'];
+ } else {
+ $result = // allow ' ' in form of '_' around
the result
+ preg_replace( '/_$/', ' ',
$params['intro'] ) .
+ $result .
+ preg_replace( '/^_/', ' ',
$params['outro'] );
+ }
+ }
+ else {
+ $result = smwfEncodeMessages( array( wfMsgForContent(
'smw_iq_disabled' ) ) );
+ }
+
+ return $result;
+ }
+
+ protected static function validateParams( array $rawParams, &$validator
= null ) {
+ $validator = new Validator();
+ $validator->setFunctionParams(
+ $rawParams,
+ static::getParameters(),
+ array( 'property', Validator::PARAM_UNNAMED )
// 'property' is parameter 1
+ );
+ $validator->validateParameters();
+
+ return $validator->getParameterValues();
+ }
+
+ /**
+ * Returns a description of all allowed function Parameters.
+ *
+ * @return array
+ */
+ public static function getParameters() {
+ $params = array();
+
+ $params['intro'] = new Parameter( 'intro' );
+ $params['intro']->setDefault( '' );
+
+ $params['outro'] = new Parameter( 'outro' );
+ $params['outro']->setDefault( '' );
+
+ $params['default'] = new Parameter( 'default' );
+ $params['default']->setDefault( '' );
+
+ // add function parameters describing the querry and its
options:
+ $params = array_merge(
+ $params,
+ SemExShortQuery::getPFParams(),
+ SemExShortQueryOutputOptions::getPFParams()
+ );
+
+ return $params;
+ }
+}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs