2222class LuaAskResultProcessor {
2323
2424 /**
25- * Holds all possible representations of "true" in this smw instance
26- *
27- * @var array
25+ * Cached representations of "true" — shared across all processor instances
26+ * within a request because the message bundle is request-stable.
2827 */
29- private $ msgTrue ;
28+ private static ? array $ msgTrue = null ;
3029
3130 /**
32- * This counter serves as fallback, if no label for printout is specified
33- *
34- * @var int
31+ * Fallback index for printouts without a label.
3532 */
36- private $ numericIndex ;
33+ private int $ numericIndex ;
3734
38- /**
39- * Holds the query result for this object
40- *
41- * @var QueryResult
42- */
43- private $ queryResult ;
35+ private QueryResult $ queryResult ;
36+
37+ private readonly Linker $ linker ;
4438
4539 /**
46- * LuaAskResultProcessor constructor.
40+ * Memoised PrintRequest labels, keyed by spl_object_id.
41+ * Per-processor (i.e. per-ask-call) scope.
4742 *
48- * @param QueryResult $queryResult
43+ * @var array<int, int|string>
4944 */
45+ private array $ printRequestLabels = [];
46+
5047 public function __construct ( QueryResult $ queryResult ) {
5148 $ this ->queryResult = $ queryResult ;
52- $ this ->msgTrue = explode ( ', ' , wfMessage ( 'smw_true_words ' )->text () . ',true,t,yes,y ' );
49+ if ( self ::$ msgTrue === null ) {
50+ self ::$ msgTrue = explode ( ', ' , wfMessage ( 'smw_true_words ' )->text () . ',true,t,yes,y ' );
51+ }
5352 $ this ->numericIndex = 1 ;
53+ $ this ->linker = new Linker ();
5454 }
5555
5656 /**
@@ -138,11 +138,15 @@ public function getDataFromResultArray( ResultArray $resultArray ) {
138138 * @return int|string
139139 */
140140 public function getKeyFromPrintRequest ( PrintRequest $ printRequest ) {
141- if ( $ printRequest ->getLabel () !== '' ) {
142- return $ printRequest ->getText ( SMW_OUTPUT_WIKI );
141+ $ id = spl_object_id ( $ printRequest );
142+ if ( isset ( $ this ->printRequestLabels [$ id ] ) ) {
143+ return $ this ->printRequestLabels [$ id ];
143144 }
144-
145- return $ this ->getNumericIndex ();
145+ $ label = $ printRequest ->getLabel () !== ''
146+ ? $ printRequest ->getText ( SMW_OUTPUT_WIKI )
147+ : $ this ->getNumericIndex ();
148+ $ this ->printRequestLabels [$ id ] = $ label ;
149+ return $ label ;
146150 }
147151
148152 /**
@@ -157,7 +161,7 @@ public function getValueFromDataValue( DataValue $dataValue ) {
157161 switch ( $ dataValue ->getTypeID () ) {
158162 case '_boo ' :
159163 // boolean value found, convert it
160- $ value = in_array ( strtolower ( $ dataValue ->getWikiValue () ?? 'null ' ), $ this -> msgTrue );
164+ $ value = in_array ( strtolower ( $ dataValue ->getWikiValue () ?? 'null ' ), self :: $ msgTrue );
161165 break ;
162166 case '_num ' :
163167 // number value found
@@ -167,7 +171,7 @@ public function getValueFromDataValue( DataValue $dataValue ) {
167171 break ;
168172 default :
169173 # FIXME ignores parameter link=none|subject
170- $ value = $ dataValue ->getShortText ( SMW_OUTPUT_WIKI , new Linker () );
174+ $ value = $ dataValue ->getShortText ( SMW_OUTPUT_WIKI , $ this -> linker );
171175 }
172176
173177 return $ value ;
0 commit comments