User:Jack Phoenix/patches/GetFamily

Index: GetFamily.i18n.php

=
====================================================== --- GetFamily.i18n.php	(revision 0) +++ GetFamily.i18n.php	(revision 0) @@ -0,0 +1,16 @@ + 'Get Pywikipediabot Family', +	'getfamily-interwikierror' => 'Error: incorrect interwiki setup, contact Your local admin.', +); \ No newline at end of file

Property changes on: GetFamily.i18n.php ___________________________________________________________________ Name: svn:eol-style + native

Index: GetFamily.php

=
====================================================== --- GetFamily.php	(revision 206) +++ GetFamily.php	(working copy) @@ -1,68 +1,64 @@  Error  ] This is not a valid entry point.'. "\n"; -   Exit (1); +if (!defined ('MEDIAWIKI')) { +	echo '[  Error  ] This is not a valid entry point.'. "\n"; +	exit (1); } -$wgExtensionFunctions [] = 'wfInitiateSpecialGetFamily'; +$dir = dirname(__FILE__). '/'; +$wgExtensionMessagesFiles['GetFamily'] = $dir. 'GetFamily.i18n.php'; +$wgSpecialPages['GetFamily'] = array('SpecialPage', 'GetFamily', 'getfamily'); -include_once( "$IP/extensions/wikia/WikiCurl/WikiCurl.php" ); +$wgAvailableRights[] = 'getfamily'; +$wgGroupPermissions['*']['getfamily'] = true; -function wfInitiateSpecialGetFamily{ -	Global $IP, $wgMessageCache, $wgAvailableRights, $wgGroupPermissions; -	-	Require_Once ($IP. '/includes/SpecialPage.php'); -	-	$wgSpecialPages ['GetFamily'] = Array ('SpecialPage', 'GetFamily'); -	SpecialPage::AddPage (new SpecialPage ('GetFamily', 'GetFamily', True, 'wfSpecialGetFamily', False)); -	$wgMessageCache->AddMessage ('getfamily', 'Get Pywikipediabot Family'); -	$wgMessageCache->AddMessage ('interwikierror', 'Error: inncorrect interwiki setup, contact Your local admin.' ); +$wgExtensionCredits['specialpage'][] = array( +	'name' => 'GetFamily', +	'version' => '1.0', +	'author' => 'Łukasz Matysiak', +	'description' => 'Generates a family file for pywikipediabot', +	'url' => 'http://www.mediawiki.org/wiki/Extension:GetFamily' +); -	$wgAvailableRights[] = 'GetFamily'; -   $wgGroupPermissions['*'    ]['GetFamily'] = true; -	-	//$wgGroupPermissions['bot']['getfamily'] = true; -	//$wgGroupPermissions['staff']['getfamily'] = true; -} +include_once( "$IP/extensions/wikia/WikiCurl/WikiCurl.php" ); function wfSpecialGetFamily{ global $wgRequest, $wgOut, $wgLanguageNames; -	global $wgScript, $wgDBname, $wgLanguageCode, $wgSitename, $wgServer, $wgArticlePath, $wgCanonicalNamespaceNames,$wgVersion; -	+	global $wgScript, $wgDBname, $wgLanguageCode, $wgSitename, $wgServer, $wgArticlePath, $wgCanonicalNamespaceNames, $wgVersion; + 	$out = ''; -	+ 	if ($wgRequest->getVal('action') == 'GetLocal'){ -		$db =& wfGetDB( DB_SLAVE ); +		$db = wfGetDB( DB_SLAVE ); $fromLang = $wgRequest->getVal('fromLang'); $result = $db->query( "SELECT iw_url FROM interwiki WHERE iw_prefix ='$fromLang';"); if ($object = $db->fetchObject($result) ){ $fromLang = $object->iw_url; -		}else{ +		} else { $fromLang = ''; } -		Header ('Content-Type: text/xml'); +		header('Content-Type: text/xml'); $out .= " \n"; -		+ 		$out .= wfElement('urlcheck', array, $fromLang)."\n"; $out .= wfElement('language', array, $wgLanguageCode)."\n"; $out .= wfElement('hostname', array, str_replace('http://', '', $wgServer))."\n"; $out .= wfElement('path', array, $wgScript )."\n"; -		 		//$keys = array_keys ($wgCanonicalNamespaceNames); $language = Language::factory($wgLanguageCode); $array = $language->getNamespaces; -		$keys = array_keys ($array); +		$keys = array_keys($array); foreach( $keys as $key ){ $out .= wfOpenElement('namespace', array). "\n"; @@ -72,28 +68,28 @@ 		  $out .= wfCloseElement('namespace'); } 		$out .= " \n"; -	}else{ -		Header ('Content-Type: text'); -		+	} else { +		header('Content-Type: text'); + 		$langcodes = array_keys($wgLanguageNames); -		-		$db =& wfGetDB( DB_SLAVE ); + +		$db = wfGetDB( DB_SLAVE ); foreach( $langcodes as $lang_code){ $where .= ', '. $db->AddQuotes($lang_code); } 		$where = SubStr ($where, 1); $result = $db->query( "SELECT iw_prefix, iw_url FROM interwiki WHERE iw_prefix IN ( $where );"); -		+ 		$datalinks = array; -		+ 		while($dbObject = $db->fetchObject($result)){ $datalinks[$dbObject->iw_prefix] = $dbObject->iw_url; } -		+ 		$datalinks[$wgLanguageCode] = $wgServer.$wgArticlePath; -		+ 		unset($datalinks['bug']); -		+ 		$metadata = array; $metadata['langs'] = array; $metadata['path'] = array; @@ -110,9 +106,9 @@            		$content = substr( $content, strpos( $content, "\r\n\r\n" ) + 4 ); unset($handler); -			try{ +			try { $xml = new SimpleXMLElement($content); -           		} catch (Exception $e){ +           		} catch(Exception $e){ continue; } @@ -138,7 +134,7 @@ It was generated by Special:GetFamily (a Wikia extension). Save this file to families/{$wgDBname}_family.py in your pywikibot installation -The pywikipediabot itself is available for free download from sourceforge.net +The pywikipediabot itself is available for free download from svn.wikimedia.org ''' import family @@ -152,15 +148,15 @@ \t\t self.langs = {\n"; 		$keys = array_keys($metadata['langs']); -		+ 		foreach($keys as $key){           $out .=  "\t\t\t'$key': '{$metadata['langs'][$key]}', \n"; 		} -		+ 		$out .="\t\t }\n\t\t \n"; 		$namespace_keys = array_keys($namespacedata); -		+ 		foreach($namespace_keys as $key){ 			$langs = array_keys($namespacedata[$key]); 			$out .= "\t\t self.namespaces[$key] = {\n"; @@ -173,7 +169,7 @@ 		$version = array; 		preg_match('/[0-9]*\.[0-9]*/',$wgVersion, $version ); 		$version = $version[0]; -		+ $out .="\t\t \t def hostname(self,code): \t\t return self.langs[code] @@ -182,13 +178,13 @@ \t\t path = ''\n"; 		$keys = array_keys($metadata['langs']); -		+ 		foreach($keys as $key){           $out .=  "\t\t if (code=='$key'):\n\t\t\t path='{$metadata['path'][$key]}'\n"; 		} -		+ $out .="\t\t return path \t \t def login_address(self,code): @@ -197,10 +193,9 @@ \t def version(self, code): \t\t return '".$version."' #The MediaWiki version used. Not very important in most cases. "; -}else{ - $out .= wfMsg('interwikierror'); +} else { +  $out .= wfMsg('getfamily-interwikierror'); } 	} 	die( $out ); -} -?> +} \ No newline at end of file