SwiftlyTilting: usability, reusability

Thursday, February 10, 2011

An unexpected PHP quirk

The other day when I was doing work for a new client, I ran into a very strange error. I was configuring their Mediawiki site, but whenever I added code to the configuration file, it would cause a fatal error. Unfortunately the site’s error logs were not available to me. Initially I was baffled, though with some trial and error I was able to discover the problem. It was very minor and would have been discovered instantly if I had access to the error log, but it revealed an interesting quirk of the PHP engine, specifically: PHP does not require a closing semicolon at the end of the last line of the PHP script.

I was trying to add new configuration lines, and was baffled why any valid code except comments would cause an error. I eventually discovered that lines added at the top of the file worked correctly, and worked my way down the file to find which line was causing the error. Once I knew which line was causing the problem, the error was quite obvious, but until then, I had been baffled!

In a proper development environment where you have access to error logs, this will never be an issue, but when working “blind”, this is an unusual quirk that can cause some very unexpected and confusing results.

Thursday, October 14, 2010

Don’t close your PHP tags!

I saw this post over at sitepoint about whether or not you should close your PHP tags. Apparently there is some debate, though to me it seems pretty clear the choice is to leave them out.

If you’re unaware, the closing ?> tag in PHP files is completely optional. It is only really required if you are mixing HTML and PHP code, which itself is not a particularly good practice. Leaving off the closing tag prevents any erroneous white space or random characters from being sent to the output. It reduces the amount of code and prevents a possible error from occurring.

I can’t really think of a good reason to leave them on (assuming your document is pure PHP). Perhaps if you are from an XML background you will feel compelled to close the tag, but it’s entirely unnecessary in PHP.

Multiple frameworks and libraries such as Zend, CodeIgniter, Drupal and others suggest you to leave off the closing PHP tag as part of their style guide or best practices documentation, and I suggest the same. This is especially important for WinBinder developers (or anyone who uses php-win.exe), where any output sent to the console immediately ends the script.

Some have suggested dropping the need for <?php from php files completely. It’s not a bad suggestion, though i sort of think of it as analogous to #!/bin/sh in unix scripts. Those tags don’t need closing tags either.

So go out there and remove all those nasty ?> tags from your code ;)

WinBinder 2010.10.14 released - WinBinder is a PHP extension for making Windows Applications

I’m now “officially” maintaining WinBinder, so from now on you can get the latest version of WinBinder directly from Winbinder.org’s download page

Read my tutorial on getting started with WinBinder.
Visit the Winbinder Forums if you need more assistance

Changes since 2010.10.01

Added in 2010.10.14
* Fixed bug with return values for wb_sys_dlg_open when using wbc_multiselect
* Made 3rd and 4th parameters of wb_send_message optional

Added in 2010.10.13
* Additional flag parameter for wb_sys_dlg_open that accepts the option WBC_MULTISELECT. If this is enabled, all selected files will be returned as an array.

Sunday, October 3, 2010

Winter 2.2.1 Released - Winter is an Interpreted language for MediaWiki

Here is an update for Winter, the Wiki Interpreter.

Changes include
* added ^o and ^c escape characters
* added + to allowed characters in function names and functions
* added #reset_all_vars function
* added ++ and — functions
* fixed bug with #strpos and #substr returning false when it shouldn’t
* added #is_numeric, #is_int and #is_string functions
* fixed bug with array assignment
* other minor bug fixes

Winter Homepage on Mediawiki.org
Winter Documentation

Download Winter 2.2.1
Downloaded 2882 times

Saturday, October 2, 2010

New version of Winbinder, the PHP extension for making Windows Apps, released

New version of WinBinder… with some actual NEW FEATURES

Download WinBinder 2010.10.01
Downloaded 2320 times
Tutorial on getting started
Winbinder Forum

