From d9dbcf5d34c03cb1345869b2ea79f0d18f2fa2e7 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sun, 13 Mar 2011 16:36:51 +0000 Subject: [PATCH] * (bug 27183) API: Add filter by customisation state for meta=allmessages --- RELEASE-NOTES | 2 +- includes/api/ApiQueryAllmessages.php | 36 ++++++++++++++++++++++-- includes/specials/SpecialAllmessages.php | 20 +++++++------ 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index bbee46af95..d5272a9ab3 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -247,7 +247,7 @@ PHP if you have not done so prior to upgrading MediaWiki. * (bug 27670) Ordering by timestamp (and usage of start and end) isn't as clear in auto generated document, as it is on mw.org * (bug 27182) API: Add filter by prefix for meta=allmessages - +* (bug 27183) API: Add filter by customisation state for meta=allmessages === Languages updated in 1.18 === diff --git a/includes/api/ApiQueryAllmessages.php b/includes/api/ApiQueryAllmessages.php index 30ffeb1831..85b34d648b 100644 --- a/includes/api/ApiQueryAllmessages.php +++ b/includes/api/ApiQueryAllmessages.php @@ -71,7 +71,7 @@ class ApiQueryAllmessages extends ApiQueryBase { } else { $messages_target = $params['messages']; } - + // Filter messages that have the specified prefix // Because we sorted the message array earlier, they will appear in a clump: if ( isset( $params['prefix'] ) ) { @@ -90,7 +90,7 @@ class ApiQueryAllmessages extends ApiQueryBase { } $messages_target = $messages_filtered; } - + // Filter messages that contain specified string if ( isset( $params['filter'] ) ) { $messages_filtered = array(); @@ -103,6 +103,18 @@ class ApiQueryAllmessages extends ApiQueryBase { $messages_target = $messages_filtered; } + // Whether we have any sort of message customisation filtering + $customiseFilterEnabled = $params['customised'] !== 'all'; + if ( $customiseFilterEnabled ) { + global $wgContLang; + $lang = $langObj->getCode(); + + $customisedMessages = AllmessagesTablePager::getCustomisedStatuses( + array_map( array( $langObj, 'ucfirst'), $messages_target ), $lang, $lang != $wgContLang->getCode() ); + + $customised = $params['customised'] === 'modified'; + } + // Get all requested messages and print the result $skip = !is_null( $params['from'] ); $useto = !is_null( $params['to'] ); @@ -124,6 +136,17 @@ class ApiQueryAllmessages extends ApiQueryBase { $args = $params['args']; } + if ( $customiseFilterEnabled ) { + $messageIsCustomised = isset( $customisedMessages['pages'][ $langObj->ucfirst( $message ) ] ); + if ( $customised === $messageIsCustomised && $customised ) { + if ( $customised ) { + $a['customised'] = ''; + } + } else { + continue; + } + } + $msg = wfMessage( $message, $args )->inLanguage( $langObj ); if ( !$msg->exists() ) { @@ -185,6 +208,14 @@ class ApiQueryAllmessages extends ApiQueryBase { ApiBase::PARAM_ISMULTI => true ), 'filter' => array(), + 'customised' => array( + ApiBase::PARAM_DFLT => 'all', + ApiBase::PARAM_TYPE => array( + 'all', + 'modified', + 'unmodified' + ) + ), 'lang' => null, 'from' => null, 'to' => null, @@ -203,6 +234,7 @@ class ApiQueryAllmessages extends ApiQueryBase { 'args' => 'Arguments to be substituted into message', 'prefix' => 'Return messages with this prefix', 'filter' => 'Return only messages with names that contain this string', + 'customised' => 'Return only messages in this customisation state', 'lang' => 'Return messages in this language', 'from' => 'Return messages starting at this message', 'to' => 'Return messages ending at this message', diff --git a/includes/specials/SpecialAllmessages.php b/includes/specials/SpecialAllmessages.php index 68b6e1d4eb..cba580bb92 100644 --- a/includes/specials/SpecialAllmessages.php +++ b/includes/specials/SpecialAllmessages.php @@ -233,12 +233,16 @@ class AllmessagesTablePager extends TablePager { } /** - * Determine which of the MediaWiki and MediaWiki_talk namespace pages exist. - * Returns array( 'pages' => ..., 'talks' => ... ), where the subarrays have - * an entry for each existing page, with the key being the message name and + * Determine which of the MediaWiki and MediaWiki_talk namespace pages exist. + * Returns array( 'pages' => ..., 'talks' => ... ), where the subarrays have + * an entry for each existing page, with the key being the message name and * value arbitrary. + * + * @param array $messageNames + * @param string $langcode What language code + * @param bool $foreign Whether the $langcode is not the content language */ - function getCustomisedStatuses( $messageNames ) { + public static function getCustomisedStatuses( $messageNames, $langcode = 'en', $foreign = false ) { wfProfileIn( __METHOD__ . '-db' ); $dbr = wfGetDB( DB_SLAVE ); @@ -251,12 +255,12 @@ class AllmessagesTablePager extends TablePager { $xNames = array_flip( $messageNames ); $pageFlags = $talkFlags = array(); - + foreach ( $res as $s ) { if( $s->page_namespace == NS_MEDIAWIKI ) { - if( $this->foreign ) { + if( $foreign ) { $title = explode( '/', $s->page_title ); - if( count( $title ) === 2 && $this->langcode == $title[1] + if( count( $title ) === 2 && $langcode == $title[1] && isset( $xNames[$title[0]] ) ) { $pageFlags["{$title[0]}"] = true; } @@ -281,7 +285,7 @@ class AllmessagesTablePager extends TablePager { $result = new FakeResultWrapper( array() ); $messageNames = $this->getAllMessages( $descending ); - $statuses = $this->getCustomisedStatuses( $messageNames ); + $statuses = self::getCustomisedStatuses( $messageNames, $this->langcode, $this->foreign ); $count = 0; foreach( $messageNames as $key ) { -- 2.20.1