Update docs in Pager.php for join_conds
[lhc/web/wiklou.git] / includes / Title.php
index 85451de..782169c 100644 (file)
@@ -179,20 +179,15 @@ class Title {
        /**
         * Create a new Title from an article ID
         *
-        * @todo This is inefficiently implemented, the page row is requested
-        *       but not used for anything else
-        *
         * @param $id \type{\int} the page_id corresponding to the Title to create
         * @param $flags \type{\int} use GAID_FOR_UPDATE to use master
         * @return \type{Title} the new object, or NULL on an error
         */
        public static function newFromID( $id, $flags = 0 ) {
-               $fname = 'Title::newFromID';
                $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
-               $row = $db->selectRow( 'page', array( 'page_namespace', 'page_title' ),
-                       array( 'page_id' => $id ), $fname );
-               if ( $row !== false ) {
-                       $title = Title::makeTitle( $row->page_namespace, $row->page_title );
+               $row = $db->selectRow( 'page', '*', array( 'page_id' => $id ), __METHOD__ );
+               if( $row !== false ) {
+                       $title = Title::newFromRow( $row );
                } else {
                        $title = NULL;
                }
@@ -1020,7 +1015,8 @@ class Title {
 
        /**
         * Can $wgUser perform $action on this page?
-        * This skips potentially expensive cascading permission checks.
+        * This skips potentially expensive cascading permission checks
+        * as well as avoids expensive error formatting
         *
         * Suitable for use for nonessential UI controls in common cases, but
         * _not_ for functional access control.
@@ -1205,8 +1201,14 @@ class Title {
                        }
                } elseif( !$user->isAllowed( $action ) ) {
                        $return = null;
-                       $groups = array_map( array( 'User', 'makeGroupLinkWiki' ),
-                               User::getGroupsWithPermission( $action ) );
+                       
+                       // We avoid expensive display logic for quickUserCan's and such
+                       $groups = false; 
+                       if (!$short) {
+                               $groups = array_map( array( 'User', 'makeGroupLinkWiki' ),
+                                       User::getGroupsWithPermission( $action ) );
+                       } 
+                       
                        if( $groups ) {
                                $return = array( 'badaccess-groups',
                                        array( implode( ', ', $groups ), count( $groups ) ) );
@@ -2197,9 +2199,6 @@ class Title {
                #
                $dbkey = preg_replace( '/[ _]+/', '_', $dbkey );
                $dbkey = trim( $dbkey, '_' );
-               
-               # Clean up Arabic harakats (bug 16899)
-               $dbkey = preg_replace( '/[\x{064B}-\x{0652}]/Su', '', $dbkey );
 
                if ( '' == $dbkey ) {
                        return false;
@@ -2665,6 +2664,18 @@ class Title {
                        return $err;
                }
 
+               // If it is a file, more it first. It is done before all other moving stuff is done because it's hard to revert
+               $dbw = wfGetDB( DB_MASTER );
+               if( $this->getNamespace() == NS_FILE ) {
+                       $file = wfLocalFile( $this );
+                       if( $file->exists() ) {
+                               $status = $file->move( $nt );
+                               if( !$status->isOk() ) {
+                                       return $status->getErrorsArray();
+                               }
+                       }
+               }
+
                $pageid = $this->getArticleID();
                $protected = $this->isProtected();
                if( $nt->exists() ) {
@@ -2691,7 +2702,6 @@ class Title {
                // we can't actually distinguish it from a default here, and it'll
                // be set to the new title even though it really shouldn't.
                // It'll get corrected on the next edit, but resetting cl_timestamp.
-               $dbw = wfGetDB( DB_MASTER );
                $dbw->update( 'categorylinks',
                        array(
                                'cl_sortkey' => $nt->getPrefixedText(),
@@ -2874,18 +2884,6 @@ class Title {
                        $redirectSuppressed = true;
                }
 
-               # Move an image if this is a file
-               if( $this->getNamespace() == NS_FILE ) {
-                       $file = wfLocalFile( $this );
-                       if( $file->exists() ) {
-                               $status = $file->move( $nt );
-                               if( !$status->isOk() ) {
-                                       $dbw->rollback();
-                                       return $status->getErrorsArray();
-                               }
-                       }
-               }
-
                # Log the move
                $log = new LogPage( 'move' );
                $log->addEntry( 'move_redir', $this, $reason, array( 1 => $nt->getPrefixedText(), 2 => $redirectSuppressed ) );
@@ -2971,18 +2969,6 @@ class Title {
                        $redirectSuppressed = true;
                }
 
-               # Move an image if this is a file
-               if( $this->getNamespace() == NS_FILE ) {
-                       $file = wfLocalFile( $this );
-                       if( $file->exists() ) {
-                               $status = $file->move( $nt );
-                               if( !$status->isOk() ) {
-                                       $dbw->rollback();
-                                       return $status->getErrorsArray();
-                               }
-                       }
-               }
-
                # Log the move
                $log = new LogPage( 'move' );
                $log->addEntry( 'move', $this, $reason, array( 1 => $nt->getPrefixedText(), 2 => $redirectSuppressed ) );