* Display the anon talk page info message on anon talk pages again (moved outside...
[lhc/web/wiklou.git] / includes / Article.php
index 33ffc76..4ede20f 100644 (file)
@@ -175,32 +175,23 @@ class Article {
                        return "<div class='noarticletext'>$ret</div>";
                } else {
                        $this->loadContent();
-                       # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
-                       if ( $this->mTitle->getNamespace() == NS_USER_TALK &&
-                         $wgUser->isIP($this->mTitle->getText()) &&
-                         $action=='view'
-                       ) {
-                               wfProfileOut( $fname );
-                               return $this->mContent . "\n" .wfMsg('anontalkpagetext');
-                       } else {
-                               if($action=='edit') {
-                                       if($section!='') {
-                                               if($section=='new') {
-                                                       wfProfileOut( $fname );
-                                                       $text=$this->getPreloadedText($preload);
-                                                       return $text;
-                                               }
-
-                                               # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
-                                               # comments to be stripped as well)
-                                               $rv=$this->getSection($this->mContent,$section);
+                       if($action=='edit') {
+                               if($section!='') {
+                                       if($section=='new') {
                                                wfProfileOut( $fname );
-                                               return $rv;
+                                               $text=$this->getPreloadedText($preload);
+                                               return $text;
                                        }
+
+                                       # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
+                                       # comments to be stripped as well)
+                                       $rv=$this->getSection($this->mContent,$section);
+                                       wfProfileOut( $fname );
+                                       return $rv;
                                }
-                               wfProfileOut( $fname );
-                               return $this->mContent;
                        }
+                       wfProfileOut( $fname );
+                       return $this->mContent;
                }
        }
 
@@ -923,6 +914,12 @@ class Article {
                if( empty( $t ) ) {
                        $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
                }
+               
+               # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
+               if( $this->mTitle->getNamespace() == NS_USER_TALK &&
+                       User::isIP( $this->mTitle->getText() ) ) {
+                       $wgOut->addWikiText( wfMsg('anontalkpagetext') );
+               }
 
                # If we have been passed an &rcid= parameter, we want to give the user a
                # chance to mark this new article as patrolled.
@@ -1179,9 +1176,6 @@ class Article {
                        return false;
                }
 
-               $this->mGoodAdjustment = (int)$this->isCountable( $text );
-               $this->mTotalAdjustment = 1;
-
                $ns = $this->mTitle->getNamespace();
                $ttl = $this->mTitle->getDBkey();
 
@@ -1191,6 +1185,13 @@ class Article {
                }
                $text = $this->preSaveTransform( $text );
 
+
+               # Set statistics members
+               # We work out if it's countable after PST to avoid counter drift 
+               # when articles are created with {{subst:}}
+               $this->mGoodAdjustment = (int)$this->isCountable( $text );
+               $this->mTotalAdjustment = 1;
+
                /* Silently ignore minoredit if not allowed */
                $isminor = $isminor && $wgUser->isAllowed('minoredit');
                $now = wfTimestampNow();
@@ -1686,47 +1687,63 @@ class Article {
         * @return bool true on success
         */
        function updateRestrictions( $limit = array(), $reason = '' ) {
-               global $wgUser;
-
-               if ( !$wgUser->isAllowed( 'protect' ) ) {
-                       return false;
-               }
-
-               if( wfReadOnly() ) {
-                       return false;
-               }
-
+               global $wgUser, $wgRestrictionTypes, $wgContLang;
+               
                $id = $this->mTitle->getArticleID();
-               if ( 0 == $id ) {
+               if( !$wgUser->isAllowed( 'protect' ) || wfReadOnly() || $id == 0 ) {
                        return false;
                }
 
-               $flat = Article::flattenRestrictions( $limit );
-               $protecting = ($flat != '');
-
-               if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser,
-                       $limit, $reason ) ) ) {
+               # FIXME: Same limitations as described in ProtectionForm.php (line 37);
+               # we expect a single selection, but the schema allows otherwise.
+               $current = array();
+               foreach( $wgRestrictionTypes as $action )
+                       $current[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
 
-                       $dbw =& wfGetDB( DB_MASTER );
-                       $dbw->update( 'page',
-                               array( /* SET */
-                                       'page_touched' => $dbw->timestamp(),
-                                       'page_restrictions' => $flat
-                               ), array( /* WHERE */
-                                       'page_id' => $id
-                               ), 'Article::protect'
-                       );
-
-                       wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser,
-                               $limit, $reason ) );
+               $current = Article::flattenRestrictions( $current );
+               $updated = Article::flattenRestrictions( $limit );
+               
+               $changed = ( $current != $updated );
+               $protect = ( $updated != '' );
+               
+               # If nothing's changed, do nothing
+               if( $changed ) {
+                       if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser, $limit, $reason ) ) ) {
 
-                       $log = new LogPage( 'protect' );
-                       if( $protecting ) {
-                               $log->addEntry( 'protect', $this->mTitle, trim( $reason . " [$flat]" ) );
-                       } else {
-                               $log->addEntry( 'unprotect', $this->mTitle, $reason );
-                       }
-               }
+                               $dbw =& wfGetDB( DB_MASTER );
+                               
+                               # Prepare a null revision to be added to the history
+                               $comment = $wgContLang->ucfirst( wfMsgForContent( $protect ? 'protectedarticle' : 'unprotectedarticle', $this->mTitle->getPrefixedText() ) );
+                               if( $reason )
+                                       $comment .= ": $reason";
+                               if( $protect )
+                                       $comment .= " [$updated]";
+                               $nullRevision = Revision::newNullRevision( $dbw, $id, $comment, true );
+                               $nullRevId = $nullRevision->insertOn( $dbw );
+                       
+                               # Update page record
+                               $dbw->update( 'page',
+                                       array( /* SET */
+                                               'page_touched' => $dbw->timestamp(),
+                                               'page_restrictions' => $updated,
+                                               'page_latest' => $nullRevId
+                                       ), array( /* WHERE */
+                                               'page_id' => $id
+                                       ), 'Article::protect'
+                               );
+                               wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser, $limit, $reason ) );
+       
+                               # Update the protection log
+                               $log = new LogPage( 'protect' );
+                               if( $protect ) {
+                                       $log->addEntry( 'protect', $this->mTitle, trim( $reason . " [$updated]" ) );
+                               } else {
+                                       $log->addEntry( 'unprotect', $this->mTitle, $reason );
+                               }
+                               
+                       } # End hook
+               } # End "changed" check
+               
                return true;
        }
 
