Fix function level comments that start with /* not /**
[lhc/web/wiklou.git] / includes / Title.php
index 88ec68e..3a4c3fe 100644 (file)
@@ -712,7 +712,8 @@ class Title {
         * @return String the prefixed title, with spaces
         */
        public function getPrefixedText() {
-               if ( empty( $this->mPrefixedText ) ) { // FIXME: bad usage of empty() ?
+               // @todo FIXME: Bad usage of empty() ?
+               if ( empty( $this->mPrefixedText ) ) {
                        $s = $this->prefix( $this->mTextform );
                        $s = str_replace( '_', ' ', $s );
                        $this->mPrefixedText = $s;
@@ -876,33 +877,25 @@ class Title {
                                        $url = str_replace( '$1', $dbkey, $wgArticlePath );
                                }
                        } else {
-                               global $wgActionPaths;
                                $url = false;
-                               $matches = array();
-                               if ( !empty( $wgActionPaths ) &&
-                                       preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches ) )
-                               {
-                                       $action = urldecode( $matches[2] );
-                                       if ( isset( $wgActionPaths[$action] ) ) {
-                                               $query = $matches[1];
-                                               if ( isset( $matches[4] ) ) {
-                                                       $query .= $matches[4];
-                                               }
-                                               $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
-                                               if ( $query != '' ) {
-                                                       $url = wfAppendQuery( $url, $query );
-                                               }
-                                       }
+
+                               global $wgActionPaths;
+                               if( !empty( $wgActionPaths ) ) {
+                                       $url = Title::resolveActionPath( $dbkey, $query );
                                }
+
                                if ( $url === false ) {
                                        if ( $query == '-' ) {
                                                $query = '';
                                        }
-                                       $url = "{$wgScript}?title={$dbkey}&{$query}";
+                                       #$url = "{$wgScript}?title={$dbkey}&{$query}";
+                                       # forge a nice URL (ex: /wiki/Special:Foo?q=1&r=2 )
+                                       $baseurl = str_replace( '$1', $dbkey, $wgArticlePath );
+                                       $url = wfAppendQuery( $baseurl, $query );
                                }
                        }
 
-                       // FIXME: this causes breakage in various places when we
+                       // @todo FIXME: This causes breakage in various places when we
                        // actually expected a local URL and end up with dupe prefixes.
                        if ( $wgRequest->getVal( 'action' ) == 'render' ) {
                                $url = $wgServer . $url;
@@ -912,6 +905,38 @@ class Title {
                return $url;
        }
 
+       /**
+        * Helper for getLocalUrl() to handles $wgActionPaths
+        *
+        * @param $dbkey string Title in database key format
+        * @param $query string request parameters in CGI format (p=1&q=2&..)
+        * @return Url resolved or boolean false
+        */
+       private static function resolveActionPath( $dbkey, $query ) {
+               $url = '';
+
+               # query parameters are easier to handle using an array:
+               $queryArray = wfCGIToArray( $query );
+
+               global $wgActionPaths;
+               if( !array_key_exists( 'action', $queryArray ) ) {
+                       // Makes the default action 'view' and points to $wgArticlePath
+                       // @todo FIXME: This should be handled in Setup or Wiki!
+                       global $wgArticlePath;
+                       $url = str_replace( '$1', $dbkey, $wgArticlePath );
+               } elseif( isset( $wgActionPaths[$queryArray['action']] ) ) {
+                       $url = str_replace( '$1', $dbkey, $wgActionPaths[$queryArray['action']] );
+               } else {
+                       # No path found
+                       return false;
+               }
+
+               # No need to append the action since we have embed it in the path
+               unset( $queryArray['action'] );
+               $url = wfAppendQuery( $url, wfArrayToCGI( $queryArray ) );
+               return $url;
+       }
+
        /**
         * Get a URL that's the simplest URL that will be valid to link, locally,
         * to the current Title.  It includes the fragment, but does not include
@@ -1165,7 +1190,7 @@ class Title {
        /**
         * Can $user perform $action on this page?
         *
-        * FIXME: This *does not* check throttles (User::pingLimiter()).
+        * @todo FIXME: This *does not* check throttles (User::pingLimiter()).
         *
         * @param $action String action that permission needs to be checked for
         * @param $user User to check
@@ -1745,7 +1770,7 @@ class Title {
                                # 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
@@ -3089,7 +3114,7 @@ class Title {
                // Do the actual move
                $err = $this->moveToInternal( $nt, $reason, $createRedirect );
                if ( is_array( $err ) ) {
-                       # FIXME: What about the File we have already moved?
+                       # @todo FIXME: What about the File we have already moved?
                        $dbw->rollback();
                        return $err;
                }
@@ -3140,7 +3165,8 @@ class Title {
                        if ( $reason ) {
                                $comment .= wfMsgForContent( 'colon-separator' ) . $reason;
                        }
-                       $log->addEntry( 'move_prot', $nt, $comment, array( $this->getPrefixedText() ) ); // FIXME: $params?
+                       // @todo FIXME: $params?
+                       $log->addEntry( 'move_prot', $nt, $comment, array( $this->getPrefixedText() ) );
                }
 
                # Update watchlists
@@ -3272,9 +3298,6 @@ class Title {
                }
                $nullRevId = $nullRevision->insertOn( $dbw );
 
-               $article = new Article( $this );
-               wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest, $wgUser ) );
-
                # Change the name of the target page:
                $dbw->update( 'page',
                        /* SET */ array(
@@ -3288,6 +3311,9 @@ class Title {
                );
                $nt->resetArticleID( $oldid );
 
+               $article = new Article( $nt );
+               wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest, $wgUser ) );
+
                # Recreate the redirect, this time in the other direction.
                if ( $createRedirect || !$wgUser->isAllowed( 'suppressredirect' ) ) {
                        $mwRedir = MagicWord::get( 'redirect' );