INDEX use fixes
[lhc/web/wiklou.git] / includes / Title.php
index ae0f986..616aebd 100644 (file)
@@ -339,7 +339,7 @@ class Title {
                // recursive check to follow double redirects
                $recurse = $wgMaxRedirects;
                $titles = array( $title );
-               while( --$recurse >= 0 ) {
+               while( --$recurse > 0 ) {
                        if( $title->isRedirect() ) {
                                $article = new Article( $title, 0 );
                                $newtitle = $article->getRedirectTarget();
@@ -555,7 +555,7 @@ class Title {
         * @return \type{\string} Namespace text
         */
        public function getNsText() {
-               global $wgCanonicalNamespaceNames;
+               global $wgContLang, $wgCanonicalNamespaceNames;
 
                if ( '' != $this->mInterwiki ) {
                        // This probably shouldn't even happen. ohh man, oh yuck.
@@ -568,35 +568,6 @@ class Title {
                                return $wgCanonicalNamespaceNames[$this->mNamespace];
                        }
                }
-
-               return $this->getNsTextInternal( $this->mNamespace );
-       }
-
-       function getNsTextInternal( $namespace ) {
-               global $wgContLang, $wgRequest, $wgTitle, $wgSlowGenderAliases;
-               if( $namespace === NS_USER || $namespace === NS_USER_TALK ) {
-                       static $gender = null;
-
-                       $name = $this->getBaseText();
-                       if( !isset($gender[$name] ) ) {
-                               $gender[$name] = User::getDefaultOption( 'gender' );
-
-                               // wgTitle may not be defined
-                               $mytitle = isset( $wgTitle ) ? $wgTitle : Title::newFromText( $wgRequest->getVal( 'title' ) );
-
-                               // Check stuff
-                               if ( $wgSlowGenderAliases ||
-                                    // Needs to be checked always to produce desired
-                                    // effect when viewing user pages
-                                    ( $mytitle && $name === $mytitle->getBaseText() ) ) {
-
-                                       $user = User::newFromName( $name );
-                                       if ( $user ) $gender[$name] = $user->getOption( 'gender' );
-                               }
-                       }
-
-                       return $wgContLang->getGenderNsText( $this->mNamespace, $gender[$name] );
-               }
                return $wgContLang->getNsText( $this->mNamespace );
        }
        /**
@@ -611,14 +582,16 @@ class Title {
         * @return \type{\string} Namespace text
         */
        public function getSubjectNsText() {
-               return $this->getNsTextInternal( MWNamespace::getSubject( $this->mNamespace ) );
+               global $wgContLang;
+               return $wgContLang->getNsText( MWNamespace::getSubject( $this->mNamespace ) );
        }
        /**
         * Get the namespace text of the talk page
         * @return \type{\string} Namespace text
         */
        public function getTalkNsText() {
-               return $this->getNsTextInternal( MWNamespace::getTalk( $this->mNamespace ) );
+               global $wgContLang;
+               return( $wgContLang->getNsText( MWNamespace::getTalk( $this->mNamespace ) ) );
        }
        /**
         * Could this title have a corresponding talk page?
@@ -894,19 +867,21 @@ class Title {
         * @return \type{\string} the URL
         */
        public function getLinkUrl( $query = array(), $variant = false ) {
+               wfProfileIn( __METHOD__ );
                if( !is_array( $query ) ) {
+                       wfProfileOut( __METHOD__ );
                        throw new MWException( 'Title::getLinkUrl passed a non-array for '.
                        '$query' );
                }
                if( $this->isExternal() ) {
-                       return $this->getFullURL( $query );
-               } elseif( $this->getPrefixedText() === ''
-               and $this->getFragment() !== '' ) {
-                       return $this->getFragmentForURL();
+                       $ret = $this->getFullURL( $query );
+               } elseif( $this->getPrefixedText() === '' && $this->getFragment() !== '' ) {
+                       $ret = $this->getFragmentForURL();
                } else {
-                       return $this->getLocalURL( $query, $variant )
-                               . $this->getFragmentForURL();
+                       $ret = $this->getLocalURL( $query, $variant ) . $this->getFragmentForURL();
                }
+               wfProfileOut( __METHOD__ );
+               return $ret;
        }
 
        /**
@@ -1640,7 +1615,6 @@ class Title {
                        return $this->mHasSubpages;
                }
 
-               $db = wfGetDB( DB_SLAVE );
                $subpages = $this->getSubpages( 1 );
                if( $subpages instanceof TitleArray )
                        return $this->mHasSubpages = (bool)$subpages->count();
@@ -1653,7 +1627,7 @@ class Title {
         * @return mixed TitleArray, or empty array if this page's namespace
         *  doesn't allow subpages
         */
-       public function getSubpages($limit = -1) {
+       public function getSubpages( $limit = -1 ) {
                if( !MWNamespace::hasSubpages( $this->getNamespace() ) )
                        return array();
 
@@ -2005,20 +1979,45 @@ class Title {
         * @return \type{\int} the number of archived revisions
         */
        public function isDeleted() {
-               $fname = 'Title::isDeleted';
-               if ( $this->getNamespace() < 0 ) {
+               if( $this->getNamespace() < 0 ) {
                        $n = 0;
                } else {
                        $dbr = wfGetDB( DB_SLAVE );
-                       $n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(),
-                               'ar_title' => $this->getDBkey() ), $fname );
+                       $n = $dbr->selectField( 'archive', 'COUNT(*)', 
+                               array( 'ar_namespace' => $this->getNamespace(), 'ar_title' => $this->getDBkey() ),
+                               __METHOD__
+                       );
                        if( $this->getNamespace() == NS_FILE ) {
                                $n += $dbr->selectField( 'filearchive', 'COUNT(*)',
-                                       array( 'fa_name' => $this->getDBkey() ), $fname );
+                                       array( 'fa_name' => $this->getDBkey() ),
+                                       __METHOD__
+                               );
                        }
                }
                return (int)$n;
        }
+       
+       /**
+        * Is there a version of this page in the deletion archive?
+        * @return bool
+        */
+       public function isDeletedQuick() {
+               if( $this->getNamespace() < 0 ) {
+                       return false;
+               }
+               $dbr = wfGetDB( DB_SLAVE );
+               $deleted = (bool)$dbr->selectField( 'archive', '1',
+                       array( 'ar_namespace' => $this->getNamespace(), 'ar_title' => $this->getDBkey() ),
+                       __METHOD__
+               );
+               if( !$deleted && $this->getNamespace() == NS_FILE ) {
+                       $deleted = (bool)$dbr->selectField( 'filearchive', '1',
+                               array( 'fa_name' => $this->getDBkey() ),
+                               __METHOD__
+                       );
+               }
+               return $deleted;
+       }
 
        /**
         * Get the article ID for this Title from the link cache,
@@ -2198,6 +2197,9 @@ class Title {
                #
                $dbkey = preg_replace( '/[ _]+/', '_', $dbkey );
                $dbkey = trim( $dbkey, '_' );
+               
+               # Clean up Arabic harakats (bug 16899)
+               $dbkey = preg_replace( '/[\x{064B}-\x{0652}]/Su', '', $dbkey );
 
                if ( '' == $dbkey ) {
                        return false;
@@ -2470,42 +2472,35 @@ class Title {
         * Get an array of Title objects referring to non-existent articles linked from this page
         *
         * @todo check if needed (used only in SpecialBrokenRedirects.php, and should use redirect table in this case)
-        * @param array $options may be FOR UPDATE
         * @return \type{\arrayof{Title}} the Title objects
         */
-       public function getBrokenLinksFrom( $options = array() ) {
+       public function getBrokenLinksFrom() {
                if ( $this->getArticleId() == 0 ) {
                        # All links from article ID 0 are false positives
                        return array();
                }
 
-               if ( count( $options ) > 0 ) {
-                       $db = wfGetDB( DB_MASTER );
-               } else {
-                       $db = wfGetDB( DB_SLAVE );
-               }
-
-               $res = $db->safeQuery(
-                         "SELECT pl_namespace, pl_title
-                            FROM !
-                       LEFT JOIN !
-                              ON pl_namespace=page_namespace
-                             AND pl_title=page_title
-                           WHERE pl_from=?
-                             AND page_namespace IS NULL
-                                 !",
-                       $db->tableName( 'pagelinks' ),
-                       $db->tableName( 'page' ),
-                       $this->getArticleId(),
-                       $options );
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select(
+                       array( 'page', 'pagelinks' ),
+                       array( 'pl_namespace', 'pl_title' ),
+                       array(
+                               'pl_from' => $this->getArticleId(),
+                               'page_namespace IS NULL'
+                       ),
+                       __METHOD__, array(),
+                       array(
+                               'page' => array( 
+                                       'LEFT JOIN', 
+                                       array( 'pl_namespace=page_namespace', 'pl_title=page_title' )
+                               )
+                       )
+               );
 
                $retVal = array();
-               if ( $db->numRows( $res ) ) {
-                       foreach( $res as $row ) {
-                               $retVal[] = Title::makeTitle( $row->pl_namespace, $row->pl_title );
-                       }
+               foreach( $res as $row ) {
+                       $retVal[] = Title::makeTitle( $row->pl_namespace, $row->pl_title );
                }
-               $db->freeResult( $res );
                return $retVal;
        }
 
@@ -3391,7 +3386,7 @@ class Title {
                if( $this->mInterwiki != '' ) {
                        return true;  // any interwiki link might be viewable, for all we know
                }
-               switch( $this->mNamespace ) {                   
+               switch( $this->mNamespace ) {
                case NS_MEDIA:
                case NS_FILE:
                        return wfFindFile( $this );  // file exists, possibly in a foreign repo