@@ -1742,6 +1759,7 @@ class Article {
                        wfDebugDieBacktrace( 'Article::flattenRestrictions given non-array restriction set' );
                }
                $bits = array();
+               ksort( $limit );
                foreach( $limit as $action => $restrictions ) {
                        if( $restrictions != '' ) {
                                $bits[] = "$action=$restrictions";
@@ -1801,8 +1819,7 @@ class Article {
                
                if( count( $authors ) > 1 && !$confirm ) {
                        $skin=$wgUser->getSkin();
-                       $wgOut->addHTML('<b>'.wfMsg('historywarning'));
-                       $wgOut->addHTML( $skin->historyLink() .'</b>');
+                       $wgOut->addHTML( '<strong>' . wfMsg( 'historywarning' ) . ' ' . $skin->historyLink() . '</strong>' );
                }
 
                # If a single user is responsible for all revisions, find out who they are
@@ -2497,7 +2514,7 @@ class Article {
                        $old_user_abort = ignore_user_abort( true );
 
                        $dbw->query("LOCK TABLES $hitcounterTable WRITE");
-                       $dbw->query("CREATE TEMPORARY TABLE $acchitsTable ENGINE=HEAP ".
+                       $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
                                "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
                                'GROUP BY hc_id');
                        $dbw->query("DELETE FROM $hitcounterTable");