Revert r91561
[lhc/web/wiklou.git] / includes / Title.php
index 81715ca..418740d 100644 (file)
@@ -860,7 +860,7 @@ class Title {
                # Finally, add the fragment.
                $url .= $this->getFragmentForURL();
 
-               wfRunHooks( 'GetFullURL', array( &$this, &$url, $query ) );
+               wfRunHooks( 'GetFullURL', array( &$this, &$url, $query, $variant ) );
                return $url;
        }
 
@@ -1028,7 +1028,7 @@ class Title {
                        $server = $wgInternalServer !== false ? $wgInternalServer : $wgServer;
                }
                $url = wfExpandUrl( $server . $this->getLocalURL( $query, $variant ), PROTO_HTTP );
-               wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) );
+               wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query, $variant ) );
                return $url;
        }
 
@@ -1044,9 +1044,8 @@ class Title {
         * @return string The URL
         */
        public function getCanonicalURL( $query = '', $variant = false ) {
-               global $wgCanonicalServer;
-               $url = $wgCanonicalServer . $this->getLocalURL( $query, $variant ) . $this->getFragmentForURL();
-               wfRunHooks( 'GetCanonicalURL', array( &$this, &$url, $query ) );
+               $url = wfExpandUrl( $this->getLocalURL( $query, $variant ) . $this->getFragmentForURL(), PROTO_CANONICAL );
+               wfRunHooks( 'GetCanonicalURL', array( &$this, &$url, $query, $variant ) );
                return $url;
        }
 
@@ -1555,7 +1554,7 @@ class Title {
                                $errors[] = array( 'immobile-source-namespace', $this->getNsText() );
                        } elseif ( !$this->isMovable() ) {
                                // Less specific message for rarer cases
-                               $errors[] = array( 'immobile-page' );
+                               $errors[] = array( 'immobile-source-page' );
                        }
                } elseif ( $action == 'move-target' ) {
                        if ( !MWNamespace::isMovable( $this->mNamespace ) ) {
@@ -1786,7 +1785,12 @@ class Title {
         * @return Bool TRUE or FALSE
         */
        public function isMovable() {
-               $result = MWNamespace::isMovable( $this->getNamespace() ) && $this->getInterwiki() == '';
+               if ( !MWNamespace::isMovable( $this->getNamespace() ) || $this->getInterwiki() != '' ) {
+                       // Interwiki title or immovable namespace. Hooks don't get to override here
+                       return false;
+               }
+               
+               $result = true;
                wfRunHooks( 'TitleIsMovable', array( $this, &$result ) );
                return $result;
        }
@@ -1894,6 +1898,7 @@ class Title {
         * acidentally creating new bugs where $title->equals( Title::newFromText() )
         * ends up reporting something differently than $title->isMainPage();
         *
+        * @since 1.18
         * @return Bool
         */
        public function isMainPage() {
@@ -2386,37 +2391,21 @@ class Title {
        /**
         * Is there a version of this page in the deletion archive?
         *
-        * @param $includeSuppressed Boolean Include suppressed revisions?
         * @return Int the number of archived revisions
         */
-       public function isDeleted( $includeSuppressed = false ) {
+       public function isDeleted() {
                if ( $this->getNamespace() < 0 ) {
                        $n = 0;
                } else {
                        $dbr = wfGetDB( DB_SLAVE );
-                       $conditions = array( 'ar_namespace' => $this->getNamespace(), 'ar_title' => $this->getDBkey() );
-
-                       if( !$includeSuppressed ) {
-                               $suppressedTextBits = Revision::DELETED_TEXT | Revision::DELETED_RESTRICTED;
-                               $conditions[] = $dbr->bitAnd('ar_deleted', $suppressedTextBits ) .
-                               ' != ' . $suppressedTextBits;
-                       }
 
                        $n = $dbr->selectField( 'archive', 'COUNT(*)',
-                               $conditions,
+                               array( 'ar_namespace' => $this->getNamespace(), 'ar_title' => $this->getDBkey() ),
                                __METHOD__
                        );
                        if ( $this->getNamespace() == NS_FILE ) {
-                               $fconditions = array( 'fa_name' => $this->getDBkey() );
-                               if( !$includeSuppressed ) {
-                                       $suppressedTextBits = File::DELETED_FILE | File::DELETED_RESTRICTED;
-                                       $fconditions[] = $dbr->bitAnd('fa_deleted', $suppressedTextBits ) .
-                                       ' != ' . $suppressedTextBits;
-                               }
-
-                               $n += $dbr->selectField( 'filearchive',
-                                       'COUNT(*)',
-                                       $fconditions,
+                               $n += $dbr->selectField( 'filearchive', 'COUNT(*)',
+                                       array( 'fa_name' => $this->getDBkey() ),
                                        __METHOD__
                                );
                        }
@@ -2547,7 +2536,7 @@ class Title {
         */
        public function resetArticleID( $newid ) {
                $linkCache = LinkCache::singleton();
-               $linkCache->clearBadLink( $this->getPrefixedDBkey() );
+               $linkCache->clearLink( $this );
 
                if ( $newid === false ) {
                        $this->mArticleID = -1;
@@ -3327,11 +3316,28 @@ class Title {
        private function moveOverExistingRedirect( &$nt, $reason = '', $createRedirect = true ) {
                global $wgUser, $wgContLang, $wgEnableInterwikiTemplatesTracking, $wgGlobalDatabase;
 
-               $moveOverRedirect = $nt->exists();
+               if ( $nt->exists() ) {
+                       $moveOverRedirect = true;
+                       $logType = 'move_redir';
+               } else {
+                       $moveOverRedirect = false;
+                       $logType = 'move';
+               }
 
-               $commentMsg = ( $moveOverRedirect ? '1movedto2_redir' : '1movedto2' );
-               $comment = wfMsgForContent( $commentMsg, $this->getPrefixedText(), $nt->getPrefixedText() );
+               $redirectSuppressed = !$createRedirect && $wgUser->isAllowed( 'suppressredirect' );
 
+               $logEntry = new ManualLogEntry( 'move', $logType );
+               $logEntry->setPerformer( $wgUser );
+               $logEntry->setTarget( $this );
+               $logEntry->setComment( $reason );
+               $logEntry->setParameters( array(
+                       '4::target' => $nt->getPrefixedText(),
+                       '5::noredir' => $redirectSuppressed ? '1': '0',
+               ) );
+
+               $formatter = LogFormatter::newFromEntry( $logEntry );
+               $formatter->setContext( RequestContext::newExtraneousContext( $this ) );
+               $comment = $formatter->getPlainActionText();
                if ( $reason ) {
                        $comment .= wfMsgForContent( 'colon-separator' ) . $reason;
                }
@@ -3382,7 +3388,7 @@ class Title {
                                                        array(  'gtl_from_wiki' => wfGetID(),
                                                                        'gtl_from_page' => $newid ),
                                                        __METHOD__ );
-               }
+                       }
                }
 
                # Save a null revision in the page's history notifying of the move
@@ -3438,16 +3444,13 @@ class Title {
                                                'pl_title'     => $nt->getDBkey() ),
                                        __METHOD__ );
                        }
-                       $redirectSuppressed = false;
                } else {
                        $this->resetArticleID( 0 );
-                       $redirectSuppressed = true;
                }
 
                # Log the move
-               $log = new LogPage( 'move' );
-               $logType = ( $moveOverRedirect ? 'move_redir' : 'move' );
-               $log->addEntry( $logType, $this, $reason, array( 1 => $nt->getPrefixedText(), 2 => $redirectSuppressed ) );
+               $logid = $logEntry->insert();
+               $logEntry->publish( $logid );
 
                # Purge caches for old and new titles
                if ( $moveOverRedirect ) {
@@ -3855,6 +3858,18 @@ class Title {
                        && $this->getDBkey() === $title->getDBkey();
        }
 
+       /**
+        * Check if this title is a subpage of another title
+        *
+        * @param $title Title
+        * @return Bool
+        */
+       public function isSubpageOf( Title $title ) {
+               return $this->getInterwiki() === $title->getInterwiki()
+                       && $this->getNamespace() == $title->getNamespace()
+                       && strpos( $this->getDBkey(), $title->getDBkey() . '/' ) === 0;
+       }
+
        /**
         * Callback for usort() to do title sorts by (namespace, title)
         *