Index: branches/REL1_13/phase3/docs/hooks.txt |
— | — | @@ -879,12 +879,6 @@ |
880 | 880 | whether to use the content language (true) or site language (false) (bool) |
881 | 881 | &$transform: whether or not to expand variables and templates in the message (bool) |
882 | 882 | |
883 | | -'ObjectArrayFromResult': called when creating an ObjectArray object from a |
884 | | - database result. |
885 | | -$class: The class of object that this array represents (e.g., 'User', 'Title') |
886 | | -&$array: set this to an object to override the default object returned |
887 | | -$res: database result used to create the object |
888 | | - |
889 | 883 | 'OpenSearchUrls': Called when constructing the OpenSearch description XML. |
890 | 884 | Hooks can alter or append to the array of URLs for search & suggestion formats. |
891 | 885 | &$urls: array of associative arrays with Url element attributes |
— | — | @@ -1240,6 +1234,10 @@ |
1241 | 1235 | 'UploadComplete': Upon completion of a file upload |
1242 | 1236 | $uploadForm: Upload form object. File can be accessed by $uploadForm->mLocalFile. |
1243 | 1237 | |
| 1238 | +'UserArrayFromResult': called when creating an UserArray object from a database result |
| 1239 | +&$userArray: set this to an object to override the default object returned |
| 1240 | +$res: database result used to create the object |
| 1241 | + |
1244 | 1242 | 'userCan': To interrupt/advise the "user can do X to Y article" check. |
1245 | 1243 | If you want to display an error message, try getUserPermissionsErrors. |
1246 | 1244 | $title: Title object being checked against |
Index: branches/REL1_13/phase3/includes/ObjectArray.php |
— | — | @@ -1,107 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * ObjectArray is a class that stores arrays of objects in an efficient manner. |
5 | | - * It stores a minimum of information about each object, and then constructs |
6 | | - * them on the fly for iteration in foreach() loops. Currently this can only |
7 | | - * be done by storing the info in the form of a database result, which is a |
8 | | - * good choice because 1) it tends to be readily available and 2) it uses less |
9 | | - * memory than a PHP array. Other storage methods may be developed in the fu- |
10 | | - * ture. |
11 | | - * |
12 | | - * Currently you can get TitleArrays and UserArrays. Any other class could be |
13 | | - * easily added: it just needs a newFromRow() method that will accept a data- |
14 | | - * base row as its sole argument, and return an object. For the fields that |
15 | | - * need to be provided in the result you pass to the newFromResult() construc- |
16 | | - * tor, consult the appropriate object class' newFromRow() documentation. |
17 | | - * |
18 | | - * In addition to the usual Iterator methods, there's a count() method that |
19 | | - * will return the number of objects in the array. When later versions of PHP |
20 | | - * are supported, we may be able to avoid this by implementing the Countable |
21 | | - * interface, making this act more like a real array. |
22 | | - * |
23 | | - * Sample usage: |
24 | | - * $users = UserArray::newFromResult( $dbr->select( |
25 | | - * 'user', '*', $conds, $opts, __METHOD__ |
26 | | - * ) ); |
27 | | - * foreach( $users as $user ) { |
28 | | - * ...use $user's methods here, it's a User object!... |
29 | | - * } |
30 | | - */ |
31 | | -abstract class ObjectArray implements Iterator { |
32 | | - static function newFromClassAndResult( $class, $res ) { |
33 | | - $array = null; |
34 | | - if ( !wfRunHooks( 'ObjectArrayFromResult', array( $class, &$array, $res ) ) ) { |
35 | | - return null; |
36 | | - } |
37 | | - if ( $array === null ) { |
38 | | - $array = self::newFromResult_internal( $class, $res ); |
39 | | - } |
40 | | - return $array; |
41 | | - } |
42 | | - |
43 | | - protected static function newFromResult_internal( $class, $res ) { |
44 | | - return new ObjectArrayFromResult( $class, $res ); |
45 | | - } |
46 | | -} |
47 | | - |
48 | | -class ObjectArrayFromResult extends ObjectArray { |
49 | | - var $res, $class; |
50 | | - var $key = 0, $current = false; |
51 | | - |
52 | | - function __construct( $class, $res ) { |
53 | | - $this->class = $class; |
54 | | - $this->res = $res; |
55 | | - $this->key = 0; |
56 | | - $this->setCurrent( $this->res->current() ); |
57 | | - } |
58 | | - |
59 | | - protected function setCurrent( $row ) { |
60 | | - if ( $row === false ) { |
61 | | - $this->current = false; |
62 | | - } else { |
63 | | - $this->current = call_user_func( |
64 | | - array( $this->class, 'newFromRow' ), $row |
65 | | - ); |
66 | | - } |
67 | | - } |
68 | | - |
69 | | - public function count() { |
70 | | - return $this->res->numRows(); |
71 | | - } |
72 | | - |
73 | | - function current() { |
74 | | - return $this->current; |
75 | | - } |
76 | | - |
77 | | - function key() { |
78 | | - return $this->key; |
79 | | - } |
80 | | - |
81 | | - function next() { |
82 | | - $row = $this->res->next(); |
83 | | - $this->setCurrent( $row ); |
84 | | - $this->key++; |
85 | | - } |
86 | | - |
87 | | - function rewind() { |
88 | | - $this->res->rewind(); |
89 | | - $this->key = 0; |
90 | | - $this->setCurrent( $this->res->current() ); |
91 | | - } |
92 | | - |
93 | | - function valid() { |
94 | | - return $this->current !== false; |
95 | | - } |
96 | | -} |
97 | | - |
98 | | -abstract class UserArray extends ObjectArray { |
99 | | - static function newFromResult( $res ) { |
100 | | - return parent::newFromClassAndResult( 'User', $res ); |
101 | | - } |
102 | | -} |
103 | | - |
104 | | -abstract class TitleArray extends ObjectArray { |
105 | | - static function newFromResult( $res ) { |
106 | | - return parent::newFromClassAndResult( 'Title', $res ); |
107 | | - } |
108 | | -} |
Index: branches/REL1_13/phase3/includes/AutoLoader.php |
— | — | @@ -129,7 +129,6 @@ |
130 | 130 | 'MWNamespace' => 'includes/Namespace.php', |
131 | 131 | 'MySQLSearchResultSet' => 'includes/SearchMySQL.php', |
132 | 132 | 'Namespace' => 'includes/NamespaceCompat.php', // Compat |
133 | | - 'ObjectArray' => 'includes/ObjectArray.php', |
134 | 133 | 'OldChangesList' => 'includes/ChangesList.php', |
135 | 134 | 'OracleSearchResultSet' => 'includes/SearchOracle.php', |
136 | 135 | 'OutputPage' => 'includes/OutputPage.php', |
— | — | @@ -189,7 +188,6 @@ |
190 | 189 | 'TableDiffFormatter' => 'includes/DifferenceEngine.php', |
191 | 190 | 'TablePager' => 'includes/Pager.php', |
192 | 191 | 'ThumbnailImage' => 'includes/MediaTransformOutput.php', |
193 | | - 'TitleArray' => 'includes/ObjectArray.php', |
194 | 192 | 'TitleDependency' => 'includes/CacheDependency.php', |
195 | 193 | 'Title' => 'includes/Title.php', |
196 | 194 | 'TitleListDependency' => 'includes/CacheDependency.php', |
— | — | @@ -198,7 +196,7 @@ |
199 | 197 | 'UnifiedDiffFormatter' => 'includes/DifferenceEngine.php', |
200 | 198 | 'UnlistedSpecialPage' => 'includes/SpecialPage.php', |
201 | 199 | 'User' => 'includes/User.php', |
202 | | - 'UserArray' => 'includes/ObjectArray.php', |
| 200 | + 'UserArray' => 'includes/UserArray.php', |
203 | 201 | 'UserArrayFromResult' => 'includes/UserArray.php', |
204 | 202 | 'UserMailer' => 'includes/UserMailer.php', |
205 | 203 | 'UserRightsProxy' => 'includes/UserRightsProxy.php', |
Index: branches/REL1_13/phase3/includes/UserArray.php |
— | — | @@ -0,0 +1,62 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +abstract class UserArray implements Iterator { |
| 5 | + static function newFromResult( $res ) { |
| 6 | + $userArray = null; |
| 7 | + if ( !wfRunHooks( 'UserArrayFromResult', array( &$userArray, $res ) ) ) { |
| 8 | + return null; |
| 9 | + } |
| 10 | + if ( $userArray === null ) { |
| 11 | + $userArray = self::newFromResult_internal( $res ); |
| 12 | + } |
| 13 | + return $userArray; |
| 14 | + } |
| 15 | + |
| 16 | + protected static function newFromResult_internal( $res ) { |
| 17 | + $userArray = new UserArrayFromResult( $res ); |
| 18 | + return $userArray; |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +class UserArrayFromResult extends UserArray { |
| 23 | + var $res; |
| 24 | + var $key, $current; |
| 25 | + |
| 26 | + function __construct( $res ) { |
| 27 | + $this->res = $res; |
| 28 | + $this->key = 0; |
| 29 | + $this->setCurrent( $this->res->current() ); |
| 30 | + } |
| 31 | + |
| 32 | + protected function setCurrent( $row ) { |
| 33 | + if ( $row === false ) { |
| 34 | + $this->current = false; |
| 35 | + } else { |
| 36 | + $this->current = User::newFromRow( $row ); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + function current() { |
| 41 | + return $this->current; |
| 42 | + } |
| 43 | + |
| 44 | + function key() { |
| 45 | + return $this->key; |
| 46 | + } |
| 47 | + |
| 48 | + function next() { |
| 49 | + $row = $this->res->next(); |
| 50 | + $this->setCurrent( $row ); |
| 51 | + $this->key++; |
| 52 | + } |
| 53 | + |
| 54 | + function rewind() { |
| 55 | + $this->res->rewind(); |
| 56 | + $this->key = 0; |
| 57 | + $this->setCurrent( $this->res->current() ); |
| 58 | + } |
| 59 | + |
| 60 | + function valid() { |
| 61 | + return $this->current !== false; |
| 62 | + } |
| 63 | +} |
Property changes on: branches/REL1_13/phase3/includes/UserArray.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 64 | + native |