(Bug 15936) New page's patrol button should always be visible
[lhc/web/wiklou.git] / includes / Title.php
index 593b11c..bac558f 100644 (file)
@@ -452,8 +452,12 @@ class Title {
         */
        static function escapeFragmentForURL( $fragment ) {
                global $wgEnforceHtmlIds;
+               # Note that we don't urlencode the fragment.  urlencoded Unicode
+               # fragments appear not to work in IE (at least up to 7) or in at least
+               # one version of Opera 9.x.  The W3C validator, for one, doesn't seem
+               # to care if they aren't encoded.
                return Sanitizer::escapeId( $fragment,
-                       $wgEnforceHtmlIds ? array() : 'xml' );
+                       $wgEnforceHtmlIds ? 'noninitial' : 'xml' );
        }
 
 #----------------------------------------------------------------------------
@@ -760,7 +764,9 @@ class Title {
                                                $query = $matches[1];
                                                if( isset( $matches[4] ) ) $query .= $matches[4];
                                                $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
-                                               if( $query != '' ) $url .= '?' . $query;
+                                               if( $query != '' ) {
+                                                       $url = wfAppendQuery( $url, $query );
+                                               }
                                        }
                                }
                                if ( $url === false ) {
@@ -1009,7 +1015,9 @@ class Title {
                }
                $errors = $this->getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries );
 
-               global $wgContLang, $wgLang, $wgEmailConfirmToEdit;
+               global $wgContLang;
+               global $wgLang;
+               global $wgEmailConfirmToEdit;
 
                if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount' ) {
                        $errors[] = array( 'confirmedittext' );
@@ -1041,7 +1049,20 @@ class Title {
                        $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $user->mBlock->mTimestamp ), true );
 
                        if ( $blockExpiry == 'infinity' ) {
-                               $blockExpiry = wfMsg( 'ipbinfinite' );
+                               // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
+                               $scBlockExpiryOptions = wfMsg( 'ipboptions' );
+
+                               foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
+                                       if ( strpos( $option, ':' ) == false )
+                                               continue;
+
+                                       list ($show, $value) = explode( ":", $option );
+
+                                       if ( $value == 'infinite' || $value == 'indefinite' ) {
+                                               $blockExpiry = $show;
+                                               break;
+                                       }
+                               }
                        } else {
                                $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true );
                        }
@@ -1051,9 +1072,9 @@ class Title {
                        $errors[] = array( ($block->mAuto ? 'autoblockedtext' : 'blockedtext'), $link, $reason, $ip, $name, 
                                $blockid, $blockExpiry, $intended, $blockTimestamp );
                }
-
+               
                // Remove the errors being ignored.
-
+               
                foreach( $errors as $index => $error ) {
                        $error_key = is_array($error) ? $error[0] : $error;
                        
@@ -1076,8 +1097,6 @@ class Title {
         * @return \type{\array} Array of arrays of the arguments to wfMsg to explain permissions problems.
         */
        private function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries = true ) {
-               global $wgLang;
-
                wfProfileIn( __METHOD__ );
 
                $errors = array();
@@ -1249,34 +1268,6 @@ class Title {
                        $errors[] = $return;
                }
 
-               // Check per-user restrictions
-               if( $doExpensiveQueries && $action != 'read' ) {
-                       $rs = UserRestriction::fetchForTitle( $user, $this );
-                       if( !$rs )
-                               $rs = UserRestriction::fetchForNamespace( $user, $this->getNamespace() );
-                       if( $rs ) {
-                               $r = $rs[0];
-                               if( !$r->deleteIfExpired() ) {
-                                       $error = array(); 
-                                       $start = array( $wgLang->date( $r->getTimestamp() ), $wgLang->time( $r->getTimestamp() ) );
-                                       if( $r->isPage() )
-                                               $error = array( 'userrestricted-page', $this->getFullText(),
-                                                       $r->getBlockerText(), $r->getReason(), $start[0], $start[1] );
-                                       elseif( $r->isNamespace() )
-                                               $error = array( 'userrestricted-namespace', $wgLang->getDisplayNsText( $this->getNamespace() ),
-                                                       $r->getBlockerText(), $r->getReason(), $start[0], $start[1] );
-
-                                       if( $r->getExpiry() == 'infinity' ) {
-                                               $error[0] .= '-indef';
-                                       } else {
-                                               $error[] = $wgLang->date( $r->getExpiry() );
-                                               $error[] = $wgLang->time( $r->getExpiry() );
-                                       }
-                                       $errors[] = $error;
-                               }
-                       }
-               }
-
                wfProfileOut( __METHOD__ );
                return $errors;
        }
@@ -1327,7 +1318,7 @@ class Title {
 
                $expiry_description = '';
                if ( $encodedExpiry != 'infinity' ) {
-                       $expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry ) ).')';
+                       $expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry ) , $wgContLang->date( $expiry ) , $wgContLang->time( $expiry ) ).')';
                }
                else {
                        $expiry_description .= ' (' . wfMsgForContent( 'protect-expiry-indefinite' ).')';
@@ -2568,17 +2559,11 @@ class Title {
                        );
                        # Update the protection log
                        $log = new LogPage( 'protect' );
-                       $comment = wfMsgForContent('prot_1movedto2',$this->getPrefixedText(), $nt->getPrefixedText() );
-                       if( $reason ) $comment .= ': ' . $reason;
+                       $comment = wfMsgForContent( 'prot_1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
+                       if( $reason ) $comment .= wfMsgForContent( 'colon-separator' ) . $reason;
                        $log->addEntry( 'move_prot', $nt, $comment, array($this->getPrefixedText()) ); // FIXME: $params?
                }
 
-               # Update user restrictions
-               $dbw->update( 'user_restrictions',
-                       array( 'ur_page_namespace' => $nt->getNamespace(), 'ur_page_title' => $nt->getDBKey() ),
-                       array( 'ur_page_namespace' => $this->getNamespace(), 'ur_page_title' => $this->getDBKey() ),
-                       __METHOD__ );
-
                # Update watchlists
                $oldnamespace = $this->getNamespace() & ~1;
                $newnamespace = $nt->getNamespace() & ~1;
@@ -3048,6 +3033,28 @@ class Title {
                );
        }
        
+       /**
+        * Get the first revision of the page
+        *
+        * @param $flags \type{\int} GAID_FOR_UPDATE
+        * @return Revision (or NULL if page doesn't exist)
+        */
+       public function getFirstRevision( $flags=0 ) {
+               $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
+               $pageId = $this->getArticleId($flags);
+               if( !$pageId ) return NULL;
+               $row = $db->selectRow( 'revision', '*',
+                       array( 'rev_page' => $pageId ),
+                       __METHOD__,
+                       array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 1 )
+               );
+               if( !$row ) {
+                       return NULL;
+               } else {
+                       return new Revision( $row );
+               }
+       }
+       
        /**
         * Check if this is a new page
         *
@@ -3191,6 +3198,15 @@ class Title {
        public function isKnown() {
                return $this->exists() || $this->isAlwaysKnown();
        }
+       
+       /**
+       * Is this in a namespace that allows actual pages?
+       *
+       * @return \type{\bool} TRUE or FALSE
+       */
+       public function canExist() {
+               return $this->mNamespace >= 0 && $this->mNamespace != NS_MEDIA;
+       }
 
        /**
         * Update page_touched timestamps and send squid purge messages for