<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[19051] trunk/wp-admin/includes/screen.php: screen.php tidying.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/19051">19051</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2011-10-24 06:40:15 +0000 (Mon, 24 Oct 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>screen.php tidying. Doc fixes and improvements. Improve logic in ::show_screen_options(). Remove regex in ::set_parentage(). Better variable names. Streamline get_screen_icon(). Whitespace. see <a href="http://core.trac.wordpress.org/ticket/18785">#18785</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesscreenphp">trunk/wp-admin/includes/screen.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesscreenphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/screen.php (19050 => 19051)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/screen.php        2011-10-24 06:10:36 UTC (rev 19050)
+++ trunk/wp-admin/includes/screen.php        2011-10-24 06:40:15 UTC (rev 19051)
</span><span class="lines">@@ -11,7 +11,7 @@
</span><span class="cx">  *
</span><span class="cx">  * @since 2.7.0
</span><span class="cx">  *
</span><del>- * @param string|object $screen The screen you want the headers for
</del><ins>+ * @param string|WP_Screen $screen The screen you want the headers for
</ins><span class="cx">  * @return array Containing the headers in the format id =&gt; UI String
</span><span class="cx">  */
</span><span class="cx"> function get_column_headers( $screen ) {
</span><span class="lines">@@ -31,7 +31,7 @@
</span><span class="cx">  *
</span><span class="cx">  * @since 2.7.0
</span><span class="cx">  *
</span><del>- * @param string|object $screen The screen you want the hidden columns for
</del><ins>+ * @param string|WP_Screen $screen The screen you want the hidden columns for
</ins><span class="cx">  * @return array
</span><span class="cx">  */
</span><span class="cx"> function get_hidden_columns( $screen ) {
</span><span class="lines">@@ -42,17 +42,17 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * {@internal Missing Short Description}}
</del><ins>+ * Prints the meta box preferences for screen meta.
</ins><span class="cx">  *
</span><span class="cx">  * @since 2.7.0
</span><span class="cx">  *
</span><del>- * @param unknown_type $screen
</del><ins>+ * @param string|WP_Screen $screen
</ins><span class="cx">  */
</span><span class="cx"> function meta_box_prefs( $screen ) {
</span><span class="cx">         global $wp_meta_boxes;
</span><span class="cx"> 
</span><del>-        if ( is_string($screen) )
-                $screen = convert_to_screen($screen);
</del><ins>+        if ( is_string( $screen ) )
+                $screen = convert_to_screen( $screen );
</ins><span class="cx"> 
</span><span class="cx">         if ( empty($wp_meta_boxes[$screen-&gt;id]) )
</span><span class="cx">                 return;
</span><span class="lines">@@ -81,7 +81,7 @@
</span><span class="cx">  *
</span><span class="cx">  * @since 2.7.0
</span><span class="cx">  *
</span><del>- * @param string|object $screen Screen identifier
</del><ins>+ * @param string|WP_Screen $screen Screen identifier
</ins><span class="cx">  * @return array Hidden Meta Boxes
</span><span class="cx">  */
</span><span class="cx"> function get_hidden_meta_boxes( $screen ) {
</span><span class="lines">@@ -112,11 +112,11 @@
</span><span class="cx">  *
</span><span class="cx">  * @since 3.0.0
</span><span class="cx">  *
</span><del>- * @param string $screen The name of the screen
</del><ins>+ * @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen.
</ins><span class="cx">  * @return object An object containing the safe screen name and id
</span><span class="cx">  */
</span><del>-function convert_to_screen( $screen ) {
-        $screen = str_replace( array('.php', '-new', '-add', '-network', '-user' ), '', $screen);
</del><ins>+function convert_to_screen( $hook_suffix ) {
+        $screen = str_replace( array('.php', '-new', '-add', '-network', '-user' ), '', $hook_suffix);
</ins><span class="cx"> 
</span><span class="cx">         if ( is_network_admin() )
</span><span class="cx">                 $screen .= '-network';
</span><span class="lines">@@ -144,7 +144,7 @@
</span><span class="cx">         if ( is_string( $screen ) )
</span><span class="cx">                 $screen = convert_to_screen( $screen );
</span><span class="cx"> 
</span><del>-        WP_Screen::add_old_compat_help( $screen-&gt;id, $help );
</del><ins>+        WP_Screen::add_old_compat_help( $screen, $help );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -165,52 +165,63 @@
</span><span class="cx">         return $current_screen-&gt;add_option( $option, $args );
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/**
+ * Displays a screen icon.
+ *
+ * @uses get_screen_icon()
+ * @since 2.7.0
+ *
+ * @param string|WP_Screen $screen Optional. Accepts a screen object (and defaults to the current screen object)
+ *         which it uses to determine an icon HTML ID. Or, if a string is provided, it is used to form the icon HTML ID.
+ */
</ins><span class="cx"> function screen_icon( $screen = '' ) {
</span><span class="cx">         echo get_screen_icon( $screen );
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/**
+ * Gets a screen icon.
+ *
+ * @since 3.2.0
+ *
+ * @param string|WP_Screen $screen Optional. Accepts a screen object (and defaults to the current screen object)
+ *         which it uses to determine an icon HTML ID. Or, if a string is provided, it is used to form the icon HTML ID.
+ * @return string HTML for the screen icon.
+ */
</ins><span class="cx"> function get_screen_icon( $screen = '' ) {
</span><del>-        global $current_screen, $typenow;
</del><ins>+        if ( empty( $screen ) )
+                $screen = get_current_screen();
+        elseif ( is_string( $screen ) )
+                $icon_id = $screen;
</ins><span class="cx"> 
</span><del>-        if ( empty($screen) )
-                $screen = $current_screen;
-        elseif ( is_string($screen) )
-                $name = $screen;
-
</del><span class="cx">         $class = 'icon32';
</span><span class="cx"> 
</span><del>-        if ( empty($name) ) {
-                if ( !empty($screen-&gt;parent_base) )
-                        $name = $screen-&gt;parent_base;
</del><ins>+        if ( empty( $icon_id ) ) {
+                if ( ! empty( $screen-&gt;parent_base ) )
+                        $icon_id = $screen-&gt;parent_base;
</ins><span class="cx">                 else
</span><del>-                        $name = $screen-&gt;base;
</del><ins>+                        $icon_id = $screen-&gt;base;
</ins><span class="cx"> 
</span><del>-                if ( 'edit' == $name &amp;&amp; isset($screen-&gt;post_type) &amp;&amp; 'page' == $screen-&gt;post_type )
-                        $name = 'edit-pages';
</del><ins>+                if ( ! empty( $screen-&gt;post_type ) &amp;&amp; 'page' == $screen-&gt;post_type )
+                        $icon_id = 'edit-pages';
</ins><span class="cx"> 
</span><del>-                $post_type = '';
-                if ( isset( $screen-&gt;post_type ) )
-                        $post_type = $screen-&gt;post_type;
-                elseif ( $current_screen == $screen )
-                        $post_type = $typenow;
-                if ( $post_type )
-                        $class .= ' ' . sanitize_html_class( 'icon32-posts-' . $post_type );
</del><ins>+                if ( ! empty( $screen-&gt;post_type ) )
+                        $class .= ' ' . sanitize_html_class( 'icon32-posts-' . $screen-&gt;post_type );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        return '&lt;div id=&quot;icon-' . esc_attr( $name ) . '&quot; class=&quot;' . $class . '&quot;&gt;&lt;br /&gt;&lt;/div&gt;';
</del><ins>+        return '&lt;div id=&quot;icon-' . esc_attr( $icon_id ) . '&quot; class=&quot;' . $class . '&quot;&gt;&lt;br /&gt;&lt;/div&gt;';
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- *  Get the current screen object
</del><ins>+ * Get the current screen object
</ins><span class="cx">  *
</span><del>- *  @since 3.1.0
</del><ins>+ * @since 3.1.0
</ins><span class="cx">  *
</span><span class="cx">  * @return object Current screen object
</span><span class="cx">  */
</span><span class="cx"> function get_current_screen() {
</span><span class="cx">         global $current_screen;
</span><span class="cx"> 
</span><del>-        if ( !isset($current_screen) )
</del><ins>+        if ( ! isset( $current_screen ) )
</ins><span class="cx">                 return null;
</span><span class="cx"> 
</span><span class="cx">         return $current_screen;
</span><span class="lines">@@ -220,28 +231,27 @@
</span><span class="cx">  * Set the current screen object
</span><span class="cx">  *
</span><span class="cx">  * @since 3.0.0
</span><del>- *
</del><span class="cx">  * @uses $current_screen
</span><span class="cx">  *
</span><del>- * @param string $id Screen id, optional.
</del><ins>+ * @param string $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
</ins><span class="cx">  */
</span><del>-function set_current_screen( $id =  '' ) {
</del><ins>+function set_current_screen( $hook_name =  '' ) {
</ins><span class="cx">         global $current_screen;
</span><span class="cx"> 
</span><del>-        $current_screen = new WP_Screen( $id );
</del><ins>+        $current_screen = new WP_Screen( $hook_name );
</ins><span class="cx"> 
</span><span class="cx">         $current_screen = apply_filters('current_screen', $current_screen);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * A class representing the current admin screen.
</del><ins>+ * A class representing the admin screen.
</ins><span class="cx">  *
</span><span class="cx">  * @since 3.3.0
</span><span class="cx">  * @access public
</span><span class="cx">  */
</span><span class="cx"> final class WP_Screen {
</span><span class="cx">         /**
</span><del>-         * Any action associated with the screen.  'add' for *-add.php and *-new.php screens.  Empty otherwise.
</del><ins>+         * Any action associated with the screen. 'add' for *-add.php and *-new.php screens.  Empty otherwise.
</ins><span class="cx">          *
</span><span class="cx">          * @since 3.3.0
</span><span class="cx">          * @var string
</span><span class="lines">@@ -453,8 +463,18 @@
</span><span class="cx">                         self::$_options[ $this-&gt;id ] = array();
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        /**
+         * Sets the old string-based contextual help for the screen.
+         *
+         * For backwards compatibility.
+         *
+         * @since 3.3.0
+         *
+         * @param WP_Screen $screen A screen object.
+         * @param string $help Help text.
+         */
</ins><span class="cx">         static function add_old_compat_help( $screen, $help ) {
</span><del>-                self::$_old_compat_help[ $screen ] = $help;        
</del><ins>+                self::$_old_compat_help[ $screen-&gt;id ] = $help;        
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><span class="lines">@@ -467,8 +487,8 @@
</span><span class="cx">          */
</span><span class="cx">         function set_parentage( $parent_file ) {
</span><span class="cx">                 $this-&gt;parent_file = $parent_file;
</span><del>-                $this-&gt;parent_base = preg_replace('/\?.*$/', '', $parent_file);
-                $this-&gt;parent_base = str_replace('.php', '', $this-&gt;parent_base);
</del><ins>+                list( $this-&gt;parent_base ) = explode( '?', $parent_file );
+                $this-&gt;parent_base = str_replace( '.php', '', $this-&gt;parent_base );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><span class="lines">@@ -489,7 +509,7 @@
</span><span class="cx">          *
</span><span class="cx">          * @since 3.3.0
</span><span class="cx">          *
</span><del>-         * @param string 
</del><ins>+         * @param string
</ins><span class="cx">          */
</span><span class="cx">         public function get_option( $option, $key = false ) {
</span><span class="cx">                 if ( ! isset( self::$_options[ $this-&gt;id ][ $option ] ) )
</span><span class="lines">@@ -640,35 +660,26 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         public function show_screen_options() {
</span><del>-                global $wp_meta_boxes, $wp_list_table;
</del><ins>+                global $wp_meta_boxes;
</ins><span class="cx"> 
</span><span class="cx">                 if ( is_bool( $this-&gt;_show_screen_options ) )
</span><span class="cx">                         return $this-&gt;_show_screen_options;
</span><span class="cx"> 
</span><span class="cx">                 $columns = get_column_headers( $this );
</span><span class="cx"> 
</span><del>-                $show_screen = false;
-                if ( ! empty( $wp_meta_boxes[ $this-&gt;id ] ) || ! empty( $columns ) )
-                        $show_screen = true;
</del><ins>+                $show_screen = ! empty( $wp_meta_boxes[ $this-&gt;id ] ) || $columns || $this-&gt;get_option( 'per_page' );
</ins><span class="cx"> 
</span><del>-                // Check if there are per-page options.
-                $show_screen = $show_screen || $this-&gt;get_option('per_page');
-
</del><span class="cx">                 $this-&gt;_screen_settings = apply_filters( 'screen_settings', '', $this );
</span><span class="cx"> 
</span><span class="cx">                 switch ( $this-&gt;id ) {
</span><span class="cx">                         case 'widgets':
</span><span class="cx">                                 $this-&gt;_screen_settings = '&lt;p&gt;&lt;a id=&quot;access-on&quot; href=&quot;widgets.php?widgets-access=on&quot;&gt;' . __('Enable accessibility mode') . '&lt;/a&gt;&lt;a id=&quot;access-off&quot; href=&quot;widgets.php?widgets-access=off&quot;&gt;' . __('Disable accessibility mode') . &quot;&lt;/a&gt;&lt;/p&gt;\n&quot;;
</span><del>-                                $show_screen = true;
</del><span class="cx">                                 break;
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                if ( ! empty( $this-&gt;_screen_settings ) )
</del><ins>+                if ( $this-&gt;_screen_settings || self::$_options[ $this-&gt;id ] )
</ins><span class="cx">                         $show_screen = true;
</span><span class="cx"> 
</span><del>-                if ( ! empty( self::$_options[ $this-&gt;id ] ) )
-                        $show_screen = true;
-
</del><span class="cx">                 $this-&gt;_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
</span><span class="cx">                 return $this-&gt;_show_screen_options;
</span><span class="cx">         }
</span></span></pre>
</div>
</div>

</body>
</html>