Extension talk:CategorySubscriptions

From mediawiki.org
Latest comment: 8 years ago by Ckoerner in topic Google Code Shutting Down


Feel free to list bugs and issues you may fine. I will be monitoring this discussion page on a weekly basis. I can also be reached via email (myatzkan at gmail.com).

Issues/Bugs[edit]

NameSpaces not showing up in links.[edit]

This appears to have a problem with namespaces. It does not include them in the link it sends. --Johnp125 20:27, 10 March 2010 (UTC)Reply


On my mw 1.11.0, it appears that the table name category_subscriptions must be prefaced with $wgDBprefix

--The php mailer script does not run inside the mw engine, thus it cannot access the $wg variables. I am not a database and php expert, but my script runs just fine on both windows and unix machines. In the script the database host and name is defined then the link is created. This is all specific to mysql. If you are using a different database vendor then the script will need to be modified.

I did just update the code online. There was a small bug with how the email to and from fields are created. I had left a variable in that shouldn't have been there and that was causing a php error to occur. That would have caused you a mysql error as it was trying to find a column in a sql result set that didn't exist.

Try using the new code I just published. Maybe it will fix the error you are having.


It is not the mail script, it is CategorySubscriptions.php causing the exception in the SQL select invocation. Still happens with the new code unless one renames the table with the DBprefix which in my case is the installation default mw:


Database error
A database query syntax error has occurred. This may indicate a bug in the software. The last attempted database query was:

(SQL query hidden)

from within function "Database::select". MySQL returned error "1146: Table 'wikidb.mwcategory_subscriptions' doesn't exist (localhost)".

--Bob 02:40, 28 January 2008 (UTC)Reply

Whenever you created the table in the database, did you modify the SQL code provided to include your database prefix? I just created another wiki installation using a dbprefix of 'mw' and changed the SQL code to "CREATE TABLE mwcategory_subscriptions" and all works fine for me (this is on MW 1.10). The PHP code should not need modified, because it is using the mediawiki database accessors and will automatically use whatever prefix is defined. Please make sure that the actual table created has your prefix in the table name. Because the table is manually created the prefix needs to be manually inserted.

This does, however, expose a design flaw in the mailer script that I will need fix - the mailer script does not provide any method to tell it the wiki database prefix. I will edit the code so that there is a variable at the top of the script that allows one to define the db prefix, which will then be concatinated to all db table calls throughout the script. I should have that done today (hopefully).

I hope this helps and that I am understanding the issue correctly. If you could, please double check the database name in the mean time and let me know if that solves your problem. I will try to have an updated mailer script posted today. I need to figure out how to get files uploaded to cvs on here, if anyone reading can point me in the right direction that would be helpful :) Thanks. --Mike 8 February 2008

Bug Fixes[edit]

Fixed a bug in how the mailer script gets the user's email address and sets them to the $to and $from variables. A variable was left in place which was trying to access a column in a sql result set that didn't exist, which throws an error.


8 February 2008 Update

Several design issues have been addressed:

  • Added ability to set a database prefix. A new variable $DATABASE_PREFIX is defined near the top of the script - this is where the prefix is defined, if one exists for your wiki.
  • Added ability to set the wiki url. I accidentally left my hardcoded url address. Please disregard that and update to the new code. The variable $WIKI_URL is where you can now define your url to your wiki. This will make the links in the emails point to your wiki.

headers already sent error[edit]

Several instances of

Warning: Cannot modify header information - headers already sent by (output started at /var/www/wiki/mediawiki-1.11.0/extensions/CategorySubscriptions/CategorySubscriptions.php:373) in /var/www/wiki/mediawiki-1.11.0/includes/WebResponse.php on line 10

are thrown onto each page using code from Jan 27 --Bob 03:08, 28 January 2008 (UTC)Reply


Just want to make sure, do you have any extra spaces or lines before the first '<?' and after the last '?>'? Extra lines and spaces can cause errors when MW parses the script. Other than that I am a bit stumped. I am a little stumped on this, but will keep looking for a cause. Thanks. --Mike 2.8.2008

enhancement: directmailer.php[edit]

After installing this extension I realised that a cron job is necessary to run the emailing periodically. This is not what I wanted. I just wanted to see the immediate result. Therefore I added an enhancement to this extension that sends out the email right away. It's not perfect, but it works. In order to use it you need to install the extension and the directmailer.php, too:

