r68510 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68509‎ | r68510 | r68511 >
Date:11:03, 24 June 2010
Author:ning
Status:deferred
Tags:
Comment:
Bug fix: RSS generate redundant data when 'delegate' is enabled
Modified paths:
  • /trunk/extensions/SemanticNotifyMe/includes/SMW_NotifyProcessor.php (modified) (history)
  • /trunk/extensions/SemanticNotifyMe/includes/storage/SMW_NMStorageSQL.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticNotifyMe/includes/SMW_NotifyProcessor.php
@@ -43,16 +43,10 @@
4444 SMWQueryProcessor::processFunctionParams( SMWNotifyProcessor::getQueryRawParams( $querystring ), $querystring, $params, $printouts );
4545 $relatedArticles = array();
4646 foreach ( $printouts as $po ) {
47 - if ( $po == $params['sort'] ) $sorted = true;
4847 $printoutArticles[] = array(
4948 'namespace' => SMW_NS_PROPERTY,
50 - 'title' => Title::makeTitle( SMW_NS_PROPERTY, $po->getText() )->getDBkey() );
 49+ 'title' => Title::makeTitle( SMW_NS_PROPERTY, $po->getText( SMW_OUTPUT_WIKI ) )->getDBkey() );
5150 }
52 - if ( !$sorted && isset( $params['sort'] ) ) {
53 - $printoutArticles[] = array(
54 - 'namespace' => SMW_NS_PROPERTY,
55 - 'title' => Title::makeTitle( SMW_NS_PROPERTY, $params['sort'] )->getDBkey() );
56 - }
5751
5852 $qp = new SMWNotifyParser( $notify_id, $printoutArticles );
5953 $qp->setDefaultNamespaces( $smwgQDefaultNamespaces );
@@ -1129,16 +1123,16 @@
11301124
11311125 class SMWNotifyUpdate {
11321126 protected $m_info;
1133 - protected $m_title;
1134 - protected $m_userMsgs;
1135 - protected $m_userHtmlPropMsgs;
1136 - protected $m_userHtmlNMMsgs;
1137 - protected $m_userNMs;
1138 - protected $m_notifyHtmlPropMsgs;
1139 - protected $m_notifyHtmlMsgs;
1140 - protected $m_newMonitor;
1141 - protected $m_removeMonitored;
1142 - protected $m_subQueryNotify;
 1127+ protected $m_title; // current title of the update
 1128+ protected $m_userMsgs; // user_id => plain text message
 1129+ protected $m_userHtmlPropMsgs; // user_id => html message, prop change detail
 1130+ protected $m_userHtmlNMMsgs; // user_id => html message, all notify hint
 1131+ protected $m_userNMs; // user_id => notify_id
 1132+ protected $m_notifyHtmlPropMsgs; // notify_id => html message, prop change detail
 1133+ protected $m_notifyHtmlMsgs; // notify_id => html message, all notify hint
 1134+ protected $m_newMonitor; // notify newly matches the page, array( notify id, page id )
 1135+ protected $m_removeMonitored; // notify no longer matches the page, array( notify id, page id )
 1136+ protected $m_subQueryNotify; // subquery, will go through all pages, attention!!!
11431137
11441138 protected $m_linker;
11451139
@@ -1202,6 +1196,7 @@
12031197 $sStore = NMStorage::getDatabase();
12041198 $notifications = $sStore->getMonitoredNotifications( $page_id );
12051199
 1200+ $notifyMsgAdded = array();
12061201 foreach ( $notifications as $user_id => $notifies ) {
12071202 $this->m_userMsgs[$user_id] .= $msg . '\r\n( NM: ';
12081203 $hint = wfMsg( 'smw_nm_hint_delete_html', $page_html_name, htmlspecialchars( $reason ) );
@@ -1215,7 +1210,10 @@
12161211 } else {
12171212 $first = false;
12181213 }
1219 - $this->m_notifyHtmlMsgs[$notify_id] .= $hint;
 1214+ if ( !isset( $notifyMsgAdded[$notify_id] ) ) {
 1215+ $this->m_notifyHtmlMsgs[$notify_id] .= $hint;
 1216+ $notifyMsgAdded[$notify_id] = true;
 1217+ }
12201218
12211219 $this->m_userMsgs[$user_id] .= $notify_detail['name'];
12221220 $htmlMsg .= '<b>' . htmlspecialchars( $notify_detail['name'] ) . '</b>';
@@ -1273,13 +1271,13 @@
12741272 $i = SMWNotifyProcessor::getInfoFromId( $key );
12751273 if ( $i[type] == 0 ) {
12761274 return "<td>Category</td>
1277 - <td>" . $info[name]->getShortHTMLText( $this->m_linker ) . "</td>
 1275+ <td>" . $this->getFullLink( $info[name] ) . "</td>
12781276 <td>" . ( $info[sem_act] == 0 ? "<font color='green'>remove</font>":"<font color='red'>cite</font>" ) . "</td>
12791277 <td colspan='2'>N/A</td>";
12801278 } else {
12811279 $rows = max( count( $info[del_vals] ), count( $info[new_vals] ) );
12821280 $tmp = "<tr><td rowspan='$rows'>Property</td>
1283 - <td rowspan='$rows'>" . $info[name]->getShortHTMLText( $this->m_linker ) . "</td>
 1281+ <td rowspan='$rows'>" . $this->getFullLink( $info[name] ) . "</td>
12841282 <td rowspan='$rows'>" . ( $info[sem_act] == 0 ? "<font color='green'>remove</font>":( $info[sem_act] == 1 ? "<font color='blue'>modify</font>":"<font color='red'>cite</font>" ) ) . "</td>";
12851283 for ( $idx = 0; $idx < $rows; ++$idx ) {
12861284 if ( $idx > 0 ) {
@@ -1311,7 +1309,7 @@
13121310 } else {
13131311 $tmp_info[$key] = array( 'sem_act' => 0, 'name' => $value[0][name], 'del_vals' => array(), 'new_vals' => array() );
13141312 foreach ( $value as $v ) {
1315 - $tmp_info[$key][del_vals][] = array( 'plain' => $v[value]->getWikiValue(), 'html' => $v[value]->getShortHTMLText( $this->m_linker ) );
 1313+ $tmp_info[$key][del_vals][] = array( 'plain' => $v[value]->getWikiValue(), 'html' => $this->getFullLink( $v[value] ) );
13161314 }
13171315 }
13181316 } else if ( $i[type] == 2 ) {
@@ -1329,7 +1327,7 @@
13301328 $updated = true;
13311329 $tmp_info[$key] = array( 'sem_act' => 1, 'name' => $value[0][name], 'del_vals' => array(), 'new_vals' => array() );
13321330 }
1333 - $tmp_info[$key][del_vals][] = array( 'plain' => $v1[value]->getWikiValue(), 'html' => $v1[value]->getShortHTMLText( $this->m_linker ) );
 1331+ $tmp_info[$key][del_vals][] = array( 'plain' => $v1[value]->getWikiValue(), 'html' => $this->getFullLink( $v1[value] ) );
13341332 }
13351333 }
13361334 foreach ( $mvalue as $v1 ) {
@@ -1345,7 +1343,7 @@
13461344 $updated = true;
13471345 $tmp_info[$key] = array( 'sem_act' => 1, 'name' => $value[0][name], 'del_vals' => array(), 'new_vals' => array() );
13481346 }
1349 - $tmp_info[$key][new_vals][] = array( 'plain' => $v1[value]->getWikiValue(), 'html' => $v1[value]->getShortHTMLText( $this->m_linker ) );
 1347+ $tmp_info[$key][new_vals][] = array( 'plain' => $v1[value]->getWikiValue(), 'html' => $this->getFullLink( $v1[value] ) );
