Index

This is the tools index.

Source code (hide)

globals.php

back to toc
<?php
/****************************
**** global config    *******
****************************/
/* error reporting */
ini_set('display_errors'1);
error_reporting(E_ALL & ~E_NOTICE);

/* URLs */
$globals['urls']['server']     = 'http://jpwillard.com/';
$globals['urls']['tools']      = $globals['urls']['server'] . 'tools/';
$globals['urls']['globals']    = $globals['urls']['tools']  . 'globals/';
$globals['urls']['toolserver'] = 'http://toolserver.org/~pathoschild/';

/* navigation */
// format: $nav[menu title]
// values = array(name,description,path override)
$nav = array(
    
'navigation' => array(
        array(
'tools','tools index',$globals['urls']['server']),
        
#array('blog','personal blog',$globals['urls']['server']),
        #array('wiki','personal wiki',$globals['urls']['server'])
    
),
    
'lists' => array(
        array(
'set operations''perform set operations on two lists.'),
        array(
'sort''sort an input list.'),
        array(
'increment','increment numbers and repeat text with $new and $last magic words.'),
        array(
'timecount','calculate time elapsed in multiple time ranges.')
    ),
    
'strings' => array(
        array(
'regex','perform regex search and replace'),
        array(
'etymology reader','convert etymology shorthand into legible text.'),
        array(
'line numbers','add line numbers to text for proofreading.'),
        array(
'poem formatting','convert HTML and wikiML formatting to &lt;poem&gt; formatting.')
    ),
    
'databases' => array(
        array(
'iso639db','search ISO 639 codes.')
    ),
    
'Wikimedia' => array(
        array(
'accountEligibility''analyze an account to determine whether it is eligible to vote in a given event.',$globals['urls']['toolserver']),
        array(
'catanalysis','analyze edits to pages in a category tree or with a prefix over time.'$globals['urls']['toolserver']),
        array(
'crossBlock','lists block status on all Wikimedia wikis, with links to prefilled (un)block forms.'$globals['urls']['toolserver']),
        array(
'crossActivity','measures a user\'s latest edit, bureaucrat, or sysop activity on all wikis.'$globals['urls']['toolserver']),
        array(
'globalGroups','Lists rights with descriptions for each global group.'$globals['urls']['toolserver']),
        array(
'stewardry','analyze bureaucrat activity on a Wikimedia wiki.',$globals['urls']['toolserver']),
        array(
'wmelections','analyze votes in the 2008 Wikimedia Board elections.'),
    ),
    
'other' => array(
        array(
'pgkbot','IRC-based wiki monitoring bot'),
        array(
'redirspecial','Redirects to a Wikimedia special page with parsed arguments.',$globals['urls']['toolserver']),
        array(
'wikilink action table','create links to pre-filled delete or move forms from wikilinks.'),
    )
);

/* default licensing */
$globals['license']  = 'This tool is written and copyright by Jesse Plamondon-Willard (<a href="http://meta.wikimedia.org/wiki/User:Pathoschild" title="Pathoschild\'s wiki userpage">Pathoschild</a>). You may freely use, distribute, and modify this script in any way and for any purpose, so long as you cite the above name as original author.';

/****************************
**** $locals autoconfig *****
****************************/
/* action */
switch($_REQUEST['action']) {
    case 
'debug':
        
$locals['action'] = 'debug';
        break;
    case 
'source':
        
$locals['action'] = 'source';
        break;
    default:
        if(
$_REQUEST['debug']=='on')
            
$locals['action'] = 'debug';
        else
            
$locals['action'] = 'script';
}

/* URLs */
if(!$locals['path']) {
    
$locals['path'] = $globals['urls']['tools'] . gUrlTitle($locals['title']);
}
else if(
$locals['title'] != 'Index') {
    
$locals['path'] .= gUrlTitle($locals['title']);
}

/****************************
**** global functions *******
****************************/
/* script titles to URL format */
function gUrlTitle($title) {
    return 
strtolower(str_replace(' ','',$title));
}

/* debug */
// display debug option in forms
function gDebugOption() {
    global 
$locals;
    echo 
'<input type="checkbox" name="debug" id="debug"',
         ((
$locals['action']=='debug')?' checked="checked"':''),
         
' /> <label for="debug">show debug output</label><br />',
         
"\n";
}

