From a42e23da228688a95b6bbc534611065058ea3100 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Tue, 29 Jul 2008 14:53:10 +0000 Subject: [PATCH] Revert r38165 for now, breaks CentralAuth and I don't have that installed anywhere to debug. --- docs/hooks.txt | 14 ++--- includes/AutoLoader.php | 5 +- includes/ObjectArray.php | 107 --------------------------------------- includes/TitleArray.php | 81 +++++++++++++++++++++++++++++ includes/UserArray.php | 66 ++++++++++++++++++++++++ 5 files changed, 157 insertions(+), 116 deletions(-) delete mode 100644 includes/ObjectArray.php create mode 100644 includes/TitleArray.php create mode 100644 includes/UserArray.php diff --git a/docs/hooks.txt b/docs/hooks.txt index e09528ed2f..98ceb42681 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -871,12 +871,6 @@ $baseID: the revision ID this was based off, if any whether to use the content language (true) or site language (false) (bool) &$transform: whether or not to expand variables and templates in the message (bool) -'ObjectArrayFromResult': called when creating an ObjectArray object from a - database result. -$class: The class of object that this array represents (e.g., 'User', 'Title') -&$array: set this to an object to override the default object returned -$res: database result used to create the object - 'OpenSearchUrls': Called when constructing the OpenSearch description XML. Hooks can alter or append to the array of URLs for search & suggestion formats. &$urls: array of associative arrays with Url element attributes @@ -1185,6 +1179,10 @@ $term: string of search term 'SpecialVersionExtensionTypes': called when generating the extensions credits, use this to change the tables headers $extTypes: associative array of extensions types +'TitleArrayFromResult': called when creating an TitleArray object from a database result +&$titleArray: set this to an object to override the default object returned +$res: database result used to create the object + 'TitleMoveComplete': after moving an article (title) $old: old title $nt: new title @@ -1232,6 +1230,10 @@ string &$error: output: HTML error to show if upload canceled by returning false 'UploadComplete': Upon completion of a file upload $uploadForm: Upload form object. File can be accessed by $uploadForm->mLocalFile. +'UserArrayFromResult': called when creating an UserArray object from a database result +&$userArray: set this to an object to override the default object returned +$res: database result used to create the object + 'userCan': To interrupt/advise the "user can do X to Y article" check. If you want to display an error message, try getUserPermissionsErrors. $title: Title object being checked against diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 0af6bfd909..0351017145 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -130,7 +130,6 @@ $wgAutoloadLocalClasses = array( 'MWNamespace' => 'includes/Namespace.php', 'MySQLSearchResultSet' => 'includes/SearchMySQL.php', 'Namespace' => 'includes/NamespaceCompat.php', // Compat - 'ObjectArray' => 'includes/ObjectArray.php', 'OldChangesList' => 'includes/ChangesList.php', 'OracleSearchResultSet' => 'includes/SearchOracle.php', 'OutputPage' => 'includes/OutputPage.php', @@ -192,14 +191,14 @@ $wgAutoloadLocalClasses = array( 'ThumbnailImage' => 'includes/MediaTransformOutput.php', 'TitleDependency' => 'includes/CacheDependency.php', 'Title' => 'includes/Title.php', - 'TitleArray' => 'includes/ObjectArray.php', + 'TitleArray' => 'includes/TitleArray.php', 'TitleListDependency' => 'includes/CacheDependency.php', 'TransformParameterError' => 'includes/MediaTransformOutput.php', 'TurckBagOStuff' => 'includes/BagOStuff.php', 'UnifiedDiffFormatter' => 'includes/DifferenceEngine.php', 'UnlistedSpecialPage' => 'includes/SpecialPage.php', 'User' => 'includes/User.php', - 'UserArray' => 'includes/ObjectArray.php', + 'UserArray' => 'includes/UserArray.php', 'UserArrayFromResult' => 'includes/UserArray.php', 'UserMailer' => 'includes/UserMailer.php', 'UserRightsProxy' => 'includes/UserRightsProxy.php', diff --git a/includes/ObjectArray.php b/includes/ObjectArray.php deleted file mode 100644 index 429d369134..0000000000 --- a/includes/ObjectArray.php +++ /dev/null @@ -1,107 +0,0 @@ -select( - * 'user', '*', $conds, $opts, __METHOD__ - * ) ); - * foreach( $users as $user ) { - * ...use $user's methods here, it's a User object!... - * } - */ -abstract class ObjectArray implements Iterator { - static function newFromClassAndResult( $class, $res ) { - $array = null; - if ( !wfRunHooks( 'ObjectArrayFromResult', array( $class, &$array, $res ) ) ) { - return null; - } - if ( $array === null ) { - $array = self::newFromResult_internal( $class, $res ); - } - return $array; - } - - protected static function newFromResult_internal( $class, $res ) { - return new ObjectArrayFromResult( $class, $res ); - } -} - -class ObjectArrayFromResult extends ObjectArray { - var $res, $class; - var $key = 0, $current = false; - - function __construct( $class, $res ) { - $this->class = $class; - $this->res = $res; - $this->key = 0; - $this->setCurrent( $this->res->current() ); - } - - protected function setCurrent( $row ) { - if ( $row === false ) { - $this->current = false; - } else { - $this->current = call_user_func( - array( $this->class, 'newFromRow' ), $row - ); - } - } - - public function count() { - return $this->res->numRows(); - } - - function current() { - return $this->current; - } - - function key() { - return $this->key; - } - - function next() { - $row = $this->res->next(); - $this->setCurrent( $row ); - $this->key++; - } - - function rewind() { - $this->res->rewind(); - $this->key = 0; - $this->setCurrent( $this->res->current() ); - } - - function valid() { - return $this->current !== false; - } -} - -abstract class UserArray extends ObjectArray { - static function newFromResult( $res ) { - return parent::newFromClassAndResult( 'User', $res ); - } -} - -abstract class TitleArray extends ObjectArray { - static function newFromResult( $res ) { - return parent::newFromClassAndResult( 'Title', $res ); - } -} diff --git a/includes/TitleArray.php b/includes/TitleArray.php new file mode 100644 index 0000000000..f7a9e1dc64 --- /dev/null +++ b/includes/TitleArray.php @@ -0,0 +1,81 @@ +res = $res; + $this->key = 0; + $this->setCurrent( $this->res->current() ); + } + + protected function setCurrent( $row ) { + if ( $row === false ) { + $this->current = false; + } else { + $this->current = Title::newFromRow( $row ); + } + } + + public function count() { + return $this->res->numRows(); + } + + function current() { + return $this->current; + } + + function key() { + return $this->key; + } + + function next() { + $row = $this->res->next(); + $this->setCurrent( $row ); + $this->key++; + } + + function rewind() { + $this->res->rewind(); + $this->key = 0; + $this->setCurrent( $this->res->current() ); + } + + function valid() { + return $this->current !== false; + } +} diff --git a/includes/UserArray.php b/includes/UserArray.php new file mode 100644 index 0000000000..a2f54b7f27 --- /dev/null +++ b/includes/UserArray.php @@ -0,0 +1,66 @@ +res = $res; + $this->key = 0; + $this->setCurrent( $this->res->current() ); + } + + protected function setCurrent( $row ) { + if ( $row === false ) { + $this->current = false; + } else { + $this->current = User::newFromRow( $row ); + } + } + + public function count() { + return $this->res->numRows(); + } + + function current() { + return $this->current; + } + + function key() { + return $this->key; + } + + function next() { + $row = $this->res->next(); + $this->setCurrent( $row ); + $this->key++; + } + + function rewind() { + $this->res->rewind(); + $this->key = 0; + $this->setCurrent( $this->res->current() ); + } + + function valid() { + return $this->current !== false; + } +} -- 2.20.1