Merge "rebuildLocalisationCache: Implement --lang option"
[lhc/web/wiklou.git] / includes / Article.php
index 10cbac7..87b94ae 100644 (file)
@@ -33,7 +33,7 @@
  *
  * @internal documentation reviewed 15 Mar 2010
  */
-class Article extends Page {
+class Article implements Page {
        /**@{{
         * @private
         */
@@ -134,7 +134,7 @@ class Article extends Page {
 
        /**
         * Constructor from a page id
-        * @param $id Int article ID to load
+        * @param int $id article ID to load
         * @return Article|null
         */
        public static function newFromID( $id ) {
@@ -160,7 +160,7 @@ class Article extends Page {
                $page = null;
                wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
                if ( !$page ) {
-                       switch( $title->getNamespace() ) {
+                       switch ( $title->getNamespace() ) {
                                case NS_FILE:
                                        $page = new ImagePage( $title );
                                        break;
@@ -393,7 +393,6 @@ class Article extends Page {
                return $this->mContent;
        }
 
-
        /**
         * Get text content object
         * Does *NOT* follow redirects.
@@ -420,7 +419,7 @@ class Article extends 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 ), array() );
 
                if ( $oldid ) {
                        # $this->mRevision might already be fetched by getOldIDFromRequest()
@@ -610,7 +609,7 @@ class Article extends Page {
                $this->mParserOutput = false;
 
                while ( !$outputDone && ++$pass ) {
-                       switch( $pass ) {
+                       switch ( $pass ) {
                                case 1:
                                        wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
                                        break;
@@ -674,12 +673,12 @@ class Article extends Page {
                                                wfDebug( __METHOD__ . ": showing CSS/JS source\n" );
                                                $this->showCssOrJsPage();
                                                $outputDone = true;
-                                       } elseif( !wfRunHooks( 'ArticleContentViewCustom',
+                                       } elseif ( !wfRunHooks( 'ArticleContentViewCustom',
                                                        array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
 
                                                # Allow extensions do their own custom view for certain pages
                                                $outputDone = true;
-                                       } elseif( !ContentHandler::runLegacyHooks( 'ArticleViewCustom',
+                                       } elseif ( !ContentHandler::runLegacyHooks( 'ArticleViewCustom',
                                                        array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
 
                                                # Allow extensions do their own custom view for certain pages
@@ -767,6 +766,8 @@ class Article extends Page {
                $this->showViewFooter();
                $this->mPage->doViewUpdates( $user );
 
+               $outputPage->addModules( 'mediawiki.action.view.postEdit' );
+
                wfProfileOut( __METHOD__ );
        }
 
@@ -852,7 +853,7 @@ class Article extends Page {
 
        /**
         * Get the robot policy to be used for the current view
-        * @param $action String the action= GET parameter
+        * @param string $action the action= GET parameter
         * @param $pOutput ParserOutput
         * @return Array the policy that should be set
         * TODO: actions other than 'view'
@@ -874,7 +875,7 @@ class Article extends Page {
                        }
                        if ( Block::newFromTarget( $specificTarget, $vagueTarget ) instanceof Block ) {
                                return array(
-                                       'index'  => 'noindex',
+                                       'index' => 'noindex',
                                        'follow' => 'nofollow'
                                );
                        }
@@ -883,19 +884,19 @@ class Article extends Page {
                if ( $this->mPage->getID() === 0 || $this->getOldID() ) {
                        # Non-articles (special pages etc), and old revisions
                        return array(
-                               'index'  => 'noindex',
+                               'index' => 'noindex',
                                'follow' => 'nofollow'
                        );
                } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
                        # Discourage indexing of printable versions, but encourage following
                        return array(
-                               'index'  => 'noindex',
+                               'index' => 'noindex',
                                'follow' => 'follow'
                        );
                } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
                        # For ?curid=x urls, disallow indexing
                        return array(
-                               'index'  => 'noindex',
+                               'index' => 'noindex',
                                'follow' => 'follow'
                        );
                }
@@ -987,8 +988,9 @@ class Article extends Page {
 
                                // Set the fragment if one was specified in the redirect
                                if ( strval( $this->getTitle()->getFragment() ) != '' ) {
-                                       $fragment = Xml::escapeJsString( $this->getTitle()->getFragmentForURL() );
-                                       $outputPage->addInlineScript( "redirectToFragment(\"$fragment\");" );
+                                       $outputPage->addInlineScript( Xml::encodeJsCall(
+                                               'redirectToFragment', array( $this->getTitle()->getFragmentForURL() )
+                                       ) );
                                }
 
                                // Add a <link rel="canonical"> tag
@@ -1089,6 +1091,7 @@ class Article extends Page {
        public function showMissingArticle() {
                global $wgSend404Code;
                $outputPage = $this->getContext()->getOutput();
+               $validUserPage = false;
 
                # Show info in user (talk) namespace. Does the user exist? Is he blocked?
                if ( $this->getTitle()->getNamespace() == NS_USER || $this->getTitle()->getNamespace() == NS_USER_TALK ) {
@@ -1097,7 +1100,7 @@ class Article extends Page {
                        $user = User::newFromName( $rootPart, false /* allow IP users*/ );
                        $ip = User::isIP( $rootPart );
 
-                       if ( !($user && $user->isLoggedIn()) && !$ip ) { # User does not exist
+                       if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
                                $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
                                        array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
                        } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
@@ -1115,6 +1118,9 @@ class Article extends Page {
                                                )
                                        )
                                );
+                               $validUserPage = true;
+                       } else {
+                               $validUserPage = true;
                        }
                }
 
@@ -1122,13 +1128,13 @@ class Article extends Page {
 
                # Show delete and move logs
                LogEventsList::showLogExtract( $outputPage, array( 'delete', 'move' ), $this->getTitle(), '',
-                       array(  'lim' => 10,
+                       array( 'lim' => 10,
                                'conds' => array( "log_action != 'revision'" ),
                                'showIfEmpty' => false,
                                'msgKey' => array( 'moveddeleted-notice' ) )
                );
 
-               if ( !$this->mPage->hasViewableContent() && $wgSend404Code ) {
+               if ( !$this->mPage->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
                        // If there's no backing content, send a 404 Not Found
                        // for better machine handling of broken links.
                        $this->getContext()->getRequest()->response()->header( "HTTP/1.1 404 Not Found" );
@@ -1183,7 +1189,7 @@ class Article extends Page {
                } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
                        # Give explanation and add a link to view the revision...
                        $oldid = intval( $this->getOldID() );
-                       $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
+                       $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
                        $msg = $this->mRevision->isDeleted( Revision::DELETED_RESTRICTED ) ?
                                'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
                        $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
@@ -1206,7 +1212,7 @@ class Article extends Page {
         *   Revision as of \<date\>; view current revision
         *   \<- Previous version | Next Version -\>
         *
-        * @param $oldid int: revision ID of this article revision
+        * @param int $oldid revision ID of this article revision
         */
        public function setOldSubtitle( $oldid = 0 ) {
                if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
@@ -1268,7 +1274,7 @@ class Article extends Page {
                                        'oldid' => $oldid
                                ) + $extraParams
                        );
-               $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
+               $prev = $this->getTitle()->getPreviousRevisionID( $oldid );
                $prevlink = $prev
                        ? Linker::linkKnown(
                                $this->getTitle(),
@@ -1483,7 +1489,7 @@ class Article extends Page {
                                $reason = $this->generateReason( $hasHistory );
                        } catch ( MWException $e ) {
                                # if a page is horribly broken, we still want to be able to delete it. so be lenient about errors here.
-                               wfDebug("Error while building auto delete summary: $e");
+                               wfDebug( "Error while building auto delete summary: $e" );
                                $reason = '';
                        }
                }
@@ -1514,7 +1520,7 @@ class Article extends Page {
        /**
         * Output deletion confirmation dialog
         * @todo FIXME: Move to another file?
-        * @param $reason String: prefilled reason
+        * @param string $reason prefilled reason
         */
        public function confirmDelete( $reason ) {
                wfDebug( "Article::confirmDelete\n" );
@@ -1722,7 +1728,7 @@ class Article extends Page {
         *
         * @param $oldid mixed integer Revision ID or null
         * @param $user User The relevant user
-        * @return ParserOutput or false if the given revsion ID is not found
+        * @return ParserOutput or false if the given revision ID is not found
         */
        public function getParserOutput( $oldid = null, User $user = null ) {
                //XXX: bypasses mParserOptions and thus setParserOptions()
@@ -1882,8 +1888,8 @@ class Article extends Page {
         *
         * @deprecated in 1.18; call OutputPage::redirect() directly
         * @param $noRedir Boolean: add redirect=no
-        * @param $sectionAnchor String: section to redirect to, including "#"
-        * @param $extraQuery String: extra query params
+        * @param string $sectionAnchor section to redirect to, including "#"
+        * @param string $extraQuery extra query params
         */
        public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
                wfDeprecated( __METHOD__, '1.18' );
@@ -1903,7 +1909,7 @@ class Article extends Page {
         * Use PHP's magic __get handler to handle accessing of
         * raw WikiPage fields for backwards compatibility.
         *
-        * @param $fname String Field name
+        * @param string $fname Field name
         */
        public function __get( $fname ) {
                if ( property_exists( $this->mPage, $fname ) ) {
@@ -1917,7 +1923,7 @@ class Article extends Page {
         * Use PHP's magic __set handler to handle setting of
         * raw WikiPage fields for backwards compatibility.
         *
-        * @param $fname String Field name
+        * @param string $fname Field name
         * @param $fvalue mixed New value
         */
        public function __set( $fname, $fvalue ) {
@@ -1936,8 +1942,8 @@ class Article extends Page {
         * Use PHP's magic __call handler to transform instance calls to
         * WikiPage functions for backwards compatibility.
         *
-        * @param $fname String Name of called method
-        * @param $args Array Arguments to the method
+        * @param string $fname Name of called method
+        * @param array $args Arguments to the method
         * @return mixed
         */
        public function __call( $fname, $args ) {