[wp-meta] [Making WordPress.org] #5942: DevHub: Support viewing source on GitHub mirror

Making WordPress.org noreply at wordpress.org
Thu Nov 4 01:27:10 UTC 2021


#5942: DevHub: Support viewing source on GitHub mirror
---------------------------+---------------------
 Reporter:  netweb         |       Owner:  (none)
     Type:  enhancement    |      Status:  new
 Priority:  normal         |   Milestone:
Component:  Developer Hub  |  Resolution:
 Keywords:  needs-patch    |
---------------------------+---------------------
Changes (by netweb):

 * keywords:   => needs-patch
 * type:  defect => enhancement


Old description:

> Currently when looking up references in devhub links to the source only
> link to Trac source, it would be great to add support to also link to the
> GitHub mirror.
>

> For example, looking at
> https://developer.wordpress.org/reference/functions/add_theme_support/#source,
> there is a link to the Trac source at:
>
> - https://core.trac.wordpress.org/browser/tags/5.8/src/wp-
> includes/theme.php#L2519
>
> meta-5942-1.png placeholder
>
> And it would be great to also link to the GitHub mirror source at:
> - https://github.com/WordPress/wordpress-develop/blob/5.8/src/wp-
> includes/theme.php#L2519
> meta-5942-2.png placeholder
>
> ----
>
> A quick look at the code, here's an initial quick patch duplicating the
> existing `get_source_file_link()` function:
>
> {{{
> #!diff
> diff --git wordpress.org/public_html/wp-content/themes/pub/wporg-
> developer/inc/template-tags.php wordpress.org/public_html/wp-
> content/themes/pub/wporg-developer/inc/template-tags.php
> index 58cfadba4..78daa8e92 100644
> --- wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc
> /template-tags.php
> +++ wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc
> /template-tags.php
> @@ -1180,6 +1180,33 @@ namespace DevHub {
>                 return esc_url( $url );
>         }
>
> +       /**
> +        * Retrieve the URL to the GitHub source file and line.
> +        *
> +        * @param null $post_id     Post ID.
> +        * @param bool $line_number Whether to append the line number to
> the URL.
> +        *                          Default true.
> +        * @return string Source file URL with or without line number.
> +        */
> +       function get_github_source_file_link( $post_id = null,
> $line_number = true ) {
> +
> +               $post_id = empty( $post_id ) ? get_the_ID() : $post_id;
> +               $url     = '';
> +
> +               // Source file.
> +               $source_file = get_source_file( $post_id );
> +               if ( ! empty( $source_file ) ) {
> +                       $url = 'https://github.com/WordPress/wordpress-
> develop/blob/' . get_current_version() . '/src/' . $source_file;
> +                       // Line number.
> +                       if ( $line_number = get_post_meta( get_the_ID(),
> '_wp-parser_line_num', true ) ) {
> +                               $url .= "#L{$line_number}";
> +                       }
> +               }
> +
> +               return esc_url( $url );
> +       }
> +
> +
>         /**
>          * Compare two objects by name for sorting.
>          *
> diff --git wordpress.org/public_html/wp-content/themes/pub/wporg-
> developer/reference/template-source.php wordpress.org/public_html/wp-
> content/themes/pub/wporg-developer/reference/template-source.php
> index 7f83fb36e..4c1cab14d 100644
> --- wordpress.org/public_html/wp-content/themes/pub/wporg-
> developer/reference/template-source.php
> +++ wordpress.org/public_html/wp-content/themes/pub/wporg-
> developer/reference/template-source.php
> @@ -30,6 +30,7 @@ if ( ! empty( $source_file ) ) :
>                                         <a href="#" class="less-complete-
> source"><?php _e( 'Collapse full source code', 'wporg' ); ?></a>
>                                 </span>
>                                 <span><a href="<?php echo
> get_source_file_link(); ?>"><?php _e( 'View on Trac', 'wporg' );
> ?></a></span>
> +                               <span><a href="<?php echo
> get_github_source_file_link(); ?>"><?php _e( 'View on GitHub', 'wporg' );
> ?></a></span>
>                         </p>
>                 <?php else : ?>
>                         <p>
> }}}

New description:

 Currently when looking up references in devhub links to the source only
 link to Trac source, it would be great to add support to also link to the
 GitHub mirror.


 For example, looking at
 https://developer.wordpress.org/reference/functions/add_theme_support/#source,
 there is a link to the Trac source at:

 - https://core.trac.wordpress.org/browser/tags/5.8/src/wp-
 includes/theme.php#L2519

 [[Image(https://meta.trac.wordpress.org/raw-
 attachment/ticket/5942/meta-5942-1.png)]]

 And it would be great to also link to the GitHub mirror source at:
 - https://github.com/WordPress/wordpress-develop/blob/5.8/src/wp-
 includes/theme.php#L2519

 [[Image(https://meta.trac.wordpress.org/raw-
 attachment/ticket/5942/meta-5942-2.png)]]

 ----

 A quick look at the code, here's an initial quick patch duplicating the
 existing `get_source_file_link()` function:

 {{{
 #!diff
 diff --git wordpress.org/public_html/wp-content/themes/pub/wporg-
 developer/inc/template-tags.php wordpress.org/public_html/wp-
 content/themes/pub/wporg-developer/inc/template-tags.php
 index 58cfadba4..78daa8e92 100644
 --- wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc
 /template-tags.php
 +++ wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc
 /template-tags.php
 @@ -1180,6 +1180,33 @@ namespace DevHub {
                 return esc_url( $url );
         }

 +       /**
 +        * Retrieve the URL to the GitHub source file and line.
 +        *
 +        * @param null $post_id     Post ID.
 +        * @param bool $line_number Whether to append the line number to
 the URL.
 +        *                          Default true.
 +        * @return string Source file URL with or without line number.
 +        */
 +       function get_github_source_file_link( $post_id = null,
 $line_number = true ) {
 +
 +               $post_id = empty( $post_id ) ? get_the_ID() : $post_id;
 +               $url     = '';
 +
 +               // Source file.
 +               $source_file = get_source_file( $post_id );
 +               if ( ! empty( $source_file ) ) {
 +                       $url = 'https://github.com/WordPress/wordpress-
 develop/blob/' . get_current_version() . '/src/' . $source_file;
 +                       // Line number.
 +                       if ( $line_number = get_post_meta( get_the_ID(),
 '_wp-parser_line_num', true ) ) {
 +                               $url .= "#L{$line_number}";
 +                       }
 +               }
 +
 +               return esc_url( $url );
 +       }
 +
 +
         /**
          * Compare two objects by name for sorting.
          *
 diff --git wordpress.org/public_html/wp-content/themes/pub/wporg-
 developer/reference/template-source.php wordpress.org/public_html/wp-
 content/themes/pub/wporg-developer/reference/template-source.php
 index 7f83fb36e..4c1cab14d 100644
 --- wordpress.org/public_html/wp-content/themes/pub/wporg-
 developer/reference/template-source.php
 +++ wordpress.org/public_html/wp-content/themes/pub/wporg-
 developer/reference/template-source.php
 @@ -30,6 +30,7 @@ if ( ! empty( $source_file ) ) :
                                         <a href="#" class="less-complete-
 source"><?php _e( 'Collapse full source code', 'wporg' ); ?></a>
                                 </span>
                                 <span><a href="<?php echo
 get_source_file_link(); ?>"><?php _e( 'View on Trac', 'wporg' );
 ?></a></span>
 +                               <span><a href="<?php echo
 get_github_source_file_link(); ?>"><?php _e( 'View on GitHub', 'wporg' );
 ?></a></span>
                         </p>
                 <?php else : ?>
                         <p>
 }}}

--

Comment:

 [[Image()]]

-- 
Ticket URL: <https://meta.trac.wordpress.org/ticket/5942#comment:1>
Making WordPress.org <https://meta.trac.wordpress.org/>
Making WordPress.org


More information about the wp-meta mailing list