This is a list of all changes since 0.46.190.

  • PHP 5.3 compatible
  • Unicode support added
  • Removed version checking from wb_windows.inc.php
  • Fixed memory leak in winapi library calls
  • Fixed bug where maximize wasn’t triggering WBC_RESIZE
  • Fixed bug where closing child windows would kill main window
  • Added WBC_NOHEADER style for ListView to disable the listview column header
  • Added WBC_MULTISELECT style for ListBox to that you can select more than one item
  • Added WBC_DEFAULT style to PushButton to make them display as the default button
  • ListView will respond to right clicks and fire WBC_RBUTTON
  • Window callback will pass WBC_GETFOCUS as an event when the window is focused
  • Window callback will respond to WM_HOTKEY(windows message) (experimental)
    New functions for use with the low level Windows API. These functions return pointers to callback functions, which are needed by certain WinAPI functions. The callback functions will send windows messages to the main Winbinder callback function, which will then trigger your PHP based callback function(s).

    • wb_get_midi_callback returns a pointer to MidiOutProc (can also be used for MidiInProc, WaveInProc, WaveOutProc or any similar callback) for use with functions like midiOutOpen
    • wb_get_enum_callback returns pointer to EnumWindowProc
    • wb_get_hook_callback returns a pointer to HookProc for use with various hooks.[/list][/list]

Finally got the time to merge my changes with Winbinder 0.5.0.. thanks to Ermac and Alec for their contributions to that version.

C source is included in the ZIP

Tuesday, September 21, 2010

Stop the #twittervirus

This greasemonkey script will stop mouseovers

// ==UserScript==
// @name           Stop the #twittervirus
// @namespace      http://swiftlytilting.com/*
// @include        http://www.twitter.com/*
// @include        https://www.twitter.com/*
// @include        http://twitter.com/*
// @include        https://twitter.com/*
// @description    fix twitter
// ==/UserScript==

var links = document.getElementsByTagName("a");

   for (i = 0; i < links.length; i++) {
      var node = links[i];
      var tag = node.getAttribute("onmouseover");

      if (tag) {

            node.innerHTML = 'hack removed';

      }  // end if(tag)
   } // end for loop

Download No Twitter Virus
Downloaded 5353 times

edit: Twitter fixed itself so the script isn’t needed now, though might not be bad to leave it running in case any future bugs appear. Not sure how it will affect #newtwitter though.

Tuesday, August 3, 2010

MediawikiPlayer 0.2.4

This version fixes a bug where some variables were being written as parameters instead.

Mediawiki Extension Page: Extension:MediawikiPlayer
Original post: Embed JW FLV Media Player with Mediawiki using the MediawikiPlayer Extension

If you find MediawikiPlayer useful, please consider making a $5 donation.

Download MediawikiPlayer v0.2.4
Downloaded 2323 times

Thursday, July 1, 2010

MediawikiPlayer v0.2.3

This version fixes additional security issues for servers with register_globals enabled.

Local Wiki page: MediawikiPlayer
Mediawiki Extension Page: Extension:MediawikiPlayer
Original post: Embed JW FLV Media Player with Mediawiki using the MediawikiPlayer Extension

If you find MediawikiPlayer useful, please consider making a $5 donation.

Download MediawikiPlayer v0.2.3
Downloaded 2312 times

Sunday, June 20, 2010

MediawikiPlayer 0.2.2

This version fixes some security issues. All users are encouraged to upgrade

Local Wiki page: MediawikiPlayer
Mediawiki Extension Page: Extension:MediawikiPlayer
Original post: Embed JW FLV Media Player with Mediawiki using the MediawikiPlayer Extension

If you find MediawikiPlayer useful, please consider making a $5 donation.

Download MediawikiPlayer v0.2.2
Downloaded 2222 times

Thursday, June 10, 2010

MaintenanceShell 0.3.1

This version fixes a minor bug which caused a warning error to be displayed. This bug was introduced in 0.3.0

MaintenanceShell homepage on MediaWiki.org

Download MaintenanceShell v0.3.1
Downloaded 2320 times

Sunday, May 23, 2010

MaintenanceShell v0.3.0

This version fixes a major security issue with XSS and CSRF vulnerabilities. All users are encouraged to upgrade immediately.

MaintenanceShell homepage on MediaWiki.org

Download MaintenanceShell v0.3.0
Downloaded 2192 times

Thursday, May 13, 2010

cStruct and WinAPI: Classes for accessing the Windows API with PHP and WinBinder