// parse and display debug info
// note: gDebug(get_defined_vars()); should appear in script code somewhere after variables are defined
function gDebug($vars) {
    global 
$locals;
    if(
$locals['action']=='debug') {
        
// strip most PHP globals
        
unset($vars['GLOBALS'], $vars['_ENV'], $vars['HTTP_ENV_VARS'], $vars['HTTP_POST_VARS'], $vars['HTTP_GET_VARS'], $vars['HTTP_COOKIE_VARS'], $vars['_SERVER'], $vars['HTTP_SERVER_VARS'], $vars['HTTP_POST_FILES']);
        
        
// strip framework globals 
        
unset($vars['nav']);
        
        
// output 
        
echo '<h2>Debug (<a href="'$locals['path'], '" title="hide debug">hide</a>)</h2>'"\n",
             
'<pre>'htmlspecialchars(print_r($vars,true)), '</pre>';
    }
}

/* forms */
// check selected boxes
function gCheckBox($variable$default=0) {
    if((!isset(
$variable) && $default==true) || $variable)
        echo 
'checked="checked"';
}

// check selected radio buttons
function gCheckRadio($variable,$value) {
    if(
$variable==$value) {
        echo 
'checked="checked"';
    }
}

// select drop-down option
function gSelect($variable,$value,$isdefault=false) {
    if(
$variable==$value or (!$variable && $isdefault)) {
        echo 
' selected="selected"';
    }
}

/* generic */
// generate a table of contents
function gen_toc($ids$names) {
    echo 
'<div id="toc"><b>Table of contents</b><ol>';
    
    
$count count($ids);
    for(
$i=0$i<$count$i++) {
        echo 
'<li><a href="#'$ids[$i], '">'$names[$i], '</a></li>';
    }
    echo 
'</ol></div>';
}

/****************************
**** Build top of document **
****************************/
?>
<!-- begin generated header -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title><?php echo $locals['title']; ?></title>
        <link rel="shortcut icon" href="<?php echo $globals['urls']['globals'], 'favicon.ico'?>" />
        <link rel="stylesheet" type="text/css" href="<?php echo $globals['urls']['globals'], 'stylesheet.css'?>" />
        <?
        
// load files
        
if(isset($locals['load_files'])) {
            foreach(
$locals['load_files'] as $file) {
                
$extension substr($file,-3);
                switch(
$extension) {
                    case 
'css':
                        echo 
'<link rel="stylesheet" type="text/css" href="'$file'" />';
                        break;
                    case 
'.js':
                        echo 
'<script type="text/javascript" src="'$file'"></script>';
                        break;
                }
            }
            unset(
$file$extension);
        }
        
        
// misc head
        
echo $locals['add_headers'];
        
?>
    </head>
    <body>
        <div id="sidebar">
            <div id="logo">
                <a href="<?php echo $globals['urls']['server']; ?>" title="return to main page"><img src="<?php echo $globals['urls']['globals'], 'logo.png'?>" alt="site logo" /></a>
            </div>
            
<?php
            
// output navigation menu
            
foreach($nav as $section => $links) {
                echo 
"\t\t\t"'<h5>'$section'</h5>',
                     
"\n\t\t\t"'<ul>'"\n";
                
                foreach(
$links as $link_array) {
                    
// generate data (0=title,1=description,3=url override)
                    
$link_title $link_array[0];
                    if(isset(
$link_array[2]))
                        
$link_url $link_array[2] . gUrlTitle($link_title);
                    else
                        
$link_url $globals['urls']['tools'] . gUrlTitle($link_title);
                    
$link_description = (isset($link_array[1]))?$link_array[1]:'';
    
                    
// output
                    
echo "\t\t\t\t"'<li><a href="'$link_url'" title="'$link_description'">'$link_title'</a></li>'"\n";
                }
                echo 
"\t\t\t"'</ul>'"\n";
            }
            unset(
$section$links$link_array$link_url$link_data$link_description); 
            
?>
        </div>
        <div id="content-column">
<?php
            
/* generate tabs */
            
echo "\n\t\t\t"'<div id="tabs">',
                 
"\n\t\t\t\t"'<ul>';
                   
            
// script
            
echo "\n\t\t\t\t\t"'<li';
            if(
$locals['action']=='script' || $locals['action']=='debug')
                echo 
' id="current"';
            echo 
'><a href="'$locals['path'], '" title="script page">Script</a></li>';

            
// source code
            
if(isset($locals['files'])) {
                echo 
'<li';
                if(
$locals['action']=='source')
                    echo 
' id="current"';
                echo 
'><a href="'$locals['path'], '?action=source" title="view source code">Source code</a></li>';
            }
            
            
// feedback
            
