Added placeholders for text injection by hooks to EditPage.php
[lhc/web/wiklou.git] / includes / Revision.php
index a915a96..6ef9ede 100644 (file)
@@ -4,9 +4,6 @@
  * @todo document
  */
 
-/** */
-require_once( 'Database.php' );
-
 /**
  * @package MediaWiki
  * @todo document
@@ -22,8 +19,8 @@ class Revision {
         * Returns null if no such revision can be found.
         *
         * @param int $id
-        * @static
         * @access public
+        * @static
         */
        public static function newFromId( $id ) {
                return Revision::newFromConds(
@@ -55,6 +52,21 @@ class Revision {
                               'page_title'     => $title->getDbkey() ) );
        }
 
+       /**
+        * Load a page revision from a given revision ID number.
+        * Returns null if no such revision can be found.
+        *
+        * @param Database $db
+        * @param int $id
+        * @access public
+        * @static
+        */
+       public static function loadFromId( &$db, $id ) {
+               return Revision::loadFromConds( $db,
+                       array( 'page_id=rev_page',
+                              'rev_id' => intval( $id ) ) );
+       }
+
        /**
         * Load either the current, or a specified, revision
         * that's attached to a given page. If not attached
@@ -65,6 +77,7 @@ class Revision {
         * @param int $id
         * @return Revision
         * @access public
+        * @static
         */
        public static function loadFromPageId( &$db, $pageid, $id = 0 ) {
                $conds=array('page_id=rev_page','rev_page'=>intval( $pageid ), 'page_id'=>intval( $pageid ));
@@ -86,8 +99,9 @@ class Revision {
         * @param int $id
         * @return Revision
         * @access public
+        * @static
         */
-       function loadFromTitle( &$db, $title, $id = 0 ) {
+       public static function loadFromTitle( &$db, $title, $id = 0 ) {
                if( $id ) {
                        $matchId = intval( $id );
                } else {
@@ -113,7 +127,7 @@ class Revision {
         * @access public
         * @static
         */
-       function loadFromTimestamp( &$db, &$title, $timestamp ) {
+       public static function loadFromTimestamp( &$db, &$title, $timestamp ) {
                return Revision::loadFromConds(
                        $db,
                        array( 'rev_timestamp'  => $db->timestamp( $timestamp ),
@@ -127,8 +141,8 @@ class Revision {
         *
         * @param array $conditions
         * @return Revision
-        * @static
         * @access private
+        * @static
         */
        private static function newFromConds( $conditions ) {
                $db =& wfGetDB( DB_SLAVE );
@@ -147,8 +161,8 @@ class Revision {
         * @param Database $db
         * @param array $conditions
         * @return Revision
-        * @static
         * @access private
+        * @static
         */
        private static function loadFromConds( &$db, $conditions ) {
                $res = Revision::fetchFromConds( $db, $conditions );
@@ -171,10 +185,10 @@ class Revision {
         *
         * @param Title $title
         * @return ResultWrapper
-        * @static
         * @access public
+        * @static
         */
-       function fetchAllRevisions( &$title ) {
+       public static function fetchAllRevisions( &$title ) {
                return Revision::fetchFromConds(
                        wfGetDB( DB_SLAVE ),
                        array( 'page_namespace' => $title->getNamespace(),
@@ -189,8 +203,8 @@ class Revision {
         *
         * @param Title $title
         * @return ResultWrapper
-        * @static
         * @access public
+        * @static
         */
        public static function fetchRevision( &$title ) {
                return Revision::fetchFromConds(
@@ -209,8 +223,8 @@ class Revision {
         * @param Database $db
         * @param array $conditions
         * @return ResultWrapper
-        * @static
         * @access private
+        * @static
         */
        private static function fetchFromConds( &$db, $conditions ) {
                $res = $db->select(
@@ -283,6 +297,7 @@ class Revision {
                        // Enforce spacing trimming on supplied text
                        $this->mComment   = isset( $row['comment']    ) ?  trim( strval( $row['comment'] ) ) : null;
                        $this->mText      = isset( $row['text']       ) ? rtrim( strval( $row['text']    ) ) : null;
+                       $this->mTextRow   = null;
 
                        $this->mTitle     = null; # Load on demand if needed
                        $this->mCurrent   = false;
@@ -522,7 +537,6 @@ class Revision {
                                wfProfileOut( $fname );
                                return false;
                        }
-                       require_once('ExternalStore.php');
                        $text=ExternalStore::fetchFromURL($url);
                }
 
@@ -612,7 +626,6 @@ class Revision {
                        } else {
                                $store = $wgDefaultExternalStore;
                        }
-                       require_once('ExternalStore.php');
                        // Store and get the URL
                        $data = ExternalStore::insert( $store, $data );
                        if ( !$data ) {
@@ -673,8 +686,8 @@ class Revision {
                wfProfileIn( $fname );
                
                // Caching may be beneficial for massive use of external storage
-               global $wgRevisionCacheExpiry, $wgMemc, $wgDBname;
-               $key = "$wgDBname:revisiontext:textid:" . $this->getTextId();
+               global $wgRevisionCacheExpiry, $wgMemc;
+               $key = wfMemcKey( 'revisiontext', 'textid', $this->getTextId() );
                if( $wgRevisionCacheExpiry ) {
                        $text = $wgMemc->get( $key );
                        if( is_string( $text ) ) {
@@ -684,8 +697,12 @@ class Revision {
                }
                
                // If we kept data for lazy extraction, use it now...
-               $row = $this->mTextRow;
-               $this->mTextRow = null;
+               if ( isset( $this->mTextRow ) ) {
+                       $row = $this->mTextRow;
+                       $this->mTextRow = null;
+               } else {
+                       $row = null;
+               }
                
                if( !$row ) {
                        // Text data is immutable; check slaves first.