r59929 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59928‎ | r59929 | r59930 >
Date:15:55, 10 December 2009
Author:mkroetzsch
Status:deferred
Tags:
Comment:
better support 0 as a maximum for listings on property/type/concept namespace pages (Bug 21748)
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Settings.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_ConceptPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_PropertyPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_TypePage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_ConceptPage.php
@@ -30,42 +30,46 @@
3131 * article that indicates further results).
3232 */
3333 protected function doQuery() {
34 - $store = smwfGetStore();
 34+ if ($this->limit > 0) {
 35+ $store = smwfGetStore();
 36+ $desc = new SMWConceptDescription($this->mTitle);
 37+ if ($this->from != '') {
 38+ $dv = SMWWikiPageValue::makePage($this->from, NS_MAIN); // make a dummy wiki page as boundary
 39+ $fromdesc = new SMWValueDescription($dv, SMW_CMP_GEQ);
 40+ $desc = new SMWConjunction(array($desc,$fromdesc));
 41+ $order = 'ASC';
 42+ } elseif ($this->until != '') {
 43+ $dv = SMWWikiPageValue::makePage($this->until, NS_MAIN); // make a dummy wiki page as boundary
 44+ $fromdesc = new SMWValueDescription($dv, SMW_CMP_LEQ);
 45+ $neqdesc = new SMWValueDescription($dv, SMW_CMP_NEQ); // do not include boundary in this case
 46+ $desc = new SMWConjunction(array($desc,$fromdesc,$neqdesc));
 47+ $order = 'DESC';
 48+ } else {
 49+ $order = 'ASC';
 50+ }
 51+ $desc->addPrintRequest(new SMWPrintRequest(SMWPrintRequest::PRINT_THIS, ''));
 52+ $query = new SMWQuery($desc);
 53+ $query->sortkeys[''] = $order;
 54+ $query->setLimit($this->limit+1);
3555
36 - $desc = new SMWConceptDescription($this->mTitle);
37 - if ($this->from != '') {
38 - $dv = SMWWikiPageValue::makePage($this->from, NS_MAIN); // make a dummy wiki page as boundary
39 - $fromdesc = new SMWValueDescription($dv, SMW_CMP_GEQ);
40 - $desc = new SMWConjunction(array($desc,$fromdesc));
41 - $order = 'ASC';
42 - } elseif ($this->until != '') {
43 - $dv = SMWWikiPageValue::makePage($this->until, NS_MAIN); // make a dummy wiki page as boundary
44 - $fromdesc = new SMWValueDescription($dv, SMW_CMP_LEQ);
45 - $neqdesc = new SMWValueDescription($dv, SMW_CMP_NEQ); // do not include boundary in this case
46 - $desc = new SMWConjunction(array($desc,$fromdesc,$neqdesc));
47 - $order = 'DESC';
 56+ $result = $store->getQueryResult($query);
 57+ $row = $result->getNext();
 58+ while ( $row !== false ) {
 59+ $this->articles[] = end($row)->getNextObject();
 60+ $row = $result->getNext();
 61+ }
 62+ if ($order == 'DESC') {
 63+ $this->articles = array_reverse($this->articles);
 64+ }
 65+ $this->m_errors = $query->getErrors();
4866 } else {
49 - $order = 'ASC';
 67+ $this->articles = array();
 68+ $this->errors = array();
5069 }
51 - $desc->addPrintRequest(new SMWPrintRequest(SMWPrintRequest::PRINT_THIS, ''));
52 - $query = new SMWQuery($desc);
53 - $query->sortkeys[''] = $order;
54 - $query->setLimit($this->limit+1);
55 -
56 - $result = $store->getQueryResult($query);
57 - $row = $result->getNext();
58 - while ( $row !== false ) {
59 - $this->articles[] = end($row)->getNextObject();
60 - $row = $result->getNext();
61 - }
62 - if ($order == 'DESC') {
63 - $this->articles = array_reverse($this->articles);
64 - }
65 - $this->m_errors = $query->getErrors();
6670 }
6771
6872 /**
69 - * Generates the headline for the page list and the HTML encoded list of pages which
 73+ * Generates the headline for the page list and the HTML encoded list of pages which
7074 * shall be shown.
7175 */
7276 protected function getPages() {
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_TypePage.php
@@ -31,29 +31,33 @@
3232 * article that indicates further results).
3333 */
3434 protected function doQuery() {
35 - $store = smwfGetStore();
36 - $options = new SMWRequestOptions();
37 - $options->limit = $this->limit + 1;
38 - $options->sort = true;
39 - $typevalue = SMWDataValueFactory::newTypeIDValue('__typ', $this->mTitle->getText());
40 - $this->m_typevalue = $typevalue;
41 - if ($this->from != '') {
42 - $options->boundary = $this->from;
43 - $options->ascending = true;
44 - $options->include_boundary = true;
45 - $this->articles = $store->getPropertySubjects(SMWPropertyValue::makeProperty('_TYPE'), $typevalue, $options);
46 - } elseif ($this->until != '') {
47 - $options->boundary = $this->until;
48 - $options->ascending = false;
49 - $options->include_boundary = false;
50 - $this->articles = array_reverse($store->getPropertySubjects(SMWPropertyValue::makeProperty('_TYPE'), $typevalue, $options));
 35+ if ($this->limit > 0) {
 36+ $store = smwfGetStore();
 37+ $options = new SMWRequestOptions();
 38+ $options->limit = $this->limit + 1;
 39+ $options->sort = true;
 40+ $typevalue = SMWDataValueFactory::newTypeIDValue('__typ', $this->mTitle->getText());
 41+ $this->m_typevalue = $typevalue;
 42+ if ($this->from != '') {
 43+ $options->boundary = $this->from;
 44+ $options->ascending = true;
 45+ $options->include_boundary = true;
 46+ $this->articles = $store->getPropertySubjects(SMWPropertyValue::makeProperty('_TYPE'), $typevalue, $options);
 47+ } elseif ($this->until != '') {
 48+ $options->boundary = $this->until;
 49+ $options->ascending = false;
 50+ $options->include_boundary = false;
 51+ $this->articles = array_reverse($store->getPropertySubjects(SMWPropertyValue::makeProperty('_TYPE'), $typevalue, $options));
 52+ } else {
 53+ $this->articles = $store->getPropertySubjects(SMWPropertyValue::makeProperty('_TYPE'), $typevalue, $options);
 54+ }
5155 } else {
52 - $this->articles = $store->getPropertySubjects(SMWPropertyValue::makeProperty('_TYPE'), $typevalue, $options);
 56+ $this->articles = array();
5357 }
5458 }
5559
5660 /**
57 - * Generates the headline for the page list and the HTML encoded list of pages which
 61+ * Generates the headline for the page list and the HTML encoded list of pages which
5862 * shall be shown.
5963 */
6064 protected function getPages() {
@@ -65,8 +69,8 @@
6670 $r .= '<p style="font-style: italic; ">' .wfMsg('smw_isknowntype') . "</p>\n";
6771 }
6872 /*
69 - * TODO: also detect isAlias()?
70 - * But smw_isaliastype message requires determining alias target;
 73+ * TODO: also detect isAlias()?
 74+ * But smw_isaliastype message requires determining alias target;
7175 * code is in SMW_SpecialTypes, not SMW_DV_Types.
7276 */
7377 $ti = htmlspecialchars( $this->mTitle->getText() );
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_PropertyPage.php
@@ -41,24 +41,28 @@
4242 */
4343 protected function doQuery() {
4444 $store = smwfGetStore();
45 - $options = new SMWRequestOptions();
46 - $options->limit = $this->limit + 1;
47 - $options->sort = true;
48 - $reverse = false;
49 - if ($this->from != '') {
50 - $options->boundary = $this->from;
51 - $options->ascending = true;
52 - $options->include_boundary = true;
53 - } elseif ($this->until != '') {
54 - $options->boundary = $this->until;
55 - $options->ascending = false;
56 - $options->include_boundary = false;
57 - $reverse = true;
 45+ if ($this->limit > 0) { // for limit==0 there is no paging, and no query
 46+ $options = new SMWRequestOptions();
 47+ $options->limit = $this->limit + 1;
 48+ $options->sort = true;
 49+ $reverse = false;
 50+ if ($this->from != '') {
 51+ $options->boundary = $this->from;
 52+ $options->ascending = true;
 53+ $options->include_boundary = true;
 54+ } elseif ($this->until != '') {
 55+ $options->boundary = $this->until;
 56+ $options->ascending = false;
 57+ $options->include_boundary = false;
 58+ $reverse = true;
 59+ }
 60+ $this->articles = $store->getAllPropertySubjects($this->mProperty, $options);
 61+ if ($reverse) {
 62+ $this->articles = array_reverse($this->articles);
 63+ }
 64+ } else {
 65+ $this->articles = array();
5866 }
59 - $this->articles = $store->getAllPropertySubjects($this->mProperty, $options);
60 - if ($reverse) {
61 - $this->articles = array_reverse($this->articles);
62 - }
6367
6468 // retrieve all subproperties of this property
6569 $s_options = new SMWRequestOptions();
@@ -76,29 +80,27 @@
7781 wfLoadExtensionMessages('SemanticMediaWiki');
7882 $r = '';
7983 $ti = htmlspecialchars( $this->mTitle->getText() );
80 - $nav = $this->getNavigationLinks();
8184 if (count($this->subproperties) > 0) {
82 - $r .= "<div id=\"mw-subcategories\">\n<h2>" . wfMsg('smw_subproperty_header',$ti) . "</h2>\n";
83 - $r .= '<p>';
 85+ $r .= "<div id=\"mw-subcategories\">\n<h2>" . wfMsg('smw_subproperty_header',$ti) . "</h2>\n<p>";
8486 if (!$this->mProperty->isUserDefined()) {
8587 $r .= wfMsg('smw_isspecprop') . ' ';
8688 }
87 - $r .= wfMsgExt('smw_subpropertyarticlecount', array( 'parsemag' ), min($this->limit, count($this->subproperties))) . "</p>\n";
88 - if (count($this->subproperties) < 6) {
89 - $r .= $this->shortList(0,count($this->subproperties), $this->subproperties);
90 - } else {
91 - $r .= $this->columnList(0,count($this->subproperties), $this->subproperties);
92 - }
 89+ $r .= wfMsgExt('smw_subpropertyarticlecount', array( 'parsemag' ), count($this->subproperties)) . "</p>\n";
 90+ $r .= (count($this->subproperties) < 6)?
 91+ $this->shortList(0,count($this->subproperties), $this->subproperties):
 92+ $this->columnList(0,count($this->subproperties), $this->subproperties);
9393 $r .= "\n</div>";
9494 }
95 - $r .= '<a name="SMWResults"></a>' . $nav . "<div id=\"mw-pages\">\n";
96 - $r .= '<h2>' . wfMsg('smw_attribute_header',$ti) . "</h2>\n";
97 - $r .= '<p>';
98 - if (!$this->mProperty->isUserDefined()) {
99 - $r .= wfMsg('smw_isspecprop') . ' ';
 95+ if (count($this->articles) > 0) {
 96+ $nav = $this->getNavigationLinks();
 97+ $r .= '<a name="SMWResults"></a>' . $nav . "<div id=\"mw-pages\">\n" .
 98+ '<h2>' . wfMsg('smw_attribute_header',$ti) . "</h2>\n<p>";
 99+ if (!$this->mProperty->isUserDefined()) {
 100+ $r .= wfMsg('smw_isspecprop') . ' ';
 101+ }
 102+ $r .= wfMsgExt('smw_attributearticlecount', array( 'parsemag' ), min($this->limit, count($this->articles))) . "</p>\n" .
 103+ $this->subjectObjectList() . "\n</div>" . $nav;
100104 }
101 - $r .= wfMsgExt('smw_attributearticlecount', array( 'parsemag' ), min($this->limit, count($this->articles))) . "</p>\n";
102 - $r .= $this->subjectObjectList() . "\n</div>" . $nav;
103105 wfProfileOut( __METHOD__ . ' (SMW)');
104106 return $r;
105107 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Settings.php
@@ -120,7 +120,8 @@
121121
122122 ###
123123 # Number results shown in the listings on pages in the namespaces Property,
124 -# Type, and Concept.
 124+# Type, and Concept. If a value of 0 is given, the respective listings are
 125+# hidden completely.
125126 ##
126127 $smwgTypePagingLimit = 200; // same number as for categories
127128 $smwgConceptPagingLimit = 200; // same number as for categories
@@ -130,7 +131,7 @@
131132 ###
132133 # How many values should at most be displayed for a page on the Property page?
133134 ##
134 -$smwgMaxPropertyValues = 3; // if large values are desired, consider reducing $smwgPropertyPagingLimit for unchanged performance
 135+$smwgMaxPropertyValues = 3; // if large values are desired, consider reducing $smwgPropertyPagingLimit for better performance
135136 ##
136137
137138 ###
@@ -243,7 +244,7 @@
244245 # Array of available aliases for result formats. Can be redefined in
245246 # the settings to disallow certain aliases or to register extension aliases.
246247 # To disable an alias, do "unset($smwgResultAliases['alias']);" Disabled
247 -# aliases will be treated like if the alias parameter had been omitted.
 248+# aliases will be treated like if the alias parameter had been omitted.
248249 ##
249250 $smwgResultAliases = array();
250251 ##

Status & tagging log