Jump to content

User:Jwanders/Template:Chess white move

From Wikipedia, the free encyclopedia

<?php /*

Defines a subset of parser functions that operate on strings.
{{#sub:value|start|length}} Returns a substring of the given value with the
                            given starting position and length.  If length
                            is omitted, this returns the rest of the string.
                            http://php.net/manual/en/function.substr.php
{{#pos:value|key|offset}}   Returns the first position of key inside value,
                            or nothing.  If offset is defined, this method
                            will not search the first offset characters.
                            Note: key may not exceed 30 characters in length.
                            http://php.net/manual/en/function.strpos.php
{{#len:value}}       Returns the length of the given value.
                     http://php.net/manual/en/function.strlen.php
{{#urlencode:value}} URL-encodes the given value.
                     http://php.net/manual/en/function.urlencode.php
{{#urldecode:value}} URL-decodes the given value.
                     http://php.net/manual/en/function.urldecode.php
Author: Algorithm [1]
Version 1.2.1 5/19/06
  • /

$wgExtensionFunctions[] = 'wfStringFunctions'; $wgExtensionCredits['parserhook'][] = array( 'name' => 'StringFunctions v1.2.1', 'url' => 'http://meta.wikimedia.org/wiki/StringFunctions', );

function wfStringFunctions() {

   global $wgParser, $wgExtStringFunctions, $wgStrPosMaxKeyLength;
   $wgExtStringFunctions = new ExtStringFunctions();
   $wgStrPosMaxKeyLength = 30;
   $wgParser->setFunctionHook( 'sub',       array( &$wgExtStringFunctions, 'sub' ) );
   $wgParser->setFunctionHook( 'pos',       array( &$wgExtStringFunctions, 'pos' ) );
   $wgParser->setFunctionHook( 'len',       array( &$wgExtStringFunctions, 'len' ) );
   $wgParser->setFunctionHook( 'urlencode', array( &$wgExtStringFunctions, 'runUrlEncode' ) );
   $wgParser->setFunctionHook( 'urldecode', array( &$wgExtStringFunctions, 'runUrlDecode' ) );

}

class ExtStringFunctions {

   function sub( &$parser, $value = , $start = , $length =  )
   {
       if ( $length ===  )
           return substr( $value, intval($start) );
       else
           return substr( $value, intval($start), intval($length) );
   }
   function pos( &$parser, $value = , $key = , $offset = 0 )
   {
       global $wgStrPosMaxKeyLength;
       if( $key ===  )
           $key = ' ';
       else
           $key = substr($key, 0, $wgStrPosMaxKeyLength);
       $offset = intval($offset);
       if ( $offset < strlen($value) )
       {
           if( $offset < 0 )
               $offset = 0;
           $p = strpos($value, $key, $offset);
           if( $p !== false )
               return $p;
       }
       return ;
   }
   function len( &$parser, $value =  )
   {
       return strlen($value);
   }
   function runUrlEncode( &$parser, $value =  )
   {
       return urlencode($value);
   }
   function runUrlDecode( &$parser, $value =  )
   {
       return urldecode($value);
   }

}

?>

Length:{{#len:{{{65}}} }}