r37399 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37398‎ | r37399 | r37400 >
Date:16:05, 9 July 2008
Author:yaron
Status:old
Tags:
Comment:
Changed to conventional structure for special pages, added handling o SMW's
new SMWWikiPageValue class, fixed some tabbing
Modified paths:
  • /trunk/extensions/DataTransfer/specials/DT_ViewXML.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DataTransfer/specials/DT_ViewXML.php
@@ -7,11 +7,24 @@
88
99 if (!defined('MEDIAWIKI')) die();
1010
11 -global $IP;
12 -require_once( "$IP/includes/SpecialPage.php" );
 11+class DTViewXML extends SpecialPage {
1312
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+ }
1522
 23+ function execute($query = '') {
 24+ $this->setHeaders();
 25+ doSpecialViewXML($query);
 26+ }
 27+}
 28+
1629 function getCategoriesList() {
1730 global $wgContLang, $dtgContLang;
1831 $dt_props = $dtgContLang->getSpecialPropertiesArray();
@@ -69,6 +82,10 @@
7083 $grouping_prop = Title::makeTitle(SMW_NS_PROPERTY, $xml_grouping_prop);
7184 $grouped_props = $store->getAllPropertySubjects($grouping_prop);
7285 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+ }
7390 $res = $store->getPropertyValues($grouped_prop, $grouping_prop);
7491 $num = count($res);
7592 if ($num > 0) {
@@ -82,12 +99,12 @@
83100 }
84101
85102 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)) {
92109 $subpage_name = $row[0];
93110 $query_subpage_name = str_replace("'", "\'", $subpage_name);
94111 // get the display order
@@ -97,13 +114,13 @@
98115 } else {
99116 $display_order = -1;
100117 }
101 - $dbr->freeResult($res2);
 118+ $dbr->freeResult($res2);
102119 // 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);
108125 }
109126
110127
@@ -129,8 +146,8 @@
130147 array('cl_from = page_id',
131148 'cl_to = '. $db->addQuotes($category)),
132149 $fname);
133 - if ($res) {
134 - while ($res && $row = $db->fetchRow($res)) {
 150+ if ($res) {
 151+ while ($res && $row = $db->fetchRow($res)) {
135152 if (array_key_exists('page_title', $row)) {
136153 $page_namespace = $row['page_namespace'];
137154 if ($page_namespace == NS_CATEGORY) {
@@ -262,11 +279,11 @@
263280 $free_text .= $c;
264281 $uncompleted_curly_brackets++;
265282 $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('<', '&lt;', $free_text);
270 - $free_text = str_replace('>', '&gt;', $free_text);
 283+ $free_text = str_replace('&', '&amp;', $free_text);
 284+ $free_text = str_replace('[', '&#91;', $free_text);
 285+ $free_text = str_replace(']', '&#93;', $free_text);
 286+ $free_text = str_replace('<', '&lt;', $free_text);
 287+ $free_text = str_replace('>', '&gt;', $free_text);
271288 if ($free_text != "") {
272289 $text .= "<$free_text_str id=\"$free_text_id\">$free_text</$free_text_str>";
273290 $free_text = "";
@@ -285,7 +302,7 @@
286303 $uncompleted_curly_brackets--;
287304 // is this needed?
288305 //if ($field_name != "") {
289 - // $field_name = "";
 306+ // $field_name = "";
290307 //}
291308 if ($page_contents[$i - 1] == '}') {
292309 if ($simplified_format)
@@ -382,7 +399,11 @@
383400 $num = count($res);
384401 if ($num > 0) {
385402 $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+ }
387408 $text .= getXMLForPage($title, $simplified_format, $groupings, $depth + 1);
388409 }
389410 $text .= "</$grouping_label>\n";
@@ -417,52 +438,51 @@
418439 if ($form_submitted) {
419440 $wgOut->disable();
420441
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" );
425446
426447 $groupings = getGroupings();
427448 $simplified_format = $wgRequest->getVal('simplified_format');
428449 $text = "<Pages>";
429450 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";
438464 }
439 - if ($simplified_format)
440 - $text .= '</' . str_replace(' ', '_', $cat) . ">\n";
441 - else
442 - $text .= "</$category_label>\n";
443 -
444 - }
445465 }
446466
447467 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";
453486 }
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 - }
467487 }
468488 $text .= "</Pages>";
469489 print $text;
@@ -473,7 +493,7 @@
474494 $categories = getCategoriesList();
475495 foreach ($categories as $category) {
476496 $title = Title::makeTitle( NS_CATEGORY, $category );
477 - $link = $skin->makeLinkObj( $title, $title->getText() );
 497+ $link = $skin->makeLinkObj( $title, $title->getText() );
478498 $text .= "<input type=\"checkbox\" name=\"categories[$category]\" /> $link <br />\n";
479499 }
480500 $text .= "<h2>" . wfMsg('dt_viewxml_namespaces') . "</h2>\n";

Status & tagging log