13501348 }
13511349 }
13521350 }
@@ -1358,7 +1356,7 @@
13591357 } else {
13601358 $tmp_info[$key] = array( 'sem_act' => 2, 'name' => $value[0][name], 'del_vals' => array(), 'new_vals' => array() );
13611359 foreach ( $value as $v ) {
1362 - $tmp_info[$key][new_vals][] = array( 'plain' => $v[value]->getWikiValue(), 'html' => $v[value]->getShortHTMLText( $this->m_linker ) );
 1360+ $tmp_info[$key][new_vals][] = array( 'plain' => $v[value]->getWikiValue(), 'html' => $this->getFullLink( $v[value] ) );
13631361 }
13641362 }
13651363 }
@@ -1375,7 +1373,9 @@
13761374 }
13771375 $page_name = $this->m_title->getText() . ' (' . $this->m_title->getFullUrl() . ')';
13781376
 1377+ $notifyMsgAdded = array();
13791378 foreach ( $notifications as $user_id => $notifies ) {
 1379+ if ( !isset( $notifies['semantic'] ) ) continue;
13801380 foreach ( $notifies['semantic'] as $key => $notify ) {
13811381 if ( isset( $tmp_info[$key] ) ) {
13821382 $hint = "";
@@ -1388,18 +1388,25 @@
13891389 $this->m_userMsgs[$user_id] .= $this->getNotifyPlain( $tmp_info[$key], $key ) . ' ( NM: ';
13901390 $propHint = $this->getNotifyHtml( $tmp_info[$key], $key );
13911391 $this->m_userHtmlPropMsgs[$user_id] .= $propHint . "<tr><td colspan='5'>" . wfMsg( 'smw_notifyme' ) . ": ";
1392 - $idx = 0;
 1392+ $first = true;
13931393 foreach ( $notify as $notify_id => $notify_name ) {
1394 - if ( $idx > 0 ) {
 1394+ if ( !$first ) {
13951395 $this->m_userMsgs[$user_id] .= ', ';
13961396 $this->m_userHtmlPropMsgs[$user_id] .= ', ';
 1397+ } else {
 1398+ $first = false;
13971399 }
13981400 $this->m_userMsgs[$user_id] .= $notify_name;
13991401 $this->m_userHtmlPropMsgs[$user_id] .= '<b>' . htmlspecialchars( $notify_name ) . '</b>';
1400 - $this->m_notifyHtmlMsgs[$notify_id] .= $hint;
1401 - $this->m_notifyHtmlPropMsgs[$notify_id] .= $propHint;
1402 - $idx++;
14031402
 1403+ if ( !isset( $notifyMsgAdded[$notify_id] ) ) {
 1404+ $this->m_notifyHtmlMsgs[$notify_id] .= $hint;
 1405+ }
 1406+ if ( !isset( $notifyMsgAdded[$notify_id][$key] ) ) {
 1407+ $this->m_notifyHtmlPropMsgs[$notify_id] .= $propHint;
 1408+ $notifyMsgAdded[$notify_id][$key] = true;
 1409+ }
 1410+
14041411 $this->m_userNMs[$user_id][] = $notify_id;
14051412 }
14061413 $this->m_userMsgs[$user_id] .= ' ).';
@@ -1443,19 +1450,25 @@
14441451 foreach ( $main_queries as $notify_id => $notify ) {
14451452 $sStore->getNotifyInMainQuery( $page_id, $notify_id, $notify['sql'], $notify['hierarchy'], $match, $monitoring );
14461453 if ( ( !$monitoring ) && $match ) {
1447 - $this->m_userMsgs[$notify['user_id']] .= wfMsg( 'smw_nm_hint_match', $page_name, $notify[name] );
14481454 $hint = wfMsg( 'smw_nm_hint_match_html', $page_html_name, htmlspecialchars( $notify[name] ) );
1449 - $this->m_userHtmlNMMsgs[$notify['user_id']] .= $hint;
 1455+ foreach ( $notify['user_ids'] as $uid ) {
 1456+ $this->m_userMsgs[$uid] .= wfMsg( 'smw_nm_hint_match', $page_name, $notify[name] );
 1457+ $this->m_userHtmlNMMsgs[$uid] .= $hint;
 1458+ }
14501459 $this->m_notifyHtmlMsgs[$notify_id] .= $hint;
14511460 $this->m_newMonitor[] = array( 'notify_id' => $notify_id, 'page_id' => $page_id );
14521461 } else if ( ( !$match ) && $monitoring ) {
1453 - $this->m_userMsgs[$notify['user_id']] .= wfMsg( 'smw_nm_hint_nomatch', $page_name, $notify[name] );
14541462 $hint = wfMsg( 'smw_nm_hint_nomatch_html', $page_html_name, htmlspecialchars( $notify[name] ) );
1455 - $this->m_userHtmlNMMsgs[$notify['user_id']] .= $hint;
 1463+ foreach ( $notify['user_ids'] as $uid ) {
 1464+ $this->m_userMsgs[$uid] .= wfMsg( 'smw_nm_hint_nomatch', $page_name, $notify[name] );
 1465+ $this->m_userHtmlNMMsgs[$uid] .= $hint;
 1466+ }
14561467 $this->m_notifyHtmlMsgs[$notify_id] .= $hint;
14571468 $this->m_removeMonitored[] = array( 'notify_id' => $notify_id, 'page_id' => $page_id );
14581469 }
1459 - $this->m_userNMs[$notify['user_id']][] = $notify_id;
 1470+ foreach ( $notify['user_ids'] as $uid ) {
 1471+ $this->m_userNMs[$uid][] = $notify_id;
 1472+ }
14601473 }
14611474 // begin notify query on sub query, should go through all pages
14621475 foreach ( $queries[1] as $notify_id => $notify ) {
@@ -1475,13 +1488,17 @@
14761489 $p_name = $t->getText() . ' (' . $t->getFullUrl() . ')';
14771490 $p_html_name = '<a href="' . $t->getFullUrl() . '">' . htmlspecialchars( $t->getText() ) . '</a>';
14781491
1479 - $this->m_userMsgs[$notify['user_id']] .= wfMsg( 'smw_nm_hint_submatch', $page_name, $p_name, $notify[name] );
14801492 $hint = wfMsg( 'smw_nm_hint_submatch_html', $page_html_name, $p_html_name, htmlspecialchars( $notify[name] ) );
1481 - $this->m_userHtmlNMMsgs[$notify['user_id']] .= $hint;
 1493+ foreach ( $notify['user_ids'] as $uid ) {
 1494+ $this->m_userMsgs[$uid] .= wfMsg( 'smw_nm_hint_submatch', $page_name, $p_name, $notify[name] );
 1495+ $this->m_userHtmlNMMsgs[$uid] .= $hint;
 1496+ }
14821497 $this->m_notifyHtmlMsgs[$notify_id] .= $hint;
14831498 $this->m_newMonitor[] = array( 'notify_id' => $notify_id, 'page_id' => $pid );
14841499
1485 - $this->m_userNMs[$notify['user_id']][] = $notify_id;
 1500+ foreach ( $notify['user_ids'] as $uid ) {
 1501+ $this->m_userNMs[$uid][] = $notify_id;
 1502+ }
14861503 }
14871504 foreach ( $no_matches as $pid ) {
14881505 $pt = $sStore->getPageTitle( $pid );
@@ -1492,19 +1509,33 @@
14931510 $p_name = $t->getText() . ' (' . $t->getFullUrl() . ')';
14941511 $p_html_name = '<a href="' . $t->getFullUrl() . '">' . htmlspecialchars( $t->getText() ) . '</a>';
14951512
1496 - $this->m_userMsgs[$notify['user_id']] .= wfMsg( 'smw_nm_hint_subnomatch', $page_name, $p_name, $notify[name] );
14971513 $hint = wfMsg( 'smw_nm_hint_subnomatch_html', $page_html_name, $p_html_name, htmlspecialchars( $notify[name] ) );
1498 - $this->m_userHtmlNMMsgs[$notify['user_id']] .= $hint;
 1514+ foreach ( $notify['user_ids'] as $uid ) {
 1515+ $this->m_userMsgs[$uid] .= wfMsg( 'smw_nm_hint_subnomatch', $page_name, $p_name, $notify[name] );
 1516+ $this->m_userHtmlNMMsgs[$uid] .= $hint;
 1517+ }
14991518 $this->m_notifyHtmlMsgs[$notify_id] .= $hint;
15001519 $this->m_removeMonitored[] = array( 'notify_id' => $notify_id, 'page_id' => $pid );
15011520
1502 - $this->m_userNMs[$notify['user_id']][] = $notify_id;
 1521+ foreach ( $notify['user_ids'] as $uid ) {
 1522+ $this->m_userNMs[$uid][] = $notify_id;
 1523+ }
15031524 }
15041525 }
15051526
15061527 $sStore->removeNotifyMonitor( $this->m_removeMonitored );
15071528 $sStore->addNotifyMonitor( $this->m_newMonitor );
15081529 }
 1530+ private function getFullLink( $val ) {
 1531+ if ( $val instanceof SMWWikiPageValue ) {
 1532+ return '<a href="' . $val->getTitle()->getFullUrl() . '">' . htmlspecialchars( $val->getTitle()->getText() ) . '</a>';
 1533+ } else if ( $val instanceof SMWPropertyValue ) {
 1534+ $val = $val->getWikiPageValue();
 1535+ return '<a href="' . $val->getTitle()->getFullUrl() . '">' . htmlspecialchars( $val->getTitle()->getText() ) . '</a>';
 1536+ } else {
 1537+ return $val->getShortHTMLText( $this->m_linker );
 1538+ }
 1539+ }
15091540 private function applyStyle( $html ) {
15101541 $html = str_replace( "class=\"smwtable\"", "style=\"background-color: #EEEEFF;\"", $html );
15111542 $html = str_replace( "<th", "<th style=\"background-color: #EEEEFF;text-align: left;\"", $html );
@@ -1533,7 +1564,7 @@
15341565 $html_msg = $html_style;
15351566 $showing_all = false;
15361567 if ( isset( $notifications[$notify_id] ) && $notifications[$notify_id]['show_all'] ) {
1537 - SMWQueryProcessor::processFunctionParams( explode( "\n", $notifications[$notify_id]['query'] ), $querystring, $params, $printouts );
 1568+ SMWQueryProcessor::processFunctionParams( SMWNotifyProcessor::getQueryRawParams( $notifications[$notify_id]['query'] ), $querystring, $params, $printouts );
15381569
15391570 $format = 'auto';
15401571 if ( array_key_exists( 'format', $params ) ) {
Index: trunk/extensions/SemanticNotifyMe/includes/storage/SMW_NMStorageSQL.php
@@ -390,19 +390,19 @@
391391 if ( $db->numRows( $res ) > 0 ) {
392392 while ( $row = $db->fetchObject( $res ) ) {
393393 $ds = explode( ',', $row->delegate );
394 - $delegated = false;
 394+ $uids = array();
395395 foreach ( $ds as $delegate ) {
396396 $u = User::newFromName( trim( $delegate ) );
397397 if ( $u == null ) continue;
398398 $id = $u->getId();
399399 if ( $id > 0 ) {
400 - $result[$row->subquery > 0 ? 1:0][$row->notify_id] = array( 'user_id' => $id, 'name' => $row->name, 'sql' => $row->nm_sql, 'hierarchy' => $row->nm_hierarchy );
401 - $delegated = true;
 400+ $uids[] = $id;
402401 }
403402 }
404 - if ( !$delegated ) {
405 - $result[$row->subquery > 0 ? 1:0][$row->notify_id] = array( 'user_id' => $row->user_id, 'name' => $row->name, 'sql' => $row->nm_sql, 'hierarchy' => $row->nm_hierarchy );
 403+ if ( count( $uids ) == 0 ) {
 404+ $uids[] = $row->user_id;
406405 }
 406+ $result[$row->subquery > 0 ? 1:0][$row->notify_id] = array( 'user_ids' => $uids, 'name' => $row->name, 'sql' => $row->nm_sql, 'hierarchy' => $row->nm_hierarchy );
407407 }
408408 }
409409 $db->freeResult( $res );
@@ -421,19 +421,19 @@
422422 if ( $db->numRows( $res ) > 0 ) {
423423 while ( $row = $db->fetchObject( $res ) ) {
424424 $ds = explode( ',', $row->delegate );
425 - $delegated = false;
 425+ $uids = array();
426426 foreach ( $ds as $delegate ) {
427427 $u = User::newFromName( trim( $delegate ) );
428428 if ( $u == null ) continue;
429429 $id = $u->getId();
430430 if ( $id > 0 ) {
431 - $result[$row->notify_id] = array( 'user_id' => $id, 'name' => $row->name, 'sql' => $row->nm_sql, 'hierarchy' => $row->nm_hierarchy );
432 - $delegated = true;
 431+ $uids[] = $id;
433432 }
434433 }
435 - if ( !$delegated ) {
436 - $result[$row->notify_id] = array( 'user_id' => $row->user_id, 'name' => $row->name, 'sql' => $row->nm_sql, 'hierarchy' => $row->nm_hierarchy );
 434+ if ( count( $uids ) == 0 ) {
 435+ $uids[] = $row->user_id;
437436 }
 437+ $result[$row->notify_id] = array( 'user_ids' => $uids, 'name' => $row->name, 'sql' => $row->nm_sql, 'hierarchy' => $row->nm_hierarchy );
438438 }
439439 }
440440 $db->freeResult( $res );

Status & tagging log