@@ -72,11 +72,16 @@ public function wiki_table( $name ) {
7272 }
7373
7474 public function get_page_id ( $ ns , $ title ) {
75+ $ title = $ this ->get_db_key ($ title );
76+ $ ns = (int )$ ns ;
77+
7578 $ sql = "select page_id from " . $ this ->wiki_table ( "page " );
7679 $ sql .= " where page_namespace = " . (int )$ ns ;
77- $ sql .= " and page_title = " . $ this ->quote_string ( $ this -> get_db_key ( $ title) );
80+ $ sql .= " and page_title = " . $ this ->quote_string ( $ title );
7881
7982 $ id = $ this ->mysql_query_value ( $ sql );
83+
84+ if ( !$ id ) throw new gpClientException ("Page not found in namespace $ ns: $ title " );
8085 return $ id ;
8186 }
8287
@@ -224,7 +229,7 @@ class gpPageSet {
224229
225230 var $ big = true ;
226231
227- public function __construct ( $ glue , $ table = "? " , $ id_field = "page_id " , $ namespace_field = "page_namespace " , $ title_field = "page_title " ) { #TODO: port new field names to python
232+ public function __construct ( $ glue , $ table = "? " , $ id_field = "pageset_id " , $ namespace_field = "pageset_namespace " , $ title_field = "pageset_title " ) { #TODO: port new field names to python
228233 $ this ->glue = $ glue ;
229234 $ this ->table = $ table ;
230235
@@ -291,7 +296,7 @@ public function resolve_ids( ) {
291296 $ sql = $ tmp ->get_insert (true );
292297 $ sql .= "SELECT " . $ this ->id_field ;
293298 $ sql .= " FROM " . $ this ->table ;
294- $ sql .= " WHERE page_title IS NULL " ;
299+ $ sql .= " WHERE " . $ this -> title_field . " IS NULL " ;
295300
296301 $ this ->query ( $ sql ); //copy page ids with no page title into temp table
297302
@@ -504,33 +509,86 @@ public function retain_transcluding( $title, $ns = null ) { #TODO: port to pytho
504509 return $ this ->strip ( $ where , $ join );
505510 }
506511
507- public function strip_modified_since ( $ timestamp, $ inverse = false ) { #TODO: port to python!
512+ public function strip_modified_since ( $ timestamp ) { #TODO: port to python!
508513 $ where = 'rc_timestamp >= ' . $ this ->glue ->quote_string ($ timestamp );
509514
510515 $ join = array (
511- 'recentchanges ' => ' rc_page = ' . $ this ->id_field
516+ 'recentchanges ' => array (
517+ 'rc_namespace ' => $ this ->namespace_field ,
518+ 'rc_title ' => $ this ->title_field ,
519+ ),
512520 );
513521
514- return $ this ->strip ( $ where , $ join, $ inverse );
522+ return $ this ->strip ( $ where , $ join );
515523 }
516524
517- public function retian_modified_since ( $ timestamp ) { #TODO: port to python!
518- return $ this ->strip_modified_since ( $ title , $ ns , true );
525+ public function retain_modified_since ( $ timestamp ) { #TODO: port to python!
526+ #TODO: normalize $timestamp
527+
528+ $ join = 'LEFT JOIN ' . $ this ->glue ->wiki_table ('recentchanges ' );
529+ $ join .= ' ON rc_namespace = ' . $ this ->namespace_field #literals not assumed: used as a field name, not a string value
530+ . ' AND rc_title = ' . $ this ->title_field #literals not assumed: used as a field name, not a string value
531+ . ' AND rc_timestamp >= ' . $ this ->glue ->quote_string ($ timestamp );
532+
533+ $ where = " rc_id is null " ;
534+
535+ return $ this ->strip ( $ where , $ join );
519536 }
520537
521- public function strip_larger ( $ size , $ inverse = false ) { #TODO: port to python!
522- $ where = 'rev_length >= ' . (int )$ size ;
538+ public function strip_by_size ( $ size , $ op ) { #TODO: port to python!
539+ $ where = 'rev_len ' . $ op . ' ' . (int )$ size ;
523540
524541 $ join = array (
525542 'page ' => 'page_id = ' . $ this ->id_field ,
526543 'revision ' => 'rev_id = page_latest '
527544 );
528545
529- return $ this ->strip ( $ where , $ join , $ inverse );
546+ return $ this ->strip ( $ where , $ join );
547+ }
548+
549+ public function strip_larger ( $ size ) { #TODO: port to python!
550+ return $ this ->strip_by_size ( $ size , '> ' );
551+ }
552+
553+ public function strip_smaller ( $ size ) { #TODO: port to python!
554+ return $ this ->strip_by_size ( $ size , '< ' );
555+ }
556+
557+ public function retain_larger ( $ size ) { #TODO: port to python!
558+ return $ this ->strip_by_size ( $ size , '<= ' );
559+ }
560+
561+ public function retain_smaller ( $ size ) { #TODO: port to python!
562+ return $ this ->strip_by_size ( $ size , '>= ' );
563+ }
564+
565+ public function strip_by_creation ( $ timestamp , $ op ) { #TODO: port to python!
566+ $ where = 'rev_timestamp ' . $ op . ' ' . (int )$ timestamp ;
567+
568+ $ join = array (
569+ 'revision ' => array ('rev_page ' => $ this ->id_field ,
570+ 'rev_deleted ' => 0 , #not deleted
571+ 'rev_parent_id ' => 0 , #first rev of page #XXX: is this reliable?
572+ ),
573+ );
574+
575+ return $ this ->strip ( $ where , $ join );
576+ }
577+
578+ public function strip_older ( $ timestamp ) { #TODO: port to python!
579+ return $ this ->strip_by_creation ( $ timestamp , '< ' );
580+ }
581+
582+ public function strip_newer ( $ timestamp ) { #TODO: port to python!
583+ return $ this ->strip_by_creation ( $ timestamp , '> ' );
584+ }
585+
586+ public function retain_older ( $ timestamp ) { #TODO: port to python!
587+ return $ this ->strip_by_creation ( $ timestamp , '>= ' );
530588 }
531589
532- public function retian_larger ( $ size ) { #TODO: port to python!
533- return $ this ->strip_larger ( $ title , $ ns , true );
590+ public function retain_newer ( $ timestamp ) { #TODO: port to python!
591+ return $ this ->strip_by_creation ( $ timestamp , ' <= ' );
534592 }
535593
536594 public function strip ( $ where , $ join = null , $ inverse = false ) { #TODO: port to python!
@@ -564,6 +622,7 @@ public function strip( $where, $join = null, $inverse = false ) { #TODO: port to
564622 $ sql .= ' WHERE ' . $ where ;
565623 }
566624
625+ #print "*** $sql ***";
567626 $ this ->query ($ sql );
568627 return true ;
569628 }
@@ -606,9 +665,9 @@ public function expand_categories( $ns = null ) {
606665 $ tmp = $ this ->glue ->make_temp_table ( $ t );
607666
608667 $ sql = $ tmp ->get_insert (true );
609- $ sql .= " select page_title " ;
668+ $ sql .= " select " . $ this -> title_field ;
610669 $ sql .= " from " . $ this ->table . " as T " ;
611- $ sql .= " where page_namespace = " .NS_CATEGORY ;
670+ $ sql .= " where " . $ this -> namespace_field . " = " .NS_CATEGORY ;
612671
613672 $ this ->query ( $ sql );
614673 #$this->glue->dump_query("select * from ".$tmp->get_name());
0 commit comments