Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -716,10 +716,12 @@ |
717 | 717 | * @return string |
718 | 718 | */ |
719 | 719 | function wfMsgWikiHtml( $key ) { |
720 | | - global $wgOut; |
| 720 | + global $wgMessageCache; |
721 | 721 | $args = func_get_args(); |
722 | 722 | array_shift( $args ); |
723 | | - return wfMsgReplaceArgs( $wgOut->parse( wfMsgGetKey( $key, true ), /* can't be set to false */ true ), $args ); |
| 723 | + return wfMsgReplaceArgs( |
| 724 | + $wgMessageCache->parse( wfMsgGetKey( $key, true ), null, /* can't be set to false */ true ), |
| 725 | + $args ); |
724 | 726 | } |
725 | 727 | |
726 | 728 | /** |
— | — | @@ -741,7 +743,7 @@ |
742 | 744 | * Behavior for conflicting options (e.g., parse+parseinline) is undefined. |
743 | 745 | */ |
744 | 746 | function wfMsgExt( $key, $options ) { |
745 | | - global $wgOut; |
| 747 | + global $wgMessageCache; |
746 | 748 | |
747 | 749 | $args = func_get_args(); |
748 | 750 | array_shift( $args ); |
— | — | @@ -781,9 +783,9 @@ |
782 | 784 | } |
783 | 785 | |
784 | 786 | if( in_array( 'parse', $options, true ) ) { |
785 | | - $string = $wgOut->parse( $string, true, !$forContent, $langCodeObj ); |
| 787 | + $string = $wgMessageCache->parse( $string, null, true, !$forContent, $langCodeObj ); |
786 | 788 | } elseif ( in_array( 'parseinline', $options, true ) ) { |
787 | | - $string = $wgOut->parse( $string, true, !$forContent, $langCodeObj ); |
| 789 | + $string = $wgMessageCache->parse( $string, null, true, !$forContent, $langCodeObj ); |
788 | 790 | $m = array(); |
789 | 791 | if( preg_match( '/^<p>(.*)\n?<\/p>\n?$/sU', $string, $m ) ) { |
790 | 792 | $string = $m[1]; |
Index: trunk/phase3/includes/MessageCache.php |
— | — | @@ -102,6 +102,8 @@ |
103 | 103 | |
104 | 104 | /** |
105 | 105 | * ParserOptions is lazy initialised. |
| 106 | + * |
| 107 | + * @return ParserOptions |
106 | 108 | */ |
107 | 109 | function getParserOptions() { |
108 | 110 | if ( !$this->mParserOptions ) { |
— | — | @@ -220,6 +222,8 @@ |
221 | 223 | |
222 | 224 | /** |
223 | 225 | * Set the cache to $cache, if it is valid. Otherwise set the cache to false. |
| 226 | + * |
| 227 | + * @return bool |
224 | 228 | */ |
225 | 229 | function setCache( $cache, $code ) { |
226 | 230 | if ( isset( $cache['VERSION'] ) && $cache['VERSION'] == MSG_CACHE_VERSION ) { |
— | — | @@ -734,6 +738,21 @@ |
735 | 739 | return $message; |
736 | 740 | } |
737 | 741 | |
| 742 | + $parser = $this->getParser(); |
| 743 | + if ( $parser ) { |
| 744 | + $popts = $this->getParserOptions(); |
| 745 | + $popts->setInterfaceMessage( $interface ); |
| 746 | + $popts->setTargetLanguage( $language ); |
| 747 | + $popts->setUserLang( $language ); |
| 748 | + $message = $parser->transformMsg( $message, $popts, $title ); |
| 749 | + } |
| 750 | + return $message; |
| 751 | + } |
| 752 | + |
| 753 | + /** |
| 754 | + * @return Parser |
| 755 | + */ |
| 756 | + function getParser() { |
738 | 757 | global $wgParser, $wgParserConf; |
739 | 758 | if ( !$this->mParser && isset( $wgParser ) ) { |
740 | 759 | # Do some initialisation so that we don't have to do it twice |
— | — | @@ -746,16 +765,28 @@ |
747 | 766 | } else { |
748 | 767 | $this->mParser = clone $wgParser; |
749 | 768 | } |
750 | | - #wfDebug( __METHOD__ . ": following contents triggered transform: $message\n" ); |
751 | 769 | } |
752 | | - if ( $this->mParser ) { |
753 | | - $popts = $this->getParserOptions(); |
754 | | - $popts->setInterfaceMessage( $interface ); |
| 770 | + return $this->mParser; |
| 771 | + } |
| 772 | + |
| 773 | + /** |
| 774 | + * @param $text string |
| 775 | + * @param $title |
| 776 | + * @param $linestart bool |
| 777 | + * @return ParserOutput |
| 778 | + */ |
| 779 | + public function parse( $text, $title = null, $linestart = true, $interface = false, $language = null ) { |
| 780 | + $parser = $this->getParser(); |
| 781 | + $popts = $this->getParserOptions(); |
| 782 | + |
| 783 | + if ( $interface ) { |
| 784 | + $popts->setInterfaceMessage( true ); |
| 785 | + } |
| 786 | + if ( $language !== null ) { |
755 | 787 | $popts->setTargetLanguage( $language ); |
756 | | - $popts->setUserLang( $language ); |
757 | | - $message = $this->mParser->transformMsg( $message, $popts, $title ); |
758 | 788 | } |
759 | | - return $message; |
| 789 | + |
| 790 | + return $parser->parse( $text, $title, $popts, $linestart ); |
760 | 791 | } |
761 | 792 | |
762 | 793 | function disable() { |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -792,7 +792,7 @@ |
793 | 793 | * @param $t Title object |
794 | 794 | */ |
795 | 795 | public function setTitle( $t ) { |
796 | | - $this->getContext()->setTitle($t); |
| 796 | + $this->getContext()->setTitle( $t ); |
797 | 797 | } |
798 | 798 | |
799 | 799 | /** |
Index: trunk/phase3/includes/api/ApiFormatYaml.php |
— | — | @@ -33,20 +33,12 @@ |
34 | 34 | * API YAML output formatter |
35 | 35 | * @ingroup API |
36 | 36 | */ |
37 | | -class ApiFormatYaml extends ApiFormatBase { |
| 37 | +class ApiFormatYaml extends ApiFormatJson { |
38 | 38 | |
39 | | - public function __construct( $main, $format ) { |
40 | | - parent::__construct( $main, $format ); |
41 | | - } |
42 | | - |
43 | 39 | public function getMimeType() { |
44 | 40 | return 'application/yaml'; |
45 | 41 | } |
46 | 42 | |
47 | | - public function execute() { |
48 | | - $this->printText( Spyc::YAMLDump( $this->getResultData() ) ); |
49 | | - } |
50 | | - |
51 | 43 | public function getDescription() { |
52 | 44 | return 'Output data in YAML format' . parent::getDescription(); |
53 | 45 | } |
Index: trunk/phase3/includes/libs/spyc.php |
— | — | @@ -1,248 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Spyc -- A Simple PHP YAML Class |
5 | | - * |
6 | | - * @file |
7 | | - * @version 0.2.3 -- 2006-02-04 |
8 | | - * @author Chris Wanstrath <chris@ozmm.org> |
9 | | - * @see http://spyc.sourceforge.net/ |
10 | | - * @copyright Copyright 2005-2006 Chris Wanstrath |
11 | | - * @license http://www.opensource.org/licenses/mit-license.php MIT License |
12 | | - */ |
13 | | - |
14 | | -/** |
15 | | - * The Simple PHP YAML Class. |
16 | | - * |
17 | | - * This class can be used to read a YAML file and convert its contents |
18 | | - * into a PHP array. It currently supports a very limited subsection of |
19 | | - * the YAML spec. |
20 | | - * |
21 | | - * @ingroup API |
22 | | - */ |
23 | | -class Spyc { |
24 | | - |
25 | | - /** |
26 | | - * Dump YAML from PHP array statically |
27 | | - * |
28 | | - * The dump method, when supplied with an array, will do its best |
29 | | - * to convert the array into friendly YAML. Pretty simple. Feel free to |
30 | | - * save the returned string as nothing.yml and pass it around. |
31 | | - * |
32 | | - * Oh, and you can decide how big the indent is and what the wordwrap |
33 | | - * for folding is. Pretty cool -- just pass in 'false' for either if |
34 | | - * you want to use the default. |
35 | | - * |
36 | | - * Indent's default is 2 spaces, wordwrap's default is 40 characters. And |
37 | | - * you can turn off wordwrap by passing in 0. |
38 | | - * |
39 | | - * @param $array Array: PHP array |
40 | | - * @param $indent Integer: Pass in false to use the default, which is 2 |
41 | | - * @param $wordwrap Integer: Pass in 0 for no wordwrap, false for default (40) |
42 | | - * @return String |
43 | | - */ |
44 | | - public static function YAMLDump( $array, $indent = false, $wordwrap = false ) { |
45 | | - $spyc = new Spyc; |
46 | | - return $spyc->dump( $array, $indent, $wordwrap ); |
47 | | - } |
48 | | - |
49 | | - /** |
50 | | - * Dump PHP array to YAML |
51 | | - * |
52 | | - * The dump method, when supplied with an array, will do its best |
53 | | - * to convert the array into friendly YAML. Pretty simple. Feel free to |
54 | | - * save the returned string as tasteful.yml and pass it around. |
55 | | - * |
56 | | - * Oh, and you can decide how big the indent is and what the wordwrap |
57 | | - * for folding is. Pretty cool -- just pass in 'false' for either if |
58 | | - * you want to use the default. |
59 | | - * |
60 | | - * Indent's default is 2 spaces, wordwrap's default is 40 characters. And |
61 | | - * you can turn off wordwrap by passing in 0. |
62 | | - * |
63 | | - * @param $array Array: PHP array |
64 | | - * @param $indent Integer: Pass in false to use the default, which is 2 |
65 | | - * @param $wordwrap Integer: Pass in 0 for no wordwrap, false for default (40) |
66 | | - * @return String |
67 | | - */ |
68 | | - public function dump( $array, $indent = false, $wordwrap = false ) { |
69 | | - // Dumps to some very clean YAML. We'll have to add some more features |
70 | | - // and options soon. And better support for folding. |
71 | | - |
72 | | - // New features and options. |
73 | | - if ( $indent === false or !is_numeric( $indent ) ) { |
74 | | - $this->_dumpIndent = 2; |
75 | | - } else { |
76 | | - $this->_dumpIndent = $indent; |
77 | | - } |
78 | | - |
79 | | - if ( $wordwrap === false or !is_numeric( $wordwrap ) ) { |
80 | | - $this->_dumpWordWrap = 40; |
81 | | - } else { |
82 | | - $this->_dumpWordWrap = $wordwrap; |
83 | | - } |
84 | | - |
85 | | - // New YAML document |
86 | | - $string = "---\n"; |
87 | | - |
88 | | - // Start at the base of the array and move through it. |
89 | | - foreach ( $array as $key => $value ) { |
90 | | - $string .= $this->_yamlize( $key, $value, 0 ); |
91 | | - } |
92 | | - return $string; |
93 | | - } |
94 | | - |
95 | | - /**** Private Properties ****/ |
96 | | - |
97 | | - /** |
98 | | - * Unused variables, but just commented rather than deleting |
99 | | - * to save altering the library |
100 | | - private $_haveRefs; |
101 | | - private $_allNodes; |
102 | | - private $_lastIndent; |
103 | | - private $_lastNode; |
104 | | - private $_inBlock; |
105 | | - private $_isInline; |
106 | | - **/ |
107 | | - private $_dumpIndent; |
108 | | - private $_dumpWordWrap; |
109 | | - |
110 | | - /**** Private Methods ****/ |
111 | | - |
112 | | - /** |
113 | | - * Attempts to convert a key / value array item to YAML |
114 | | - * |
115 | | - * @param $key Mixed: the name of the key |
116 | | - * @param $value Mixed: the value of the item |
117 | | - * @param $indent Integer: the indent of the current node |
118 | | - * @return String |
119 | | - */ |
120 | | - private function _yamlize( $key, $value, $indent ) { |
121 | | - if ( is_array( $value ) ) { |
122 | | - // It has children. What to do? |
123 | | - // Make it the right kind of item |
124 | | - $string = $this->_dumpNode( $key, null, $indent ); |
125 | | - // Add the indent |
126 | | - $indent += $this->_dumpIndent; |
127 | | - // Yamlize the array |
128 | | - $string .= $this->_yamlizeArray( $value, $indent ); |
129 | | - } else { |
130 | | - // It doesn't have children. Yip. |
131 | | - $string = $this->_dumpNode( $key, $value, $indent ); |
132 | | - } |
133 | | - return $string; |
134 | | - } |
135 | | - |
136 | | - /** |
137 | | - * Attempts to convert an array to YAML |
138 | | - * |
139 | | - * @param $array Array: the array you want to convert |
140 | | - * @param $indent Integer: the indent of the current level |
141 | | - * @return String |
142 | | - */ |
143 | | - private function _yamlizeArray( $array, $indent ) { |
144 | | - if ( is_array( $array ) ) { |
145 | | - $string = ''; |
146 | | - foreach ( $array as $key => $value ) { |
147 | | - $string .= $this->_yamlize( $key, $value, $indent ); |
148 | | - } |
149 | | - return $string; |
150 | | - } else { |
151 | | - return false; |
152 | | - } |
153 | | - } |
154 | | - |
155 | | - /** |
156 | | - * Find out whether a string needs to be output as a literal rather than in plain style. |
157 | | - * Added by Roan Kattouw 13-03-2008 |
158 | | - * |
159 | | - * @param $value String: the string to check |
160 | | - * @return Boolean |
161 | | - */ |
162 | | - function _needLiteral( $value ) { |
163 | | - // Check whether the string contains # or : or begins with any of: |
164 | | - // [ - ? , [ ] { } ! * & | > ' " % @ ` ] |
165 | | - // or is a number or contains newlines |
166 | | - return (bool)( gettype( $value ) == "string" && |
167 | | - ( is_numeric( $value ) || |
168 | | - strpos( $value, "\n" ) || |
169 | | - preg_match( "/[#:]/", $value ) || |
170 | | - preg_match( "/^[-?,[\]{}!*&|>'\"%@`]/", $value ) ) ); |
171 | | - } |
172 | | - |
173 | | - /** |
174 | | - * Returns YAML from a key and a value |
175 | | - * |
176 | | - * @param $key Mixed: the name of the key |
177 | | - * @param $value Mixed: the value of the item |
178 | | - * @param $indent Integer: the indent of the current node |
179 | | - * @return String |
180 | | - */ |
181 | | - private function _dumpNode( $key, $value, $indent ) { |
182 | | - // do some folding here, for blocks |
183 | | - if ( $this->_needLiteral( $value ) ) { |
184 | | - $value = $this->_doLiteralBlock( $value, $indent ); |
185 | | - } else { |
186 | | - $value = $this->_doFolding( $value, $indent ); |
187 | | - } |
188 | | - |
189 | | - $spaces = str_repeat( ' ', $indent ); |
190 | | - |
191 | | - if ( is_int( $key ) ) { |
192 | | - // It's a sequence |
193 | | - if ( $value !== '' && !is_null( $value ) ) |
194 | | - $string = $spaces . '- ' . $value . "\n"; |
195 | | - else |
196 | | - $string = $spaces . "-\n"; |
197 | | - } else { |
198 | | - if ( $key == '*' ) // bug 21922 - Quote asterix used as keys |
199 | | - $key = "'*'"; |
200 | | - |
201 | | - // It's mapped |
202 | | - if ( $value !== '' && !is_null( $value ) ) |
203 | | - $string = $spaces . $key . ': ' . $value . "\n"; |
204 | | - else |
205 | | - $string = $spaces . $key . ":\n"; |
206 | | - } |
207 | | - return $string; |
208 | | - } |
209 | | - |
210 | | - /** |
211 | | - * Creates a literal block for dumping |
212 | | - * |
213 | | - * @param $value String |
214 | | - * @param $indent Integer: the value of the indent |
215 | | - * @return String |
216 | | - */ |
217 | | - private function _doLiteralBlock( $value, $indent ) { |
218 | | - $exploded = explode( "\n", $value ); |
219 | | - $newValue = '|-'; |
220 | | - $indent += $this->_dumpIndent; |
221 | | - $spaces = str_repeat( ' ', $indent ); |
222 | | - foreach ( $exploded as $line ) { |
223 | | - $newValue .= "\n" . $spaces . trim( $line ); |
224 | | - } |
225 | | - return $newValue; |
226 | | - } |
227 | | - |
228 | | - /** |
229 | | - * Folds a string of text, if necessary |
230 | | - * |
231 | | - * @param $value String: the string you wish to fold |
232 | | - * @param $indent Integer: the indent of the current node |
233 | | - * @return String |
234 | | - */ |
235 | | - private function _doFolding( $value, $indent ) { |
236 | | - // Don't do anything if wordwrap is set to 0 |
237 | | - if ( $this->_dumpWordWrap === 0 ) { |
238 | | - return $value; |
239 | | - } |
240 | | - |
241 | | - if ( strlen( $value ) > $this->_dumpWordWrap ) { |
242 | | - $indent += $this->_dumpIndent; |
243 | | - $indent = str_repeat( ' ', $indent ); |
244 | | - $wrapped = wordwrap( $value, $this->_dumpWordWrap, "\n$indent" ); |
245 | | - $value = ">-\n" . $indent . $wrapped; |
246 | | - } |
247 | | - return $value; |
248 | | - } |
249 | | -} |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -67,6 +67,7 @@ |
68 | 68 | require_once "$IP/extensions/Math/Math.php"; |
69 | 69 | * $wgProfiler is now a configuration array, see StartProfiler.sample for details |
70 | 70 | * $wgProfiling has been removed |
| 71 | +* The spyc library is now no longer included in phase3 |
71 | 72 | |
72 | 73 | === New features in 1.18 === |
73 | 74 | * (bug 8130) Query pages should limit to content namespaces, not just main |
— | — | @@ -336,6 +337,9 @@ |
337 | 338 | * (bug 27712) add parent_id to list=deletedrevs |
338 | 339 | * (bug 28455) Add 'toponly' to recentchanges API module |
339 | 340 | * (bug 26873) API: Add 'toponly' filter in usercontribs module |
| 341 | +* (bug 28586) YAML: strings that are the same as boolean literals |
| 342 | +* (bug 28591) Update/replace/supplement spyc (YAML parsing library) |
| 343 | +* YAML API output is now 1.2 compliant, using JSON as the formatter |
340 | 344 | |
341 | 345 | === Languages updated in 1.18 === |
342 | 346 | |