Merge "mediawiki.Upload.BookletLayout: Allow for asynchronous initialization"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 29 Oct 2015 15:59:59 +0000 (15:59 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 29 Oct 2015 15:59:59 +0000 (15:59 +0000)
27 files changed:
RELEASE-NOTES-1.27
autoload.php
composer.json
includes/cache/MessageCache.php
includes/db/IORMRow.php [deleted file]
includes/db/IORMTable.php [deleted file]
includes/db/ORMIterator.php [deleted file]
includes/db/ORMResult.php [deleted file]
includes/db/ORMRow.php [deleted file]
includes/db/ORMTable.php [deleted file]
includes/libs/Xhprof.php
includes/libs/objectcache/WANObjectCache.php
includes/parser/MWTidy.php
includes/parser/Parser.php
includes/skins/Skin.php
includes/tidy/RaggettWrapper.php
languages/Language.php
resources/Resources.php
resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js
resources/src/mediawiki/mediawiki.raggett.css [new file with mode: 0644]
tests/TestsAutoLoader.php
tests/parser/parserTests.txt
tests/phpunit/includes/db/ORMRowTest.php [deleted file]
tests/phpunit/includes/db/ORMTableTest.php [deleted file]
tests/phpunit/includes/db/TestORMRowTest.php [deleted file]
tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
tests/phpunit/includes/objectcache/MemcachedBagOStuffTest.php

index 3a45fae..d0a5c4e 100644 (file)
@@ -93,6 +93,7 @@ changes to languages because of Bugzilla reports.
 * WikiPage::doDeleteArticleReal() and WikiPage::doDeleteArticle() now
   ignore the 2nd and 3rd arguments (formerly $id and $commit).
 * Removed "loaderScripts" option from ResourceLoaderFileModule class.
+* Removed ORM-like wrapper added in 1.20.
 
 == Compatibility ==
 
index 2bcf6b5..65a84bf 100644 (file)
@@ -543,8 +543,6 @@ $wgAutoloadLocalClasses = array(
        'IEUrlExtension' => __DIR__ . '/includes/libs/IEUrlExtension.php',
        'IExpiringStore' => __DIR__ . '/includes/libs/objectcache/IExpiringStore.php',
        'IJobSpecification' => __DIR__ . '/includes/jobqueue/JobSpecification.php',
-       'IORMRow' => __DIR__ . '/includes/db/IORMRow.php',
-       'IORMTable' => __DIR__ . '/includes/db/IORMTable.php',
        'IP' => __DIR__ . '/includes/utils/IP.php',
        'IPSet' => __DIR__ . '/includes/compat/IPSetCompat.php',
        'IPTC' => __DIR__ . '/includes/media/IPTC.php',
@@ -848,10 +846,6 @@ $wgAutoloadLocalClasses = array(
        'OOUIHTMLForm' => __DIR__ . '/includes/htmlform/OOUIHTMLForm.php',
        'ORAField' => __DIR__ . '/includes/db/DatabaseOracle.php',
        'ORAResult' => __DIR__ . '/includes/db/DatabaseOracle.php',
-       'ORMIterator' => __DIR__ . '/includes/db/ORMIterator.php',
-       'ORMResult' => __DIR__ . '/includes/db/ORMResult.php',
-       'ORMRow' => __DIR__ . '/includes/db/ORMRow.php',
-       'ORMTable' => __DIR__ . '/includes/db/ORMTable.php',
        'ObjectCache' => __DIR__ . '/includes/objectcache/ObjectCache.php',
        'ObjectCacheSessionHandler' => __DIR__ . '/includes/objectcache/ObjectCacheSessionHandler.php',
        'ObjectFactory' => __DIR__ . '/includes/libs/ObjectFactory.php',
index cfff697..4aa9b92 100644 (file)
@@ -31,7 +31,7 @@
                "wikimedia/composer-merge-plugin": "1.2.1",
                "wikimedia/ip-set": "1.0.1",
                "wikimedia/relpath": "1.0.3",
-               "wikimedia/running-stat": "1.0.0",
+               "wikimedia/running-stat": "1.1.0",
                "wikimedia/utfnormal": "1.0.3",
                "wikimedia/wrappedstring": "2.0.0",
                "zordius/lightncandy": "0.21"
index 09e9077..bcfa792 100644 (file)
@@ -574,7 +574,7 @@ class MessageCache {
 
                foreach ( $codes as $code ) {
                        $sidebarKey = wfMemcKey( 'sidebar', $code );
-                       $this->wanCache->delete( $sidebarKey, 5 );
+                       $this->wanCache->delete( $sidebarKey );
                }
 
                // Update the message in the message blob store
diff --git a/includes/db/IORMRow.php b/includes/db/IORMRow.php
deleted file mode 100644 (file)
index c66cddf..0000000
+++ /dev/null
@@ -1,270 +0,0 @@
-<?php
-/**
- * Interface for representing objects that are stored in some DB table.
- * This is basically an ORM-like wrapper around rows in database tables that
- * aims to be both simple and very flexible. It is centered around an associative
- * array of fields and various methods to do common interaction with the database.
- *
- * Documentation inline and at https://www.mediawiki.org/wiki/Manual:ORMTable
- *
- * 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 ORM
- *
- * @license GNU GPL v2 or later
- * @author Jeroen De Dauw < jeroendedauw@gmail.com >
- */
-
-interface IORMRow {
-       /**
-        * Load the specified fields from the database.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @param array|null $fields
-        * @param bool $override
-        * @param bool $skipLoaded
-        *
-        * @return bool Success indicator
-        */
-       public function loadFields( $fields = null, $override = true, $skipLoaded = false );
-
-       /**
-        * Gets the value of a field.
-        *
-        * @since 1.20
-        *
-        * @param string $name
-        * @param mixed $default
-        *
-        * @throws MWException
-        * @return mixed
-        */
-       public function getField( $name, $default = null );
-
-       /**
-        * Gets the value of a field but first loads it if not done so already.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @param string $name
-        *
-        * @return mixed
-        */
-       public function loadAndGetField( $name );
-
-       /**
-        * Remove a field.
-        *
-        * @since 1.20
-        *
-        * @param string $name
-        */
-       public function removeField( $name );
-
-       /**
-        * Returns the objects database id.
-        *
-        * @since 1.20
-        *
-        * @return int|null
-        */
-       public function getId();
-
-       /**
-        * Sets the objects database id.
-        *
-        * @since 1.20
-        *
-        * @param int|null $id
-        */
-       public function setId( $id );
-
-       /**
-        * Gets if a certain field is set.
-        *
-        * @since 1.20
-        *
-        * @param string $name
-        *
-        * @return bool
-        */
-       public function hasField( $name );
-
-       /**
-        * Gets if the id field is set.
-        *
-        * @since 1.20
-        *
-        * @return bool
-        */
-       public function hasIdField();
-
-       /**
-        * Sets multiple fields.
-        *
-        * @since 1.20
-        *
-        * @param array $fields The fields to set
-        * @param bool $override Override already set fields with the provided values?
-        */
-       public function setFields( array $fields, $override = true );
-
-       /**
-        * Serializes the object to an associative array which
-        * can then easily be converted into JSON or similar.
-        *
-        * @since 1.20
-        *
-        * @param null|array $fields
-        * @param bool $incNullId
-        *
-        * @return array
-        */
-       public function toArray( $fields = null, $incNullId = false );
-
-       /**
-        * Load the default values, via getDefaults.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @param bool $override
-        */
-       public function loadDefaults( $override = true );
-
-       /**
-        * Writes the answer to the database, either updating it
-        * when it already exists, or inserting it when it doesn't.
-        *
-        * @since 1.20
-        *
-        * @param string|null $functionName
-        * @deprecated since 1.22
-        *
-        * @return bool Success indicator
-        */
-       public function save( $functionName = null );
-
-       /**
-        * Removes the object from the database.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @return bool Success indicator
-        */
-       public function remove();
-
-       /**
-        * Return the names and values of the fields.
-        *
-        * @since 1.20
-        *
-        * @return array
-        */
-       public function getFields();
-
-       /**
-        * Return the names of the fields.
-        *
-        * @since 1.20
-        *
-        * @return array
-        */
-       public function getSetFieldNames();
-
-       /**
-        * Sets the value of a field.
-        * Strings can be provided for other types,
-        * so this method can be called from unserialization handlers.
-        *
-        * @since 1.20
-        *
-        * @param string $name
-        * @param mixed $value
-        *
-        * @throws MWException
-        */
-       public function setField( $name, $value );
-
-       /**
-        * Add an amount (can be negative) to the specified field (needs to be numeric).
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @param string $field
-        * @param int $amount
-        *
-        * @return bool Success indicator
-        */
-       public function addToField( $field, $amount );
-
-       /**
-        * Return the names of the fields.
-        *
-        * @since 1.20
-        *
-        * @return array
-        */
-       public function getFieldNames();
-
-       /**
-        * Computes and updates the values of the summary fields.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @param array|string|null $summaryFields
-        */
-       public function loadSummaryFields( $summaryFields = null );
-
-       /**
-        * Sets the value for the @see $updateSummaries field.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @param bool $update
-        */
-       public function setUpdateSummaries( $update );
-
-       /**
-        * Sets the value for the @see $inSummaryMode field.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @param bool $summaryMode
-        */
-       public function setSummaryMode( $summaryMode );
-
-       /**
-        * Returns the table this IORMRow is a row in.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @return IORMTable
-        */
-       public function getTable();
-}
diff --git a/includes/db/IORMTable.php b/includes/db/IORMTable.php
deleted file mode 100644 (file)
index b2527f9..0000000
+++ /dev/null
@@ -1,520 +0,0 @@
-<?php
-/**
- * Interface for objects representing a single database table.
- * Documentation inline and at https://www.mediawiki.org/wiki/Manual:ORMTable
- *
- * 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 ORM
- *
- * @license GNU GPL v2 or later
- * @author Jeroen De Dauw < jeroendedauw@gmail.com >
- */
-
-interface IORMTable {
-       /**
-        * Returns the name of the database table objects of this type are stored in.
-        *
-        * @since 1.20
-        *
-        * @return string
-        */
-       public function getName();
-
-       /**
-        * Returns the name of a IORMRow implementing class that
-        * represents single rows in this table.
-        *
-        * @since 1.20
-        *
-        * @return string
-        */
-       public function getRowClass();
-
-       /**
-        * Returns an array with the fields and their types this object contains.
-        * This corresponds directly to the fields in the database, without prefix.
-        *
-        * field name => type
-        *
-        * Allowed types:
-        * * id
-        * * str
-        * * int
-        * * float
-        * * bool
-        * * array
-        * * blob
-        *
-        * @todo Get rid of the id field. Every row instance needs to have one so
-        *   this is just causing hassle at various locations by requiring an extra
-        *   check for field name.
-        *
-        * @since 1.20
-        *
-        * @return array
-        */
-       public function getFields();
-
-       /**
-        * Returns a list of default field values.
-        * field name => field value
-        *
-        * @since 1.20
-        *
-        * @return array
-        */
-       public function getDefaults();
-
-       /**
-        * Returns a list of the summary fields.
-        * These are fields that cache computed values, such as the amount of linked objects of $type.
-        * This is relevant as one might not want to do actions such as log changes when these get updated.
-        *
-        * @since 1.20
-        *
-        * @return array
-        */
-       public function getSummaryFields();
-
-       /**
-        * Selects the specified fields of the records matching the provided
-        * conditions and returns them as DBDataObject. Field names get prefixed.
-        *
-        * @see DatabaseBase::select()
-        *
-        * @since 1.20
-        *
-        * @param array|string|null $fields
-        * @param array $conditions
-        * @param array $options
-        * @param string|null $functionName
-        *
-        * @return ORMResult The result set
-        * @throws DBQueryError If the query failed (even if the database was in ignoreErrors mode)
-        */
-       public function select( $fields = null, array $conditions = array(),
-               array $options = array(), $functionName = null );
-
-       /**
-        * Selects the specified fields of the records matching the provided
-        * conditions and returns them as DBDataObject. Field names get prefixed.
-        *
-        * @since 1.20
-        *
-        * @param array|string|null $fields
-        * @param array $conditions
-        * @param array $options
-        * @param string|null $functionName
-        *
-        * @return array Array of self
-        */
-       public function selectObjects( $fields = null, array $conditions = array(),
-               array $options = array(), $functionName = null );
-
-       /**
-        * Do the actual select.
-        *
-        * @since 1.20
-        *
-        * @param null|string|array $fields
-        * @param array $conditions
-        * @param array $options
-        * @param null|string $functionName
-        *
-        * @return ResultWrapper
-        * @throws DBQueryError If the query failed (even if the database was in ignoreErrors mode)
-        */
-       public function rawSelect( $fields = null, array $conditions = array(),
-               array $options = array(), $functionName = null );
-
-       /**
-        * Selects the specified fields of the records matching the provided
-        * conditions and returns them as associative arrays.
-        * Provided field names get prefixed.
-        * Returned field names will not have a prefix.
-        *
-        * When $collapse is true:
-        * If one field is selected, each item in the result array will be this field.
-        * If two fields are selected, each item in the result array will have as key
-        * the first field and as value the second field.
-        * If more then two fields are selected, each item will be an associative array.
-        *
-        * @since 1.20
-        *
-        * @param array|string|null $fields
-        * @param array $conditions
-        * @param array $options
-        * @param bool $collapse Set to false to always return each result row as associative array.
-        * @param string|null $functionName
-        *
-        * @return array Array of array
-        */
-       public function selectFields( $fields = null, array $conditions = array(),
-               array $options = array(), $collapse = true, $functionName = null );
-
-       /**
-        * Selects the specified fields of the first matching record.
-        * Field names get prefixed.
-        *
-        * @since 1.20
-        *
-        * @param array|string|null $fields
-        * @param array $conditions
-        * @param array $options
-        * @param string|null $functionName
-        *
-        * @return IORMRow|bool False on failure
-        */
-       public function selectRow( $fields = null, array $conditions = array(),
-               array $options = array(), $functionName = null );
-
-       /**
-        * Selects the specified fields of the records matching the provided
-        * conditions. Field names do NOT get prefixed.
-        *
-        * @since 1.20
-        *
-        * @param array $fields
-        * @param array $conditions
-        * @param array $options
-        * @param string|null $functionName
-        *
-        * @return ResultWrapper
-        */
-       public function rawSelectRow( array $fields, array $conditions = array(),
-               array $options = array(), $functionName = null );
-
-       /**
-        * Selects the specified fields of the first record matching the provided
-        * conditions and returns it as an associative array, or false when nothing matches.
-        * This method makes use of selectFields and expects the same parameters and
-        * returns the same results (if there are any, if there are none, this method returns false).
-        * @see IORMTable::selectFields
-        *
-        * @since 1.20
-        *
-        * @param array|string|null $fields
-        * @param array $conditions
-        * @param array $options
-        * @param bool $collapse Set to false to always return each result row as associative array.
-        * @param string|null $functionName
-        *
-        * @return mixed|array|bool False on failure
-        */
-       public function selectFieldsRow( $fields = null, array $conditions = array(),
-               array $options = array(), $collapse = true, $functionName = null );
-
-       /**
-        * Returns if there is at least one record matching the provided conditions.
-        * Condition field names get prefixed.
-        *
-        * @since 1.20
-        *
-        * @param array $conditions
-        *
-        * @return bool
-        */
-       public function has( array $conditions = array() );
-
-       /**
-        * Checks if the table exists
-        *
-        * @since 1.21
-        *
-        * @return bool
-        */
-       public function exists();
-
-       /**
-        * Returns the amount of matching records.
-        * Condition field names get prefixed.
-        *
-        * Note that this can be expensive on large tables.
-        * In such cases you might want to use DatabaseBase::estimateRowCount instead.
-        *
-        * @since 1.20
-        *
-        * @param array $conditions
-        * @param array $options
-        *
-        * @return int
-        */
-       public function count( array $conditions = array(), array $options = array() );
-
-       /**
-        * Removes the object from the database.
-        *
-        * @since 1.20
-        *
-        * @param array $conditions
-        * @param string|null $functionName
-        *
-        * @return bool Success indicator
-        */
-       public function delete( array $conditions, $functionName = null );
-
-       /**
-        * Get API parameters for the fields supported by this object.
-        *
-        * @since 1.20
-        *
-        * @param bool $requireParams
-        * @param bool $setDefaults
-        *
-        * @return array
-        */
-       public function getAPIParams( $requireParams = false, $setDefaults = false );
-
-       /**
-        * Returns an array with the fields and their descriptions.
-        *
-        * field name => field description
-        *
-        * @since 1.20
-        *
-        * @return array
-        */
-       public function getFieldDescriptions();
-
-       /**
-        * Get the database type used for read operations.
-        *
-        * @since 1.20
-        *
-        * @return int DB_ enum
-        */
-       public function getReadDb();
-
-       /**
-        * Set the database type to use for read operations.
-        *
-        * @param int $db
-        *
-        * @since 1.20
-        */
-       public function setReadDb( $db );
-
-       /**
-        * Get the ID of the any foreign wiki to use as a target for database operations
-        *
-        * @since 1.20
-        *
-        * @return string|bool The target wiki, in a form that LBFactory
-        *   understands (or false if the local wiki is used)
-        */
-       public function getTargetWiki();
-
-       /**
-        * Set the ID of the any foreign wiki to use as a target for database operations
-        *
-        * @param string|bool $wiki The target wiki, in a form that LBFactory
-        *   understands (or false if the local wiki shall be used)
-        *
-        * @since 1.20
-        */
-       public function setTargetWiki( $wiki );
-
-       /**
-        * Get the database type used for read operations.
-        * This is to be used instead of wfGetDB.
-        *
-        * @see LoadBalancer::getConnection
-        *
-        * @since 1.20
-        *
-        * @return DatabaseBase The database object
-        */
-       public function getReadDbConnection();
-
-       /**
-        * Get the database type used for read operations.
-        * This is to be used instead of wfGetDB.
-        *
-        * @see LoadBalancer::getConnection
-        *
-        * @since 1.20
-        *
-        * @return DatabaseBase The database object
-        */
-       public function getWriteDbConnection();
-
-       /**
-        * Get the database type used for read operations.
-        *
-        * @see wfGetLB
-        *
-        * @since 1.20
-        *
-        * @return LoadBalancer The database load balancer object
-        */
-       public function getLoadBalancer();
-
-       /**
-        * Releases the lease on the given database connection. This is useful mainly
-        * for connections to a foreign wiki. It does nothing for connections to the local wiki.
-        *
-        * @see LoadBalancer::reuseConnection
-        *
-        * @param DatabaseBase $db The database
-        *
-        * @since 1.20
-        */
-       public function releaseConnection( DatabaseBase $db );
-
-       /**
-        * Update the records matching the provided conditions by
-        * setting the fields that are keys in the $values param to
-        * their corresponding values.
-        *
-        * @since 1.20
-        *
-        * @param array $values
-        * @param array $conditions
-        *
-        * @return bool Success indicator
-        */
-       public function update( array $values, array $conditions = array() );
-
-       /**
-        * Computes the values of the summary fields of the objects matching the provided conditions.
-        *
-        * @since 1.20
-        *
-        * @param array|string|null $summaryFields
-        * @param array $conditions
-        */
-       public function updateSummaryFields( $summaryFields = null, array $conditions = array() );
-
-       /**
-        * Takes in an associative array with field names as keys and
-        * their values as value. The field names are prefixed with the
-        * db field prefix.
-        *
-        * @since 1.20
-        *
-        * @param array $values
-        *
-        * @return array
-        */
-       public function getPrefixedValues( array $values );
-
-       /**
-        * Takes in a field or array of fields and returns an
-        * array with their prefixed versions, ready for db usage.
-        *
-        * @since 1.20
-        *
-        * @param array $fields
-        *
-        * @return array
-        */
-       public function getPrefixedFields( array $fields );
-
-       /**
-        * Takes in a field and returns an it's prefixed version, ready for db usage.
-        *
-        * @since 1.20
-        *
-        * @param string|array $field
-        *
-        * @return string
-        */
-       public function getPrefixedField( $field );
-
-       /**
-        * Takes an array of field names with prefix and returns the unprefixed equivalent.
-        *
-        * @since 1.20
-        * @deprecated since 1.25, will be removed
-        *
-        * @param string[] $fieldNames
-        *
-        * @return string[]
-        */
-       public function unprefixFieldNames( array $fieldNames );
-
-       /**
-        * Takes a field name with prefix and returns the unprefixed equivalent.
-        *
-        * @since 1.20
-        * @deprecated since 1.25, will be removed
-        *
-        * @param string $fieldName
-        *
-        * @return string
-        */
-       public function unprefixFieldName( $fieldName );
-
-       /**
-        * Get an array with fields from a database result,
-        * that can be fed directly to the constructor or
-        * to setFields.
-        *
-        * @since 1.20
-        *
-        * @param stdClass $result
-        *
-        * @return array
-        */
-       public function getFieldsFromDBResult( stdClass $result );
-
-       /**
-        * Get a new instance of the class from a database result.
-        *
-        * @since 1.20
-        *
-        * @param stdClass $result
-        *
-        * @return IORMRow
-        */
-       public function newRowFromDBResult( stdClass $result );
-
-       /**
-        * Get a new instance of the class from an array.
-        *
-        * @since 1.20
-        *
-        * @param array $data
-        * @param bool $loadDefaults
-        *
-        * @return IORMRow
-        */
-       public function newRow( array $data, $loadDefaults = false );
-
-       /**
-        * Return the names of the fields.
-        *
-        * @since 1.20
-        *
-        * @return array
-        */
-       public function getFieldNames();
-
-       /**
-        * Gets if the object can take a certain field.
-        *
-        * @since 1.20
-        *
-        * @param string $name
-        *
-        * @return bool
-        */
-       public function canHaveField( $name );
-}
diff --git a/includes/db/ORMIterator.php b/includes/db/ORMIterator.php
deleted file mode 100644 (file)
index e8104b6..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-
-/**
- * Interface for Iterators containing IORMRows.
- *
- * 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 ORM
- *
- * @license GNU GPL v2 or later
- * @author Jeroen De Dauw < jeroendedauw@gmail.com >
- */
-interface ORMIterator extends Iterator {
-}
diff --git a/includes/db/ORMResult.php b/includes/db/ORMResult.php
deleted file mode 100644 (file)
index 327d20d..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-<?php
-/**
- * ORMIterator that takes a ResultWrapper object returned from
- * a select operation returning IORMRow objects (ie IORMTable::select).
- *
- * Documentation inline and at https://www.mediawiki.org/wiki/Manual:ORMTable
- *
- * 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 ORMResult.php
- * @ingroup ORM
- *
- * @license GNU GPL v2 or later
- * @author Jeroen De Dauw < jeroendedauw@gmail.com >
- */
-
-class ORMResult implements ORMIterator {
-       /**
-        * @var ResultWrapper
-        */
-       protected $res;
-
-       /**
-        * @var int
-        */
-       protected $key;
-
-       /**
-        * @var IORMRow
-        */
-       protected $current;
-
-       /**
-        * @var IORMTable
-        */
-       protected $table;
-
-       /**
-        * @param IORMTable $table
-        * @param ResultWrapper $res
-        */
-       public function __construct( IORMTable $table, ResultWrapper $res ) {
-               $this->table = $table;
-               $this->res = $res;
-               $this->key = 0;
-               $this->setCurrent( $this->res->current() );
-       }
-
-       /**
-        * @param bool|object $row
-        */
-       protected function setCurrent( $row ) {
-               if ( $row === false ) {
-                       $this->current = false;
-               } else {
-                       $this->current = $this->table->newRowFromDBResult( $row );
-               }
-       }
-
-       /**
-        * @return int
-        */
-       public function count() {
-               return $this->res->numRows();
-       }
-
-       /**
-        * @return bool
-        */
-       public function isEmpty() {
-               return $this->res->numRows() === 0;
-       }
-
-       /**
-        * @return IORMRow
-        */
-       public function current() {
-               return $this->current;
-       }
-
-       /**
-        * @return int
-        */
-       public function key() {
-               return $this->key;
-       }
-
-       public function next() {
-               $row = $this->res->next();
-               $this->setCurrent( $row );
-               $this->key++;
-       }
-
-       public function rewind() {
-               $this->res->rewind();
-               $this->key = 0;
-               $this->setCurrent( $this->res->current() );
-       }
-
-       /**
-        * @return bool
-        */
-       public function valid() {
-               return $this->current !== false;
-       }
-}
diff --git a/includes/db/ORMRow.php b/includes/db/ORMRow.php
deleted file mode 100644 (file)
index b0bade3..0000000
+++ /dev/null
@@ -1,593 +0,0 @@
-<?php
-/**
- * Abstract base class for representing objects that are stored in some DB table.
- * This is basically an ORM-like wrapper around rows in database tables that
- * aims to be both simple and very flexible. It is centered around an associative
- * array of fields and various methods to do common interaction with the database.
- *
- * Documentation inline and at https://www.mediawiki.org/wiki/Manual:ORMTable
- *
- * 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 ORMRow.php
- * @ingroup ORM
- *
- * @license GNU GPL v2 or later
- * @author Jeroen De Dauw < jeroendedauw@gmail.com >
- */
-
-class ORMRow implements IORMRow {
-       /**
-        * The fields of the object.
-        * field name (w/o prefix) => value
-        *
-        * @since 1.20
-        * @var array
-        */
-       protected $fields = array( 'id' => null );
-
-       /**
-        * If the object should update summaries of linked items when changed.
-        * For example, update the course_count field in universities when a course in courses is deleted.
-        * Settings this to false can prevent needless updating work in situations
-        * such as deleting a university, which will then delete all it's courses.
-        *
-        * @deprecated since 1.22
-        * @since 1.20
-        * @var bool
-        */
-       protected $updateSummaries = true;
-
-       /**
-        * Indicates if the object is in summary mode.
-        * This mode indicates that only summary fields got updated,
-        * which allows for optimizations.
-        *
-        * @deprecated since 1.22
-        * @since 1.20
-        * @var bool
-        */
-       protected $inSummaryMode = false;
-
-       /**
-        * @deprecated since 1.22
-        * @since 1.20
-        * @var ORMTable|null
-        */
-       protected $table;
-
-       /**
-        * Constructor.
-        *
-        * @since 1.20
-        *
-        * @param IORMTable|null $table Deprecated since 1.22
-        * @param array|null $fields
-        * @param bool $loadDefaults Deprecated since 1.22
-        */
-       public function __construct( IORMTable $table = null, $fields = null, $loadDefaults = false ) {
-               $this->table = $table;
-
-               if ( !is_array( $fields ) ) {
-                       $fields = array();
-               }
-
-               if ( $loadDefaults ) {
-                       $fields = array_merge( $this->table->getDefaults(), $fields );
-               }
-
-               $this->setFields( $fields );
-       }
-
-       /**
-        * Load the specified fields from the database.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @param array|null $fields
-        * @param bool $override
-        * @param bool $skipLoaded
-        *
-        * @return bool Success indicator
-        */
-       public function loadFields( $fields = null, $override = true, $skipLoaded = false ) {
-               if ( is_null( $this->getId() ) ) {
-                       return false;
-               }
-
-               if ( is_null( $fields ) ) {
-                       $fields = array_keys( $this->table->getFields() );
-               }
-
-               if ( $skipLoaded ) {
-                       $fields = array_diff( $fields, array_keys( $this->fields ) );
-               }
-
-               if ( !empty( $fields ) ) {
-                       $result = $this->table->rawSelectRow(
-                               $this->table->getPrefixedFields( $fields ),
-                               array( $this->table->getPrefixedField( 'id' ) => $this->getId() ),
-                               array( 'LIMIT' => 1 ),
-                               __METHOD__
-                       );
-
-                       if ( $result !== false ) {
-                               $this->setFields( $this->table->getFieldsFromDBResult( $result ), $override );
-
-                               return true;
-                       }
-
-                       return false;
-               }
-
-               return true;
-       }
-
-       /**
-        * Gets the value of a field.
-        *
-        * @since 1.20
-        *
-        * @param string $name Field name
-        * @param mixed $default Default value to return when none is found
-        * (default: null)
-        *
-        * @throws MWException
-        * @return mixed
-        */
-       public function getField( $name, $default = null ) {
-               if ( $this->hasField( $name ) ) {
-                       return $this->fields[$name];
-               } elseif ( !is_null( $default ) ) {
-                       return $default;
-               } else {
-                       throw new MWException( 'Attempted to get not-set field ' . $name );
-               }
-       }
-
-       /**
-        * Gets the value of a field but first loads it if not done so already.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @param string $name
-        *
-        * @return mixed
-        */
-       public function loadAndGetField( $name ) {
-               if ( !$this->hasField( $name ) ) {
-                       $this->loadFields( array( $name ) );
-               }
-
-               return $this->getField( $name );
-       }
-
-       /**
-        * Remove a field.
-        *
-        * @since 1.20
-        *
-        * @param string $name
-        */
-       public function removeField( $name ) {
-               unset( $this->fields[$name] );
-       }
-
-       /**
-        * Returns the objects database id.
-        *
-        * @since 1.20
-        *
-        * @return int|null
-        */
-       public function getId() {
-               return $this->getField( 'id' );
-       }
-
-       /**
-        * Sets the objects database id.
-        *
-        * @since 1.20
-        *
-        * @param int|null $id
-        */
-       public function setId( $id ) {
-               $this->setField( 'id', $id );
-       }
-
-       /**
-        * Gets if a certain field is set.
-        *
-        * @since 1.20
-        *
-        * @param string $name
-        *
-        * @return bool
-        */
-       public function hasField( $name ) {
-               return array_key_exists( $name, $this->fields );
-       }
-
-       /**
-        * Gets if the id field is set.
-        *
-        * @since 1.20
-        *
-        * @return bool
-        */
-       public function hasIdField() {
-               return $this->hasField( 'id' ) && !is_null( $this->getField( 'id' ) );
-       }
-
-       /**
-        * Gets the fields => values to write to the table.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @return array
-        */
-       protected function getWriteValues() {
-               $values = array();
-
-               foreach ( $this->table->getFields() as $name => $type ) {
-                       if ( array_key_exists( $name, $this->fields ) ) {
-                               $value = $this->fields[$name];
-
-                               // Skip null id fields so that the DBMS can set the default.
-                               if ( $name === 'id' && is_null( $value ) ) {
-                                       continue;
-                               }
-
-                               switch ( $type ) {
-                                       case 'array':
-                                               $value = (array)$value;
-                                       // fall-through!
-                                       case 'blob':
-                                               $value = serialize( $value );
-                                       // fall-through!
-                               }
-
-                               $values[$this->table->getPrefixedField( $name )] = $value;
-                       }
-               }
-
-               return $values;
-       }
-
-       /**
-        * Sets multiple fields.
-        *
-        * @since 1.20
-        *
-        * @param array $fields The fields to set
-        * @param bool $override Override already set fields with the provided values?
-        */
-       public function setFields( array $fields, $override = true ) {
-               foreach ( $fields as $name => $value ) {
-                       if ( $override || !$this->hasField( $name ) ) {
-                               $this->setField( $name, $value );
-                       }
-               }
-       }
-
-       /**
-        * Serializes the object to an associative array which
-        * can then easily be converted into JSON or similar.
-        *
-        * @since 1.20
-        *
-        * @param null|array $fields
-        * @param bool $incNullId
-        *
-        * @return array
-        */
-       public function toArray( $fields = null, $incNullId = false ) {
-               $data = array();
-               $setFields = array();
-
-               if ( !is_array( $fields ) ) {
-                       $setFields = $this->getSetFieldNames();
-               } else {
-                       foreach ( $fields as $field ) {
-                               if ( $this->hasField( $field ) ) {
-                                       $setFields[] = $field;
-                               }
-                       }
-               }
-
-               foreach ( $setFields as $field ) {
-                       if ( $incNullId || $field != 'id' || $this->hasIdField() ) {
-                               $data[$field] = $this->getField( $field );
-                       }
-               }
-
-               return $data;
-       }
-
-       /**
-        * Load the default values, via getDefaults.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @param bool $override
-        */
-       public function loadDefaults( $override = true ) {
-               $this->setFields( $this->table->getDefaults(), $override );
-       }
-
-       /**
-        * Writes the answer to the database, either updating it
-        * when it already exists, or inserting it when it doesn't.
-        *
-        * @since 1.20
-        * @deprecated since 1.22 Use IORMTable->updateRow or ->insertRow
-        *
-        * @param string|null $functionName
-        *
-        * @return bool Success indicator
-        */
-       public function save( $functionName = null ) {
-               if ( $this->hasIdField() ) {
-                       return $this->table->updateRow( $this, $functionName );
-               } else {
-                       return $this->table->insertRow( $this, $functionName );
-               }
-       }
-
-       /**
-        * Updates the object in the database.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @param string|null $functionName
-        *
-        * @return bool Success indicator
-        */
-       protected function saveExisting( $functionName = null ) {
-               $dbw = $this->table->getWriteDbConnection();
-
-               $success = $dbw->update(
-                       $this->table->getName(),
-                       $this->getWriteValues(),
-                       $this->table->getPrefixedValues( $this->getUpdateConditions() ),
-                       is_null( $functionName ) ? __METHOD__ : $functionName
-               );
-
-               $this->table->releaseConnection( $dbw );
-
-               // DatabaseBase::update does not always return true for success as documented...
-               return $success !== false;
-       }
-
-       /**
-        * Returns the WHERE considtions needed to identify this object so
-        * it can be updated.
-        *
-        * @since 1.20
-        *
-        * @return array
-        */
-       protected function getUpdateConditions() {
-               return array( 'id' => $this->getId() );
-       }
-
-       /**
-        * Inserts the object into the database.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @param string|null $functionName
-        * @param array|null $options
-        *
-        * @return bool Success indicator
-        */
-       protected function insert( $functionName = null, array $options = null ) {
-               $dbw = $this->table->getWriteDbConnection();
-
-               $success = $dbw->insert(
-                       $this->table->getName(),
-                       $this->getWriteValues(),
-                       is_null( $functionName ) ? __METHOD__ : $functionName,
-                       $options
-               );
-
-               // DatabaseBase::insert does not always return true for success as documented...
-               $success = $success !== false;
-
-               if ( $success ) {
-                       $this->setField( 'id', $dbw->insertId() );
-               }
-
-               $this->table->releaseConnection( $dbw );
-
-               return $success;
-       }
-
-       /**
-        * Removes the object from the database.
-        *
-        * @since 1.20
-        * @deprecated since 1.22, use IORMTable->removeRow
-        *
-        * @return bool Success indicator
-        */
-       public function remove() {
-               $this->beforeRemove();
-
-               $success = $this->table->removeRow( $this, __METHOD__ );
-
-               if ( $success ) {
-                       $this->onRemoved();
-               }
-
-               return $success;
-       }
-
-       /**
-        * Gets called before an object is removed from the database.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        */
-       protected function beforeRemove() {
-               $this->loadFields( $this->getBeforeRemoveFields(), false, true );
-       }
-
-       /**
-        * Before removal of an object happens, @see beforeRemove gets called.
-        * This method loads the fields of which the names have been returned by
-        * this one (or all fields if null is returned). This allows for loading
-        * info needed after removal to get rid of linked data and the like.
-        *
-        * @since 1.20
-        *
-        * @return array|null
-        */
-       protected function getBeforeRemoveFields() {
-               return array();
-       }
-
-       /**
-        * Gets called after successful removal.
-        * Can be overridden to get rid of linked data.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        */
-       protected function onRemoved() {
-               $this->setField( 'id', null );
-       }
-
-       /**
-        * Return the names and values of the fields.
-        *
-        * @since 1.20
-        *
-        * @return array
-        */
-       public function getFields() {
-               return $this->fields;
-       }
-
-       /**
-        * Return the names of the fields.
-        *
-        * @since 1.20
-        *
-        * @return array
-        */
-       public function getSetFieldNames() {
-               return array_keys( $this->fields );
-       }
-
-       /**
-        * Sets the value of a field.
-        * Strings can be provided for other types,
-        * so this method can be called from unserialization handlers.
-        *
-        * @since 1.20
-        *
-        * @param string $name
-        * @param mixed $value
-        *
-        * @throws MWException
-        */
-       public function setField( $name, $value ) {
-               $this->fields[$name] = $value;
-       }
-
-       /**
-        * Add an amount (can be negative) to the specified field (needs to be numeric).
-        *
-        * @since 1.20
-        * @deprecated since 1.22, use IORMTable->addToField
-        *
-        * @param string $field
-        * @param int $amount
-        *
-        * @return bool Success indicator
-        */
-       public function addToField( $field, $amount ) {
-               return $this->table->addToField( $this->getUpdateConditions(), $field, $amount );
-       }
-
-       /**
-        * Return the names of the fields.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @return array
-        */
-       public function getFieldNames() {
-               return array_keys( $this->table->getFields() );
-       }
-
-       /**
-        * Computes and updates the values of the summary fields.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @param array|string|null $summaryFields
-        */
-       public function loadSummaryFields( $summaryFields = null ) {
-       }
-
-       /**
-        * Sets the value for the @see $updateSummaries field.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @param bool $update
-        */
-       public function setUpdateSummaries( $update ) {
-               $this->updateSummaries = $update;
-       }
-
-       /**
-        * Sets the value for the @see $inSummaryMode field.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @param bool $summaryMode
-        */
-       public function setSummaryMode( $summaryMode ) {
-               $this->inSummaryMode = $summaryMode;
-       }
-
-       /**
-        * Returns the table this IORMRow is a row in.
-        *
-        * @since 1.20
-        * @deprecated since 1.22
-        *
-        * @return IORMTable
-        */
-       public function getTable() {
-               return $this->table;
-       }
-}
diff --git a/includes/db/ORMTable.php b/includes/db/ORMTable.php
deleted file mode 100644 (file)
index 562a810..0000000
+++ /dev/null
@@ -1,1144 +0,0 @@
-<?php
-/**
- * Abstract base class for representing a single database table.
- * Documentation inline and at https://www.mediawiki.org/wiki/Manual:ORMTable
- *
- * 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
- * Non-abstract since 1.21
- *
- * @file ORMTable.php
- * @ingroup ORM
- *
- * @license GNU GPL v2 or later
- * @author Jeroen De Dauw < jeroendedauw@gmail.com >
- */
-
-class ORMTable extends DBAccessBase implements IORMTable {
-       /**
-        * Cache for instances, used by the singleton method.
-        *
-        * @since 1.20
-        * @deprecated since 1.21
-        *
-        * @var ORMTable[]
-        */
-       protected static $instanceCache = array();
-
-       /**
-        * @since 1.21
-        *
-        * @var string
-        */
-       protected $tableName;
-
-       /**
-        * @since 1.21
-        *
-        * @var string[]
-        */
-       protected $fields = array();
-
-       /**
-        * @since 1.21
-        *
-        * @var string
-        */
-       protected $fieldPrefix = '';
-
-       /**
-        * @since 1.21
-        *
-        * @var string
-        */
-       protected $rowClass = 'ORMRow';
-
-       /**
-        * @since 1.21
-        *
-        * @var array
-        */
-       protected $defaults = array();
-
-       /**
-        * ID of the database connection to use for read operations.
-        * Can be changed via @see setReadDb.
-        *
-        * @since 1.20
-        *
-        * @var int DB_ enum
-        */
-       protected $readDb = DB_SLAVE;
-
-       /**
-        * Constructor.
-        *
-        * @since 1.21
-        *
-        * @param string $tableName
-        * @param string[] $fields
-        * @param array $defaults
-        * @param string|null $rowClass
-        * @param string $fieldPrefix
-        */
-       public function __construct( $tableName = '', array $fields = array(),
-               array $defaults = array(), $rowClass = null, $fieldPrefix = ''
-       ) {
-               $this->tableName = $tableName;
-               $this->fields = $fields;
-               $this->defaults = $defaults;
-
-               if ( is_string( $rowClass ) ) {
-                       $this->rowClass = $rowClass;
-               }
-
-               $this->fieldPrefix = $fieldPrefix;
-       }
-
-       /**
-        * @see IORMTable::getName
-        *
-        * @since 1.21
-        *
-        * @return string
-        * @throws MWException
-        */
-       public function getName() {
-               if ( $this->tableName === '' ) {
-                       throw new MWException( 'The table name needs to be set' );
-               }
-
-               return $this->tableName;
-       }
-
-       /**
-        * Gets the db field prefix.
-        *
-        * @since 1.20
-        * @deprecated since 1.25, use the $this->fieldPrefix property instead
-        *
-        * @return string
-        */
-       protected function getFieldPrefix() {
-               return $this->fieldPrefix;
-       }
-
-       /**
-        * @see IORMTable::getRowClass
-        *
-        * @since 1.21
-        *
-        * @return string
-        */
-       public function getRowClass() {
-               return $this->rowClass;
-       }
-
-       /**
-        * @see ORMTable::getFields
-        *
-        * @since 1.21
-        *
-        * @return array
-        * @throws MWException
-        */
-       public function getFields() {
-               if ( $this->fields === array() ) {
-                       throw new MWException( 'The table needs to have one or more fields' );
-               }
-
-               return $this->fields;
-       }
-
-       /**
-        * Returns a list of default field values.
-        * field name => field value
-        *
-        * @since 1.20
-        *
-        * @return array
-        */
-       public function getDefaults() {
-               return $this->defaults;
-       }
-
-       /**
-        * Returns a list of the summary fields.
-        * These are fields that cache computed values, such as the amount of linked objects of $type.
-        * This is relevant as one might not want to do actions such as log changes when these get updated.
-        *
-        * @since 1.20
-        *
-        * @return array
-        */
-       public function getSummaryFields() {
-               return array();
-       }
-
-       /**
-        * Selects the specified fields of the records matching the provided
-        * conditions and returns them as DBDataObject. Field names get prefixed.
-        *
-        * @since 1.20
-        *
-        * @param array|string|null $fields
-        * @param array $conditions
-        * @param array $options
-        * @param string|null $functionName
-        *
-        * @return ORMResult
-        */
-       public function select( $fields = null, array $conditions = array(),
-               array $options = array(), $functionName = null
-       ) {
-               $res = $this->rawSelect( $fields, $conditions, $options, $functionName );
-
-               return new ORMResult( $this, $res );
-       }
-
-       /**
-        * Selects the specified fields of the records matching the provided
-        * conditions and returns them as DBDataObject. Field names get prefixed.
-        *
-        * @since 1.20
-        *
-        * @param array|string|null $fields
-        * @param array $conditions
-        * @param array $options
-        * @param string|null $functionName
-        *
-        * @return array Array of row objects
-        * @throws DBQueryError If the query failed (even if the database was in ignoreErrors mode).
-        */
-       public function selectObjects( $fields = null, array $conditions = array(),
-               array $options = array(), $functionName = null
-       ) {
-               $result = $this->selectFields( $fields, $conditions, $options, false, $functionName );
-
-               $objects = array();
-
-               foreach ( $result as $record ) {
-                       $objects[] = $this->newRow( $record );
-               }
-
-               return $objects;
-       }
-
-       /**
-        * Do the actual select.
-        *
-        * @since 1.20
-        *
-        * @param null|string|array $fields
-        * @param array $conditions
-        * @param array $options
-        * @param null|string $functionName
-        * @return ResultWrapper
-        * @throws Exception
-        * @throws MWException
-        */
-       public function rawSelect( $fields = null, array $conditions = array(),
-               array $options = array(), $functionName = null
-       ) {
-               if ( is_null( $fields ) ) {
-                       $fields = array_keys( $this->getFields() );
-               } else {
-                       $fields = (array)$fields;
-               }
-
-               $dbr = $this->getReadDbConnection();
-               $result = $dbr->select(
-                       $this->getName(),
-                       $this->getPrefixedFields( $fields ),
-                       $this->getPrefixedValues( $conditions ),
-                       is_null( $functionName ) ? __METHOD__ : $functionName,
-                       $options
-               );
-
-               /* @var Exception $error */
-               $error = null;
-
-               if ( $result === false ) {
-                       // Database connection was in "ignoreErrors" mode. We don't like that.
-                       // So, we emulate the DBQueryError that should have been thrown.
-                       $error = new DBQueryError(
-                               $dbr,
-                               $dbr->lastError(),
-                               $dbr->lastErrno(),
-                               $dbr->lastQuery(),
-                               is_null( $functionName ) ? __METHOD__ : $functionName
-                       );
-               }
-
-               $this->releaseConnection( $dbr );
-
-               if ( $error ) {
-                       // Note: construct the error before releasing the connection,
-                       // but throw it after.
-                       throw $error;
-               }
-
-               return $result;
-       }
-
-       /**
-        * Selects the specified fields of the records matching the provided
-        * conditions and returns them as associative arrays.
-        * Provided field names get prefixed.
-        * Returned field names will not have a prefix.
-        *
-        * When $collapse is true:
-        * If one field is selected, each item in the result array will be this field.
-        * If two fields are selected, each item in the result array will have as key
-        * the first field and as value the second field.
-        * If more then two fields are selected, each item will be an associative array.
-        *
-        * @since 1.20
-        *
-        * @param array|string|null $fields
-        * @param array $conditions
-        * @param array $options
-        * @param bool $collapse Set to false to always return each result row as associative array.
-        * @param string|null $functionName
-        *
-        * @return array Array of array
-        */
-       public function selectFields( $fields = null, array $conditions = array(),
-               array $options = array(), $collapse = true, $functionName = null
-       ) {
-               $objects = array();
-
-               $result = $this->rawSelect( $fields, $conditions, $options, $functionName );
-
-               foreach ( $result as $record ) {
-                       $objects[] = $this->getFieldsFromDBResult( $record );
-               }
-
-               if ( $collapse ) {
-                       if ( count( $fields ) === 1 ) {
-                               $objects = array_map( 'array_shift', $objects );
-                       } elseif ( count( $fields ) === 2 ) {
-                               $o = array();
-
-                               foreach ( $objects as $object ) {
-                                       $o[array_shift( $object )] = array_shift( $object );
-                               }
-
-                               $objects = $o;
-                       }
-               }
-
-               return $objects;
-       }
-
-       /**
-        * Selects the specified fields of the first matching record.
-        * Field names get prefixed.
-        *
-        * @since 1.20
-        *
-        * @param array|string|null $fields
-        * @param array $conditions
-        * @param array $options
-        * @param string|null $functionName
-        *
-        * @return IORMRow|bool False on failure
-        */
-       public function selectRow( $fields = null, array $conditions = array(),
-               array $options = array(), $functionName = null
-       ) {
-               $options['LIMIT'] = 1;
-
-               $objects = $this->select( $fields, $conditions, $options, $functionName );
-
-               return ( !$objects || $objects->isEmpty() ) ? false : $objects->current();
-       }
-
-       /**
-        * Selects the specified fields of the records matching the provided
-        * conditions. Field names do NOT get prefixed.
-        *
-        * @since 1.20
-        *
-        * @param array $fields
-        * @param array $conditions
-        * @param array $options
-        * @param string|null $functionName
-        *
-        * @return stdClass
-        */
-       public function rawSelectRow( array $fields, array $conditions = array(),
-               array $options = array(), $functionName = null
-       ) {
-               $dbr = $this->getReadDbConnection();
-
-               $result = $dbr->selectRow(
-                       $this->getName(),
-                       $fields,
-                       $conditions,
-                       is_null( $functionName ) ? __METHOD__ : $functionName,
-                       $options
-               );
-
-               $this->releaseConnection( $dbr );
-
-               return $result;
-       }
-
-       /**
-        * Selects the specified fields of the first record matching the provided
-        * conditions and returns it as an associative array, or false when nothing matches.
-        * This method makes use of selectFields and expects the same parameters and
-        * returns the same results (if there are any, if there are none, this method returns false).
-        * @see ORMTable::selectFields
-        *
-        * @since 1.20
-        *
-        * @param array|string|null $fields
-        * @param array $conditions
-        * @param array $options
-        * @param bool $collapse Set to false to always return each result row as associative array.
-        * @param string|null $functionName
-        *
-        * @return mixed|array|bool False on failure
-        */
-       public function selectFieldsRow( $fields = null, array $conditions = array(),
-               array $options = array(), $collapse = true, $functionName = null
-       ) {
-               $options['LIMIT'] = 1;
-
-               $objects = $this->selectFields( $fields, $conditions, $options, $collapse, $functionName );
-
-               return empty( $objects ) ? false : $objects[0];
-       }
-
-       /**
-        * Returns if there is at least one record matching the provided conditions.
-        * Condition field names get prefixed.
-        *
-        * @since 1.20
-        *
-        * @param array $conditions
-        *
-        * @return bool
-        */
-       public function has( array $conditions = array() ) {
-               return $this->selectRow( array( 'id' ), $conditions ) !== false;
-       }
-
-       /**
-        * Checks if the table exists
-        *
-        * @since 1.21
-        *
-        * @return bool
-        */
-       public function exists() {
-               $dbr = $this->getReadDbConnection();
-               $exists = $dbr->tableExists( $this->getName() );
-               $this->releaseConnection( $dbr );
-
-               return $exists;
-       }
-
-       /**
-        * Returns the amount of matching records.
-        * Condition field names get prefixed.
-        *
-        * Note that this can be expensive on large tables.
-        * In such cases you might want to use DatabaseBase::estimateRowCount instead.
-        *
-        * @since 1.20
-        *
-        * @param array $conditions
-        * @param array $options
-        *
-        * @return int
-        */
-       public function count( array $conditions = array(), array $options = array() ) {
-               $res = $this->rawSelectRow(
-                       array( 'rowcount' => 'COUNT(*)' ),
-                       $this->getPrefixedValues( $conditions ),
-                       $options,
-                       __METHOD__
-               );
-
-               return $res->rowcount;
-       }
-
-       /**
-        * Removes the object from the database.
-        *
-        * @since 1.20
-        *
-        * @param array $conditions
-        * @param string|null $functionName
-        *
-        * @return bool Success indicator
-        */
-       public function delete( array $conditions, $functionName = null ) {
-               $dbw = $this->getWriteDbConnection();
-
-               $result = $dbw->delete(
-                       $this->getName(),
-                       $conditions === array() ? '*' : $this->getPrefixedValues( $conditions ),
-                       is_null( $functionName ) ? __METHOD__ : $functionName
-               ) !== false; // DatabaseBase::delete does not always return true for success as documented...
-
-               $this->releaseConnection( $dbw );
-
-               return $result;
-       }
-
-       /**
-        * Get API parameters for the fields supported by this object.
-        *
-        * @since 1.20
-        *
-        * @param bool $requireParams
-        * @param bool $setDefaults
-        *
-        * @return array
-        */
-       public function getAPIParams( $requireParams = false, $setDefaults = false ) {
-               $typeMap = array(
-                       'id' => 'integer',
-                       'int' => 'integer',
-                       'float' => 'NULL',
-                       'str' => 'string',
-                       'bool' => 'integer',
-                       'array' => 'string',
-                       'blob' => 'string',
-               );
-
-               $params = array();
-               $defaults = $this->getDefaults();
-
-               foreach ( $this->getFields() as $field => $type ) {
-                       if ( $field == 'id' ) {
-                               continue;
-                       }
-
-                       $hasDefault = array_key_exists( $field, $defaults );
-
-                       $params[$field] = array(
-                               ApiBase::PARAM_TYPE => $typeMap[$type],
-                               ApiBase::PARAM_REQUIRED => $requireParams && !$hasDefault
-                       );
-
-                       if ( $type == 'array' ) {
-                               $params[$field][ApiBase::PARAM_ISMULTI] = true;
-                       }
-
-                       if ( $setDefaults && $hasDefault ) {
-                               $default = is_array( $defaults[$field] )
-                                       ? implode( '|', $defaults[$field] )
-                                       : $defaults[$field];
-                               $params[$field][ApiBase::PARAM_DFLT] = $default;
-                       }
-               }
-
-               return $params;
-       }
-
-       /**
-        * Returns an array with the fields and their descriptions.
-        *
-        * field name => field description
-        *
-        * @since 1.20
-        *
-        * @return array
-        */
-       public function getFieldDescriptions() {
-               return array();
-       }
-
-       /**
-        * Get the database ID used for read operations.
-        *
-        * @since 1.20
-        *
-        * @return int DB_ enum
-        */
-       public function getReadDb() {
-               return $this->readDb;
-       }
-
-       /**
-        * Set the database ID to use for read operations, use DB_XXX constants or
-        *   an index to the load balancer setup.
-        *
-        * @param int $db
-        *
-        * @since 1.20
-        */
-       public function setReadDb( $db ) {
-               $this->readDb = $db;
-       }
-
-       /**
-        * Get the ID of the any foreign wiki to use as a target for database operations
-        *
-        * @since 1.20
-        *
-        * @return string|bool The target wiki, in a form that LBFactory understands
-        *   (or false if the local wiki is used)
-        */
-       public function getTargetWiki() {
-               return $this->wiki;
-       }
-
-       /**
-        * Set the ID of the any foreign wiki to use as a target for database operations
-        *
-        * @param string|bool $wiki The target wiki, in a form that  LBFactory
-        *   understands (or false if the local wiki shall be used)
-        *
-        * @since 1.20
-        */
-       public function setTargetWiki( $wiki ) {
-               $this->wiki = $wiki;
-       }
-
-       /**
-        * Get the database type used for read operations.
-        * This is to be used instead of wfGetDB.
-        *
-        * @see LoadBalancer::getConnection
-        *
-        * @since 1.20
-        *
-        * @return DatabaseBase The database object
-        */
-       public function getReadDbConnection() {
-               return $this->getConnection( $this->getReadDb(), array() );
-       }
-
-       /**
-        * Get the database type used for read operations.
-        * This is to be used instead of wfGetDB.
-        *
-        * @see LoadBalancer::getConnection
-        *
-        * @since 1.20
-        *
-        * @return DatabaseBase The database object
-        */
-       public function getWriteDbConnection() {
-               return $this->getConnection( DB_MASTER, array() );
-       }
-
-       /**
-        * Releases the lease on the given database connection. This is useful mainly
-        * for connections to a foreign wiki. It does nothing for connections to the local wiki.
-        *
-        * @see LoadBalancer::reuseConnection
-        *
-        * @param DatabaseBase $db
-        *
-        * @since 1.20
-        */
-       // @codingStandardsIgnoreStart Suppress "useless method overriding" sniffer warning
-       public function releaseConnection( DatabaseBase $db ) {
-               parent::releaseConnection( $db ); // just make it public
-       }
-       // @codingStandardsIgnoreEnd
-
-       /**
-        * Update the records matching the provided conditions by
-        * setting the fields that are keys in the $values param to
-        * their corresponding values.
-        *
-        * @since 1.20
-        *
-        * @param array $values
-        * @param array $conditions
-        *
-        * @return bool Success indicator
-        */
-       public function update( array $values, array $conditions = array() ) {
-               $dbw = $this->getWriteDbConnection();
-
-               $result = $dbw->update(
-                       $this->getName(),
-                       $this->getPrefixedValues( $values ),
-                       $this->getPrefixedValues( $conditions ),
-                       __METHOD__
-               ) !== false; // DatabaseBase::update does not always return true for success as documented...
-
-               $this->releaseConnection( $dbw );
-
-               return $result;
-       }
-
-       /**
-        * Computes the values of the summary fields of the objects matching the provided conditions.
-        *
-        * @since 1.20
-        *
-        * @param array|string|null $summaryFields
-        * @param array $conditions
-        */
-       public function updateSummaryFields( $summaryFields = null, array $conditions = array() ) {
-               $slave = $this->getReadDb();
-               $this->setReadDb( DB_MASTER );
-
-               /**
-                * @var IORMRow $item
-                */
-               foreach ( $this->select( null, $conditions ) as $item ) {
-                       $item->loadSummaryFields( $summaryFields );
-                       $item->setSummaryMode( true );
-                       $item->save();
-               }
-
-               $this->setReadDb( $slave );
-       }
-
-       /**
-        * Takes in an associative array with field names as keys and
-        * their values as value. The field names are prefixed with the
-        * db field prefix.
-        *
-        * @since 1.20
-        *
-        * @param array $values
-        *
-        * @return array
-        */
-       public function getPrefixedValues( array $values ) {
-               $prefixedValues = array();
-
-               foreach ( $values as $field => $value ) {
-                       if ( is_integer( $field ) ) {
-                               if ( is_array( $value ) ) {
-                                       $field = $value[0];
-                                       $value = $value[1];
-                               } else {
-                                       $value = explode( ' ', $value, 2 );
-                                       $value[0] = $this->getPrefixedField( $value[0] );
-                                       $prefixedValues[] = implode( ' ', $value );
-                                       continue;
-                               }
-                       }
-
-                       $prefixedValues[$this->getPrefixedField( $field )] = $value;
-               }
-
-               return $prefixedValues;
-       }
-
-       /**
-        * Takes in a field or array of fields and returns an
-        * array with their prefixed versions, ready for db usage.
-        *
-        * @since 1.20
-        *
-        * @param array $fields
-        *
-        * @return array
-        */
-       public function getPrefixedFields( array $fields ) {
-               foreach ( $fields as &$field ) {
-                       $field = $this->getPrefixedField( $field );
-               }
-
-               return $fields;
-       }
-
-       /**
-        * Takes in a field and returns an it's prefixed version, ready for db usage.
-        *
-        * @since 1.20
-        *
-        * @param string|array $field
-        *
-        * @return string
-        */
-       public function getPrefixedField( $field ) {
-               return $this->fieldPrefix . $field;
-       }
-
-       /**
-        * Takes an array of field names with prefix and returns the unprefixed equivalent.
-        *
-        * @since 1.20
-        * @deprecated since 1.25, will be removed
-        *
-        * @param string[] $fieldNames
-        *
-        * @return string[]
-        */
-       public function unprefixFieldNames( array $fieldNames ) {
-               wfDeprecated( __METHOD__, '1.25' );
-
-               return $this->stripFieldPrefix( $fieldNames );
-       }
-
-       /**
-        * Takes an array of field names with prefix and returns the unprefixed equivalent.
-        *
-        * @param string[] $fieldNames
-        *
-        * @return string[]
-        */
-       private function stripFieldPrefix( array $fieldNames ) {
-               $start = strlen( $this->fieldPrefix );
-
-               return array_map( function ( $fieldName ) use ( $start ) {
-                       return substr( $fieldName, $start );
-               }, $fieldNames );
-       }
-
-       /**
-        * Takes a field name with prefix and returns the unprefixed equivalent.
-        *
-        * @since 1.20
-        * @deprecated since 1.25, will be removed
-        *
-        * @param string $fieldName
-        *
-        * @return string
-        */
-       public function unprefixFieldName( $fieldName ) {
-               wfDeprecated( __METHOD__, '1.25' );
-
-               return substr( $fieldName, strlen( $this->fieldPrefix ) );
-       }
-
-       /**
-        * Get an instance of this class.
-        *
-        * @since 1.20
-        * @deprecated since 1.21
-        *
-        * @return IORMTable
-        */
-       public static function singleton() {
-               $class = get_called_class();
-
-               if ( !array_key_exists( $class, self::$instanceCache ) ) {
-                       self::$instanceCache[$class] = new $class;
-               }
-
-               return self::$instanceCache[$class];
-       }
-
-       /**
-        * Get an array with fields from a database result,
-        * that can be fed directly to the constructor or
-        * to setFields.
-        *
-        * @since 1.20
-        *
-        * @param stdClass $result
-        * @throws MWException
-        * @return array
-        */
-       public function getFieldsFromDBResult( stdClass $result ) {
-               $result = (array)$result;
-
-               $rawFields = array_combine(
-                       $this->stripFieldPrefix( array_keys( $result ) ),
-                       array_values( $result )
-               );
-
-               $fieldDefinitions = $this->getFields();
-               $fields = array();
-
-               foreach ( $rawFields as $name => $value ) {
-                       if ( array_key_exists( $name, $fieldDefinitions ) ) {
-                               switch ( $fieldDefinitions[$name] ) {
-                                       case 'int':
-                                               $value = (int)$value;
-                                               break;
-                                       case 'float':
-                                               $value = (float)$value;
-                                               break;
-                                       case 'bool':
-                                               if ( is_string( $value ) ) {
-                                                       $value = $value !== '0';
-                                               } elseif ( is_int( $value ) ) {
-                                                       $value = $value !== 0;
-                                               }
-                                               break;
-                                       case 'array':
-                                               if ( is_string( $value ) ) {
-                                                       $value = unserialize( $value );
-                                               }
-
-                                               if ( !is_array( $value ) ) {
-                                                       $value = array();
-                                               }
-                                               break;
-                                       case 'blob':
-                                               if ( is_string( $value ) ) {
-                                                       $value = unserialize( $value );
-                                               }
-                                               break;
-                                       case 'id':
-                                               if ( is_string( $value ) ) {
-                                                       $value = (int)$value;
-                                               }
-                                               break;
-                               }
-
-                               $fields[$name] = $value;
-                       } else {
-                               throw new MWException( 'Attempted to set unknown field ' . $name );
-                       }
-               }
-
-               return $fields;
-       }
-
-       /**
-        * @see ORMTable::newRowFromFromDBResult
-        *
-        * @deprecated since 1.20 use newRowFromDBResult instead
-        * @since 1.20
-        *
-        * @param stdClass $result
-        *
-        * @return IORMRow
-        */
-       public function newFromDBResult( stdClass $result ) {
-               return self::newRowFromDBResult( $result );
-       }
-
-       /**
-        * Get a new instance of the class from a database result.
-        *
-        * @since 1.20
-        *
-        * @param stdClass $result
-        *
-        * @return IORMRow
-        */
-       public function newRowFromDBResult( stdClass $result ) {
-               return $this->newRow( $this->getFieldsFromDBResult( $result ) );
-       }
-
-       /**
-        * @see ORMTable::newRow
-        *
-        * @deprecated since 1.20 use newRow instead
-        * @since 1.20
-        *
-        * @param array $data
-        * @param bool $loadDefaults
-        *
-        * @return IORMRow
-        */
-       public function newFromArray( array $data, $loadDefaults = false ) {
-               return static::newRow( $data, $loadDefaults );
-       }
-
-       /**
-        * Get a new instance of the class from an array.
-        *
-        * @since 1.20
-        *
-        * @param array $fields
-        * @param bool $loadDefaults
-        *
-        * @return IORMRow
-        */
-       public function newRow( array $fields, $loadDefaults = false ) {
-               $class = $this->getRowClass();
-
-               return new $class( $this, $fields, $loadDefaults );
-       }
-
-       /**
-        * Return the names of the fields.
-        *
-        * @since 1.20
-        *
-        * @return array
-        */
-       public function getFieldNames() {
-               return array_keys( $this->getFields() );
-       }
-
-       /**
-        * Gets if the object can take a certain field.
-        *
-        * @since 1.20
-        *
-        * @param string $name
-        *
-        * @return bool
-        */
-       public function canHaveField( $name ) {
-               return array_key_exists( $name, $this->getFields() );
-       }
-
-       /**
-        * Updates the provided row in the database.
-        *
-        * @since 1.22
-        *
-        * @param IORMRow $row The row to save
-        * @param string|null $functionName
-        *
-        * @return bool Success indicator
-        */
-       public function updateRow( IORMRow $row, $functionName = null ) {
-               $dbw = $this->getWriteDbConnection();
-
-               $success = $dbw->update(
-                       $this->getName(),
-                       $this->getWriteValues( $row ),
-                       $this->getPrefixedValues( array( 'id' => $row->getId() ) ),
-                       is_null( $functionName ) ? __METHOD__ : $functionName
-               );
-
-               $this->releaseConnection( $dbw );
-
-               // DatabaseBase::update does not always return true for success as documented...
-               return $success !== false;
-       }
-
-       /**
-        * Inserts the provided row into the database.
-        *
-        * @since 1.22
-        *
-        * @param IORMRow $row
-        * @param string|null $functionName
-        * @param array|null $options
-        *
-        * @return bool Success indicator
-        */
-       public function insertRow( IORMRow $row, $functionName = null, array $options = null ) {
-               $dbw = $this->getWriteDbConnection();
-
-               $success = $dbw->insert(
-                       $this->getName(),
-                       $this->getWriteValues( $row ),
-                       is_null( $functionName ) ? __METHOD__ : $functionName,
-                       $options
-               );
-
-               // DatabaseBase::insert does not always return true for success as documented...
-               $success = $success !== false;
-
-               if ( $success ) {
-                       $row->setField( 'id', $dbw->insertId() );
-               }
-
-               $this->releaseConnection( $dbw );
-
-               return $success;
-       }
-
-       /**
-        * Gets the fields => values to write to the table.
-        *
-        * @since 1.22
-        *
-        * @param IORMRow $row
-        *
-        * @return array
-        */
-       protected function getWriteValues( IORMRow $row ) {
-               $values = array();
-
-               $rowFields = $row->getFields();
-
-               foreach ( $this->getFields() as $name => $type ) {
-                       if ( array_key_exists( $name, $rowFields ) ) {
-                               $value = $rowFields[$name];
-
-                               switch ( $type ) {
-                                       case 'array':
-                                               $value = (array)$value;
-                                       // fall-through!
-                                       case 'blob':
-                                               $value = serialize( $value );
-                                       // fall-through!
-                               }
-
-                               $values[$this->getPrefixedField( $name )] = $value;
-                       }
-               }
-
-               return $values;
-       }
-
-       /**
-        * Removes the provided row from the database.
-        *
-        * @since 1.22
-        *
-        * @param IORMRow $row
-        * @param string|null $functionName
-        *
-        * @return bool Success indicator
-        */
-       public function removeRow( IORMRow $row, $functionName = null ) {
-               $success = $this->delete(
-                       array( 'id' => $row->getId() ),
-                       is_null( $functionName ) ? __METHOD__ : $functionName
-               );
-
-               // DatabaseBase::delete does not always return true for success as documented...
-               return $success !== false;
-       }
-
-       /**
-        * Add an amount (can be negative) to the specified field (needs to be numeric).
-        *
-        * @since 1.22
-        *
-        * @param array $conditions
-        * @param string $field
-        * @param int $amount
-        *
-        * @return bool Success indicator
-        * @throws MWException
-        */
-       public function addToField( array $conditions, $field, $amount ) {
-               if ( !array_key_exists( $field, $this->fields ) ) {
-                       throw new MWException( 'Unknown field "' . $field . '" provided' );
-               }
-
-               if ( $amount == 0 ) {
-                       return true;
-               }
-
-               $absoluteAmount = abs( $amount );
-               $isNegative = $amount < 0;
-
-               $fullField = $this->getPrefixedField( $field );
-
-               $dbw = $this->getWriteDbConnection();
-
-               $success = $dbw->update(
-                       $this->getName(),
-                       array( "$fullField=$fullField" . ( $isNegative ? '-' : '+' ) . $absoluteAmount ),
-                       $this->getPrefixedValues( $conditions ),
-                       __METHOD__
-               ) !== false; // DatabaseBase::update does not always return true for success as documented...
-
-               $this->releaseConnection( $dbw );
-
-               return $success;
-       }
-}
index eaf15df..d2cd0e4 100644 (file)
@@ -256,7 +256,7 @@ class Xhprof {
                                        }
 
                                        for ( $i = 0; $i < $stats['ct']; $i++ ) {
-                                               $this->inclusive[$child][$stat]->push(
+                                               $this->inclusive[$child][$stat]->addObservation(
                                                        $value / $stats['ct']
                                                );
                                        }
index 5338e3a..6ef2bce 100644 (file)
@@ -89,7 +89,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
        /** Seconds to keep dependency purge keys around */
        const CHECK_KEY_TTL = self::TTL_YEAR;
        /** Seconds to keep lock keys around */
-       const LOCK_TTL = 5;
+       const LOCK_TTL = 10;
        /** Default remaining TTL at which to consider pre-emptive regeneration */
        const LOW_TTL = 30;
        /** Default time-since-expiry on a miss that makes a key "hot" */
@@ -104,6 +104,9 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
        /** Max TTL to store keys when a data sourced is lagged */
        const TTL_LAGGED = 30;
 
+       /** Tiny negative float to use when CTL comes up >= 0 due to clock skew */
+       const TINY_NEGATIVE = -0.000001;
+
        /** Cache format version number */
        const VERSION = 1;
 
@@ -111,6 +114,10 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
        const FLD_VALUE = 1;
        const FLD_TTL = 2;
        const FLD_TIME = 3;
+       const FLD_FLAGS = 4;
+
+       /** @var integer Treat this value as expired-on-arrival */
+       const FLG_STALE = 1;
 
        const ERR_NONE = 0; // no error
        const ERR_NO_RESPONSE = 1; // no response
@@ -159,11 +166,11 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
        /**
         * Fetch the value of a key from cache
         *
-        * If passed in, $curTTL is set to the remaining TTL (current time left):
-        *   - a) INF; if the key exists, has no TTL, and is not expired by $checkKeys
-        *   - b) float (>=0); if the key exists, has a TTL, and is not expired by $checkKeys
-        *   - c) float (<0); if the key is tombstoned or existing but expired by $checkKeys
-        *   - d) null; if the key does not exist and is not tombstoned
+        * If supplied, $curTTL is set to the remaining TTL (current time left):
+        *   - a) INF; if $key exists, has no TTL, and is not expired by $checkKeys
+        *   - b) float (>=0); if $key exists, has a TTL, and is not expired by $checkKeys
+        *   - c) float (<0); if $key is tombstoned, stale, or existing but expired by $checkKeys
+        *   - d) null; if $key does not exist and is not tombstoned
         *
         * If a key is tombstoned, $curTTL will reflect the time since delete().
         *
@@ -314,10 +321,9 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         *               Generally, other threads should not see values from the future and
         *               they certainly should not see ones that ended up getting rolled back.
         *               Default: false
-        *   - lockTSE : if excessive possible snapshot lag is detected,
-        *               then stash the value into a temporary location
-        *               with this TTL. This is only useful if the reads
-        *               use getWithSetCallback() with "lockTSE" set.
+        *   - lockTSE : if excessive replication/snapshot lag is detected, then store the value
+        *               with this TTL and flag it as stale. This is only useful if the reads for
+        *               this key use getWithSetCallback() with "lockTSE" set.
         *               Default: WANObjectCache::TSE_NONE
         * @return bool Success
         */
@@ -325,29 +331,31 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
                $lockTSE = isset( $opts['lockTSE'] ) ? $opts['lockTSE'] : self::TSE_NONE;
                $age = isset( $opts['since'] ) ? max( 0, microtime( true ) - $opts['since'] ) : 0;
                $lag = isset( $opts['lag'] ) ? $opts['lag'] : 0;
-               // Disallow set() if the source data is uncommitted as it might get rolled back
+
+               // Do not cache potentially uncommitted data as it might get rolled back
                if ( !empty( $opts['pending'] ) ) {
                        $this->logger->info( "Rejected set() for $key due to pending writes." );
 
                        return true; // no-op the write for being unsafe
                }
+
+               $wrapExtra = array(); // additional wrapped value fields
                // Check if there's a risk of writing stale data after the purge tombstone expired
                if ( ( $lag + $age ) > self::MAX_READ_LAG ) {
+                       // Case A: read lag with "lockTSE"; save but record value as stale
                        if ( $lockTSE >= 0 ) {
-                               // Focus on avoiding stampedes; stash the value with a low TTL
-                               $tempTTL = max( 1, (int)$lockTSE ); // set() expects seconds
-                               $this->cache->set( self::STASH_KEY_PREFIX . $key, $value, $tempTTL );
-                       }
-                       // Case A: any long-running transaction; ignore this set()
-                       if ( $age > self::MAX_READ_LAG ) {
+                               $ttl = max( 1, (int)$lockTSE ); // set() expects seconds
+                               $wrapExtra[self::FLD_FLAGS] = self::FLG_STALE; // mark as stale
+                       // Case B: any long-running transaction; ignore this set()
+                       } elseif ( $age > self::MAX_READ_LAG ) {
                                $this->logger->warning( "Rejected set() for $key due to snapshot lag." );
 
                                return true; // no-op the write for being unsafe
-                       // Case B: replication lag is high; lower TTL instead of ignoring all set()s
+                       // Case C: high replication lag; lower TTL instead of ignoring all set()s
                        } elseif ( $lag > self::MAX_READ_LAG ) {
                                $ttl = $ttl ? min( $ttl, self::TTL_LAGGED ) : self::TTL_LAGGED;
                                $this->logger->warning( "Lowered set() TTL for $key due to replication lag." );
-                       // Case C: medium length request during medium lag; ignore this set()
+                       // Case D: medium length request with medium replication lag; ignore this set()
                        } else {
                                $this->logger->warning( "Rejected set() for $key due to high read lag." );
 
@@ -355,7 +363,8 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
                        }
                }
 
-               $wrapped = $this->wrap( $value, $ttl );
+               // Wrap that value with time/TTL/version metadata
+               $wrapped = $this->wrap( $value, $ttl ) + $wrapExtra;
 
                $func = function ( $cache, $key, $cWrapped ) use ( $wrapped ) {
                        return ( is_string( $cWrapped ) )
@@ -922,7 +931,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         *
         * @param mixed $value
         * @param integer $ttl [0=forever]
-        * @return string
+        * @return array
         */
        protected function wrap( $value, $ttl ) {
                return array(
@@ -945,7 +954,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
                $purgeTimestamp = self::parsePurgeValue( $wrapped );
                if ( is_float( $purgeTimestamp ) ) {
                        // Purged values should always have a negative current $ttl
-                       $curTTL = min( -0.000001, $purgeTimestamp - $now );
+                       $curTTL = min( $purgeTimestamp - $now, self::TINY_NEGATIVE );
                        return array( false, $curTTL );
                }
 
@@ -956,7 +965,12 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
                        return array( false, null );
                }
 
-               if ( $wrapped[self::FLD_TTL] > 0 ) {
+               $flags = isset( $wrapped[self::FLD_FLAGS] ) ? $wrapped[self::FLD_FLAGS] : 0;
+               if ( ( $flags & self::FLG_STALE ) == self::FLG_STALE ) {
+                       // Treat as expired, with the cache time as the expiration
+                       $age = $now - $wrapped[self::FLD_TIME];
+                       $curTTL = min( -$age, self::TINY_NEGATIVE );
+               } elseif ( $wrapped[self::FLD_TTL] > 0 ) {
                        // Get the approximate time left on the key
                        $age = $now - $wrapped[self::FLD_TIME];
                        $curTTL = max( $wrapped[self::FLD_TTL] - $age, 0.0 );
index 3a2bb17..746e15b 100644 (file)
@@ -51,6 +51,24 @@ class MWTidy {
                return $driver->tidy( $text );
        }
 
+       /**
+        * Get CSS modules needed if HTML from the current driver is to be displayed.
+        *
+        * This is just a migration tool to allow some changes expected as part of
+        * Tidy replacement (T89331) to be exposed on the client side via user
+        * scripts, without actually replacing tidy. See T49673.
+        *
+        * @return array
+        */
+       public static function getModuleStyles() {
+               $driver = self::singleton();
+               if ( $driver && $driver instanceof MediaWiki\Tidy\RaggettBase ) {
+                       return array( 'mediawiki.raggett' );
+               } else {
+                       return array();
+               }
+       }
+
        /**
         * Check HTML for errors, used if $wgValidateAllHtml = true.
         *
index 9060756..cfbf0b4 100644 (file)
@@ -1340,6 +1340,7 @@ class Parser {
 
                if ( MWTidy::isEnabled() && $this->mOptions->getTidy() ) {
                        $text = MWTidy::tidy( $text );
+                       $this->mOutput->addModuleStyles( MWTidy::getModuleStyles() );
                } else {
                        # attempt to sanitize at least some nesting problems
                        # (bug #2702 and quite a few others)
index 12ebb54..08e4885 100644 (file)
@@ -1225,29 +1225,31 @@ abstract class Skin extends ContextSource {
        function buildSidebar() {
                global $wgEnableSidebarCache, $wgSidebarCacheExpiry;
 
-               $cache = ObjectCache::getMainWANInstance();
-               $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
+               $that = $this;
+               $callback = function () use ( $that ) {
+                       $bar = array();
+                       $that->addToSidebar( $bar, 'sidebar' );
+                       Hooks::run( 'SkinBuildSidebar', array( $that, &$bar ) );
 
-               if ( $wgEnableSidebarCache ) {
-                       $cachedsidebar = $cache->get( $key );
-                       if ( $cachedsidebar ) {
-                               Hooks::run( 'SidebarBeforeOutput', array( $this, &$cachedsidebar ) );
-
-                               return $cachedsidebar;
-                       }
-               }
+                       return $bar;
+               };
 
-               $bar = array();
-               $this->addToSidebar( $bar, 'sidebar' );
-
-               Hooks::run( 'SkinBuildSidebar', array( $this, &$bar ) );
                if ( $wgEnableSidebarCache ) {
-                       $cache->set( $key, $bar, $wgSidebarCacheExpiry );
+                       $cache = ObjectCache::getMainWANInstance();
+                       $sidebar = $cache->getWithSetCallback(
+                               $cache->makeKey( 'sidebar', $this->getLanguage()->getCode() ),
+                               $wgSidebarCacheExpiry,
+                               $callback,
+                               array( 'lockTSE' => 30 )
+                       );
+               } else {
+                       $sidebar = $callback();
                }
 
-               Hooks::run( 'SidebarBeforeOutput', array( $this, &$bar ) );
+               // Apply post-processing to the cached value
+               Hooks::run( 'SidebarBeforeOutput', array( $this, &$sidebar ) );
 
-               return $bar;
+               return $sidebar;
        }
 
        /**
@@ -1259,7 +1261,7 @@ abstract class Skin extends ContextSource {
         * @param array $bar
         * @param string $message
         */
-       function addToSidebar( &$bar, $message ) {
+       public function addToSidebar( &$bar, $message ) {
                $this->addToSidebarPlain( $bar, wfMessage( $message )->inContentLanguage()->plain() );
        }
 
index 3f549d0..4759023 100644 (file)
@@ -51,6 +51,11 @@ class RaggettWrapper {
                // we can trick Tidy into not stripping them out by including them in tidy's new-empty-tags config
                $wrappedtext = preg_replace( '!<(link|meta)([^>]*?)(/{0,1}>)!', '<html-$1$2$3', $wrappedtext );
 
+               // Preserve empty li elements (T49673) by abusing Tidy's datafld hack
+               // The whitespace class is as in TY_(InitMap)
+               $wrappedtext = preg_replace( "!<li>([ \r\n\t\f]*)</li>!",
+                       '<li datafld="" class="mw-empty-li">\1</li>', $wrappedtext );
+
                // Wrap the whole thing in a doctype and body for Tidy.
                $wrappedtext = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' .
                        ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>' .
@@ -79,6 +84,9 @@ class RaggettWrapper {
                // Revert <html-{link,meta}> back to <{link,meta}>
                $text = preg_replace( '!<html-(link|meta)([^>]*?)(/{0,1}>)!', '<$1$2$3', $text );
 
+               // Remove datafld
+               $text = str_replace( '<li datafld=""', '<li', $text );
+
                // Restore the contents of placeholder tokens
                $text = $this->mTokens->replace( $text );
 
index 3ea2693..c7871c1 100644 (file)
@@ -207,10 +207,7 @@ class Language {
         * @return Language
         */
        protected static function newFromCode( $code ) {
-               // Protect against path traversal below
-               if ( !Language::isValidCode( $code )
-                       || strcspn( $code, ":/\\\000" ) !== strlen( $code )
-               ) {
+               if ( !Language::isValidCode( $code ) ) {
                        throw new MWException( "Invalid language code \"$code\"" );
                }
 
@@ -224,7 +221,6 @@ class Language {
 
                // Check if there is a language class for the code
                $class = self::classFromCode( $code );
-               self::preloadLanguageClass( $class );
                if ( class_exists( $class ) ) {
                        $lang = new $class;
                        return $lang;
@@ -238,9 +234,8 @@ class Language {
                        }
 
                        $class = self::classFromCode( $fallbackCode );
-                       self::preloadLanguageClass( $class );
                        if ( class_exists( $class ) ) {
-                               $lang = Language::newFromCode( $fallbackCode );
+                               $lang = new $class;
                                $lang->setCode( $code );
                                return $lang;
                        }
@@ -341,17 +336,16 @@ class Language {
         */
        public static function isValidCode( $code ) {
                static $cache = array();
-               if ( isset( $cache[$code] ) ) {
-                       return $cache[$code];
+               if ( !isset( $cache[$code] ) ) {
+                       // People think language codes are html safe, so enforce it.
+                       // Ideally we should only allow a-zA-Z0-9-
+                       // but, .+ and other chars are often used for {{int:}} hacks
+                       // see bugs 37564, 37587, 36938
+                       $cache[$code] =
+                               // Protect against path traversal
+                               strcspn( $code, ":/\\\000&<>'\"" ) === strlen( $code )
+                               && !preg_match( MediaWikiTitleCodec::getTitleInvalidRegex(), $code );
                }
-               // People think language codes are html safe, so enforce it.
-               // Ideally we should only allow a-zA-Z0-9-
-               // but, .+ and other chars are often used for {{int:}} hacks
-               // see bugs 37564, 37587, 36938
-               $cache[$code] =
-                       strcspn( $code, ":/\\\000&<>'\"" ) === strlen( $code )
-                       && !preg_match( MediaWikiTitleCodec::getTitleInvalidRegex(), $code );
-
                return $cache[$code];
        }
 
@@ -411,35 +405,6 @@ class Language {
                return false;
        }
 
-       /**
-        * @param string $code
-        * @return string Name of the language class
-        */
-       public static function classFromCode( $code ) {
-               if ( $code == 'en' ) {
-                       return 'Language';
-               } else {
-                       return 'Language' . str_replace( '-', '_', ucfirst( $code ) );
-               }
-       }
-
-       /**
-        * Includes language class files
-        *
-        * @param string $class Name of the language class
-        */
-       public static function preloadLanguageClass( $class ) {
-               global $IP;
-
-               if ( $class === 'Language' ) {
-                       return;
-               }
-
-               if ( file_exists( "$IP/languages/classes/$class.php" ) ) {
-                       include_once "$IP/languages/classes/$class.php";
-               }
-       }
-
        /**
         * Get the LocalisationCache instance
         *
@@ -4407,22 +4372,6 @@ class Language {
                $this->mParentLanguage = false;
        }
 
-       /**
-        * Get the name of a file for a certain language code
-        * @param string $prefix Prepend this to the filename
-        * @param string $code Language code
-        * @param string $suffix Append this to the filename
-        * @throws MWException
-        * @return string $prefix . $mangledCode . $suffix
-        */
-       public static function getFileName( $prefix = 'Language', $code, $suffix = '.php' ) {
-               if ( !self::isValidBuiltInCode( $code ) ) {
-                       throw new MWException( "Invalid language code \"$code\"" );
-               }
-
-               return $prefix . str_replace( '-', '_', ucfirst( $code ) ) . $suffix;
-       }
-
        /**
         * Get the language code from a file name. Inverse of getFileName()
         * @param string $filename $prefix . $languageCode . $suffix
@@ -4440,6 +4389,34 @@ class Language {
                return str_replace( '_', '-', strtolower( $m[1] ) );
        }
 
+       /**
+        * @param string $code
+        * @return string Name of the language class
+        */
+       public static function classFromCode( $code ) {
+               if ( $code == 'en' ) {
+                       return 'Language';
+               } else {
+                       return 'Language' . str_replace( '-', '_', ucfirst( $code ) );
+               }
+       }
+
+       /**
+        * Get the name of a file for a certain language code
+        * @param string $prefix Prepend this to the filename
+        * @param string $code Language code
+        * @param string $suffix Append this to the filename
+        * @throws MWException
+        * @return string $prefix . $mangledCode . $suffix
+        */
+       public static function getFileName( $prefix = 'Language', $code, $suffix = '.php' ) {
+               if ( !self::isValidBuiltInCode( $code ) ) {
+                       throw new MWException( "Invalid language code \"$code\"" );
+               }
+
+               return $prefix . str_replace( '-', '_', ucfirst( $code ) ) . $suffix;
+       }
+
        /**
         * @param string $code
         * @return string
@@ -4466,15 +4443,6 @@ class Language {
                return "$IP/languages/i18n/$code.json";
        }
 
-       /**
-        * @param string $code
-        * @return string
-        */
-       public static function getClassFileName( $code ) {
-               global $IP;
-               return self::getFileName( "$IP/languages/classes/Language", $code, '.php' );
-       }
-
        /**
         * Get the first fallback for a given language.
         *
index 59ce155..b1b1541 100644 (file)
@@ -1318,6 +1318,9 @@ return array(
                'scripts' => 'resources/src/mediawiki/mediawiki.experiments.js',
                'targets' => array( 'desktop', 'mobile' ),
        ),
+       'mediawiki.raggett' => array(
+               'styles' => 'resources/src/mediawiki/mediawiki.raggett.css'
+       ),
 
        /* MediaWiki Action */
 
index 0ef5095..f764513 100644 (file)
                                redirect: suggestionPage.redirect !== undefined,
                                disambiguation: OO.getProp( suggestionPage, 'pageprops', 'disambiguation' ) !== undefined,
                                imageUrl: OO.getProp( suggestionPage, 'thumbnail', 'source' ),
-                               description: OO.getProp( suggestionPage, 'terms', 'description' )
+                               description: OO.getProp( suggestionPage, 'terms', 'description' ),
+                               // sort index
+                               index: suggestionPage.index
                        };
 
                        // Throw away pages from wrong namespaces. This can happen when 'showRedirectTargets' is true
                        }
                }
 
+               titles.sort( function ( a, b ) {
+                       return pageData[ a ].index - pageData[ b ].index;
+               } );
+
                // If not found, run value through mw.Title to avoid treating a match as a
                // mismatch where normalisation would make them matching (bug 48476)
 
diff --git a/resources/src/mediawiki/mediawiki.raggett.css b/resources/src/mediawiki/mediawiki.raggett.css
new file mode 100644 (file)
index 0000000..1e1e973
--- /dev/null
@@ -0,0 +1,3 @@
+.mw-empty-li {
+       display: none;
+}
index 093748d..1c48515 100644 (file)
@@ -77,9 +77,6 @@ $wgAutoloadClasses += array(
        'WikitextContentTest' => "$testDir/phpunit/includes/content/WikitextContentTest.php",
 
        # tests/phpunit/includes/db
-       'ORMRowTest' => "$testDir/phpunit/includes/db/ORMRowTest.php",
-       'ORMTableTest' => "$testDir/phpunit/includes/db/ORMTableTest.php",
-       'PageORMTableForTesting' => "$testDir/phpunit/includes/db/ORMTableTest.php",
        'DatabaseTestHelper' => "$testDir/phpunit/includes/db/DatabaseTestHelper.php",
 
        # tests/phpunit/includes/diff
index f245826..4e6c591 100644 (file)
@@ -26405,3 +26405,19 @@ B <ref group="X" name="b" />
 <ref name="b"><span id="Z">foo</span>bar</ref>
 </references>
 !! end
+
+!! test
+Empty LI (T49673)
+!! wikitext
+* a
+* 
+*
+* b
+!! html/php+tidy
+<ul>
+<li>a</li>
+<li class="mw-empty-li"></li>
+<li class="mw-empty-li"></li>
+<li>b</li>
+</ul>
+!! end
diff --git a/tests/phpunit/includes/db/ORMRowTest.php b/tests/phpunit/includes/db/ORMRowTest.php
deleted file mode 100644 (file)
index 807bd14..0000000
+++ /dev/null
@@ -1,225 +0,0 @@
-<?php
-
-/**
- * Abstract class to construct tests for ORMRow deriving classes.
- *
- * 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
- * @since 1.20
- *
- * @ingroup Test
- *
- * @group ORM
- *
- * The database group has as a side effect that temporal database tables are created. This makes
- * it possible to test without poisoning a production database.
- * @group Database
- *
- * Some of the tests takes more time, and needs therefor longer time before they can be aborted
- * as non-functional. The reason why tests are aborted is assumed to be set up of temporal databases
- * that hold the first tests in a pending state awaiting access to the database.
- * @group medium
- *
- * @author Jeroen De Dauw < jeroendedauw@gmail.com >
- */
-abstract class ORMRowTest extends \MediaWikiTestCase {
-
-       /**
-        * @since 1.20
-        * @return string
-        */
-       abstract protected function getRowClass();
-
-       /**
-        * @since 1.20
-        * @return IORMTable
-        */
-       abstract protected function getTableInstance();
-
-       /**
-        * @since 1.20
-        * @return array
-        */
-       abstract public function constructorTestProvider();
-
-       /**
-        * @since 1.20
-        * @param IORMRow $row
-        * @param array $data
-        */
-       protected function verifyFields( IORMRow $row, array $data ) {
-               foreach ( array_keys( $data ) as $fieldName ) {
-                       $this->assertEquals( $data[$fieldName], $row->getField( $fieldName ) );
-               }
-       }
-
-       /**
-        * @since 1.20
-        * @param array $data
-        * @param bool $loadDefaults
-        * @return IORMRow
-        */
-       protected function getRowInstance( array $data, $loadDefaults ) {
-               $class = $this->getRowClass();
-
-               return new $class( $this->getTableInstance(), $data, $loadDefaults );
-       }
-
-       /**
-        * @since 1.20
-        * @return array
-        */
-       protected function getMockValues() {
-               return array(
-                       'id' => 1,
-                       'str' => 'foobar4645645',
-                       'int' => 42,
-                       'float' => 4.2,
-                       'bool' => true,
-                       'array' => array( 42, 'foobar' ),
-                       'blob' => new stdClass()
-               );
-       }
-
-       /**
-        * @since 1.20
-        * @return array
-        */
-       protected function getMockFields() {
-               $mockValues = $this->getMockValues();
-               $mockFields = array();
-
-               foreach ( $this->getTableInstance()->getFields() as $name => $type ) {
-                       if ( $name !== 'id' ) {
-                               $mockFields[$name] = $mockValues[$type];
-                       }
-               }
-
-               return $mockFields;
-       }
-
-       /**
-        * @since 1.20
-        * @return array Array of IORMRow
-        */
-       public function instanceProvider() {
-               $instances = array();
-
-               foreach ( $this->constructorTestProvider() as $arguments ) {
-                       $instances[] = array( call_user_func_array( array( $this, 'getRowInstance' ), $arguments ) );
-               }
-
-               return $instances;
-       }
-
-       /**
-        * @dataProvider constructorTestProvider
-        */
-       public function testConstructor( array $data, $loadDefaults ) {
-               $this->verifyFields( $this->getRowInstance( $data, $loadDefaults ), $data );
-       }
-
-       /**
-        * @dataProvider constructorTestProvider
-        */
-       public function testSaveAndRemove( array $data, $loadDefaults ) {
-               $item = $this->getRowInstance( $data, $loadDefaults );
-
-               $this->assertTrue( $item->save() );
-
-               $this->assertTrue( $item->hasIdField() );
-               $this->assertTrue( is_integer( $item->getId() ) );
-
-               $id = $item->getId();
-
-               $this->assertTrue( $item->save() );
-
-               $this->assertEquals( $id, $item->getId() );
-
-               $this->verifyFields( $item, $data );
-
-               $this->assertTrue( $item->remove() );
-
-               $this->assertFalse( $item->hasIdField() );
-
-               $this->assertTrue( $item->save() );
-
-               $this->verifyFields( $item, $data );
-
-               $this->assertTrue( $item->remove() );
-
-               $this->assertFalse( $item->hasIdField() );
-
-               $this->verifyFields( $item, $data );
-       }
-
-       /**
-        * @dataProvider instanceProvider
-        */
-       public function testSetField( IORMRow $item ) {
-               foreach ( $this->getMockFields() as $name => $value ) {
-                       $item->setField( $name, $value );
-                       $this->assertEquals( $value, $item->getField( $name ) );
-               }
-       }
-
-       /**
-        * @since 1.20
-        * @param array $expected
-        * @param IORMRow $item
-        */
-       protected function assertFieldValues( array $expected, IORMRow $item ) {
-               foreach ( $expected as $name => $type ) {
-                       if ( $name !== 'id' ) {
-                               $this->assertEquals( $expected[$name], $item->getField( $name ) );
-                       }
-               }
-       }
-
-       /**
-        * @dataProvider instanceProvider
-        */
-       public function testSetFields( IORMRow $item ) {
-               $originalValues = $item->getFields();
-
-               $item->setFields( array(), false );
-
-               foreach ( $item->getTable()->getFields() as $name => $type ) {
-                       $originalHas = array_key_exists( $name, $originalValues );
-                       $newHas = $item->hasField( $name );
-
-                       $this->assertEquals( $originalHas, $newHas );
-
-                       if ( $originalHas && $newHas ) {
-                               $this->assertEquals( $originalValues[$name], $item->getField( $name ) );
-                       }
-               }
-
-               $mockFields = $this->getMockFields();
-
-               $item->setFields( $mockFields, false );
-
-               $this->assertFieldValues( $originalValues, $item );
-
-               $item->setFields( $mockFields, true );
-
-               $this->assertFieldValues( $mockFields, $item );
-       }
-
-       // TODO: test all of the methods!
-
-}
diff --git a/tests/phpunit/includes/db/ORMTableTest.php b/tests/phpunit/includes/db/ORMTableTest.php
deleted file mode 100644 (file)
index 764560d..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-<?php
-/**
- * Abstract class to construct tests for ORMTable deriving classes.
- *
- * 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
- * @since 1.21
- *
- * @ingroup Test
- *
- * @group ORM
- * @group Database
- *
- * @covers PageORMTableForTesting
- *
- * @author Jeroen De Dauw < jeroendedauw@gmail.com >
- * @author Daniel Kinzler
- */
-
-class ORMTableTest extends MediaWikiTestCase {
-
-       /**
-        * @since 1.21
-        * @return string
-        */
-       protected function getTableClass() {
-               return 'PageORMTableForTesting';
-       }
-
-       /**
-        * @since 1.21
-        * @return IORMTable
-        */
-       public function getTable() {
-               $class = $this->getTableClass();
-
-               return $class::singleton();
-       }
-
-       /**
-        * @since 1.21
-        * @return string
-        */
-       public function getRowClass() {
-               return $this->getTable()->getRowClass();
-       }
-
-       /**
-        * @since 1.21
-        */
-       public function testSingleton() {
-               $class = $this->getTableClass();
-
-               $this->assertInstanceOf( $class, $class::singleton() );
-               $this->assertTrue( $class::singleton() === $class::singleton() );
-       }
-}
-
-/**
- * Dummy ORM table for testing, reading Title objects from the page table.
- *
- * @since 1.21
- */
-
-class PageORMTableForTesting extends ORMTable {
-
-       public function __construct() {
-               $this->fieldPrefix = 'page_';
-       }
-
-       /**
-        * @see ORMTable::getName
-        *
-        * @return string
-        */
-       public function getName() {
-               return 'page';
-       }
-
-       /**
-        * @see ORMTable::getRowClass
-        *
-        * @return string
-        */
-       public function getRowClass() {
-               return 'Title';
-       }
-
-       /**
-        * @see ORMTable::newRow
-        *
-        * @return IORMRow
-        */
-       public function newRow( array $data, $loadDefaults = false ) {
-               return Title::makeTitle( $data['namespace'], $data['title'] );
-       }
-
-       /**
-        * @see ORMTable::getFields
-        *
-        * @return array
-        */
-       public function getFields() {
-               return array(
-                       'id' => 'int',
-                       'namespace' => 'int',
-                       'title' => 'str',
-               );
-       }
-}
diff --git a/tests/phpunit/includes/db/TestORMRowTest.php b/tests/phpunit/includes/db/TestORMRowTest.php
deleted file mode 100644 (file)
index 04bb9f3..0000000
+++ /dev/null
@@ -1,207 +0,0 @@
-<?php
-
-/**
- * Tests for the TestORMRow class.
- * TestORMRow is a dummy class to be able to test the abstract ORMRow class.
- *
- * 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
- * @ingroup Test
- * @author Jeroen De Dauw < jeroendedauw@gmail.com >
- */
-
-/**
- * The database group has as a side effect that temporal database tables are created. This makes
- * it possible to test without poisoning a production database.
- *
- * Some of the tests takes more time, and needs therefor longer time before they can be aborted
- * as non-functional. The reason why tests are aborted is assumed to be set up of temporal databases
- * that hold the first tests in a pending state awaiting access to the database.
- *
- * @since 1.20
- *
- * @group ORM
- * @group Database
- * @group medium
- * @covers TestORMRow
- */
-class TestORMRowTest extends ORMRowTest {
-
-       /**
-        * @since 1.20
-        * @return string
-        */
-       protected function getRowClass() {
-               return 'TestORMRow';
-       }
-
-       /**
-        * @since 1.20
-        * @return IORMTable
-        */
-       protected function getTableInstance() {
-               return TestORMTable::singleton();
-       }
-
-       protected function setUp() {
-               parent::setUp();
-
-               $dbw = wfGetDB( DB_MASTER );
-
-               $isSqlite = $GLOBALS['wgDBtype'] === 'sqlite';
-               $isPostgres = $GLOBALS['wgDBtype'] === 'postgres';
-
-               $idField = $isSqlite ? 'INTEGER' : 'INT unsigned';
-               $primaryKey = $isSqlite ? 'PRIMARY KEY AUTOINCREMENT' : 'auto_increment PRIMARY KEY';
-
-               if ( $isPostgres ) {
-                       $dbw->query(
-                               'CREATE TABLE IF NOT EXISTS ' . $dbw->tableName( 'orm_test' ) . "(
-                                       test_id serial PRIMARY KEY,
-                                       test_name TEXT NOT NULL DEFAULT '',
-                                       test_age INTEGER NOT NULL DEFAULT 0,
-                                       test_height REAL NOT NULL DEFAULT 0,
-                                       test_awesome INTEGER NOT NULL DEFAULT 0,
-                                       test_stuff BYTEA,
-                                       test_moarstuff BYTEA,
-                                       test_time TIMESTAMPTZ
-                                       );",
-                                       __METHOD__
-                               );
-               } else {
-                       $dbw->query(
-                               'CREATE TABLE IF NOT EXISTS ' . $dbw->tableName( 'orm_test' ) . '(
-                                       test_id                    ' . $idField . '        NOT NULL ' . $primaryKey . ',
-                                       test_name                  VARCHAR(255)        NOT NULL,
-                                       test_age                   TINYINT unsigned    NOT NULL,
-                                       test_height                FLOAT               NOT NULL,
-                                       test_awesome               TINYINT unsigned    NOT NULL,
-                                       test_stuff                 BLOB                NOT NULL,
-                                       test_moarstuff             BLOB                NOT NULL,
-                                       test_time                  varbinary(14)       NOT NULL
-                               );',
-                               __METHOD__
-                       );
-               }
-       }
-
-       protected function tearDown() {
-               $dbw = wfGetDB( DB_MASTER );
-               $dbw->dropTable( 'orm_test', __METHOD__ );
-
-               parent::tearDown();
-       }
-
-       public function constructorTestProvider() {
-               $dbw = wfGetDB( DB_MASTER );
-               return array(
-                       array(
-                               array(
-                                       'name' => 'Foobar',
-                                       'time' => $dbw->timestamp( '20120101020202' ),
-                                       'age' => 42,
-                                       'height' => 9000.1,
-                                       'awesome' => true,
-                                       'stuff' => array( 13, 11, 7, 5, 3, 2 ),
-                                       'moarstuff' => (object)array( 'foo' => 'bar', 'bar' => array( 4, 2 ), 'baz' => true )
-                               ),
-                               true
-                       ),
-               );
-       }
-
-       /**
-        * @since 1.21
-        * @return array
-        */
-       protected function getMockValues() {
-               return array(
-                       'id' => 1,
-                       'str' => 'foobar4645645',
-                       'int' => 42,
-                       'float' => 4.2,
-                       'bool' => '',
-                       'array' => array( 42, 'foobar' ),
-                       'blob' => new stdClass()
-               );
-       }
-}
-
-class TestORMRow extends ORMRow {
-}
-
-class TestORMTable extends ORMTable {
-
-       public function __construct() {
-               $this->fieldPrefix = 'test_';
-       }
-
-       /**
-        * Returns the name of the database table objects of this type are stored in.
-        *
-        * @since 1.20
-        *
-        * @return string
-        */
-       public function getName() {
-               return 'orm_test';
-       }
-
-       /**
-        * Returns the name of a IORMRow implementing class that
-        * represents single rows in this table.
-        *
-        * @since 1.20
-        *
-        * @return string
-        */
-       public function getRowClass() {
-               return 'TestORMRow';
-       }
-
-       /**
-        * Returns an array with the fields and their types this object contains.
-        * This corresponds directly to the fields in the database, without prefix.
-        *
-        * field name => type
-        *
-        * Allowed types:
-        * * id
-        * * str
-        * * int
-        * * float
-        * * bool
-        * * array
-        * * blob
-        *
-        * @since 1.20
-        *
-        * @return array
-        */
-       public function getFields() {
-               return array(
-                       'id' => 'id',
-                       'name' => 'str',
-                       'age' => 'int',
-                       'height' => 'float',
-                       'awesome' => 'bool',
-                       'stuff' => 'array',
-                       'moarstuff' => 'blob',
-                       'time' => 'str', // TS_MW
-               );
-       }
-}
index 54393a7..a1fdd91 100644 (file)
@@ -175,7 +175,6 @@ class WANObjectCacheTest extends MediaWikiTestCase {
                        return $value;
                };
 
-               $cache->delete( $key );
                $ret = $cache->getWithSetCallback( $key, 30, $func, array( 'lockTSE' => 5 ) );
                $this->assertEquals( $value, $ret );
                $this->assertEquals( 1, $calls, 'Value was populated' );
@@ -187,6 +186,36 @@ class WANObjectCacheTest extends MediaWikiTestCase {
                $this->assertEquals( 1, $calls, 'Callback was not used' );
        }
 
+       /**
+        * @covers WANObjectCache::getWithSetCallback()
+        */
+       public function testLockTSESlow() {
+               $cache = $this->cache;
+               $key = wfRandomString();
+               $value = wfRandomString();
+
+               $calls = 0;
+               $func = function( $oldValue, &$ttl, &$setOpts ) use ( &$calls, $value ) {
+                       ++$calls;
+                       $setOpts['since'] = microtime( true ) - 10;
+                       return $value;
+               };
+
+               // Value should be marked as stale due to snapshot lag
+               $curTTL = null;
+               $ret = $cache->getWithSetCallback( $key, 30, $func, array( 'lockTSE' => 5 ) );
+               $this->assertEquals( $value, $ret );
+               $this->assertEquals( $value, $cache->get( $key, $curTTL ), 'Value was populated' );
+               $this->assertLessThan( 0, $curTTL, 'Value has negative curTTL' );
+               $this->assertEquals( 1, $calls, 'Value was generated' );
+
+               // Acquire a lock to verify that getWithSetCallback uses lockTSE properly
+               $this->internalCache->lock( $key, 0 );
+               $ret = $cache->getWithSetCallback( $key, 30, $func, array( 'lockTSE' => 5 ) );
+               $this->assertEquals( $value, $ret );
+               $this->assertEquals( 1, $calls, 'Callback was not used' );
+       }
+
        /**
         * @covers WANObjectCache::getMulti()
         */
index b0c9e4f..3e3bac3 100644 (file)
@@ -12,7 +12,7 @@ class MemcachedBagOStuffTest extends MediaWikiTestCase {
        }
 
        /**
-        * @covers MemcachedBagOStuff::makeKeyInternal
+        * @covers MemcachedBagOStuff::makeKey
         */
        public function testKeyNormalization() {
                $this->assertEquals(
@@ -67,4 +67,39 @@ class MemcachedBagOStuffTest extends MediaWikiTestCase {
                        $this->cache->makeKey( 'long_key_part_hashed', str_repeat( 'y', 500 ) )
                );
        }
+
+       /**
+        * @dataProvider validKeyProvider
+        */
+       public function testValidateKeyEncoding( $key ) {
+               $this->assertSame( $key, $this->cache->validateKeyEncoding( $key ) );
+       }
+
+       public function validKeyProvider() {
+               return array(
+                       'empty' => array( '' ),
+                       'digits' => array( '09' ),
+                       'letters' => array( 'AZaz' ),
+                       'ASCII special characters' => array( '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' ),
+               );
+       }
+
+       /**
+        * @dataProvider invalidKeyProvider
+        */
+       public function testValidateKeyEncodingThrowsException( $key ) {
+               $this->setExpectedException( 'Exception' );
+               $this->cache->validateKeyEncoding( $key );
+       }
+
+       public function invalidKeyProvider() {
+               return array(
+                       array( "\x00" ),
+                       array( ' ' ),
+                       array( "\x1F" ),
+                       array( "\x7F" ),
+                       array( "\x80" ),
+                       array( "\xFF" ),
+               );
+       }
 }