From c1f6d862746ffccdef043ff2013590b20bfd88e6 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sun, 31 Jan 2010 23:06:35 +0000 Subject: [PATCH] Finish (bug 18427) Comment (edit summary) parser option for API Followup to r61747 r61754 (RELEASE-NOTES to cover whole bug) --- RELEASE-NOTES | 1 + includes/api/ApiQueryDeletedrevs.php | 16 +++++++++++---- includes/api/ApiQueryLogEvents.php | 18 ++++++++++++---- includes/api/ApiQueryProtectedTitles.php | 11 +++++++--- includes/api/ApiQueryRecentChanges.php | 10 +++++++-- includes/api/ApiQueryUserContributions.php | 24 +++++++++++++++------- includes/api/ApiQueryWatchlist.php | 15 +++++++++++--- 7 files changed, 72 insertions(+), 23 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 982b893898..a19ac2d937 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -813,6 +813,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 22297) safesubst: to allow substitution without breaking transclusion * (bug 18758) API read of watchlist's wl_notificationtimestamp * (bug 20809) Expose EditFormPreloadText via the API +* (bug 18427) Comment (edit summary) parser option for API === Languages updated in 1.16 === diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php index 6c32a206d7..308c0c1fc2 100644 --- a/includes/api/ApiQueryDeletedrevs.php +++ b/includes/api/ApiQueryDeletedrevs.php @@ -52,6 +52,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase { $fld_revid = isset( $prop['revid'] ); $fld_user = isset( $prop['user'] ); $fld_comment = isset( $prop['comment'] ); + $fld_parsedcomment = isset ( $prop['parsedcomment'] ); $fld_minor = isset( $prop['minor'] ); $fld_len = isset( $prop['len'] ); $fld_content = isset( $prop['content'] ); @@ -82,7 +83,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase { $this->addFields( 'ar_rev_id' ); if ( $fld_user ) $this->addFields( 'ar_user_text' ); - if ( $fld_comment ) + if ( $fld_comment || $fld_parsedcomment ) $this->addFields( 'ar_comment' ); if ( $fld_minor ) $this->addFields( 'ar_minor_edit' ); @@ -193,8 +194,15 @@ class ApiQueryDeletedrevs extends ApiQueryBase { $rev['user'] = $row->ar_user_text; if ( $fld_comment ) $rev['comment'] = $row->ar_comment; + + $title = Title::makeTitle( $row->ar_namespace, $row->ar_title ); + + if ( $fld_parsedcomment) { + global $wgUser; + $rev['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->ar_comment, $title ); + } if ( $fld_minor && $row->ar_minor_edit == 1 ) - $rev['minor'] = ''; + $rev['minor'] = ''; if ( $fld_len ) $rev['len'] = $row->ar_len; if ( $fld_content ) @@ -203,10 +211,9 @@ class ApiQueryDeletedrevs extends ApiQueryBase { if ( !isset( $pageMap[$row->ar_namespace][$row->ar_title] ) ) { $pageID = $newPageID++; $pageMap[$row->ar_namespace][$row->ar_title] = $pageID; - $t = Title::makeTitle( $row->ar_namespace, $row->ar_title ); $a['revisions'] = array( $rev ); $result->setIndexedTagName( $a['revisions'], 'rev' ); - ApiQueryBase::addTitleInfo( $a, $t ); + ApiQueryBase::addTitleInfo( $a, $title ); if ( $fld_token ) $a['token'] = $token; $fit = $result->addValue( array( 'query', $this->getModuleName() ), $pageID, $a ); @@ -270,6 +277,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase { 'revid', 'user', 'comment', + 'parsedcomment', 'minor', 'len', 'content', diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index ea92260dbf..59ac83a6b8 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -50,6 +50,7 @@ class ApiQueryLogEvents extends ApiQueryBase { $this->fld_user = isset( $prop['user' ); $this->fld_timestamp = isset( $prop['timestamp' ); $this->fld_comment = isset( $prop['comment' ); + $this->fld_parsedcomment = isset ( $prop['parsedcomment'] ); $this->fld_details = isset( $prop['details' ); $this->fld_tags = isset( $prop['tags' ); @@ -83,7 +84,7 @@ class ApiQueryLogEvents extends ApiQueryBase { $this->addFieldsIf( 'user_name', $this->fld_user ); $this->addFieldsIf( 'log_namespace', $this->fld_title ); $this->addFieldsIf( 'log_title', $this->fld_title ); - $this->addFieldsIf( 'log_comment', $this->fld_comment ); + $this->addFieldsIf( 'log_comment', $this->fld_comment || $this->fld_parsedcomment ); $this->addFieldsIf( 'log_params', $this->fld_details ); if ( $this->fld_tags ) { @@ -216,11 +217,12 @@ class ApiQueryLogEvents extends ApiQueryBase { $vals['pageid'] = intval( $row->page_id ); } + $title = Title :: makeTitle( $row->log_namespace, $row->log_title ); + if ( $this->fld_title ) { if ( LogEventsList::isDeleted( $row, LogPage::DELETED_ACTION ) ) { $vals['actionhidden'] = ''; } else { - $title = Title :: makeTitle( $row->log_namespace, $row->log_title ); ApiQueryBase :: addTitleInfo( $vals, $title ); } } @@ -252,11 +254,18 @@ class ApiQueryLogEvents extends ApiQueryBase { if ( $this->fld_timestamp ) { $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->log_timestamp ); } - if ( $this->fld_comment && isset( $row->log_comment ) ) { + + if ( ($this->fld_comment || $this->fld_parsedcomment) && isset( $row->log_comment ) ) { if ( LogEventsList::isDeleted( $row, LogPage::DELETED_COMMENT ) ) { $vals['commenthidden'] = ''; } else { - $vals['comment'] = $row->log_comment; + if ( $this->fld_comment ) + $vals['comment'] = $row->log_comment; + + if ( $this->fld_parsedcomment ) { + global $wgUser; + $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->log_comment, $title ); + } } } @@ -287,6 +296,7 @@ class ApiQueryLogEvents extends ApiQueryBase { 'user', 'timestamp', 'comment', + 'parsedcomment', 'details', 'tags' ) diff --git a/includes/api/ApiQueryProtectedTitles.php b/includes/api/ApiQueryProtectedTitles.php index 038988abed..939118e5b1 100644 --- a/includes/api/ApiQueryProtectedTitles.php +++ b/includes/api/ApiQueryProtectedTitles.php @@ -56,7 +56,7 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { $prop = array_flip( $params['prop'] ); $this->addFieldsIf( 'pt_user', isset( $prop['user'] ) ); - $this->addFieldsIf( 'pt_reason', isset( $prop['comment'] ) ); + $this->addFieldsIf( 'pt_reason', isset( $prop['comment'] ) || isset( $prop['parsedcomment'] ) ); $this->addFieldsIf( 'pt_expiry', isset( $prop['expiry'] ) ); $this->addFieldsIf( 'pt_create_perm', isset( $prop['level'] ) ); @@ -98,6 +98,11 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { if ( isset( $prop['comment'] ) ) $vals['comment'] = $row->pt_reason; + if ( isset( $prop['parsedcomment'] ) ) { + global $wgUser; + $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->pt_reason, $title ); + } + if ( isset( $prop['expiry'] ) ) $vals['expiry'] = Block::decodeExpiry( $row->pt_expiry, TS_ISO_8601 ); @@ -105,8 +110,7 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { $vals['level'] = $row->pt_create_perm; $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals ); - if ( !$fit ) - { + if ( !$fit ) { $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->pt_timestamp ) ); break; @@ -160,6 +164,7 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { 'timestamp', 'user', 'comment', + 'parsedcomment', 'expiry', 'level' ) diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php index 90f847346f..6fc5099e36 100644 --- a/includes/api/ApiQueryRecentChanges.php +++ b/includes/api/ApiQueryRecentChanges.php @@ -40,7 +40,7 @@ class ApiQueryRecentChanges extends ApiQueryBase { parent :: __construct( $query, $moduleName, 'rc' ); } - private $fld_comment = false, $fld_user = false, $fld_flags = false, + private $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_flags = false, $fld_timestamp = false, $fld_title = false, $fld_ids = false, $fld_sizes = false; /** @@ -87,6 +87,7 @@ class ApiQueryRecentChanges extends ApiQueryBase { */ public function initProperties( $prop ) { $this->fld_comment = isset ( $prop['comment'] ); + $this->fld_parsedcomment = isset ( $prop['parsedcomment'] ); $this->fld_user = isset ( $prop['user'] ); $this->fld_flags = isset ( $prop['flags'] ); $this->fld_timestamp = isset ( $prop['timestamp'] ); @@ -195,7 +196,7 @@ class ApiQueryRecentChanges extends ApiQueryBase { $this->addFieldsIf( 'rc_id', $this->fld_ids ); $this->addFieldsIf( 'rc_this_oldid', $this->fld_ids ); $this->addFieldsIf( 'rc_last_oldid', $this->fld_ids ); - $this->addFieldsIf( 'rc_comment', $this->fld_comment ); + $this->addFieldsIf( 'rc_comment', $this->fld_comment || $this->fld_parsedcomment ); $this->addFieldsIf( 'rc_user', $this->fld_user ); $this->addFieldsIf( 'rc_user_text', $this->fld_user ); $this->addFieldsIf( 'rc_minor', $this->fld_flags ); @@ -351,6 +352,10 @@ class ApiQueryRecentChanges extends ApiQueryBase { /* Add edit summary / log summary. */ if ( $this->fld_comment && isset( $row->rc_comment ) ) { $vals['comment'] = $row->rc_comment; + + if ( $this->fld_parsedcomment && isset( $row->rc_comment ) ) { + global $wgUser; + $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->rc_comment, $title ); } if ( $this->fld_redirect ) @@ -446,6 +451,7 @@ class ApiQueryRecentChanges extends ApiQueryBase { ApiBase :: PARAM_TYPE => array ( 'user', 'comment', + 'parsedcomment', 'flags', 'timestamp', 'title', diff --git a/includes/api/ApiQueryUserContributions.php b/includes/api/ApiQueryUserContributions.php index f1ca2324b4..fbd909ee5d 100644 --- a/includes/api/ApiQueryUserContributions.php +++ b/includes/api/ApiQueryUserContributions.php @@ -41,7 +41,7 @@ class ApiQueryContributions extends ApiQueryBase { private $params, $username; private $fld_ids = false, $fld_title = false, $fld_timestamp = false, - $fld_comment = false, $fld_flags = false, + $fld_comment = false, $fld_parsedcomment = false, $fld_flags = false, $fld_patrolled = false, $fld_tags = false; public function execute() { @@ -52,6 +52,7 @@ class ApiQueryContributions extends ApiQueryBase { $this->fld_ids = isset( $prop['ids'] ); $this->fld_title = isset( $prop['title'] ); $this->fld_comment = isset( $prop['comment'] ); + $this->fld_parsedcomment = isset ( $prop['parsedcomment'] ); $this->fld_size = isset( $prop['size'] ); $this->fld_flags = isset( $prop['flags'] ); $this->fld_timestamp = isset( $prop['timestamp'] ); @@ -242,7 +243,7 @@ class ApiQueryContributions extends ApiQueryBase { $this->addFieldsIf( 'rev_id', $this->fld_ids || $this->fld_flags ); $this->addFieldsIf( 'page_latest', $this->fld_flags ); // $this->addFieldsIf('rev_text_id', $this->fld_ids); // Should this field be exposed? - $this->addFieldsIf( 'rev_comment', $this->fld_comment ); + $this->addFieldsIf( 'rev_comment', $this->fld_comment || $this->fld_parsedcomment ); $this->addFieldsIf( 'rev_len', $this->fld_size ); $this->addFieldsIf( 'rev_minor_edit', $this->fld_flags ); $this->addFieldsIf( 'rev_parent_id', $this->fld_flags ); @@ -278,9 +279,10 @@ class ApiQueryContributions extends ApiQueryBase { // $vals['textid'] = intval($row->rev_text_id); // todo: Should this field be exposed? } + $title = Title :: makeTitle( $row->page_namespace, $row->page_title ); + if ( $this->fld_title ) - ApiQueryBase :: addTitleInfo( $vals, - Title :: makeTitle( $row->page_namespace, $row->page_title ) ); + ApiQueryBase :: addTitleInfo( $vals, $title ); if ( $this->fld_timestamp ) $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rev_timestamp ); @@ -294,11 +296,18 @@ class ApiQueryContributions extends ApiQueryBase { $vals['top'] = ''; } - if ( $this->fld_comment && isset( $row->rev_comment ) ) { + if ( ($this->fld_comment || $this->fld_parsedcomment) && isset( $row->rev_comment ) ) { if ( $row->rev_deleted & Revision::DELETED_COMMENT ) $vals['commenthidden'] = ''; - else - $vals['comment'] = $row->rev_comment; + } else { + if ( $this->fld_comment ) + $vals['comment'] = $row->rev_comment; + + if ( $this->fld_parsedcomment ) { + global $wgUser; + $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->rev_comment, $title ); + } + } } if ( $this->fld_patrolled && $row->rc_patrolled ) @@ -365,6 +374,7 @@ class ApiQueryContributions extends ApiQueryBase { 'title', 'timestamp', 'comment', + 'parsedcomment', 'size', 'flags', 'patrolled', diff --git a/includes/api/ApiQueryWatchlist.php b/includes/api/ApiQueryWatchlist.php index be253b2ad7..0b780c64da 100644 --- a/includes/api/ApiQueryWatchlist.php +++ b/includes/api/ApiQueryWatchlist.php @@ -49,7 +49,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { } private $fld_ids = false, $fld_title = false, $fld_patrol = false, $fld_flags = false, - $fld_timestamp = false, $fld_user = false, $fld_comment = false, $fld_sizes = false, + $fld_timestamp = false, $fld_user = false, $fld_comment = false, $fld_parsedcomment = false, $fld_sizes = false, $fld_notificationtimestamp = false; private function run( $resultPageSet = null ) { @@ -83,6 +83,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { $this->fld_flags = isset( $prop['flags'] ); $this->fld_user = isset( $prop['user'] ); $this->fld_comment = isset( $prop['comment'] ); + $this->fld_parsedcomment = isset ( $prop['parsedcomment'] ); $this->fld_timestamp = isset( $prop['timestamp'] ); $this->fld_sizes = isset( $prop['sizes'] ); $this->fld_patrol = isset( $prop['patrol'] ); @@ -111,7 +112,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { $this->addFieldsIf( 'rc_bot', $this->fld_flags ); $this->addFieldsIf( 'rc_user', $this->fld_user ); $this->addFieldsIf( 'rc_user_text', $this->fld_user ); - $this->addFieldsIf( 'rc_comment', $this->fld_comment ); + $this->addFieldsIf( 'rc_comment', $this->fld_comment || $this->fld_parsedcomment ); $this->addFieldsIf( 'rc_patrolled', $this->fld_patrol ); $this->addFieldsIf( 'rc_old_len', $this->fld_sizes ); $this->addFieldsIf( 'rc_new_len', $this->fld_sizes ); @@ -232,8 +233,10 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { $vals['revid'] = intval( $row->rc_this_oldid ); } + $title = Title :: makeTitle( $row->rc_namespace, $row->rc_title ); + if ( $this->fld_title ) - ApiQueryBase :: addTitleInfo( $vals, Title :: makeTitle( $row->rc_namespace, $row->rc_title ) ); + ApiQueryBase :: addTitleInfo( $vals, $title ); if ( $this->fld_user ) { $vals['user'] = $row->rc_user_text; @@ -266,6 +269,11 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { if ( $this->fld_comment && isset( $row->rc_comment ) ) $vals['comment'] = $row->rc_comment; + + if ( $this->fld_parsedcomment && isset( $row->rc_comment ) ) { + global $wgUser; + $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->rc_comment, $title ); + } return $vals; } @@ -312,6 +320,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { 'flags', 'user', 'comment', + 'parsedcomment', 'timestamp', 'patrol', 'sizes', -- 2.20.1