rendered paste body<?php
if (!defined('MEDIAWIKI'))
die();
$wgExtensionFunctions[] = "wfExtensionCreateMirandaLanguagepack";
$wgExtensionFunctions[] = "wfExtensionAsignMirandaVersionsinfo";
//====================================================
//specialpage to select the language files
//used NEW Table in DB:
//Name: user_miranda_lang
//Field 1: user_id, Typ: INT,Länge: 5, Attribute: Usigned, Null:not Null, standard 0; Primärschlüssel, Typ Primär
//Field 2: user_not_selected_langfiles, Typ:MEDIUMBLOB,Null:Null,Standard:Null
//CREATE TABLE `user_miranda_lang` (`user_id` int(5) unsigned NOT NULL default '0',`user_not_selected_langfiles` mediumblob, PRIMARY KEY (`user_id`) ) TYPE=MyISAM COMMENT='stored the not selected languagefiles per User';
//
//Name: user_miranda_versinfo
//Field 1: page_title, Typ: varchar, Länge: 255, Attribute: Binary,Null:Nein, Not Null
//Field 2: dll_name1, Typ: varchar, Länge: 50, Attribute: -, Null: Ja, Standard: Null
//Field 3: dll_name2, Typ: varchar, Länge: 50, Attribute: -, Null: Ja, Standard: Null
//Field 4: dll_name3, Typ: varchar, Länge: 50, Attribute: -, Null: Ja, Standard: Null
//Field 5: dll_name4, Typ: varchar, Länge: 50, Attribute: -, Null: Ja, Standard: Null
//CREATE TABLE `user_miranda_versinfo` (`page_title` varchar(255) binary NOT NULL default '',`dll_name1` varchar(50) default NULL,`dll_name2` varchar(50) default NULL,`dll_name3` varchar(50) default NULL,`dll_name4` varchar(50) default NULL,PRIMARY KEY (`page_title`)) TYPE=MyISAM COMMENT='stores the page_title for each DLL name from versionsinfo';
function wfExtensionCreateMirandaLanguagepack()
{
global $IP, $wgMessageCache;
require_once( "$IP/includes/SpecialPage.php" );
class MirandaLanguagepack extends SpecialPage
{
var $mAction,$mPosted;
var $ArrayLanguageArticles=Array();
function MirandaLanguagepack()
{
SpecialPage::SpecialPage( "MirandaLanguagepack" );
}
function execute( $par )
{
global $wgRequest,$wgOut, $wgUser;
$fname = "MirandaLanguagepack::execute";
$this->setHeaders();
$this->mPosted=$wgRequest->wasPosted();
$this->mAction=$wgRequest->getText( "action" );
if(count($ArrayLanguageArticles)==0)
{
$dbr =& wfGetDB( DB_SLAVE );
$sql="SELECT page_title FROM page, categorylinks WHERE page.page_id = categorylinks.cl_from AND categorylinks.cl_to = 'Texte' AND page.page_namespace =100 ORDER BY page_title DESC";
$res=$dbr->query($sql,$fname);
while($row=$dbr->fetchObject($res))
$this->ArrayLanguageArticles[$row->page_title]=TRUE;
$dbr->freeResult($res);
//read, if available, the not selected titles from the user, and deselect it again
$UserID=$wgUser->idForName();
if($UserID>0)
{
$sql="SELECT user_not_selected_langfiles FROM user_miranda_lang WHERE user_id=$UserID";
$res=$dbr->query($sql,$fname);
$row=$dbr->fetchRow($res);
if($row!==FALSE)
{
$arrNotSelected=unserialize($row[0]);
foreach($this->ArrayLanguageArticles as $key=>$value)
{
if(in_array($key,$arrNotSelected)===TRUE)
$this->ArrayLanguageArticles[$key]=FALSE;
}
}
}
}
if($this->mPosted==true && $this->mAction=="submit")
{
if($wgRequest->getCheck("CreateFile"))
$this->DownloadLanguagepack();
If($wgRequest->getCheck("SelectAll"))
$this->MakeSelection("SelectAll");
If($wgRequest->getCheck("SelectNone"))
$this->MakeSelection("SelectNone");
If($wgRequest->getCheck("TextVersionsinfo"))
{
$this->MakeSelection("TextVersionsinfo");
$this->ShowLanguagepackSelection();
}
If($wgRequest->getCheck("FileVersionsinfo"))
{
$this->MakeSelection("FileVersionsinfo");
$this->ShowLanguagepackSelection();
}
}
else
{
$this->ShowLanguagepackSelection();
}
}
//Display the Buttons, the list with languagearticles and selection, selection is loaded from a special user DB Table
function ShowLanguagepackSelection()
{
global $wgOut, $wgRequest, $wgUser;
$dbr =& wfGetDB( DB_SLAVE );
$fname = "MirandaLanguagepack::ShowLanguagepackSelect";
$titleObj = Title::makeTitle( NS_SPECIAL, 'MirandaLanguagepack' );
$action = $titleObj->escapeLocalURL( "action=submit" );
$wgOut->addWikiText("[[Sprachdatei:Quellcode MirandaLanguagepack.php]]");
$wgOut->addWikiText("{{Sprachdatei erstellen}}");
$text="<hr><form name=\"SelectedTitles\" method=\"post\" action=\"$action\" enctype=\"multipart/form-data\" >\r\n";
$text.="<button type=\"submit\" name=\"CreateFile\"style=\"width:200px; height:50px\">Sprachdatei erstellen<br />und downloaden</button><br /><hr />\r\n";
$text.="Versionsinfo als Text einfügen (Strg+V):<textarea style=\"width:100px\" name=\"TextVersionsinfo\" cols=\"20\" rows=\"1\"></textarea>\r\n";
$text.="Aus Datei:<input name=\"FileVersionsinfo\" type=\"file\" size=\"20\" maxlenght=\"10000\" accept=\"text/*.txt\"><br />";
$text.="<button type=\"submit\" name=\"SendVersionsinfo\"style=\"width:200px\">Versionsinfo übetragen</button><br />\r\n";
$text.="<hr /><button type=\"submit\" name=\"SelectAll\" style=\"font-size:small;width:100px\">Alle auswählen</button>\r\n";
$text.="<button type=\"submit\" name=\"SelectNone\" style=\"width:100px\">Alle abwählen</button><br />\r\n";
$text.="<p style=\"font-size:large\">Auswahl für <b>".$wgUser->getName()."</b></p>\r\n";
foreach($this->ArrayLanguageArticels as $Title => $select)
{
$text.="<input type=\"checkbox\" name=\"Auswahl[]\" value=\"$Title\" ";
if($select==TRUE)
$text.=" checked=\"checked\" />";
else
$text.=" />";
$text.=$wgOut->parse("[[Sprachdatei:$Title|$Title]]<br />",false)."\r\n";
}
$text.="</form>";
$wgOut->addHTML($text);
}
//Create a textfile from all selected languagearticles
function DownloadLanguagepack()
{
global $wgOut, $wgRequest, $wgUser;
$SelectedTitleArray=$wgRequest->getArray('Auswahl');
$dbrw =& wfGetDB( DB_MASTER );
$fname = "MirandaLanguagepack::DownloadLanguagepack";
if(!is_null($SelectedTitleArray))
{
//Without that the mediwiki software add the web site itself to the the output file
$wgOut->disable();
//save the NOT selected titles in the db per user
//save the selected titles could make some problems for new translated files.
$UserID=$wgUser->idForName();
if($UserID>0)
{
$arrNotSelected=array();
foreach($this->ArrayLanguageArticles as $Title =>$dummyvalue)
{
if(!in_array($Title,$SelectedTitleArray))
$arrNotSelected[]=$Title;
}
$serNotSelected="'".addslashes(serialize($arrNotSelected))."'";
$sql="REPLACE INTO user_miranda_lang (user_id, user_not_selected_langfiles) VALUES ($UserID,$serNotSelected)";
$res=$dbrw->query($sql,$fname);
}
for($i=0;$i<count($SelectedTitleArray); $i++)
$SelectedTitleArray[$i]="'".$SelectedTitleArray[$i]."'";
$dbr =& wfGetDB( DB_SLAVE );
$sql="SELECT old_text FROM page,text, revision WHERE page.page_title IN (".implode(",",$SelectedTitleArray).") AND revision.rev_id=page.page_latest AND revision.rev_text_id=text.old_id AND page.page_namespace=100";
$res=$dbrw->query($sql,$fname);
while ($row=$dbrw->fetchObject($res))
{
$curText=$row->old_text;
$this->FormatText($curText);
$outText.=$curText;
}
$dbrw->freeResult($res);
$filename="../wiki/extensions/langpack_german.txt";
if($file=fopen($filename,"w"))
fwrite($file,$outText);
fclose($file);
header('Content-Description: File Transfer');
header("Content-type: text/html; charset=CP1252" );
header("Content-length: ".filesize($filename));
header( "Content-disposition: attachment; filename=langpack_german.txt");
readfile($filename);
unlink($filename);
}
else
{
$wgOut->addHTML("<span style=\"color:red;\"><b>Nichts ausgewählt!</b></span>");
}
}
//title selection with buttons or with versionsinfo
function MakeSelection($selection)
{
if($selection=="SelectAll")
{
foreach($this->ArrayLanguageArticels as $Title => $select)
$this->ArrayLanguageArticels[$Title]=TRUE;
return;
}
if($selection=="SelectNone")
{
foreach($this->ArrayLanguageArticels as $Title => $select)
$this->ArrayLanguageArticels[$Title]=FALSE;
return;
}
if($selection=="TextVersionsinfo")
{
return;
}
if($selection=="FileVersionsinfo")
{
return;
}
}
//Text = Text from one language text article in the Wiki
// we use a reference, it should be faster and save some memory
// additinonal checks if the languagearticel should added here
function FormatText(&$Text)
{
$Text=iconv("UTF-8","cp1252",$Text);//wiki is utf-8 langugepack use ANSI, windows-1252 not work correctly
preg_match_all("#<pre>(.*)</pre>#Us", $Text,$arrTextBlocks);
$Text="";
foreach($arrTextBlocks[1] as $TextBlock)
$Text.=$TextBlock;
}
}
SpecialPage::addPage( new MirandaLanguagepack );
$wgMessageCache->addMessages( array("mirandalanguagepack" => "Sprachdatei erstellen und downloaden"));
}
//=====================================================
//Specialpage to display the assign dll-name versionsinfo - Language file
//used NEW Table in DB:
//
function wfExtensionAsignMirandaVersionsinfo()
{
global $IP, $wgMessageCache;
require_once( "$IP/includes/SpecialPage.php" );
class MirandaVersionsinfo extends SpecialPage
{
var $mAction,$mPosted;
var $ArrayLanguageArticlesVersinfo=Array();
function MirandaVersionsinfo()
{
SpecialPage::SpecialPage( "MirandaVersionsinfo" );
}
function execute( $par )
{
global $wgRequest,$wgOut;
$fname = "MirandaVersionsinfo::execute";
$this->setHeaders();
$this->mPosted=$wgRequest->wasPosted();
$this->mAction=$wgRequest->getText( "action" );
if(count($ArrayLanguageArticlesVersinfo)==0)
{
$dbr =& wfGetDB( DB_SLAVE );
//$sql="SELECT page.page_title FROM page, categorylinks WHERE page.page_id = categorylinks.cl_from AND categorylinks.cl_to = 'Texte' AND page.page_namespace =100 ORDER BY page_title DESC";
$sql="SELECT page.page_title, user_miranda_versinfo.dll_name1, user_miranda_versinfo.dll_name2, user_miranda_versinfo.dll_name3, user_miranda_versinfo.dll_name4 FROM page, categorylinks LEFT JOIN user_miranda_versinfo ON user_miranda_versinfo.page_title = page.page_title WHERE page.page_id = categorylinks.cl_from AND categorylinks.cl_to = 'Texte'AND page.page_namespace =100 ORDER BY page_title ASC";
$res=$dbr->query($sql,$fname);
while($row=$dbr->fetchRow($res))
$this->ArrayLanguageArticlesVersinfo[$row[0]]=array($row[1],$row[2],$row[3],$row[4]);
$dbr->freeResult($res);
}
if($this->mPosted==true && $this->mAction=="submit")
{
$this->StoreNamesInDB();
}
else
{
$this->ShowVersionsinfoTable();
}
}
function ShowVersionsinfoTable()
{
global $wgOut;
$fname = "MirandaVersionsinfo::ShowVersionsinfoTable";
$title = Title::makeTitle( NS_SPECIAL, 'MirandaVersionsinfo' );
$action = $title->escapeLocalURL( "action=submit" );
$wgOut->addWikiText("{{Sprachdatei Versionsinfo zuweisen}}");
$text="<hr><form name=\"AsignVersionsinfo\" method=\"post\" action=\"$action \" ><br />\r\n";
$text.="<table border=\"1\" cellspacing=\"1\" width=\"100%\" cellpadding=\"2\">\r\n";
$text.="<caption>(Nur den Namen der DLL Datei, ohne den Anhang <b>.dll</b> angeben.)</caption>\r\n";
$text.="<colgroup><col width=\"6*\" span=\"6\" /></colgroup>\r\n";
$text.="<tr><th>Sprachdatei</th><th>DLL Name 1</th><th>DLL Name 2</th><th>DLL Name 3</th><th>DLL Name 4</th></tr>\r\n";
foreach($this->ArrayLanguageArticlesVersinfo as $Title => $arrDLLName)
{
$text.="<tr><td>".$wgOut->parse("[[Sprachdatei:$Title|$Title]]")."</td>\r\n";
$text.="<td><input name=\"arrDLLNames[$Title][]\" type=\"text\" size=\"25\" maxlength=\"50\" value=\"".$arrDLLName[0]."\"></td>\r\n";
$text.="<td><input name=\"arrDLLNames[$Title][]\" type=\"text\" size=\"25\" maxlength=\"50\" value=\"".$arrDLLName[1]."\"></td>\r\n";
$text.="<td><input name=\"arrDLLNames[$Title][]\" type=\"text\" size=\"25\" maxlength=\"50\" value=\"".$arrDLLName[2]."\"></td>\r\n";
$text.="<td><input name=\"arrDLLNames[$Title][]\" type=\"text\" size=\"25\" maxlength=\"50\" value=\"".$arrDLLName[3]."\"></td>\r\n";
$text.="<td><input type=\"submit\" name=\"clickedSubmit[$Title]\" value=\"Zeile Speichern\"></td>\r\n";
}
$text.="</table>";
$text.="</form>";
$wgOut->addHTML($text);
}
function StoreNamesInDB()
{
global $wgRequest,$wgOut;
$fname = "MirandaVersionsinfo::StoreNamesInDB";
$submitDLLNames=$wgRequest->getArray('arrDLLNames');
$clickedSubmit=$wgRequest->getArray('clickedSubmit');
$clickedSubmit=key($clickedSubmit);
if(empty($clickedSubmit)===TRUE )
return;
$arrDLLNames=$submitDLLNames[$clickedSubmit];
$dbrw =& wfGetDB( DB_MASTER );
$sql="REPLACE INTO user_miranda_versinfo (page_title, dll_name1, dll_name2 ,dll_name3,dll_name4) VALUES('$clickedSubmit', '$arrDLLNames[0]', '$arrDLLNames[1]', '$arrDLLNames[2]' ,'$arrDLLNames[3]')";
$res=$dbrw->query($sql,$fname);
$wgOut->addHTML($sql);
$title =& Title::makeTitle( NS_SPECIAL, 'MirandaVersionsinfo' );
$wgOut->redirect($title->getFullUrl());
}
}
SpecialPage::addPage( new MirandaVersionsinfo );
$wgMessageCache->addMessages( array("mirandaversionsinfo" => "Sprachdatei Versionsinfo Zuordnung"));
}
?>