Auto refresh content in Mediawiki - ajax

I added a new tag (<news />) to my mediawiki to list the last modified pages.
Unfortunately the list is not updated unless I modify the page where the tag is.
I'm looking for a way to do it, and I think of AJAX. But I didn't manage to make AJAX refreshing my list.
Does anyone know a simple way to add an auto refresh feature on my Mediawiki ?
Here is my extension code :
$wgHooks['ParserFirstCallInit'][] = 'replaceTags';
function replaceTags( Parser $parser ) {
$parser->setHook( 'news', 'newsRender' );
return true;
}
function newsRender( $input, array $args, Parser $parser, PPFrame $frame ) {
// Titre =News=
$output = $parser->parse( "=News=", $parser->mTitle, $parser->mOptions, false, false )->getText();
$nb = 5;
$querySQL = "SELECT page_namespace, page_title, page_id, page_latest, rev_timestamp
FROM page, revision
WHERE page.page_latest = revision.rev_id
AND page_namespace = 0
ORDER BY rev_timestamp
DESC LIMIT 0,$nb";
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->query( $querySQL );
$count = $dbr->numRows( $res );
if( $count > 0 ) {
$output .= "<ul>";
while( $row = $dbr->fetchObject( $res ) )
{
$pageTitle = $row->page_title;
$nicerPageTitle = str_replace("_", " ", $pageTitle);
$pageNamespace = $row->page_namespace;
$title = Title::makeTitleSafe( $pageNamespace, $pageTitle );
$url = $title->getFullURL();
$date = $row->rev_timestamp;
$date = wfTimestamp( TS_RFC2822, $date );
$output .= "<li>$nicerPageTitle $date</li>";
}
$output .= "</ul>";
} else {
$output .= "A l'ouest rien de nouveau !!!";
}
return $output;
}

Thanks to nischayn22, I go into the cache problem in depth.
And I found that it's possible to deactivate it :
$parser->disableCache();
I tried it, and it works !!!
http://www.mediawiki.org/wiki/Extensions_FAQ#How_do_I_disable_caching_for_pages_using_my_extension.3F

