* Don't show edit permissions errors on a red link click, just redirect to the articl...
authorTim Starling <tstarling@users.mediawiki.org>
Thu, 21 Feb 2008 09:32:59 +0000 (09:32 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Thu, 21 Feb 2008 09:32:59 +0000 (09:32 +0000)
* Put "not yet written" in the title attribute of red links, so that readers unfamiliar with the site might guess what the colour means.
* Fixed minor bugs and refactored code in the vicinity of EditPage::edit().

RELEASE-NOTES
includes/EditPage.php
includes/GlobalFunctions.php
includes/Linker.php
includes/OutputPage.php
includes/Wiki.php
languages/messages/MessagesEn.php

index f3b0e0d..662e2ed 100644 (file)
@@ -161,7 +161,15 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 12857) Patrol link on new pages should clear floats
 * (bug 12968) Render redirect wikilinks in a redirect class for customization
   via user/site CSS.
-* EditPageBeforeEditButtons hook added for altering the edit buttons below the edit box
+* EditPageBeforeEditButtons hook added for altering the edit buttons below the 
+  edit box.
+* __HIDDENCAT__ on a category page causes the category to be hidden on the 
+  article page.
+* Don't show edit permissions errors on a red link click, just redirect to the 
+  article. This is so that readers who don't know what a red link is aren't 
+  confused when they are told they are range-blocked.
+* Put "not yet written" in the title attribute of red links, so that readers
+  unfamiliar with the site might guess what the colour means.
 
 === Bug fixes in 1.12 ===
 
