User:Diploid/ATS (Article Tagging System)/ATS.php

<?php /* Copyright (c) 2007 MediaWiki.org User: Diploid * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of  * the Software, and to permit persons to whom the Software is furnished to do  * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * --- */
 * 1) Rob's Article Tagging System (ATS) for Media Wiki! Extension: WikiInterface.php - a work in progress

if ( ! defined( 'MEDIAWIKI' ) ) die( 1 ); session_start;

require(dirname(__FILE__) .'/ATS_Body.php'); $ATSajax = new ATSajaxresponse;

/*$wgOut->addLink( 	array( 'rel' => 'stylesheet', 'type' => 'text/css', 'href' => $wgScriptPath. '/extensions/ATS/ATS.css' ) );*/

$wgHooks['BeforePageDisplay'][] = 'ATSaddscript';

$wgHooks['BeforePageDisplay'][] = 'ATSloadeventimage';

$wgExtensionFunctions[] = 'wfATSParserFunction_Setup'; $wgHooks['LanguageGetMagic'][]      = 'wfATSParserFunction_Magic';
 * 1) Define a setup function
 * 1) Add a hook to initialise the magic word

function wfATSParserFunction_Setup { global $wgParser; # Set a function hook associating the "tagcloud" magic word with our function $wgParser->setFunctionHook( 'tagcloud', 'ATSwikitext' ); # A tagcloudhtmlonly function is inserted in the wikitext by the tagcloud function $wgParser->setFunctionHook( 'tagcloudhtmlonly', 'ATShtml' ); # Used in categories that have tagged pages to get a list of the top tagged pages for that category $wgParser->setFunctionHook( 'tagranking', 'ATScategoryTagRanking' );

} function wfATSParserFunction_Magic( &$magicWords, $langCode ) { # Add the magic word # The first array element is case sensitive, in this case it is not case sensitive # All remaining elements are synonyms for our parser function $magicWords['tagcloud'] = array( 0, 'tagcloud' ); $magicWords['tagcloudhtmlonly'] = array( 0, 'tagcloudhtmlonly' ); $magicWords['tagranking'] = array( 0, 'tagranking' ); # unless we return true, other parser functions extensions won't get loaded. return true; }

function ATSwikitext(&$parser){ global $wgTitle, $ATSajax; $metatags = "GetTags_CommaSeperatedText($wgTitle->getPrefixedText)."\" />"; $tagdata = $ATSajax->GetTags($wgTitle->getPrefixedText); $size = count($tagdata); $categories = ""; if ($tagdata!=false && $size != 0) {		for ($i=0; $i<$size; $i++) {			$categories .= ""; }	}	$output = "" .""	.$metatags .$categories .""	;	return $output; }

function ATShtml( &$parser) { global $Path; # The parser function itself # The input parameters are wikitext with templates expanded # The output should be wikitext too #returns the div which is then manipulated by javascript to contain the #tag cloud upon the page being loaded $output ="" #Rounded Corners - Top ."" ."" #Content ."" ." "       #Various Loading Overlays for grey out and loading message ."" ."" ."" ." Loading..." ." "       ." "        #Rounded Corners - Bottom ."</b></b></b></b></b>" ." "       ;        $parser->disableCache; return array($output, 'noparse' => true, 'isHTML' => true); }

function ATScategoryTagRanking ( &$parser) {		global $Path, $wgTitle, $ATSajax; # The parser function itself # The input parameters are wikitext with templates expanded # The output should be wikitext too #Getting the list of pages tagged as belonging to this category and the number of tags they each have $tag = str_replace("Category:","",$wgTitle->getPrefixedText); $tagdata = $ATSajax->GetTaggedPages($tag); $size = count($tagdata); $pagelist = ""; if ($tagdata!=false && $size != 0) {			for ($i=0; $i<$size; $i++) {				$tagurl = $Path."/index.php?title=".$tagdata[$i]["Page"]; $pagelist .= "<li><a href=\"".$tagurl."\">".$tagdata[$i]["Page"]."</a> (".$tagdata[$i]["tagcount"].")</li>"; }		}       #returns the div which is then manipulated by javascript to contain the #tag cloud upon the page being loaded $output ="" ."<div id=\"ATStagranking\">" #Rounded Corners - Top ."</b></b></b></b></b>" #Content ."<div id=\"ATStagranking_content\">" ." Most Tagged " ."<ul>" .$pagelist ."</ul>" ." "       #Rounded Corners - Bottom ."</b></b></b></b></b>" ." "       ;        $parser->disableCache; return array($output, 'noparse' => true, 'isHTML' => true);

}

function MakeHashKey {	global $wgUser,$wgTitle; if ($wgUser->isLoggedIn) {		$_SESSION['ATSuser'] = $wgUser->getName; }	else {		$_SESSION['ATSuser'] = ""; };	$_SESSION['ATSpage'] = $wgTitle->getPrefixedText; $key = "testkey3"; $_SESSION['ATShash'] = sha1($key); return $key; }

function ATSaddscript { global $wgOut, $wgUser, $Path, $wgTitle; //$wgOut->addScript("<script type=\"text/javascript\" />"); //<img src=\"".$Path."/extensions/ATS/loading_circle.gif\" style=\"position:absolue; left: -500px; top: 0px; width: 1px;\" onLoad=\"AsyncLoadATS(, );\"> $wgOut->addScript("<link rel=\"stylesheet\" type=\"text/css\" href=\"".$Path."/extensions/ATS/ATS.css\" />"); $wgOut->addScript(" <script type=\"text/javascript\"> function AsyncLoadATS(tag) { var page = \"".$wgTitle->getPrefixedText."\";  var user = \"".$wgUser->getName."\";  var id = \"".MakeHashKey."\";

var ATSdiv = document.getElementById('ATStagcloud'); var ATSloadingDiv = document.getElementById('ATStagcloudOverlay'); ATSdiv.setAttribute('class',\"ATSloading\"); ATSloadingDiv.setAttribute('class',\"ATSvisible\");

args = '&ATSuser=' + user; args = args + '&ATSpagename=' + page; args = args + '&ATSid=' + id; args = args + '&ATSaddtag=' + tag; var xmlHttp; try {   // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest; } catch (e) {   // Internet Explorer try {     xmlHttp=new ActiveXObject(\"Msxml2.XMLHTTP\"); }   catch (e) {     try {       xmlHttp=new ActiveXObject(\"Microsoft.XMLHTTP\"); }     catch (e) {       alert(\"Your browser does not support AJAX!\"); return false; }     }    }    xmlHttp.onreadystatechange=function {     if(xmlHttp.readyState==4) {	ATSdiv.innerHTML = xmlHttp.responseText; ATSdiv.setAttribute('class',\"ATSloaded\"); ATSloadingDiv.setAttribute('class',\"ATShidden\"); }     }

xmlHttp.open(\"GET\",\"".$Path."/extensions/ATS/ATS_HTML_Update.php?\"+args,true); xmlHttp.send(null);

}

\n"	); }

?>