Merge "Cache page content language in Title object"
[lhc/web/wiklou.git] / includes / Title.php
index 3418fa2..09c5a3a 100644 (file)
@@ -2459,31 +2459,31 @@ class Title {
        }
 
        /**
-        * Is this page "semi-protected" - the *only* protection is autoconfirm?
+        * Is this page "semi-protected" - the *only* protection levels are listed
+        * in $wgSemiprotectedRestrictionLevels?
         *
         * @param string $action Action to check (default: edit)
         * @return Bool
         */
        public function isSemiProtected( $action = 'edit' ) {
-               if ( $this->exists() ) {
-                       $restrictions = $this->getRestrictions( $action );
-                       if ( count( $restrictions ) > 0 ) {
-                               foreach ( $restrictions as $restriction ) {
-                                       if ( strtolower( $restriction ) != 'editsemiprotected' &&
-                                               strtolower( $restriction ) != 'autoconfirmed' // BC
-                                       ) {
-                                               return false;
-                                       }
-                               }
-                       } else {
-                               # Not protected
-                               return false;
-                       }
-                       return true;
-               } else {
-                       # If it doesn't exist, it can't be protected
+               global $wgSemiprotectedRestrictionLevels;
+
+               $restrictions = $this->getRestrictions( $action );
+               $semi = $wgSemiprotectedRestrictionLevels;
+               if ( !$restrictions || !$semi ) {
+                       // Not protected, or all protection is full protection
                        return false;
                }
+
+               // Remap autoconfirmed to editsemiprotected for BC
+               foreach ( array_keys( $semi, 'autoconfirmed' ) as $key ) {
+                       $semi[$key] = 'editsemiprotected';
+               }
+               foreach ( array_keys( $restrictions, 'autoconfirmed' ) as $key ) {
+                       $restrictions[$key] = 'editsemiprotected';
+               }
+
+               return !array_diff( $restrictions, $semi );
        }
 
        /**
@@ -3905,7 +3905,12 @@ class Title {
                        __METHOD__
                );
 
-               $this->resetArticleID( 0 );
+               // clean up the old title before reset article id - bug 45348
+               if ( !$redirectContent ) {
+                       WikiPage::onArticleDelete( $this );
+               }
+
+               $this->resetArticleID( 0 ); // 0 == non existing
                $nt->resetArticleID( $oldid );
                $newpage->loadPageData( WikiPage::READ_LOCKING ); // bug 46397
 
@@ -3921,13 +3926,12 @@ class Title {
                }
 
                # Recreate the redirect, this time in the other direction.
-               if ( !$redirectContent ) {
-                       WikiPage::onArticleDelete( $this );
-               } else {
+               if ( $redirectContent ) {
                        $redirectArticle = WikiPage::factory( $this );
                        $redirectArticle->loadFromRow( false, WikiPage::READ_LOCKING ); // bug 46397
                        $newid = $redirectArticle->insertOn( $dbw );
                        if ( $newid ) { // sanity
+                               $this->resetArticleID( $newid );
                                $redirectRevision = new Revision( array(
                                        'title' => $this, // for determining the default content model
                                        'page' => $newid,