Fix highlighting of results when the search result does not return termMatches
[lhc/web/wiklou.git] / includes / Title.php
index ab55257..526bc92 100644 (file)
@@ -74,6 +74,9 @@ class Title {
        /** @var string Interwiki prefix */
        public $mInterwiki = '';
 
+       /** @var bool Was this Title created from a string with a local interwiki prefix? */
+       private $mLocalInterwiki = false;
+
        /** @var string Title fragment (i.e. the bit after the #) */
        public $mFragment = '';
 
@@ -823,6 +826,15 @@ class Title {
                return $this->mInterwiki;
        }
 
+       /**
+        * Was this a local interwiki link?
+        *
+        * @return bool
+        */
+       public function wasLocalInterwiki() {
+               return $this->mLocalInterwiki;
+       }
+
        /**
         * Determine whether the object refers to a page within
         * this project and is transcludable.
@@ -1643,6 +1655,8 @@ class Title {
         * $wgServer is prepended to make an absolute URL.
         *
         * @see self::getFullURL to always get an absolute URL.
+        * @see self::getLinkURL to always get a URL that's the simplest URL that will be
+        *  valid to link, locally, to the current Title.
         * @see self::newFromText to produce a Title object.
         *
         * @param string|array $query An optional query string,
@@ -2061,7 +2075,7 @@ class Title {
                        $ns = $this->mNamespace == NS_MAIN ?
                                wfMessage( 'nstab-main' )->text() : $this->getNsText();
                        $errors[] = $this->mNamespace == NS_MEDIAWIKI ?
-                               array( 'protectedinterface' ) : array( 'namespaceprotected', $ns );
+                               array( 'protectedinterface', $action ) : array( 'namespaceprotected', $ns, $action );
                }
 
                return $errors;
@@ -2085,15 +2099,15 @@ class Title {
                if ( $action != 'patrol' && !$user->isAllowed( 'editusercssjs' ) ) {
                        if ( preg_match( '/^' . preg_quote( $user->getName(), '/' ) . '\//', $this->mTextform ) ) {
                                if ( $this->isCssSubpage() && !$user->isAllowedAny( 'editmyusercss', 'editusercss' ) ) {
-                                       $errors[] = array( 'mycustomcssprotected' );
+                                       $errors[] = array( 'mycustomcssprotected', $action );
                                } elseif ( $this->isJsSubpage() && !$user->isAllowedAny( 'editmyuserjs', 'edituserjs' ) ) {
-                                       $errors[] = array( 'mycustomjsprotected' );
+                                       $errors[] = array( 'mycustomjsprotected', $action );
                                }
                        } else {
                                if ( $this->isCssSubpage() && !$user->isAllowed( 'editusercss' ) ) {
-                                       $errors[] = array( 'customcssprotected' );
+                                       $errors[] = array( 'customcssprotected', $action );
                                } elseif ( $this->isJsSubpage() && !$user->isAllowed( 'edituserjs' ) ) {
-                                       $errors[] = array( 'customjsprotected' );
+                                       $errors[] = array( 'customjsprotected', $action );
                                }
                        }
                }
@@ -2128,9 +2142,9 @@ class Title {
                                continue;
                        }
                        if ( !$user->isAllowed( $right ) ) {
-                               $errors[] = array( 'protectedpagetext', $right );
+                               $errors[] = array( 'protectedpagetext', $right, $action );
                        } elseif ( $this->mCascadeRestriction && !$user->isAllowed( 'protect' ) ) {
-                               $errors[] = array( 'protectedpagetext', 'protect' );
+                               $errors[] = array( 'protectedpagetext', 'protect', $action );
                        }
                }
 
@@ -2177,7 +2191,7 @@ class Title {
                                                foreach ( $cascadingSources as $page ) {
                                                        $pages .= '* [[:' . $page->getPrefixedText() . "]]\n";
                                                }
-                                               $errors[] = array( 'cascadeprotected', count( $cascadingSources ), $pages );
+                                               $errors[] = array( 'cascadeprotected', count( $cascadingSources ), $pages, $action );
                                        }
                                }
                        }
@@ -2244,6 +2258,12 @@ class Title {
                                $errors[] = array( 'immobile-target-page' );
                        }
                } elseif ( $action == 'delete' ) {
+                       if ( count( $this->getUserPermissionsErrorsInternal( 'edit',
+                               $user, $doExpensiveQueries, true ) )
+                       ) {
+                               // If they can't edit, they shouldn't delete.
+                               $errors[] = array( 'delete-cantedit' );
+                       }
                        if ( $doExpensiveQueries && $wgDeleteRevisionsLimit
                                && !$this->userCan( 'bigdelete', $user ) && $this->isBigDeletion()
                        ) {
@@ -2417,6 +2437,19 @@ class Title {
                                'checkPermissionHooks',
                                'checkReadPermissions',
                        );
+               # Don't call checkSpecialsAndNSPermissions or checkCSSandJSPermissions
+               # here as it will lead to duplicate error messages. This is okay to do
+               # since anywhere that checks for create will also check for edit, and
+               # those checks are called for edit.
+               } elseif ( $action == 'create' ) {
+                       $checks = array(
+                               'checkQuickPermissions',
+                               'checkPermissionHooks',
+                               'checkPageRestrictions',
+                               'checkCascadingSourcesRestrictions',
+                               'checkActionPermissions',
+                               'checkUserBlock'
+                       );
                } else {
                        $checks = array(
                                'checkQuickPermissions',
@@ -3289,6 +3322,7 @@ class Title {
                # Fill fields
                $this->setFragment( '#' . $parts['fragment'] );
                $this->mInterwiki = $parts['interwiki'];
+               $this->mLocalInterwiki = $parts['local_interwiki'];
                $this->mNamespace = $parts['namespace'];
                $this->mUserCaseDBKey = $parts['user_case_dbkey'];