summaryrefslogtreecommitdiff
path: root/includes/libs
diff options
context:
space:
mode:
Diffstat (limited to 'includes/libs')
-rw-r--r--includes/libs/CSSJanus.php16
-rw-r--r--includes/libs/CSSMin.php26
-rw-r--r--includes/libs/GenericArrayObject.php244
-rw-r--r--includes/libs/HttpStatus.php21
-rw-r--r--includes/libs/IEContentAnalyzer.php6
-rw-r--r--includes/libs/IEUrlExtension.php26
-rw-r--r--includes/libs/JavaScriptMinifier.php10
-rw-r--r--includes/libs/jsminplus.php2
8 files changed, 331 insertions, 20 deletions
diff --git a/includes/libs/CSSJanus.php b/includes/libs/CSSJanus.php
index c8fc296b..4ebbc497 100644
--- a/includes/libs/CSSJanus.php
+++ b/includes/libs/CSSJanus.php
@@ -1,5 +1,7 @@
<?php
/**
+ * PHP port of CSSJanus.
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -15,6 +17,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
+ * @file
*/
/**
@@ -122,7 +125,7 @@ class CSSJanus {
* @param $css String: stylesheet to transform
* @param $swapLtrRtlInURL Boolean: If true, swap 'ltr' and 'rtl' in URLs
* @param $swapLeftRightInURL Boolean: If true, swap 'left' and 'right' in URLs
- * @return Transformed stylesheet
+ * @return string Transformed stylesheet
*/
public static function transform( $css, $swapLtrRtlInURL = false, $swapLeftRightInURL = false ) {
// We wrap tokens in ` , not ~ like the original implementation does.
@@ -265,10 +268,17 @@ class CSSJanus {
* @return string
*/
private static function fixBackgroundPosition( $css ) {
- $css = preg_replace_callback( self::$patterns['bg_horizontal_percentage'],
+ $replaced = preg_replace_callback( self::$patterns['bg_horizontal_percentage'],
array( 'self', 'calculateNewBackgroundPosition' ), $css );
- $css = preg_replace_callback( self::$patterns['bg_horizontal_percentage_x'],
+ if ( $replaced !== null ) {
+ // Check for null; sometimes preg_replace_callback() returns null here for some weird reason
+ $css = $replaced;
+ }
+ $replaced = preg_replace_callback( self::$patterns['bg_horizontal_percentage_x'],
array( 'self', 'calculateNewBackgroundPosition' ), $css );
+ if ( $replaced !== null ) {
+ $css = $replaced;
+ }
return $css;
}
diff --git a/includes/libs/CSSMin.php b/includes/libs/CSSMin.php
index 4f4b28bb..fc75cdcc 100644
--- a/includes/libs/CSSMin.php
+++ b/includes/libs/CSSMin.php
@@ -1,5 +1,7 @@
<?php
/**
+ * Minification of CSS stylesheets.
+ *
* Copyright 2010 Wikimedia Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -12,12 +14,6 @@
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
* OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
- */
-
-/**
- * Transforms CSS data
- *
- * This class provides minification, URL remapping, URL extracting, and data-URL embedding.
*
* @file
* @version 0.1.1 -- 2010-09-11
@@ -25,6 +21,12 @@
* @copyright Copyright 2010 Wikimedia Foundation
* @license http://www.apache.org/licenses/LICENSE-2.0
*/
+
+/**
+ * Transforms CSS data
+ *
+ * This class provides minification, URL remapping, URL extracting, and data-URL embedding.
+ */
class CSSMin {
/* Constants */
@@ -150,6 +152,13 @@ class CSSMin {
$offset = $match[0][1] + strlen( $match[0][0] ) + $lengthIncrease;
continue;
}
+
+ // Guard against double slashes, because "some/remote/../foo.png"
+ // resolves to "some/remote/foo.png" on (some?) clients (bug 27052).
+ if ( substr( $remote, -1 ) == '/' ) {
+ $remote = substr( $remote, 0, -1 );
+ }
+
// Shortcuts
$embed = $match['embed'][0];
$pre = $match['pre'][0];
@@ -157,10 +166,9 @@ class CSSMin {
$query = $match['query'][0];
$url = "{$remote}/{$match['file'][0]}";
$file = "{$local}/{$match['file'][0]}";
- // bug 27052 - Guard against double slashes, because foo//../bar
- // apparently resolves to foo/bar on (some?) clients
- $url = preg_replace( '#([^:])//+#', '\1/', $url );
+
$replacement = false;
+
if ( $local !== false && file_exists( $file ) ) {
// Add version parameter as a time-stamp in ISO 8601 format,
// using Z for the timezone, meaning GMT
diff --git a/includes/libs/GenericArrayObject.php b/includes/libs/GenericArrayObject.php
new file mode 100644
index 00000000..b4b9d610
--- /dev/null
+++ b/includes/libs/GenericArrayObject.php
@@ -0,0 +1,244 @@
+<?php
+
+/**
+ * Extends ArrayObject and does two things:
+ *
+ * Allows for deriving classes to easily intercept additions
+ * and deletions for purposes such as additional indexing.
+ *
+ * Enforces the objects to be of a certain type, so this
+ * can be replied upon, much like if this had true support
+ * for generics, which sadly enough is not possible in PHP.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @since 1.20
+ *
+ * @file
+ * @ingroup Diff
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+abstract class GenericArrayObject extends ArrayObject {
+
+ /**
+ * Returns the name of an interface/class that the element should implement/extend.
+ *
+ * @since 1.20
+ *
+ * @return string
+ */
+ public abstract function getObjectType();
+
+ /**
+ * @see SiteList::getNewOffset()
+ * @since 1.20
+ * @var integer
+ */
+ protected $indexOffset = 0;
+
+ /**
+ * Finds a new offset for when appending an element.
+ * The base class does this, so it would be better to integrate,
+ * but there does not appear to be any way to do this...
+ *
+ * @since 1.20
+ *
+ * @return integer
+ */
+ protected function getNewOffset() {
+ while ( true ) {
+ if ( !$this->offsetExists( $this->indexOffset ) ) {
+ return $this->indexOffset;
+ }
+
+ $this->indexOffset++;
+ }
+ }
+
+ /**
+ * Constructor.
+ * @see ArrayObject::__construct
+ *
+ * @since 1.20
+ *
+ * @param null|array $input
+ * @param int $flags
+ * @param string $iterator_class
+ */
+ public function __construct( $input = null, $flags = 0, $iterator_class = 'ArrayIterator' ) {
+ parent::__construct( array(), $flags, $iterator_class );
+
+ if ( !is_null( $input ) ) {
+ foreach ( $input as $offset => $value ) {
+ $this->offsetSet( $offset, $value );
+ }
+ }
+ }
+
+ /**
+ * @see ArrayObject::append
+ *
+ * @since 1.20
+ *
+ * @param mixed $value
+ */
+ public function append( $value ) {
+ $this->setElement( null, $value );
+ }
+
+ /**
+ * @see ArrayObject::offsetSet()
+ *
+ * @since 1.20
+ *
+ * @param mixed $index
+ * @param mixed $value
+ */
+ public function offsetSet( $index, $value ) {
+ $this->setElement( $index, $value );
+ }
+
+ /**
+ * Returns if the provided value has the same type as the elements
+ * that can be added to this ArrayObject.
+ *
+ * @since 1.20
+ *
+ * @param mixed $value
+ *
+ * @return boolean
+ */
+ protected function hasValidType( $value ) {
+ $class = $this->getObjectType();
+ return $value instanceof $class;
+ }
+
+ /**
+ * Method that actually sets the element and holds
+ * all common code needed for set operations, including
+ * type checking and offset resolving.
+ *
+ * If you want to do additional indexing or have code that
+ * otherwise needs to be executed whenever an element is added,
+ * you can overload @see preSetElement.
+ *
+ * @since 1.20
+ *
+ * @param mixed $index
+ * @param mixed $value
+ *
+ * @throws InvalidArgumentException
+ */
+ protected function setElement( $index, $value ) {
+ if ( !$this->hasValidType( $value ) ) {
+ throw new InvalidArgumentException(
+ 'Can only add ' . $this->getObjectType() . ' implementing objects to ' . get_called_class() . '.'
+ );
+ }
+
+ if ( is_null( $index ) ) {
+ $index = $this->getNewOffset();
+ }
+
+ if ( $this->preSetElement( $index, $value ) ) {
+ parent::offsetSet( $index, $value );
+ }
+ }
+
+ /**
+ * Gets called before a new element is added to the ArrayObject.
+ *
+ * At this point the index is always set (ie not null) and the
+ * value is always of the type returned by @see getObjectType.
+ *
+ * Should return a boolean. When false is returned the element
+ * does not get added to the ArrayObject.
+ *
+ * @since 1.20
+ *
+ * @param integer|string $index
+ * @param mixed $value
+ *
+ * @return boolean
+ */
+ protected function preSetElement( $index, $value ) {
+ return true;
+ }
+
+ /**
+ * @see Serializable::serialize
+ *
+ * @since 1.20
+ *
+ * @return string
+ */
+ public function serialize() {
+ return serialize( $this->getSerializationData() );
+ }
+
+ /**
+ * Returns an array holding all the data that should go into serialization calls.
+ * This is intended to allow overloading without having to reimplement the
+ * behaviour of this base class.
+ *
+ * @since 1.20
+ *
+ * @return array
+ */
+ protected function getSerializationData() {
+ return array(
+ 'data' => $this->getArrayCopy(),
+ 'index' => $this->indexOffset,
+ );
+ }
+
+ /**
+ * @see Serializable::unserialize
+ *
+ * @since 1.20
+ *
+ * @param string $serialization
+ *
+ * @return array
+ */
+ public function unserialize( $serialization ) {
+ $serializationData = unserialize( $serialization );
+
+ foreach ( $serializationData['data'] as $offset => $value ) {
+ // Just set the element, bypassing checks and offset resolving,
+ // as these elements have already gone through this.
+ parent::offsetSet( $offset, $value );
+ }
+
+ $this->indexOffset = $serializationData['index'];
+
+ return $serializationData;
+ }
+
+ /**
+ * Returns if the ArrayObject has no elements.
+ *
+ * @since 1.20
+ *
+ * @return boolean
+ */
+ public function isEmpty() {
+ return $this->count() === 0;
+ }
+
+}
diff --git a/includes/libs/HttpStatus.php b/includes/libs/HttpStatus.php
index 2985c652..78d81803 100644
--- a/includes/libs/HttpStatus.php
+++ b/includes/libs/HttpStatus.php
@@ -1,5 +1,26 @@
<?php
/**
+ * List of HTTP status codes.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
* @todo document
*/
class HttpStatus {
diff --git a/includes/libs/IEContentAnalyzer.php b/includes/libs/IEContentAnalyzer.php
index 01e72e68..cfc7f536 100644
--- a/includes/libs/IEContentAnalyzer.php
+++ b/includes/libs/IEContentAnalyzer.php
@@ -1,4 +1,10 @@
<?php
+/**
+ * Simulation of Microsoft Internet Explorer's MIME type detection algorithm.
+ *
+ * @file
+ * @todo Define the exact license of this file.
+ */
/**
* This class simulates Microsoft Internet Explorer's terribly broken and
diff --git a/includes/libs/IEUrlExtension.php b/includes/libs/IEUrlExtension.php
index e00e6663..e9cfa997 100644
--- a/includes/libs/IEUrlExtension.php
+++ b/includes/libs/IEUrlExtension.php
@@ -1,4 +1,24 @@
<?php
+/**
+ * Checks for validity of requested URL's extension.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
/**
* Internet Explorer derives a cache filename from a URL, and then in certain
@@ -35,8 +55,8 @@ class IEUrlExtension {
*
* If the a variable is unset in $_SERVER, it should be unset in $vars.
*
- * @param $vars A subset of $_SERVER.
- * @param $extWhitelist Extensions which are allowed, assumed harmless.
+ * @param $vars array A subset of $_SERVER.
+ * @param $extWhitelist array Extensions which are allowed, assumed harmless.
* @return bool
*/
public static function areServerVarsBad( $vars, $extWhitelist = array() ) {
@@ -73,7 +93,7 @@ class IEUrlExtension {
* a potentially harmful file extension.
*
* @param $urlPart string The right-hand portion of a URL
- * @param $extWhitelist An array of file extensions which may occur in this
+ * @param $extWhitelist array An array of file extensions which may occur in this
* URL, and which should be allowed.
* @return bool
*/
diff --git a/includes/libs/JavaScriptMinifier.php b/includes/libs/JavaScriptMinifier.php
index baf93385..0b4be9ae 100644
--- a/includes/libs/JavaScriptMinifier.php
+++ b/includes/libs/JavaScriptMinifier.php
@@ -2,17 +2,19 @@
/**
* JavaScript Minifier
*
+ * @file
+ * @author Paul Copperman <paul.copperman@gmail.com>
+ * @license Choose any of Apache, MIT, GPL, LGPL
+ */
+
+/**
* This class is meant to safely minify javascript code, while leaving syntactically correct
* programs intact. Other libraries, such as JSMin require a certain coding style to work
* correctly. OTOH, libraries like jsminplus, that do parse the code correctly are rather
* slow, because they construct a complete parse tree before outputting the code minified.
* So this class is meant to allow arbitrary (but syntactically correct) input, while being
* fast enough to be used for on-the-fly minifying.
- *
- * Author: Paul Copperman <paul.copperman@gmail.com>
- * License: choose any of Apache, MIT, GPL, LGPL
*/
-
class JavaScriptMinifier {
/* Class constants */
diff --git a/includes/libs/jsminplus.php b/includes/libs/jsminplus.php
index 8ed08d74..7c4e32bd 100644
--- a/includes/libs/jsminplus.php
+++ b/includes/libs/jsminplus.php
@@ -1,5 +1,4 @@
<?php
-
/**
* JSMinPlus version 1.4
*
@@ -25,6 +24,7 @@
*
* Latest version of this script: http://files.tweakers.net/jsminplus/jsminplus.zip
*
+ * @file
*/
/* ***** BEGIN LICENSE BLOCK *****