Index: wp-includes/link-template.php
===================================================================
--- wp-includes/link-template.php	(wersja 21271)
+++ wp-includes/link-template.php	(kopia robocza)
@@ -1375,22 +1375,30 @@
  *
  * @param int $pagenum Optional. Page ID.
  * @param bool $escape Optional. Whether to escape the URL for display, with esc_url(). Defaults to true.
-* 	Otherwise, prepares the URL with esc_url_raw().
+ * 	Otherwise, prepares the URL with esc_url_raw().
+ * @param string $url Optional. URL to modify. Defaults to null - in this case function will use $_SERVER['REQUEST_URI']
  * @return string
  */
-function get_pagenum_link($pagenum = 1, $escape = true ) {
+function get_pagenum_link( $pagenum = 1, $escape = true, $url = null ) {
 	global $wp_rewrite;
 
 	$pagenum = (int) $pagenum;
 
-	$request = remove_query_arg( 'paged' );
+	if ( !empty( $url ) )
+		$request = remove_query_arg( 'paged', $url );
+	else
+		$request = remove_query_arg( 'paged' );
 
-	$home_root = parse_url(home_url());
-	$home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
+	if ( !empty( $url ) )
+		$home_root = home_url();
+	else {
+		$home_root = parse_url( home_url() );
+		$home_root = ( isset( $home_root['path'] ) ) ? $home_root['path'] : '';
+	}
 	$home_root = preg_quote( $home_root, '|' );
 
-	$request = preg_replace('|^'. $home_root . '|', '', $request);
-	$request = preg_replace('|^/+|', '', $request);
+	$request = preg_replace( '|^'. $home_root . '|', '', $request );
+	$request = preg_replace( '|^/+|', '', $request );
 
 	if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
 		$base = trailingslashit( get_bloginfo( 'url' ) );
@@ -1411,9 +1419,9 @@
 			$query_string = '';
 		}
 
-		$request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request);
-		$request = preg_replace( '|^index\.php|', '', $request);
-		$request = ltrim($request, '/');
+		$request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request );
+		$request = preg_replace( '|^index\.php|', '', $request );
+		$request = ltrim( $request, '/' );
 
 		$base = trailingslashit( get_bloginfo( 'url' ) );
 
@@ -1427,7 +1435,7 @@
 		$result = $base . $request . $query_string;
 	}
 
-	$result = apply_filters('get_pagenum_link', $result);
+	$result = apply_filters( 'get_pagenum_link', $result, $url );
 
 	if ( $escape )
 		return esc_url( $result );
@@ -1640,37 +1648,84 @@
 }
 
 /**
+ * Retrieve page link for paginated post (i.e. includes the <!--nextpage-->
+ * Quicktag one or more times).
+ *
+ * @since 3.5.0
+ *
+ * @param int $pagenum Optional. Page number. Default is 1.
+ * @param int|object $post Optional. Post ID or post object. Default is null
+ * @return string
+ */
+function get_post_page_link( $pagenum = 1, $post = null ) {
+	global $wp_rewrite;
+	
+	$post = get_post( $post );
+	$pagenum = (int) $pagenum;
+	
+	$result = get_permalink( $post->ID );
+
+	if ( 1 != $pagenum ) {
+		if ( ( '' == get_option( 'permalink_structure' ) ) || in_array( $post->post_status, array( 'draft', 'pending' ) ) )
+			$result = add_query_arg( 'page', $pagenum, $result );
+		elseif ( ( 'page' == get_option('show_on_front') ) && ( get_option('page_on_front') == $post->ID ) ) {
+			if ( $wp_rewrite->using_index_permalinks() )
+				$result = trailingslashit( $result ) . trailingslashit( $wp_rewrite->index ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $pagenum, 'single_paged' );
+			else
+				$result = trailingslashit( $result ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $pagenum, 'single_paged' );
+		} else
+			$result = trailingslashit( $result ) . user_trailingslashit( $pagenum, 'single_paged' );
+	}
+
+	$result = apply_filters( 'get_post_page_link', $result, $post, $pagenum );
+
+	return $result;
+}
+
+/**
  * Retrieve comments page number link.
  *
  * @since 2.7.0
  *
- * @param int $pagenum Optional. Page number.
+ * @param int $pagenum Optional. Page number. Default is 1.
+ * @param int $max_page Optional. Maximum page number. Default is 0.
+ * @param int|object $post Optional. Post ID or post object. Default is null
+ * @param boolean $add_anchor Optional. Add anchor part to link or not. Default is true.
  * @return string
  */
