r89368 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89367‎ | r89368 | r89369 >
Date:21:17, 2 June 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on replacing skin by linker
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialUnusedProperties.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialWantedProperties.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialPageProperty.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialSearchByProperty.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php
@@ -52,6 +52,8 @@
5353 }
5454
5555 function formatResult( $skin, $result ) {
 56+ $linker = smwfGetLinker();
 57+
5658 $typestring = '';
5759 $errors = array();
5860
@@ -67,25 +69,25 @@
6870 $types = smwfGetStore()->getPropertyValues( $diWikiPage, $typeProperty );
6971 if ( count( $types ) >= 1 ) {
7072 $typeDataValue = SMWDataValueFactory::newDataItemValue( current( $types ), $typeProperty );
71 - $typestring = $typeDataValue->getLongHTMLText( $skin );
 73+ $typestring = $typeDataValue->getLongHTMLText( $linker );
7274 }
73 - $proplink = $skin->makeKnownLinkObj( $title, $result[0]->getLabel() );
 75+ $proplink = $linker->makeKnownLinkObj( $title, $result[0]->getLabel() );
7476 } elseif ( $result[0]->isUserDefined() && $title !== null ) {
7577 $errors[] = wfMsg( 'smw_propertylackspage' );
76 - $proplink = $skin->makeBrokenLinkObj( $title, $result[0]->getLabel(), 'action=view' );
 78+ $proplink = $linker->makeBrokenLinkObj( $title, $result[0]->getLabel(), 'action=view' );
7779 } else { // predefined property
7880 $typeid = $result[0]->findPropertyTypeID();
7981 $typeDataValue = SMWTypesValue::newFromTypeId( $typeid );
8082 $propertyDataValue = SMWDataValueFactory::newDataItemValue( $result[0], null );
81 - $typestring = $typeDataValue->getLongHTMLText( $skin );
 83+ $typestring = $typeDataValue->getLongHTMLText( $linker );
8284 if ( $typestring == '' ) $typestring = '–'; /// FIXME some types of builtin props have no name, and another message should be used then
83 - $proplink = $propertyDataValue->getLongHTMLText( $skin );
 85+ $proplink = $propertyDataValue->getLongHTMLText( $linker );
8486 }
8587
8688 if ( $typestring == '' ) {
8789 global $smwgPDefaultType;
8890 $typeDataValue = SMWTypesValue::newFromTypeId( $smwgPDefaultType );
89 - $typestring = $typeDataValue->getLongHTMLText( $skin );
 91+ $typestring = $typeDataValue->getLongHTMLText( $linker );
9092 if ( $title !== null && $title->exists() ) { // print only when we did not print a "nopage" warning yet
9193 $errors[] = wfMsg( 'smw_propertylackstype', $typestring );
9294 }
Index: trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialWantedProperties.php
@@ -66,11 +66,14 @@
6767 }
6868
6969 function formatResult( $skin, $result ) {
 70+ $linker = smwfGetLinker();
 71+
7072 if ( $result[0]->isUserDefined() ) {
71 - $proplink = $skin->makeLinkObj( $result[0]->getWikiPageValue()->getTitle(), htmlspecialchars( $result[0]->getWikiValue() ), 'action=view' );
 73+ $proplink = $linker->makeLinkObj( $result[0]->getWikiPageValue()->getTitle(), htmlspecialchars( $result[0]->getWikiValue() ), 'action=view' );
7274 } else {
73 - $proplink = $result[0]->getLongHTMLText( $skin );
 75+ $proplink = $result[0]->getLongHTMLText( $linker );
7476 }
 77+
7578 return wfMsgExt( 'smw_wantedproperty_template', array( 'parsemag' ), $proplink, $result[1] );
7679 }
7780
Index: trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialUnusedProperties.php
@@ -67,7 +67,9 @@
6868 }
6969
7070 function formatResult( $skin, /* SMWDIProperty */ $result ) {
71 - $proplink = $skin->makeKnownLinkObj(
 71+ $linker = smwfGetLinker();
 72+
 73+ $proplink = $linker->makeKnownLinkObj(
7274 $result->getDiWikiPage()->getTitle(),
7375 $result->getLabel()
7476 );
@@ -76,10 +78,10 @@
7779 $errors = array();
7880
7981 if ( count( $types ) >= 1 ) {
80 - $typestring = SMWDataValueFactory::newDataItemValue( current( $types ), new SMWDIProperty( '_TYPE' ) )->getLongHTMLText( $skin );
 82+ $typestring = SMWDataValueFactory::newDataItemValue( current( $types ), new SMWDIProperty( '_TYPE' ) )->getLongHTMLText( $linker );
8183 } else {
8284 $type = SMWTypesValue::newFromTypeId( '_wpg' );
83 - $typestring = $type->getLongHTMLText( $skin );
 85+ $typestring = $type->getLongHTMLText( $linker );
8486 $errors[] = wfMsg( 'smw_propertylackstype', $type->getLongHTMLText() );
8587 }
8688
Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialSearchByProperty.php
@@ -100,14 +100,14 @@
101101 */
102102 private function displaySearchByProperty() {
103103 global $wgOut, $smwgSearchByPropertyFuzzy;
104 - $skin = $this->getSkin();
 104+ $linker = smwfGetLinker();
105105
106106 if ( $this->propertystring == '' ) {
107107 return '<p>' . wfMsg( 'smw_sbv_docu' ) . "</p>\n";
108108 }
109109
110110 if ( ( $this->value == null ) || !$this->value->isValid() ) {
111 - return '<p>' . wfMsg( 'smw_sbv_novalue', $this->property->getShortHTMLText( $skin ) ) . "</p>\n";
 111+ return '<p>' . wfMsg( 'smw_sbv_novalue', $this->property->getShortHTMLText( $linker ) ) . "</p>\n";
112112 }
113113
114114 $wgOut->setPagetitle( $this->property->getWikiValue() . ' ' . $this->value->getShortHTMLText( null ) );
@@ -119,12 +119,15 @@
120120 if ( ( $count < ( $this->limit / 3 ) ) && ( $this->value->isNumeric() ) && $smwgSearchByPropertyFuzzy ) {
121121 $greater = $this->getNearbyResults( $count, true );
122122 $lesser = $this->getNearbyResults( $count, false );
 123+
123124 // Calculate how many greater and lesser results should be displayed
124125 $cG = count( $greater );
125126 $cL = count( $lesser );
 127+
126128 if ( ( $cG + $cL + $count ) > $this->limit ) {
127129 $l = $this->limit - $count;
128130 $lhalf = round( $l / 2 );
 131+
129132 if ( $lhalf < $cG ) {
130133 if ( $lhalf < $cL ) {
131134 $cL = $lhalf; $cG = $lhalf;
@@ -135,20 +138,24 @@
136139 $cL = $this->limit - ( $count + $cG );
137140 }
138141 }
 142+
139143 if ( ( $cG + $cL + $count ) == 0 )
140144 $html .= wfMsg( 'smw_result_noresults' );
141145 else {
142 - $html .= wfMsg( 'smw_sbv_displayresultfuzzy', $this->property->getShortHTMLText( $skin ), $this->value->getShortHTMLText( $skin ) ) . "<br />\n";
 146+ $html .= wfMsg( 'smw_sbv_displayresultfuzzy', $this->property->getShortHTMLText( $linker ), $this->value->getShortHTMLText( $linker ) ) . "<br />\n";
143147 $html .= $this->displayResults( $lesser, $cL, false );
 148+
144149 if ( $count == 0 ) {
145150 $html .= " &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<em><strong><small>(" . $this->value->getLongHTMLText() . ")</small></strong></em>\n";
146151 } else {
147152 $html .= $this->displayResults( $exact, $count, true, true );
148153 }
 154+
149155 $html .= $this->displayResults( $greater, $cG );
150156 }
151157 } else {
152 - $html .= wfMsg( 'smw_sbv_displayresult', $this->property->getShortHTMLText( $skin ), $this->value->getShortHTMLText( $skin ) ) . "<br />\n";
 158+ $html .= wfMsg( 'smw_sbv_displayresult', $this->property->getShortHTMLText( $linker ), $this->value->getShortHTMLText( $linker ) ) . "<br />\n";
 159+
153160 if ( 0 == $count ) {
154161 $html .= wfMsg( 'smw_result_noresults' );
155162 } else {
@@ -160,6 +167,7 @@
161168 }
162169
163170 $html .= '<p>&#160;</p>';
 171+
164172 return $html;
165173 }
166174
@@ -173,18 +181,16 @@
174182 * @return string HTML with the bullet list and a header
175183 */
176184 private function displayResults( $results, $number = - 1, $first = true, $highlight = false ) {
177 - $skin = $this->getSkin();
178 -
179185 $html = "<ul>\n";
180186
181187 if ( !$first && ( $number > 0 ) ) while ( count( $results ) > $number ) array_shift( $results );
182188 while ( $results && $number != 0 ) {
183189 $result = array_shift( $results );
184 - $thing = $result[0]->getLongHTMLText( $skin );
 190+ $thing = $result[0]->getLongHTMLText( smwfGetLinker() );
185191 $browselink = ( $result[0]->getTypeId() == '_wpg' ) ?
186 - '&#160;&#160;' . SMWInfolink::newBrowsingLink( '+', $result[0]->getShortHTMLText() )->getHTML( $skin ):'';
 192+ '&#160;&#160;' . SMWInfolink::newBrowsingLink( '+', $result[0]->getShortHTMLText() )->getHTML( smwfGetLinker() ):'';
187193 $html .= '<li>' . $thing . $browselink;
188 - if ( ( $this->value != $result[1] ) || $highlight ) $html .= " <em><small>(" . $result[1]->getLongHTMLText( $skin ) . ")</small></em>";
 194+ if ( ( $this->value != $result[1] ) || $highlight ) $html .= " <em><small>(" . $result[1]->getLongHTMLText( smwfGetLinker() ) . ")</small></em>";
189195 $html .= "</li>";
190196 if ( $highlight ) $html = "<strong>" . $html . "</strong>";
191197 $html .= "\n";
@@ -204,13 +210,14 @@
205211 */
206212 private function getNavigationBar( $count ) {
207213 global $smwgQMaxInlineLimit;
208 - $skin = $this->getSkin();
209214
210 - if ( $this->offset > 0 )
 215+ if ( $this->offset > 0 ) {
211216 $navigation = '<a href="' . htmlspecialchars( $skin->makeSpecialUrl( 'SearchByProperty', 'offset=' . max( 0, $this->offset - $this->limit ) . '&limit=' . $this->limit . '&property=' . urlencode( $this->property->getWikiValue() ) . '&value=' . urlencode( $this->value->getWikiValue() ) ) ) . '">' . wfMsg( 'smw_result_prev' ) . '</a>';
212 - else
 217+ }
 218+ else {
213219 $navigation = wfMsg( 'smw_result_prev' );
214 -
 220+ }
 221+
215222 $navigation .= '&#160;&#160;&#160;&#160; <b>' . wfMsg( 'smw_result_results' ) . ' ' . ( $this->offset + 1 ) . '– ' . ( $this->offset + min( $count, $this->limit ) ) . '</b>&#160;&#160;&#160;&#160;';
216223
217224 if ( $count > $this->limit ) {
@@ -219,25 +226,31 @@
220227 $navigation .= wfMsg( 'smw_result_next' );
221228 }
222229
223 - $max = false; $first = true;
 230+ $max = false;
 231+ $first = true;
 232+
224233 foreach ( array( 20, 50, 100, 250, 500 ) as $l ) {
225234 if ( $max ) continue;
 235+
226236 if ( $first ) {
227237 $navigation .= '&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(';
228238 $first = false;
229239 } else {
230240 $navigation .= ' ' . wfMsgExt( 'pipe-separator' , 'escapenoentities' ) . ' ';
231241 }
 242+
232243 if ( $l > $smwgQMaxInlineLimit ) {
233244 $l = $smwgQMaxInlineLimit;
234245 $max = true;
235246 }
 247+
236248 if ( $this->limit != $l ) {
237249 $navigation .= '<a href="' . htmlspecialchars( $skin->makeSpecialUrl( 'SearchByProperty', 'offset=' . $this->offset . '&limit=' . $l . '&property=' . urlencode( $this->property->getWikiValue() ) . '&value=' . urlencode( $this->value->getWikiValue() ) ) ) . '">' . $l . '</a>';
238250 } else {
239251 $navigation .= '<b>' . $l . '</b>';
240252 }
241253 }
 254+
242255 $navigation .= ')';
243256 return $navigation;
244257 }
@@ -327,21 +340,4 @@
328341 return $html;
329342 }
330343
331 - /**
332 - * Compatibility method to get the skin; MW 1.18 introduces a getSkin method in SpecialPage.
333 - *
334 - * @since 1.6
335 - *
336 - * @return Skin
337 - */
338 - public function getSkin() {
339 - if ( method_exists( 'SpecialPage', 'getSkin' ) ) {
340 - return parent::getSkin();
341 - }
342 - else {
343 - global $wgUser;
344 - return $wgUser->getSkin();
345 - }
346 - }
347 -
348344 }
Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php
@@ -201,16 +201,16 @@
202202 * @return string HTML with the link to the article, browse, and search pages
203203 */
204204 private function displayValue( SMWPropertyValue $property, SMWDataValue $dataValue, $incoming ) {
205 - $skin = $this->getSkin();
 205+ $linker = smwfGetLinker();
206206
207 - $html = $dataValue->getLongHTMLText( $skin );
 207+ $html = $dataValue->getLongHTMLText( $linker );
208208
209209 if ( $dataValue->getTypeID() == '_wpg' ) {
210 - $html .= "&#160;" . SMWInfolink::newBrowsingLink( '+', $dataValue->getLongWikiText() )->getHTML( $skin );
 210+ $html .= "&#160;" . SMWInfolink::newBrowsingLink( '+', $dataValue->getLongWikiText() )->getHTML( $linker );
211211 } elseif ( $incoming && $property->isVisible() ) {
212 - $html .= "&#160;" . SMWInfolink::newInversePropertySearchLink( '+', $dataValue->getTitle(), $property->getText(), 'smwsearch' )->getHTML( $skin );
 212+ $html .= "&#160;" . SMWInfolink::newInversePropertySearchLink( '+', $dataValue->getTitle(), $property->getText(), 'smwsearch' )->getHTML( $linker );
213213 } else {
214 - $html .= $dataValue->getInfolinkText( SMW_OUTPUT_HTML, $skin );
 214+ $html .= $dataValue->getInfolinkText( SMW_OUTPUT_HTML, $linker );
215215 }
216216
217217 return $html;
@@ -376,21 +376,4 @@
377377 return $count > 2 ? preg_replace( '/($nonBreakingSpace)/u', ' ', $text, max( 0, $count - 2 ) ):$text;
378378 }
379379
380 - /**
381 - * Compatibility method to get the skin; MW 1.18 introduces a getSkin method in SpecialPage.
382 - *
383 - * @since 1.6
384 - *
385 - * @return Skin
386 - */
387 - public function getSkin() {
388 - if ( method_exists( 'SpecialPage', 'getSkin' ) ) {
389 - return parent::getSkin();
390 - }
391 - else {
392 - global $wgUser;
393 - return $wgUser->getSkin();
394 - }
395 - }
396 -
397380 }
Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialPageProperty.php
@@ -31,7 +31,7 @@
3232
3333 public function execute( $query ) {
3434 global $wgRequest, $wgOut;
35 - $skin = $this->getSkin();
 35+ $linker = smwfGetLinker();
3636 $this->setHeaders();
3737
3838 // Get parameters
@@ -72,14 +72,41 @@
7373 // prepare navigation bar if needed
7474 if ( ( $offset > 0 ) || ( count( $results ) > $limit ) ) {
7575 if ( $offset > 0 ) {
76 - $navigation = '<a href="' . htmlspecialchars( $skin->makeSpecialUrl( 'PageProperty', 'offset=' . max( 0, $offset - $limit ) . '&limit=' . $limit . '&type=' . urlencode( $propname ) . '&from=' . urlencode( $pagename ) ) ) . '">' . wfMsg( 'smw_result_prev' ) . '</a>';
 76+ $navigation = Html::element(
 77+ 'a',
 78+ array(
 79+ 'href' => SpecialPage::getSafeTitleFor( 'PageProperty' )->getLocalURL(
 80+ 'offset=' . max( 0, $offset - $limit ) .
 81+ '&limit=' . $limit .
 82+ '&type=' . urlencode( $propname ) .
 83+ '&from=' . urlencode( $pagename )
 84+ )
 85+ ),
 86+ wfMsg( 'smw_result_prev' )
 87+ );
7788 } else {
7889 $navigation = wfMsg( 'smw_result_prev' );
7990 }
8091
81 - $navigation .= '&#160;&#160;&#160;&#160; <b>' . wfMsg( 'smw_result_results' ) . ' ' . ( $offset + 1 ) . '– ' . ( $offset + min( count( $results ), $limit ) ) . '</b>&#160;&#160;&#160;&#160;';
 92+ $navigation .=
 93+ '&#160;&#160;&#160;&#160; <b>' .
 94+ wfMsg( 'smw_result_results' ) . ' ' .
 95+ ( $offset + 1 ) . '– ' . ( $offset + min( count( $results ), $limit ) ) .
 96+ '</b>&#160;&#160;&#160;&#160;';
 97+
8298 if ( count( $results ) == ( $limit + 1 ) ) {
83 - $navigation .= ' <a href="' . htmlspecialchars( $skin->makeSpecialUrl( 'PageProperty', 'offset=' . ( $offset + $limit ) . '&limit=' . $limit . '&type=' . urlencode( $propname ) . '&from=' . urlencode( $pagename ) ) ) . '">' . wfMsg( 'smw_result_next' ) . '</a>';
 99+ $navigation = Html::element(
 100+ 'a',
 101+ array(
 102+ 'href' => SpecialPage::getSafeTitleFor( 'PageProperty' )->getLocalURL(
 103+ 'offset=' . ( $offset + $limit ) .
 104+ '&limit=' . $limit .
 105+ '&type=' . urlencode( $propname ) .
 106+ '&from=' . urlencode( $pagename )
 107+ )
 108+ ),
 109+ wfMsg( 'smw_result_next' )
 110+ );
84111 } else {
85112 $navigation .= wfMsg( 'smw_result_next' );
86113 }
@@ -98,10 +125,10 @@
99126 $count--;
100127 if ( $count < 1 ) continue;
101128 $dv = SMWDataValueFactory::newDataItemValue( $di, $property->getDataItem() );
102 - $html .= '<li>' . $dv->getLongHTMLText( $skin ); // do not show infolinks, the magnifier "+" is ambiguous with the browsing '+' for '_wpg' (see below)
 129+ $html .= '<li>' . $dv->getLongHTMLText( $linker ); // do not show infolinks, the magnifier "+" is ambiguous with the browsing '+' for '_wpg' (see below)
103130 if ( $property->getDataItem()->findPropertyTypeID() == '_wpg' ) {
104131 $browselink = SMWInfolink::newBrowsingLink( '+', $dv->getLongWikiText() );
105 - $html .= ' &#160;' . $browselink->getHTML( $skin );
 132+ $html .= ' &#160;' . $browselink->getHTML( $linker );
106133 }
107134 $html .= "</li> \n";
108135 }
@@ -123,21 +150,4 @@
124151 SMWOutputs::commitToOutputPage( $wgOut ); // make sure locally collected output data is pushed to the output!
125152 }
126153
127 - /**
128 - * Compatibility method to get the skin; MW 1.18 introduces a getSkin method in SpecialPage.
129 - *
130 - * @since 1.6
131 - *
132 - * @return Skin
133 - */
134 - public function getSkin() {
135 - if ( method_exists( 'SpecialPage', 'getSkin' ) ) {
136 - return parent::getSkin();
137 - }
138 - else {
139 - global $wgUser;
140 - return $wgUser->getSkin();
141 - }
142 - }
143 -
144154 }

Status & tagging log