echo "\n\t\t\t\t\t"'<li><a href="http://meta.wikimedia.org/wiki/User_talk:Pathoschild?action=edit&section=new" title="leave feedback">Feedback</a></li>';
            
            echo 
"\n\t\t\t\t"'</ul>',
                 
"\n\t\t\t"'</div>';
            
?>
            <div id="content">
                <h1><?php echo $locals['title']; ?></h1>
                <p><?php echo $locals['description']; ?></p>
<!-- end generated header -->
<?php

/****************************
**** Build source code ******
****************************/
if($locals['action']=='source' && $locals['files']) {
?>
    <h2>Source code (<a href="<?php echo $locals['path']; ?>" title="hide source code">hide</a>)</h2>
    <div class="section" id="source">
    <?php
    
if($locals['path']!=$globals['urls']['globals']) {
        echo 
'<p><a href="'$globals['urls']['globals'], '?action=source" title="source code for global files">Global files</a> are not shown below.</p>';
    }
?>
    <!-- table of contents -->
    <div id="toc">
        <b>Table of contents</b>
        <ol>
            <?php
            
foreach($locals['files'] as $file) {
                echo 
'<li><a href="#'str_replace('.','',$file), '" title="section for '$file'">'$file'</a></li>';
            }
            
?>
        </ol>
    </div>

    <?php
    
// source code sections
    
foreach($locals['files'] as $file) {
        echo 
'<h3 id="'str_replace('.','',$file), '">'$file'</h3><a href="#toc" title="toc">back to toc</a><div class="source">';
        
highlight_file($file);
        echo 
'</div>';
    }
    unset(
$file);
}

/****************************
**** Build bottom of document
****************************/
function makeFooter() {
    global 
$globals$locals;

    
// hide
    
if(isset($locals['license']) && $locals['license']===false) {}
    else {
        
// override
        
if(isset($locals['license']))
            
$license $locals['license'];
        
// default
        
else
            
$license $globals['license'];
        
        echo 
'<!-- begin generated footer -->'"\n",
             
"\t\t\t\t"'<p id="license">'$license'</p>'"\n";
        unset(
$license);
    }
?>
            </div>
        </div>
    </body>
</html>
<?php
}
?>

stylesheet.css

back to toc
/* tags */
body {
    background:#000;
    font-family:sans-serif;
}

a {
    border-bottom:1px dashed #888;
    text-decoration:none;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: bold;
    margin: 0.2em 0 0.1em 0;
    padding-top: .5em;
}

h2 { border-bottom: 1px solid #AAA; }

h1 { font-size:1.5em; color:#888; }
h2 { font-size:1.5em; }
h3 { font-size:1.2em; }
h4 { font-size:1.1em; }
h5 { font-size:1.0em; }
h6 { font-size:0.8em; }

table {
    border:1px solid #000;
    border-collapse:collapse;
}

table th {
    border:1px solid #000;
    background:#CCC;
    font-weight:bold;
}

table td {
    border:1px solid #000;
}

pre {
    overflow:auto;
    width:95%;
    margin:0.5em;
    padding:0.5em;
    background:#CCC;
    border:1px dotted #000;
}

/* sidebar */
#sidebar {
    position:absolute;
    top:1em;
    left:1em;
    width:9em;
}

#sidebar a {
    color:#888 !important;
    border:0;
}

#sidebar #logo {
    width:100%;
    text-align:center;
}

#sidebar #logo * {
    border:0;
}

#sidebar h5 {
    margin:1em 0 0 0;
    color:#FFF;
    font-size:1.1em;
    font-style:italic;
    font-family:monospace;
    font-weight:normal;
}

#sidebar ul, #sidebar li {
    margin:0;
    padding:0;
    list-style:none;
    list-style-image:none;
    font-size:0.9em;
    color:#888;
}

#sidebar li {
    margin-left:1em;
}

/* tabs */
#tabs {
    margin-bottom:3px;
    font-size:0.8em;
}

#tabs a {
    color:#888;
}

#tabs .brokenlink a {
    text-decoration:line-through;
    font-style:italic;
}

#tabs * {
    border:0;
    margin:0;
    padding:0;
    list-style:none;
    list-style-image:none;
}

#tabs li {
    display:inline;
    height:1em;
    padding:0 0.2em;
    background:#000;
}

#tabs a:hover {
    color:#FFF;
}

#tabs #current {
      border:1px dashed #888 !important;
     }

/* content */
.section {
    border:1px solid #CCC;
    padding:0.5em;
    margin-bottom:1em;
}

