Merge "Fix edit link for messages in $wgForceUIMsgAsContentMsg"
[lhc/web/wiklou.git] / includes / page / Article.php
index eb597d2..48f3161 100644 (file)
@@ -378,7 +378,7 @@ class Article implements Page {
                # Pre-fill content with error message so that if something
                # fails we'll have something telling us what we intended.
                //XXX: this isn't page content but a UI message. horrible.
-               $this->mContentObject = new MessageContent( 'missing-revision', array( $oldid ), array() );
+               $this->mContentObject = new MessageContent( 'missing-revision', array( $oldid ) );
 
                if ( $oldid ) {
                        # $this->mRevision might already be fetched by getOldIDFromRequest()
@@ -390,17 +390,20 @@ class Article implements Page {
                                }
                        }
                } else {
-                       if ( !$this->mPage->getLatest() ) {
+                       $oldid = $this->mPage->getLatest();
+                       if ( !$oldid ) {
                                wfDebug( __METHOD__ . " failed to find page data for title " .
                                        $this->getTitle()->getPrefixedText() . "\n" );
                                return false;
                        }
 
+                       # Update error message with correct oldid
+                       $this->mContentObject = new MessageContent( 'missing-revision', array( $oldid ) );
+
                        $this->mRevision = $this->mPage->getRevision();
 
                        if ( !$this->mRevision ) {
-                               wfDebug( __METHOD__ . " failed to retrieve current page, rev_id " .
-                                       $this->mPage->getLatest() . "\n" );
+                               wfDebug( __METHOD__ . " failed to retrieve current page, rev_id $oldid\n" );
                                return false;
                        }
                }
@@ -1251,22 +1254,22 @@ class Article implements Page {
 
                # Show error message
                $oldid = $this->getOldID();
-               if ( $oldid ) {
-                       $text = wfMessage( 'missing-revision', $oldid )->plain();
-               } elseif ( $title->getNamespace() === NS_MEDIAWIKI ) {
-                       // Use the default message text
-                       $text = $title->getDefaultMessageText();
-               } elseif ( $title->quickUserCan( 'create', $this->getContext()->getUser() )
-                       && $title->quickUserCan( 'edit', $this->getContext()->getUser() )
-               ) {
-                       $message = $this->getContext()->getUser()->isLoggedIn() ? 'noarticletext' : 'noarticletextanon';
-                       $text = wfMessage( $message )->plain();
+               if ( !$oldid && $title->getNamespace() === NS_MEDIAWIKI ) {
+                       $outputPage->addParserOutput( $this->getContentObject()->getParserOutput( $title ) );
                } else {
-                       $text = wfMessage( 'noarticletext-nopermission' )->plain();
-               }
-               $text = "<div class='noarticletext'>\n$text\n</div>";
+                       if ( $oldid ) {
+                               $text = wfMessage( 'missing-revision', $oldid )->plain();
+                       } elseif ( $title->quickUserCan( 'create', $this->getContext()->getUser() )
+                               && $title->quickUserCan( 'edit', $this->getContext()->getUser() )
+                       ) {
+                               $message = $this->getContext()->getUser()->isLoggedIn() ? 'noarticletext' : 'noarticletextanon';
+                               $text = wfMessage( $message )->plain();
+                       } else {
+                               $text = wfMessage( 'noarticletext-nopermission' )->plain();
+                       }
 
-               $outputPage->addWikiText( $text );
+                       $outputPage->addWikiText( "<div class='noarticletext'>\n$text\n</div>" );
+               }
        }
 
        /**
@@ -1502,6 +1505,28 @@ class Article implements Page {
                        '</div>';
        }
 
+       /**
+        * Adds help link with an icon via page indicators.
+        * Link target can be overridden by a local message containing a wikilink:
+        * the message key is: 'namespace-' + namespace number + '-helppage'.
+        * @param string $to Target MediaWiki.org page title or encoded URL.
+        * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o.
+        * @since 1.25
+        */
+       public function addHelpLink( $to, $overrideBaseUrl = false ) {
+               $msg = wfMessage(
+                       'namespace-' . $this->getTitle()->getNamespace() . '-helppage'
+               );
+
+               $out = $this->getContext()->getOutput();
+               if ( !$msg->isDisabled() ) {
+                       $helpUrl = Skin::makeUrl( $msg->plain() );
+                       $out->addHelpLink( $helpUrl, true );
+               } else {
+                       $out->addHelpLink( $to, $overrideBaseUrl );
+               }
+       }
+
        /**
         * Handle action=render
         */
@@ -1747,9 +1772,8 @@ class Article implements Page {
                        Xml::closeElement( 'form' );
 
                        if ( $user->isAllowed( 'editinterface' ) ) {
-                               $dropdownTitle = Title::makeTitle( NS_MEDIAWIKI, 'Deletereason-dropdown' );
                                $link = Linker::link(
-                                       $dropdownTitle,
+                                       $ctx->msg( 'deletereason-dropdown' )->inContentLanguage()->getTitle(),
                                        wfMessage( 'delete-edit-reasonlist' )->escaped(),
                                        array(),
                                        array( 'action' => 'edit' )