Index: trunk/extensions/IndexFunction/IndexFunction_body.php |
— | — | @@ -1,5 +1,4 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /* TODO: |
5 | 4 | * Memcached |
6 | 5 | * Warnings for API edit |
— | — | @@ -7,7 +6,6 @@ |
8 | 7 | */ |
9 | 8 | |
10 | 9 | class IndexFunction { |
11 | | - |
12 | 10 | var $mTo = array(); // An array of titles for pages being indexed |
13 | 11 | var $mFrom = null; // A title object representing the index-title |
14 | 12 | |
— | — | @@ -18,20 +16,26 @@ |
19 | 17 | $ns = $indextitle->getNamespace(); |
20 | 18 | $t = $indextitle->getDBkey(); |
21 | 19 | $dbr = wfGetDB( DB_SLAVE ); |
22 | | - $res = $dbr->select( 'indexes', 'in_from', |
| 20 | + |
| 21 | + $res = $dbr->select( 'indexes', 'in_from', |
23 | 22 | array( 'in_namespace' => $ns, 'in_title' => $t ), |
24 | 23 | __METHOD__ |
25 | 24 | ); |
| 25 | + |
26 | 26 | if ( !$res->numRows() ) { |
27 | 27 | return null; |
28 | 28 | } |
| 29 | + |
29 | 30 | $ind = new IndexFunction(); |
30 | 31 | $ids = array(); |
| 32 | + |
31 | 33 | foreach ( $res as $row ) { |
32 | 34 | $ids[] = $row->in_from; |
33 | 35 | } |
| 36 | + |
34 | 37 | $ind->mTo = Title::newFromIDs( $ids ); |
35 | 38 | $ind->mFrom = $indextitle; |
| 39 | + |
36 | 40 | return $ind; |
37 | 41 | } |
38 | 42 | |
— | — | @@ -39,16 +43,20 @@ |
40 | 44 | public static function newFromTarget( Title $target ) { |
41 | 45 | $pageid = $target->getArticleID(); |
42 | 46 | $dbr = wfGetDB( DB_SLAVE ); |
43 | | - $res = $dbr->select( 'indexes', array('in_namespace', 'in_title'), |
| 47 | + |
| 48 | + $res = $dbr->select( 'indexes', array( 'in_namespace', 'in_title' ), |
44 | 49 | array( 'in_from' => $pageid ), |
45 | 50 | __METHOD__ |
46 | 51 | ); |
| 52 | + |
47 | 53 | if ( !$res->numRows() ) { |
48 | 54 | return null; |
49 | 55 | } |
| 56 | + |
50 | 57 | $ind = new IndexFunction(); |
51 | 58 | $row = $res->fetchRow(); |
52 | 59 | $ind->mFrom = Title::makeTitle( $row->in_namespace, $row->in_title ); |
| 60 | + |
53 | 61 | return $ind; |
54 | 62 | } |
55 | 63 | |
— | — | @@ -60,32 +68,42 @@ |
61 | 69 | if ( $this->mTo ) { |
62 | 70 | return $this->mTo; |
63 | 71 | } |
| 72 | + |
64 | 73 | $dbr = wfGetDB( DB_SLAVE ); |
65 | 74 | $ns = $this->mFrom->getNamespace(); |
66 | 75 | $t = $this->mFrom->getDBkey(); |
67 | | - $res = $dbr->select( 'indexes', 'in_from', |
| 76 | + |
| 77 | + $res = $dbr->select( 'indexes', 'in_from', |
68 | 78 | array( 'in_namespace' => $ns, 'in_title' => $t ), |
69 | 79 | __METHOD__ |
70 | 80 | ); |
| 81 | + |
71 | 82 | $ids = array(); |
| 83 | + |
72 | 84 | foreach ( $res as $row ) { |
73 | 85 | $ids[] = $row->in_from; |
74 | 86 | } |
| 87 | + |
75 | 88 | $this->mTo = Title::newFromIDs( $ids ); |
| 89 | + |
76 | 90 | return $this->mTo; |
77 | 91 | } |
78 | | - |
| 92 | + |
79 | 93 | // Makes an HTML <ul> list of targets |
80 | 94 | public function makeTargetList() { |
81 | 95 | global $wgUser; |
| 96 | + |
82 | 97 | $sk = $wgUser->getSkin(); |
83 | 98 | $targets = $this->getTargets(); |
84 | 99 | $list = Xml::openElement( 'ul' ); |
85 | | - foreach( $targets as $t ) { |
86 | | - $link = $sk->link( $t, $t->getPrefixedText(), array(), array(), array('known', 'noclasses') ); |
87 | | - $list.= Xml::tags( 'li', null, $link ); |
| 100 | + |
| 101 | + foreach ( $targets as $t ) { |
| 102 | + $link = $sk->link( $t, $t->getPrefixedText(), array(), array(), array( 'known', 'noclasses' ) ); |
| 103 | + $list .= Xml::tags( 'li', null, $link ); |
88 | 104 | } |
| 105 | + |
89 | 106 | $list .= Xml::CloseElement( 'ul' ); |
| 107 | + |
90 | 108 | return $list; |
91 | 109 | } |
92 | 110 | |
— | — | @@ -95,105 +113,131 @@ |
96 | 114 | if ( !$this->mTo ) { |
97 | 115 | $this->getTargets(); |
98 | 116 | } |
99 | | - return count( $this->mTo) > 1; |
| 117 | + |
| 118 | + return count( $this->mTo ) > 1; |
100 | 119 | } |
101 | 120 | } |
102 | 121 | |
103 | 122 | class IndexFunctionHooks { |
104 | | - |
105 | 123 | // Makes "Go" searches for an index title go directly to their target |
106 | 124 | static function redirectSearch( $term, &$title ) { |
107 | 125 | $title = Title::newFromText( $term ); |
108 | | - if ( is_null($title) ) { |
| 126 | + |
| 127 | + if ( is_null( $title ) ) { |
109 | 128 | return true; |
110 | 129 | } |
| 130 | + |
111 | 131 | $index = IndexFunction::newFromTitle( $title ); |
| 132 | + |
112 | 133 | if ( !$index ) { |
113 | 134 | return true; |
114 | 135 | } elseif ( $index->useSpecialPage() ) { |
115 | 136 | global $wgOut; |
| 137 | + |
116 | 138 | $title = SpecialPage::getTitleFor( 'Index', $title->getPrefixedText() ); |
117 | 139 | $wgOut->redirect( $title->getLocalURL() ); |
| 140 | + |
118 | 141 | return true; |
119 | 142 | } |
| 143 | + |
120 | 144 | $targets = $index->getTargets(); |
121 | 145 | $title = $targets[0]; |
| 146 | + |
122 | 147 | return false; |
123 | 148 | } |
124 | 149 | |
125 | 150 | // Make indexes work like redirects |
126 | | - static function doRedirect( &$title, &$request,& $ignoreRedirect, &$target, &$article ) { |
| 151 | + static function doRedirect( &$title, &$request, & $ignoreRedirect, &$target, &$article ) { |
127 | 152 | if ( $article->exists() ) { |
128 | 153 | return true; |
129 | 154 | } |
| 155 | + |
130 | 156 | $index = IndexFunction::newFromTitle( $title ); |
| 157 | + |
131 | 158 | if ( !$index ) { |
132 | 159 | return true; |
133 | | - } elseif ($index->useSpecialPage() ) { |
| 160 | + } elseif ( $index->useSpecialPage() ) { |
134 | 161 | global $wgOut; |
| 162 | + |
135 | 163 | $t = SpecialPage::getTitleFor( 'Index', $title->getPrefixedText() ); |
136 | 164 | $wgOut->redirect( $t->getLocalURL() ); |
| 165 | + |
137 | 166 | return true; |
138 | | - } |
| 167 | + } |
| 168 | + |
139 | 169 | $targets = $index->getTargets(); |
140 | 170 | $target = $targets[0]; |
141 | 171 | $article->mIsRedirect = true; |
142 | 172 | $ignoreRedirect = false; |
| 173 | + |
143 | 174 | return true; |
144 | 175 | } |
145 | | - |
| 176 | + |
146 | 177 | // Turn links to indexes into blue links |
147 | 178 | static function blueLinkIndexes( $skin, $target, $options, &$text, &$attribs, &$ret ) { |
148 | 179 | if ( in_array( 'known', $options ) ) { |
149 | 180 | return true; |
150 | 181 | } |
| 182 | + |
151 | 183 | $index = IndexFunction::newFromTitle( $target ); |
| 184 | + |
152 | 185 | if ( !$index ) { |
153 | 186 | return true; |
154 | 187 | } |
| 188 | + |
155 | 189 | $attribs['class'] = str_replace( 'new', 'mw-index', $attribs['class'] ); |
156 | 190 | $attribs['href'] = $target->getLinkUrl(); |
157 | 191 | $attribs['title'] = $target->getEscapedText(); |
| 192 | + |
158 | 193 | return true; |
159 | 194 | } |
160 | 195 | |
161 | 196 | // Register the function name |
162 | 197 | static function addIndexFunction( &$magicWords, $langCode ) { |
163 | 198 | $magicWords['index-func'] = array( 0, 'index' ); |
| 199 | + |
164 | 200 | return true; |
165 | 201 | } |
166 | | - |
| 202 | + |
167 | 203 | // Function called to render the parser function |
168 | 204 | // Output is an empty string unless there are errors |
169 | 205 | static function indexRender( &$parser ) { |
170 | | - if ( !isset($parser->mOutput->mIndexes) ) { |
| 206 | + if ( !isset( $parser->mOutput->mIndexes ) ) { |
171 | 207 | $parser->mOutput->mIndexes = array(); |
172 | | - } |
173 | | - |
| 208 | + } |
| 209 | + |
174 | 210 | static $indexCount = 0; |
175 | 211 | static $indexes = array(); |
| 212 | + |
176 | 213 | $args = func_get_args(); |
177 | 214 | unset( $args[0] ); |
| 215 | + |
178 | 216 | if ( $parser->mOptions->getIsPreview() ) { |
179 | 217 | # This is kind of hacky, but it seems that we only |
180 | 218 | # know if its a preview during parse, not when its |
181 | 219 | # done, which is when it matters for this |
182 | 220 | $parser->mOutput->setProperty( 'preview', 1 ); |
183 | 221 | } |
| 222 | + |
184 | 223 | $errors = array(); |
185 | 224 | $pageid = $parser->mTitle->getArticleID(); |
| 225 | + |
186 | 226 | foreach ( $args as $name ) { |
187 | 227 | $t = Title::newFromText( $name ); |
188 | | - if( is_null( $t ) ) { |
| 228 | + |
| 229 | + if ( is_null( $t ) ) { |
189 | 230 | $errors[] = wfMsg( 'indexfunc-badtitle', $name ); |
190 | 231 | continue; |
191 | 232 | } |
| 233 | + |
192 | 234 | $ns = $t->getNamespace(); |
193 | 235 | $dbkey = $t->getDBkey(); |
194 | 236 | $entry = array( $ns, $dbkey ); |
| 237 | + |
195 | 238 | if ( in_array( $entry, $indexes ) ) { |
196 | 239 | continue; |
197 | | - } |
| 240 | + } |
| 241 | + |
198 | 242 | if ( $t->exists() ) { |
199 | 243 | $errors[] = wfMsg( 'indexfunc-index-exists', $name ); |
200 | 244 | continue; |
— | — | @@ -201,58 +245,77 @@ |
202 | 246 | $indexCount++; |
203 | 247 | $parser->mOutput->mIndexes[$indexCount] = $entry; |
204 | 248 | } |
| 249 | + |
205 | 250 | if ( !$errors ) { |
206 | 251 | return ''; |
207 | 252 | } |
208 | | - $out = Xml::openElement( 'ul', array( 'class'=>'error' ) ); |
209 | | - foreach( $errors as $e ) { |
| 253 | + |
| 254 | + $out = Xml::openElement( 'ul', array( 'class' => 'error' ) ); |
| 255 | + |
| 256 | + foreach ( $errors as $e ) { |
210 | 257 | $out .= Xml::element( 'li', null, $e ); |
211 | 258 | } |
| 259 | + |
212 | 260 | $out .= Xml::closeElement( 'ul' ); |
| 261 | + |
213 | 262 | return $out; |
214 | 263 | } |
215 | 264 | |
216 | 265 | // Called after parse, updates the index table |
217 | 266 | static function doIndexes( $out, $parseroutput ) { |
218 | | - if ( !isset($parseroutput->mIndexes) ) { |
| 267 | + if ( !isset( $parseroutput->mIndexes ) ) { |
219 | 268 | $parseroutput->mIndexes = array(); |
220 | 269 | } |
| 270 | + |
221 | 271 | if ( $parseroutput->getProperty( 'preview' ) ) { |
222 | 272 | return true; |
223 | 273 | } |
| 274 | + |
224 | 275 | $pageid = $out->getTitle()->getArticleID(); |
225 | 276 | $dbw = wfGetDB( DB_MASTER ); |
226 | | - $res = $dbw->select( 'indexes', |
| 277 | + |
| 278 | + $res = $dbw->select( 'indexes', |
227 | 279 | array( 'in_namespace', 'in_title' ), |
228 | 280 | array( 'in_from' => $pageid ), |
229 | 281 | __METHOD__ |
230 | 282 | ); |
| 283 | + |
231 | 284 | $current = array(); |
232 | | - foreach( $res as $row ) { |
| 285 | + |
| 286 | + foreach ( $res as $row ) { |
233 | 287 | $current[] = array( $row->in_namespace, $row->in_title ); |
234 | 288 | } |
| 289 | + |
235 | 290 | $toAdd = wfArrayDiff2( $parseroutput->mIndexes, $current ); |
236 | 291 | $toRem = wfArrayDiff2( $current, $parseroutput->mIndexes ); |
| 292 | + |
237 | 293 | if ( $toAdd || $toRem ) { |
238 | 294 | $dbw->begin( __METHOD__ ); |
| 295 | + |
239 | 296 | if ( $toRem ) { |
240 | 297 | $delCond = "in_from = $pageid AND ("; |
241 | | - $parts = array(); |
| 298 | + $parts = array(); |
| 299 | + |
242 | 300 | # Looking at Database::delete, it seems to turn arrays into AND statements |
243 | 301 | # but we need to chain together groups of ANDs with ORs |
244 | 302 | foreach ( $toRem as $entry ) { |
245 | | - $parts[] = "(in_namespace = " . $entry[0] . " AND in_title = " . $dbw->addQuotes($entry[1]) . ")"; |
| 303 | + $parts[] = "(in_namespace = " . $entry[0] . " AND in_title = " . $dbw->addQuotes( $entry[1] ) . ")"; |
246 | 304 | } |
| 305 | + |
247 | 306 | $delCond .= implode( ' OR ', $parts ) . ")"; |
248 | | - $dbw->delete( 'indexes', array($delCond), __METHOD__ ); |
| 307 | + $dbw->delete( 'indexes', array( $delCond ), __METHOD__ ); |
249 | 308 | } |
| 309 | + |
250 | 310 | if ( $toAdd ) { |
251 | 311 | $ins = array(); |
| 312 | + |
252 | 313 | foreach ( $toAdd as $entry ) { |
253 | 314 | $ins[] = array( 'in_from' => $pageid, 'in_namespace' => $entry[0], 'in_title' => $entry[1] ); |
254 | 315 | } |
| 316 | + |
255 | 317 | $dbw->insert( 'indexes', $ins, __METHOD__ ); |
256 | 318 | } |
| 319 | + |
257 | 320 | $dbw->commit( __METHOD__ ); |
258 | 321 | } |
259 | 322 | return true; |
— | — | @@ -261,7 +324,8 @@ |
262 | 325 | // When deleting a page, delete all rows from the index table that point to it |
263 | 326 | static function onDelete( &$article, &$user, $reason, $id ) { |
264 | 327 | $dbw = wfGetDB( DB_MASTER ); |
265 | | - $dbw->delete( 'indexes', array( 'in_from'=>$id ), __METHOD__ ); |
| 328 | + $dbw->delete( 'indexes', array( 'in_from' => $id ), __METHOD__ ); |
| 329 | + |
266 | 330 | return true; |
267 | 331 | } |
268 | 332 | |
— | — | @@ -271,10 +335,12 @@ |
272 | 336 | $ns = $t->getNamespace(); |
273 | 337 | $dbkey = $t->getDBkey(); |
274 | 338 | $dbw = wfGetDB( DB_MASTER ); |
275 | | - $dbw->delete( 'indexes', |
276 | | - array( 'in_namespace'=>$ns, 'in_title'=>$dbkey ), |
277 | | - __METHOD__ |
| 339 | + |
| 340 | + $dbw->delete( 'indexes', |
| 341 | + array( 'in_namespace' => $ns, 'in_title' => $dbkey ), |
| 342 | + __METHOD__ |
278 | 343 | ); |
| 344 | + |
279 | 345 | return true; |
280 | 346 | } |
281 | 347 | |
— | — | @@ -282,37 +348,44 @@ |
283 | 349 | static function editWarning( $editpage ) { |
284 | 350 | $t = $editpage->mTitle; |
285 | 351 | $index = IndexFunction::newFromTitle( $t ); |
286 | | - if (!$index) { |
| 352 | + |
| 353 | + if ( !$index ) { |
287 | 354 | return true; |
288 | 355 | } |
289 | | - |
| 356 | + |
290 | 357 | $list = $index->makeTargetList(); |
291 | 358 | $c = count( $index->getTargets() ); |
292 | 359 | $warn = wfMsgExt( 'indexfunc-editwarning', array( 'parsemag' ), $list, $c ); |
293 | 360 | $editpage->editFormTextTop .= "<span class='error'>$warn</span>"; |
| 361 | + |
294 | 362 | return true; |
295 | 363 | } |
296 | 364 | |
297 | 365 | static function afterMove( &$form, &$orig, &$new ) { |
298 | 366 | global $wgOut; |
| 367 | + |
299 | 368 | $index = IndexFunction::newFromTitle( $new ); |
| 369 | + |
300 | 370 | if ( !$index ) { |
301 | 371 | return true; |
302 | 372 | } |
| 373 | + |
303 | 374 | $c = count( $index->getTargets() ); |
304 | 375 | $list = $index->makeTargetList(); |
305 | 376 | $newns = $new->getNamespace(); |
306 | 377 | $newdbk = $new->getDBkey(); |
307 | 378 | $dbw = wfGetDB( DB_MASTER ); |
308 | | - $dbw->delete( 'indexes', |
309 | | - array( 'in_namespace'=>$newns, 'in_title'=>$newdbk ), |
310 | | - __METHOD__ |
| 379 | + |
| 380 | + $dbw->delete( 'indexes', |
| 381 | + array( 'in_namespace' => $newns, 'in_title' => $newdbk ), |
| 382 | + __METHOD__ |
311 | 383 | ); |
| 384 | + |
312 | 385 | $msg = wfMsgExt( 'indexfunc-movewarn', array( 'parsemag' ), $new->getPrefixedText(), $list, $c ); |
313 | 386 | $msg = "<span class='error'>$msg</span>"; |
| 387 | + |
314 | 388 | $wgOut->addHTML( $msg ); |
| 389 | + |
315 | 390 | return true; |
316 | 391 | } |
317 | | - |
318 | 392 | } |
319 | | - |
Index: trunk/extensions/IndexFunction/IndexFunction.i18n.php |
— | — | @@ -32,9 +32,9 @@ |
33 | 33 | 'index-emptylist' => 'There are no pages associated with "$1"', |
34 | 34 | 'index-expand-detail' => 'Show pages indexed under this title', |
35 | 35 | 'index-hide-detail' => 'Hide the list of pages', |
36 | | - 'index-no-results' => 'The search returned no results', |
37 | | - 'index-search-explain' => 'This page uses a prefix search. |
38 | | - |
| 36 | + 'index-no-results' => 'The search returned no results', |
| 37 | + 'index-search-explain' => 'This page uses a prefix search. |
| 38 | + |
39 | 39 | Type the first few characters and press the submit button to search for page titles and index entries that start with the search string', |
40 | 40 | 'index-details-explain' => 'Entries with arrows are index entries. |
41 | 41 | Click the arrow to show all pages indexed under that title.', |
— | — | @@ -213,7 +213,7 @@ |
214 | 214 | 'index-search-explain' => 'Ober a ra ar bajenn-mañ gant ur rakger klask. |
215 | 215 | |
216 | 216 | Merkit an nebeud arouezennoù kentañ ha pouezit war ar bouton klask evit kavout titloù ar pajennoù a grog gant an neudennad klask-se', |
217 | | - 'index-details-explain' => 'Monedoù meneger eo ar monedoù gant biroù. |
| 217 | + 'index-details-explain' => 'Monedoù meneger eo ar monedoù gant biroù. |
218 | 218 | Klikit war ar bir evit gwelet an holl bajennoù menegeret dindan an titl-se.', |
219 | 219 | ); |
220 | 220 | |
— | — | @@ -439,13 +439,13 @@ |
440 | 440 | $messages['fi'] = array( |
441 | 441 | 'indexfunc-desc' => 'Jäsenninfunktio automaattisten ohjauksien ja täsmennyssivujen luomiseen.', |
442 | 442 | 'indexfunc-badtitle' => 'Epäkelpo otsikko: ”$1”', |
443 | | - 'indexfunc-editwarning' => 'Varoitus: |
| 443 | + 'indexfunc-editwarning' => 'Varoitus: |
444 | 444 | Tämä otsikko on indeksiotsikko {{PLURAL:$2|seuraavalle sivulle|seuraaville sivuille}}: |
445 | 445 | $1 |
446 | 446 | Tarkista ettei sivua, jota olet luomassa ole jo olemassa toisella otsikolla. |
447 | 447 | Jos luot tämän sivun, poista otsikko <nowiki>{{#index:}}</nowiki>-tagista {{PLURAL:$2|yllä olevalla sivulla|yllä olevilla sivuilla}}.', |
448 | 448 | 'indexfunc-index-exists' => 'Sivu ”$1” on jo olemassa', |
449 | | - 'indexfunc-movewarn' => 'Virhe: |
| 449 | + 'indexfunc-movewarn' => 'Virhe: |
450 | 450 | ”$1” on indeksiotsikko {{PLURAL:$3|seuraavalle sivulle|seuraaville sivuille}}: |
451 | 451 | $2 |
452 | 452 | Poista ”$1” <nowiki>{{#index:}}</nowiki>-tagista {{PLURAL:$3|yllä olevilla sivuilla|yllä olevalla sivulla}}.', |
— | — | @@ -461,7 +461,7 @@ |
462 | 462 | 'index-search-explain' => 'Tämä sivu käyttää etuliitehakua. |
463 | 463 | |
464 | 464 | Kirjoita pari ensimmäistä kirjainta ja napsauta lähetä-nappia hakeaksesi sivujen otsikoista ja indeksimerkinnöistä, jotka alkavat hakusanalla.', |
465 | | - 'index-details-explain' => 'Nuolin varustetut merkinnät ovat indeksimerkintöjä. |
| 465 | + 'index-details-explain' => 'Nuolin varustetut merkinnät ovat indeksimerkintöjä. |
466 | 466 | Napsauta nuolta näyttääksesi kaikki sivut, jotka on indeksoitu otsikon alle.', |
467 | 467 | ); |
468 | 468 | |
— | — | @@ -538,7 +538,7 @@ |
539 | 539 | 'index-expand-detail' => 'Mostrar as páxinas indexadas baixo este título', |
540 | 540 | 'index-hide-detail' => 'Agochar a lista de páxinas', |
541 | 541 | 'index-no-results' => 'A procura non devolveu resultados', |
542 | | - 'index-search-explain' => 'Esta páxina usa unha procura por prefixos. |
| 542 | + 'index-search-explain' => 'Esta páxina usa unha procura por prefixos. |
543 | 543 | |
544 | 544 | Insira os primeiros caracteres e prema o botón "Enviar" para buscar títulos de páxinas e entradas de índice que comezan coa secuencia de procura', |
545 | 545 | 'index-details-explain' => 'As entradas con frechas son entradas de índice. |
— | — | @@ -576,7 +576,7 @@ |
577 | 577 | 'index-expand-detail' => 'Syte aazeige, wu unter däm Titel ufglischtet sin', |
578 | 578 | 'index-hide-detail' => 'D Sytelischt verstecke', |
579 | 579 | 'index-no-results' => 'D Suechi het kei Ergebnis brocht', |
580 | | - 'index-search-explain' => 'Die Syte verwändet e Präfixsuechi. |
| 580 | + 'index-search-explain' => 'Die Syte verwändet e Präfixsuechi. |
581 | 581 | |
582 | 582 | Tipp di erschte paar Buehcstabe yy un druck dr „Abschicke“-Chnopf go Sytetitel un Verzeichnisyytreg suech, wu mit däre Zeichechette aafange', |
583 | 583 | 'index-details-explain' => 'Yytreg mit Bege sin Verzeichnisyytreg. |
— | — | @@ -720,12 +720,12 @@ |
721 | 721 | 'indexfunc-badtitle' => 'Judul tidak sah: "$1"', |
722 | 722 | 'indexfunc-editwarning' => 'Peringatan: |
723 | 723 | Judul ini adalah judul indeks {{PLURAL:$2|halaman|halaman}} berikut : |
724 | | -$1 |
725 | | -Pastikan halaman yang akan Anda buat tidak ada pada judul yang berbeda. |
| 724 | +$1 |
| 725 | +Pastikan halaman yang akan Anda buat tidak ada pada judul yang berbeda. |
726 | 726 | Jika Anda membuat halaman ini, hapus halaman ini dari <nowiki>{{#index:}}</nowiki> di atas {{PLURAL:$2|halaman|halaman}}.', |
727 | 727 | 'indexfunc-index-exists' => 'Halaman "$1" sudah ada', |
728 | 728 | 'indexfunc-movewarn' => 'Peringatan: |
729 | | -"$1" adalah judul indeks {{PLURAL:$3|halaman|halaman}} berikut : |
| 729 | +"$1" adalah judul indeks {{PLURAL:$3|halaman|halaman}} berikut : |
730 | 730 | $2 |
731 | 731 | Hapus "$1" dari <nowiki>{{#index:}}</nowiki> di atas {{PLURAL:$3|halaman|halaman}}.', |
732 | 732 | 'index' => 'Indeks', |
— | — | @@ -1056,7 +1056,7 @@ |
1057 | 1057 | 'indexfunc-editwarning' => 'Uwaga. |
1058 | 1058 | Ten tytuł jest tytułem indeksu {{PLURAL:$2|strony|następujących stron:}} |
1059 | 1059 | $1 |
1060 | | -Upewnij się, że strona, którą chcesz utworzyć nie istnieje pod inną nazwą. |
| 1060 | +Upewnij się, że strona, którą chcesz utworzyć nie istnieje pod inną nazwą. |
1061 | 1061 | Jeśli utworzysz tę stronę, usuń tytułu z <nowiki>{{#index:}}</nowiki> dla {{PLURAL:$2|powyższej strony|powyższych stron}}.', |
1062 | 1062 | 'indexfunc-index-exists' => 'Strona „$1” już istnieje', |
1063 | 1063 | 'indexfunc-movewarn' => 'Uwaga. |
Index: trunk/extensions/IndexFunction/IndexFunction.php |
— | — | @@ -3,20 +3,20 @@ |
4 | 4 | $wgExtensionCredits['other'][] = array( |
5 | 5 | 'path' => __FILE__, |
6 | 6 | 'name' => 'IndexFunction', |
7 | | - 'author' =>'Alex Zaddach', |
8 | | - 'url' => 'http://www.mediawiki.org/wiki/Extension:IndexFunction', |
| 7 | + 'author' => 'Alex Zaddach', |
| 8 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:IndexFunction', |
9 | 9 | 'descriptionmsg' => 'indexfunc-desc', |
10 | 10 | ); |
11 | 11 | |
12 | | -$dir = dirname(__FILE__) . '/'; |
| 12 | +$dir = dirname( __FILE__ ) . '/'; |
13 | 13 | |
14 | | -# Register function |
| 14 | +# Register function |
15 | 15 | $wgHooks['ParserFirstCallInit'][] = 'efIndexSetup'; |
16 | 16 | $wgHooks['LanguageGetMagic'][] = 'IndexFunctionHooks::addIndexFunction'; |
17 | 17 | # Add to database |
18 | | -$wgHooks['OutputPageParserOutput'][] = 'IndexFunctionHooks::doIndexes'; |
| 18 | +$wgHooks['OutputPageParserOutput'][] = 'IndexFunctionHooks::doIndexes'; |
19 | 19 | # Make links to indexes blue |
20 | | -$wgHooks['LinkEnd'][] = 'IndexFunctionHooks::blueLinkIndexes'; |
| 20 | +$wgHooks['LinkEnd'][] = 'IndexFunctionHooks::blueLinkIndexes'; |
21 | 21 | # Make links to indexes redirect |
22 | 22 | $wgHooks['InitializeArticleMaybeRedirect'][] = 'IndexFunctionHooks::doRedirect'; |
23 | 23 | # Make "go" searches for indexes redirect |
— | — | @@ -53,9 +53,10 @@ |
54 | 54 | * Can be 1 of 2 options: |
55 | 55 | * 'extract' (default) - Show an extract from the start of the article |
56 | 56 | * 'categories' - Show a comma-separated list of categories the article is in |
57 | | -*/ |
| 57 | + */ |
58 | 58 | $wgSpecialIndexContext = 'extract'; |
59 | 59 | |
| 60 | +// @todo FIXME: put these methods in a separate class and file. |
60 | 61 | function efIndexSetup( &$parser ) { |
61 | 62 | $parser->setFunctionHook( 'index-func', array( 'IndexFunctionHooks', 'indexRender' ) ); |
62 | 63 | return true; |
— | — | @@ -69,9 +70,12 @@ |
70 | 71 | $updater->addExtensionUpdate( array( 'addTable', 'indexes', |
71 | 72 | dirname( __FILE__ ) . '/indexes.sql', true ) ); |
72 | 73 | } |
| 74 | + |
73 | 75 | return true; |
74 | 76 | } |
| 77 | + |
75 | 78 | function efParserTestTables( &$tables ) { |
76 | 79 | $tables[] = 'indexes'; |
| 80 | + |
77 | 81 | return true; |
78 | 82 | } |
Index: trunk/extensions/IndexFunction/specialindex.js |
— | — | @@ -13,12 +13,12 @@ |
14 | 14 | '}'+ |
15 | 15 | '#use-js-note {'+ |
16 | 16 | ' display: block !important;'+ |
17 | | - '}' |
| 17 | + '}' |
18 | 18 | ); |
19 | 19 | |
20 | 20 | /* |
21 | 21 | * Switch details between hidden/shown |
22 | | -*/ |
| 22 | + */ |
23 | 23 | function toggleVisibility(idNumber) { |
24 | 24 | var openarrow = document.getElementById("mw-index-open-"+idNumber); |
25 | 25 | var closearrow = document.getElementById("mw-index-close-"+idNumber); |
Index: trunk/extensions/IndexFunction/IndexAbstracts.php |
— | — | @@ -3,8 +3,7 @@ |
4 | 4 | /* |
5 | 5 | * Class to extract the first bit of text from an article |
6 | 6 | * Adapted from the OpenSearchXML extension, by Brion Vibber |
7 | | -*/ |
8 | | - |
| 7 | + */ |
9 | 8 | class IndexAbstracts { |
10 | 9 | /** |
11 | 10 | * Strip markup to show plaintext |
— | — | @@ -14,14 +13,14 @@ |
15 | 14 | */ |
16 | 15 | function _stripMarkup( $text ) { |
17 | 16 | global $wgContLang; |
18 | | - |
| 17 | + |
19 | 18 | $text = substr( $text, 0, 4096 ); // don't bother with long text... |
20 | | - |
| 19 | + |
21 | 20 | $text = str_replace( "'''", "", $text ); |
22 | 21 | $text = str_replace( "''", "", $text ); |
23 | | - |
| 22 | + |
24 | 23 | $text = preg_replace( '#__[a-z0-9_]+__#i', '', $text ); // magic words |
25 | | - |
| 24 | + |
26 | 25 | $cleanChar = "[^|\[\]]"; |
27 | 26 | $subLink = "\[\[$cleanChar*(?:\|$cleanChar*)*\]\]"; |
28 | 27 | $pipeContents = "(?:$cleanChar|$subLink)*"; |
— | — | @@ -32,7 +31,7 @@ |
33 | 32 | (?:\|$pipeContents)* |
34 | 33 | \]\] |
35 | 34 | #six", array( $this, '_stripLink' ), $text ); |
36 | | - |
| 35 | + |
37 | 36 | $protocols = wfUrlProtocols(); |
38 | 37 | $text = preg_replace( '#\\[(?:$protocols).*? (.*?)\\]#s', '$1', $text ); // URL links |
39 | 38 | $text = preg_replace( '#</?[a-z0-9]+.*?>#s', '', $text ); // HTML-style tags |
— | — | @@ -40,21 +39,24 @@ |
41 | 40 | |
42 | 41 | $text = preg_replace( '#^:.*$#m', '', $text ); // indented lines near start are usually disambigs or notices |
43 | 42 | $text = Sanitizer::decodeCharReferences( $text ); |
| 43 | + |
44 | 44 | return trim( $text ); |
45 | 45 | } |
46 | | - |
| 46 | + |
47 | 47 | function _stripLink( $matches ) { |
48 | 48 | $target = trim( $matches[1] ); |
49 | | - if( isset( $matches[2] ) ) { |
| 49 | + |
| 50 | + if ( isset( $matches[2] ) ) { |
50 | 51 | $text = trim( $matches[2] ); |
51 | 52 | } else { |
52 | 53 | $text = $target; |
53 | 54 | } |
54 | | - |
| 55 | + |
55 | 56 | $title = Title::newFromText( $target ); |
56 | | - if( $title ) { |
| 57 | + |
| 58 | + if ( $title ) { |
57 | 59 | $ns = $title->getNamespace(); |
58 | | - if( $title->getInterwiki() || $ns == NS_IMAGE || $ns == NS_CATEGORY ) { |
| 60 | + if ( $title->getInterwiki() || $ns == NS_IMAGE || $ns == NS_CATEGORY ) { |
59 | 61 | return ""; |
60 | 62 | } else { |
61 | 63 | return $text; |
— | — | @@ -63,7 +65,7 @@ |
64 | 66 | return $matches[0]; |
65 | 67 | } |
66 | 68 | } |
67 | | - |
| 69 | + |
68 | 70 | /** |
69 | 71 | * Extract the first two sentences, if detectable, from the text. |
70 | 72 | * @param string $text |
— | — | @@ -77,63 +79,69 @@ |
78 | 80 | '.', '!', '?', // double-width roman forms |
79 | 81 | '。', // half-width ideographic full stop |
80 | 82 | ); |
81 | | - |
| 83 | + |
82 | 84 | $endgroup = implode( '|', $endchars ); |
83 | 85 | $end = "(?:$endgroup)"; |
84 | 86 | $sentence = ".*?$end+"; |
85 | 87 | $firstone = "/^($sentence)/u"; |
86 | | - if( preg_match( $firstone, $text, $matches ) ) { |
| 88 | + |
| 89 | + if ( preg_match( $firstone, $text, $matches ) ) { |
87 | 90 | return $matches[1]; |
88 | 91 | } else { |
89 | 92 | // Just return the first line |
90 | 93 | $lines = explode( "\n", $text ); |
| 94 | + |
91 | 95 | return trim( $lines[0] ); |
92 | 96 | } |
93 | 97 | } |
94 | | - |
95 | | - public function getExtract( $title, $chars=50 ) { |
| 98 | + |
| 99 | + public function getExtract( $title, $chars = 50 ) { |
96 | 100 | $rev = Revision::newFromTitle( $title ); |
97 | | - if( $rev ) { |
| 101 | + |
| 102 | + if ( $rev ) { |
98 | 103 | $text = substr( $rev->getText(), 0, 16384 ); |
99 | | - |
| 104 | + |
100 | 105 | // Ok, first note this is a TERRIBLE HACK. :D |
101 | 106 | // |
102 | 107 | // First, we use the system preprocessor to break down the text |
103 | 108 | // into text, templates, extensions, and comments: |
104 | 109 | global $wgParser; |
| 110 | + |
105 | 111 | $wgParser->mOptions = new ParserOptions(); |
106 | 112 | $wgParser->clearState(); |
| 113 | + |
107 | 114 | $frame = $wgParser->getPreprocessor()->newFrame(); |
108 | 115 | $dom = $wgParser->preprocessToDom( $text ); |
109 | | - |
| 116 | + |
110 | 117 | $imageArgs = array( |
111 | 118 | 'image', |
112 | 119 | 'image_skyline', |
113 | 120 | 'img', |
114 | 121 | 'Img', |
115 | 122 | ); |
116 | | - |
| 123 | + |
117 | 124 | // Now, we strip out everything that's not text. |
118 | 125 | // This works with both DOM and Hash parsers, but feels fragile. |
119 | 126 | $node = $dom->getFirstChild(); |
120 | 127 | $out = ''; |
121 | | - while( $node ) { |
122 | | - if( $node->getName() == '#text' ) { |
| 128 | + |
| 129 | + while ( $node ) { |
| 130 | + if ( $node->getName() == '#text' ) { |
123 | 131 | $out .= $frame->expand( $node, PPFrame::RECOVER_ORIG ); |
124 | 132 | } |
125 | 133 | $node = $node->getNextSibling(); |
126 | 134 | } |
127 | | - |
| 135 | + |
128 | 136 | // The remaining text may still contain wiki and HTML markup. |
129 | 137 | // We'll use our shitty hand parser to strip most of those from |
130 | 138 | // the beginning of the text. |
131 | 139 | $stripped = $this->_stripMarkup( $out ); |
132 | | - |
| 140 | + |
133 | 141 | // And now, we'll grab just the first sentence as text, and |
134 | 142 | // also try to rip out a badge image. |
135 | 143 | return $this->_extractStart( $stripped ); |
136 | 144 | } |
| 145 | + |
137 | 146 | return ''; |
138 | 147 | } |
139 | | - |
140 | 148 | } |
Index: trunk/extensions/IndexFunction/indexes.sql |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | CREATE TABLE /*$wgDBprefix*/indexes ( |
3 | 3 | -- The pageid of the page containing the parser function |
4 | 4 | in_from int unsigned NOT NULL default 0, |
5 | | - |
| 5 | + |
6 | 6 | -- The NS/title that should redirect to the page |
7 | 7 | in_namespace int NOT NULL default 0, |
8 | 8 | in_title varchar(255) binary NOT NULL default '', |
Index: trunk/extensions/IndexFunction/SpecialIndex.php |
— | — | @@ -1,19 +1,19 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | class SpecialIndexPager extends AlphabeticPager { |
5 | | - |
6 | 5 | public $mSearchTitle; |
7 | 6 | private $mJSid = 0; |
8 | 7 | |
9 | 8 | function __construct( $search ) { |
10 | 9 | $this->mSearchTitle = $search; |
11 | | - parent::__construct(); |
| 10 | + parent::__construct(); |
12 | 11 | // This can potentially be a lot of data, set a lower max limit |
13 | 12 | $this->mLimit = $this->mLimit > 1000 ? 1000 : $this->mLimit; |
14 | 13 | } |
15 | 14 | |
16 | 15 | function formatRow( $row ) { |
17 | 16 | $sk = $this->getSkin(); |
| 17 | + |
18 | 18 | if ( $row->type == 'page' ) { |
19 | 19 | $title = Title::makeTitle( $row->ns, $row->title ); |
20 | 20 | $ret = Xml::openElement( 'tr' ); |
— | — | @@ -23,52 +23,62 @@ |
24 | 24 | $ret .= Xml::tags( 'td', null, $link ); |
25 | 25 | $ret .= Xml::tags( 'td', null, ' ' ); |
26 | 26 | $ret .= Xml::closeElement( 'tr' ); |
| 27 | + |
27 | 28 | return $ret; |
28 | 29 | } else { |
29 | 30 | $ret = Xml::openElement( 'tr' ); |
30 | 31 | $targettitle = Title::makeTitle( $row->ns, $row->title ); |
31 | 32 | $title = SpecialPage::getTitleFor( 'Index', $row->title ); |
32 | | - $link = $sk->link( $title, $targettitle->getPrefixedText(), array( 'class'=>'mw-index' ), array(), array( 'known', 'noclasses' ) ); |
33 | | - |
| 33 | + $link = $sk->link( $title, $targettitle->getPrefixedText(), array( 'class' => 'mw-index' ), array(), array( 'known', 'noclasses' ) ); |
| 34 | + |
34 | 35 | $jsid = $this->mJSid; |
35 | 36 | $expandTitle = wfMsgHtml( 'index-expand-detail' ); |
36 | 37 | $closeTitle = wfMsgHtml( 'index-hide-detail' ); |
37 | 38 | $toggleLink = "onclick='toggleVisibility($jsid); return false'"; |
38 | 39 | $tl = "<span id='mw-index-open-$jsid' class='mw-index-expanded' style='visibility:hidden' ><a href='#' $toggleLink title='$expandTitle'>" . $this->sideArrow() . "</a></span>"; |
39 | 40 | $tl .= "<span id='mw-index-close-$jsid' class='mw-index-hidden' style='display:none'><a href='#' $toggleLink title='$closeTitle'>" . $this->downArrow() . "</a></span>"; |
40 | | - |
| 41 | + |
41 | 42 | $ret .= Xml::tags( 'td', array( 'style' => 'vertical-align:top' ), $tl . ' ' ); |
42 | 43 | $ret .= Xml::tags( 'td', array( 'style' => 'vertical-align:top' ), $link ); |
43 | 44 | $ret .= Xml::openElement( 'td' ); |
44 | | - $ret .= Xml::openElement( 'ul', |
45 | | - array( 'style' => 'margin-top:1em', 'class'=>'mw-index-hidden', 'id'=>"mw-index-inner-$jsid" ) |
46 | | - ); |
| 45 | + $ret .= Xml::openElement( 'ul', |
| 46 | + array( 'style' => 'margin-top:1em', 'class' => 'mw-index-hidden', 'id' => "mw-index-inner-$jsid" ) |
| 47 | + ); |
| 48 | + |
47 | 49 | $pages = explode( '|', $row->extra ); |
48 | | - foreach( $pages as $page ) { |
| 50 | + |
| 51 | + foreach ( $pages as $page ) { |
49 | 52 | $bits = explode( ':', $page, 2 ); |
50 | 53 | $t = Title::makeTitle( $bits[0], $bits[1] ); |
51 | 54 | $ln = $sk->link( $t, null, array(), array(), array( 'known', 'noclasses' ) ); |
52 | | - $ret .= Xml::tags( 'li', null, $ln ); |
| 55 | + $ret .= Xml::tags( 'li', null, $ln ); |
53 | 56 | } |
| 57 | + |
54 | 58 | $ret .= Xml::closeElement( 'ul' ); |
55 | 59 | $ret .= Xml::closeElement( 'td' ); |
56 | 60 | $ret .= Xml::closeElement( 'tr' ); |
| 61 | + |
57 | 62 | $this->mJSid++; |
58 | | - return $ret; |
| 63 | + |
| 64 | + return $ret; |
59 | 65 | } |
60 | 66 | } |
61 | | - |
62 | | - protected function arrow( $dir, $alt='', $title='' ) { |
| 67 | + |
| 68 | + protected function arrow( $dir, $alt = '', $title = '' ) { |
63 | 69 | global $wgStylePath; |
| 70 | + |
64 | 71 | $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' ); |
65 | 72 | $encAlt = htmlspecialchars( $alt ); |
66 | 73 | $encTitle = htmlspecialchars( $title ); |
| 74 | + |
67 | 75 | return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />"; |
68 | 76 | } |
69 | 77 | |
70 | 78 | protected function sideArrow() { |
71 | 79 | global $wgContLang; |
| 80 | + |
72 | 81 | $dir = $wgContLang->isRTL() ? 'l' : 'r'; |
| 82 | + |
73 | 83 | return $this->arrow( $dir, '+', wfMsg( 'index-expand-detail' ) ); |
74 | 84 | } |
75 | 85 | |
— | — | @@ -80,250 +90,277 @@ |
81 | 91 | return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space |
82 | 92 | } |
83 | 93 | |
84 | | - |
85 | | - |
86 | 94 | // Since we're overriding reallyDoQuery, we don't really need this |
87 | 95 | // its easier to just do it all in one function |
88 | 96 | function getQueryInfo() { } |
89 | | - |
| 97 | + |
90 | 98 | function getIndexField() { |
91 | | - return 'title'; |
| 99 | + return 'title'; |
92 | 100 | } |
93 | | - |
| 101 | + |
94 | 102 | function getEmptyBody() { |
95 | | - return "<tr><td class='errorbox'>" . wfMsgHtml( 'index-no-results' ) ."</td></tr>"; |
| 103 | + return "<tr><td class='errorbox'>" . wfMsgHtml( 'index-no-results' ) . "</td></tr>"; |
96 | 104 | } |
97 | | - |
| 105 | + |
98 | 106 | // Need to override reallyDoQuery() to do the UNION |
99 | | - function reallyDoQuery( $offset, $limit, $descending ) { |
| 107 | + function reallyDoQuery( $offset, $limit, $descending ) { |
100 | 108 | $limit = ' LIMIT ' . intval( $limit ); |
101 | | - $order = " ORDER BY {$this->mIndexField}"; |
| 109 | + $order = " ORDER BY {$this->mIndexField}"; |
| 110 | + |
102 | 111 | if ( $descending ) { |
103 | 112 | $operator = '>'; |
104 | 113 | } else { |
105 | 114 | $order .= ' DESC'; |
106 | 115 | $operator = '<'; |
107 | | - } |
108 | | - |
| 116 | + } |
| 117 | + |
109 | 118 | $pageconds = array(); |
110 | 119 | $indexconds = array(); |
| 120 | + |
111 | 121 | if ( $offset != '' ) { |
112 | 122 | $pageconds[] = 'page_title' . $operator . $this->mDb->addQuotes( $offset ); |
113 | 123 | $indexconds[] = 'in_title' . $operator . $this->mDb->addQuotes( $offset ); |
114 | | - } |
| 124 | + } |
| 125 | + |
115 | 126 | $ns = $this->mSearchTitle->getNamespace(); |
116 | 127 | |
117 | 128 | $like = $this->mDb->buildLike( $this->mSearchTitle->getDBkey(), $this->mDb->anyString() ); |
118 | | - |
| 129 | + |
119 | 130 | $pageconds[] = "page_namespace = $ns"; |
120 | 131 | $pageconds[] = "page_title " . $like; |
121 | 132 | $indexconds[] = "in_namespace = $ns"; |
122 | 133 | $indexconds[] = "in_title " . $like; |
123 | | - |
124 | | - |
125 | | - $pagequery = $this->mDb->selectSQLText( 'page', |
| 134 | + |
| 135 | + $pagequery = $this->mDb->selectSQLText( 'page', |
126 | 136 | "page_title AS title, page_namespace AS ns, 'page' AS type, NULL AS extra", |
127 | 137 | $pageconds, |
128 | 138 | '' |
129 | 139 | ); |
130 | | - $indexquery = $this->mDb->selectSQLText( array('indexes', 'page'), |
131 | | - "in_title AS title, in_namespace AS ns, 'index' AS type, |
| 140 | + |
| 141 | + $indexquery = $this->mDb->selectSQLText( array( 'indexes', 'page' ), |
| 142 | + "in_title AS title, in_namespace AS ns, 'index' AS type, |
132 | 143 | GROUP_CONCAT(page_namespace,':',page_title SEPARATOR '|') AS extra", |
133 | 144 | $indexconds, |
134 | 145 | '', |
135 | 146 | array( 'GROUP BY' => 'in_namespace, in_title' ), |
136 | | - array( 'page' => array('JOIN','page_id=in_from') ) |
| 147 | + array( 'page' => array( 'JOIN', 'page_id=in_from' ) ) |
137 | 148 | ); |
138 | | - |
| 149 | + |
139 | 150 | $union = $this->mDb->unionQueries( array( $pagequery, $indexquery ), false ); |
140 | | - $union .= $order . $limit; |
| 151 | + $union .= $order . $limit; |
141 | 152 | |
142 | 153 | $res = $this->mDb->query( $union, __METHOD__ ); |
143 | 154 | return new ResultWrapper( $this->mDb, $res ); |
144 | 155 | } |
145 | | - |
146 | 156 | } |
147 | 157 | |
148 | 158 | class SpecialIndex extends SpecialPage { |
149 | 159 | function __construct() { |
150 | | - |
151 | 160 | parent::__construct( 'Index' ); |
152 | 161 | } |
153 | | - |
154 | | - function execute( $par ) { |
155 | | - |
| 162 | + |
| 163 | + function execute( $par ) { |
| 164 | + |
156 | 165 | $this->setHeaders(); |
157 | | - if ($par) { |
| 166 | + if ( $par ) { |
158 | 167 | $t1 = Title::newFromText( $par ); |
159 | 168 | $this->showDabPage( $t1 ); |
160 | | - } else { |
161 | | - $this->showSearchForm(); |
| 169 | + } else { |
| 170 | + $this->showSearchForm(); |
162 | 171 | } |
| 172 | + } |
163 | 173 | |
164 | | - } |
165 | | - |
166 | 174 | function showSearchForm() { |
167 | 175 | global $wgOut, $wgRequest, $wgScript, $wgExtensionAssetsPath; |
168 | 176 | $search = $wgRequest->getText( 'searchtext' ); |
169 | 177 | $wgOut->addScriptFile( "$wgExtensionAssetsPath/IndexFunction/specialindex.js" ); |
170 | 178 | $wgOut->addWikiMsg( 'index-search-explain' ); |
171 | | - $form = Xml::openElement( 'fieldset', array( 'style'=>'line-height:200%' ) ) . |
172 | | - Xml::element( 'legend', array(), wfMsgHtml( 'index-legend' ) ) . |
173 | | - Xml::openElement( 'form', array( 'method'=>'GET', 'action'=>$wgScript ) ) . |
| 179 | + $form = Xml::openElement( 'fieldset', array( 'style' => 'line-height:200%' ) ) . |
| 180 | + Xml::element( 'legend', array(), wfMsgHtml( 'index-legend' ) ) . |
| 181 | + Xml::openElement( 'form', array( 'method' => 'GET', 'action' => $wgScript ) ) . |
174 | 182 | Html::Hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) . |
175 | 183 | |
176 | 184 | Xml::label( wfMsg( 'index-search' ), 'mw-index-searchtext' ) . |
177 | | - Xml::input( 'searchtext', 100, $search, array( 'id' => 'mw-index-searchtext' ) ) . |
178 | | - '<br />' . |
| 185 | + Xml::input( 'searchtext', 100, $search, array( 'id' => 'mw-index-searchtext' ) ) . |
| 186 | + '<br />' . |
179 | 187 | Xml::submitButton( wfMsg( 'index-submit' ) ) . |
180 | 188 | |
181 | | - Xml::closeElement( 'form' ) . |
182 | | - Xml::closeElement( 'fieldset' ); |
| 189 | + Xml::closeElement( 'form' ) . |
| 190 | + Xml::closeElement( 'fieldset' ); |
183 | 191 | |
184 | 192 | $wgOut->addHTML( $form ); |
185 | | - |
| 193 | + |
186 | 194 | $t = Title::newFromText( $search ); |
187 | | - |
188 | | - if ( !is_null( $t) ) { |
| 195 | + |
| 196 | + if ( !is_null( $t ) ) { |
189 | 197 | $t = Title::newFromText( $wgRequest->getVal( 'searchtext' ) ); |
190 | 198 | $pager = new SpecialIndexPager( $t ); |
191 | | - $out = Xml::openElement( 'div', array( 'id'=>'mw-index-searchresults' ) ) . |
| 199 | + $out = Xml::openElement( 'div', array( 'id' => 'mw-index-searchresults' ) ) . |
192 | 200 | '<div id="use-js-note" style="display:none">' . wfMsgExt( 'index-details-explain' , array( 'parse' ) ) . '</div>' . |
193 | 201 | $pager->getNavigationBar() . |
194 | | - Xml::openElement( 'table' ) . |
195 | | - $pager->getBody() . |
| 202 | + Xml::openElement( 'table' ) . |
| 203 | + $pager->getBody() . |
196 | 204 | Xml::closeElement( 'table' ) . |
197 | 205 | $pager->getNavigationBar() . |
198 | 206 | Xml::closeElement( 'div' ); |
199 | 207 | $wgOut->addHtml( $out ); |
200 | | - |
| 208 | + |
201 | 209 | } |
202 | | - |
203 | 210 | } |
204 | | - |
| 211 | + |
205 | 212 | function showDabPage( Title $t1 ) { |
206 | 213 | global $wgOut, $wgUser, $wgSpecialIndexContext; |
207 | 214 | $sk = $wgUser->getSkin(); |
208 | 215 | $wgOut->setPagetitle( $t1->getPrefixedText() ); |
209 | 216 | $dbr = wfGetDB( DB_SLAVE ); |
210 | | - $pages = $dbr->select( array('page', 'indexes'), |
| 217 | + $pages = $dbr->select( array( 'page', 'indexes' ), |
211 | 218 | array( 'page_id', 'page_namespace', 'page_title' ), |
212 | | - array( 'in_namespace'=>$t1->getNamespace(), 'in_title'=>$t1->getDBkey() ), |
213 | | - __METHOD__, |
214 | | - array('ORDER BY'=> 'page_namespace, page_title'), |
215 | | - array( 'indexes' => array('JOIN', 'in_from=page_id') ) |
| 219 | + array( 'in_namespace' => $t1->getNamespace(), 'in_title' => $t1->getDBkey() ), |
| 220 | + __METHOD__, |
| 221 | + array( 'ORDER BY' => 'page_namespace, page_title' ), |
| 222 | + array( 'indexes' => array( 'JOIN', 'in_from=page_id' ) ) |
216 | 223 | ); |
217 | | - |
| 224 | + |
218 | 225 | $list = array(); |
219 | | - foreach( $pages as $row ) { |
| 226 | + |
| 227 | + foreach ( $pages as $row ) { |
220 | 228 | $t = Title::newFromRow( $row ); |
221 | | - $list[strval($row->page_id)] = array( 'title' => $t, 'cats' => array() ); |
| 229 | + $list[strval( $row->page_id )] = array( 'title' => $t, 'cats' => array() ); |
222 | 230 | } |
223 | | - if (count($list) == 0) { |
| 231 | + |
| 232 | + if ( count( $list ) == 0 ) { |
224 | 233 | $wgOut->addWikiMsg( 'index-emptylist', $t1->getPrefixedText() ); |
| 234 | + |
225 | 235 | return; |
226 | | - } elseif (count($list) == 1) { |
| 236 | + } elseif ( count( $list ) == 1 ) { |
227 | 237 | $target = reset( $list ); |
228 | 238 | $wgOut->redirect( $target['title']->getLocalURL() ); |
229 | | - } |
| 239 | + } |
| 240 | + |
230 | 241 | $wgOut->addWikiMsg( 'index-disambig-start', $t1->getPrefixedText() ); |
231 | 242 | $keys = array_keys( $list ); |
232 | | - $set = '(' . implode(',', $keys) . ')'; |
233 | | - |
234 | | - $exclude = wfMsg('index-exclude-categories'); |
| 243 | + $set = '(' . implode( ',', $keys ) . ')'; |
| 244 | + |
| 245 | + $exclude = wfMsg( 'index-exclude-categories' ); |
235 | 246 | $excludecats = array(); |
236 | | - if ($exclude) { |
| 247 | + |
| 248 | + if ( $exclude ) { |
237 | 249 | $exclude = explode( '\n', $exclude ); |
238 | | - foreach( $exclude as $cat ) { |
239 | | - if (!$cat) { |
| 250 | + |
| 251 | + foreach ( $exclude as $cat ) { |
| 252 | + if ( !$cat ) { |
240 | 253 | continue; |
241 | 254 | } |
| 255 | + |
242 | 256 | $cat = Title::newFromText( $cat, NS_CATEGORY ); |
243 | | - if ( !is_null($cat) ) { |
| 257 | + |
| 258 | + if ( !is_null( $cat ) ) { |
244 | 259 | $excludecats[] = $dbr->addQuotes( $cat->getDBkey() ); |
245 | 260 | } |
246 | 261 | } |
247 | | - $excludecats = 'AND cl_to NOT IN (' . implode(',', $excludecats) . ')'; |
| 262 | + |
| 263 | + $excludecats = 'AND cl_to NOT IN (' . implode( ',', $excludecats ) . ')'; |
248 | 264 | } else { |
249 | 265 | $excludecats = ''; |
250 | 266 | } |
251 | | - |
| 267 | + |
252 | 268 | $categories = $dbr->select( 'categorylinks', |
253 | | - array('cl_from', 'cl_to'), |
| 269 | + array( 'cl_from', 'cl_to' ), |
254 | 270 | "cl_from IN $set $excludecats", |
255 | 271 | __METHOD__, |
256 | | - array('ORDER BY' => 'cl_from') |
| 272 | + array( 'ORDER BY' => 'cl_from' ) |
257 | 273 | ); |
| 274 | + |
258 | 275 | $groups = array(); |
259 | 276 | $catlist = array(); |
260 | | - foreach( $categories as $row ) { |
| 277 | + |
| 278 | + foreach ( $categories as $row ) { |
261 | 279 | $ct = Title::newFromText( $row->cl_to, NS_CATEGORY ); |
262 | 280 | $textform = $ct->getText(); |
263 | | - $list[strval($row->cl_from)]['cats'][] = $textform; |
| 281 | + $list[strval( $row->cl_from )]['cats'][] = $textform; |
| 282 | + |
264 | 283 | if ( array_key_exists( $textform, $catlist ) ) { |
265 | | - $catlist[$textform][] = strval($row->cl_from); |
| 284 | + $catlist[$textform][] = strval( $row->cl_from ); |
266 | 285 | } else { |
267 | | - $catlist[$textform] = array ( strval($row->cl_from) ); |
| 286 | + $catlist[$textform] = array ( strval( $row->cl_from ) ); |
268 | 287 | } |
269 | 288 | } |
270 | | - if (count($catlist) > 2) { |
271 | | - while (true) { |
272 | | - arsort($catlist); |
| 289 | + |
| 290 | + if ( count( $catlist ) > 2 ) { |
| 291 | + while ( true ) { |
| 292 | + arsort( $catlist ); |
273 | 293 | $group = reset( $catlist ); |
274 | | - if (count($group) == 0) { |
| 294 | + |
| 295 | + if ( count( $group ) == 0 ) { |
275 | 296 | break; |
276 | 297 | } |
277 | | - $keys = array_keys($catlist, $group); |
| 298 | + |
| 299 | + $keys = array_keys( $catlist, $group ); |
278 | 300 | $heading = $keys[0]; |
279 | | - $grouphtml = Xml::element('h2', null, $heading); |
| 301 | + $grouphtml = Xml::element( 'h2', null, $heading ); |
280 | 302 | $grouphtml .= Xml::openElement( 'ul' ); |
281 | | - foreach( $group as $pageid ) { |
| 303 | + |
| 304 | + foreach ( $group as $pageid ) { |
282 | 305 | $t = $list[$pageid]['title']; |
283 | | - $cats = $list[$pageid]['cats']; |
284 | | - $grouphtml .= $this->makeContextLine( $t, $cats ); |
| 306 | + $cats = $list[$pageid]['cats']; |
| 307 | + $grouphtml .= $this->makeContextLine( $t, $cats ); |
| 308 | + |
285 | 309 | unset( $list[$pageid] ); |
286 | | - ksort($list); |
287 | | - foreach($catlist as $remaining) { |
| 310 | + ksort( $list ); |
| 311 | + |
| 312 | + foreach ( $catlist as $remaining ) { |
288 | 313 | $key = array_search( $pageid, $remaining ); |
| 314 | + |
289 | 315 | if ( $key !== false ) { |
290 | | - $masterkeys = array_keys($catlist, $remaining); |
| 316 | + $masterkeys = array_keys( $catlist, $remaining ); |
291 | 317 | $heading = $masterkeys[0]; |
292 | | - unset($catlist[$heading][$key]); |
293 | | - sort($catlist[$heading]); |
| 318 | + unset( $catlist[$heading][$key] ); |
| 319 | + sort( $catlist[$heading] ); |
294 | 320 | } |
295 | 321 | } |
296 | 322 | } |
| 323 | + |
297 | 324 | $grouphtml .= Xml::closeElement( 'ul' ); |
298 | 325 | $groups[] = $grouphtml; |
| 326 | + |
299 | 327 | unset( $catlist[$heading] ); |
300 | | - if (count($catlist) == 0) { |
| 328 | + |
| 329 | + if ( count( $catlist ) == 0 ) { |
301 | 330 | break; |
302 | | - } |
| 331 | + } |
303 | 332 | } |
304 | | - if (count($list) != 0) { //Pages w/ no cats |
| 333 | + |
| 334 | + if ( count( $list ) != 0 ) { // Pages w/ no cats |
305 | 335 | $grouphtml = Xml::openElement( 'ul' ); |
306 | | - foreach( $list as $pageid => $info ) { |
| 336 | + |
| 337 | + foreach ( $list as $pageid => $info ) { |
307 | 338 | $grouphtml .= $this->makeContextLine( $info['title'], array() ); |
308 | 339 | } |
309 | | - $grouphtml .= Xml::closeElement('ul'); |
310 | | - $groups = array_merge( array($grouphtml), $groups); |
| 340 | + |
| 341 | + $grouphtml .= Xml::closeElement( 'ul' ); |
| 342 | + $groups = array_merge( array( $grouphtml ), $groups ); |
311 | 343 | } |
| 344 | + |
312 | 345 | $out = implode( "\n", $groups ); |
313 | 346 | } else { |
314 | 347 | $out = Xml::openElement( 'ul' ); |
315 | | - foreach( $list as $pageid => $info ) { |
| 348 | + |
| 349 | + foreach ( $list as $pageid => $info ) { |
316 | 350 | $out .= $this->makeContextLine( $info['title'], $info['cats'] ); |
317 | 351 | } |
318 | | - $out .= Xml::closeElement('ul'); |
| 352 | + |
| 353 | + $out .= Xml::closeElement( 'ul' ); |
319 | 354 | } |
320 | | - |
321 | | - $wgOut->addHtml($out); |
| 355 | + |
| 356 | + $wgOut->addHtml( $out ); |
322 | 357 | } |
323 | | - |
| 358 | + |
324 | 359 | private function makeContextLine( $title, $cats ) { |
325 | 360 | global $wgUser, $wgSpecialIndexContext; |
| 361 | + |
326 | 362 | $sk = $wgUser->getSkin(); |
327 | 363 | $link = $sk->link( $title, null, array(), array(), array( 'known', 'noclasses' ) ); |
| 364 | + |
328 | 365 | if ( $wgSpecialIndexContext == 'extract' ) { |
329 | 366 | $extracter = new IndexAbstracts(); |
330 | 367 | $text = $extracter->getExtract( $title ); |
— | — | @@ -337,6 +374,7 @@ |
338 | 375 | } else { |
339 | 376 | $line = $link; |
340 | 377 | } |
| 378 | + |
341 | 379 | $line = Xml::tags( 'li', array(), $line ); |
342 | 380 | } elseif ( $wgSpecialIndexContext == 'categories' ) { |
343 | 381 | if ( $cats ) { |
— | — | @@ -350,6 +388,4 @@ |
351 | 389 | } |
352 | 390 | return $line; |
353 | 391 | } |
354 | | - |
355 | 392 | } |
356 | | - |