Joanjoc tools: Index - Suggest articles from interwikis - Articles without interwikis

Viewing: sugart Filesize: 7.94Kb
<?php
    
require_once('functions.inc.php');
    
    
//Variable initialitzation
    
$scriptname 'sugart';
    
$nresults 0;  //Results counter
    
$Result_text '';  //result string
    
$catfrom ''
    
$catwhere ''
    
$tplfrom ''
    
$tplwhere ''
    
$par['l1']  = strtolower(param_val('l1''gpcd'''));
    
$par['pr']  = param_val('pr''gpcd''');
    
$par['l2']  = strtolower(param_val('l2''gpcd'''));  
    
$par['cat']  = param_val('cat''gpcd''');
    
$par['dpt']  = param_val('dpt''gpcd''');
    
$par['tpl']  = param_val('tpl''gpcd''');
    
$par['go']  = param_val('go''gpcd''');

    
//Changing spaces for undescores for sqls
    
$cat ucfirst(str_replace(" ""_"$par['cat'])); 
    
$tpl ucfirst(str_replace(" ""_"$par['tpl']));
    
    
//cache optimization    
    
if ($par['cat']== '')  $par['dpt'] = 1;
    
    require_once (
'header.inc.php');

//<h1><font color="red">$String['Tool in testing phase']</font></h1>
?>
<h1><font color="#7F7F7F"><?=$String['Suggest articles from interwikis']?></font></h1>
<?=$String['Sugart info']?><br/>
<hr/>
<form method="get">
    <br/>
    <table>
        <tr><td><?=$String['Look articles in']?></td><td><input name="l1" type="text" size="5" value="<?=$par['l1']?>" ><small> <?=$String['reference language code']?></small></td></tr>
         <tr><td><?=$String['Project']?></td><td><select name="pr">
            <?=Option_item('wiki','wiki',$par['pr'])?>
            <?=Option_item('wikibooks','wikibooks',$par['pr'])?>
            <?=Option_item('wikinews','wikinews',$par['pr'])?>
            <?=Option_item('wikisource','wikisource',$par['pr'])?>
            <?=Option_item('wikiversity','wikiversity',$par['pr'])?>
            <?=Option_item('wikiquote','wikiquote',$par['pr'])?>
            <?=Option_item('wiktionary','wiktionary',$par['pr'])?>
            </select> </td></tr>
          <tr><td><?=$String['Without interwiki to']?></td><td><input name="l2" type="text" size="5" value="<?=$par['l2']?>"/><small> <?=$String['missing language code']?></small></td></tr> 
        <tr><td><?=$String['Inside category']?>:</td><td><input name="cat" type="text" size="20" value="<?=$par['cat']?>"/> <?=$String['depth']?> <select name="dpt">
        <?=Option_item('1','1',$par['dpt'])?>
        <?=Option_item('2','2',$par['dpt'])?>
        <?=Option_item('3','3',$par['dpt'])?>
    </select></td></tr>
<tr><td><?=$String['Including template']?>:</td><td><input name="tpl" type="text" size="20" value="<?=$par['tpl']?>"/></td></tr>
<tr><td><input type="hidden" name="uselang" value="<?=$par['uselang']?>"></td><td><input name="go" type="submit" value="<?=$String['Proceed']?>" /></td></tr>
    
</table>
</form>
<hr/>
<?php

echo $String['Average execution time'].' : ';
echo 
Average_get('./counters/'.$scriptname.'.average.proceed.txt');
echo 
' '.$String['seconds'].' <br/>'."\r\n";


