[JobQueue] Made the maximum number of job attempts configurable.
[lhc/web/wiklou.git] / includes / Title.php
index 9de94d8..c1782e5 100644 (file)
@@ -149,7 +149,7 @@ class Title {
                $t->mDbkeyform = str_replace( ' ', '_', $filteredText );
                $t->mDefaultNamespace = $defaultNamespace;
 
-               static $cachedcount = 0 ;
+               static $cachedcount = 0;
                if ( $t->secureAndSplit() ) {
                        if ( $defaultNamespace == NS_MAIN ) {
                                if ( $cachedcount >= self::CACHE_MAX ) {
@@ -1330,7 +1330,7 @@ class Title {
         * second argument named variant. This was deprecated in favor
         * of passing an array of option with a "variant" key
         * Once $query2 is removed for good, this helper can be dropped
-        * andthe wfArrayToCGI moved to getLocalURL();
+        * andthe wfArrayToCgi moved to getLocalURL();
         *
         * @since 1.19 (r105919)
         * @param $query
@@ -1342,15 +1342,15 @@ class Title {
                        wfDeprecated( "Title::get{Canonical,Full,Link,Local} method called with a second parameter is deprecated. Add your parameter to an array passed as the first parameter.", "1.19" );
                }
                if ( is_array( $query ) ) {
-                       $query = wfArrayToCGI( $query );
+                       $query = wfArrayToCgi( $query );
                }
                if ( $query2 ) {
                        if ( is_string( $query2 ) ) {
                                // $query2 is a string, we will consider this to be
                                // a deprecated $variant argument and add it to the query
-                               $query2 = wfArrayToCGI( array( 'variant' => $query2 ) );
+                               $query2 = wfArrayToCgi( array( 'variant' => $query2 ) );
                        } else {
-                               $query2 = wfArrayToCGI( $query2 );
+                               $query2 = wfArrayToCgi( $query2 );
                        }
                        // If we have $query content add a & to it first
                        if ( $query ) {
@@ -1728,8 +1728,10 @@ class Title {
         */
        private function checkQuickPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) {
                if ( $action == 'create' ) {
-                       if ( ( $this->isTalkPage() && !$user->isAllowed( 'createtalk' ) ) ||
-                                ( !$this->isTalkPage() && !$user->isAllowed( 'createpage' ) ) ) {
+                       if (
+                               ( $this->isTalkPage() && !$user->isAllowed( 'createtalk' ) ) ||
+                               ( !$this->isTalkPage() && !$user->isAllowed( 'createpage' ) )
+                       ) {
                                $errors[] = $user->isAnon() ? array( 'nocreatetext' ) : array( 'nocreate-loggedin' );
                        }
                } elseif ( $action == 'move' ) {
@@ -1818,8 +1820,11 @@ class Title {
                        $errors = $this->resultToError( $errors, $result );
                }
                // Check getUserPermissionsErrorsExpensive hook
-               if ( $doExpensiveQueries && !( $short && count( $errors ) > 0 ) &&
-                        !wfRunHooks( 'getUserPermissionsErrorsExpensive', array( &$this, &$user, $action, &$result ) ) ) {
+               if (
+                       $doExpensiveQueries
+                       && !( $short && count( $errors ) > 0 )
+                       && !wfRunHooks( 'getUserPermissionsErrorsExpensive', array( &$this, &$user, $action, &$result ) )
+               ) {
                        $errors = $this->resultToError( $errors, $result );
                }
 
@@ -1849,7 +1854,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' ) : array( 'namespaceprotected', $ns );
                }
 
                return $errors;
@@ -2087,7 +2092,7 @@ class Title {
         * @return Array list of errors
         */
        private function checkReadPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) {
-               global $wgWhitelistRead, $wgRevokePermissions;
+               global $wgWhitelistRead, $wgWhitelistReadRegexp, $wgRevokePermissions;
                static $useShortcut = null;
 
                # Initialize the $useShortcut boolean, to determine if we can skip quite a bit of code below
@@ -2146,7 +2151,7 @@ class Title {
                                # If it's a special page, ditch the subpage bit and check again
                                $name = $this->getDBkey();
                                list( $name, /* $subpage */ ) = SpecialPageFactory::resolveAlias( $name );
-                               if ( $name !== false ) {
+                               if ( $name ) {
                                        $pure = SpecialPage::getTitleFor( $name )->getPrefixedText();
                                        if ( in_array( $pure, $wgWhitelistRead, true ) ) {
                                                $whitelisted = true;
@@ -2155,6 +2160,17 @@ class Title {
                        }
                }
 
+               if( !$whitelisted && is_array( $wgWhitelistReadRegexp ) && !empty( $wgWhitelistReadRegexp ) ) {
+                       $name = $this->getPrefixedText();
+                       // Check for regex whitelisting
+                       foreach ( $wgWhitelistReadRegexp as $listItem ) {
+                               if ( preg_match( $listItem, $name ) ) {
+                                       $whitelisted = true;
+                                       break;
+                               }
+                       }
+               }
+
                if ( !$whitelisted ) {
                        # If the title is not whitelisted, give extensions a chance to do so...
                        wfRunHooks( 'TitleReadWhitelist', array( $this, $user, &$whitelisted ) );
@@ -2263,8 +2279,10 @@ class Title {
        public function userCanEditJsSubpage() {
                global $wgUser;
                wfDeprecated( __METHOD__, '1.19' );
-               return ( ( $wgUser->isAllowedAll( 'editusercssjs', 'edituserjs' ) )
-                          || preg_match( '/^' . preg_quote( $wgUser->getName(), '/' ) . '\//', $this->mTextform ) );
+               return (
+                       ( $wgUser->isAllowedAll( 'editusercssjs', 'edituserjs' ) )
+                       || preg_match( '/^' . preg_quote( $wgUser->getName(), '/' ) . '\//', $this->mTextform )
+               );
        }
 
        /**
@@ -2332,9 +2350,12 @@ class Title {
 
                if ( !isset( $this->mTitleProtection ) ) {
                        $dbr = wfGetDB( DB_SLAVE );
-                       $res = $dbr->select( 'protected_titles', '*',
+                       $res = $dbr->select(
+                               'protected_titles',
+                               array( 'pt_user', 'pt_reason', 'pt_expiry', 'pt_create_perm' ),
                                array( 'pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey() ),
-                               __METHOD__ );
+                               __METHOD__
+                       );
 
                        // fetchRow returns false if there are no rows.
                        $this->mTitleProtection = $dbr->fetchRow( $res );
@@ -2511,7 +2532,7 @@ class Title {
 
                if ( $getPages ) {
                        $cols = array( 'pr_page', 'page_namespace', 'page_title',
-                                                  'pr_expiry', 'pr_type', 'pr_level' );
+                               'pr_expiry', 'pr_type', 'pr_level' );
                        $where_clauses[] = 'page_id=pr_page';
                        $tables[] = 'page';
                } else {
@@ -2539,8 +2560,10 @@ class Title {
                                                $pagerestrictions[$row->pr_type] = array();
                                        }
 
-                                       if ( isset( $pagerestrictions[$row->pr_type] ) &&
-                                                !in_array( $row->pr_level, $pagerestrictions[$row->pr_type] ) ) {
+                                       if (
+                                               isset( $pagerestrictions[$row->pr_type] )
+                                               && !in_array( $row->pr_level, $pagerestrictions[$row->pr_type] )
+                                       ) {
                                                $pagerestrictions[$row->pr_type][] = $row->pr_level;
                                        }
                                } else {
@@ -2724,7 +2747,7 @@ class Title {
 
                                $res = $dbr->select(
                                        'page_restrictions',
-                                       '*',
+                                       array( 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ),
                                        array( 'pr_page' => $this->getArticleID() ),
                                        __METHOD__
                                );
@@ -2766,6 +2789,10 @@ class Title {
         * Purge expired restrictions from the page_restrictions table
         */
        static function purgeExpiredRestrictions() {
+               if ( wfReadOnly() ) {
+                       return;
+               }
+
                $dbw = wfGetDB( DB_MASTER );
                $dbw->delete(
                        'page_restrictions',
@@ -3175,15 +3202,18 @@ class Title {
                # Pages with "/./" or "/../" appearing in the URLs will often be un-
                # reachable due to the way web browsers deal with 'relative' URLs.
                # Also, they conflict with subpage syntax.  Forbid them explicitly.
-               if ( strpos( $dbkey, '.' ) !== false &&
-                        ( $dbkey === '.' || $dbkey === '..' ||
-                          strpos( $dbkey, './' ) === 0  ||
-                          strpos( $dbkey, '../' ) === 0 ||
-                          strpos( $dbkey, '/./' ) !== false ||
-                          strpos( $dbkey, '/../' ) !== false  ||
-                          substr( $dbkey, -2 ) == '/.' ||
-                          substr( $dbkey, -3 ) == '/..' ) )
-               {
+               if (
+                       strpos( $dbkey, '.' ) !== false &&
+                       (
+                               $dbkey === '.' || $dbkey === '..' ||
+                               strpos( $dbkey, './' ) === 0  ||
+                               strpos( $dbkey, '../' ) === 0 ||
+                               strpos( $dbkey, '/./' ) !== false ||
+                               strpos( $dbkey, '/../' ) !== false  ||
+                               substr( $dbkey, -2 ) == '/.' ||
+                               substr( $dbkey, -3 ) == '/..'
+                       )
+               ) {
                        return false;
                }
 
@@ -3196,9 +3226,10 @@ class Title {
                # underlying database field. We make an exception for special pages, which
                # don't need to be stored in the database, and may edge over 255 bytes due
                # to subpage syntax for long titles, e.g. [[Special:Block/Long name]]
-               if ( ( $this->mNamespace != NS_SPECIAL && strlen( $dbkey ) > 255 ) ||
-                 strlen( $dbkey ) > 512 )
-               {
+               if (
+                       ( $this->mNamespace != NS_SPECIAL && strlen( $dbkey ) > 255 )
+                       || strlen( $dbkey ) > 512
+               ) {
                        return false;
                }
 
@@ -3493,9 +3524,11 @@ class Title {
                if ( strlen( $nt->getDBkey() ) < 1 ) {
                        $errors[] = array( 'articleexists' );
                }
-               if ( ( $this->getDBkey() == '' ) ||
-                        ( !$oldid ) ||
-                        ( $nt->getDBkey() == '' ) ) {
+               if (
+                       ( $this->getDBkey() == '' ) ||
+                       ( !$oldid ) ||
+                       ( $nt->getDBkey() == '' )
+               ) {
                        $errors[] = array( 'badarticleerror' );
                }
 
@@ -4024,12 +4057,11 @@ class Title {
 
                $dbr = wfGetDB( DB_SLAVE );
 
-               $res = $dbr->select( 'categorylinks', '*',
-                       array(
-                               'cl_from' => $titleKey,
-                       ),
-                       __METHOD__,
-                       array()
+               $res = $dbr->select(
+                       'categorylinks',
+                       'cl_to',
+                       array( 'cl_from' => $titleKey ),
+                       __METHOD__
                );
 
                if ( $res->numRows() > 0 ) {
@@ -4269,7 +4301,7 @@ class Title {
                }
                $old_cmp = '>';
                $new_cmp = '<';
-               $options = (array) $options;
+               $options = (array)$options;
                if ( in_array( 'include_old', $options ) ) {
                        $old_cmp = '>=';
                }