Message: Don't include Title objects in the serialization (part 1)
authorBrad Jorsch <bjorsch@wikimedia.org>
Wed, 28 Nov 2018 15:23:12 +0000 (10:23 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Wed, 28 Nov 2018 18:43:00 +0000 (13:43 -0500)
Stringify the title instead. This will help avoid running into the
PHP/HHVM serialization incompatibility described in T210528.

This is part 1: start stringifying and using the string, but continue
storing the Title object for the benefit of mixed environments where
some servers still only handle a Title object.

Bug: T210528
Change-Id: I07aac3aab2d4e27a7203f4e4fb3ce1b5d86c517c

includes/Message.php

index 3bd7755..f9d1cce 100644 (file)
@@ -290,6 +290,7 @@ class Message implements MessageSpecifier, Serializable {
                        'format' => $this->format,
                        'useDatabase' => $this->useDatabase,
                        'title' => $this->title,
+                       'titlestr' => $this->title ? $this->title->getFullText() : null,
                ] );
        }
 
@@ -307,7 +308,15 @@ class Message implements MessageSpecifier, Serializable {
                $this->format = $data['format'];
                $this->useDatabase = $data['useDatabase'];
                $this->language = $data['language'] ? Language::factory( $data['language'] ) : false;
-               $this->title = $data['title'];
+
+               if ( isset( $data['titlestr'] ) ) {
+                       $this->title = Title::newFromText( $data['titlestr'] );
+               } elseif ( isset( $data['title'] ) && $data['title'] instanceof Title ) {
+                       // Old serializations from before December 2018
+                       $this->title = $data['title'];
+               } else {
+                       $this->title = null; // Explicit for sanity
+               }
        }
 
        /**