Index: trunk/phase3/includes/api/ApiQueryLinks.php |
— | — | @@ -48,6 +48,7 @@ |
49 | 49 | $this->prefix = 'pl'; |
50 | 50 | $this->description = 'link'; |
51 | 51 | $this->titlesParam = 'titles'; |
| 52 | + $this->titlesParamDescription = 'Only list links to these titles. Useful for checking whether a certain page links to a certain title.'; |
52 | 53 | $this->helpUrl = 'http://www.mediawiki.org/wiki/API:Properties#links_.2F_pl'; |
53 | 54 | break; |
54 | 55 | case self::TEMPLATES: |
— | — | @@ -55,6 +56,7 @@ |
56 | 57 | $this->prefix = 'tl'; |
57 | 58 | $this->description = 'template'; |
58 | 59 | $this->titlesParam = 'templates'; |
| 60 | + $this->titlesParamDescription = 'Only list these templates. Useful for checking whether a certain page uses a certain template.'; |
59 | 61 | $this->helpUrl = 'http://www.mediawiki.org/wiki/API:Properties#templates_.2F_tl'; |
60 | 62 | break; |
61 | 63 | default: |
— | — | @@ -131,6 +133,7 @@ |
132 | 134 | ); |
133 | 135 | } |
134 | 136 | |
| 137 | + $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' ); |
135 | 138 | // Here's some MySQL craziness going on: if you use WHERE foo='bar' |
136 | 139 | // and later ORDER BY foo MySQL doesn't notice the ORDER BY is pointless |
137 | 140 | // but instead goes and filesorts, because the index for foo was used |
— | — | @@ -138,15 +141,15 @@ |
139 | 142 | // clause from the ORDER BY clause |
140 | 143 | $order = array(); |
141 | 144 | if ( count( $this->getPageSet()->getGoodTitles() ) != 1 ) { |
142 | | - $order[] = "{$this->prefix}_from"; |
| 145 | + $order[] = $this->prefix . '_from' . $dir; |
143 | 146 | } |
144 | 147 | if ( count( $params['namespace'] ) != 1 ) { |
145 | | - $order[] = "{$this->prefix}_namespace"; |
| 148 | + $order[] = $this->prefix . '_namespace' . $dir; |
146 | 149 | } |
147 | 150 | |
148 | | - $order[] = "{$this->prefix}_title"; |
149 | | - $this->addOption( 'ORDER BY', implode( ', ', $order ) ); |
150 | | - $this->addOption( 'USE INDEX', "{$this->prefix}_from" ); |
| 151 | + $order[] = $this->prefix . "_title" . $dir; |
| 152 | + $this->addOption( 'ORDER BY', $order ); |
| 153 | + $this->addOption( 'USE INDEX', $this->prefix . '_from' ); |
151 | 154 | $this->addOption( 'LIMIT', $params['limit'] + 1 ); |
152 | 155 | |
153 | 156 | $res = $this->select( __METHOD__ ); |
— | — | @@ -207,22 +210,25 @@ |
208 | 211 | $this->titlesParam => array( |
209 | 212 | ApiBase::PARAM_ISMULTI => true, |
210 | 213 | ), |
| 214 | + 'dir' => array( |
| 215 | + ApiBase::PARAM_DFLT => 'ascending', |
| 216 | + ApiBase::PARAM_TYPE => array( |
| 217 | + 'ascending', |
| 218 | + 'descending' |
| 219 | + ) |
| 220 | + ), |
211 | 221 | ); |
212 | 222 | } |
213 | 223 | |
214 | 224 | public function getParamDescription() { |
215 | 225 | $desc = $this->description; |
216 | | - $arr = array( |
| 226 | + return array( |
217 | 227 | 'namespace' => "Show {$desc}s in this namespace(s) only", |
218 | 228 | 'limit' => "How many {$desc}s to return", |
219 | 229 | 'continue' => 'When more results are available, use this to continue', |
| 230 | + $this->titlesParam => $this->titlesParamDescription, |
| 231 | + 'dir' => 'The direction in which to list', |
220 | 232 | ); |
221 | | - if ( $this->getModuleName() == self::LINKS ) { |
222 | | - $arr[$this->titlesParam] = 'Only list links to these titles. Useful for checking whether a certain page links to a certain title.'; |
223 | | - } elseif ( $this->getModuleName() == self::TEMPLATES ) { |
224 | | - $arr[$this->titlesParam] = 'Only list these templates. Useful for checking whether a certain page uses a certain template.'; |
225 | | - } |
226 | | - return $arr; |
227 | 233 | } |
228 | 234 | |
229 | 235 | public function getDescription() { |
Index: trunk/phase3/includes/api/ApiQueryBase.php |
— | — | @@ -214,11 +214,10 @@ |
215 | 215 | |
216 | 216 | if ( $sort ) { |
217 | 217 | $order = $field . ( $isDirNewer ? '' : ' DESC' ); |
218 | | - if ( !isset( $this->options['ORDER BY'] ) ) { |
219 | | - $this->addOption( 'ORDER BY', $order ); |
220 | | - } else { |
221 | | - $this->addOption( 'ORDER BY', $this->options['ORDER BY'] . ', ' . $order ); |
222 | | - } |
| 218 | + // Append ORDER BY |
| 219 | + $optionOrderBy = isset( $this->options['ORDER BY'] ) ? (array)$this->options['ORDER BY'] : array(); |
| 220 | + $optionOrderBy[] = $order; |
| 221 | + $this->addOption( 'ORDER BY', $optionOrderBy ); |
223 | 222 | } |
224 | 223 | } |
225 | 224 | |
Index: trunk/phase3/includes/api/ApiQueryIWLinks.php |
— | — | @@ -79,20 +79,27 @@ |
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
| 83 | + $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' ); |
83 | 84 | if ( isset( $params['prefix'] ) ) { |
84 | 85 | $this->addWhereFld( 'iwl_prefix', $params['prefix'] ); |
85 | 86 | if ( isset( $params['title'] ) ) { |
86 | 87 | $this->addWhereFld( 'iwl_title', $params['title'] ); |
87 | | - $this->addOption( 'ORDER BY', 'iwl_from' ); |
| 88 | + $this->addOption( 'ORDER BY', 'iwl_from' . $dir ); |
88 | 89 | } else { |
89 | | - $this->addOption( 'ORDER BY', 'iwl_title, iwl_from' ); |
| 90 | + $this->addOption( 'ORDER BY', array( |
| 91 | + 'iwl_title' . $dir, |
| 92 | + 'iwl_from' . $dir |
| 93 | + )); |
90 | 94 | } |
91 | 95 | } else { |
92 | 96 | // Don't order by iwl_from if it's constant in the WHERE clause |
93 | 97 | if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) { |
94 | | - $this->addOption( 'ORDER BY', 'iwl_prefix' ); |
| 98 | + $this->addOption( 'ORDER BY', 'iwl_prefix' . $dir ); |
95 | 99 | } else { |
96 | | - $this->addOption( 'ORDER BY', 'iwl_from, iwl_prefix' ); |
| 100 | + $this->addOption( 'ORDER BY', array ( |
| 101 | + 'iwl_from' . $dir, |
| 102 | + 'iwl_prefix' . $dir |
| 103 | + )); |
97 | 104 | } |
98 | 105 | } |
99 | 106 | |
— | — | @@ -142,6 +149,13 @@ |
143 | 150 | 'continue' => null, |
144 | 151 | 'prefix' => null, |
145 | 152 | 'title' => null, |
| 153 | + 'dir' => array( |
| 154 | + ApiBase::PARAM_DFLT => 'ascending', |
| 155 | + ApiBase::PARAM_TYPE => array( |
| 156 | + 'ascending', |
| 157 | + 'descending' |
| 158 | + ) |
| 159 | + ), |
146 | 160 | ); |
147 | 161 | } |
148 | 162 | |
— | — | @@ -152,6 +166,7 @@ |
153 | 167 | 'continue' => 'When more results are available, use this to continue', |
154 | 168 | 'prefix' => 'Prefix for the interwiki', |
155 | 169 | 'title' => "Interwiki link to search for. Must be used with {$this->getModulePrefix()}prefix", |
| 170 | + 'dir' => 'The direction in which to list', |
156 | 171 | ); |
157 | 172 | } |
158 | 173 | |
Index: trunk/phase3/includes/api/ApiQueryLangLinks.php |
— | — | @@ -74,20 +74,27 @@ |
75 | 75 | ); |
76 | 76 | } |
77 | 77 | |
| 78 | + $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' ); |
78 | 79 | if ( isset( $params['lang'] ) ) { |
79 | 80 | $this->addWhereFld( 'll_lang', $params['lang'] ); |
80 | 81 | if ( isset( $params['title'] ) ) { |
81 | 82 | $this->addWhereFld( 'll_title', $params['title'] ); |
82 | | - $this->addOption( 'ORDER BY', 'll_from' ); |
| 83 | + $this->addOption( 'ORDER BY', 'll_from' . $dir ); |
83 | 84 | } else { |
84 | | - $this->addOption( 'ORDER BY', 'll_title, ll_from' ); |
| 85 | + $this->addOption( 'ORDER BY', array( |
| 86 | + 'll_title' . $dir, |
| 87 | + 'll_from' . $dir |
| 88 | + )); |
85 | 89 | } |
86 | 90 | } else { |
87 | 91 | // Don't order by ll_from if it's constant in the WHERE clause |
88 | 92 | if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) { |
89 | | - $this->addOption( 'ORDER BY', 'll_lang' ); |
| 93 | + $this->addOption( 'ORDER BY', 'll_lang' . $dir ); |
90 | 94 | } else { |
91 | | - $this->addOption( 'ORDER BY', 'll_from, ll_lang' ); |
| 95 | + $this->addOption( 'ORDER BY', array( |
| 96 | + 'll_from' . $dir, |
| 97 | + 'll_lang' . $dir |
| 98 | + )); |
92 | 99 | } |
93 | 100 | } |
94 | 101 | |
— | — | @@ -135,6 +142,13 @@ |
136 | 143 | 'url' => false, |
137 | 144 | 'lang' => null, |
138 | 145 | 'title' => null, |
| 146 | + 'dir' => array( |
| 147 | + ApiBase::PARAM_DFLT => 'ascending', |
| 148 | + ApiBase::PARAM_TYPE => array( |
| 149 | + 'ascending', |
| 150 | + 'descending' |
| 151 | + ) |
| 152 | + ), |
139 | 153 | ); |
140 | 154 | } |
141 | 155 | |
— | — | @@ -145,6 +159,7 @@ |
146 | 160 | 'url' => 'Whether to get the full URL', |
147 | 161 | 'lang' => 'Language code', |
148 | 162 | 'title' => "Link to search for. Must be used with {$this->getModulePrefix()}lang", |
| 163 | + 'dir' => 'The direction in which to list', |
149 | 164 | ); |
150 | 165 | } |
151 | 166 | |
Index: trunk/phase3/includes/api/ApiQueryCategories.php |
— | — | @@ -127,11 +127,16 @@ |
128 | 128 | } |
129 | 129 | |
130 | 130 | $this->addOption( 'USE INDEX', array( 'categorylinks' => 'cl_from' ) ); |
| 131 | + |
| 132 | + $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' ); |
131 | 133 | // Don't order by cl_from if it's constant in the WHERE clause |
132 | 134 | if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) { |
133 | | - $this->addOption( 'ORDER BY', 'cl_to' ); |
| 135 | + $this->addOption( 'ORDER BY', 'cl_to' . $dir ); |
134 | 136 | } else { |
135 | | - $this->addOption( 'ORDER BY', "cl_from, cl_to" ); |
| 137 | + $this->addOption( 'ORDER BY', array( |
| 138 | + 'cl_from' . $dir, |
| 139 | + 'cl_to' . $dir |
| 140 | + )); |
136 | 141 | } |
137 | 142 | |
138 | 143 | $res = $this->select( __METHOD__ ); |
— | — | @@ -213,6 +218,13 @@ |
214 | 219 | 'categories' => array( |
215 | 220 | ApiBase::PARAM_ISMULTI => true, |
216 | 221 | ), |
| 222 | + 'dir' => array( |
| 223 | + ApiBase::PARAM_DFLT => 'ascending', |
| 224 | + ApiBase::PARAM_TYPE => array( |
| 225 | + 'ascending', |
| 226 | + 'descending' |
| 227 | + ) |
| 228 | + ), |
217 | 229 | ); |
218 | 230 | } |
219 | 231 | |
— | — | @@ -228,6 +240,7 @@ |
229 | 241 | 'show' => 'Which kind of categories to show', |
230 | 242 | 'continue' => 'When more results are available, use this to continue', |
231 | 243 | 'categories' => 'Only list these categories. Useful for checking whether a certain page is in a certain category', |
| 244 | + 'dir' => 'The direction in which to list', |
232 | 245 | ); |
233 | 246 | } |
234 | 247 | |
Index: trunk/phase3/includes/api/ApiQueryDuplicateFiles.php |
— | — | @@ -94,7 +94,8 @@ |
95 | 95 | ); |
96 | 96 | } |
97 | 97 | |
98 | | - $this->addOption( 'ORDER BY', 'i1.img_name' ); |
| 98 | + $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' ); |
| 99 | + $this->addOption( 'ORDER BY', 'i1.img_name' . $dir ); |
99 | 100 | $this->addOption( 'LIMIT', $params['limit'] + 1 ); |
100 | 101 | |
101 | 102 | $res = $this->select( __METHOD__ ); |
— | — | @@ -141,6 +142,13 @@ |
142 | 143 | ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
143 | 144 | ), |
144 | 145 | 'continue' => null, |
| 146 | + 'dir' => array( |
| 147 | + ApiBase::PARAM_DFLT => 'ascending', |
| 148 | + ApiBase::PARAM_TYPE => array( |
| 149 | + 'ascending', |
| 150 | + 'descending' |
| 151 | + ) |
| 152 | + ), |
145 | 153 | ); |
146 | 154 | } |
147 | 155 | |
— | — | @@ -148,6 +156,7 @@ |
149 | 157 | return array( |
150 | 158 | 'limit' => 'How many files to return', |
151 | 159 | 'continue' => 'When more results are available, use this to continue', |
| 160 | + 'dir' => 'The direction in which to list', |
152 | 161 | ); |
153 | 162 | } |
154 | 163 | |
Index: trunk/phase3/includes/api/ApiQueryImages.php |
— | — | @@ -79,11 +79,15 @@ |
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
| 83 | + $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' ); |
83 | 84 | // Don't order by il_from if it's constant in the WHERE clause |
84 | 85 | if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) { |
85 | | - $this->addOption( 'ORDER BY', 'il_to' ); |
| 86 | + $this->addOption( 'ORDER BY', 'il_to' . $dir ); |
86 | 87 | } else { |
87 | | - $this->addOption( 'ORDER BY', 'il_from, il_to' ); |
| 88 | + $this->addOption( 'ORDER BY', array( |
| 89 | + 'il_from' . $dir, |
| 90 | + 'il_to' . $dir |
| 91 | + )); |
88 | 92 | } |
89 | 93 | $this->addOption( 'LIMIT', $params['limit'] + 1 ); |
90 | 94 | |
— | — | @@ -154,7 +158,14 @@ |
155 | 159 | 'continue' => null, |
156 | 160 | 'images' => array( |
157 | 161 | ApiBase::PARAM_ISMULTI => true, |
158 | | - ) |
| 162 | + ), |
| 163 | + 'dir' => array( |
| 164 | + ApiBase::PARAM_DFLT => 'ascending', |
| 165 | + ApiBase::PARAM_TYPE => array( |
| 166 | + 'ascending', |
| 167 | + 'descending' |
| 168 | + ) |
| 169 | + ), |
159 | 170 | ); |
160 | 171 | } |
161 | 172 | |
— | — | @@ -163,6 +174,7 @@ |
164 | 175 | 'limit' => 'How many images to return', |
165 | 176 | 'continue' => 'When more results are available, use this to continue', |
166 | 177 | 'images' => 'Only list these images. Useful for checking whether a certain page has a certain Image.', |
| 178 | + 'dir' => 'The direction in which to list', |
167 | 179 | ); |
168 | 180 | } |
169 | 181 | |