Wikipedia is a nice open source project. However it may incur a lot of hackers' interests if it is open for edit. Hackers may register large number of spam accounts, create new pages and modify existing pages. This is what's happening to a wikipedia I'm managing right now.
Although quite straightforward, I keep log of these management tips of wikipedia.
The default settings are in wiki/includes/DefaultSettings.php. But changes to settings can be made in wiki/LocalSettings.php, the changes here will override default settings.
1) To change logo, change this line:
$wgLogo = "$wgStylePath/common/images/wiki.png";
2) To disable anonymous user (not logged in) creating new page and editing, add this to the end of LocalSettings:
#
# See: http://www.mediawiki.org/wiki/Manual:User_rights
#
#
# not-logged-in user
#
$wgGroupPermissions['*']['createaccount'] = false; # no new user registration.
//$wgGroupPermissions['*']['read'] = true; # default is true, so no need to add this statement.
$wgGroupPermissions['*']['edit'] = false;
$wgGroupPermissions['*']['createpage'] = false;
#
# logged-in user.
# Add this if you want to disable logged-in users from createpage/edit actions.
#
#$wgGroupPermissions['user']['edit'] = false;
#$wgGroupPermissions['user']['createpage'] = false; // true;
#
# sysop
# If you disabled logged-in users actions, you may want to enable sysop's permission here.
#
#$wgGroupPermissions['sysop']['edit'] = true;
#$wgGroupPermissions['sysop']['createpage'] = true;
After you disabled new user's createaccount ability, you will want to manually create new accounts. You can do this by logging in as sysop, and going to "Special pages -> Login / create account".
3) Email setting. Use $wgSMTP to change email setting: either use Pear Mail or PHP Mail.
Refer to the last post "Fix Bluehost wikipedia email problem".
Tuesday, November 4, 2014
Fix Bluehost wikipedia email problem
I'm managing a website hosted by Bluehost.com.
From CPanel I installed wikipedia. However the email function does not work. It says: "bluehost Mailer returned: Failed to add recipient: [email] … Mailer returned: Unknown error in PHP's mail() function."
I followed instruction at http://www.mediawiki.org/wiki/Manual:$wgSMTP to add email SMTP setting to wiki/LocalSettings.php:
Still it does not work. I followed Bluehost's email setting page, use either SSL/TLS setting or non-SSL setting. Still it fails.
Finally I tried to find out where $wgSMTP is used: grep -i wgSMTH */*, and found it being used in /wiki/includes/UserMailer.php. It comes down to the function send(). When $wgSMTP is used, it uses Pear Mail; otherwise, it uses PHP Mail. Since I'm using PHP Mail in a personal project on the same server, I tried to check what's different it uses PHP Mail from my use. On line 359 of UserMailer.php, it has this code:
I print out $headers, it is:
From: CareerAssist Wiki Return-Path: apache@www.careerassist.org Date: Tue, 04 Nov 2014 04:41:29 -0700 Message-ID: X-Mailer: MediaWiki mailer MIME-Version: 1.0 Content-type: text/plain; charset=UTF-8 Content-transfer-encoding: 8bit
Since I'm using the PHP's mail() function in a personal project on the same server and it works well, where I simply use: $headers = "From: [email]";
So I replace the $headers here with this simpler rendition:
Then it works! This also shows it takes the 2nd path here ($safeMode is false).
Thus I got wikipedia email working on Bluehost, with this hack into wikipedia's source code.
From CPanel I installed wikipedia. However the email function does not work. It says: "bluehost Mailer returned: Failed to add recipient: [email] … Mailer returned: Unknown error in PHP's mail() function."
I followed instruction at http://www.mediawiki.org/wiki/Manual:$wgSMTP to add email SMTP setting to wiki/LocalSettings.php:
$wgSMTP = array( 'host' => "mail.example.com", 'IDHost' => "example.com", 'port' => 26, 'auth' => true, 'username' => "my_user_name", 'password' => "my_password" );
Still it does not work. I followed Bluehost's email setting page, use either SSL/TLS setting or non-SSL setting. Still it fails.
Finally I tried to find out where $wgSMTP is used: grep -i wgSMTH */*, and found it being used in /wiki/includes/UserMailer.php. It comes down to the function send(). When $wgSMTP is used, it uses Pear Mail; otherwise, it uses PHP Mail. Since I'm using PHP Mail in a personal project on the same server, I tried to check what's different it uses PHP Mail from my use. On line 359 of UserMailer.php, it has this code:
foreach ( $to as $recip ) {
if ( $safeMode ) {
$sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers );
} else {
$sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
}
}I print out $headers, it is:
From: CareerAssist Wiki Return-Path: apache@www.careerassist.org Date: Tue, 04 Nov 2014 04:41:29 -0700 Message-ID: X-Mailer: MediaWiki mailer MIME-Version: 1.0 Content-type: text/plain; charset=UTF-8 Content-transfer-encoding: 8bit
Since I'm using the PHP's mail() function in a personal project on the same server and it works well, where I simply use: $headers = "From: [email]";
So I replace the $headers here with this simpler rendition:
foreach ( $to as $recip ) {
if ( $safeMode ) {
$sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers );
} else {
$headers = "From: [email]";
$sent = mail( $recip, self::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
}
}Then it works! This also shows it takes the 2nd path here ($safeMode is false).
Thus I got wikipedia email working on Bluehost, with this hack into wikipedia's source code.
Saturday, October 25, 2014
Mysql - myisam and innodb
Major differences:
innodb: supports referential integrity (foreign key), transaction.
myisam does not support these 2.
In more details [1]:
innodb: supports referential integrity (foreign key), transaction.
myisam does not support these 2.
In more details [1]:
MYISAM:
INNODB:
- MYISAM supports Table-level Locking
- MyISAM designed for need of speed
- MyISAM does not support foreign keys hence we call MySQL with MYISAM is DBMS
- MyISAM stores its tables, data and indexes in diskspace using separate three different files. (tablename.FRM, tablename.MYD, tablename.MYI)
- MYISAM not supports transaction. You cannot commit and rollback with MYISAM. Once you issue a command it’s done.
- MYISAM supports fulltext search
- You can use MyISAM, if the table is more static with lots of select and less update and delete.
INNODB:
- InnoDB supports Row-level Locking
- InnoDB designed for maximum performance when processing high volume of data
- InnoDB support foreign keys hence we call MySQL with InnoDB is RDBMS
- InnoDB stores its tables and indexes in a tablespace
- InnoDB supports transaction. You can commit and rollback with InnoDB
Tuesday, October 21, 2014
jQuery 1.8 update on ajax call
jQuery ajax call uses different syntax since version 1.8 [1].
Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are deprecated as of jQuery 1.8 (but still works in 1.9.1). To prepare your code for their eventual removal, use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.
Get html in jQuery before 1.8:
$.ajax({
url: 'test.html',
dataType: 'html',
success: function (data, textStatus, xhr)
{
console.log(data);
},
error: function (xhr, textStatus, errorThrown)
{
console.log('error: '+textStatus);
}
});
The code above still works in 1.8. But the code below no longer works in 1.8:
$.post("get_news.php", { id: id }, function(data, status) {
if (status == "success") {
if ( data != '' ) {
o.innerHTML = data;
}
return 1;
} else {
return 1; // ok
}
}, 5);
Get html in jQuery since 1.8:
// cache: false is used to fetch the latest version
$.ajax({
type: 'POST',
url: "test.html",
data: { id: id },
dataType: 'html',
cache: false
})
.done(function(data, textStatus, jqXHR)
{
console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown)
{
console.log('error: '+textStatus);
});
[1] http://www.sitepoint.com/ajax-jquery-1-8/
Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are deprecated as of jQuery 1.8 (but still works in 1.9.1). To prepare your code for their eventual removal, use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.
Get html in jQuery before 1.8:
$.ajax({
url: 'test.html',
dataType: 'html',
success: function (data, textStatus, xhr)
{
console.log(data);
},
error: function (xhr, textStatus, errorThrown)
{
console.log('error: '+textStatus);
}
});
The code above still works in 1.8. But the code below no longer works in 1.8:
$.post("get_news.php", { id: id }, function(data, status) {
if (status == "success") {
if ( data != '' ) {
o.innerHTML = data;
}
return 1;
} else {
return 1; // ok
}
}, 5);
Get html in jQuery since 1.8:
// cache: false is used to fetch the latest version
$.ajax({
type: 'POST',
url: "test.html",
data: { id: id },
dataType: 'html',
cache: false
})
.done(function(data, textStatus, jqXHR)
{
console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown)
{
console.log('error: '+textStatus);
});
[1] http://www.sitepoint.com/ajax-jquery-1-8/
Wednesday, October 15, 2014
Nginx v.s. Apache
[1] Blog: Nginx v.s. Apache (May 14th, 2014)
Apache - spawns a new process for each request. In pre-forked mode, each process contains one thread; in worker Multi-process mode (not thread safe), each process contains multiple thread. Apache is process-driven.
Nginx - creates a fixed number of processes at start (a rule of thumb is 1 process each CPU), each process is single-threaded. Each request is handled by a thread. Each thread can handle thousands of requests in sequence. Nginx is event-driven, asynchronous and non-blocking.
Nginx can process php natively. But it does not support Python/Ruby etc. Nginx is much faster in serving static contents. A common configuration is use Nginx as proxy server in front of Apache back end server.
[2] http://www.thegeekstuff.com/2013/11/nginx-vs-apache/
Nginx v.s. Apache:
[3] http://www.wikivs.com/wiki/Apache_vs_nginx
Apache is like Microsoft Word, it has a million options but you only need six. Nginx does those six things, and it does five of them 50 times faster than Apache.
[4] Install Nginx: http://www.thegeekstuff.com/2011/07/install-nginx-from-source/
Summary of installation steps:
- download source code from: here. Or:
- Install Nginx:
./configure --help
./configure
make
make install
Note: if in the step of "./configure" you get a complaint that pcre is not available, then you can either install pcre, or do: "./configure –-without-http_rewrite_module"
- Change default listening port
After this you can query the nginx processes:
Get version:
Read logs:
- Stop Nginx server:
Apache - spawns a new process for each request. In pre-forked mode, each process contains one thread; in worker Multi-process mode (not thread safe), each process contains multiple thread. Apache is process-driven.
Nginx - creates a fixed number of processes at start (a rule of thumb is 1 process each CPU), each process is single-threaded. Each request is handled by a thread. Each thread can handle thousands of requests in sequence. Nginx is event-driven, asynchronous and non-blocking.
Nginx can process php natively. But it does not support Python/Ruby etc. Nginx is much faster in serving static contents. A common configuration is use Nginx as proxy server in front of Apache back end server.
[2] http://www.thegeekstuff.com/2013/11/nginx-vs-apache/
Nginx v.s. Apache:
- As discussed above Nginx is based on event-driven architecture. Apache is based on process-driven architecture. It is interesting to note that Apache in its earliest release was not having multitasking architecture. Later Apache MPM (multi-processing module) was added to achieve this.
- Nginx doesn’t create a new process for a new request. Apache creates a new process for each request.
- In Nginx, memory consumption is very low for serving static pages. But, Apache’s nature of creating new process for each request increases the memory consumption.
- Several benchmarking results indicates that when compared to Apache, Nginx is extremely fast for serving static pages.
- Nginx development started only in 2002. But Apache initial release was in 1995.
- In complex configurations situation, when compared to Nginx, Apache can be configured easily as it comes with lot of configuration features to cover wide range of requirements.
- When compared to Nginx, Apache has excellent documentation.
- In general, Nginx have less components to add more features. But Apache has tons of features and provides lot more functionality than Nginx.
- Nginx do not support Operating Systems like OpenVMS and IBMi. But Apache supports much wider range of Operating Systems.
- Since Nginx comes only with core features that are required for a web server, it is lightweight when compared to Apache.
- The performance and scalability of Nginx is not completely dependent on hardware resources, whereas the performance and scalability of the Apache is dependent on underlying hardware resources like memory and CPU.
[3] http://www.wikivs.com/wiki/Apache_vs_nginx
Apache is like Microsoft Word, it has a million options but you only need six. Nginx does those six things, and it does five of them 50 times faster than Apache.
[4] Install Nginx: http://www.thegeekstuff.com/2011/07/install-nginx-from-source/
Summary of installation steps:
- download source code from: here. Or:
cd wget http://nginx.org/download/nginx-1.0.5.tar.gz tar xvfz nginx-1.0.5.tar.gz cd nginx-1.0.5
- Install Nginx:
./configure --help
./configure
make
make install
Note: if in the step of "./configure" you get a complaint that pcre is not available, then you can either install pcre, or do: "./configure –-without-http_rewrite_module"
- Change default listening port
# vi /usr/local/nginx/conf/nginx.conf
server {
listen 8081;
server_name localhost;
- Start Nginx server:
cd /usr/local/nginx/sbin
./nginx
After this you can query the nginx processes:
# ps -ef | grep -i nginx root 18596 13:16 nginx: master process ./nginx nobody 18597 13:16 nginx: worker process
Get version:
# ./nginx -v nginx: nginx version: nginx/1.0.5
Read logs:
# ls /usr/local/nginx/logs/ access.log error.log nginx.pid
- Stop Nginx server:
cd /usr/local/nginx/sbin ./nginx -s stop
Friday, October 10, 2014
CSS Box Shadow
CSS Box Shadow
Basically you use this css:
div {
box-shadow: 0px 20px 15px -15px rgba(0,0,0,0.49), /* bottom */
10px 0px 15px -15px rgba(0,0,0,0.49), /* right */
-10px 0px 15px -15px rgba(0,0,0,0.49); /* left */
-webkit-box-shadow: 0px 20px 15px -15px rgba(0, 0, 0, 0.49),
10px 0px 15px -15px rgba(0,0,0,0.49),
-10px 0px 15px -15px rgba(0,0,0,0.49);
}
The 5 parameters are:
1. The horizontal offset of the shadow, positive means the shadow will be on the right of the box, a negative offset will put the shadow on the left of the box.
2. The vertical offset of the shadow, a negative one means the box-shadow will be above the box, a positive one means the shadow will be below the box.
3. The blur radius (optional), if set to 0 the shadow will be sharp, the higher the number, the more blurred it will be.
4. The spread radius (optional), positive values increase the size of the shadow, negative values decrease the size. Default is 0 (the shadow is same size as blur).
5. Color
Basically you use this css:
div {
box-shadow: 0px 20px 15px -15px rgba(0,0,0,0.49), /* bottom */
10px 0px 15px -15px rgba(0,0,0,0.49), /* right */
-10px 0px 15px -15px rgba(0,0,0,0.49); /* left */
-webkit-box-shadow: 0px 20px 15px -15px rgba(0, 0, 0, 0.49),
10px 0px 15px -15px rgba(0,0,0,0.49),
-10px 0px 15px -15px rgba(0,0,0,0.49);
}
The 5 parameters are:
1. The horizontal offset of the shadow, positive means the shadow will be on the right of the box, a negative offset will put the shadow on the left of the box.
2. The vertical offset of the shadow, a negative one means the box-shadow will be above the box, a positive one means the shadow will be below the box.
3. The blur radius (optional), if set to 0 the shadow will be sharp, the higher the number, the more blurred it will be.
4. The spread radius (optional), positive values increase the size of the shadow, negative values decrease the size. Default is 0 (the shadow is same size as blur).
5. Color
Wednesday, September 10, 2014
Subscribe to:
Posts (Atom)
Blog Archive
-
▼
2026
(36)
-
▼
June
(19)
- C10K to C10M: from thread-per-connection model to ...
- Benchmark server performance
- Application server for php, python, java, node.js,...
- Application server for C++, Go and Rust
- Nginx as reverse proxy and load balancer
- Infrastructure running: nginx, apache, php, python...
- Flow chart of nginx+apache+uvcorn infrastructure
- Flow chart of apache+uvcorn infrastructure
- Uvicorn and Gunicorn
- What's deadsnakes PPA
- What's the optional lsb-core package
- Codex known logging bug
- Daemonsize a service
- Train text to image model, to generate images of c...
- Train a model based on OpenAI API
- Open port 8080 for WebSocket
- Add websocket support on Bluehost Ubuntu VPS for D...
- Install Claude Code on ubuntu VPS of Bluehost
- Install PostgreSQL on Mac
-
▼
June
(19)