Fix check of return value from SpecialPageFactory::resolveAlias
[lhc/web/wiklou.git] / includes / Title.php
index e02396b..b11d8c1 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 ) {
@@ -689,7 +689,7 @@ class Title {
                }
 
                if( !$this->mContentModel ) {
-                       throw new MWException( "failed to determin content model!" );
+                       throw new MWException( 'Failed to determine content model!' );
                }
 
                return $this->mContentModel;
@@ -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 ) {
@@ -1838,10 +1838,9 @@ class Title {
         * @return Array list of errors
         */
        private function checkSpecialsAndNSPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) {
-               # Only 'createaccount' and 'execute' can be performed on
-               # special pages, which don't actually exist in the DB.
-               $specialOKActions = array( 'createaccount', 'execute' );
-               if ( NS_SPECIAL == $this->mNamespace && !in_array( $action, $specialOKActions ) ) {
+               # Only 'createaccount' can be performed on special pages,
+               # which don't actually exist in the DB.
+               if ( NS_SPECIAL == $this->mNamespace && $action !== 'createaccount' ) {
                        $errors[] = array( 'ns-specialprotected' );
                }
 
@@ -1850,7 +1849,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;
@@ -2088,7 +2087,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
@@ -2147,7 +2146,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;
@@ -2156,6 +2155,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 ) );
@@ -2333,9 +2343,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 );
@@ -2725,7 +2738,7 @@ class Title {
 
                                $res = $dbr->select(
                                        'page_restrictions',
-                                       '*',
+                                       array( 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ),
                                        array( 'pr_page' => $this->getArticleID() ),
                                        __METHOD__
                                );
@@ -2767,6 +2780,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',
@@ -3504,9 +3521,11 @@ class Title {
                if ( !$wgContentHandlerUseDB &&
                                $this->getContentModel() !== $nt->getContentModel() ) {
                        // can't move a page if that would change the page's content model
-                       $errors[] = array( 'bad-target-model',
-                                                       ContentHandler::getLocalizedName( $this->getContentModel() ),
-                                                       ContentHandler::getLocalizedName( $nt->getContentModel() ) );
+                       $errors[] = array(
+                               'bad-target-model',
+                               ContentHandler::getLocalizedName( $this->getContentModel() ),
+                               ContentHandler::getLocalizedName( $nt->getContentModel() )
+                       );
                }
 
                // Image-specific checks
@@ -3979,7 +3998,7 @@ class Title {
                }
                # Get the article text
                $rev = Revision::newFromTitle( $nt, false, Revision::READ_LATEST );
-               if( !is_object( $rev ) ){
+               if( !is_object( $rev ) ) {
                        return false;
                }
                $content = $rev->getContent();
@@ -4023,12 +4042,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 ) {