r106430 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106429‎ | r106430 | r106431 >
Date:14:01, 16 December 2011
Author:nikerabbit
Status:deferred
Tags:
Comment:
Fix half of bug 29422 - weird display of special properties
* Some cleanup to related code
* Format the number
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Types.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php
@@ -17,7 +17,7 @@
1818 parent::__construct( 'Properties' );
1919 }
2020
21 - public function execute( $param ) {
 21+ public function execute( $param ) {
2222 wfProfileIn( 'smwfDoSpecialProperties (SMW)' );
2323
2424 global $wgOut;
@@ -55,50 +55,64 @@
5656 }
5757
5858 function formatResult( $skin, $result ) {
 59+ global $wgLang;
5960 $linker = smwfGetLinker();
 61+ list ( $property, $useCount ) = $result;
6062
6163 $typestring = '';
6264 $errors = array();
6365
64 - $diWikiPage = $result[0]->getDiWikiPage();
 66+ $diWikiPage = $property->getDiWikiPage();
6567 $title = !is_null( $diWikiPage ) ? $diWikiPage->getTitle() : null;
6668
67 - if ( $result[0]->isUserDefined() && ( $result[1] <= 5 ) ) {
68 - $errors[] = wfMsg( 'smw_propertyhardlyused' );
69 - }
 69+ if ( $property->isUserDefined() ) {
7070
71 - if ( $result[0]->isUserDefined() && !is_null( $title ) && $title->exists() ) {
72 - $typeProperty = new SMWDIProperty( '_TYPE' );
73 - $types = smwfGetStore()->getPropertyValues( $diWikiPage, $typeProperty );
74 - if ( count( $types ) >= 1 ) {
75 - $typeDataValue = SMWDataValueFactory::newDataItemValue( current( $types ), $typeProperty );
76 - $typestring = $typeDataValue->getLongHTMLText( $linker );
 71+ if ( $title === null ) {
 72+ continue;
7773 }
78 - $proplink = $linker->link( $title, $result[0]->getLabel() );
79 - } elseif ( $result[0]->isUserDefined() && !is_null( $title ) ) {
80 - $errors[] = wfMsg( 'smw_propertylackspage' );
81 - $proplink = $linker->makeBrokenLinkObj( $title, $result[0]->getLabel(), 'action=view' );
82 - } else { // predefined property
83 - $typeid = $result[0]->findPropertyTypeID();
84 - $typeDataValue = SMWTypesValue::newFromTypeId( $typeid );
85 - $propertyDataValue = SMWDataValueFactory::newDataItemValue( $result[0], null );
86 - $typestring = $typeDataValue->getLongHTMLText( $linker );
87 - if ( $typestring === '' ) $typestring = '–'; /// FIXME some types of builtin props have no name, and another message should be used then
88 - $proplink = $propertyDataValue->getLongHTMLText( $linker );
89 - }
9074
91 - if ( $typestring === '' ) {
 75+ if ( $useCount <= 5 ) {
 76+ $errors[] = wfMsgHtml( 'smw_propertyhardlyused' );
 77+ }
 78+
 79+ // User defined types default to Page
9280 global $smwgPDefaultType;
93 -
9481 $typeDataValue = SMWTypesValue::newFromTypeId( $smwgPDefaultType );
9582 $typestring = $typeDataValue->getLongHTMLText( $linker );
96 -
97 - if ( !is_null( $title ) && $title->exists() ) { // print only when we did not print a "nopage" warning yet
98 - $errors[] = wfMsg( 'smw_propertylackstype', $typestring );
 83+
 84+ $label = htmlspecialchars( $property->getLabel() );
 85+ if ( $title->exists() ) {
 86+ $typeProperty = new SMWDIProperty( '_TYPE' );
 87+ $types = smwfGetStore()->getPropertyValues( $diWikiPage, $typeProperty );
 88+ if ( count( $types ) >= 1 ) {
 89+ $typeDataValue = SMWDataValueFactory::newDataItemValue( current( $types ), $typeProperty );
 90+ $typestring = $typeDataValue->getLongHTMLText( $linker );
 91+ } else {
 92+ $errors[] = wfMsgHtml( 'smw_propertylackstype', $typestring );
 93+ }
 94+
 95+ $proplink = $linker->link( $title, $label );
 96+ } else {
 97+ $errors[] = wfMsgHtml( 'smw_propertylackspage' );
 98+ $proplink = $linker->link( $title, $label, array(), array( 'action' => 'view' ) );
9999 }
 100+
 101+ } else { // predefined property
 102+ $typeid = $property->findPropertyTypeID();
 103+ $typeDataValue = SMWTypesValue::newFromTypeId( $typeid );
 104+ $typestring = $typeDataValue->getLongHTMLText( $linker );
 105+ $propertyDataValue = SMWDataValueFactory::newDataItemValue( $property, null );
 106+ $proplink = $propertyDataValue->getShortHtmlText( $linker );
100107 }
101108
102 - return wfMsg( 'smw_property_template', $proplink, $typestring, $result[1] ) . ' ' . smwfEncodeMessages( $errors, 'warning', ' <!--br-->', false );
 109+ $warnings = smwfEncodeMessages( $errors, 'warning', '', false );
 110+
 111+ $useCount = $wgLang->formatNum( $useCount );
 112+ if ( $typestring === '' ) { // Builtins have no type
 113+ return wfMsgHtml( 'smw_property_template_notype', $proplink, $useCount ) . ' ' . $warnings;
 114+ } else {
 115+ return wfMsgHtml( 'smw_property_template', $proplink, $typestring, $useCount ) . ' ' . $warnings;
 116+ }
103117 }
104118
105119 function getResults( $requestoptions ) {
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Types.php
@@ -92,9 +92,9 @@
9393 }
9494 }
9595
96 - public function getShortWikiText( $linked = null ) {
 96+ public function getShortWikiText( $linker = null ) {
9797 global $wgContLang;
98 - if ( is_null( $linked ) || ( $linked === false ) || ( $this->m_outformat == '-' ) || ( $this->m_caption === '' ) ) {
 98+ if ( !$linker || $this->m_outformat === '-' || $this->m_caption === '' ) {
9999 return $this->m_caption;
100100 } else {
101101 $titleText = $this->getSpecialPageTitleText();
@@ -103,18 +103,18 @@
104104 }
105105 }
106106
107 - public function getShortHTMLText( $linked = null ) {
108 - if ( is_null( $linked ) || ( $linked === false ) || ( $this->m_outformat == '-' ) || ( $this->m_caption === '' ) ) {
 107+ public function getShortHTMLText( $linker = null ) {
 108+ if ( !$linker || $this->m_outformat === '-' || $this->m_caption === '' ) {
109109 return htmlspecialchars( $this->m_caption );
110110 } else {
111111 $title = Title::makeTitle( NS_SPECIAL, $this->getSpecialPageTitleText() );
112 - return $linked->makeLinkObj( $title, htmlspecialchars( $this->m_caption ) );
 112+ return $linker->link( $title, htmlspecialchars( $this->m_caption ) );
113113 }
114114 }
115115
116 - public function getLongWikiText( $linked = null ) {
 116+ public function getLongWikiText( $linker = null ) {
117117 global $wgContLang;
118 - if ( is_null( $linked ) || ( $linked === false ) ) {
 118+ if ( !$linker || $this->m_realLabel === '' ) {
119119 return $this->m_realLabel;
120120 } else {
121121 $titleText = $this->getSpecialPageTitleText();
@@ -124,11 +124,11 @@
125125 }
126126
127127 public function getLongHTMLText( $linker = null ) {
128 - if ( is_null( $linker ) || ( $linker === false ) ) {
 128+ if ( !$linker || $this->m_realLabel === '' ) {
129129 return htmlspecialchars( $this->m_realLabel );
130130 } else {
131131 $title = Title::makeTitle( NS_SPECIAL, $this->getSpecialPageTitleText() );
132 - return $linker->makeLinkObj( $title, htmlspecialchars( $this->m_realLabel ) );
 132+ return $linker->link( $title, htmlspecialchars( $this->m_realLabel ) );
133133 }
134134 }
135135
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php
@@ -187,6 +187,7 @@
188188 'properties' => 'Properties',
189189 'smw_properties_docu' => 'The following properties are used in the wiki.',
190190 'smw_property_template' => '$1 of type $2 ($3)', // <propname> of type <type> (<count>)
 191+ 'smw_property_template_notype' => '$1 ($2)', // <propname> (<count>)
191192 'smw_propertylackspage' => 'All properties should be described by a page!',
192193 'smw_propertylackstype' => 'No type was specified for this property (assuming type $1 for now).',
193194 'smw_propertyhardlyused' => 'This property is hardly used within the wiki!',
@@ -506,6 +507,14 @@
507508 'smw_smwadmin_announcedocu' => 'Do not alter or translate link targets',
508509 'smw-info-par-message' => 'Short description of the message parameter behaviour.',
509510 'smw-info-par-icon' => 'Short description of the icon parameter behaviour.',
 511+ 'smw_property_template' => 'Used on [[Special:Properties]]
 512+* $1 link to Property page
 513+* $2 link to Type page
 514+* $3 Number of times the property is used',
 515+ 'smw_property_template_notype' => 'Used on [[Special:Properties]]
 516+* $1 link to Property page
 517+* $2 Number of times the property is used',
 518+
510519 );
511520
512521 /** Niuean (ko e vagahau Niuē)

Follow-up revisions

RevisionCommit summaryAuthorDate
r106571r106430: Make message optional for translationraymond17:52, 18 December 2011