* (bug 27183) API: Add filter by customisation state for meta=allmessages
authorSam Reed <reedy@users.mediawiki.org>
Sun, 13 Mar 2011 16:36:51 +0000 (16:36 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Sun, 13 Mar 2011 16:36:51 +0000 (16:36 +0000)
RELEASE-NOTES
includes/api/ApiQueryAllmessages.php
includes/specials/SpecialAllmessages.php

index bbee46a..d5272a9 100644 (file)
@@ -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 ===
 
index 30ffeb1..85b34d6 100644 (file)
@@ -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',
index 68b6e1d..cba580b 100644 (file)
@@ -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 ) {