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

Viewing: artniw Filesize: 8.41Kb
<?php
    
require_once('functions.inc.php');
    
    
//Variable initialitzation
    
$scriptname 'artniw';
    
$nresults 0;      //Results counter
    
$Result_text '';  //result string
    
$catfrom '';       //from added to SQL for category search 
    
$catwhere '';      //where added to SQL for category search
    
$tplfrom '';       //from added to SQL for template search
    
$tplwhere '';        //where added to SQL for template search
    
$subwhere '';      //where added to SQL for subpage search
    
$par['l1']  = strtolower(param_val('l1''gpcd'''));
    
$par['pr']  = param_val('pr''gpcd''');
    
$par['ns']  = param_val('ns''gpcd''');
    
$par['cat']  = param_val('cat''gpcd''');
    
$par['dpt']  = param_val('dpt''gpcd''');
    
$par['tpl']  = param_val('tpl''gpcd''');
    
$par['sub']  = param_val('sub''gpcd''');
    
$par['go']  = param_val('go''gpcd''');
    
$ns = array(=> ''=> 'Wikipedia:'10 => 'Template:'12 => 'Help;'14 => 'Category:'100 => 'Portal:' );

    
//Changing spaces for undescores for sqls
    
$cat ucfirst(str_replace(" ""_"trim($par['cat']))); 
    
$tpl ucfirst(str_replace(" ""_"trim($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['Articles without interwikis']?></font></h1>
<?=$String['Artniw 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['Namespace']?>:</td><td><select name="ns">
            <?=Option_item('Articles','0',$par['ns'])?>
            <?=Option_item('Wikipedia','4',$par['ns'])?>
            <?=Option_item('Template','10',$par['ns'])?>
            <?=Option_item('Help','12',$par['ns'])?>
            <?=Option_item('Category','14',$par['ns'])?>
            <?=Option_item('Portal','100',$par['ns'])?>
    </select></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><?=$String['Include subpages']?>:</td><td><input type="checkbox" name="sub" value="1" <?=Checked($par['sub'])?>/></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/>';


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['ns'].'.'.$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'];
        require_once(
'../database.inc');
        
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 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['category']))
        
        
if ($catfrom != '') {
            
$catfrom ', ('.$catfrom.') cat';
            
$catwhere 'p.page_id=cat.page_id and';
        }
        
        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 "p.page_id=tpl.page_id and";                        
        }

        if (
$par['sub'] != '1') {
            
$subwhere "p.page_title not like '%/%' and";
        }
        
        
$query "select p.page_title 
                from page p "
.$catfrom." ".$tplfrom."
                where "
.$catwhere." ".$tplwhere." ".$subwhere.
                p.page_namespace = "
.$par['ns']."
                and not exists (select 1 from langlinks ll where p.page_id=ll.ll_from )
                and p.page_is_redirect = 0
                order by p.page_title
                limit 0,500"
;

        echo 
'<!--'.$query.'-->'
        
$result mysql_query($query);
        
        if(!
$result) Die($String['ERROR:no results']);
          
        
$db1url $par['l1'].'.'.$par['pr'];
        
$projecturl $par['pr'];
        if (
$par['pr'] == 'wiki') {
         
$db1url $db1url.'pedia';
         
$projecturl $projecturl.'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/'.$ns[$par['ns']].$row['page_title'].'">'.$row['page_title'].'</a>]]';
       
$Result_text .= ' [<a href="http://www.google.com/search?q='.$ns[$par['ns']].str_replace("_"" "$row['page_title']).'+site%3A*.'.$projecturl.'.org+-site%3A'.$db1url.'.org">Google wikipedias</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