Index: trunk/extensions/SiteMatrix/SiteMatrixApi.php |
— | — | @@ -31,69 +31,94 @@ |
32 | 32 | $localLanguageNames = array(); |
33 | 33 | } |
34 | 34 | |
35 | | - foreach ( $matrix->getLangList() as $lang ) { |
36 | | - $langhost = str_replace( '_', '-', $lang ); |
37 | | - $language = array( |
38 | | - 'code' => $langhost, |
39 | | - 'name' => $langNames[$lang], |
40 | | - 'site' => array(), |
41 | | - ); |
42 | | - if( isset( $localLanguageNames[$lang] ) ) { |
43 | | - $language['localname'] = $localLanguageNames[$lang]; |
44 | | - } |
| 35 | + $params = $this->extractRequestParams(); |
| 36 | + $type = array_flip( $params['type'] ); |
| 37 | + $state = array_flip( $params['state'] ); |
| 38 | + |
| 39 | + $allOrClosed = isset( $state['all'] ) || isset( $state['closed'] ); |
| 40 | + $allOrPrivate = isset( $state['all'] ) || isset( $state['private'] ); |
| 41 | + $allOrFishbowl = isset( $state['all'] ) || isset( $state['fishbowl'] ); |
45 | 42 | |
46 | | - foreach ( $matrix->getSites() as $site ) { |
47 | | - if ( $matrix->exist( $lang, $site ) ) { |
48 | | - $url = $matrix->getUrl( $lang, $site ); |
49 | | - $site_out = array( |
50 | | - 'url' => $url, |
51 | | - 'code' => $site, |
52 | | - ); |
53 | | - if( $matrix->isClosed( $lang, $site ) ) { |
54 | | - $site_out['closed'] = ''; |
| 43 | + if ( isset( $type['language'] ) ) { |
| 44 | + foreach ( $matrix->getLangList() as $lang ) { |
| 45 | + $langhost = str_replace( '_', '-', $lang ); |
| 46 | + $language = array( |
| 47 | + 'code' => $langhost, |
| 48 | + 'name' => $langNames[$lang], |
| 49 | + 'site' => array(), |
| 50 | + ); |
| 51 | + if( isset( $localLanguageNames[$lang] ) ) { |
| 52 | + $language['localname'] = $localLanguageNames[$lang]; |
| 53 | + } |
| 54 | + |
| 55 | + foreach ( $matrix->getSites() as $site ) { |
| 56 | + if ( $matrix->exist( $lang, $site ) ) { |
| 57 | + $url = $matrix->getUrl( $lang, $site ); |
| 58 | + $site_out = array( |
| 59 | + 'url' => $url, |
| 60 | + 'code' => $site, |
| 61 | + ); |
| 62 | + if( $matrix->isClosed( $lang, $site ) ) { |
| 63 | + $site_out['closed'] = ''; |
| 64 | + } |
| 65 | + $language['site'][] = $site_out; |
55 | 66 | } |
56 | | - $language['site'][] = $site_out; |
57 | 67 | } |
| 68 | + |
| 69 | + $result->setIndexedTagName( $language['site'], 'site' ); |
| 70 | + $matrix_out[] = $language; |
58 | 71 | } |
59 | | - |
60 | | - $result->setIndexedTagName($language['site'], 'site'); |
61 | | - $matrix_out[] = $language; |
62 | 72 | } |
63 | | - $result->setIndexedTagName($matrix_out, 'language'); |
64 | | - $result->addValue(null, "sitematrix", $matrix_out); |
65 | 73 | |
66 | | - $specials = array(); |
67 | | - foreach ( $matrix->getSpecials() as $special ){ |
68 | | - list( $lang, $site ) = $special; |
69 | | - $url = $matrix->getUrl( $lang, $site ); |
| 74 | + $result->setIndexedTagName( $matrix_out, 'language' ); |
| 75 | + $result->addValue( null, "sitematrix", $matrix_out ); |
70 | 76 | |
71 | | - $wiki = array(); |
72 | | - $wiki['url'] = $url; |
73 | | - $wiki['code'] = str_replace( '_', '-', $lang ) . ( $site != 'wiki' ? $site : '' ); |
| 77 | + if ( isset( $type['special'] ) ) { |
74 | 78 | |
75 | | - if( $matrix->isPrivate( $lang . $site ) ) { |
76 | | - $wiki['private'] = ''; |
| 79 | + $specials = array(); |
| 80 | + foreach ( $matrix->getSpecials() as $special ){ |
| 81 | + list( $lang, $site ) = $special; |
| 82 | + $url = $matrix->getUrl( $lang, $site ); |
| 83 | + |
| 84 | + $wiki = array(); |
| 85 | + $wiki['url'] = $url; |
| 86 | + $wiki['code'] = str_replace( '_', '-', $lang ) . ( $site != 'wiki' ? $site : '' ); |
| 87 | + |
| 88 | + if ( $matrix->isPrivate( $lang . $site ) ) { |
| 89 | + $wiki['private'] = ''; |
| 90 | + } |
| 91 | + if ( $matrix->isFishbowl( $lang . $site ) ) { |
| 92 | + $wiki['fishbowl'] = ''; |
| 93 | + } |
| 94 | + if ( $matrix->isClosed( $lang, $site ) ) { |
| 95 | + $wiki['closed'] = ''; |
| 96 | + } |
| 97 | + |
| 98 | + $specials[] = $wiki; |
77 | 99 | } |
78 | | - if( $matrix->isFishbowl( $lang . $site ) ) { |
79 | | - $wiki['fishbowl'] = ''; |
80 | | - } |
81 | | - if( $matrix->isClosed( $lang, $site ) ) { |
82 | | - $wiki['closed'] = ''; |
83 | | - } |
84 | 100 | |
85 | | - $specials[] = $wiki; |
| 101 | + $result->setIndexedTagName( $specials, 'special' ); |
| 102 | + $result->addValue( "sitematrix", "specials", $specials ); |
86 | 103 | } |
87 | | - |
88 | | - $result->setIndexedTagName($specials, 'special'); |
89 | | - $result->addValue("sitematrix", "specials", $specials); |
90 | 104 | } |
91 | 105 | |
92 | 106 | protected function getAllowedParams() { |
93 | | - return array(); |
| 107 | + return array( |
| 108 | + 'type' => array( |
| 109 | + ApiBase::PARAM_ISMULTI => true, |
| 110 | + ApiBase::PARAM_TYPE => array( |
| 111 | + 'special', |
| 112 | + 'language' |
| 113 | + ), |
| 114 | + ApiBase::PARAM_DFLT => 'special|language', |
| 115 | + ), |
| 116 | + ); |
94 | 117 | } |
95 | 118 | |
96 | 119 | protected function getParamDescription() { |
97 | | - return array(); |
| 120 | + return array( |
| 121 | + 'type' => 'Filter the Site Matrix by type', |
| 122 | + ); |
98 | 123 | } |
99 | 124 | |
100 | 125 | protected function getDescription() { |