[Mediawiki-l] Tag Extensions Multiple??

Daniel Friesen lists at nadir-seen-fire.com
Fri Sep 2 00:07:17 UTC 2011


Perhaps you're double-requiring a class and making it fail as a result.

Try autoloading DB_MySQL.
Or perhaps rewrite that code to use MW's own built in database layer
instead of duplicating that effort.

Some of that code is gawd awful too...
The way it makes a separate mysql conn for each is horrid. Heck seeing
an extra unused mysql conn in one of those is even worse.
The use of $_GET['title'] is horrid.
The way it uses two variables for the same thing `$endURL =
$_GET['title'];` then `$phrase = $endURL;`, and the pointless $healthy,
$yummy variables.
Btw, as it looks like you're trying to extract the title where you
should be using $parser->getTitle(), because you're using $_GET and not
even touching the WebRequest much less where you should be getting the
proper title if you happen to enable pretty urls, your code will break.
It may also mess up on titles with namespaces in them. Or on redirects.
Oh right, the way you're using $newphrase also has the potential to open
up a SQL injection vector.

I might as well point out also that by putting the setup code inside the
class you end up voiding the purpose of autoloading since the code is
loaded even when the tag isn't used. Also to top it off you shouldn't be
using $wgParser from that setup code, you should be using setup( $parser
) and using $parser->setHook on the parser that gets passed in (that is
the ENTIRE point of using the ParserFirstCallInit hook).
For $wgExtensionFunctions fallback code which you probably don't even
need now, you'd have an extra function and call your setup function with
$wgParser in there, not in the setup code.

~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]

