From: Brad Jorsch Date: Sat, 4 May 2013 12:34:41 +0000 (-0400) Subject: API: Fix setnotificationtimestamp with no pages given X-Git-Tag: 1.31.0-rc.0~15138^2 X-Git-Url: http://git.cyclocoop.org/%22.%24image2.%22?a=commitdiff_plain;h=1552e7db72f9f839b736f802bda5553ba0d0833b;p=lhc%2Fweb%2Fwiklou.git API: Fix setnotificationtimestamp with no pages given When newerthanrevid or torevid is used and no pages are given, do not throw a fatal PHP error. When no pages are given in other modes, do not return a database error. Bug: 48071 Change-Id: I5abcdf0fa20486f1198d1cc111461b3088a311df --- diff --git a/RELEASE-NOTES-1.24 b/RELEASE-NOTES-1.24 index 73ba1c23d8..3fdc3cfb31 100644 --- a/RELEASE-NOTES-1.24 +++ b/RELEASE-NOTES-1.24 @@ -148,6 +148,8 @@ production. * meta=userinfo can now return the count of unread pages on the watchlist. * list=watchlist can now filter by unread status. * The deprecated action=parse&prop=languageshtml has been removed. +* (bug 48071) action=setnotificationtimestamp no longer throws PHP or database + errors when no pages are given. === Languages updated in 1.24 === diff --git a/includes/api/ApiSetNotificationTimestamp.php b/includes/api/ApiSetNotificationTimestamp.php index dc593e5f91..d5741d9a14 100644 --- a/includes/api/ApiSetNotificationTimestamp.php +++ b/includes/api/ApiSetNotificationTimestamp.php @@ -70,22 +70,26 @@ class ApiSetNotificationTimestamp extends ApiBase { $this->dieUsage( 'torevid may only be used with a single page', 'multpages' ); } $title = reset( $pageSet->getGoodTitles() ); - $timestamp = Revision::getTimestampFromId( $title, $params['torevid'] ); - if ( $timestamp ) { - $timestamp = $dbw->timestamp( $timestamp ); - } else { - $timestamp = null; + if ( $title ) { + $timestamp = Revision::getTimestampFromId( $title, $params['torevid'] ); + if ( $timestamp ) { + $timestamp = $dbw->timestamp( $timestamp ); + } else { + $timestamp = null; + } } } elseif ( isset( $params['newerthanrevid'] ) ) { if ( $params['entirewatchlist'] || $pageSet->getGoodTitleCount() > 1 ) { $this->dieUsage( 'newerthanrevid may only be used with a single page', 'multpages' ); } $title = reset( $pageSet->getGoodTitles() ); - $revid = $title->getNextRevisionID( $params['newerthanrevid'] ); - if ( $revid ) { - $timestamp = $dbw->timestamp( Revision::getTimestampFromId( $title, $revid ) ); - } else { - $timestamp = null; + if ( $title ) { + $revid = $title->getNextRevisionID( $params['newerthanrevid'] ); + if ( $revid ) { + $timestamp = $dbw->timestamp( Revision::getTimestampFromId( $title, $revid ) ); + } else { + $timestamp = null; + } } } @@ -124,46 +128,48 @@ class ApiSetNotificationTimestamp extends ApiBase { $result[] = $rev; } - // Now process the valid titles - $lb = new LinkBatch( $pageSet->getTitles() ); - $dbw->update( 'watchlist', array( 'wl_notificationtimestamp' => $timestamp ), - array( 'wl_user' => $user->getID(), $lb->constructSet( 'wl', $dbw ) ), - __METHOD__ - ); - - // Query the results of our update - $timestamps = array(); - $res = $dbw->select( - 'watchlist', - array( 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ), - array( 'wl_user' => $user->getID(), $lb->constructSet( 'wl', $dbw ) ), - __METHOD__ - ); - foreach ( $res as $row ) { - $timestamps[$row->wl_namespace][$row->wl_title] = $row->wl_notificationtimestamp; - } + if ( $pageSet->getTitles() ) { + // Now process the valid titles + $lb = new LinkBatch( $pageSet->getTitles() ); + $dbw->update( 'watchlist', array( 'wl_notificationtimestamp' => $timestamp ), + array( 'wl_user' => $user->getID(), $lb->constructSet( 'wl', $dbw ) ), + __METHOD__ + ); - // Now, put the valid titles into the result - /** @var $title Title */ - foreach ( $pageSet->getTitles() as $title ) { - $ns = $title->getNamespace(); - $dbkey = $title->getDBkey(); - $r = array( - 'ns' => intval( $ns ), - 'title' => $title->getPrefixedText(), + // Query the results of our update + $timestamps = array(); + $res = $dbw->select( + 'watchlist', + array( 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ), + array( 'wl_user' => $user->getID(), $lb->constructSet( 'wl', $dbw ) ), + __METHOD__ ); - if ( !$title->exists() ) { - $r['missing'] = ''; + foreach ( $res as $row ) { + $timestamps[$row->wl_namespace][$row->wl_title] = $row->wl_notificationtimestamp; } - if ( isset( $timestamps[$ns] ) && array_key_exists( $dbkey, $timestamps[$ns] ) ) { - $r['notificationtimestamp'] = ''; - if ( $timestamps[$ns][$dbkey] !== null ) { - $r['notificationtimestamp'] = wfTimestamp( TS_ISO_8601, $timestamps[$ns][$dbkey] ); + + // Now, put the valid titles into the result + /** @var $title Title */ + foreach ( $pageSet->getTitles() as $title ) { + $ns = $title->getNamespace(); + $dbkey = $title->getDBkey(); + $r = array( + 'ns' => intval( $ns ), + 'title' => $title->getPrefixedText(), + ); + if ( !$title->exists() ) { + $r['missing'] = ''; } - } else { - $r['notwatched'] = ''; + if ( isset( $timestamps[$ns] ) && array_key_exists( $dbkey, $timestamps[$ns] ) ) { + $r['notificationtimestamp'] = ''; + if ( $timestamps[$ns][$dbkey] !== null ) { + $r['notificationtimestamp'] = wfTimestamp( TS_ISO_8601, $timestamps[$ns][$dbkey] ); + } + } else { + $r['notwatched'] = ''; + } + $result[] = $r; } - $result[] = $r; } $apiResult->setIndexedTagName( $result, 'page' );