<?php
+/**
+ * Global functions used everywhere
+ * @file
+ */
if ( !defined( 'MEDIAWIKI' ) ) {
die( "This file is part of MediaWiki, it is not a valid entry point" );
}
-/**
- * Global functions used everywhere
- */
-
require_once dirname(__FILE__) . '/normal/UtfNormalUtil.php';
// Hide compatibility functions from Doxygen
$split = mb_substr_split_unicode( $str, intval( $start ) );
$str = substr( $str, $split );
}
-
+
if( $count !== 'end' ) {
$split = mb_substr_split_unicode( $str, intval( $count ) );
$str = substr( $str, 0, $split );
}
-
+
return $str;
}
-
+
function mb_substr_split_unicode( $str, $splitPos ) {
if( $splitPos == 0 ) {
return 0;
}
-
+
$byteLen = strlen( $str );
-
+
if( $splitPos > 0 ) {
if( $splitPos > 256 ) {
// Optimize large string offsets by skipping ahead N bytes.
$charPos = 0;
$bytePos = 0;
}
-
+
while( $charPos++ < $splitPos ) {
++$bytePos;
// Move past any tail bytes
--$bytePos;
}
}
-
+
return $bytePos;
}
}
$ar = array();
preg_match_all( '/'.$needle.'/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset );
- if( isset( $ar[0] ) && count( $ar[0] ) > 0 &&
+ if( isset( $ar[0] ) && count( $ar[0] ) > 0 &&
isset( $ar[0][count($ar[0])-1][1] ) ) {
return $ar[0][count($ar[0])-1][1];
} else {
return false;
- }
+ }
}
}
*
* ;:@$!*(),/
*
- * However, IIS7 redirects fail when the url contains a colon (Bug 22709),
+ * However, IIS7 redirects fail when the url contains a colon (Bug 22709),
* so no fancy : for IIS7.
- *
+ *
* %2F in the page titles seems to fatally break for some reason.
*
* @param $s String:
if (! isset($_SERVER['SERVER_SOFTWARE']) || ( strpos($_SERVER['SERVER_SOFTWARE'], "Microsoft-IIS/7") === false)) {
$needle[] = '%3A';
}
- }
-
+ }
+
$s = urlencode( $s );
$s = str_ireplace(
$needle,
/**
* Log to a file without getting "file size exceeded" signals.
- *
- * Can also log to TCP or UDP with the syntax udp://host:port/prefix. This will
+ *
+ * Can also log to TCP or UDP with the syntax udp://host:port/prefix. This will
* send lines to the specified port, prefixed by the specified prefix and a space.
*/
function wfErrorLog( $text, $file ) {
# Great, we already have the object (hopefully)!
return $langcode;
}
-
+
global $wgContLang, $wgLanguageCode;
if( $langcode === true || $langcode === $wgLanguageCode ) {
# $langcode is the language code of the wikis content language object.
# or it is a boolean and value is true
return $wgContLang;
}
-
+
global $wgLang;
if( $langcode === false || $langcode === $wgLang->getCode() ) {
# $langcode is the language code of user language object.
global $wgMessageCache;
wfRunHooks('NormalizeMessageKey', array(&$key, &$useDB, &$langCode, &$transform));
-
+
if ( !is_object( $wgMessageCache ) ) {
throw new MWException( "Trying to get message before message cache is initialised" );
}
*/
function wfShowingResultsNum( $offset, $limit, $num ) {
global $wgLang;
- return wfMsgExt( 'showingresultsnum', array( 'parseinline' ), $wgLang->formatNum( $limit ),
+ return wfMsgExt( 'showingresultsnum', array( 'parseinline' ), $wgLang->formatNum( $limit ),
$wgLang->formatNum( $offset+1 ), $wgLang->formatNum( $num ) );
}
$q .= '&'.$query;
}
$plink = '<a href="' . $title->escapeLocalUrl( $q ) . "\" title=\"{$pTitle}\" class=\"mw-prevlink\">{$prev}</a>";
- } else {
+ } else {
$plink = $prev;
}
# Make 'next' link
$nlink = '<a href="' . $title->escapeLocalUrl( $q ) . "\" title=\"{$nTitle}\" class=\"mw-nextlink\">{$next}</a>";
}
# Make links to set number of items per page
- $nums = $wgLang->pipeList( array(
+ $nums = $wgLang->pipeList( array(
wfNumLink( $offset, 20, $title, $query ),
wfNumLink( $offset, 50, $title, $query ),
wfNumLink( $offset, 100, $title, $query ),
*/
function wfNumLink( $offset, $limit, $title, $query = '' ) {
global $wgLang;
- if( $query == '' ) {
+ if( $query == '' ) {
$q = '';
- } else {
+ } else {
$q = $query.'&';
}
$q .= "limit={$limit}&offset={$offset}";
* Windows doesn't recognise single-quotes in the shell, but the escapeshellarg()
* function puts single quotes in regardless of OS.
*
- * Also fixes the locale problems on Linux in PHP 5.2.6+ (bug backported to
+ * Also fixes the locale problems on Linux in PHP 5.2.6+ (bug backported to
* earlier distro releases of PHP)
*/
function wfEscapeShellArg( ) {
if ($before == $after) {
return '';
}
-
+
global $wgDiff;
# This check may also protect against code injection in
fwrite( $oldtextFile, $before ); fclose( $oldtextFile );
fwrite( $newtextFile, $after ); fclose( $newtextFile );
-
+
// Get the diff of the two files
$cmd = "$wgDiff " . $params . ' ' .wfEscapeShellArg( $oldtextName, $newtextName );
-
+
$h = popen( $cmd, 'r' );
-
+
$diff = '';
-
+
do {
$data = fread( $h, 8192 );
if ( strlen( $data ) == 0 ) {
}
$diff .= $data;
} while ( true );
-
+
// Clean up
pclose( $h );
unlink( $oldtextName );
unlink( $newtextName );
-
+
// Kill the --- and +++ lines. They're not useful.
$diff_lines = explode( "\n", $diff );
if (strpos( $diff_lines[0], '---' ) === 0) {
if (strpos( $diff_lines[1], '+++' ) === 0) {
unset($diff_lines[1]);
}
-
+
$diff = implode( "\n", $diff_lines );
-
+
return $diff;
}
* variables are then checked in sequence, and if none are set /tmp is
* returned as the generic Unix default.
* It is common to call it with tempnam().
- *
- * NOTE: When possible, use instead the tmpfile() function to create
+ *
+ * NOTE: When possible, use instead the tmpfile() function to create
* temporary files to avoid race conditions on file creation, etc.
*
* @return String
/**
* Make directory, and make all parent directories if they don't exist
- *
+ *
* @param $dir String: full path to directory to create
* @param $mode Integer: chmod value to use, default is $wgDirectoryMode
* @param $caller String: optional caller param for debugging.
$cmd = escapeshellarg( $script ) . " $time $mem $filesize " . escapeshellarg( $cmd );
}
}
- } elseif ( php_uname( 's' ) == 'Windows NT' &&
- version_compare( PHP_VERSION, '5.3.0', '<' ) )
+ } elseif ( php_uname( 's' ) == 'Windows NT' &&
+ version_compare( PHP_VERSION, '5.3.0', '<' ) )
{
# This is a hack to work around PHP's flawed invocation of cmd.exe
# http://news.php.net/php.internals/21796
/**
* Merge arrays in the style of getUserPermissionsErrors, with duplicate removal
* e.g.
- * wfMergeErrorArrays(
- * array( array( 'x' ) ),
- * array( array( 'x', '2' ) ),
- * array( array( 'x' ) ),
+ * wfMergeErrorArrays(
+ * array( array( 'x' ) ),
+ * array( array( 'x', '2' ) ),
+ * array( array( 'x' ) ),
* array( array( 'y') )
* );
* returns:
- * array(
+ * array(
* array( 'x', '2' ),
* array( 'x' ),
* array( 'y' )
* Initialise php session
*/
function wfSetupSession() {
- global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain,
+ global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain,
$wgCookieSecure, $wgCookieHttpOnly, $wgSessionHandler;
if( $wgSessionsInMemcached ) {
require_once( 'MemcachedSessions.php' );
*
* ignoreRedirect: If true, do not follow file redirects
*
- * private: If true, return restricted (deleted) files if the current
+ * private: If true, return restricted (deleted) files if the current
* user is allowed to view them. Otherwise, such files will not
* be found.
*
}
/**
- * Count down from $n to zero on the terminal, with a one-second pause
+ * Count down from $n to zero on the terminal, with a one-second pause
* between showing each number. For use in command-line scripts.
*/
function wfCountDown( $n ) {
for ( $i = $n; $i >= 0; $i-- ) {
if ( $i != $n ) {
echo str_repeat( "\x08", strlen( $i + 1 ) );
- }
+ }
echo $i;
flush();
if ( $i ) {
// Find the offset of the element to insert after.
$keys = array_keys($array);
$offsetByKey = array_flip( $keys );
-
+
$offset = $offsetByKey[$after];
-
+
// Insert at the specified offset
$before = array_slice( $array, 0, $offset + 1, true );
$after = array_slice( $array, $offset + 1, count($array)-$offset, true );
-
+
$output = $before + $insert + $after;
-
+
return $output;
}
/* Recursively converts the parameter (an object) to an array with the same data */
function wfObjectToArray( $object, $recursive = true ) {
$array = array();
- foreach ( get_object_vars($object) as $key => $value ) {
- if ( is_object($value) && $recursive ) {
+ foreach ( get_object_vars( $object ) as $key => $value ) {
+ if ( is_object( $value ) && $recursive ) {
$value = wfObjectToArray( $value );
}
-
+
$array[$key] = $value;
}
-
+
return $array;
}
* Set PHP's memory limit to the larger of php.ini or $wgMemoryLimit;
* @return Integer value memory was set to.
*/
-
-function wfMemoryLimit () {
+function wfMemoryLimit() {
global $wgMemoryLimit;
$memlimit = wfShorthandToInteger( ini_get( "memory_limit" ) );
$conflimit = wfShorthandToInteger( $wgMemoryLimit );