r40363 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40362‎ | r40363 | r40364 >
Date:08:00, 3 September 2008
Author:mkroetzsch
Status:old
Tags:
Comment:
Simplified code for Article pages
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_OrderedListPage.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_OrderedListPage.php
@@ -1,8 +1,6 @@
22 <?php
33 /**
44 * Abstract class to encapsulate properties of OrderedListPages.
5 - * Inherited by SMWTypePage and SMWPropertyPage.
6 - *
75 * Some code adapted from CategoryPage.php
86 *
97 * @author Nikolas Iwan
@@ -26,7 +24,6 @@
2725 protected $from; // start string: print $limit results from here
2826 protected $until; // end string: print $limit results strictly before this article
2927 protected $articles; // array of articles for which information is printed (primary ordering method)
30 - protected $articles_start_char; // array of first characters of printed articles, used for making subheaders
3128 protected $skin; // cache for the current skin, obtained from $wgUser
3229
3330 /**
@@ -63,7 +60,7 @@
6461 /**
6562 * Initialise some parameters that might be changed by subclasses
6663 * (e.g. $limit). Method can be overwritten in this case.
67 - * If the method returns false, nothing will be printed besides
 64+ * If the method returns false, nothing will be printed besides
6865 * the original article.
6966 */
7067 protected function initParameters() {
@@ -87,7 +84,6 @@
8885 */
8986 protected function clearPageState() {
9087 $this->articles = array();
91 - $this->articles_start_char = array();
9288 }
9389
9490 /**
@@ -168,7 +164,8 @@
169165 * Format a list of SMWWikipageValues chunked by letter in a three-column
170166 * list, ordered vertically.
171167 */
172 - protected function columnList($start, $end, $elements, $elements_start_char) {
 168+ protected function columnList($start, $end, $elements) {
 169+ global $wgContLang;
173170 // divide list into three equal chunks
174171 $chunk = (int) ( ($end-$start+1) / 3);
175172
@@ -189,18 +186,20 @@
190187 $index < $endChunk && $index < $end;
191188 $index++ ) {
192189 // check for change of starting letter or begining of chunk
 190+ $start_char = $wgContLang->convert( $wgContLang->firstChar( $elements[$index]->getSortkey() ) );
193191 if ( ($index == $startChunk) ||
194 - ($elements_start_char[$index] != $elements_start_char[$index - 1]) ) {
 192+ ($start_char != $prev_start_char) ) {
195193 if( $atColumnTop ) {
196194 $atColumnTop = false;
197195 } else {
198196 $r .= "</ul>\n";
199197 }
200198 $cont_msg = "";
201 - if ( $elements_start_char[$index] == $prev_start_char )
 199+ if ( $start_char == $prev_start_char ) {
202200 $cont_msg = wfMsgHtml('listingcontinuesabbrev');
203 - $r .= "<h3>" . htmlspecialchars( $elements_start_char[$index] ) . " $cont_msg</h3>\n<ul>";
204 - $prev_start_char = $elements_start_char[$index];
 201+ }
 202+ $r .= "<h3>" . htmlspecialchars( $start_char ) . " $cont_msg</h3>\n<ul>";
 203+ $prev_start_char = $start_char;
205204 }
206205 $r .= "<li>" . $elements[$index]->getLongHTMLText($this->getSkin()) . "</li>\n";
207206 }
@@ -216,12 +215,17 @@
217216 /**
218217 * Format a list of articles chunked by letter in a bullet list.
219218 */
220 - protected function shortList($start, $end, $elements, $elements_start_char) {
221 - $r = '<h3>' . htmlspecialchars( $elements_start_char[$start] ) . "</h3>\n";
 219+ protected function shortList($start, $end, $elements) {
 220+ global $wgContLang;
 221+ $start_char = $wgContLang->convert( $wgContLang->firstChar( $elements[$start]->getSortkey() ) );
 222+ $prev_start_char = $start_char;
 223+ $r = '<h3>' . htmlspecialchars( $start_char ) . "</h3>\n";
222224 $r .= '<ul><li>'. $elements[$start]->getLongHTMLText($this->getSkin()) . '</li>';
223225 for ($index = $start+1; $index < $end; $index++ ) {
224 - if ($elements_start_char[$index] != $elements_start_char[$index - 1]) {
225 - $r .= "</ul><h3>" . htmlspecialchars( $elements_start_char[$index] ) . "</h3>\n<ul>";
 226+ $start_char = $wgContLang->convert( $wgContLang->firstChar( $elements[$index]->getSortkey() ) );
 227+ if ($start_char != $prev_start_char) {
 228+ $r .= "</ul><h3>" . htmlspecialchars( $start_char ) . "</h3>\n<ul>";
 229+ $prev_start_char = $start_char;
226230 }
227231 $r .= '<li>' . $elements[$index]->getLongHTMLText($this->getSkin()) . '</li>';
228232 }
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_TypePage.php
@@ -1,6 +1,6 @@
22 <?php
33 /**
4 - * Special handling for relation/attribute description pages.
 4+ * Special handling for type description pages.
55 * Some code based on CategoryPage.php
66 *
77 * @author: Markus Krötzsch
@@ -51,9 +51,6 @@
5252 } else {
5353 $this->articles = $store->getSpecialSubjects(SMW_SP_HAS_TYPE, $typevalue, $options);
5454 }
55 - foreach ($this->articles as $dv) {
56 - $this->articles_start_char[] = $wgContLang->convert( $wgContLang->firstChar( $dv->getSortkey() ) );
57 - }
5855 }
5956
6057 /**
@@ -107,10 +104,10 @@
108105 }
109106
110107 if ( count ( $this->articles ) > $cutoff ) {
111 - return $this->columnList( $start, $end, $this->articles, $this->articles_start_char );
 108+ return $this->columnList( $start, $end, $this->articles );
112109 } elseif ( count($this->articles) > 0) {
113110 // for short lists of articles
114 - return $this->shortList( $start, $end, $this->articles, $this->articles_start_char );
 111+ return $this->shortList( $start, $end, $this->articles );
115112 }
116113 return '';
117114 }
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_PropertyPage.php
@@ -18,7 +18,6 @@
1919
2020 protected $special_prop; // code number of special property, false if not.
2121 private $subproperties; // list of sub-properties of this property
22 - private $subprop_start_char; // array of first characters of printed articles, used for making subheaders
2322
2423 /**
2524 * Use small $limit (property pages might become large)
@@ -33,7 +32,6 @@
3433 protected function clearPageState() {
3534 parent::clearPageState();
3635 $this->subproperties = array();
37 - $this->subprop_start_char = array();
3836 }
3937
4038 /**
@@ -70,18 +68,11 @@
7169 $this->articles = array_reverse($this->articles);
7270 }
7371
74 - foreach ($this->articles as $dv) {
75 - $this->articles_start_char[] = $wgContLang->convert( $wgContLang->firstChar( $dv->getSortkey() ) );
76 - }
77 -
7872 // retrieve all subproperties of this property
7973 $s_options = new SMWRequestOptions();
8074 $s_options->sort = true;
8175 $s_options->ascending = true;
8276 $this->subproperties = $store->getSpecialSubjects(SMW_SP_SUBPROPERTY_OF, $this->getDataValue(), $s_options);
83 - foreach ($this->subproperties as $dv) {
84 - $this->subprop_start_char[] = $wgContLang->convert( $wgContLang->firstChar( $dv->getSortKey() ) );
85 - }
8677 }
8778
8879 /**
@@ -101,9 +92,9 @@
10293 $r .= "<div id=\"mw-subcategories\">\n<h2>" . wfMsg('smw_subproperty_header',$ti) . "</h2>\n";
10394 $r .= '<p>' . wfMsg('smw_subpropertyarticlecount', min($this->limit, count($this->subproperties))) . "</p>\n";
10495 if (count($this->subproperties) < 6) {
105 - $r .= $this->shortList(0,count($this->subproperties), $this->subproperties, $this->subprop_start_char);
 96+ $r .= $this->shortList(0,count($this->subproperties), $this->subproperties);
10697 } else {
107 - $r .= $this->columnList(0,count($this->subproperties), $this->subproperties, $this->subprop_start_char);
 98+ $r .= $this->columnList(0,count($this->subproperties), $this->subproperties);
10899 }
109100 $r .= "\n</div>";
110101 }
@@ -137,20 +128,18 @@
138129 }
139130
140131 $r = '<table style="width: 100%; ">';
141 - $prevchar = 'None';
 132+ $prev_start_char = 'None';
142133 for ($index = $start; $index < $ac; $index++ ) {
 134+ $start_char = $wgContLang->convert( $wgContLang->firstChar( $this->articles[$index]->getSortkey() ) );
143135 // Header for index letters
144 - if ($this->articles_start_char[$index] != $prevchar) {
145 - $r .= '<tr><th class="smwpropname"><h3>' . htmlspecialchars( $this->articles_start_char[$index] ) . "</h3></th><th></th></tr>\n";
146 - $prevchar = $this->articles_start_char[$index];
 136+ if ($start_char != $prev_start_char) {
 137+ $r .= '<tr><th class="smwpropname"><h3>' . htmlspecialchars( $start_char ) . "</h3></th><th></th></tr>\n";
 138+ $prev_start_char = $start_char;
147139 }
148140 // Property name
149141 $searchlink = SMWInfolink::newBrowsingLink('+',$this->articles[$index]->getShortHTMLText());
150142 $r .= '<tr><td class="smwpropname">' . $this->articles[$index]->getLongHTMLText($this->getSkin()) .
151 - /*$this->getSkin()->makeKnownLinkObj( $this->articles[$index]->getTitle,
152 - $wgContLang->convert( $this->articles[$index]->getLongHTMLText() ) ) .*/
153 - '&nbsp;' . $searchlink->getHTML($this->getSkin()) .
154 - '</td><td class="smwprops">';
 143+ '&nbsp;' . $searchlink->getHTML($this->getSkin()) . '</td><td class="smwprops">';
155144 // Property values
156145 $ropts = new SMWRequestOptions();
157146 $ropts->limit = 4;

Status & tagging log