Database in mediawiki

<?php
# Here the necessary description of file, authors and license
# @FILLME!
# Always good to remind that important part

# Avoids illegal processing, doesn’t cost much, but unnecessary on a correct installation
if (!defined(‘MEDIAWIKI’)) { die(-1); }
class SpecialStudent extends SpecialPage{
public function __construct($request=null){
parent::__construct(‘Student’);
}
public function execute($par){
global $wgUser;
global $wgOut;
$wgOut->setPageTitle(wfMessage(‘Name’));

if($wgUser->isLoggedIn()){

$this->setHeaders();
$formDescriptor=array(
‘field1’=>array(
‘section’=>’section’,
‘class’=>’HTMLTextField’,
‘label’=>’Student Name’
),
‘field2’=>array(
‘section’=>’section’,
‘class’=>’HTMLTextField’,
‘label’=>’Student RollNo’
),
‘field3’=>array(
‘section’=>’section’,
‘class’=>’HTMLTextField’,
‘label’=>’Branch’
),
‘field4’=>array(
‘section’=>’section’,
‘class’=>’HTMLTextField’,
‘label’=>’Batch’
),
‘field5’=>array(
‘section’=>’section’,
‘class’=>’HTMLTextField’,
‘label’=>’Phone Number’
),
‘field6’=>array(
‘section’=>’section’,
‘class’=>’HTMLTextField’,
‘label’=>’Section’
),
);
$htmlForm=new HTMLForm($formDescriptor,$this->getContext(),’student’);
$htmlForm->setSubmitText(‘Submit’);
$htmlForm->setSubmitCallback(array(‘SpecialStudent’,’processInt’));
$htmlForm->show();
}else
{
$this->getOutput()->addHTML(“Please Login For adding new Data “);

$this->getOutput()->addHTML(“<form action=’http://&#8221;.$_SERVER[‘SERVER_NAME’].$_SERVER[‘SCRIPT_NAME’].”/Special:Student’ method=’post’> <table><tr><td>Search Student</form></td><td><input type=’text’ name=’t1′><input type=’submit’ value=’search’></td></tr></table></form>”);

$dbr=wfGetDB(DB_SLAVE);
if(isset($_POST[‘t1’])){
$res=$dbr->select(‘student’,array(‘name’,’rollno’,’branch’,’batch’,’ph’,’sec’,’id’),”name='”.$_POST[‘t1’].”‘”,__METHOD__);
}elseif(isset($_GET[‘mode’])){
$res=$dbr->select(‘student’,array(‘name’,’rollno’,’branch’,’batch’,’ph’,’sec’,’id’),”id='”.$_GET[‘mode’].”‘”,__METHOD__);
}
else{
$res=$dbr->select(‘student’,array(‘name’,’rollno’,’branch’,’batch’,’ph’,’sec’,’id’),””,__METHOD__);
}
if(!isset($_GET[‘mode’])){
foreach($res as $data){
$this->getOutput()->addHTML(“<br>”);
$this->getOutput()->addHTML(“<a href=’http://&#8221;.$_SERVER[‘SERVER_NAME’].$_SERVER[‘SCRIPT_NAME’].”/Special:Student?mode=”.$data->id.”‘>”.$data->name.”</a>”);
}
}
else
{
foreach($res as $data){
$this->getOutput()->addHTML(“<table border=’1’><tr><td>Name</td><td>RollNO</td><td>Branch</td><td>Batch</td><td>PH.Number</td><td>Section</td></tr>”);
$this->getOutput()->addHTML(“<tr><td>”.$data->name.”</td><td>”.$data->rollno.”</td><td>”.$data->branch.”</td><td>”.$data->batch.”</td><td>”.$data->ph.”</td><td>”.$data->sec.”</td></tr></table>”);
}
}
}
}
static function processInt($formData){
if($formData[‘field1’]){
$db=wfGetDB(DB_MASTER);

$d=array(
‘name’=>$formData[‘field1’],
‘rollno’=>$formData[‘field2’],
‘branch’=>$formData[‘field3’],
‘batch’=>$formData[‘field4’],
‘ph’=>$formData[‘field5’],
‘sec’=>$formData[‘field6’],
‘id’=>0
);
$db->insert(‘student’,$d,__METHOD__);
$db->commit(__METHOD__);
return “Ok Data is Inserted”;
}
else{
return ‘Try Again’;
}
}

}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s