r41463 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41462‎ | r41463 | r41464 >
Date:06:17, 1 October 2008
Author:mkroetzsch
Status:old
Tags:
Comment:
Compatibility hacks for MediaWiki <= 1.13
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Hooks.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php
@@ -10,29 +10,35 @@
1111 /**
1212 * Static class for managing semantic data collected during parsing. All methods
1313 * 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.
1518 * @ingroup SMW
1619 */
1720 class SMWParseData {
1821
 22+ /// ParserOutput last used. See documentation to SMWParseData.
 23+ static public $mPrevOutput = NULL;
 24+
1925 /**
2026 * This function retrieves the SMW data from a given parser, and creates
2127 * a new empty container if it is not initiated yet.
2228 */
2329 static public function getSMWdata(Parser $parser) {
2430 if (method_exists($parser,'getOutput')) {
25 - $output = $parser->getOutput();
 31+ SMWParseData::$mPrevOutput = $parser->getOutput();
2632 } else {
27 - $output = $parser->mOutput;
 33+ SMWParseData::$mPrevOutput = $parser->mOutput;
2834 }
2935 $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
3238 $dv = SMWDataValueFactory::newTypeIDValue('_wpg');
3339 $dv->setValues($title->getDBkey(), $title->getNamespace());
34 - $output->mSMWData = new SMWSemanticData($dv);
 40+ SMWParseData::$mPrevOutput->mSMWData = new SMWSemanticData($dv);
3541 }
36 - return $output->mSMWData;
 42+ return SMWParseData::$mPrevOutput->mSMWData;
3743 }
3844
3945 /**
@@ -40,15 +46,15 @@
4147 */
4248 static public function clearStorage(Parser $parser) {
4349 if (method_exists($parser,'getOutput')) {
44 - $output = $parser->getOutput();
 50+ SMWParseData::$mPrevOutput = $parser->getOutput();
4551 } else {
46 - $output = $parser->mOutput;
 52+ SMWParseData::$mPrevOutput = $parser->mOutput;
4753 }
4854 $title = $parser->getTitle();
49 - if (!isset($output) || !isset($title)) return;
 55+ if (!isset(SMWParseData::$mPrevOutput) || !isset($title)) return;
5056 $dv = SMWDataValueFactory::newTypeIDValue('_wpg');
5157 $dv->setValues($title->getDBkey(), $title->getNamespace());
52 - $output->mSMWData = new SMWSemanticData($dv);
 58+ SMWParseData::$mPrevOutput->mSMWData = new SMWSemanticData($dv);
5359 }
5460
5561 /**
@@ -183,9 +189,9 @@
184190 }
185191
186192 /**
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.
190196 */
191197 static public function equalDatavalues($dv1, $dv2) {
192198 // The hashes of all values of both arrays are taken, then sorted
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Hooks.php
@@ -165,7 +165,16 @@
166166 * Used to updates data after changes of templates, but also at each saving of an article.
167167 */
168168 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);
170179 return true;
171180 }
172181

Status & tagging log