Merge "Revert "Log the reason why revision->getContent() returns null""
[lhc/web/wiklou.git] / includes / page / Article.php
index df189af..cd72267 100644 (file)
@@ -75,6 +75,13 @@ class Article implements Page {
        /** @var ParserOutput */
        public $mParserOutput;
 
+       /**
+        * @var bool Whether render() was called. With the way subclasses work
+        * here, there doesn't seem to be any other way to stop calling
+        * OutputPage::enableSectionEditLinks() and still have it work as it did before.
+        */
+       private $disableSectionEditForRender = false;
+
        /**
         * Constructor and clear the article
         * @param Title $title Reference to a Title object.
@@ -469,12 +476,15 @@ class Article implements Page {
                $parserCache = MediaWikiServices::getInstance()->getParserCache();
 
                $parserOptions = $this->getParserOptions();
+               $poOptions = [];
                # Render printable version, use printable version cache
                if ( $outputPage->isPrintable() ) {
                        $parserOptions->setIsPrintable( true );
-                       $parserOptions->setEditSection( false );
-               } elseif ( !$this->isCurrent() || !$this->getTitle()->quickUserCan( 'edit', $user ) ) {
-                       $parserOptions->setEditSection( false );
+                       $poOptions['enableSectionEditLinks'] = false;
+               } elseif ( $this->disableSectionEditForRender
+                       || !$this->isCurrent() || !$this->getTitle()->quickUserCan( 'edit', $user )
+               ) {
+                       $poOptions['enableSectionEditLinks'] = false;
                }
 
                # Try client and file cache
@@ -533,7 +543,7 @@ class Article implements Page {
                                                        } else {
                                                                wfDebug( __METHOD__ . ": showing parser cache contents\n" );
                                                        }
-                                                       $outputPage->addParserOutput( $this->mParserOutput );
+                                                       $outputPage->addParserOutput( $this->mParserOutput, $poOptions );
                                                        # Ensure that UI elements requiring revision ID have
                                                        # the correct version information.
                                                        $outputPage->setRevisionId( $this->mPage->getLatest() );
@@ -590,14 +600,14 @@ class Article implements Page {
                                                        $outputPage->setRobotPolicy( 'noindex,nofollow' );
 
                                                        $errortext = $error->getWikiText( false, 'view-pool-error' );
-                                                       $outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
+                                                       $outputPage->addWikiText( Html::errorBox( $errortext ) );
                                                }
                                                # Connection or timeout error
                                                return;
                                        }
 
                                        $this->mParserOutput = $poolArticleView->getParserOutput();
-                                       $outputPage->addParserOutput( $this->mParserOutput );
+                                       $outputPage->addParserOutput( $this->mParserOutput, $poOptions );
                                        if ( $content->getRedirectTarget() ) {
                                                $outputPage->addSubtitle( "<span id=\"redirectsub\">" .
                                                        $this->getContext()->msg( 'redirectpagesub' )->parse() . "</span>" );
@@ -1514,7 +1524,7 @@ class Article implements Page {
        public function render() {
                $this->getContext()->getRequest()->response()->header( 'X-Robots-Tag: noindex' );
                $this->getContext()->getOutput()->setArticleBodyOnly( true );
-               $this->getContext()->getOutput()->enableSectionEditLinks( false );
+               $this->disableSectionEditForRender = true;
                $this->view();
        }
 
@@ -1673,6 +1683,7 @@ class Article implements Page {
                $outputPage->setPageTitle( wfMessage( 'delete-confirm', $title->getPrefixedText() ) );
                $outputPage->addBacklinkSubtitle( $title );
                $outputPage->setRobotPolicy( 'noindex,nofollow' );
+               $outputPage->addModules( 'mediawiki.action.delete' );
 
                $backlinkCache = $title->getBacklinkCache();
                if ( $backlinkCache->hasLinks( 'pagelinks' ) || $backlinkCache->hasLinks( 'templatelinks' ) ) {
@@ -1717,12 +1728,17 @@ class Article implements Page {
                        ]
                );
 
+               // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
+               // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
+               // Unicode codepoints (or 255 UTF-8 bytes for old schema).
+               $conf = $this->getContext()->getConfig();
+               $oldCommentSchema = $conf->get( 'CommentTableSchemaMigrationStage' ) === MIGRATION_OLD;
                $fields[] = new OOUI\FieldLayout(
                        new OOUI\TextInputWidget( [
                                'name' => 'wpReason',
                                'inputId' => 'wpReason',
                                'tabIndex' => 2,
-                               'maxLength' => 255,
+                               'maxLength' => $oldCommentSchema ? 255 : CommentStore::COMMENT_CHARACTER_LIMIT,
                                'infusable' => true,
                                'value' => $reason,
                                'autofocus' => true,
@@ -2540,7 +2556,7 @@ class Article implements Page {
         * @see WikiPage::updateRedirectOn
         */
        public function updateRedirectOn( $dbw, $redirectTitle, $lastRevIsRedirect = null ) {
-               return $this->mPage->updateRedirectOn( $dbw, $redirectTitle, $lastRevIsRedirect = null );
+               return $this->mPage->updateRedirectOn( $dbw, $redirectTitle, $lastRevIsRedirect );
        }
 
        /**