https://www.mediawiki.org/wiki/Special:Code/MediaWiki/101991

Revision: 101991
Author:   nikerabbit
Date:     2011-11-04 13:59:02 +0000 (Fri, 04 Nov 2011)
Log Message:
-----------
Bug 21788 - allow fuzzy.php to take optional namespace prefix

Modified Paths:
--------------
    trunk/extensions/Translate/README
    trunk/extensions/Translate/scripts/fuzzy.php

Modified: trunk/extensions/Translate/README
===================================================================
--- trunk/extensions/Translate/README   2011-11-04 13:21:32 UTC (rev 101990)
+++ trunk/extensions/Translate/README   2011-11-04 13:59:02 UTC (rev 101991)
@@ -29,6 +29,8 @@
  http://translatewiki.net/docs/Translate/html/
 
 == Change log ==
+* 2011-11-04
+- fuzzy.php can now take optional namespace prefix for each message
 * 2011-10-30
 - The script referenced at 2011-08-26 is now included in the source
 - Fixed compatibility with MW 1.17

Modified: trunk/extensions/Translate/scripts/fuzzy.php
===================================================================
--- trunk/extensions/Translate/scripts/fuzzy.php        2011-11-04 13:21:32 UTC 
(rev 101990)
+++ trunk/extensions/Translate/scripts/fuzzy.php        2011-11-04 13:59:02 UTC 
(rev 101991)
@@ -79,14 +79,6 @@
         */
        public function __construct( $titles ) {
                $this->titles = $titles;
-
-               global $wgTranslateFuzzyBotName;
-
-               if ( !isset( $wgTranslateFuzzyBotName ) ) {
-                       STDERR( "\$wgTranslateFuzzyBotName is not set" );
-                       return;
-               }
-
                $this->allclear = true;
        }
 
@@ -111,27 +103,31 @@
                global $wgTranslateMessageNamespaces;
                $dbr = wfGetDB( DB_SLAVE );
 
-               $search_titles = array();
+               $search = array();
                foreach ( $this->titles as $title ) {
-                       $title = TranslateUtils::title( $title, '' );
-                       $title = str_replace( ' ', '_', $title );
-                       $search_titles[] = 'page_title ' . $dbr->buildLike( 
$title, $dbr->anyString() );
+                       $title = Title::newFromText( $title );
+                       $ns = $title->getNamespace();
+                       if ( !isset( $search[$ns] ) ) $search[$ns] = array();
+                       $search[$ns][] = 'page_title' . $dbr->buildLike( 
$title->getDBKey(), $dbr->anyString() );
                }
 
-               $condArray = array(
-                       'page_is_redirect'  => 0,
-                       'page_namespace'    => $wgTranslateMessageNamespaces,
+               $title_conds = array();
+               foreach ( $search as $ns => $names ) {
+                       if ( $ns == NS_MAIN ) $ns = 
$wgTranslateMessageNamespaces;
+                       $titles = $dbr->makeList( $names, LIST_OR );
+                       $title_conds[] = $dbr->makeList( array( 
'page_namespace' => $ns, $titles ), LIST_AND );
+               }
+
+               $conds = array(
                        'page_latest=rev_id',
                        'rev_text_id=old_id',
-                       $dbr->makeList( $search_titles, LIST_OR ),
+                       $dbr->makeList( $title_conds, LIST_OR ),
                );
 
                if ( count( $this->skipLanguages ) ) {
-                       $condArray[] = 'substring_index(page_title, \'/\', -1) 
NOT IN (' . $dbr->makeList( $this->skipLanguages ) . ')';
+                       $conds = 'substring_index(page_title, \'/\', -1) NOT IN 
(' . $dbr->makeList( $this->skipLanguages ) . ')';
                }
 
-               $conds = $dbr->makeList( $condArray, LIST_AND );
-
                $rows = $dbr->select(
                        array( 'page', 'revision', 'text' ),
                        array( 'page_title', 'page_namespace', 'old_text', 
'old_flags' ),


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to