s/Revision::MW_REV_DELETED/Revision::DELETED/, and introduced aliases for compatibili...
[lhc/web/wiklou.git] / includes / Title.php
index de971d5..ed46c4a 100644 (file)
@@ -205,6 +205,21 @@ class Title {
                return $title;
        }
 
+       /**
+        * Make an array of titles from an array of IDs 
+        */
+       function newFromIDs( $ids ) {
+               $dbr =& wfGetDB( DB_SLAVE );
+               $res = $dbr->select( 'page', array( 'page_namespace', 'page_title' ),
+                       'page_id IN (' . $dbr->makeList( $ids ) . ')', __METHOD__ );
+
+               $titles = array();
+               while ( $row = $dbr->fetchObject( $res ) ) {
+                       $titles[] = Title::makeTitle( $row->page_namespace, $row->page_title );
+               }
+               return $titles;
+       }
+
        /**
         * Create a new Title from a namespace index and a DB key.
         * It's assumed that $ns and $title are *valid*, for instance when
@@ -1256,6 +1271,10 @@ class Title {
                        $dbr =& wfGetDB( DB_SLAVE );
                        $n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(),
                                'ar_title' => $this->getDBkey() ), $fname );
+                       if( $this->getNamespace() == NS_IMAGE ) {
+                               $n += $dbr->selectField( 'filearchive', 'COUNT(*)',
+                                       array( 'fa_name' => $this->getDBkey() ), $fname );
+                       }
                }
                return (int)$n;
        }
@@ -1568,6 +1587,9 @@ class Title {
         * Get an array of Title objects linking to this Title
         * Also stores the IDs in the link cache.
         *
+        * WARNING: do not use this function on arbitrary user-supplied titles!
+        * On heavily-used templates it will max out the memory.
+        *
         * @param string $options may be FOR UPDATE
         * @return array the Title objects linking here
         * @access public
@@ -1608,6 +1630,9 @@ class Title {
         * Get an array of Title objects using this Title as a template
         * Also stores the IDs in the link cache.
         *
+        * WARNING: do not use this function on arbitrary user-supplied titles!
+        * On heavily-used templates it will max out the memory.
+        *
         * @param string $options may be FOR UPDATE
         * @return array the Title objects linking here
         * @access public
@@ -1669,6 +1694,15 @@ class Title {
                );
        }
 
+       function purgeSquid() {
+               global $wgUseSquid;
+               if ( $wgUseSquid ) {
+                       $urls = $this->getSquidURLs();
+                       $u = new SquidUpdate( $urls );
+                       $u->doUpdate();
+               }
+       }
+
        /**
         * Move this page without authentication
         * @param Title &$nt the new page Title
@@ -1949,21 +1983,9 @@ class Title {
                                'pl_title'     => $nt->getDBkey() ),
                        $fname );
 
-               # Non-existent target may have had broken links to it; these must
-               # now be touched to update link coloring.
-               $nt->touchLinks();
-
                # Purge old title from squid
                # The new title, and links to the new title, are purged in Article::onArticleCreate()
-               $titles = $nt->getLinksTo();
-               if ( $wgUseSquid ) {
-                       $urls = $this->getSquidURLs();
-                       foreach ( $titles as $linkTitle ) {
-                               $urls[] = $linkTitle->getInternalURL();
-                       }
-                       $u = new SquidUpdate( $urls );
-                       $u->doUpdate();
-               }
+               $this->purgeSquid();
        }
 
        /**
@@ -2130,11 +2152,11 @@ class Title {
        /**
         * Get the revision ID of the previous revision
         *
-        * @param integer $revision  Revision ID. Get the revision that was before this one.
+        * @param integer $revId  Revision ID. Get the revision that was before this one.
+        * @param string $timestamp The timestamp of the current revision, if known
         * @return interger $oldrevision|false
         */
-       function getPreviousRevisionID( $revision ) {
-               $dbr =& wfGetDB( DB_SLAVE );
+       function getPreviousRevisionID( $revId, $timestamp = false ) {
                return $dbr->selectField( 'revision', 'rev_id',
                        'rev_page=' . intval( $this->getArticleId() ) .
                        ' AND rev_id<' . intval( $revision ) . ' ORDER BY rev_id DESC' );
@@ -2186,44 +2208,18 @@ class Title {
        }
 
        /**
-        * Update page_touched timestamps on pages linking to this title.
-        * In principal, this could be backgrounded and could also do squid
-        * purging.
+        * Update page_touched timestamps and send squid purge messages for
+        * pages linking to this title. May be sent to the job queue depending 
+        * on the number of links. Typically called on create and delete.
         */
        function touchLinks() {
-               $fname = 'Title::touchLinks';
-
-               $dbw =& wfGetDB( DB_MASTER );
-
-               $res = $dbw->select( 'pagelinks',
-                       array( 'pl_from' ),
-                       array(
-                               'pl_namespace' => $this->getNamespace(),
-                               'pl_title'     => $this->getDbKey() ),
-                       $fname );
-
-               $toucharr = array();
-               while( $row = $dbw->fetchObject( $res ) ) {
-                       $toucharr[] = $row->pl_from;
-               }
-               $dbw->freeResult( $res );
+               $u = new HTMLCacheUpdate( $this, 'pagelinks' );
+               $u->doUpdate();
 
-               if( $this->getNamespace() == NS_CATEGORY ) {
-                       // Categories show up in a separate set of links as well
-                       $res = $dbw->select( 'categorylinks',
-                               array( 'cl_from' ),
-                               array( 'cl_to' => $this->getDbKey() ),
-                               $fname );
-                       while( $row = $dbw->fetchObject( $res ) ) {
-                               $toucharr[] = $row->cl_from;
-                       }
-                       $dbw->freeResult( $res );
+               if ( $this->getNamespace() == NS_CATEGORY ) {
+                       $u = new HTMLCacheUpdate( $this, 'categorylinks' );
+                       $u->doUpdate();
                }
-
-               if (!count($toucharr))
-                       return;
-               $dbw->update( 'page', /* SET */ array( 'page_touched' => $dbw->timestamp() ),
-                                                       /* WHERE */ array( 'page_id' => $toucharr ),$fname);
        }
 
        function trackbackURL() {