-function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) {
-	global $post, $wp_rewrite;
+function get_comments_pagenum_link( $pagenum = 1, $max_page = 0, $post = null, $add_anchor = true ) {
+	global $wp_rewrite;
 
+	$post = get_post( $post );
 	$pagenum = (int) $pagenum;
 
 	$result = get_permalink( $post->ID );
 
 	if ( 'newest' == get_option('default_comments_page') ) {
 		if ( $pagenum != $max_page ) {
-			if ( $wp_rewrite->using_permalinks() )
-				$result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged');
-			else
+			if ( $wp_rewrite->using_permalinks() ) {
+				if ( $wp_rewrite->using_index_permalinks() && ( 'page' == get_option('show_on_front') ) && ( get_option('page_on_front') == $post->ID ) )
+					$result = user_trailingslashit( trailingslashit( $result ) . trailingslashit( $wp_rewrite->index ) . 'comment-page-' . $pagenum, 'commentpaged' );
+				else
+					$result = user_trailingslashit( trailingslashit( $result ) . 'comment-page-' . $pagenum, 'commentpaged' );
+			} else
 				$result = add_query_arg( 'cpage', $pagenum, $result );
 		}
 	} elseif ( $pagenum > 1 ) {
-		if ( $wp_rewrite->using_permalinks() )
-			$result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged');
-		else
+		if ( $wp_rewrite->using_permalinks() ) {
+			if ( $wp_rewrite->using_index_permalinks() && ( 'page' == get_option('show_on_front') ) && ( get_option('page_on_front') == $post->ID ) )
+				$result = user_trailingslashit( trailingslashit($result) . trailingslashit( $wp_rewrite->index ) . 'comment-page-' . $pagenum, 'commentpaged' );
+			else
+				$result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged' );
+		} else
 			$result = add_query_arg( 'cpage', $pagenum, $result );
 	}
 
-	$result .= '#comments';
+	if ( $add_anchor ) {
+		$result .= '#comments';
+	}
 
-	$result = apply_filters('get_comments_pagenum_link', $result);
+	$result = apply_filters( 'get_comments_pagenum_link', $result, $post, $pagenum, $max_page, $add_anchor );
 
 	return $result;
 }
Index: wp-includes/post-template.php
===================================================================
--- wp-includes/post-template.php	(wersja 21271)
+++ wp-includes/post-template.php	(kopia robocza)
@@ -607,12 +607,11 @@
  *      is not linked.
  *
  * @since 1.2.0
- * @access private
  *
  * @param string|array $args Optional. Overwrite the defaults.
  * @return string Formatted output in HTML.
  */
-function wp_link_pages($args = '') {
+function wp_link_pages( $args = '' ) {
 	$defaults = array(
 		'before' => '<p>' . __('Pages:'), 'after' => '</p>',
 		'link_before' => '', 'link_after' => '',
@@ -676,19 +675,7 @@
  * @return string Link.
  */
 function _wp_link_page( $i ) {
-	global $post, $wp_rewrite;
-
-	if ( 1 == $i ) {
-		$url = get_permalink();
-	} else {
-		if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
-			$url = add_query_arg( 'page', $i, get_permalink() );
-		elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID )
-			$url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged');
-		else
-			$url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged');
-	}
-
+	$url = get_post_page_link( $i );
 	return '<a href="' . esc_url( $url ) . '">';
 }
 
