Index: trunk/extensions/DataTransclusion/DataTransclusionHandler.php |
— | — | @@ -58,15 +58,17 @@ |
59 | 59 | } |
60 | 60 | |
61 | 61 | static function errorMessage( $key, $asHTML ) { |
62 | | - $params = func_get_args(); |
63 | | - array_shift( $params ); // $key |
64 | | - array_shift( $params ); // $asHTML |
| 62 | + $params = func_get_args(); |
| 63 | + array_shift( $params ); // $key |
| 64 | + array_shift( $params ); // $asHTML |
65 | 65 | |
66 | | - if ( $asHTML ) $mode = 'parseinline'; |
67 | | - else $mode = 'parsemag'; |
| 66 | + if ( $asHTML ) $mode = 'parseinline'; |
| 67 | + else $mode = 'parsemag'; |
68 | 68 | |
69 | | - $m = wfMsgExt( $key, $mode, $params ); |
70 | | - return "<span class=\"error\">$m</span>"; |
| 69 | + $m = wfMsgExt( $key, $mode, $params ); |
| 70 | + |
| 71 | + //NOTE: using the key as a css class is done mainely for testing/debugging, but could be useful for scripting and styling too. |
| 72 | + return "<span class=\"error $key\">$m</span>"; |
71 | 73 | } |
72 | 74 | |
73 | 75 | /** |
— | — | @@ -80,7 +82,7 @@ |
81 | 83 | * Fetches a records and renders it, according to the given array of parameters. |
82 | 84 | * Common implementation for parser tag and parser function. |
83 | 85 | */ |
84 | | - static function handleRecordTransclusion( $key, $argv, $parser, $asHTML ) { |
| 86 | + static function handleRecordTransclusion( $key, $argv, $parser, $asHTML, $templateText = null ) { |
85 | 87 | //find out which data source to use... |
86 | 88 | if ( empty( $argv['source'] ) ) { |
87 | 89 | if ( empty( $argv[1] ) ) return DataTransclusionHandler::errorMessage( 'datatransclusion-missing-source', $asHTML ); //TESTME |
— | — | @@ -124,7 +126,7 @@ |
125 | 127 | //FIXME: log the template we used into the parser output, like regular template use |
126 | 128 | // (including templates used by the template, etc) |
127 | 129 | |
128 | | - $handler = new DataTransclusionHandler( $parser, $source, $t ); |
| 130 | + $handler = new DataTransclusionHandler( $parser, $source, $t, $templateText ); |
129 | 131 | |
130 | 132 | $record = $handler->normalizeRecord( $record ); |
131 | 133 | $text = $handler->render( $record ); |
— | — | @@ -233,11 +235,13 @@ |
234 | 236 | '!^;!m' => ';', |
235 | 237 | '![\r\n]!' => ' ', |
236 | 238 | '!^ !m' => ' ', |
237 | | - '!^-!m' => '-', |
238 | | - '!^=!m' => '=', |
| 239 | + '!^-!m' => '-', |
| 240 | + '!^=!m' => '=', |
239 | 241 | ); |
240 | 242 | |
241 | 243 | static function sanitizeValue( $v ) { |
| 244 | + //TODO: would be nicer to use <nowiki> - or better, insert substitution chunks directly into the parser state. would still need html escpaing though |
| 245 | + |
242 | 246 | $find = array_keys( self::$sanitizerSubstitution ); |
243 | 247 | $subst = array_values( self::$sanitizerSubstitution ); |
244 | 248 | |
Index: trunk/extensions/DataTransclusion/WebDataTransclusionSource.php |
— | — | @@ -81,7 +81,7 @@ |
82 | 82 | return $rec; |
83 | 83 | } |
84 | 84 | |
85 | | - protected function getRecordURL( $field, $value ) { |
| 85 | + public function getRecordURL( $field, $value ) { |
86 | 86 | $u = $this->url; |
87 | 87 | |
88 | 88 | if ( strpos( $u, '?' ) === false ) $u .= '?'; |
— | — | @@ -94,14 +94,14 @@ |
95 | 95 | return $u; |
96 | 96 | } |
97 | 97 | |
98 | | - protected function loadRecordData( $field, $value ) { |
| 98 | + public function loadRecordData( $field, $value ) { |
99 | 99 | $u = $this->getRecordURL( $field, $value ); |
100 | 100 | |
101 | 101 | $raw = Http::get( $u, $this->timeout, $this->httpOptions ); |
102 | 102 | return $raw; |
103 | 103 | } |
104 | 104 | |
105 | | - protected function decodeData( $raw, $format = 'php' ) { |
| 105 | + public function decodeData( $raw, $format = 'php' ) { |
106 | 106 | if ( $format == 'json' ) return FormatJson::decode( $raw, true ); //TESTME |
107 | 107 | if ( $format == 'wddx' ) return wddx_unserialize( $raw ); //TESTME |
108 | 108 | if ( $format == 'php' ) return unserialize( $raw ); //TESTME |
— | — | @@ -109,15 +109,15 @@ |
110 | 110 | return false; |
111 | 111 | } |
112 | 112 | |
113 | | - protected function extractError( $data ) { |
| 113 | + public function extractError( $data ) { |
114 | 114 | return $this->extractField( $data, $this->errorPath ); |
115 | 115 | } |
116 | 116 | |
117 | | - protected function extractRecord( $data ) { |
| 117 | + public function extractRecord( $data ) { |
118 | 118 | return $this->extractField( $data, $this->dataPath ); |
119 | 119 | } |
120 | 120 | |
121 | | - protected function extractField( $data, $path ) { |
| 121 | + public function extractField( $data, $path ) { |
122 | 122 | if ( $path == null ) return $data; |
123 | 123 | if ( is_string( $path ) ) return @$data[ $path ]; |
124 | 124 | |
Index: trunk/extensions/DataTransclusion/DataTransclusionSource.php |
— | — | @@ -59,7 +59,7 @@ |
60 | 60 | if ( $s === null || $s === false ) return $s; |
61 | 61 | if ( !is_string( $s ) ) return $s; |
62 | 62 | |
63 | | - $list = preg_split( '!\s*[,;|]\s*!', $s ); |
| 63 | + $list = preg_split( '!\s*[,;|/]\s*!', $s ); |
64 | 64 | return $list; |
65 | 65 | } |
66 | 66 | |
— | — | @@ -71,8 +71,12 @@ |
72 | 72 | $this->name = $spec[ 'name' ]; |
73 | 73 | |
74 | 74 | $this->keyFields = self::splitList( $spec[ 'keyFields' ] ); |
75 | | - $this->fieldNames = self::splitList( $spec[ 'fieldNames' ] ); |
76 | 75 | |
| 76 | + if ( isset( $spec[ 'fieldNames' ] ) ) |
| 77 | + $this->fieldNames = self::splitList( $spec[ 'fieldNames' ] ); |
| 78 | + else |
| 79 | + $this->fieldNames = $this->keyFields; |
| 80 | + |
77 | 81 | if ( !empty( $spec[ 'defaultKey' ] ) ) $this->defaultKey = $spec[ 'defaultKey' ]; |
78 | 82 | else $this->defaultKey = $this->keyFields[ 0 ]; |
79 | 83 | |
Index: trunk/extensions/DataTransclusion/DBDataTransclusionSource.php |
— | — | @@ -68,9 +68,8 @@ |
69 | 69 | else return (string)$value; |
70 | 70 | } |
71 | 71 | |
72 | | - public function fetchRecord( $field, $value ) { |
73 | | - $db = wfGetDB( DB_SLAVE ); |
74 | | - |
| 72 | + public function getQuery( $field, $value, $db = null ) { |
| 73 | + if ( !$db ) $db = wfGetDB( DB_SLAVE ); |
75 | 74 | if ( !preg_match( '/\w+[\w\d]+/', $field ) ) return false; // redundant, but make extra sure we don't get anythign evil here //TESTME |
76 | 75 | |
77 | 76 | $value = $this->convertKey( $field, $value ); //TESTME |
— | — | @@ -85,6 +84,14 @@ |
86 | 85 | |
87 | 86 | if ( $this->querySuffix ) $sql = $sql . ' ' . $this->querySuffix; |
88 | 87 | |
| 88 | + return $sql; |
| 89 | + } |
| 90 | + |
| 91 | + public function fetchRecord( $field, $value ) { |
| 92 | + $db = wfGetDB( DB_SLAVE ); |
| 93 | + |
| 94 | + $sql = $this->getQuery( $field, $value, $db ); |
| 95 | + |
89 | 96 | $rs = $db->query( $sql, "DBDataTransclusionSource(" . $this->getName() . ")::fetchRecord" ); |
90 | 97 | if ( !$rs ) return false; |
91 | 98 | |