On 11-09-01 04:24 PM, Mike Cody wrote:
> Hello,
>
> I am have a problem embedding more than one tag extensions in any given post on my wiki. wiki version 1.16
> Both tag extensions work fine by them selves but when ever I add the second one it causes errors or I just get a white page.
> I am using <servers/> and <contact/> to embed the extensions. I am guessing that when I add the second extension I am causing some type of problem with
> a global variable or some kind of name space issue. I have included all the code for the two extensions. any help would make my day!
>
> Thanks!
>
> ###ContactTag.php###
>
> <?php
>
> $wgHooks['ParserFirstCallInit'][] = 'ContactTag::setup';
>
> $wgAutoloadClasses['ConatctTag'] = dirname( __FILE__ ) . "/ContactTag_body.php";
>
>
> ###ContactTag_body.php###
>
> <?php
>
>
> // Create hello tag for the Wiki
> class HelloTag {
>   const NAME = 'contact';
>
>   static function setup() {
>     // The entry point. Associates the tag with a function.
>     global $wgParser;
>     $wgParser->setHook(self::NAME, array('ContactTag', 'render'));
>     return true;
>   }
> 		
>
>   static function render() {
>     //required for DB connection
>     require "db_mysql.inc";// defined in /etc/php.ini path: /usr/lib/php/include/
> 	require "define_hosts.php"; // defined in /etc/php.ini path: /usr/lib/php/include/
>
> 		// Connection Parameters
> 		$em7_g3 = new DB_MySQL;
> 		$em7_g3->Host = $em7_host;
> 		$em7_g3->User = $em7_user;
> 		$em7_g3->Password = $em7_pw;
> 		$em7_g3->Database = "biz";
> 		$em7_g3->connect();
> 		
> 		
> 		$ris = new DB_MySQL;
> 		$ris->Host = $storm_host;
> 		$ris->Database = "sugarcrm";
> 		$ris->User = $storm_user;
> 		$ris->Password = $storm_pw;
> 		$ris->connect();
> 	
> 	
> 		//Get end of URL remove _ from client name for DB query
> 		$endURL = $_GET["title"];
> 		$phrase  = $endURL;
> 		$healthy = array("_");
> 		$yummy   = array(" ");
> 		$newphrase = str_replace($healthy, $yummy, $phrase);
> 	
>
> 		//Run DB query and run though loop to get DB client data
> 			if ($newphrase) {
> 				$q = "Select v.first_name, v.last_name, f.email_address from contacts AS v
>     	Left join accounts_contacts AS s ON v.id = s.contact_id
>     	Left join accounts AS a ON a.id = s.account_id
>     	Left join email_addr_bean_rel AS e ON v.id = e.bean_id
>     	Left join email_addresses AS f ON f.id = e.email_address_id
>     	where a.name ='$newphrase'";
> 				$ris->query($q);
> 				$acnt = "";
> 				$table ="<table border='4'>";
> 					while ($ris->next_record()) {
> 						$company = $ris->f("first_name");
> 						$device = $ris->f("last_name");
> 						$active = $ris->f("email_address");
> 						//$ip = $ris->f("ip");
> 						$acnt = $acnt + 1;
>  							if ($company) {
>  									if ($acnt){
> 										$addr_list[$acnt] = "<tr><td>$company</td><td>$device</td><td>$active</td><td>$ip</td></tr>";
> 										$string = $string.$addr_list[$acnt];
> 									}
> 							}
>  			
> 				}
> 			
> 	 		$tableEnd="</table>";
>  			return $table.$string.$tableEnd;
> 	   
> 		}
>     
>   }
> }
>
>
> ###ServerTag.php###
>
> <?php
>
> # Credits
> $wgExtensionCredits['other'][] = array(
>   'name' => 'ServerTag',
>   'description' => 'Print All Servers Based On Client Page Name.',
>   'version' => '1.0');
>
> # Set up the hook, using different logic depending
> # on the version of MediaWiki
> if (defined('MW_SUPPORTS_PARSERFIRSTCALLINIT')) {
>   $wgHooks['ParserFirstCallInit'][] = 'ServerTag::setup';
> } else {
>   $wgExtensionFunctions[] = 'ServerTag::setup';
> }
>
> # Autoload the implementation class
> $wgAutoloadClasses['ServerTag']
>   = dirname( __FILE__ ) . "/ServerTag_body.php";
>
>
>
>
>
> ###ServerTag_body.php###
>
> <?php
>
>
>
>   class ServerTag {
>   const NAME = 'servers';
>
>   static function setup() {
>     global $wgParser;
>     $wgParser->setHook(self::NAME, array('ServerTag', 'render'));
>     return true;
>   }
> 		
>
>   static function render() {
>     //required for DB connection
>     require "db_mysql.inc";
> 	require "define_hosts.php"; 
>
> 		// Connection Parameters
> 		$em7_g3 = new DB_MySQL;
> 		$em7_g3->Host = $em7_g3_host;
> 		$em7_g3->User = $em7_g3_user;
> 		$em7_g3->Password = $em7_g3_pw;
> 		$em7_g3->Database = "master_biz";
> 		$em7_g3->connect();
> 	
> 	
> 		//Get end of URL remove _ from client name for DB query
> 		$endURL = $_GET["title"];
> 		$phrase  = $endURL;
> 		$healthy = array("_");
> 		$yummy   = array(" ");
> 		$newphrase = str_replace($healthy, $yummy, $phrase);
> 	
>
> 		//Run DB query and run though loop to get DB client data
> 			if ($newphrase) {
> 				$q = "SELECT company, device,master_dev.legend_device.active, master_dev.device_ip_addr.ip from master_biz.`organizations` left join master_dev.legend_device on master_biz.`organizations`.roa_id = master_dev.legend_device.roa_id left join master_dev.device_ip_addr on master_dev.legend_device.id = master_dev.device_ip_addr.did where company = '$newphrase'";
> 				$em7_g3->query($q);
> 				$acnt = "";
> 				$table ="<table border='4'>";
> 					while ($em7_g3->next_record()) {
> 						$company = $em7_g3->f("company");
> 						$device = $em7_g3->f("device");
> 						$active = $em7_g3->f("active");
> 						$ip = $em7_g3->f("ip");
> 						$acnt = $acnt + 1;
>  							if ($company) {
>  									if ($acnt){
> 										$addr_list[$acnt] = "<tr><td>$company</td><td>$device</td><td>$active</td><td>$ip</td></tr>";
> 										$string = $string.$addr_list[$acnt];
> 									}
> 							}
>  			
> 				}
> 			
> 	 		$tableEnd="</table>";
>  			return $table.$string.$tableEnd;
> 	   
> 		}
> 		
> 		
>     
>   }
> }
>
>
>
>
> Mike Cody
> Systems Administrator
> RELIAM
> (310) 348-9700 x 2  ( Support )
> (310) 348-9797 FAX
> ----
> Blog: http://www.reliam.com/news/reliam_blog
> Twitter: http://www.twitter.com/reliam
> Facebook: http://www.facebook.com/reliam
> ----

-- 
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]




More information about the MediaWiki-l mailing list