From 982fbb2dd9b9c34c873c032dc3d56f7161416519 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Thu, 21 Feb 2008 09:32:59 +0000 Subject: [PATCH] * 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. * Fixed minor bugs and refactored code in the vicinity of EditPage::edit(). --- RELEASE-NOTES | 10 +++++++- includes/EditPage.php | 38 +++++++++++++++++++------------ includes/GlobalFunctions.php | 23 +++++++++++++++++++ includes/Linker.php | 15 ++++++++---- includes/OutputPage.php | 2 +- includes/Wiki.php | 1 + languages/messages/MessagesEn.php | 1 + 7 files changed, 69 insertions(+), 21 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index f3b0e0d8a1..662e2ede2a 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/includes/EditPage.php b/includes/EditPage.php index a15f43b0d1..652aa0e1e2 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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? * diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index ebf086422c..8556505d2e 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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. diff --git a/includes/Linker.php b/includes/Linker.php index 4b092cf9a0..11dee27a88 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -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 = "{$prefix}{$text}{$inside}{$trail}"; diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 6a8c5efd10..3f46be8212 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1065,7 +1065,7 @@ class OutputPage { } $text .= ''; } else { - $text .= '
' . call_user_func_array( 'wfMsgNoTrans', $errors[0]) . '
'; + $text .= '
' . call_user_func_array( 'wfMsgNoTrans', reset( $errors ) ) . '
'; } return $text; diff --git a/includes/Wiki.php b/includes/Wiki.php index e0a5744515..d2c4433f3a 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -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' ); diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 6aaff1d9d6..43d0d9c1c4 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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', -- 2.20.1