Merge "Perform a permission check on the title when changing the page language"
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index 5c7c7fe..4f4decf 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  */
 
+use MediaWiki\Edit\PreparedEdit;
 use \MediaWiki\Logger\LoggerFactory;
 use \MediaWiki\MediaWikiServices;
 use Wikimedia\Rdbms\FakeResultWrapper;
@@ -49,7 +50,7 @@ class WikiPage implements Page, IDBAccessObject {
        public $mLatest = false;             // !< Integer (false means "not loaded")
        /**@}}*/
 
-       /** @var stdClass Map of cache fields (text, parser output, ect) for a proposed/new edit */
+       /** @var PreparedEdit Map of cache fields (text, parser output, ect) for a proposed/new edit */
        public $mPreparedEdit = false;
 
        /**
@@ -382,11 +383,12 @@ class WikiPage implements Page, IDBAccessObject {
                if ( is_int( $from ) ) {
                        list( $index, $opts ) = DBAccessObjectUtils::getDBOptions( $from );
                        $data = $this->pageDataFromTitle( wfGetDB( $index ), $this->mTitle, $opts );
+                       $loadBalancer = MediaWikiServices::getInstance()->getDBLoadBalancer();
 
                        if ( !$data
                                && $index == DB_REPLICA
-                               && wfGetLB()->getServerCount() > 1
-                               && wfGetLB()->hasOrMadeRecentMasterChanges()
+                               && $loadBalancer->getServerCount() > 1
+                               && $loadBalancer->hasOrMadeRecentMasterChanges()
                        ) {
                                $from = self::READ_LATEST;
                                list( $index, $opts ) = DBAccessObjectUtils::getDBOptions( $from );
@@ -781,7 +783,7 @@ class WikiPage implements Page, IDBAccessObject {
         * Determine whether a page would be suitable for being counted as an
         * article in the site_stats table based on the title & its content
         *
-        * @param object|bool $editInfo (false): object returned by prepareTextForEdit(),
+        * @param PreparedEdit|bool $editInfo (false): object returned by prepareTextForEdit(),
         *   if false, the current database state will be used
         * @return bool
         */
@@ -1314,7 +1316,6 @@ class WikiPage implements Page, IDBAccessObject {
         * @return bool
         */
        public function updateIfNewerOn( $dbw, $revision ) {
-
                $row = $dbw->selectRow(
                        [ 'revision', 'page' ],
                        [ 'rev_id', 'rev_timestamp', 'page_is_redirect' ],
@@ -1386,7 +1387,6 @@ class WikiPage implements Page, IDBAccessObject {
        public function replaceSectionContent(
                $sectionId, Content $sectionContent, $sectionTitle = '', $edittime = null
        ) {
-
                $baseRevId = null;
                if ( $edittime && $sectionId !== 'new' ) {
                        $dbr = wfGetDB( DB_REPLICA );
@@ -1425,7 +1425,6 @@ class WikiPage implements Page, IDBAccessObject {
        public function replaceSectionAtRev( $sectionId, Content $sectionContent,
                $sectionTitle = '', $baseRevId = null
        ) {
-
                if ( strval( $sectionId ) === '' ) {
                        // Whole-page edit; let the whole text through
                        $newContent = $sectionContent;
@@ -1609,7 +1608,7 @@ class WikiPage implements Page, IDBAccessObject {
                $meta = [
                        'bot' => ( $flags & EDIT_FORCE_BOT ),
                        'minor' => ( $flags & EDIT_MINOR ) && $user->isAllowed( 'minoredit' ),
-                       'serialized' => $editInfo->pst,
+                       'serialized' => $pstContent->serialize( $serialFormat ),
                        'serialFormat' => $serialFormat,
                        'baseRevId' => $baseRevId,
                        'oldRevision' => $old_revision,
@@ -1963,7 +1962,9 @@ class WikiPage implements Page, IDBAccessObject {
 
        /**
         * Prepare content which is about to be saved.
-        * Returns a stdClass with source, pst and output members
+        *
+        * Prior to 1.30, this returned a stdClass object with the same class
+        * members.
         *
         * @param Content $content
         * @param Revision|int|null $revision Revision object. For backwards compatibility, a
@@ -1972,7 +1973,7 @@ class WikiPage implements Page, IDBAccessObject {
         * @param string|null $serialFormat
         * @param bool $useCache Check shared prepared edit cache
         *
-        * @return object
+        * @return PreparedEdit
         *
         * @since 1.21
         */
@@ -2022,7 +2023,7 @@ class WikiPage implements Page, IDBAccessObject {
                $popts = ParserOptions::newFromUserAndLang( $user, $wgContLang );
                Hooks::run( 'ArticlePrepareTextForEdit', [ $this, $popts ] );
 
-               $edit = (object)[];
+               $edit = new PreparedEdit();
                if ( $cachedEdit ) {
                        $edit->timestamp = $cachedEdit->timestamp;
                } else {
@@ -2973,7 +2974,7 @@ class WikiPage implements Page, IDBAccessObject {
                }
 
                // Clear caches
-               WikiPage::onArticleDelete( $this->mTitle );
+               self::onArticleDelete( $this->mTitle );
                ResourceLoaderWikiModule::invalidateModuleCache(
                        $this->mTitle, $revision, null, wfWikiID()
                );
@@ -3000,7 +3001,7 @@ class WikiPage implements Page, IDBAccessObject {
         * @param string $token Rollback token.
         * @param bool $bot If true, mark all reverted edits as bot.
         *
-        * @param array $resultDetails Array contains result-specific array of additional values
+        * @param array &$resultDetails Array contains result-specific array of additional values
         *    'alreadyrolled' : 'current' (rev)
         *    success        : 'summary' (str), 'current' (rev), 'target' (rev)
         *
@@ -3052,7 +3053,7 @@ class WikiPage implements Page, IDBAccessObject {
         * @param string $summary Custom summary. Set to default summary if empty.
         * @param bool $bot If true, mark all reverted edits as bot.
         *
-        * @param array $resultDetails Contains result-specific array of additional values
+        * @param array &$resultDetails Contains result-specific array of additional values
         * @param User $guser The user performing the rollback
         * @param array|null $tags Change tags to apply to the rollback
         * Callers are responsible for permission checks