Index: trunk/extensions/DataTransfer/specials/DT_ViewXML.php |
— | — | @@ -7,11 +7,24 @@ |
8 | 8 | |
9 | 9 | if (!defined('MEDIAWIKI')) die(); |
10 | 10 | |
11 | | -global $IP; |
12 | | -require_once( "$IP/includes/SpecialPage.php" ); |
| 11 | +class DTViewXML extends SpecialPage { |
13 | 12 | |
14 | | -SpecialPage::addPage( new SpecialPage('ViewXML','',true,'doSpecialViewXML',false) ); |
| 13 | + /** |
| 14 | + * Constructor |
| 15 | + */ |
| 16 | + public function DTViewXML() { |
| 17 | + global $wgLanguageCode; |
| 18 | + SpecialPage::SpecialPage('ViewXML'); |
| 19 | + dtfInitContentLanguage($wgLanguageCode); |
| 20 | + wfLoadExtensionMessages('DataTransfer'); |
| 21 | + } |
15 | 22 | |
| 23 | + function execute($query = '') { |
| 24 | + $this->setHeaders(); |
| 25 | + doSpecialViewXML($query); |
| 26 | + } |
| 27 | +} |
| 28 | + |
16 | 29 | function getCategoriesList() { |
17 | 30 | global $wgContLang, $dtgContLang; |
18 | 31 | $dt_props = $dtgContLang->getSpecialPropertiesArray(); |
— | — | @@ -69,6 +82,10 @@ |
70 | 83 | $grouping_prop = Title::makeTitle(SMW_NS_PROPERTY, $xml_grouping_prop); |
71 | 84 | $grouped_props = $store->getAllPropertySubjects($grouping_prop); |
72 | 85 | foreach ($grouped_props as $grouped_prop) { |
| 86 | + // the type of $grouped_prop depends on the version of SMW |
| 87 | + if ($grouped_prop instanceof SMWWikiPageValue) { |
| 88 | + $grouped_prop = $grouped_prop->getTitle(); |
| 89 | + } |
73 | 90 | $res = $store->getPropertyValues($grouped_prop, $grouping_prop); |
74 | 91 | $num = count($res); |
75 | 92 | if ($num > 0) { |
— | — | @@ -82,12 +99,12 @@ |
83 | 100 | } |
84 | 101 | |
85 | 102 | function getSubpagesForPageGrouping($page_name, $relation_name) { |
86 | | - $dbr = wfGetDB( DB_SLAVE ); |
87 | | - $smw_relations = $dbr->tableName( 'smw_relations' ); |
88 | | - $smw_attributes = $dbr->tableName( 'smw_attributes' ); |
89 | | - $res = $dbr->query("SELECT subject_title FROM $smw_relations WHERE object_title = '$page_name' AND relation_title = '$relation_name'"); |
90 | | - $subpages = array(); |
91 | | - while ($row = $dbr->fetchRow($res)) { |
| 103 | + $dbr = wfGetDB( DB_SLAVE ); |
| 104 | + $smw_relations = $dbr->tableName( 'smw_relations' ); |
| 105 | + $smw_attributes = $dbr->tableName( 'smw_attributes' ); |
| 106 | + $res = $dbr->query("SELECT subject_title FROM $smw_relations WHERE object_title = '$page_name' AND relation_title = '$relation_name'"); |
| 107 | + $subpages = array(); |
| 108 | + while ($row = $dbr->fetchRow($res)) { |
92 | 109 | $subpage_name = $row[0]; |
93 | 110 | $query_subpage_name = str_replace("'", "\'", $subpage_name); |
94 | 111 | // get the display order |
— | — | @@ -97,13 +114,13 @@ |
98 | 115 | } else { |
99 | 116 | $display_order = -1; |
100 | 117 | } |
101 | | - $dbr->freeResult($res2); |
| 118 | + $dbr->freeResult($res2); |
102 | 119 | // HACK - page name is the key, display order is the value |
103 | | - $subpages[$subpage_name] = $display_order; |
104 | | - } |
105 | | - $dbr->freeResult($res); |
106 | | - uasort($subpages, "cmp"); |
107 | | - return array_keys($subpages); |
| 120 | + $subpages[$subpage_name] = $display_order; |
| 121 | + } |
| 122 | + $dbr->freeResult($res); |
| 123 | + uasort($subpages, "cmp"); |
| 124 | + return array_keys($subpages); |
108 | 125 | } |
109 | 126 | |
110 | 127 | |
— | — | @@ -129,8 +146,8 @@ |
130 | 147 | array('cl_from = page_id', |
131 | 148 | 'cl_to = '. $db->addQuotes($category)), |
132 | 149 | $fname); |
133 | | - if ($res) { |
134 | | - while ($res && $row = $db->fetchRow($res)) { |
| 150 | + if ($res) { |
| 151 | + while ($res && $row = $db->fetchRow($res)) { |
135 | 152 | if (array_key_exists('page_title', $row)) { |
136 | 153 | $page_namespace = $row['page_namespace']; |
137 | 154 | if ($page_namespace == NS_CATEGORY) { |
— | — | @@ -262,11 +279,11 @@ |
263 | 280 | $free_text .= $c; |
264 | 281 | $uncompleted_curly_brackets++; |
265 | 282 | $free_text = trim($free_text); |
266 | | - $free_text = str_replace('&', '&', $free_text); |
267 | | - $free_text = str_replace('[', '[', $free_text); |
268 | | - $free_text = str_replace(']', ']', $free_text); |
269 | | - $free_text = str_replace('<', '<', $free_text); |
270 | | - $free_text = str_replace('>', '>', $free_text); |
| 283 | + $free_text = str_replace('&', '&', $free_text); |
| 284 | + $free_text = str_replace('[', '[', $free_text); |
| 285 | + $free_text = str_replace(']', ']', $free_text); |
| 286 | + $free_text = str_replace('<', '<', $free_text); |
| 287 | + $free_text = str_replace('>', '>', $free_text); |
271 | 288 | if ($free_text != "") { |
272 | 289 | $text .= "<$free_text_str id=\"$free_text_id\">$free_text</$free_text_str>"; |
273 | 290 | $free_text = ""; |
— | — | @@ -285,7 +302,7 @@ |
286 | 303 | $uncompleted_curly_brackets--; |
287 | 304 | // is this needed? |
288 | 305 | //if ($field_name != "") { |
289 | | - // $field_name = ""; |
| 306 | + // $field_name = ""; |
290 | 307 | //} |
291 | 308 | if ($page_contents[$i - 1] == '}') { |
292 | 309 | if ($simplified_format) |
— | — | @@ -382,7 +399,11 @@ |
383 | 400 | $num = count($res); |
384 | 401 | if ($num > 0) { |
385 | 402 | $text .= "<$grouping_label>\n"; |
386 | | - foreach ($res as $title) { |
| 403 | + foreach ($res as $subject) { |
| 404 | + // the type of $subject depends on the version of SMW |
| 405 | + if ($subject instanceof SMWWikiPageValue) { |
| 406 | + $subject = $subject->getTitle(); |
| 407 | + } |
387 | 408 | $text .= getXMLForPage($title, $simplified_format, $groupings, $depth + 1); |
388 | 409 | } |
389 | 410 | $text .= "</$grouping_label>\n"; |
— | — | @@ -417,52 +438,51 @@ |
418 | 439 | if ($form_submitted) { |
419 | 440 | $wgOut->disable(); |
420 | 441 | |
421 | | - // Cancel output buffering and gzipping if set |
422 | | - // This should provide safer streaming for pages with history |
423 | | - wfResetOutputBuffers(); |
424 | | - header( "Content-type: application/xml; charset=utf-8" ); |
| 442 | + // Cancel output buffering and gzipping if set |
| 443 | + // This should provide safer streaming for pages with history |
| 444 | + wfResetOutputBuffers(); |
| 445 | + header( "Content-type: application/xml; charset=utf-8" ); |
425 | 446 | |
426 | 447 | $groupings = getGroupings(); |
427 | 448 | $simplified_format = $wgRequest->getVal('simplified_format'); |
428 | 449 | $text = "<Pages>"; |
429 | 450 | if ($cats) { |
430 | | - foreach ($cats as $cat => $val) { |
431 | | - if ($simplified_format) |
432 | | - $text .= '<' . str_replace(' ', '_', $cat) . ">\n"; |
433 | | - else |
434 | | - $text .= "<$category_label $name_str=\"$cat\">\n"; |
435 | | - $titles = getPagesForCategory($cat, 10); |
436 | | - foreach ($titles as $title) { |
437 | | - $text .= getXMLForPage($title, $simplified_format, $groupings); |
| 451 | + foreach ($cats as $cat => $val) { |
| 452 | + if ($simplified_format) |
| 453 | + $text .= '<' . str_replace(' ', '_', $cat) . ">\n"; |
| 454 | + else |
| 455 | + $text .= "<$category_label $name_str=\"$cat\">\n"; |
| 456 | + $titles = getPagesForCategory($cat, 10); |
| 457 | + foreach ($titles as $title) { |
| 458 | + $text .= getXMLForPage($title, $simplified_format, $groupings); |
| 459 | + } |
| 460 | + if ($simplified_format) |
| 461 | + $text .= '</' . str_replace(' ', '_', $cat) . ">\n"; |
| 462 | + else |
| 463 | + $text .= "</$category_label>\n"; |
438 | 464 | } |
439 | | - if ($simplified_format) |
440 | | - $text .= '</' . str_replace(' ', '_', $cat) . ">\n"; |
441 | | - else |
442 | | - $text .= "</$category_label>\n"; |
443 | | - |
444 | | - } |
445 | 465 | } |
446 | 466 | |
447 | 467 | if ($nses) { |
448 | | - foreach ($nses as $ns => $val) { |
449 | | - if ($ns == 0) { |
450 | | - $ns_name = "Main"; |
451 | | - } else { |
452 | | - $ns_name = $wgCanonicalNamespaceNames[$ns]; |
| 468 | + foreach ($nses as $ns => $val) { |
| 469 | + if ($ns == 0) { |
| 470 | + $ns_name = "Main"; |
| 471 | + } else { |
| 472 | + $ns_name = $wgCanonicalNamespaceNames[$ns]; |
| 473 | + } |
| 474 | + if ($simplified_format) |
| 475 | + $text .= '<' . str_replace(' ', '_', $ns_name) . ">\n"; |
| 476 | + else |
| 477 | + $text .= "<$namespace_str $name_str=\"$ns_name\">\n"; |
| 478 | + $titles = getPagesForNamespace($ns); |
| 479 | + foreach ($titles as $title) { |
| 480 | + $text .= getXMLForPage($title, $simplified_format, $groupings); |
| 481 | + } |
| 482 | + if ($simplified_format) |
| 483 | + $text .= '</' . str_replace(' ', '_', $ns_name) . ">\n"; |
| 484 | + else |
| 485 | + $text .= "</$namespace_str>\n"; |
453 | 486 | } |
454 | | - if ($simplified_format) |
455 | | - $text .= '<' . str_replace(' ', '_', $ns_name) . ">\n"; |
456 | | - else |
457 | | - $text .= "<$namespace_str $name_str=\"$ns_name\">\n"; |
458 | | - $titles = getPagesForNamespace($ns); |
459 | | - foreach ($titles as $title) { |
460 | | - $text .= getXMLForPage($title, $simplified_format, $groupings); |
461 | | - } |
462 | | - if ($simplified_format) |
463 | | - $text .= '</' . str_replace(' ', '_', $ns_name) . ">\n"; |
464 | | - else |
465 | | - $text .= "</$namespace_str>\n"; |
466 | | - } |
467 | 487 | } |
468 | 488 | $text .= "</Pages>"; |
469 | 489 | print $text; |
— | — | @@ -473,7 +493,7 @@ |
474 | 494 | $categories = getCategoriesList(); |
475 | 495 | foreach ($categories as $category) { |
476 | 496 | $title = Title::makeTitle( NS_CATEGORY, $category ); |
477 | | - $link = $skin->makeLinkObj( $title, $title->getText() ); |
| 497 | + $link = $skin->makeLinkObj( $title, $title->getText() ); |
478 | 498 | $text .= "<input type=\"checkbox\" name=\"categories[$category]\" /> $link <br />\n"; |
479 | 499 | } |
480 | 500 | $text .= "<h2>" . wfMsg('dt_viewxml_namespaces') . "</h2>\n"; |