index a15f43b..652aa0e 100644 (file)
@@ -356,28 +356,21 @@ class EditPage {
                }
                
                if( wfReadOnly() ) {
-                       $wgOut->readOnlyPage( $this->getContent() );
+                       $this->readOnlyPage( $this->getContent() );
                        wfProfileOut( __METHOD__ );
                        return;
                }
 
                $permErrors = $this->mTitle->getUserPermissionsErrors('edit', $wgUser);
                if( !$this->mTitle->exists() ) {
-                       # We can't use array_diff here, because that considers ANY TWO
-                       # ARRAYS TO BE EQUAL.  Thanks, PHP.
-                       $createErrors = $this->mTitle->getUserPermissionsErrors('create', $wgUser);
-                       foreach( $createErrors as $error ) {
-                               # in_array() actually *does* work as expected.
-                               if( !in_array( $error, $permErrors ) ) {
-                                       $permErrors[] = $error;
-                               }
-                       }
+                       $permErrors = array_merge( $permErrors, 
+                               wfArrayDiff2( $this->mTitle->getUserPermissionsErrors('create', $wgUser), $permErrors ) );
                }
 
                # Ignore some permissions errors.
                $remove = array();
                foreach( $permErrors as $error ) {
-                       if ($this->preview || $this->diff &&
+                       if ( ( $this->preview || $this->diff ) &&
                                ($error[0] == 'blockedtext' || $error[0] == 'autoblockedtext'))
                        {
                                // Don't worry about blocks when previewing/diffing
@@ -393,11 +386,11 @@ class EditPage {
                                }
                        }
                }
-               $permErrors = array_diff( $permErrors, $remove );
+               $permErrors = wfArrayDiff2( $permErrors, $remove );
 
-               if ( !empty($permErrors) ) {
+               if ( $permErrors ) {
                        wfDebug( __METHOD__.": User can't edit\n" );
-                       $wgOut->readOnlyPage( $this->getContent(), true, $permErrors );
+                       $this->readOnlyPage( $this->getContent(), true, $permErrors );
                        wfProfileOut( __METHOD__ );
                        return;
                } else {
@@ -485,6 +478,23 @@ class EditPage {
                wfProfileOut( __METHOD__ );
        }
 
+       /**
+        * Show a read-only error
+        * Parameters are the same as OutputPage:readOnlyPage()
+        * Redirect to the article page if action=editredlink
+        */
+       function readOnlyPage( $source = null, $protected = false, $reasons = array() ) {
+               global $wgRequest, $wgOut;
+               if ( $wgRequest->getVal( 'action' ) === 'editredlink' ) {
+                       // The edit page was reached via a red link.
+                       // Redirect to the article page and let them click the edit tab if 
+                       // they really want a permission error.
+                       $wgOut->redirect( $this->mTitle->getFullUrl() );
+               } else {
+                       $wgOut->readOnlyPage( $source, $protected, $reasons );
+               }
+       }
+
        /**
         * Should we show a preview when the edit form is first shown?
         *
index ebf0864..8556505 100644 (file)
@@ -87,6 +87,29 @@ if ( !function_exists( 'array_diff_key' ) ) {
        }
 }
 
+/**
+ * Like array_diff( $a, $b ) except that it works with two-dimensional arrays.
+ */
+function wfArrayDiff2( $a, $b ) {
+       return array_udiff( $a, $b, 'wfArrayDiff2_cmp' );
+}
+function wfArrayDiff2_cmp( $a, $b ) {
+       if ( !is_array( $a ) ) {
+               return strcmp( $a, $b );
+       } elseif ( count( $a ) !== count( $b ) ) {
+               return count( $a ) < count( $b ) ? -1 : 1;
+       } else {
+               reset( $a );
+               reset( $b );
+               while( ( list( $keyA, $valueA ) = each( $a ) ) && ( list( $keyB, $valueB ) = each( $b ) ) ) {
+                       $cmp = strcmp( $valueA, $valueB );
+                       if ( $cmp !== 0 ) {
+                               return $cmp;
+                       }
+               }
+               return 0;
+       }
+}
 
 /**
  * Wrapper for clone(), for compatibility with PHP4-friendly extensions.
index 4b092cf..11dee27 100644 (file)
@@ -66,9 +66,13 @@ class Linker {
         * @param $text String: FIXME
         * @param $class String: CSS class of the link, default ''.
         */
-       function getInternalLinkAttributesObj( &$nt, $text, $class='' ) {
+       function getInternalLinkAttributesObj( &$nt, $text, $class = '', $title = false ) {
                $r = ($class != '') ? ' class="' . htmlspecialchars( $class ) . '"' : '';
-               $r .= ' title="' . $nt->getEscapedText() . '"';
+               if ( $title === false ) {
+                       $r .= ' title="' . $nt->getEscapedText() . '"';
+               } else {
+                       $r .= ' title="' . htmlspecialchars( $title ) . '"';
+               }
                return $r;
        }
 
@@ -340,16 +344,17 @@ class Linker {
                if( $nt->getNamespace() == NS_SPECIAL ) {
                        $q = $query;
                } else if ( '' == $query ) {
-                       $q = 'action=edit';
+                       $q = 'action=editredlink';
                } else {
-                       $q = 'action=edit&'.$query;
+                       $q = 'action=editredlink&'.$query;
                }
                $u = $nt->escapeLocalURL( $q );
 
                if ( '' == $text ) {
                        $text = htmlspecialchars( $nt->getPrefixedText() );
                }
-               $style = $this->getInternalLinkAttributesObj( $nt, $text, 'new' );
+               $title = wfMsg( 'red-link-title', $nt->getText() );
+               $style = $this->getInternalLinkAttributesObj( $nt, $text, 'new', $title );
 
                list( $inside, $trail ) = Linker::splitTrail( $trail );
                $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
index 6a8c5ef..3f46be8 100644 (file)
@@ -1065,7 +1065,7 @@ class OutputPage {
                        }
                        $text .= '</ul>';
                } else {
-                       $text .= '<div class="permissions-errors">' . call_user_func_array( 'wfMsgNoTrans', $errors[0]) . '</div>';
+                       $text .= '<div class="permissions-errors">' . call_user_func_array( 'wfMsgNoTrans', reset( $errors ) ) . '</div>';
                }
 
                return $text;
index e0a5744..d2c4433 100644 (file)
@@ -433,6 +433,7 @@ class MediaWiki {
                                }
                                /* Continue... */
                        case 'edit':
+                       case 'editredlink':
                                if( wfRunHooks( 'CustomEditor', array( $article, $user ) ) ) {
                                        $internal = $request->getVal( 'internaledit' );
                                        $external = $request->getVal( 'externaledit' );
index 6aaff1d..43d0d9c 100644 (file)
@@ -720,6 +720,7 @@ XHTML id names.
 'sitenotice'                   => '-', # the equivalent to wgSiteNotice; don't translate or duplicate this message to other languages
 'anonnotice'                   => '-', # don't translate or duplicate this message to other languages
 'newsectionheaderdefaultlevel' => '== $1 ==', # don't translate or duplicate this message to other languages
+'red-link-title'               => '$1 (not yet written)',
 
 # Short words for each namespace, by default used in the namespace tab in monobook
 'nstab-main'      => 'Page',