Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php |
— | — | @@ -10,29 +10,35 @@ |
11 | 11 | /** |
12 | 12 | * Static class for managing semantic data collected during parsing. All methods |
13 | 13 | * in this class are stateless: data is stored persistently only in a given parser |
14 | | - * output. |
| 14 | + * output. There is one exception: to provide a minimal compatibility with MediaWiki |
| 15 | + * up to version 1.13, the class keeps track of the latest ParserOutput that was |
| 16 | + * accessed. In this way, the ParserOutput can be reproduced when storing, since it |
| 17 | + * is not available as part of the storing LinkUpdate object in MediaWiki before 1.14. |
15 | 18 | * @ingroup SMW |
16 | 19 | */ |
17 | 20 | class SMWParseData { |
18 | 21 | |
| 22 | + /// ParserOutput last used. See documentation to SMWParseData. |
| 23 | + static public $mPrevOutput = NULL; |
| 24 | + |
19 | 25 | /** |
20 | 26 | * This function retrieves the SMW data from a given parser, and creates |
21 | 27 | * a new empty container if it is not initiated yet. |
22 | 28 | */ |
23 | 29 | static public function getSMWdata(Parser $parser) { |
24 | 30 | if (method_exists($parser,'getOutput')) { |
25 | | - $output = $parser->getOutput(); |
| 31 | + SMWParseData::$mPrevOutput = $parser->getOutput(); |
26 | 32 | } else { |
27 | | - $output = $parser->mOutput; |
| 33 | + SMWParseData::$mPrevOutput = $parser->mOutput; |
28 | 34 | } |
29 | 35 | $title = $parser->getTitle(); |
30 | | - if (!isset($output) || !isset($title)) return NULL; // no parsing, create error |
31 | | - if (!isset($output->mSMWData)) { // no data container yet |
| 36 | + if (!isset(SMWParseData::$mPrevOutput) || !isset($title)) return NULL; // no parsing, create error |
| 37 | + if (!isset(SMWParseData::$mPrevOutput->mSMWData)) { // no data container yet |
32 | 38 | $dv = SMWDataValueFactory::newTypeIDValue('_wpg'); |
33 | 39 | $dv->setValues($title->getDBkey(), $title->getNamespace()); |
34 | | - $output->mSMWData = new SMWSemanticData($dv); |
| 40 | + SMWParseData::$mPrevOutput->mSMWData = new SMWSemanticData($dv); |
35 | 41 | } |
36 | | - return $output->mSMWData; |
| 42 | + return SMWParseData::$mPrevOutput->mSMWData; |
37 | 43 | } |
38 | 44 | |
39 | 45 | /** |
— | — | @@ -40,15 +46,15 @@ |
41 | 47 | */ |
42 | 48 | static public function clearStorage(Parser $parser) { |
43 | 49 | if (method_exists($parser,'getOutput')) { |
44 | | - $output = $parser->getOutput(); |
| 50 | + SMWParseData::$mPrevOutput = $parser->getOutput(); |
45 | 51 | } else { |
46 | | - $output = $parser->mOutput; |
| 52 | + SMWParseData::$mPrevOutput = $parser->mOutput; |
47 | 53 | } |
48 | 54 | $title = $parser->getTitle(); |
49 | | - if (!isset($output) || !isset($title)) return; |
| 55 | + if (!isset(SMWParseData::$mPrevOutput) || !isset($title)) return; |
50 | 56 | $dv = SMWDataValueFactory::newTypeIDValue('_wpg'); |
51 | 57 | $dv->setValues($title->getDBkey(), $title->getNamespace()); |
52 | | - $output->mSMWData = new SMWSemanticData($dv); |
| 58 | + SMWParseData::$mPrevOutput->mSMWData = new SMWSemanticData($dv); |
53 | 59 | } |
54 | 60 | |
55 | 61 | /** |
— | — | @@ -183,9 +189,9 @@ |
184 | 190 | } |
185 | 191 | |
186 | 192 | /** |
187 | | - * Compares if two arrays of data values contain the same content. |
188 | | - * Returns true if the two arrays contain the same data values, |
189 | | - * false otherwise. |
| 193 | + * Helper function that compares two arrays of data values to check whether |
| 194 | + * they contain the same content. Returns true if the two arrays contain the |
| 195 | + * same data values (irrespective of their order), false otherwise. |
190 | 196 | */ |
191 | 197 | static public function equalDatavalues($dv1, $dv2) { |
192 | 198 | // The hashes of all values of both arrays are taken, then sorted |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Hooks.php |
— | — | @@ -165,7 +165,16 @@ |
166 | 166 | * Used to updates data after changes of templates, but also at each saving of an article. |
167 | 167 | */ |
168 | 168 | function smwfLinkUpdateHook($links_update) { |
169 | | - SMWParseData::storeData($links_update->mParserOutput, $links_update->mTitle, true); |
| 169 | + if (isset($links_update->mParserOutput)) { |
| 170 | + $output = $links_update->mParserOutput; |
| 171 | + } else { // MediaWiki <= 1.13 compatibility |
| 172 | + $output = SMWParseData::$mPrevOutput; |
| 173 | + if (!isset($output)) { |
| 174 | + smwfGetStore()->clearData($links_update->mTitle, SMWFactbox::isNewArticle()); |
| 175 | + return true; |
| 176 | + } |
| 177 | + } |
| 178 | + SMWParseData::storeData($output, $links_update->mTitle, true); |
170 | 179 | return true; |
171 | 180 | } |
172 | 181 | |