if (
$par['go'] != '') {
 
    
//Checking variables
    
if (empty($par['l1']) || empty($par['pr'])) Die($String['ERROR:missing parameters']);
     
    
//Checking cache
    
$cachename './cache/'.$scriptname.'.'.date('Ymd').'.'.$par['l1'].'.'.$par['pr'].'.'.$par['l2'].'.'.$par['cat'].'.'.$par['dpt'].'.'.$par['tpl'].'.txt';
    if (
file_exists($cachename)) {
      
//Results cached, showing the cached results
      
echo $String['Results cached'].' ('.$String['cache expires in'].' '.(24-date('G')).' '.$String['hours'].') <br/>'."\r\n";
      require_once (
$cachename);
    } else {
        
//Results not cached yet
        
$stimer Timer_time();  //Start timer
        
        
$db1 $par['l1'].$par['pr'];
        
$db2 $par['l2'];
        require_once(
'../database.inc');
        if ( isset(
$_REQUEST['testing']) ) print "<pre>$db1,$toolserver_username,$toolserver_password</pre>" ;
        
mysql_connect($db1.'.labsdb',$toolserver_username,$toolserver_password);
        @
mysql_select_db($db1.'_p') or print mysql_error();
        
        
        if (!empty(
$par['cat'])) {
            if (
$par['dpt'] >= 1) {
                    
$catfrom "select /*SLOW_OK LIMIT:2000 NM*/ /*sugart*/ p.page_id, p.page_title /*depth 1*/
                                from categorylinks cl, page p
                                where cl.cl_to='"
.$cat."' 
                                and p.page_id=cl.cl_from
                                and p.page_namespace=0"
;
            }
            if (
$par['dpt'] >= 2) {
                    
$catfrom .= " union
                                select p.page_id, p.page_title /*depth 2*/
                                from categorylinks cl, page p, categorylinks cl2, page p2
                                where cl2.cl_to='"
.$cat."' 
                                and p2.page_id=cl2.cl_from
                                and p2.page_namespace=14
                                and cl.cl_to = p2.page_title
                                and cl.cl_from = p.page_id
                                and p.page_namespace=0"
;
            }
            if (
$par['dpt'] == 3) {
                    
$catfrom .= " union
                                select p.page_id, p.page_title /*depth 3*/
                                from categorylinks cl, page p, categorylinks cl2, page p2, categorylinks cl3, page p3
                                where cl3.cl_to='"
.$cat."' 
                                and p3.page_id=cl3.cl_from
                                and p3.page_namespace=14
                                and cl2.cl_to = p3.page_title
                                and p2.page_id=cl2.cl_from
                                and p2.page_namespace=14
                                and cl.cl_to = p2.page_title
                                and cl.cl_from = p.page_id
                                and p.page_namespace=0"
;
            }

                            
        }     
//if (!empty($par['cat']))
        
        
if ($catfrom != '') {
            
$catfrom ', ('.$catfrom.') cat';
            
$catwhere 'p.page_id=cat.page_id';
        } else {
            
$catwhere 'p.page_namespace=0';
        }
        
        if (
$par['tpl']!='') {
            
$tplfrom ", (select page_id, page_title
                        from templatelinks tl, page p
                        where tl.tl_title='"
.$tpl."' 
                        and p.page_id=tl.tl_from
                        and p.page_namespace = 0) tpl"
;
            
$tplwhere "and p.page_id=tpl.page_id";                        
        }


        
$query "select /*SLOW_OK LIMIT:2000 NM*/ /*sugart*/ count(*) AS count, p.page_title
                      from page p,  langlinks l1 "
.$catfrom." ".$tplfrom."
                      where "
.$catwhere." ".$tplwhere."
                      and p.page_id = l1.ll_from 
                      and not exists (select 1 from langlinks l2 where l1.ll_from=l2.ll_from and l2.ll_lang='"
.$db2."')
                      group by p.page_id, p.page_title
                      order by count(*) desc, p.page_title 
                      limit 0,500"
;
                            

        echo 
'<!--'.$query.'-->'
        
$result mysql_query($query);
        
        if(!
$result) Die($String['ERROR:no results']);
          
        
$db1url $par['l1'].'.'.$par['pr'];
        if (
$par['pr'] == 'wiki')  $db1url $db1url.'pedia';
        
        
$db2url $par['l2'].'.'.$par['pr'];
        if (
$par['pr'] == 'wiki')  $db2url $db2url.'pedia';
            
            
    
/* Parse non formated results
    $fields=mysql_num_fields($result);
    
    $Result_text .= "<table>\n<tr>";
    for ($i=0; $i < mysql_num_fields($result); $i++) { //Table Header
        $Result_text .= "<th>".mysql_field_name($result, $i)."</th>"; 
    }
    echo "</tr>\n";
    while ($row = mysql_fetch_row($result)) { //Table body
        $nresults++;
        $Result_text .= "<tr>";
        for ($f=0; $f < $fields; $f++) {
            $Result_text .= "<td>$row[$f]</td>"; 
        }
        $Result_text .= "</tr>\n";
    }
    $Result_text .= "</table><p>";
    */
    
        //Parse formatted results
        
while($row mysql_fetch_assoc($result))
        {
           
$nresults++;
              
           
$Result_text .= '* '.$row['count'];
           
$Result_text .= ' [[<a href="http://'.$db1url.'.org/wiki/'.$row['page_title'].'">'.$row['page_title'].'</a>]] ';
           
$Result_text .= ' [<a href="http://'.$db2url.'.org/wiki/Special:Search/'.$row['page_title'].'">Search in '.$par['l2'].'</a>] <br/>'."\r\n";
        }  
//while($row = mysql_fetch_assoc($result))
              
        
mysql_close();

        
//Results number
        
$Result_text .= $nresults.' '$String['results'].'. <br/>'."\r\n";
        
        
//Print results
        
echo $Result_text;
        
        
//Save results in cache
        
$fil fopen($cachenamew);
        
fwrite($fil$Result_text);
        
fclose($fil);

        
//Processing time     
        
$etimer Timer_time();  //End timer
        
$proceed_time Timer_elapsed($stimer$etimer);
           echo 
$String['Execution time'].' : '.$proceed_time.' '.$String['seconds'].' <br/>'."\r\n";
        
Average_add('./counters/'.$scriptname.'.average.proceed.txt'$proceed_time);
        

    
    } 
//if (file_exists($cachename))
    
    
echo '<br/> '.$String['Tool executed'].' ';
    
Counter('./counters/counter.'.$scriptname.'.proceed.txt');
    echo 
' '.$String['times'].'<br/>'."\r\n";
 
//if ($par['go'] != '')

echo $String['Tool info'].'<br/>'."\r\n";

echo 
'<hr/>';
echo 
$String['Page visited'].' ';
echo 
Counter('./counters/counter.'.$scriptname.'.txt');
echo 
' '.$String['times'].' <br/>'."\r\n";


require_once (
'footer.inc.php');

?>       

Source code for : header.inc.php · functions.inc.php · footer.inc.php · ca.inc.php · en.inc.php