Index: branches/apiedit/phase3/includes/api/ApiQueryInfo.php |
— | — | @@ -72,12 +72,13 @@ |
73 | 73 | $pageLatest = $pageSet->getCustomField('page_latest'); |
74 | 74 | $pageLength = $pageSet->getCustomField('page_len'); |
75 | 75 | |
| 76 | + $db = $this->getDB(); |
76 | 77 | if ($fld_protection && count($titles) > 0) { |
| 78 | + // Query all restrictions we need in one go and put them in the $protections array |
77 | 79 | $this->addTables('page_restrictions'); |
78 | 80 | $this->addFields(array('pr_page', 'pr_type', 'pr_level', 'pr_expiry')); |
79 | 81 | $this->addWhereFld('pr_page', array_keys($titles)); |
80 | 82 | |
81 | | - $db = $this->getDB(); |
82 | 83 | $res = $this->select(__METHOD__); |
83 | 84 | while($row = $db->fetchObject($res)) { |
84 | 85 | $protections[$row->pr_page][] = array( |
— | — | @@ -88,7 +89,21 @@ |
89 | 90 | } |
90 | 91 | $db->freeResult($res); |
91 | 92 | } |
92 | | - |
| 93 | + |
| 94 | + if($fld_lastrevby || isset($params['tokens']['rollback'])) |
| 95 | + { |
| 96 | + // Query all revisions we need in one go and put them in the $lastrevby array |
| 97 | + $this->resetQueryParams(); |
| 98 | + $this->addTables('revision'); |
| 99 | + $this->addFields(array('rev_id', 'rev_user_text')); |
| 100 | + $this->addWhereFld('rev_id', $pageLatest); |
| 101 | + |
| 102 | + $res = $this->select(__METHOD__); |
| 103 | + while($row = $db->fetchObject($res)) |
| 104 | + $lastrevby[intval($row->rev_id)] = $row->rev_user_text; |
| 105 | + } |
| 106 | + |
| 107 | + $et = null; // Cached edit token is stored here |
93 | 108 | foreach ( $titles as $pageid => $title ) { |
94 | 109 | $pageInfo = array ( |
95 | 110 | 'touched' => wfTimestamp(TS_ISO_8601, $pageTouched[$pageid]), |
— | — | @@ -96,12 +111,10 @@ |
97 | 112 | 'counter' => intval($pageCounter[$pageid]), |
98 | 113 | 'length' => intval($pageLength[$pageid]) |
99 | 114 | ); |
100 | | - if(isset($params['tokens']) || $fld_lastrevby) |
101 | | - { |
102 | | - $lastrev = Revision::newFromId($pageInfo['lastrevid']); |
103 | | - $pageInfo['lastrevby'] = $lastrev->getUserText(); |
104 | | - } |
105 | 115 | |
| 116 | + if($fld_lastrevby) |
| 117 | + $pageInfo['lastrevby'] = $lastrevby[$pageInfo['lastrevid']]; |
| 118 | + |
106 | 119 | if ($pageIsRedir[$pageid]) |
107 | 120 | $pageInfo['redirect'] = ''; |
108 | 121 | |
— | — | @@ -124,17 +137,23 @@ |
125 | 138 | switch($token) |
126 | 139 | { |
127 | 140 | case 'rollback': |
128 | | - $tokenArr[$token] = $wgUser->editToken(array($title->getPrefixedText(), $pageInfo['lastrevby'])); |
| 141 | + $tokenArr[$token] = $wgUser->editToken(array($title->getPrefixedText(), $lastrevby[$pageInfo['lastrevid']])); |
129 | 142 | break; |
130 | 143 | case 'edit': |
131 | 144 | case 'move': |
132 | 145 | case 'delete': |
133 | 146 | case 'protect': |
134 | 147 | case 'unprotect': |
135 | | - if($wgUser->isAnon()) |
136 | | - $tokenArr[$token] = EDIT_TOKEN_SUFFIX; |
| 148 | + // All these tokens are constant, so we can cache them |
| 149 | + if(!is_null($et)) |
| 150 | + $tokenArr[$token] = $et; |
137 | 151 | else |
138 | | - $tokenArr[$token] = $wgUser->editToken(); |
| 152 | + { |
| 153 | + if($wgUser->isAnon()) |
| 154 | + $et = $tokenArr[$token] = EDIT_TOKEN_SUFFIX; |
| 155 | + else |
| 156 | + $et = $tokenArr[$token] = $wgUser->editToken(); |
| 157 | + } |
139 | 158 | // default: can't happen, ignore it if it does happen in some weird way |
140 | 159 | } |
141 | 160 | if(count($tokenArr) > 0) |
— | — | @@ -178,7 +197,7 @@ |
179 | 198 | 'prop' => array ( |
180 | 199 | 'Which additional properties to get:', |
181 | 200 | ' "protection" - List the protection level of each page', |
182 | | - ' "lastrevby" - The name of the user who made the last edit. You may need this for action=rollback.' |
| 201 | + ' "lastrevby" - List the name of the user who made the last edit' |
183 | 202 | ), |
184 | 203 | 'tokens' => 'Which tokens to get.' |
185 | 204 | ); |