One of the biggest roadblocks to writing code which accesses the Windows API is the fact that so many functions require you to provide data formatted in specific format. This format is defined on MSDN as a C struct, which has no direct representation in PHP. The best you can hope for is to figure out the layout of the structure, and then set up some PACK/UNPACK calls to convert the data to and from something more useful in PHP.

Enter cStruct, a collection of objects that helps provide support for C-like structures. All common data types have been implemented. This will save lots of time as you don’t have to remember or figure out how many bytes each datatype takes up and how to convert it to and from binary data.

Download cStruct.0.2.2
Downloaded 2068 times

Sunday, May 9, 2010

MaintenanceShell v0.2.4

This fixes a minor html issue with IE. Also includes the German language localization.

MaintenanceShell homepage on MediaWiki.org

Download MaintenanceShell v0.2.4
Downloaded 2238 times

Friday, May 7, 2010

Maintenance Shell v0.2.3 for Mediawiki

Fixed some minor bugs and also moved the text strings into the language file for better localization.

MaintenanceShell homepage on MediaWiki.org

Download MaintenanceShell v0.2.3
Downloaded 2109 times

Thursday, May 6, 2010

How to fix Google’s new layout

Google’s new layout reminds me too much of Bing.. I really preferred the old layout. Thanks to Nathan Caroyannis, we can use Greasemonkey to change the layout. Download the userscript here: http://userscripts.org/scripts/show/76060

I added my own changes as well

AddStyle("#leftnav {display:none}");
AddStyle("#center_col {margin-left:0}");
AddStyle("#foot div {display:none}")
AddStyle("#foot #navcnt, #foot #fll {display:block}")
AddStyle(".tsf-p table {border-bottom:0 !important}")
AddStyle("#cnt {max-width:1200px !important}")
AddStyle(".s { max-width: 90em !important}")
AddStyle(".lst {height:1.4em !important;font-size:1em}")
AddStyle("li.g{padding-top:.5em !important}")
AddStyle("#center_col, #foot { margin-right:0px}")
AddStyle("#rhs_block, #fll {display:none !important}")
AddStyle(".gbh {font-size:1em;margin-top:2em !important;top:0px}")
AddStyle("#foot {margin-bottom:1em}")

Friday, March 5, 2010

MediawikiPlayer v0.2.1

This version fixes a bug which prevented loading of files that were stored on the wiki.

Local Wiki page: MediawikiPlayer
Mediawiki Extension Page: Extension:MediawikiPlayer
Original post: Embed JW FLV Media Player with Mediawiki using the MediawikiPlayer Extension

If you find MediawikiPlayer useful, please consider making a small donation.

Download MediawikiPlayer v0.2.1
Downloaded 2569 times

Sunday, February 21, 2010

MediawikiPlayer Extension v0.2.0 released

This version includes an important security update for those who allow untrusted users to make edits to their wiki. Please update ASAP to prevent cross site scripting.

* Fixed XSS security risk.
* Added ability to load media directly from the wiki using File:medianame.ext shortcut
* Added ability to store various default configurations with $wgMWPlayerConfig

Original post: Embed JW FLV Media Player with Mediawiki using the MediawikiPlayer Extension

Download MediawikiPlayer v0.2.0
Downloaded 2594 times

Thursday, December 17, 2009

How to contact Swiftly Tilting

I specialize in PHP, with an emphasis on Mediawiki and other open source web applications such as Wordpress and phpBB. I am available to create custom applications, extensions and plug-ins as well as modify or trouble shoot existing PHP-based sites.

If you wish to contact me, please use the contact form.

You may also follow this site on Twitter: @Swiftly_Tilting

Thanks for your interest!

phc-win 0.3.1 - a PHP EXE compiler

The bugs in bcompiler seem to have been worked out since phc-win 0.3.0. Unlike 0.3.0, this release has the standard PHP DLLs (for PHP 5.3.1) and separate Winbinder, win32std and bcompiler DLLs. I’m hoping to be able to get a smaller DLL with all of the required extensions going, but for now this is better than the buggy bcompiler version.

If you find php-win useful, please consider making a small donation.