#toc {
    border:1px solid #CCC;
    padding:0.5em;
    font-size:0.9em;
}

#content-column {
    position:absolute;
    top:2em;
    left:10em;
}

#content {
    padding: 0 1em 1em 1em;
    background:#FFF;
    color:#000 !important;
    font-size:0.9em;
}

#content p {
    width:35em;
}

/* Forms */
input, textarea, select {
    background:#000;
    border:1px solid #000;
    color:#FFF;
}

input {
    margin:1px;
}

textarea {
    padding:0.5em;
    font-family:monospace;
    font-size:0.95em;
}

input:hover, textarea:hover, select:hover {
    background:#333;
}

input:focus, textarea:focus {
    border:1px solid #0F0;
}

input[type=submit] {
    width:10em;
    padding:1em;
    font-size:1.3em;
}

input[type=reset] {
    width:14.44em;
    font-size:0.9em;
}

fieldset {
    margin:1em 0;
    border-color:gray;
}

legend {
    font-style:italic;
}

fieldset p.instruction {
    width:30em;
    margin: 0 0 0 0.5em;
    font-style:italic;
    margin-bottom:5px;
}

textarea {
    height:12em;
    width:100%;
}

/* debug */
.fail,
.neutral,
.success {
    margin:0;
    padding:0.5em;
    border:1px solid #000;
    border-left-width:1em;

.success { border-color:#0C0; }
.fail    { border-color:#C00; }
.neutral { border-color:#CCC; }

/* source code */
#source h3 + a {
    margin:0 0 0.5em 0.5em;
    font-size:0.9em;
}

.source {
    width:95%;
    overflow:auto;
    padding:1em;
    border:1px dashed #000;
    background: #F9F9F9;
}

/* about */
#license {
    margin:1em;
    padding:1em;
    border:1px solid #000;
}

index.php

back to toc
<?php
/* globals, templates */
$locals = array (
    
'title'       => 'Index',
    
'description' => 'This is the tools index.',
    
'files'       => array('globals.php','stylesheet.css','index.php'),
    
'license'     => false,
    
'path'        => &$globals['urls']['globals']
);
include(
'../globals/globals.php');

/* error 404 */
if($_REQUEST['action']=='error404') {
    echo 
'<p class="fail">You accessed a location that doesn\'t exist; it may have been moved. Please select a tool from the table below.</p>';
}

/* script */
// output navigation menu
?>
                <h2>Scripts</h2>
                <table>
<?php
$navtitles 
array_keys($nav);
for(
$i=0$i<count($navtitles); $i++) {
    
$navtitle $navtitles[$i];
?>
                    <tr>
                        <th colspan="2"><?php echo $navtitle?></th>
                    </tr>
<?php

    
for($x=0$x<count($nav[$navtitle]); $x++) {
        
$data $nav[$navtitle][$x];

        
$title $data[0];
        
$description $data[1];
        if(
$data[2]) {
            
$url $data[2] . gUrlTitle($title);
        }
        else {
            
$url $globals['urls']['tools'] . gUrlTitle($title);
        }

        
// output
?>
                    <tr>
                        <td><a href="<?php echo $url?>" title="<?php echo $description?>"><?php echo $title?></a></td>            
                        <td><?php echo $description?></td>
                    </tr>
<?php
    
}
}
?>
                </table>
<?php
/* globals, templates */
makeFooter();
?>

Scripts

navigation
tools tools index
lists
set operations perform set operations on two lists.
sort sort an input list.
increment increment numbers and repeat text with $new and $last magic words.
timecount calculate time elapsed in multiple time ranges.
strings
regex perform regex search and replace
etymology reader convert etymology shorthand into legible text.
line numbers add line numbers to text for proofreading.
poem formatting convert HTML and wikiML formatting to <poem> formatting.
databases
iso639db search ISO 639 codes.
Wikimedia
accountEligibility analyze an account to determine whether it is eligible to vote in a given event.
catanalysis analyze edits to pages in a category tree or with a prefix over time.
crossBlock lists block status on all Wikimedia wikis, with links to prefilled (un)block forms.
crossActivity measures a user's latest edit, bureaucrat, or sysop activity on all wikis.
globalGroups Lists rights with descriptions for each global group.
stewardry analyze bureaucrat activity on a Wikimedia wiki.
wmelections analyze votes in the 2008 Wikimedia Board elections.
other
pgkbot IRC-based wiki monitoring bot
redirspecial Redirects to a Wikimedia special page with parsed arguments.
wikilink action table create links to pre-filled delete or move forms from wikilinks.