https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112973
Revision: 112973 Author: foxtrott Date: 2012-03-04 10:53:20 +0000 (Sun, 04 Mar 2012) Log Message: ----------- stylize Modified Paths: -------------- trunk/extensions/SemanticResultFormats/Filtered/SRF_Filtered.php trunk/extensions/SemanticResultFormats/Filtered/SRF_Filtered_Item.php trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_FF_Value.php trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_Filtered_Filter.php trunk/extensions/SemanticResultFormats/Filtered/views/SRF_FV_List.php trunk/extensions/SemanticResultFormats/Filtered/views/SRF_Filtered_View.php Modified: trunk/extensions/SemanticResultFormats/Filtered/SRF_Filtered.php =================================================================== --- trunk/extensions/SemanticResultFormats/Filtered/SRF_Filtered.php 2012-03-04 10:38:06 UTC (rev 112972) +++ trunk/extensions/SemanticResultFormats/Filtered/SRF_Filtered.php 2012-03-04 10:53:20 UTC (rev 112973) @@ -2,11 +2,11 @@ /** * File holding the SRFFiltered class. - * + * * @file * @ingroup SemanticResultFormats * @author Stephan Gambke - * + * */ $formatDir = dirname( __FILE__ ) . '/'; @@ -23,56 +23,56 @@ /** * Result printer that displays results in switchable views and offers * client-side (JavaScript based) filtering. - * + * * This result printer is ultimately planned to replace exhibit. Currently only * a list view is available. It is not yet possible to switch between views. * There is also only the 'value' filter available yet. - * + * * Syntax of the #ask call: * (This is only a syntax example. For currently available features see the * documentation of the various classes.) - * + * * {{#ask:[[SomeCondition]] * |? SomePrintout |+filter=value, someFutureFilter |+value filter switches=and or, disable, all, none |+someFutureFilter filter option=someOptionValue * |? SomeOtherPrintout |+filter=value, someOtherFutureFilter |+someOtherFutureFilter filter option=someOptionValue - * + * * |format=filtered * |views=list, someFutureView, someOtherFutureView - * + * * |list view type=list * |list view template=ListItem - * + * * |someFutureView view option=someOptionValue - * + * * |someOtherFutureView view option=someOptionValue - * + * * }} - * + * * All format specific parameters are optional, although leaving the 'views' * parameter empty probably does not make much sense. - * + * */ class SRFFiltered extends SMWResultPrinter { - + /** * The available view types - * @var array of Strings + * @var array of Strings */ private $mViewTypes = array( 'list' => 'SRF_FV_List', ); - + /** * The available filter types - * @var array of Strings + * @var array of Strings */ private $mFilterTypes = array( 'value' => 'SRF_FF_Value', ); - + private $mViews; private $mParams; - + public function hasTemplates ( $hasTemplates = null ) { $ret = $this->hasTemplates; if ( is_bool( $hasTemplates ) ) { @@ -84,7 +84,7 @@ protected function handleParameters( array $params, $outputmode ) { parent::handleParameters( $params, $outputmode ); - //// Set in SMWResultPrinter: + // // Set in SMWResultPrinter: // $this->mIntro = $params['intro']; // $this->mOutro = $params['outro']; // $this->mSearchlabel = $params['searchlabel'] === false ? null : $params['searchlabel']; @@ -94,42 +94,42 @@ // $this->mShowHeaders = SMW_HEADERS_HIDE | SMW_HEADERS_PLAIN | SMW_HEADERS_SHOW; $this->mSearchlabel = null; - + $this->mParams = $params; $this->mViews = array_map( 'trim', explode( ',', $params['views'] ) ); - + } /** * Return serialised results in specified format. */ protected function getResultText( SMWQueryResult $res, $outputmode ) { - + // collect the query results in an array $result = array(); while ( $row = $res->getNext() ) { $result[uniqid()] = new SRF_Filtered_Item( $row, $this ); } - + $resourceModules = array(); - + // prepare filter data for inclusion in HTML and JS $filterHtml = ''; $filterHandlers = array(); $filterData = array(); - + foreach ( $res->getPrintRequests() as $printRequest ) { $filter = $printRequest->getParameter( 'filter' ); if ( $filter ) { $filtersForPrintout = explode( ',', $filter ); - $filtersForPrintout = array_map('trim', $filtersForPrintout); - + $filtersForPrintout = array_map( 'trim', $filtersForPrintout ); + foreach ( $filtersForPrintout as $filterName ) { if ( array_key_exists( $filterName, $this->mFilterTypes ) ) { - - $filter = new $this->mFilterTypes[$filterName]( $result, $printRequest, $this); - + + $filter = new $this->mFilterTypes[$filterName]( $result, $printRequest, $this ); + $resourceModules = $filter->getResourceModules(); if ( is_array( $resourceModules ) ) { @@ -137,18 +137,18 @@ } elseif ( is_string( $resourceModules ) ) { SMWOutputs::requireResource( $resourceModules ); } - + $printRequestHash = md5( $printRequest->getHash() ); - $filterHtml .= Html::rawElement( 'div', array('class' => "filtered-$filterName $printRequestHash"), $filter->getResultText() ); - + $filterHtml .= Html::rawElement( 'div', array( 'class' => "filtered-$filterName $printRequestHash" ), $filter->getResultText() ); + $filterHandlers[$filterName] = null; $filterData[$filterName][$printRequestHash] = $filter->getJsData(); - + } } } } - + // wrap filters in a div $filterHtml = Html::rawElement( 'div', array( 'class' => 'filtered-filters' ), $filterHtml ); @@ -156,33 +156,33 @@ $viewHtml = ''; $viewHandlers = array(); $viewElements = array(); - + foreach ( $this->mViews as $viewName ) { if ( array_key_exists( $viewName, $this->mViewTypes ) ) { - + // generate unique id $viewid = uniqid(); $view = new $this->mViewTypes[$viewName]( $viewid, $result, $this->mParams, $this ); - + $resourceModules = $view->getResourceModules(); - + if ( is_array( $resourceModules ) ) { array_walk( $resourceModules, 'SMWOutputs::requireResource' ); } elseif ( is_string( $resourceModules ) ) { SMWOutputs::requireResource( $resourceModules ); } - - $viewHtml .= Html::rawElement( 'div', array('class' => "filtered-$viewName $viewid"), $view->getResultText() ); - + + $viewHtml .= Html::rawElement( 'div', array( 'class' => "filtered-$viewName $viewid" ), $view->getResultText() ); + $viewHandlers[$viewName] = null; $viewElements[$viewName][] = $viewid; } } - + // wrap views in a div $viewHtml = Html::rawElement( 'div', array( 'class' => 'filtered-views' ), $viewHtml ); - + // Define the srf_filtered_values array SMWOutputs::requireScript( 'srf_filtered_values', Html::inlineScript( 'srf_filtered_values = {};' @@ -199,23 +199,23 @@ Html::inlineScript( 'srf_filtered_values["' . $id . '"] = { "values":' . json_encode( $resultAsArray ) . ', "data": {' . - ' "viewhandlers" : ' . json_encode( $viewHandlers ) . - ', "viewelements" : ' . json_encode( $viewElements ) . - ', "filterhandlers" : ' . json_encode( $filterHandlers ) . - ', "filterdata" : ' . json_encode( $filterData ) . + ' "viewhandlers" : ' . json_encode( $viewHandlers ) . + ', "viewelements" : ' . json_encode( $viewElements ) . + ', "filterhandlers" : ' . json_encode( $filterHandlers ) . + ', "filterdata" : ' . json_encode( $filterData ) . '}};' ) ); - - SMWOutputs::requireResource('ext.srf.filtered'); + SMWOutputs::requireResource( 'ext.srf.filtered' ); + // wrap all in a div $html = Html::rawElement( 'div', array( 'class' => 'filtered ' . $id ), $filterHtml . $viewHtml ); - + return $html; } - + public function getParameters() { $params = array_merge( parent::getParameters(), parent::textDisplayParameters() ); @@ -225,14 +225,14 @@ $params['views']->setDefault( '' ); foreach ( $this->mViewTypes as $viewType ) { - $params = array_merge($params, call_user_func( array( $viewType, 'getParameters') ) ); + $params = array_merge( $params, call_user_func( array( $viewType, 'getParameters' ) ) ); } - + return $params; } public function getLinker( $firstcol = false, $force = false ) { return ( $force ) ? $this->mLinker : parent::getLinker( $firstcol ); } - + } Modified: trunk/extensions/SemanticResultFormats/Filtered/SRF_Filtered_Item.php =================================================================== --- trunk/extensions/SemanticResultFormats/Filtered/SRF_Filtered_Item.php 2012-03-04 10:38:06 UTC (rev 112972) +++ trunk/extensions/SemanticResultFormats/Filtered/SRF_Filtered_Item.php 2012-03-04 10:53:20 UTC (rev 112973) @@ -2,7 +2,7 @@ /** * File holding the SRF_Filtered_Item class - * + * * @author Stephan Gambke * @file * @ingroup SemanticResultFormats @@ -14,60 +14,60 @@ * @ingroup SemanticResultFormats */ class SRF_Filtered_Item { - + private $mResultArray; private $mItemData = array(); private $mQueryPrinter; - - public function __construct($resultArray, SRFFiltered &$queryPrinter) { + + public function __construct( $resultArray, SRFFiltered &$queryPrinter ) { $this->mResultArray = $resultArray; $this->mQueryPrinter = $queryPrinter; } - - public function setDataForView ( $viewId, &$data ){ + + public function setDataForView ( $viewId, &$data ) { $this->mItemData[$viewId] = $data; } - - public function unsetDataForView ( $viewId ){ - unset($this->mItemData[$viewId]); + + public function unsetDataForView ( $viewId ) { + unset( $this->mItemData[$viewId] ); } - - public function getDataForView ( $viewId ){ + + public function getDataForView ( $viewId ) { return $this->mItemData[$viewId]; } - + public function getValue() { return $this->mResultArray; } - + public function getArrayRepresentation() { - + $printouts = array(); - + foreach ( $this->mResultArray as $i => $field ) { - + $printRequest = $field->getPrintRequest(); $label = $printRequest->getLabel(); $type = $printRequest->getTypeID(); $params = $printRequest->getParameters(); - + $values = array(); - + $field->reset(); while ( ( $value = $field->getNextText( SMW_OUTPUT_WIKI, null ) ) !== false ) { $values[] = $value; } - - $printouts[ md5($printRequest->getHash()) ] = array( + + $printouts[ md5( $printRequest->getHash() ) ] = array( 'label' => $label, 'type' => $type, 'params' => $params, 'values' => $values, ); } - - + + return array( 'printouts' => $printouts, 'data' => $this->mItemData, Modified: trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_FF_Value.php =================================================================== --- trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_FF_Value.php 2012-03-04 10:38:06 UTC (rev 112972) +++ trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_FF_Value.php 2012-03-04 10:53:20 UTC (rev 112973) @@ -2,7 +2,7 @@ /** * File holding the SRF_FF_Value class - * + * * @author Stephan Gambke * @file * @ingroup SemanticResultFormats @@ -13,18 +13,18 @@ * * Available parameters for this filter: * value filter switches: switches to be shown for this filter; currently only 'and or' supported - * + * * @ingroup SemanticResultFormats */ class SRF_FF_Value extends SRF_Filtered_Filter { - + /** * Returns the HTML text that is to be included for this view. - * + * * This text will appear on the page in a div that has the view's id set as * class. - * - * @return string + * + * @return string */ public function getResultText() { return ''; @@ -33,28 +33,28 @@ /** * Returns the name (string) or names (array of strings) of the resource * modules to load. - * + * * @return string|array */ public function getResourceModules() { return 'ext.srf.filtered.value-filter'; } - + /** * Returns an array of config data for this filter to be stored in the JS - * @return null + * @return null */ public function getJsData() { $params = $this->getActualParameters(); if ( array_key_exists( 'value filter switches', $params ) ) { - $switches = explode(',', $params['value filter switches'] ); - $switches = array_map('trim', $switches ); - + $switches = explode( ',', $params['value filter switches'] ); + $switches = array_map( 'trim', $switches ); + return array( 'switches' => $switches ); } - + return null; } - + } Modified: trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_Filtered_Filter.php =================================================================== --- trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_Filtered_Filter.php 2012-03-04 10:38:06 UTC (rev 112972) +++ trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_Filtered_Filter.php 2012-03-04 10:53:20 UTC (rev 112973) @@ -2,7 +2,7 @@ /** * File holding the SRF_Filtered_Filter class - * + * * @author Stephan Gambke * @file * @ingroup SemanticResultFormats @@ -14,45 +14,45 @@ * @ingroup SemanticResultFormats */ abstract class SRF_Filtered_Filter { - + private $mResults = null; private $mPrintRequest = null; private $mQueryPrinter = null; - + public function __construct( &$results, SMWPrintRequest $printRequest, SRFFiltered &$queryPrinter ) { $this->mResults = $results; $this->mPrintRequest = $printRequest; $this->mQueryPrinter = $queryPrinter; } - public function &getQueryResults() {return $this->mResults;} - public function &getPrintRequest() {return $this->mPrintRequest;} - public function &getQueryPrinter() {return $this->mQueryPrinter;} - - + public function &getQueryResults() { return $this->mResults; } + public function &getPrintRequest() { return $this->mPrintRequest; } + public function &getQueryPrinter() { return $this->mQueryPrinter; } + + public function getActualParameters() { - + return $this->mPrintRequest->getParameters(); - + } - + /** * Returns the name (string) or names (array of strings) of the resource * modules to load. - * + * * @return string|array */ public function getResourceModules() { return null; } - + /** * Returns the HTML text that is to be included for this filter. - * + * * This text will appear on the page in a div that has the filter's id set * as class. - * - * @return string + * + * @return string */ public function getResultText() { return ''; @@ -60,7 +60,7 @@ /** * Returns an array of config data for this filter to be stored in the JS - * @return null + * @return null */ public function getJsData() { return null; Modified: trunk/extensions/SemanticResultFormats/Filtered/views/SRF_FV_List.php =================================================================== --- trunk/extensions/SemanticResultFormats/Filtered/views/SRF_FV_List.php 2012-03-04 10:38:06 UTC (rev 112972) +++ trunk/extensions/SemanticResultFormats/Filtered/views/SRF_FV_List.php 2012-03-04 10:53:20 UTC (rev 112973) @@ -2,7 +2,7 @@ /** * File holding the SRF_FV_List class - * + * * @author Stephan Gambke * @file * @ingroup SemanticResultFormats @@ -17,44 +17,44 @@ * list view introtemplate: a template prepended to the list * list view outrotemplate: a template appended to the list * list view named args: use named args for templates - * + * * @ingroup SemanticResultFormats */ class SRF_FV_List extends SRF_Filtered_View { - + private $mFormat, $mTemplate, $mIntroTemplate, $mOutroTemplate, $mNamedArgs, $mShowHeaders; - + /** * Transfers the parameters applicable to this view into internal variables. */ protected function handleParameters() { - + $params = $this->getActualParameters(); - + $this->mFormat = $params['list view type']; $this->mTemplate = $params['list view template']; $this->mIntroTemplate = $params['list view introtemplate']; $this->mOutroTemplate = $params['list view outrotemplate']; $this->mNamedArgs = $params['list view named args']; - + if ( $params['headers'] == 'hide' ) { $this->mShowHeaders = SMW_HEADERS_HIDE; } elseif ( $params['headers'] == 'plain' ) { $this->mShowHeaders = SMW_HEADERS_PLAIN; } else { $this->mShowHeaders = SMW_HEADERS_SHOW; - } + } } /** * Returns the wiki text that is to be included for this view. - * - * @return string + * + * @return string */ public function getResultText() { - + $this->handleParameters(); - + // Determine mark-up strings used around list items: if ( ( $this->mFormat == 'ul' ) || ( $this->mFormat == 'ol' ) ) { $header = "<" . $this->mFormat . ">\n"; @@ -69,13 +69,13 @@ $rowend = "</div>\n"; $listsep = ', '; } - + // Initialise more values $result = ''; if ( $header !== '' ) { $result .= $header; - } + } if ( $this->mIntroTemplate !== '' ) { $result .= "{{" . $this->mIntroTemplate . "}}"; @@ -83,32 +83,32 @@ // Now print each row $rownum = -1; - - foreach ($this->getQueryResults() as $id => $value) { + + foreach ( $this->getQueryResults() as $id => $value ) { $row = $value->getValue(); - + $this->printRow( $row, $rownum, $rowstart . $id . "' id='$id' >", $rowend, $result, $listsep ); } - + if ( $this->mOutroTemplate !== '' ) { $result .= "{{" . $this->mOutroTemplate . "}}"; } - + // Print footer if ( $footer !== '' ) { $result .= $footer; } - + return $result; } - + /** * Prints one row of a list view. */ protected function printRow( $row, &$rownum, $rowstart, $rowend, &$result, $listsep ) { $rownum++; - + $result .= $rowstart; if ( $this->mTemplate !== '' ) { // build template code @@ -116,28 +116,28 @@ // $wikitext = ( $this->mUserParam ) ? "|userparam=$this->mUserParam" : ''; $wikitext = ''; - + foreach ( $row as $i => $field ) { $wikitext .= '|' . ( $this->mNamedArgs ? '?' . $field->getPrintRequest()->getLabel() : $i + 1 ) . '='; $first_value = true; - + $field->reset(); while ( ( $text = $field->getNextText( SMW_OUTPUT_WIKI, $this->getQueryPrinter()->getLinker( $i == 0 ) ) ) !== false ) { if ( $first_value ) $first_value = false; else $wikitext .= ', '; $wikitext .= $text; } } - + $wikitext .= "|#=$rownum"; $result .= '{{' . $this->mTemplate . $wikitext . '}}'; } else { // build simple list $first_col = true; $found_values = false; // has anything but the first column been printed? - + foreach ( $row as $field ) { $first_value = true; - + while ( ( $text = $field->getNextText( SMW_OUTPUT_WIKI, $this->getQueryPrinter()->getLinker( $first_col ) ) ) !== false ) { if ( !$first_col && !$found_values ) { // first values after first column $result .= ' ('; @@ -146,64 +146,64 @@ // any value after '(' or non-first values on first column $result .= "$listsep "; } - + if ( $first_value ) { // first value in any column, print header $first_value = false; - + if ( ( $this->mShowHeaders != SMW_HEADERS_HIDE ) && ( $field->getPrintRequest()->getLabel() !== '' ) ) { - $result .= $field->getPrintRequest()->getText( SMW_OUTPUT_WIKI, ( $this->mShowHeaders == SMW_HEADERS_PLAIN ? null:$this->getQueryPrinter()->getLinker(true, true) ) ) . ' '; + $result .= $field->getPrintRequest()->getText( SMW_OUTPUT_WIKI, ( $this->mShowHeaders == SMW_HEADERS_PLAIN ? null:$this->getQueryPrinter()->getLinker( true, true ) ) ) . ' '; } } - + $result .= $text; // actual output value } - + $first_col = false; } - + if ( $found_values ) $result .= ')'; } - + $result .= $rowend; } - + /** * A function to describe the allowed parameters of a query for this view. - * + * * @return array of Parameter */ public static function getParameters() { $params = parent::getParameters(); - + $params['list view type'] = new Parameter( 'list type' ); $params['list view type']->setMessage( 'srf-paramdesc-filtered-list-type' ); - $params['list view type']->setDefault( 'list' ); - + $params['list view type']->setDefault( 'list' ); + $params['list view template'] = new Parameter( 'list template' ); $params['list view template']->setMessage( 'srf-paramdesc-filtered-list-template' ); - $params['list view template']->setDefault( '' ); - + $params['list view template']->setDefault( '' ); + $params['list view named args'] = new Parameter( 'list named args', Parameter::TYPE_BOOLEAN, false ); $params['list view named args']->setMessage( 'srf-paramdesc-filtered-list-named-args' ); - + $params['list view introtemplate'] = new Parameter( 'list introtemplate' ); - $params['list view introtemplate']->setMessage( 'srf-paramdesc-filtered-list-introtemplate' ); + $params['list view introtemplate']->setMessage( 'srf-paramdesc-filtered-list-introtemplate' ); $params['list view introtemplate']->setDefault( '' ); - + $params['list view outrotemplate'] = new Parameter( 'list outrotemplate' ); - $params['list view outrotemplate']->setMessage( 'srf-paramdesc-filtered-list-outrotemplate' ); + $params['list view outrotemplate']->setMessage( 'srf-paramdesc-filtered-list-outrotemplate' ); $params['list view outrotemplate']->setDefault( '' ); - + return $params; } /** * Returns the name of the resource module to load for this view. - * + * * @return string|array */ public function getResourceModules() { return 'ext.srf.filtered.list-view'; } - + } Modified: trunk/extensions/SemanticResultFormats/Filtered/views/SRF_Filtered_View.php =================================================================== --- trunk/extensions/SemanticResultFormats/Filtered/views/SRF_Filtered_View.php 2012-03-04 10:38:06 UTC (rev 112972) +++ trunk/extensions/SemanticResultFormats/Filtered/views/SRF_Filtered_View.php 2012-03-04 10:53:20 UTC (rev 112973) @@ -2,7 +2,7 @@ /** * File holding the SRF_Filtered_View class - * + * * @author Stephan Gambke * @file * @ingroup SemanticResultFormats @@ -14,15 +14,15 @@ * @ingroup SemanticResultFormats */ abstract class SRF_Filtered_View { - + private $mId; private $mResults; private $mParameters; private $mQueryPrinter; - + /** * Constructor for the view. - * + * * @param $id the view id * @param $results array of SRF_Filtered_Item containing the query results * @param type $params array of parameter values given as key-value-pairs @@ -33,25 +33,25 @@ $this->mParameters = $params; $this->mQueryPrinter = $queryPrinter; } - - public function getId() {return $this->mId;} - public function &getQueryResults() {return $this->mResults;} - public function &getActualParameters() {return $this->mParameters;} - public function &getQueryPrinter() {return $this->mQueryPrinter;} - + + public function getId() { return $this->mId; } + public function &getQueryResults() { return $this->mResults; } + public function &getActualParameters() { return $this->mParameters; } + public function &getQueryPrinter() { return $this->mQueryPrinter; } + /** * Returns the name (string) or names (array of strings) of the resource * modules to load. - * + * * @return string|array */ public function getResourceModules() { return null; } - + /** * A function to describe the allowed parameters of a query for this view. - * + * * @return array of Parameter */ public static function getParameters() { @@ -60,11 +60,11 @@ /** * Returns the HTML text that is to be included for this view. - * + * * This text will appear on the page in a div that has the view's id set as * class. - * - * @return string + * + * @return string */ public function getResultText() { return ''; _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs