Merge "(bug 42226) failure in sites tests"
[lhc/web/wiklou.git] / includes / site / SiteObject.php
index 688b970..78c942b 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @since 1.20
+ * @since 1.21
  *
  * @file
  * @ingroup Site
  *
- * @licence GNU GPL v2+
+ * @license GNU GPL v2+
  * @author Jeroen De Dauw < jeroendedauw@gmail.com >
  * @author Daniel Werner
  */
@@ -35,7 +35,7 @@ class SiteObject extends ORMRow implements Site {
         * Holds the local ids for this site.
         * You can obtain them via @see getLocalIds
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @var array|false
         */
@@ -44,7 +44,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Site::getGlobalId
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @return string
         */
@@ -55,7 +55,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Site::setGlobalId
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @param string $globalId
         */
@@ -66,7 +66,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Site::getType
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @return string
         */
@@ -77,7 +77,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Site::setType
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @param string $type
         */
@@ -88,7 +88,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Site::getGroup
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @return string
         */
@@ -99,7 +99,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Site::setGroup
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @param string $group
         */
@@ -110,7 +110,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Site::getSource
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @return string
         */
@@ -121,7 +121,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Site::setSource
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @param string $source
         */
@@ -132,7 +132,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Site::getDomain
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @return string|false
         */
@@ -149,7 +149,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Site::getProtocol
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @return string|false
         */
@@ -157,10 +157,23 @@ class SiteObject extends ORMRow implements Site {
                $path = $this->getLinkPath();
 
                if ( $path === false ) {
-                       return false;
+                       return '';
                }
 
-               return parse_url( $path, PHP_URL_SCHEME );
+               $protocol = parse_url( $path, PHP_URL_SCHEME );
+
+               // Malformed URL
+               if ( $protocol === false ) {
+                       throw new MWException( "failed to parse URL $path" );
+               }
+
+               // No schema
+               if ( $protocol === null ) {
+                       // Used for protocol relative URLs
+                       $protocol = '';
+               }
+
+               return $protocol;
        }
 
        /**
@@ -169,7 +182,7 @@ class SiteObject extends ORMRow implements Site {
         *
         * @param string $fullUrl
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @throws MWException
         */
@@ -204,7 +217,7 @@ class SiteObject extends ORMRow implements Site {
         * This default implementation returns SiteObject::PATH_LINK as the default path type. Subclasses can override this
         * to define a different default path type, or return false to disable site links.
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @return string|false
         */
@@ -217,7 +230,7 @@ class SiteObject extends ORMRow implements Site {
         *
         * This implementation returns a URL constructed using the path returned by getLinkPath().
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @param bool|String $pageName
         *
@@ -243,7 +256,7 @@ class SiteObject extends ORMRow implements Site {
         *
         * @see Site::normalizePageName
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @param string $pageName
         *
@@ -257,7 +270,7 @@ class SiteObject extends ORMRow implements Site {
         * Returns the value of a type specific field, or the value
         * of the $default parameter in case it's not set.
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @param string $fieldName
         * @param mixed $default
@@ -271,7 +284,7 @@ class SiteObject extends ORMRow implements Site {
 
        /**
         * Sets the value of a type specific field.
-        * @since 1.20
+        * @since 1.21
         *
         * @param string $fieldName
         * @param mixed $value
@@ -285,7 +298,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Site::getLanguageCode
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @return string|false
         */
@@ -296,7 +309,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Site::setLanguageCode
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @param string $languageCode
         */
@@ -307,7 +320,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * Returns the local identifiers of this site.
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @param string $type
         *
@@ -324,7 +337,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * Loads the local ids for the site.
         *
-        * @since 1.20
+        * @since 1.21
         */
        protected function loadLocalIds() {
                $dbr = wfGetDB( $this->getTable()->getReadDb() );
@@ -351,7 +364,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * Adds a local identifier.
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @param string $type
         * @param string $identifier
@@ -373,7 +386,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Site::addInterwikiId
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @param string $identifier
         */
@@ -384,7 +397,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Site::addNavigationId
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @param string $identifier
         */
@@ -395,7 +408,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Site::getInterwikiIds
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @return array of string
         */
@@ -406,7 +419,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Site::getNavigationIds
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @return array of string
         */
@@ -417,7 +430,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Site::getInternalId
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @return integer
         */
@@ -426,17 +439,17 @@ class SiteObject extends ORMRow implements Site {
        }
 
        /**
-        * @see ORMRow::save
+        * @see IORMRow::save
         * @see Site::save
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @param string|null $functionName
         *
         * @return boolean Success indicator
         */
        public function save( $functionName = null ) {
-               $dbw = wfGetDB( DB_MASTER );
+               $dbw = $this->table->getWriteDbConnection();
 
                $trx = $dbw->trxLevel();
 
@@ -482,10 +495,29 @@ class SiteObject extends ORMRow implements Site {
                return $success;
        }
 
+       /**
+        * @since 1.21
+        *
+        * @see ORMRow::onRemoved
+        */
+       protected function onRemoved() {
+               $dbw = $this->table->getWriteDbConnection();
+
+               $dbw->delete(
+                       'site_identifiers',
+                       array(
+                               'si_site' => $this->getId()
+                       ),
+                       __METHOD__
+               );
+
+               parent::onRemoved();
+       }
+
        /**
         * @see Site::setPath
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @param string $pathType
         * @param string $fullUrl
@@ -499,7 +531,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Sitres::getPath
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @param string $pathType
         *
@@ -513,7 +545,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Sitres::getAll
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @return array of string
         */
@@ -524,7 +556,7 @@ class SiteObject extends ORMRow implements Site {
        /**
         * @see Sitres::removePath
         *
-        * @since 1.20
+        * @since 1.21
         *
         * @param string $pathType
         */