This probably happens because MediaWiki uses Cache for pages. What you could rather do is make a SpecialPage for the feature needed. AFAIK Special Pages are not cached (confirm this on irc #mediawiki).
Also you might already find a similar implementation done by someone if you search the extensions that exist on Mediawiki.org .(Otherwise I would be happy to build one for you :)
Update: Extensions you could use Dynamic List(used in wikinews) and news . There could be more if you search mediawiki.org.

Related

$_SESSION variables use in queries

I have spent nearly two days going in circles on this one.
I seem to have difficulty using $_SESSION or $_POST as strings in any query or converting them to strings to use.
I am using a simple hash approach to login to a site.
Extract from script is
<?php
session_start();
echo "******Running Authenticate<br>";
echo "data submitted<br>".$_POST['site_login']."<br>".$_POST['site_password']."<br><br>";
$SiteLogin = $_POST['site_login']
$_SESSION['site_login'] = $_POST['site_login'];
$_SESSION['site_password'] = $_POST['site_password'];
$_SESSION['session_id'] = session_id();
$_SESSION['Now_val'] = date('Y-m-d H:i:s');
//include 'showallvars.php';
include 'dbconfig.php';
// Prepare our SQL
if ($stmt = $con->prepare('SELECT site_index, site_password FROM web_sites WHERE site_login = ?')) {
// Bind parameters (s = string, i = int, b = blob, etc), hash the password using the PHP password_hash function.
$stmt->bind_param('s', $_POST['site_login']);
$stmt->execute();
$stmt->store_result();
// Store the result so we can check if the account exists in the database.
if ($stmt->num_rows > 0) {
$stmt->bind_result($id, $password);
$stmt->fetch();
echo "account exists";
}
else
{
header('Location: badindex.php');
}
if (password_verify($_POST['site_password'], $password)) {
// Verification success! User has loggedin!
echo "password good";
}
else
{
header('Location: badindex.php');
}
}
$_SESSION['loggedin'] = TRUE;
?>
that works fine
BUT there is another field ( 'site_name') in the record which i want to carry forward.
This should be easy !!
and there is a dozen ways of doing it
for example the "standard" example is something like
$name = $mysqli->query("SELECT site_name FROM web_sites WHERE site_login = 'fred'")->fetch_object()->site_name;
That works fine
but no matter how i try - concatenating or or ... I cannot get $_SESSION['site_login'] or $_POST['site_login'] to replace 'fred'.
There seems to be white space added in.
Assistance or guidance ?
It should be possible to as easy as doing the following:
So:
if ($stmt = $con->prepare('SELECT site_index, site_password
FROM web_sites WHERE site_login = ?')) {
becomes:
if ($stmt = $con->prepare('SELECT site_index, site_password, site_login
FROM web_sites WHERE site_login = ' . $SiteLogin)) {
Do note, it is bad practice to do directly parse $SiteLogin to a query, because now someone can SQL Inject this and hack your website. All they need to do is use your form and figure out that which field is responsible for $SiteLogin. You would need to escape your $SiteLogin. Assuming Mysqli, it would become:
if ($stmt = $con->prepare('SELECT site_index, site_password, site_login
FROM web_sites WHERE site_login = ' . $con->real_escape_string($SiteLogin))) {
Thank you for that BUT the instant I saw the curly brackets in your answer - it all came flooding back to me. I had forgotten that PHP has problems with the square brackets
$sql = ("SELECT site_name FROM web_sites WHERE site_login = '". $_SESSION{'site_login'} ."' LIMIT 1");
I KNEW it was easy !
Your comments on injection are of course correct but this was an edited code excerpt and $SiteLogin was just added in as a "temporary working variable if needed"

SESSION varibales are not displayed after redirection used with memcache

I have a page session_config.php in that page I have following code
session_name('session_sw');
session_start();
$session_ID = session_id();
I have another page index.php in which I am including session_config.php ,the code as follows.
$email = $_REQUEST['email'];
$pass = $_REQUEST['pass'];
$error = 0;
if(!empty($email) && !empty($pass)) {
$url = "$SERVER/sw/apis/3rdpartylogin.php?advertiser_login=1&pass=$pass&email=$email";
$resp = file_get_contents($url);// it sends json encoded string.
$resp = json_decode($resp);
if ( $resp->status == 'success' ) {
if ( !isset($resp->mesg->profile) || $resp->mesg->profile == 0 ){
$error = '1';
} else {
include "session_config.php";
$_SESSION['user_id'] = $resp->mesg->user_id;
$_SESSION['customer_id'] = $resp->mesg->customer_id;
$_SESSION['customer_name'] = $resp->mesg->customer_name;
$_SESSION['logged_in_user_email'] = $_REQUEST['email'];
$_SESSION['agency_name'] = $resp->mesg->agency_name;
$_SESSION['profile'] = $resp->mesg->profile;
$_SESSION['metadata'] = $resp->mesg->metadata;
$_SESSION['show_archival'] = $resp->mesg->show_archival;
$_SESSION['show_live'] = $resp->mesg->show_live;
$_SESSION['show_sov'] = $resp->mesg->show_sov;
$_SESSION[$session_ID]['session_name'] = 'surewaves_agency_view';
header("Location: reach.php");exit;
}
} else {
$error = '1';
}
}
?>
// Here I am able fetch the correct data in '$resp' variable and also it is redirecting to reach.php
In reach.php , i have following code
<?php
include "session_config.php";
echo "<pre>";
print_r($_SESSION);exit;
?>
But in reach.php when I am fetching the session variables the session array is showing completely empty like this Array (). WHY?
I am using memcache for it and we are using ubuntu.
In My php.ini i have included following code..
extension = memcache.so;
session.save_handler = memcache
session.save_path = "http://localhost:11211"
I have also tried with "tcp ://localhost:11211" but nothing worked.
Try to remove the http:// part from session.save_path and replace localhost with 127.0.0.1:
session.save_path = "127.0.0.1:11211"
Take a look at the second example at http://br1.php.net/manual/en/memcache.examples-overview.php.

Adding a nav-selected to a dropdown menu for concrete5

I am trying to combine two things for a dropdown menu in Concrete5 and just can't seem to make it work and wonder if someone can help me.
I have a this code for the menu
<?
defined('C5_EXECUTE') or die(_("Access Denied."));
$aBlocks = $controller->generateNav();
global $c;
if ($c->isEditMode()) {
echo("<div class=\"menu\" style=\"position:inherit!important;\"><ul>");
}
else {
echo("<div class=\"menu\"><ul>");
}
$nh = Loader::helper('navigation');
foreach($aBlocks as $ni) {
$_c = $ni->getCollectionObject();
if (!$_c->getCollectionAttributeValue('exclude_nav')) {
$thisLevel = $ni->getLevel();
if ($thisLevel > $lastLevel) {
echo("<!--[if IE 7]><!--></a><!--<![endif]-->\n<!--[if lte IE 6]><table><tr><td><![endif]-->\n<ul>\n");
} else if ($thisLevel < $lastLevel) {
for ($j = $thisLevel; $j < $lastLevel; $j++) {
echo("</a></li>\n</ul>\n<!--[if lte IE 6]></td></tr></table></a><![endif]--></li>\n");
}
}
if ($thisLevel == $lastLevel && $i >0) {
echo "</a></li>\n";
}
$pageLink = false;
if ($_c->getCollectionAttributeValue('replace_link_with_first_in_nav')) {
$subPage = $_c->getFirstChild();
if ($subPage instanceof Page) {
$pageLink = $nh->getLinkToCollection($subPage);
}
}
if (!$pageLink) {
$pageLink = $ni->getURL();
}
if ($_c->getCollectionAttributeValue('placeholder')) {
$pageLink="javascript:void(0)";
}
echo '<li><a href="'.$pageLink.'">' . $ni->getName();
$lastLevel = $thisLevel;
$i++;
}
}
$thisLevel = 0;
for ($i = $thisLevel; $i <= $lastLevel; $i++) {
echo("</a></li></ul>");
}
echo '</div>';
?>
but haven't had any luck styling the nav-selected so I wanted to add under the line beginning foreach:
$classes = array();
if ($ni->isCurrent) {
//class for the page currently being viewed
$classes[] = 'nav-selected';
}
if ($ni->inPath) {
//class for parent items of the page currently being viewed
$classes[] = 'nav-path-selected';
}
from another menu where the nav-selected can be styled but that doesn't make a difference. Does anyone see what I am doing wrong or could someone give me a hint how to make this work? I would really appreciate the help. Thanks!
It appears as though you've taken code from two different places and pasted them together (which rarely works). I think your first code sample is from an old template, and the second code sample is from the newer one.
Your best bet here is to start from scratch with the newer, cleaner autonav template:
https://raw.github.com/concrete5/concrete5/master/web/concrete/blocks/autonav/view.php
It shouldn't be too difficult to modify that to do what you want. If you run into trouble with that, try posting as a new question, either here or in the concrete5 forums ( http://concrete5.org/community/forums ).

multi image upload in custom component for joomla

I have tried http://docs.joomla.org/Creating_a_file_uploader_in_your_component but first it shows Error: 500 after some research I have removed code
"'.$session->getName().'" : "'.$session->getId().'",
"format" : "raw"
and error is gone. Now Image is not uploading anywhere (I have set path '/images/' folder) I am confuse in code for uploading image PART 5 where to use this code?
function storeImageFile()
{
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder' );
$path = 'PATH_GOES_HERE'.'designs'.DS;
$folder_permissions = "0755";
$folder_permissions = octdec((int)$folder_permissions);
//create folder if not exists
if (!JFolder::exists($path)){
JFolder::create($path, $folder_permissions);
}
$file = JRequest::getVar('design_images', null, 'files',
$count = count($file['name']);
for($i=0;$i<$count;$i++)
{
//$i is the array position of the $_FILES array
if(empty($file['tmp_name'][$i]))
{
return false;
}
//Clean up filename to get rid of strange characters like spaces etc
$filename = JFile::makeSafe($file['name'][$i]);
//setting source and destination
$temporary_name = $file['tmp_name'][$i];
$filename = str_replace(' ', '_', $file['name'][$i]);
$dest = $path.$filename;
if(JFile::upload($temporary_name, $dest))
{
echo "File Upload Successful";
return true;
}
}
}

Get original image url Magento (1.6.1.0)

I have the following piece of code:
$cProduct = Mage::getModel("catalog/product");
foreach($products_id as $product_id) {
$product = $cProduct->load($product_id);
//$products_image[] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).str_replace(Mage::getBaseUrl('media'),"", $product);
//$products_image[] = $product->getMediaConfig()->getMediaUrl($_product->getData('image'));
$products_image[] = $product->getImageUrl(); //product's image url
}
As you can see, I've tried several ways to get the original image url. Currently I'm using getImageUrl(), but it retrieves the base image, which is a cropped version. How can I retrieve the original image??
Thanks in advance.
Edit:
Seriously appears there isn't a function for it, been Googling for hours straight (also before posting here). So I've written my own function.
function get_original_image_url($base_image_url) {
$exploded = explode("/", $base_image_url);
$image_name = $exploded[count($exploded) - 1];
$original_image_url = "http://yoursitehere.com/media/catalog/product/" . $image_name[0] . "/" .
$image_name[1] . "/" . $image_name;
return $original_image_url;
}
I call it with:
$original = get_original_image_url($product->getImageUrl());
Works for me, though it isn't a nice way to do it.
You should use the catalog product media config model for this purpose.
<?php
//your code ...
echo Mage::getModel('catalog/product_media_config')
->getMediaUrl( $product->getImage() ); //getSmallImage(), getThumbnail()
Hope this helps.
Other faster way:
$cProduct = Mage::getModel("catalog/product");
$baseUrl = Mage::getBaseUrl('media') . 'catalog/product/';
foreach($products_id as $product_id) {
$product = $cProduct->load($product_id);
$products_image[] = $baseUrl . $product->getImage();
}

Resources