<?php
/**
* Direct Mailer 1.0
* This MediaWiki extension sends an email about subscripted categories right away
*
* Copyright (c) Mimberg, 2009, Kurt Wagner <elch71@chefmail.de>
* Distributed under GNU General Public License 2.0 or later (http://www.gnu.org/copyleft/gpl.html)
*/

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

#URL For your wiki
#Enter the url for your wiki, maybe it is not necessary, then leave it empty ("").
#
#If you do not use short-urls, you must enter the url like this:
#"http://www.yourdomain.com/wiki/index.php?title="
#
#If short-urls are used, you must append a trailing slash to the end of the url, like such:
#"http://www.yourdomain.com/wiki/"
$WIKI_URL = "http://www.yourdomain.com/wiki/index.php?title=";

#By default, email is sent from the email address of the loggin-user
#Enter here the user-id for emails for anon users
$EMAIL_FROM = '';

#change subject if desired
$EMAIL_SUBJECT = "Your category subscriptions";

/*
future enhancement:
$wgHooks['ArticleDeleteComplete'][] = 'CategorySubscriptionsDelete';
*/
$wgHooks['ArticleSaveComplete'][] = 'CategorySubscriptionsChange';

function CategorySubscriptionsChange(&$article, &$user, &$text, &$summary, &$minoredit, &$watchthis, &$sectionanchor, &$flags, $revision)
{ global $WIKI_URL, $EMAIL_FROM, $EMAIL_SUBJECT;
global $wgOut, $wgUser, $wgDBprefix;

$myID=$article->getID();
	#slave database handle
	$dbr =& wfGetDB( DB_SLAVE );

	#get new pages
        $result = $dbr->select(array('category_subscriptions', 
                                     'categorylinks', 
                                     'user', 
                                     'page'), 
                               array('cl_to', 
                                     'user_email', 
                                     'user_email', 
                                     'page_title', 
                                     'page_is_new', 
                                     'page_namespace'), 
                               array($wgDBprefix."category_subscriptions.category = ".$wgDBprefix."categorylinks.cl_to", 
                                     $wgDBprefix."category_subscriptions.user_id = ".$wgDBprefix."user.user_id",
                                     "cl_from = page_id",
                                     "cl_from = ".$article->getID() ));
	while($row = $result->fetchRow() )
	{
        #new pages
        if (  $row["page_is_new"] == '0' ) {
                $email_body = "A page of the subscribed category ".$row["cl_to"]." was changed:\n";
        } else {
                $email_body = "A new page has been added to the subscribed category ".$row["cl_to"].":\n";
        }
        $url = $article->mTitle->getFullURL( 'redirect=no' );
        $email_body .=$WIKI_URL.$url."\n";

	#Send the email
	$to = new MailAddress( $row["user_email"] );
	if( $wgUser->isLoggedIn() ) {
		if( User::isValidEmailAddr( $wgUser->getEmail() ) ) {
                        $from = new MailAddress( $wgUser->getEmail() );
		} else {
			$wgOut->addWikiMsg( 'confirmemail_noemail' );
		}
	}
        else {
                $from = new MailAddress( $EMAIL_FROM );
        }
	$subject = $EMAIL_SUBJECT;
	$replyTo = null;
	if ( wfRunHooks( 'EmailUser', array( &$to, &$from, &$subject, &$email_body ) ) ) {
		$mailResult = UserMailer::send( $to, $from, $subject, $email_body, $replyTo );
		if( WikiError::isError( $mailResult ) ) {
			$wgOut->addHTML( wfMsg( "usermailererror" ) .
				' ' . htmlspecialchars( $mailResult->getMessage() ) );
		}
        }

	}

    return true;
}

?>


Installation:

  • copy the source statements above to a source file in your extension library (e.g. directmailer.php)
  • add following statements to your LocalSettings.php:
require_once("extensions/DirectMailer.php");
  • fin.

K.W. 84.149.248.31 19:58, 15 March 2009 (UTC)Reply
update March 12th,2010: URL with Namespace; DB-Select with DB prefix

Google Code Shutting Down[edit]

Hello, As you are likely aware, Google is shutting down their Google Code service in January of 2016. This extension appears to house its code with Google Code and is at risk to creating broken links and confusion of users in the near future.

I’m helping to let folks know about this coming update and provide some helpful links to make this migration easy. I hope you’ll take a moment and migrate your extension to a new hosting solution.

For extensions that have a compatible license, you can request developer access to the MediaWiki source repositories for extensions and get a new repository created for you. Alternatively, you may also export your code to other popular repositories such as Github and Bitbucket. Google has provided tools to help with this migration.

Ckoerner (talk) 17:15, 7 July 2015 (UTC)Reply