Add returntoquery= parameter to Special:Userlogin which adds a query string to the...
[lhc/web/wiklou.git] / includes / Title.php
index 9245752..490ebfa 100644 (file)
@@ -862,11 +862,6 @@ class Title {
         */
        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() ) {
                        $ret = $this->getFullURL( $query );
                } elseif( $this->getPrefixedText() === '' && $this->getFragment() !== '' ) {
@@ -1483,7 +1478,33 @@ class Title {
         */
        public function userCanRead() {
                global $wgUser, $wgGroupPermissions;
-
+               
+               static $useShortcut = null;
+
+               # Initialize the $useShortcut boolean, to determine if we can skip quite a bit of code below
+               if( is_null( $useShortcut ) ) {
+                       global $wgRevokePermissions;
+                       $useShortcut = true;
+                       if( empty( $wgGroupPermissions['*']['read'] ) ) {
+                               # Not a public wiki, so no shortcut
+                               $useShortcut = false;
+                       } elseif( !empty( $wgRevokePermissions ) ) {
+                               /*
+                                * Iterate through each group with permissions being revoked (key not included since we don't care
+                                * what the group name is), then check if the read permission is being revoked. If it is, then
+                                * we don't use the shortcut below since the user might not be able to read, even though anon
+                                * reading is allowed.
+                                */
+                               foreach( $wgRevokePermissions as $perms ) {
+                                       if( !empty( $perms['read'] ) ) {
+                                               # We might be removing the read right from the user, so no shortcut
+                                               $useShortcut = false;
+                                               break;
+                                       }
+                               }
+                       }
+               }
+               
                $result = null;
                wfRunHooks( 'userCan', array( &$this, &$wgUser, 'read', &$result ) );
                if ( $result !== null ) {
@@ -1491,7 +1512,7 @@ class Title {
                }
 
                # Shortcut for public wikis, allows skipping quite a bit of code
-               if ( !empty( $wgGroupPermissions['*']['read'] ) )
+               if ( $useShortcut )
                        return true;
 
                if( $wgUser->isAllowed( 'read' ) ) {
@@ -3495,40 +3516,29 @@ class Title {
         * Generate strings used for xml 'id' names in monobook tabs
         * @return \type{\string} XML 'id' name
         */
-       public function getNamespaceKey() {
-               global $wgContLang;
-               switch ($this->getNamespace()) {
-                       case NS_MAIN:
-                       case NS_TALK:
-                               return 'nstab-main';
-                       case NS_USER:
-                       case NS_USER_TALK:
-                               return 'nstab-user';
-                       case NS_MEDIA:
-                               return 'nstab-media';
-                       case NS_SPECIAL:
-                               return 'nstab-special';
-                       case NS_PROJECT:
-                       case NS_PROJECT_TALK:
-                               return 'nstab-project';
-                       case NS_FILE:
-                       case NS_FILE_TALK:
-                               return 'nstab-image';
-                       case NS_MEDIAWIKI:
-                       case NS_MEDIAWIKI_TALK:
-                               return 'nstab-mediawiki';
-                       case NS_TEMPLATE:
-                       case NS_TEMPLATE_TALK:
-                               return 'nstab-template';
-                       case NS_HELP:
-                       case NS_HELP_TALK:
-                               return 'nstab-help';
-                       case NS_CATEGORY:
-                       case NS_CATEGORY_TALK:
-                               return 'nstab-category';
-                       default:
-                               return 'nstab-' . $wgContLang->lc( $this->getSubjectNsText() );
+       public function getNamespaceKey( $prepend = 'nstab-' ) {
+               global $wgContLang, $wgCanonicalNamespaceNames;
+               // Gets the subject namespace if this title
+               $namespace = MWNamespace::getSubject( $this->getNamespace() );
+               // Checks if cononical namespace name exists for namespace
+               if ( isset( $wgCanonicalNamespaceNames[$namespace] ) ) {
+                       // Uses canonical namespace name
+                       $namespaceKey = $wgCanonicalNamespaceNames[$namespace];
+               } else {
+                       // Uses text of namespace
+                       $namespaceKey = $this->getSubjectNsText();
+               }
+               // Makes namespace key lowercase
+               $namespaceKey = $wgContLang->lc( $namespaceKey );
+               // Uses main
+               if ( $namespaceKey == '' ) {
+                       $namespaceKey = 'main';
+               }
+               // Changes file to image for backwards compatibility
+               if ( $namespaceKey == 'file' ) {
+                       $namespaceKey = 'image';
                }
+               return $prepend . $namespaceKey;
        }
 
        /**