View the phc-win documentation.

Download phc-win 0.3.1
Downloaded 5168 times

Note to XP users:
You may need to install the Microsoft Visual C++ 2008 Redistributable Package (x86) for EXEs to run correctly.

Note to Windows 2000, 9x Users
Due to a change in 5.3.x series of PHP, phc-win does not work on Windows 2000 or 9x machines. There are no plans to compile a 5.2.x series binary for phc-win. If you cannot upgrade your OS, I recommend using phc-win 0.2.1 which uses PHP 5.0.5.

Check the phc-win category for the latest version.

Wednesday, December 16, 2009

phc-win 0.3.0 - a PHP EXE compiler - compatible with PHP 5.3.1

It’s been quite a while since phc-win was updated due to the difficulty of getting all of the extensions compiled and running with each new version of PHP. Finally I got WinBinder compiled with PHP 5.3.1, and Alec Gorge helped out and compiled some lightweight DLL files to use with phc-win.

The good:
* PHP 5.3.1 compatible
* Program EXEs need only 1 DLL file and no other files to run correctly (if using one of the Alec Gorge compiled DLLs)
* Included DLL is only 2.44 megs

The bad:
* it seems bcompiler has changed since the last update of phc-win. Unfortunately it has introduced an error which causes programs to crash if your PHP code uses constants as default function parameter values. IE function foo ($bar = CONSTANT_VALUE) will cause the a program crash. Other problems may also exist with bcompiler. Because of this I may need to make the bcompilation stage optional.

UPDATE: Bug reports have been submitted to the bcompiler team and they are working on it, so hopefully there will be a resolution to this issue. Update 2: phc-win 0.3.1 is packaged with updated bcompiler dlls.

This version of phc-win has no actual functionality changes from 0.2.1 besides minor tweaks to get things working with php5.3 and working around the bcompiler issues.

If you find php-win useful, please consider making a small donation.

Download phc-win 0.3.0
Downloaded 2743 times

For the latest version, check the phc-win category.

Monday, November 2, 2009

AdBlock for FireFox 3

AdBlock is the percursor to AdBlock Plus, one of the most popular add-ons for Firefox. Some users, including myself, find AdBlock Plus too bloated and prefer the older AdBlock. This add-on is no longer in the Mozilla database, but is available on download.com and other sites. Unfortunately the default file does not install in Firefox 3.0 or later. A simple modification of the add-on will allow you to use it with FireFox 3.0 and later, so I have modified the add-on and placed it here for download.

This add-on seems to cause issues with some Flash-based sites. AdBlock Plus does not exhibit these issues.

Download AdBlock for FireFox 3
Downloaded 6049 times

Monday, September 7, 2009

SwiftlyTilting Wiki (re)Launches!

The wiki at SwiftlyTilting.com has received a face lift. I’ve also added documentation for all of my MediaWiki extensions, and there is a new sandbox area for users to try out Winter and my other extensions as well.


Sunday, August 9, 2009

CustomSidebar v0.3.0 - Mediawiki Extension

This update adds full template support as well as the ability to add sidebars based on user group and namespace.

CustomSidebar Homepage on MediaWiki.org

Download CustomSidebar 0.3.0
Downloaded 6849 times

Friday, July 31, 2009

Embed JW FLV Media Player with Mediawiki using the MediawikiPlayer Extension

According to JW, “The JW FLV Player is the Internet’s most popular and flexible media player.” With the MediawikiPlayer Extension, one can easily include the JW FLV Media Player into wiki pages. JW FLV Player supports

  • FLV
  • MP4 (H264/AAC)
  • MP3
  • Youtube
  • Various streaming servers
  • Various XML playlists

Documentation available at the MediawikiPlayer homepage on MediaWiki.org

Download MediawikiPlayer v0.2.0
Downloaded 2594 times

Download MediawikiPlayer v0.1.0
Downloaded 2647 times

Friday, June 19, 2009

Maintenance Shell MediaWiki Extension v0.2.2

This update for Extension:MaintenanceShell adds quote mark support for the command line.

Download MaintenanceShell v0.2.2
Downloaded 2396 times

Validate XHTML | Word Press