Index: trunk/extensions/SemanticResultFormats/SRF_Settings.php |
— | — | @@ -21,15 +21,39 @@ |
22 | 22 | |
23 | 23 | # The formats you want to be able to use. |
24 | 24 | # See the INSTALL file or this url for more info: http://www.mediawiki.org/wiki/Extension:Semantic_Result_Formats#Installation |
25 | | -$srfgFormats = array( 'icalendar', 'vcard', 'bibtex', 'calendar', 'eventline', 'timeline', 'outline', 'gallery', 'jqplotbar', 'jqplotpie', 'sum', 'average', 'min', 'max', 'median', 'product', 'tagcloud', 'valuerank' ); |
| 25 | +$srfgFormats = array( 'icalendar', 'vcard', 'bibtex', 'calendar', 'eventline', 'timeline', 'outline', 'gallery', 'jqplotbar', 'jqplotpie', 'sum', 'average', 'min', 'max', 'median', 'product', 'tagcloud', 'valuerank', 'array' ); |
26 | 26 | |
| 27 | +# load hash format only if HashTables extension is initialised, otherwise 'Array' format is enough |
| 28 | +if( isset( $wgHashTables ) ) { |
| 29 | + $srfgFormats[] = 'hash'; |
| 30 | +} |
| 31 | + |
27 | 32 | # Used for jqplot formats. |
28 | 33 | $srfgJQPlotIncluded = false; |
29 | 34 | |
30 | 35 | # Used for Array and Hash formats. |
31 | 36 | # Allows value as string or object instances of Title or Article classes or an array |
32 | 37 | # where index 0 is the page title and 1 is the namespace-index (by default NS_MAIN) |
| 38 | +# also allows defining optional template-arguments by index 'args' as array where a |
| 39 | +# key represents an argument name and a keys associated value an argument value. |
33 | 40 | $srfgArraySep = ', '; |
34 | 41 | $srfgArrayPropSep = '<PROP>'; |
35 | 42 | $srfgArrayManySep = '<MANY>'; |
36 | 43 | $srfgArrayRecordSep = '<RCRD>'; |
| 44 | +$srfgArrayHeaderSep = ' '; |
| 45 | + |
| 46 | +/** |
| 47 | + * used if Array|Hash result format isn't used inline and the standard config values |
| 48 | + * defined in LocalSettings.php can't be used because they are page references which |
| 49 | + * can only be evaluated in inline queries |
| 50 | + * |
| 51 | + * @var Array |
| 52 | + */ |
| 53 | +$srfgArraySepTextualFallbacks = array ( |
| 54 | + 'sep' => $srfgArraySep, |
| 55 | + 'propsep' => $srfgArrayPropSep, |
| 56 | + 'manysep' => $srfgArrayManySep, |
| 57 | + 'recordsep' => $srfgArrayRecordSep, |
| 58 | + 'headersep' => $srfgArrayHeaderSep |
| 59 | +); |
| 60 | +$srfgArraySep = array( 'bla', NS_TEMPLATE ); |
Index: trunk/extensions/SemanticResultFormats/SRF_Messages.php |
— | — | @@ -105,14 +105,15 @@ |
106 | 106 | |
107 | 107 | // format "Array" and "Hash" |
108 | 108 | 'srf_printername_array' => 'Array', |
109 | | - 'srf_paramdesc_pagetitle' => 'Whether to show page titles as result entries or to hide them', |
110 | | - 'srf_paramdesc_hidegaps' => 'Whether to show empty property and record values separated by separators or to hide them', |
111 | | - 'srf_paramdesc_arrayname' => 'If given and ArrayExtension is available this will create an array with the specified name', |
| 109 | + 'srf_paramdesc_pagetitle' => 'Whether to show page titles as result entries or to leave them out', |
| 110 | + 'srf_paramdesc_hidegaps' => 'Whether to print requested but unavailable property and record values separated by separators or leaving them out', |
| 111 | + 'srf_paramdesc_arrayname' => 'If given and ArrayExtension is available this will create an array with the specified name (no visible output then)', |
112 | 112 | 'srf_paramdesc_propsep' => 'Separator between the requested properties', |
113 | | - 'srf_paramdesc_manysep' => 'Separator between many valued properties', |
| 113 | + 'srf_paramdesc_manysep' => 'Separator between many valued property values', |
114 | 114 | 'srf_paramdesc_recordsep' => 'Separator between values of record properties', |
| 115 | + 'srf_paramdesc_headersep' => 'Separator between property name and value if "headers" is set to "show" or "plain"', |
115 | 116 | 'srf_printername_hash' => 'Hash', |
116 | | - 'srf_paramdesc_hashname' => 'If given and the HashTables extension is available this will create an hash with the specified name', |
| 117 | + 'srf_paramdesc_hashname' => 'If given and the HashTables extension is available this will create a hash with the specified name (no visible output then)', |
117 | 118 | |
118 | 119 | // format "graph" |
119 | 120 | 'srf-printername-graph' => 'Graph', |
— | — | @@ -613,12 +614,13 @@ |
614 | 615 | 'srf_printername_array' => 'Datenfeld (Array)', |
615 | 616 | 'srf_paramdesc_pagetitle' => 'Legt fest ob Seitentitel in Auflistung mit aufgenommen werden soll', |
616 | 617 | 'srf_paramdesc_hidegaps' => 'Definiert ob auf einer Seite nicht vorhandene Werte einen leeren Listeneintrag erzeugen', |
617 | | - 'srf_paramdesc_arrayname' => 'Sofern die Erweiterung ArrayExtension verfügbar ist, wird ein Datenfeld (Array) mit diesem Namen angelegt', |
| 618 | + 'srf_paramdesc_arrayname' => 'Sofern die Erweiterung ArrayExtension vorhanden ist, wird anstelle einer sichtbaren Ausgabe ein Datenfeld (Array) mit diesem Namen angelegt', |
618 | 619 | 'srf_paramdesc_propsep' => 'Trennzeichen zwischen angeforderten Attributen', |
619 | 620 | 'srf_paramdesc_manysep' => 'Trennzeichen zwischen mehreren Werten die für ein Attribut angegeben sind', |
620 | 621 | 'srf_paramdesc_recordsep' => 'Trennzeichen zwischen einzelnen Werten eines Datenverbundattributs', |
| 622 | + 'srf_paramdesc_headersep' => 'Trennzeichen zwischen Attribut-Namen und -Wert falls „headers“ auf „show“ oder „plain“ gesetzt', |
621 | 623 | 'srf_printername_hash' => 'Assoziatives Datenfeld (Hash)', |
622 | | - 'srf_paramdesc_hashname' => 'Sofern die Erweiterung HashTables vorhanden ist wird ein assoziatives Datenfeld (Hash) mit diesem Namen angelegt', |
| 624 | + 'srf_paramdesc_hashname' => 'Sofern die Erweiterung HashTables vorhanden ist, wird anstelle einer sichtbaren Ausgabe ein assoziatives Datenfeld (Hash) mit diesem Namen angelegt', |
623 | 625 | 'srf-printername-graph' => 'Grafik', |
624 | 626 | 'srf-paramdesc-graph-relation' => 'Sind die Betreffe oder Namensattribute Haupt- oder Unterobjekte?', |
625 | 627 | 'srf-paramdesc-graph-nameprop' => 'Ermöglicht es ein Attribut festzulegen, das als Betreff anstelle des eigentlichen Betreffs genutzt wird', |
Index: trunk/extensions/SemanticResultFormats/Array/SRF_Array.php |
— | — | @@ -3,112 +3,43 @@ |
4 | 4 | * Query format for arrays with features for Extensions ArrayExtension and HashTables |
5 | 5 | * @file |
6 | 6 | * @ingroup SemanticResultFormats |
7 | | - * @author Daniel Werner |
| 7 | + * @author Daniel Werner < danweetz@web.de > |
8 | 8 | * |
9 | | - * Requires ArrayExtension 1.3.2 or higher and HashTables 0.6 or higher |
| 9 | + * Doesn't require ArrayExtension nor HashTables but has additional features |
| 10 | + * ('name' parameter in either result format) if they are available. |
| 11 | + * |
| 12 | + * ArrayExtension 1.3.2+ and HashTables 0.6+ are recommended but not necessary |
10 | 13 | */ |
11 | 14 | |
12 | 15 | /** |
13 | 16 | * Array format |
14 | 17 | */ |
15 | 18 | class SRFArray extends SMWResultPrinter { |
| 19 | + |
| 20 | + protected static $mDefaultSeps = array(); |
16 | 21 | protected $mSep; |
17 | 22 | protected $mPropSep; |
18 | 23 | protected $mManySep; |
19 | 24 | protected $mRecordSep; |
| 25 | + protected $mHeaderSep; |
20 | 26 | protected $mArrayName = null; |
21 | | - protected $mDeliverPageTitle = true; |
| 27 | + protected $mShowPageTitles; |
22 | 28 | |
23 | | - protected $mHideRecordGaps = false; |
24 | | - protected $mHidePropertyGaps = false; |
25 | | - |
26 | | - public function __construct( $format, $inline ) { |
27 | | - parent::__construct( $format, $inline ); |
28 | | - //overwrite default behavior for linking: |
| 29 | + protected $mHideRecordGaps; |
| 30 | + protected $mHidePropertyGaps; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var Boolean true if 'mainlabel' parameter is set to '-' |
| 34 | + */ |
| 35 | + protected $mMainLabelHack = false; |
| 36 | + |
| 37 | + public function __construct( $format, $inline, $useValidator = true ) { |
| 38 | + parent::__construct( $format, $inline, $useValidator ); |
| 39 | + //overwrite parent default behavior for linking: |
29 | 40 | $this->mLinkFirst = false; |
30 | 41 | $this->mLinkOthers = false; |
31 | | - |
32 | | - //initialize user configuration from localsettings or load default values: |
33 | | - $this->initializeUserConfig(); |
34 | 42 | } |
35 | | - |
36 | | - protected function initializeUserConfig() { |
37 | | - global $srfgArraySep, $srfgArrayPropSep, $srfgArrayManySep, $srfgArrayRecordSep, |
38 | | - $srfgArraySepDefault, $srfgArrayPropSepDefault, $srfgArrayManySepDefault, $srfgArrayRecordSepDefault; |
39 | 43 | |
40 | | - //Sep: |
41 | | - if( ! isset( $srfgArraySepDefault ) ) { |
42 | | - $srfgArraySepDefault = self::initializeDefaultSepText( $srfgArraySep ); |
43 | | - } $this->mSep = $srfgArraySepDefault; |
44 | | - //PropSep: |
45 | | - if( ! isset( $srfgArrayPropSepDefault ) ) { |
46 | | - $srfgArrayPropSepDefault = self::initializeDefaultSepText( $srfgArrayPropSep ); |
47 | | - } $this->mPropSep = $srfgArrayPropSepDefault; |
48 | | - //ManySep: |
49 | | - if( ! isset( $srfgArrayManySepDefault ) ) { |
50 | | - $srfgArrayManySepDefault = self::initializeDefaultSepText( $srfgArrayManySep ); |
51 | | - } $this->mManySep = $srfgArrayManySepDefault; |
52 | | - //Sep: |
53 | | - if( ! isset( $srfgArrayRecordSepDefault ) ) { |
54 | | - $srfgArrayRecordSepDefault = self::initializeDefaultSepText( $srfgArrayRecordSep ); |
55 | | - } $this->mRecordSep = $srfgArrayRecordSepDefault; |
56 | | - |
57 | | - } |
58 | | - |
59 | | - static function initializeDefaultSepText( $obj ) { |
60 | | - if( is_array( $obj ) ) { |
61 | | - if( ! array_key_exists( 0, $obj ) ) |
62 | | - return ''; |
63 | | - $obj = Title::newFromText( $obj[0], ( array_key_exists( 1, $obj ) ? $obj[1] : NS_MAIN ) ); |
64 | | - } |
65 | | - if( $obj instanceof Title ) { |
66 | | - $article = new Article( $obj ); |
67 | | - } elseif( $obj instanceof Article ) { |
68 | | - $article = obj; |
69 | | - } else { |
70 | | - return $obj; //only text |
71 | | - } |
72 | | - global $wgParser; |
73 | | - return trim( $wgParser->recursiveTagParse( $article->getRawText() ) ); //return rendered text from page |
74 | | - } |
75 | | - |
76 | | - protected function readParameters( $params, $outputmode ) { |
77 | | - parent::readParameters( $params, $outputmode ); |
78 | | - |
79 | | - //separators: |
80 | | - if( array_key_exists('sep', $params) ) $this->mSep = trim( $params['sep'] ); |
81 | | - if( array_key_exists('propsep', $params) ) $this->mPropSep = trim( $params['propsep'] ); |
82 | | - if( array_key_exists('manysep', $params) ) $this->mManySep = trim( $params['manysep'] ); |
83 | | - if( array_key_exists('recordsep', $params) ) $this->mRecordSep = trim( $params['recordsep'] ); |
84 | | - |
85 | | - if( array_key_exists( 'name', $params ) ) |
86 | | - $this->mArrayName = trim( $params['name'] ); |
87 | | - |
88 | | - if( array_key_exists( 'pagetitle', $params ) ) |
89 | | - $this->mDeliverPageTitle = !( trim( strtolower( $params['pagetitle'] ) ) == 'hide' ); |
90 | | - |
91 | | - if( array_key_exists( 'hidegaps', $params ) ) { |
92 | | - switch( trim( strtolower( $params['hidegaps'] ) ) ) { |
93 | | - case 'none': |
94 | | - $this->mHideRecordGaps = false; |
95 | | - $this->mHidePropertyGaps = false; |
96 | | - break; |
97 | | - case 'all': |
98 | | - $this->mHideRecordGaps = true; |
99 | | - $this->mHidePropertyGaps = true; |
100 | | - break; |
101 | | - case 'property': case 'prop': case 'attribute': case 'attr': |
102 | | - $this->mHideRecordGaps = false; |
103 | | - $this->mHidePropertyGaps = true; |
104 | | - break; |
105 | | - case 'record': case 'rec': case 'n-ary': case 'nary': |
106 | | - $this->mHideRecordGaps = true; |
107 | | - $this->mHidePropertyGaps = false; |
108 | | - break; |
109 | | - } |
110 | | - } |
111 | | - } |
112 | | - |
113 | 44 | public function getQueryMode($context) { |
114 | 45 | return SMWQuery::MODE_INSTANCES; |
115 | 46 | } |
— | — | @@ -116,6 +47,14 @@ |
117 | 48 | public function getName() { |
118 | 49 | return wfMsg( 'srf_printername_' . $this->mFormat ); |
119 | 50 | } |
| 51 | + |
| 52 | + /* |
| 53 | + // By overwriting this function, we disable default searchlabel handling? |
| 54 | + public function getResult( SMWQueryResult $results, array $params, $outputmode ) { |
| 55 | + $this->handleParameters( $params, $outputmode ); |
| 56 | + return $this->getResultText( $results, $outputmode ); |
| 57 | + } |
| 58 | + */ |
120 | 59 | |
121 | 60 | protected function getResultText( SMWQueryResult $res, $outputmode ) { |
122 | 61 | /* |
— | — | @@ -129,57 +68,68 @@ |
130 | 69 | //for each page: |
131 | 70 | while( $row = $res->getNext() ) { |
132 | 71 | $perProperty_items = array(); |
133 | | - $isPageTitle = true; //first field is always the page title; |
134 | 72 | |
| 73 | + /** |
| 74 | + * first field is always the page title, except, mainlabel is set to '-' |
| 75 | + * @ToDo: Is there some other way to check the data value directly for being the |
| 76 | + * page title or not? SMWs behavior could change on mainlabel handling... |
| 77 | + */ |
| 78 | + $isPageTitle = !$this->mMainLabelHack; |
| 79 | + |
135 | 80 | //for each property on that page: |
136 | 81 | foreach( $row as $field ) { // $row is array(), $field of type SMWResultArray |
137 | 82 | $manyValue_items = array(); |
138 | | - $missingProperty = false; |
| 83 | + $isMissingProperty = false; |
139 | 84 | |
140 | 85 | $manyValues = $field->getContent(); |
141 | 86 | |
142 | 87 | //If property is not set (has no value) on a page: |
143 | | - if( count( $manyValues ) < 1 ) { |
| 88 | + if( empty( $manyValues ) ) { |
144 | 89 | $delivery = $this->deliverMissingProperty( $field ); |
145 | 90 | $manyValue_items = $this->fillDeliveryArray( $manyValue_items, $delivery ); |
146 | | - $missingProperty = true; |
| 91 | + $isMissingProperty = true; |
147 | 92 | } else |
148 | | - //otherwise collect property value (potentially many values) |
149 | | - while( $obj = $field->getNextDataValue() ) { // $manyValues of type SMWResultArray, contains many values (or just one) of one property of type SMWDataValue |
| 93 | + //otherwise collect property value (potentially many values): |
| 94 | + while( $obj = $field->getNextDataValue() ) { |
150 | 95 | |
151 | 96 | $value_items = array(); |
| 97 | + $isRecord = false; |
152 | 98 | |
153 | | - if( $isPageTitle ) { |
154 | | - $isPageTitle = false; |
155 | | - if( ! $this->mDeliverPageTitle ) { |
| 99 | + // handle page Title: |
| 100 | + if( $isPageTitle ) { |
| 101 | + if( ! $this->mShowPageTitles ) { |
| 102 | + $isPageTitle = false; |
156 | 103 | continue 2; //next property |
| 104 | + } |
| 105 | + $value_items = $this->fillDeliveryArray( $value_items, $this->deliverPageTitle( $obj, $this->mLinkFirst ) ); |
| 106 | + } |
| 107 | + // handle record values: |
| 108 | + elseif( $obj instanceof SMWRecordValue ) { |
| 109 | + $recordItems = $obj->getDataItems(); |
| 110 | + // walk all single values of the record set: |
| 111 | + foreach( $recordItems as $dataItem ) { |
| 112 | + $recordField = $dataItem !== null ? SMWDataValueFactory::newDataItemValue( $dataItem, null ) : null; |
| 113 | + $value_items = $this->fillDeliveryArray( $value_items, $this->deliverRecordField( $recordField, $this->mLinkOthers ) ); |
157 | 114 | } |
158 | | - $value_items = $this->fillDeliveryArray( $value_items, $this->deliverPageTitle( $obj, $this->mLinkFirst ) ); |
159 | | - $isRecord = false; |
160 | | - } elseif( $obj instanceof SMWRecordValue ) { |
161 | | - $record = $obj->getDVs(); |
162 | | - $recordLength = count( $obj->getTypeValues() ); |
163 | | - for( $i = 0; $i < $recordLength; $i++ ) { |
164 | | - $recordField = $record[$i]; |
165 | | - $value_items = $this->fillDeliveryArray( $value_items, $this->deliverRecordField( $recordField, $this->mLinkOthers ) ); |
166 | | - } |
167 | 115 | $isRecord = true; |
168 | | - } else { |
| 116 | + } |
| 117 | + // handle normal data values: |
| 118 | + else { |
169 | 119 | $value_items = $this->fillDeliveryArray( $value_items, $this->deliverSingleValue( $obj, $this->mLinkOthers ) ); |
170 | | - $isRecord = false; |
171 | 120 | } |
172 | | - $delivery = $this->deliverSingleManyValuesData( $value_items, $isRecord ); |
| 121 | + $delivery = $this->deliverSingleManyValuesData( $value_items, $isRecord, $isPageTitle ); |
173 | 122 | $manyValue_items = $this->fillDeliveryArray( $manyValue_items, $delivery ); |
174 | 123 | } // foreach... |
175 | | - $delivery = $this->deliverPropertiesManyValues( $manyValue_items, $missingProperty ); |
| 124 | + $delivery = $this->deliverPropertiesManyValues( $manyValue_items, $isMissingProperty, $isPageTitle, $field ); |
176 | 125 | $perProperty_items = $this->fillDeliveryArray( $perProperty_items, $delivery ); |
| 126 | + $isPageTitle = false; // next one could be record or normal value |
177 | 127 | } // foreach... |
178 | 128 | $delivery = $this->deliverPageProperties( $perProperty_items ); |
179 | 129 | $perPage_items = $this->fillDeliveryArray( $perPage_items, $delivery ); |
180 | 130 | } // while... |
181 | 131 | |
182 | 132 | $output = $this->deliverQueryResultPages( $perPage_items ); |
183 | | - |
| 133 | + |
184 | 134 | return $output; |
185 | 135 | } |
186 | 136 | |
— | — | @@ -194,37 +144,46 @@ |
195 | 145 | return $this->deliverSingleValue( $value, $link ); |
196 | 146 | } |
197 | 147 | protected function deliverRecordField( $value, $link = false ) { |
198 | | - if( $value !== null ) //void value (null) |
| 148 | + if( $value !== null ) // contains value |
199 | 149 | return $this->deliverSingleValue( $value, $link ); |
200 | 150 | elseif( $this->mHideRecordGaps ) |
201 | | - return null; //hide empty entry |
| 151 | + return null; // hide gap |
202 | 152 | else |
203 | | - return ''; //empty string will make sure that array separator will be generated (for record separators) |
| 153 | + return ''; // empty string will make sure that record value separators are generated |
204 | 154 | } |
205 | 155 | protected function deliverSingleValue( $value, $link = false ) { |
| 156 | + //return trim( $value->getShortWikiText( $link ) ); |
206 | 157 | return trim( Sanitizer::decodeCharReferences( $value->getShortWikiText( $link ) ) ); // decode: better for further processing with array extension |
207 | 158 | } |
208 | 159 | // Property not declared on a page: |
209 | | - protected function deliverMissingProperty( $field ) { |
| 160 | + protected function deliverMissingProperty( SMWResultArray $field ) { |
210 | 161 | if( $this->mHidePropertyGaps ) |
211 | 162 | return null; |
212 | 163 | else |
213 | 164 | return ''; //empty string will make sure that array separator will be generated |
214 | | - //@ToDo: System for Default values... |
| 165 | + /** @ToDo: System for Default values?... **/ |
215 | 166 | } |
216 | 167 | //represented by an array of record fields or just a single array value: |
217 | | - protected function deliverSingleManyValuesData( $value_items, $containsRecord = false ) { |
218 | | - if( count( $value_items ) < 1 ) //happens when one of the higher functions delivers null |
| 168 | + protected function deliverSingleManyValuesData( $value_items, $containsRecord, $isPageTitle ) { |
| 169 | + if( empty( $value_items ) ) //happens when one of the higher functions delivers null |
219 | 170 | return null; |
220 | 171 | return implode( $this->mRecordSep, $value_items ); |
221 | 172 | } |
222 | | - protected function deliverPropertiesManyValues( $manyValue_items, $propertyIsMissing = false ) { |
223 | | - if( count( $manyValue_items ) < 1 ) |
| 173 | + protected function deliverPropertiesManyValues( $manyValue_items, $isMissingProperty, $isPageTitle, SMWResultArray $data ) { |
| 174 | + if( empty( $manyValue_items ) ) |
224 | 175 | return null; |
225 | | - return implode( $this->mManySep, $manyValue_items ); |
| 176 | + |
| 177 | + $text = implode( $this->mManySep, $manyValue_items ); |
| 178 | + |
| 179 | + // if property names should be displayed and this is not the page titles value: |
| 180 | + if( $this->mShowHeaders != SMW_HEADERS_HIDE && ! $isPageTitle ) { |
| 181 | + $linker = $this->mShowHeaders == SMW_HEADERS_PLAIN ? null : $this->mLinker; |
| 182 | + $text = $data->getPrintRequest()->getText( SMW_OUTPUT_WIKI, $linker ) . $this->mHeaderSep . $text; |
| 183 | + } |
| 184 | + return $text; |
226 | 185 | } |
227 | 186 | protected function deliverPageProperties( $perProperty_items ) { |
228 | | - if( count( $perProperty_items ) < 1 ) |
| 187 | + if( empty( $perProperty_items ) ) |
229 | 188 | return null; |
230 | 189 | return implode( $this->mPropSep, $perProperty_items ); |
231 | 190 | } |
— | — | @@ -237,46 +196,199 @@ |
238 | 197 | } |
239 | 198 | } |
240 | 199 | |
241 | | - protected function createArray( $arr ) { |
| 200 | + protected function createArray( $array ) { |
242 | 201 | global $wgArrayExtension; |
243 | 202 | |
244 | 203 | if( ! isset( $wgArrayExtension ) ) { |
245 | 204 | //Hash extension is not installed in this wiki |
246 | 205 | return false; |
247 | | - } |
| 206 | + } |
| 207 | + $version = null; |
| 208 | + if( defined( 'ArrayExtension::VERSION' ) ) { |
| 209 | + $version = ArrayExtension::VERSION; |
| 210 | + } elseif( defined( 'ExtArrayExtension::VERSION' ) ) { |
| 211 | + $version = ExtArrayExtension::VERSION; |
| 212 | + } |
| 213 | + if( $version !== null && version_compare( $version, '1.3.2', '>=' ) ) { |
| 214 | + $wgArrayExtension->createArray( $this->mArrayName, $array ); //requires Extension:ArrayExtension 1.3.2 or higher |
| 215 | + } else { |
| 216 | + $wgArrayExtension->mArrayExtension[ trim( $this->mArrayName ) ] = $array; |
| 217 | + } |
| 218 | + return true; |
| 219 | + } |
| 220 | + |
| 221 | + protected function initializeCfgValue( $dfltVal, $dfltCacheKey ) { |
| 222 | + $cache = &self::$mDefaultSeps[ $dfltCacheKey ]; |
| 223 | + if( ! isset( $cache ) ) { |
| 224 | + $cache = $this->getCfgSepText( $dfltVal ); |
| 225 | + if( $cache === null ) { |
| 226 | + // cache can't be initialized, propably function-reference in userconfig |
| 227 | + // but format is not used in inline context, use fallback in this case: |
| 228 | + global $srfgArraySepTextualFallbacks; |
| 229 | + $cache = $srfgArraySepTextualFallbacks[ $dfltCacheKey ]; |
| 230 | + } |
| 231 | + } |
| 232 | + return $cache; |
| 233 | + } |
| 234 | + protected function getCfgSepText( $obj ) { |
| 235 | + if( is_array( $obj ) ) { |
| 236 | + // invalid definition: |
| 237 | + if( ! array_key_exists( 0, $obj ) ) |
| 238 | + return null; |
| 239 | + |
| 240 | + // check for config-defined arguments to pass to the page before processing it: |
| 241 | + if( array_key_exists( 'args', $obj ) && is_array( $obj['args'] ) ) |
| 242 | + $params = $obj['args']; |
| 243 | + else |
| 244 | + $params = array(); // no arguments |
248 | 245 | |
249 | | - $arrExtClass = new ReflectionClass( get_class( $wgArrayExtension ) ); |
| 246 | + // create title of page whose text should be used as separator: |
| 247 | + $obj = Title::newFromText( $obj[0], ( array_key_exists( 1, $obj ) ? $obj[1] : NS_MAIN ) ); |
| 248 | + } |
| 249 | + if( $obj instanceof Title ) { |
| 250 | + $article = new Article( $obj ); |
| 251 | + } elseif( $obj instanceof Article ) { |
| 252 | + $article = obj; |
| 253 | + } else { |
| 254 | + return $obj; //only text |
| 255 | + } |
250 | 256 | |
251 | | - $wgArrayExtension->createArray( $this->mArrayName, $arr ); |
| 257 | + global $wgParser; |
| 258 | + /* |
| 259 | + * Feature to use page value as separator only works if Parser::parse() is running! |
| 260 | + * That's not the case on semantic search special page for example! |
| 261 | + */ |
| 262 | + // can't use $this->mInline here since SMW 1.6.2 had a bug setting it to false in most cases! |
| 263 | + if( ! isset( $wgParser->mOptions ) ) { |
| 264 | + //if( ! $this->mInline ) { |
| 265 | + return null; |
| 266 | + } |
252 | 267 | |
253 | | - return true; |
| 268 | + /* |
| 269 | + * parse page as if it were included like a template. Never use Parser::recursiveTagParse() or similar |
| 270 | + * for this since it would call hooks we don't want to call and won't return wiki text for inclusion! |
| 271 | + */ |
| 272 | + $frame = $wgParser->getPreprocessor()->newCustomFrame( $params ); |
| 273 | + $text = $wgParser->preprocessToDom( $article->getRawText(), Parser::PTD_FOR_INCLUSION ); |
| 274 | + $text = trim( $frame->expand( $text ) ); |
| 275 | + |
| 276 | + return $text; |
254 | 277 | } |
255 | 278 | |
256 | | - public function getParameters() { |
257 | | - return array ( |
258 | | - array( 'name' => 'limit', 'type' => 'int', 'description' => wfMsg( 'smw_paramdesc_limit' ) ), |
259 | | - |
260 | | - array( 'name' => 'link', 'type' => 'enumeration', 'description' => wfMsg( 'smw_paramdesc_link' ), 'values' => array( 'all', 'subject', 'none' ) ), |
261 | | - array( 'name' => 'pagetitle', 'type' => 'enumeration', 'description' => wfMsg( 'srf_paramdesc_pagetitle' ), 'values' => array( 'show', 'hide' ) ), |
262 | | - array( 'name' => 'hidegaps', 'type' => 'enumeration', 'description' => wfMsg( 'srf_paramdesc_hidegaps' ), 'values' => array( 'none', 'all', 'property', 'record' ) ), |
263 | | - |
264 | | - array( 'name' => 'name', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_arrayname' ) ), |
265 | | - array( 'name' => 'sep', 'type' => 'string', 'description' => wfMsg( 'smw_paramdesc_sep' ) ), |
266 | | - array( 'name' => 'propsep', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_propsep' ) ), |
267 | | - array( 'name' => 'manysep', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_manysep' ) ), |
268 | | - array( 'name' => 'recordsep', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_recordsep' ) ), |
269 | | - ); |
| 279 | + protected function handleParameters( array $params, $outputmode ) { |
| 280 | + // does the link parameter: |
| 281 | + parent::handleParameters( $params, $outputmode ); |
| 282 | + |
| 283 | + $wgParser; |
| 284 | + //die( isset( $wgParser->mOptions ) ); |
| 285 | + |
| 286 | + //separators: |
| 287 | + $this->mSep = $params['sep']; |
| 288 | + $this->mPropSep = $params['propsep']; |
| 289 | + $this->mManySep = $params['manysep']; |
| 290 | + $this->mRecordSep = $params['recordsep']; |
| 291 | + $this->mHeaderSep = $params['headersep']; |
| 292 | + |
| 293 | + // only use this in inline mode, if text is given. Since SMW 1.6.2 '' is given, so if |
| 294 | + // we wouldn't check, we would always end up with an array instead of visible output |
| 295 | + if( $params['name'] !== false && ( $this->mInline || trim( $params['name'] ) !== '' ) ) { |
| 296 | + $this->mArrayName = trim( $params['name'] ); |
| 297 | + $this->createArray( array() ); //create empty array in case we get no result so we won't have an undefined array in the end. |
| 298 | + } |
| 299 | + |
| 300 | + // if mainlabel set to '-', this will cause the titles not to appear, so make sure we catch this! |
| 301 | + $this->mMainLabelHack = trim( $params['mainlabel'] ) === '-'; |
| 302 | + |
| 303 | + // whether or not to display the page title: |
| 304 | + $this->mShowPageTitles = strtolower( $params['titles'] ) != 'hide'; |
| 305 | + |
| 306 | + switch( strtolower( $params['hidegaps'] ) ) { |
| 307 | + case 'none': |
| 308 | + $this->mHideRecordGaps = false; |
| 309 | + $this->mHidePropertyGaps = false; |
| 310 | + break; |
| 311 | + case 'all': |
| 312 | + $this->mHideRecordGaps = true; |
| 313 | + $this->mHidePropertyGaps = true; |
| 314 | + break; |
| 315 | + case 'property': case 'prop': case 'attribute': case 'attr': |
| 316 | + $this->mHideRecordGaps = false; |
| 317 | + $this->mHidePropertyGaps = true; |
| 318 | + break; |
| 319 | + case 'record': case 'rec': case 'rcrd': case 'n-ary': case 'nary': |
| 320 | + $this->mHideRecordGaps = true; |
| 321 | + $this->mHidePropertyGaps = false; |
| 322 | + break; |
| 323 | + } |
270 | 324 | } |
| 325 | + |
| 326 | + public function getParameters() { |
| 327 | + global $smwgQMaxInlineLimit; |
| 328 | + |
| 329 | + $params = array(); |
| 330 | + $dfltParams = SMWQueryProcessor::getParameters(); |
| 331 | + |
| 332 | + ### adjusted basic SMW params: ### |
| 333 | + |
| 334 | + $params['limit'] = $dfltParams['limit']; |
| 335 | + $params['limit']->setDefault( $smwgQMaxInlineLimit ); |
| 336 | + |
| 337 | + $params['link'] = $dfltParams['link']; |
| 338 | + $params['link']->setDefault( 'none' ); |
| 339 | + |
| 340 | + $params['headers'] = $dfltParams['headers']; |
| 341 | + $params['headers']->setDefault( 'hide' ); |
| 342 | + |
| 343 | + ### new params: ### |
| 344 | + |
| 345 | + $params['titles'] = new Parameter( 'titles' ); |
| 346 | + $params['titles']->setMessage( 'srf_paramdesc_pagetitle' ); |
| 347 | + $params['titles']->addCriteria( new CriterionInArray( 'show', 'hide' ) ); |
| 348 | + $params['titles']->addAliases( 'pagetitle', 'pagetitles' ); |
| 349 | + $params['titles']->setDefault( 'show' ); |
| 350 | + |
| 351 | + $params['hidegaps'] = new Parameter( 'hidegaps' ); |
| 352 | + $params['hidegaps']->setMessage( 'srf_paramdesc_hidegaps' ); |
| 353 | + $params['hidegaps']->addCriteria( new CriterionInArray( 'none', 'all', 'property', 'record' ) ); |
| 354 | + $params['hidegaps']->setDefault( 'none' ); |
| 355 | + |
| 356 | + # name to create 'real' array with if set (empty string '' counts as set!): |
| 357 | + $params['name'] = new Parameter( 'name' ); |
| 358 | + $params['name']->setMessage( 'srf_paramdesc_arrayname' ); |
| 359 | + $params['name']->setDefault( false, false ); |
| 360 | + |
| 361 | + # separators (default values are defined in the following globals:) |
| 362 | + global $srfgArraySep, $srfgArrayPropSep, $srfgArrayManySep, $srfgArrayRecordSep, $srfgArrayHeaderSep; |
| 363 | + |
| 364 | + $params['sep'] = new Parameter( 'sep' ); |
| 365 | + $params['sep']->setMessage( 'smw_paramdesc_sep' ); |
| 366 | + $params['sep']->setDefault( $this->initializeCfgValue( $srfgArraySep, 'sep' ) ); |
| 367 | + |
| 368 | + $params['propsep'] = new Parameter( 'propsep' ); |
| 369 | + $params['propsep']->setMessage( 'srf_paramdesc_propsep' ); |
| 370 | + $params['propsep']->setDefault( $this->initializeCfgValue( $srfgArrayPropSep, 'propsep' ) ); |
| 371 | + |
| 372 | + $params['manysep'] = new Parameter( 'manysep' ); |
| 373 | + $params['manysep']->setMessage( 'srf_paramdesc_manysep' ); |
| 374 | + $params['manysep']->setDefault( $this->initializeCfgValue( $srfgArrayManySep, 'manysep' ) ); |
| 375 | + |
| 376 | + $params['recordsep'] = new Parameter( 'recordsep' ); |
| 377 | + $params['recordsep']->setMessage( 'srf_paramdesc_recordsep' ); |
| 378 | + $params['recordsep']->addAliases( 'narysep', 'rcrdsep', 'recsep' ); |
| 379 | + $params['recordsep']->setDefault( $this->initializeCfgValue( $srfgArrayRecordSep, 'recordsep' ) ); |
| 380 | + |
| 381 | + $params['headersep'] = new Parameter( 'headersep' ); |
| 382 | + $params['headersep']->setMessage( 'srf_paramdesc_headersep' ); |
| 383 | + $params['headersep']->addAliases( 'narysep', 'rcrdsep', 'recsep' ); |
| 384 | + $params['headersep']->setDefault( $this->initializeCfgValue( $srfgArrayHeaderSep, 'headersep' ) ); |
| 385 | + |
| 386 | + return $params; |
| 387 | + } |
271 | 388 | } |
272 | 389 | |
273 | | - |
274 | | -class SRFHash extends SRFArray { |
| 390 | +class SRFHash extends SRFArray { |
275 | 391 | protected $mLastPageTitle; |
276 | 392 | |
277 | | - protected function readParameters( $params, $outputmode ) { |
278 | | - parent::readParameters( $params, $outputmode ); |
279 | | - $this->mDeliverPageTitle = true; |
280 | | - } |
281 | 393 | protected function deliverPageTitle( $value, $link = false ) { |
282 | 394 | $this->mLastPageTitle = $this->deliverSingleValue( $value, $link ); //remember the page title |
283 | 395 | return null; //don't add page title into property list |
— | — | @@ -300,26 +412,31 @@ |
301 | 413 | //Hash extension is not installed in this wiki |
302 | 414 | return false; |
303 | 415 | } |
304 | | - |
305 | 416 | $hashExtClass = new ReflectionClass( get_class( $wgHashTables ) ); |
306 | 417 | |
307 | | - $wgHashTables->createHash( $this->mArrayName, $hash ); |
308 | | - |
| 418 | + $version = null; |
| 419 | + if( defined( 'ExtHashTables::VERSION' ) ) { |
| 420 | + $version = ExtHashTables::VERSION; |
| 421 | + } |
| 422 | + if( $version !== null && version_compare( $version, '0.6', '>=' ) ) { |
| 423 | + $wgHashTables->createHash( $this->mArrayName, $hash ); //requires Extension:HashTables 0.6 or higher |
| 424 | + } else { |
| 425 | + $wgHashTables->mHashTables[ trim( $this->mArrayName ) ] = $hash; //dirty way |
| 426 | + } |
309 | 427 | return true; |
310 | 428 | } |
311 | 429 | |
| 430 | + protected function handleParameters( array $params, $outputmode ) { |
| 431 | + parent::handleParameters( $params, $outputmode ); |
| 432 | + $this->mShowPageTitles = true; |
| 433 | + } |
| 434 | + |
312 | 435 | public function getParameters() { |
313 | | - return array ( |
314 | | - array( 'name' => 'limit', 'type' => 'int', 'description' => wfMsg( 'smw_paramdesc_limit' ) ), |
315 | | - |
316 | | - array( 'name' => 'link', 'type' => 'enumeration', 'description' => wfMsg( 'smw_paramdesc_link' ), 'values' => array( 'all', 'subject', 'none' ) ), |
317 | | - array( 'name' => 'hidegaps', 'type' => 'enumeration', 'description' => wfMsg( 'srf_paramdesc_hidegaps' ), 'values' => array( 'none', 'all', 'property', 'record' ) ), |
318 | | - |
319 | | - array( 'name' => 'name', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_hashname' ) ), |
320 | | - array( 'name' => 'sep', 'type' => 'string', 'description' => wfMsg( 'smw_paramdesc_sep' ) ), |
321 | | - array( 'name' => 'propsep', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_propsep' ) ), |
322 | | - array( 'name' => 'manysep', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_manysep' ) ), |
323 | | - array( 'name' => 'recordsep', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_recordsep' ) ), |
324 | | - ); |
| 436 | + $params = parent::getParameters(); |
| 437 | + |
| 438 | + unset( $params['pagetitle'] ); // page title is Hash key, otherwise, just use Array format! |
| 439 | + $params['name']->setMessage( 'srf_paramdesc_hashname' ); |
| 440 | + |
| 441 | + return $params; |
325 | 442 | } |
326 | 443 | } |