Making WordPress.org

Changeset 903


Ignore:
Timestamp:
10/11/2014 05:02:27 AM (10 years ago)
Author:
nacin
Message:

Trac Notifications: Hacking in a /core/components/ page.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/trac-notifications/trac-components.php

    r747 r903  
    1212        add_action( 'wp_head', array( $this, 'wp_head' ) );
    1313        add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) );
     14        add_action( 'component_table_row', array( $this, 'component_table_row' ) );
    1415        $this->trac = $GLOBALS['wpdb'];
    1516    }
     
    6667            $query->set( 'orderby', 'title' );
    6768            $query->set( 'order', 'asc' );
    68         }
     69            $query->set( 'order_components', true );
     70            add_action( 'the_posts', array( $this, 'order_components_into_tree' ), 10, 2 );
     71        }
     72    }
     73
     74    function order_components_into_tree( $posts, $query ) {
     75        if ( ! $query->get( 'order_components' ) ) {
     76            return $posts;
     77        }
     78        // Poor man's hierarchy sort
     79        $parents = array_filter( wp_list_pluck( $posts, 'post_parent' ) );
     80        $new_ordering = array();
     81        foreach ( $posts as $post ) {
     82            if ( $post->post_parent ) {
     83                continue;
     84            }
     85            $new_ordering[] = $post;
     86            if ( in_array( $post->ID, $parents ) ) {
     87                foreach ( wp_list_filter( $posts, array( 'post_parent' => $post->ID ) ) as $child ) {
     88                    $new_ordering[] = $child;
     89                }
     90            }
     91        }
     92        return $new_ordering;
     93        return $posts;
    6994    }
    7095
     
    156181ul.ticket-list li { margin-bottom: 4px }
    157182ul.ticket-list .focus { display: inline-block; border-radius: 3px; background: #eee; padding: 2px 6px; margin-right: 4px }
    158 .history.growing:before, .history.shrinking:before { font-family: Dashicons; font-size: 30px; vertical-align: top }
     183.history.growing:before, .history.shrinking:before { font-family: Dashicons; font-size: 30px; vertical-align: top; line-height: 15px; float: right }
    159184.history.growing:before { content: "\f142"; color: red }
    160185.history.shrinking:before { content: "\f140"; color: green }
     186td.right { text-align: right; }
     187body.post-type-archive-component table td { vertical-align: middle; }
     188td.maintainers { padding-top: 4px; padding-bottom: 4px; height: 26px; }
     189td.maintainers img.avatar { margin-right: 5px; }
    161190.component-info .create-new-ticket { float: right; margin-top: 25px; }
    162191</style>
     
    250279        }
    251280
     281        $this->maintainers_note();
    252282        echo "\n" . "Many contributors help maintain one or more components. These maintainers are vital to keeping WordPress development running as smoothly as possible. They triage new tickets, look after existing ones, spearhead or mentor tasks, pitch new ideas, curate roadmaps, and provide feedback to other contributors. Longtime maintainers with a deep understanding of particular areas of core are always seeking to mentor others to impart their knowledge.\n\n";
    253283        echo "<strong>Want to help? Start following this component!</strong> <a href='/core/notifications/'>Adjust your notifications here</a>. Feel free to dig into any ticket." . "\n\n";
     
    270300    }
    271301
    272     function ticket_table( $component ) {
     302
     303    function generate_component_breakdowns() {
     304        if ( isset( $this->breakdown_component_type, $this->breakdown_component_milestone_type ) ) {
     305            return;
     306        }
     307
    273308        $type_filled = array_fill_keys( array( 'defect (bug)', 'enhancement', 'feature request', 'task (blessed)' ), 0 );
    274 
    275309        $rows = wp_cache_get( 'trac_tickets_by_component_type_milestone' );
    276310        if ( ! $rows ) {
     
    280314        }
    281315
    282         $component_type_milestone = array();
    283316        foreach ( $rows as $row ) {
    284317            if ( empty( $component_type[ $row->component ] ) ) {
     
    292325            $component_milestone_type[ $row->component ][ $row->milestone ][ $row->type ] += $row->count;
    293326        }
     327
     328        $this->breakdown_component_type = $component_type;
     329        $this->breakdown_component_milestone_type = $component_milestone_type;
     330    }
     331
     332    function ticket_table( $component  ) {
     333        $this->generate_component_breakdowns();
     334        $component_type = $this->breakdown_component_type;
     335        $component_milestone_type = $this->breakdown_component_milestone_type;
    294336
    295337        if ( is_singular() ) {
     
    486528            $components = $this->trac->get_col( "SELECT name FROM component" );
    487529            foreach ( $components as $component ) {
    488                 echo '<option value="component/' . esc_attr( urlencode( $component ) ) . '">' . esc_html( $component ) . "</option>";
     530                echo '<option value="component/' . esc_attr( str_replace( ' ', '+', $component ) ) . '">' . esc_html( $component ) . "</option>";
    489531            }
    490532        }
     
    492534        return ob_get_clean();
    493535    }
     536
     537    function component_table_row( $post ) {
     538        static $once = true;
     539        if ( $once ) {
     540            $once = false;
     541            echo '<thead><tr><th>Component</th><th style="width: 50px">Tickets</th><th style="width: 50px">7 Days</th><th>Maintainers</th></tr></thead>';
     542        }
     543
     544        $component = $post->post_title;
     545        $this->generate_component_breakdowns();
     546        $history = $this->get_component_history( $component );
     547
     548        $arrow = '';
     549        if ( $history['change'] ) {
     550            $direction = $history['change'] > 0 ? 'growing' : 'shrinking';
     551            $arrow = '<span class="history ' . $direction . '"></span>';
     552        }
     553
     554        echo '<tr>';
     555        if ( $post->post_parent ) {
     556            echo '<td>&mdash; <a href="' . get_permalink() . '">' . $post->post_title . '</a></td>';
     557        } else {
     558            echo '<td><a href="' . get_permalink() . '"><strong>' . $post->post_title . '</strong></a></td>';
     559        }
     560
     561        $open_tickets = array_sum( $this->breakdown_component_type[ $component ] );
     562        echo '<td class="right"><a href="https://core.trac.wordpress.org/component/' . esc_attr( str_replace( ' ', '+', $component ) ) . '">' . $open_tickets . '</a></td>';
     563        if ( $history['change'] ) {
     564            echo '<td class="right">' . $arrow . ' ' . sprintf( "%+d", $history['change'] ) . '</td>';
     565        } else {
     566            echo '<td></td>';
     567        }
     568
     569        $maintainers = get_post_meta( $post->ID, '_active_maintainers', true );
     570        $maintainers = array_filter( array_map( 'trim', explode( ',', $maintainers ) ) );
     571        echo '<td class="no-grav maintainers">';
     572        foreach ( $maintainers as $maintainer ) {
     573            echo '<a href="//profiles.wordpress.org/' . esc_attr( $maintainer ) . '" title="' . esc_attr( $maintainer ) . '">' . get_avatar( get_user_by( 'login', $maintainer )->user_email, 24 ) . "</a>";
     574        }
     575        echo '</td>';
     576        echo '</tr>';
     577    }
    494578}
    495579new Make_Core_Trac_Components;
Note: See TracChangeset for help on using the changeset viewer.