r83831 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83830‎ | r83831 | r83832 >
Date:16:36, 13 March 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
* (bug 27183) API: Add filter by customisation state for meta=allmessages
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllmessages.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialAllmessages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryAllmessages.php
@@ -71,7 +71,7 @@
7272 } else {
7373 $messages_target = $params['messages'];
7474 }
75 -
 75+
7676 // Filter messages that have the specified prefix
7777 // Because we sorted the message array earlier, they will appear in a clump:
7878 if ( isset( $params['prefix'] ) ) {
@@ -90,7 +90,7 @@
9191 }
9292 $messages_target = $messages_filtered;
9393 }
94 -
 94+
9595 // Filter messages that contain specified string
9696 if ( isset( $params['filter'] ) ) {
9797 $messages_filtered = array();
@@ -103,6 +103,18 @@
104104 $messages_target = $messages_filtered;
105105 }
106106
 107+ // Whether we have any sort of message customisation filtering
 108+ $customiseFilterEnabled = $params['customised'] !== 'all';
 109+ if ( $customiseFilterEnabled ) {
 110+ global $wgContLang;
 111+ $lang = $langObj->getCode();
 112+
 113+ $customisedMessages = AllmessagesTablePager::getCustomisedStatuses(
 114+ array_map( array( $langObj, 'ucfirst'), $messages_target ), $lang, $lang != $wgContLang->getCode() );
 115+
 116+ $customised = $params['customised'] === 'modified';
 117+ }
 118+
107119 // Get all requested messages and print the result
108120 $skip = !is_null( $params['from'] );
109121 $useto = !is_null( $params['to'] );
@@ -124,6 +136,17 @@
125137 $args = $params['args'];
126138 }
127139
 140+ if ( $customiseFilterEnabled ) {
 141+ $messageIsCustomised = isset( $customisedMessages['pages'][ $langObj->ucfirst( $message ) ] );
 142+ if ( $customised === $messageIsCustomised && $customised ) {
 143+ if ( $customised ) {
 144+ $a['customised'] = '';
 145+ }
 146+ } else {
 147+ continue;
 148+ }
 149+ }
 150+
128151 $msg = wfMessage( $message, $args )->inLanguage( $langObj );
129152
130153 if ( !$msg->exists() ) {
@@ -185,6 +208,14 @@
186209 ApiBase::PARAM_ISMULTI => true
187210 ),
188211 'filter' => array(),
 212+ 'customised' => array(
 213+ ApiBase::PARAM_DFLT => 'all',
 214+ ApiBase::PARAM_TYPE => array(
 215+ 'all',
 216+ 'modified',
 217+ 'unmodified'
 218+ )
 219+ ),
189220 'lang' => null,
190221 'from' => null,
191222 'to' => null,
@@ -203,6 +234,7 @@
204235 'args' => 'Arguments to be substituted into message',
205236 'prefix' => 'Return messages with this prefix',
206237 'filter' => 'Return only messages with names that contain this string',
 238+ 'customised' => 'Return only messages in this customisation state',
207239 'lang' => 'Return messages in this language',
208240 'from' => 'Return messages starting at this message',
209241 'to' => 'Return messages ending at this message',
Index: trunk/phase3/includes/specials/SpecialAllmessages.php
@@ -233,12 +233,16 @@
234234 }
235235
236236 /**
237 - * Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
238 - * Returns array( 'pages' => ..., 'talks' => ... ), where the subarrays have
239 - * an entry for each existing page, with the key being the message name and
 237+ * Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
 238+ * Returns array( 'pages' => ..., 'talks' => ... ), where the subarrays have
 239+ * an entry for each existing page, with the key being the message name and
240240 * value arbitrary.
 241+ *
 242+ * @param array $messageNames
 243+ * @param string $langcode What language code
 244+ * @param bool $foreign Whether the $langcode is not the content language
241245 */
242 - function getCustomisedStatuses( $messageNames ) {
 246+ public static function getCustomisedStatuses( $messageNames, $langcode = 'en', $foreign = false ) {
243247 wfProfileIn( __METHOD__ . '-db' );
244248
245249 $dbr = wfGetDB( DB_SLAVE );
@@ -251,12 +255,12 @@
252256 $xNames = array_flip( $messageNames );
253257
254258 $pageFlags = $talkFlags = array();
255 -
 259+
256260 foreach ( $res as $s ) {
257261 if( $s->page_namespace == NS_MEDIAWIKI ) {
258 - if( $this->foreign ) {
 262+ if( $foreign ) {
259263 $title = explode( '/', $s->page_title );
260 - if( count( $title ) === 2 && $this->langcode == $title[1]
 264+ if( count( $title ) === 2 && $langcode == $title[1]
261265 && isset( $xNames[$title[0]] ) ) {
262266 $pageFlags["{$title[0]}"] = true;
263267 }
@@ -281,7 +285,7 @@
282286 $result = new FakeResultWrapper( array() );
283287
284288 $messageNames = $this->getAllMessages( $descending );
285 - $statuses = $this->getCustomisedStatuses( $messageNames );
 289+ $statuses = self::getCustomisedStatuses( $messageNames, $this->langcode, $this->foreign );
286290
287291 $count = 0;
288292 foreach( $messageNames as $key ) {
Index: trunk/phase3/RELEASE-NOTES
@@ -247,8 +247,8 @@
248248 * (bug 27670) Ordering by timestamp (and usage of start and end) isn't as clear
249249 in auto generated document, as it is on mw.org
250250 * (bug 27182) API: Add filter by prefix for meta=allmessages
 251+* (bug 27183) API: Add filter by customisation state for meta=allmessages
251252
252 -
253253 === Languages updated in 1.18 ===
254254
255255 MediaWiki supports over 330 languages. Many localisations are updated

Follow-up revisions

RevisionCommit summaryAuthorDate
r83958Fix artifact of 2 working copies from r83831reedy20:26, 14 March 2011

Comments

#Comment by Duplicatebug (talk | contribs)   19:19, 14 March 2011

amcustomised=unmodified gives empty result.

The second $customised in if ( $customised === $messageIsCustomised && $customised ) looks wrong.

#Comment by Reedy (talk | contribs)   19:40, 14 March 2011

Bah. Looks like I missed a version between my working copy and my server copy for commiting.

I think it's the && $customised that needs removing again...

Will poke it in a bit

Status & tagging log