@@ -50,6 +50,16 @@ public function gp_mediawiki_exec_handler( $glue, &$command, &$source, &$sink, &
5050 */
5151
5252 public function get_db_key ( $ name ) {
53+ if ( is_array ($ name ) ) { #XXX: hack to handle multiple names
54+ $ a = array ();
55+
56+ foreach ( $ name as $ n ) {
57+ $ a [] = $ this ->get_db_key ($ n );
58+ }
59+
60+ return $ a ;
61+ }
62+
5363 //TODO: use native MediaWiki method if available
5464 $ name = trim ($ name );
5565 $ name = str_replace (' ' , '_ ' , $ name );
@@ -182,9 +192,11 @@ public function condition_sql( $where, $assume_literals = true, $inverse = false
182192 $ where = '( ' . implode (') AND ( ' , $ where ) . ') ' ;
183193 } else { #assoc array
184194 $ opt = $ where ;
185- $ where = ' ' ;
195+ $ where = '' ;
186196
187197 foreach ( $ opt as $ k => $ v ) {
198+ if ( $ where ) $ where .= ' AND ' ;
199+
188200 $ where .= '( ' ;
189201 $ where .= $ k ;
190202
@@ -428,6 +440,8 @@ public function retain_table( $table, $id_field = null ) {
428440 }
429441
430442 public function remove_page ( $ ns , $ title ) {
443+ $ title = $ this ->glue ->get_db_key ($ title );
444+
431445 $ sql = "DELETE FROM " . $ this ->table ;
432446 $ sql .= " WHERE " . $ this ->namespace_field . " = " . (int )$ ns ;
433447 $ sql .= " AND " . $ this ->title_field . " = " . $ this ->glue ->quote_string ($ title );
@@ -458,7 +472,10 @@ public function retain_namespace( $ns ) {
458472 return $ this ->strip_namespace ( $ ns , true );
459473 }
460474
461- public function strip_transcluding ( $ title , $ ns , $ inverse = false ) { #TODO: port to python!
475+ public function strip_transcluding ( $ title , $ ns = null ) { #TODO: port to python!
476+ if ( $ ns === null ) $ ns = NS_TEMPLATE ;
477+ $ title = $ this ->glue ->get_db_key ($ title );
478+
462479 $ where = array (
463480 'tl_title ' => $ title ,
464481 'tl_namespace ' => $ ns ,
@@ -468,11 +485,23 @@ public function strip_transcluding( $title, $ns, $inverse = false ) { #TODO: por
468485 'templatelinks ' => ' tl_from = ' . $ this ->id_field
469486 );
470487
471- return $ this ->strip ( $ where , $ join, $ inverse );
488+ return $ this ->strip ( $ where , $ join );
472489 }
473490
474- public function retain_transcluding ( $ title , $ ns ) { #TODO: port to python!
475- return $ this ->strip_transcluding ( $ title , $ ns , true );
491+ public function retain_transcluding ( $ title , $ ns = null ) { #TODO: port to python!
492+ if ( $ ns === null ) $ ns = NS_TEMPLATE ;
493+ $ title = $ this ->glue ->get_db_key ($ title );
494+
495+ $ join = 'LEFT JOIN ' . $ this ->glue ->wiki_table ('templatelinks ' );
496+ $ join .= ' ON ' . $ this ->glue ->condition_sql ( array (
497+ 'tl_from ' => $ this ->id_field ,
498+ 'tl_title ' => $ this ->glue ->quote_string ($ title ),
499+ 'tl_namespace ' => (int )$ ns ,
500+ ), false );
501+
502+ $ where = " tl_from is null " ;
503+
504+ return $ this ->strip ( $ where , $ join );
476505 }
477506
478507 public function strip_modified_since ( $ timestamp , $ inverse = false ) { #TODO: port to python!
0 commit comments