r111407 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111406‎ | r111407 | r111408 >
Date:19:46, 13 February 2012
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
some work on special property handling
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Property.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exporter.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php
@@ -112,7 +112,11 @@
113113 if ( $this->showincoming ) {
114114 list( $indata, $more ) = $this->getInData();
115115 global $smwgBrowseShowInverse;
116 - if ( !$smwgBrowseShowInverse ) $leftside = !$leftside;
 116+
 117+ if ( !$smwgBrowseShowInverse ) {
 118+ $leftside = !$leftside;
 119+ }
 120+
117121 $html .= $this->displayData( $indata, $leftside, true );
118122 $html .= $this->displayBottom( $more );
119123 }
@@ -150,7 +154,7 @@
151155
152156 $diProperties = $data->getProperties();
153157 $noresult = true;
154 - foreach ( $diProperties as $diProperty ) {
 158+ foreach ( $diProperties as $key => $diProperty ) {
155159 $dvProperty = SMWDataValueFactory::newDataItemValue( $diProperty, null );
156160
157161 if ( $dvProperty->isVisible() ) {
@@ -164,20 +168,25 @@
165169 continue; // skip this line
166170 }
167171
168 - $head = "<th>" . $proptext . "</th>\n";
 172+ $head = '<th>' . $proptext . "</th>\n";
169173
170174 $body = "<td>\n";
171175
172176 $values = $data->getPropertyValues( $diProperty );
 177+
173178 if ( $incoming && ( count( $values ) >= SMWSpecialBrowse::$incomingvaluescount ) ) {
174179 $moreIncoming = true;
175180 array_pop( $values );
176181 } else {
177182 $moreIncoming = false;
178183 }
179 -
 184+
180185 $first = true;
181 - foreach ( $values as $di ) {
 186+ foreach ( $values as /* SMWDataItem */ $di ) {
 187+ if ( !$di instanceof SMWDataItem ) {
 188+ throw new MWException('d');
 189+ }
 190+
182191 if ( $first ) {
183192 $first = false;
184193 } else {
@@ -189,6 +198,7 @@
190199 } else {
191200 $dv = SMWDataValueFactory::newDataItemValue( $di, $diProperty );
192201 }
 202+
193203 $body .= "<span class=\"{$ccsPrefix}value\">" .
194204 $this->displayValue( $dvProperty, $dv, $incoming ) . "</span>\n";
195205 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php
@@ -145,6 +145,17 @@
146146 }
147147
148148 /**
 149+ *
 150+ *
 151+ * @param Title $title
 152+ *
 153+ * @return array( SMWDIProperty, SMWDataItem )
 154+ */
 155+ protected static function getSpecialProperties( Title $title ) {
 156+
 157+ }
 158+
 159+ /**
149160 * This function takes care of storing the collected semantic data and takes
150161 * care of clearing out any outdated entries for the processed page. It assume that
151162 * parsing has happened and that all relevant data is contained in the provided parser
@@ -193,29 +204,29 @@
194205 }
195206
196207 // Calculate property value.
197 - $datum = null;
 208+ $value = null;
198209
199210 switch ( $propId ) {
200211 case '_MDAT' :
201212 $timestamp = Revision::getTimeStampFromID( $title, $title->getLatestRevID() );
202 - $datum = self::getDataItemFromMWTimestamp( $timestamp );
 213+ $value = self::getDataItemFromMWTimestamp( $timestamp );
203214 break;
204215 case '_CDAT' :
205216 $timestamp = $title->getFirstRevision()->getTimestamp();
206 - $datum = self::getDataItemFromMWTimestamp( $timestamp );
 217+ $value = self::getDataItemFromMWTimestamp( $timestamp );
207218 break;
208219 case '_NEWP' :
209 - $datum = new SMWDIBoolean( $title->isNewPage() );
 220+ $value = new SMWDIBoolean( $title->isNewPage() );
210221 break;
211222 case '_LEDT' :
212223 $revision = Revision::newFromId( $title->getLatestRevID() );
213224 $user = User::newFromId( $revision->getUser() );
214 - $datum = SMWDIWikiPage::newFromTitle( $user->getUserPage() );
 225+ $value = SMWDIWikiPage::newFromTitle( $user->getUserPage() );
215226 break;
216227 }
217228
218 - if ( !is_null( $datum ) ) {
219 - $semdata->addPropertyObjectValue( $prop, $datum );
 229+ if ( !is_null( $value ) ) {
 230+ $semdata->addPropertyObjectValue( $prop, $value );
220231 } // Issue error or warning?
221232
222233 } // foreach
@@ -414,8 +425,9 @@
415426 * a global/static variable appears to be the only way to get more article data to
416427 * LinksUpdate.
417428 */
418 - static public function onNewRevisionFromEditComplete( $article, $rev, $baseID ) {
 429+ static public function onNewRevisionFromEditComplete( WikiPage $article, $rev, $baseID ) {
419430 global $smwgPageSpecialProperties;
 431+
420432 if ( ( $article->mPreparedEdit ) && ( $article->mPreparedEdit->output instanceof ParserOutput ) ) {
421433 $output = $article->mPreparedEdit->output;
422434 $title = $article->getTitle();
@@ -433,14 +445,28 @@
434446 }
435447
436448 if ( in_array( '_MDAT', $smwgPageSpecialProperties ) ) {
437 - $pmdat = new SMWDIProperty( '_MDAT' );
438449 $timestamp = $article->getTimestamp();
439450 $di = self::getDataItemFromMWTimestamp( $timestamp );
440451
441452 if ( !is_null( $di ) ) {
442 - $semdata->addPropertyObjectValue( $pmdat, $di );
 453+ $semdata->addPropertyObjectValue( new SMWDIProperty( '_MDAT' ), $di );
443454 }
444455 }
 456+
 457+ if ( in_array( '_LEDT', $smwgPageSpecialProperties ) ) {
 458+ $di = SMWDIWikiPage::newFromTitle( User::newFromId( $article->getRevision()->getUser() )->getUserPage() );
 459+
 460+ if ( !is_null( $di ) ) {
 461+ $semdata->addPropertyObjectValue( new SMWDIProperty( '_LEDT' ), $di );
 462+ }
 463+ }
 464+
 465+ if ( in_array( '_NEWP', $smwgPageSpecialProperties ) ) {
 466+ $semdata->addPropertyObjectValue(
 467+ new SMWDIProperty( '_NEWP' ),
 468+ new SMWDIBoolean( is_null( $article->getRevision()->getParentId() ) )
 469+ );
 470+ }
445471
446472 return true;
447473 }
Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exporter.php
@@ -424,6 +424,12 @@
425425 }
426426 case '_MDAT':
427427 return self::getSpecialNsResource( 'swivt', 'wikiPageModificationDate' );
 428+ case '_CDAT':
 429+ return self::getSpecialNsResource( 'swivt', 'wikiPageCreationDate' );
 430+ case '_LEDT':
 431+ return self::getSpecialNsResource( 'swivt', 'wikiPageLastEditor' );
 432+ case '_NEWP':
 433+ return self::getSpecialNsResource( 'swivt', 'wikiPageIsNew' );
428434 case '_SKEY':
429435 return self::getSpecialNsResource( 'swivt', 'wikiPageSortKey' );
430436 case '_TYPE':
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Property.php
@@ -331,8 +331,8 @@
332332 '_CONC' => array( '__con', false ), // associated concept
333333 '_MDAT' => array( '_dat', false ), // "modification date"
334334 '_CDAT' => array( '_dat', false ), // "creation date"
335 - '_NEWP' => array( '_boo', false ), // "page is new"
336 - '_LEDT' => array( '_wpg', false ), // "page is new"
 335+ '_NEWP' => array( '_dat', false ), // "is a new page"
 336+ '_LEDT' => array( '_wpg', false ), // "last editor is"
337337 '_ERRP' => array( '_wpp', false ), // "has improper value for"
338338 '_LIST' => array( '__pls', true ), // "has fields"
339339 '_SKEY' => array( '__key', false ), // sort key of a page

Follow-up revisions

RevisionCommit summaryAuthorDate
r111410Follow up to r111407;jeroendedauw19:57, 13 February 2012
r112197fix bug 34499, follow up r111407jeroendedauw12:34, 23 February 2012

Comments

#Comment by Nikerabbit (talk | contribs)   16:09, 14 February 2012
-		foreach ( $diProperties as $diProperty ) {
+		foreach ( $diProperties as $key => $diProperty ) {

I don't see $key being used anywhere.