Index: trunk/extensions/SiteMatrix/SiteMatrixApi.php |
— | — | @@ -31,69 +31,109 @@ |
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 ( $allOrClosed ) { |
| 63 | + if( $matrix->isClosed( $lang, $site ) ) { |
| 64 | + $site_out['closed'] = ''; |
| 65 | + } |
| 66 | + } else { |
| 67 | + continue; |
| 68 | + } |
| 69 | + $language['site'][] = $site_out; |
55 | 70 | } |
56 | | - $language['site'][] = $site_out; |
57 | 71 | } |
| 72 | + |
| 73 | + $result->setIndexedTagName( $language['site'], 'site' ); |
| 74 | + $matrix_out[] = $language; |
58 | 75 | } |
| 76 | + } |
59 | 77 | |
60 | | - $result->setIndexedTagName($language['site'], 'site'); |
61 | | - $matrix_out[] = $language; |
62 | | - } |
63 | 78 | $result->setIndexedTagName($matrix_out, 'language'); |
64 | 79 | $result->addValue(null, "sitematrix", $matrix_out); |
65 | 80 | |
66 | | - $specials = array(); |
67 | | - foreach ( $matrix->getSpecials() as $special ){ |
68 | | - list( $lang, $site ) = $special; |
69 | | - $url = $matrix->getUrl( $lang, $site ); |
| 81 | + if ( isset( $type['special'] ) ) { |
| 82 | + $specials = array(); |
| 83 | + foreach ( $matrix->getSpecials() as $special ){ |
| 84 | + list( $lang, $site ) = $special; |
| 85 | + $url = $matrix->getUrl( $lang, $site ); |
70 | 86 | |
71 | | - $wiki = array(); |
72 | | - $wiki['url'] = $url; |
73 | | - $wiki['code'] = str_replace( '_', '-', $lang ) . ( $site != 'wiki' ? $site : '' ); |
| 87 | + $wiki = array(); |
| 88 | + $wiki['url'] = $url; |
| 89 | + $wiki['code'] = str_replace( '_', '-', $lang ) . ( $site != 'wiki' ? $site : '' ); |
74 | 90 | |
75 | | - if( $matrix->isPrivate( $lang . $site ) ) { |
76 | | - $wiki['private'] = ''; |
| 91 | + if( $allOrPrivate ) { |
| 92 | + if ( $matrix->isPrivate( $lang . $site ) ) { |
| 93 | + $wiki['private'] = ''; |
| 94 | + } |
| 95 | + } else { |
| 96 | + continue; |
| 97 | + } |
| 98 | + if( $allOrFishbowl ) { |
| 99 | + if ( $matrix->isFishbowl( $lang . $site ) ) { |
| 100 | + $wiki['fishbowl'] = ''; |
| 101 | + } |
| 102 | + } else { |
| 103 | + continue; |
| 104 | + } |
| 105 | + if( $allOrClosed ) { |
| 106 | + if ( $matrix->isClosed( $lang, $site ) ) { |
| 107 | + $wiki['closed'] = ''; |
| 108 | + } |
| 109 | + } else { |
| 110 | + continue; |
| 111 | + } |
| 112 | + |
| 113 | + $specials[] = $wiki; |
77 | 114 | } |
78 | | - if( $matrix->isFishbowl( $lang . $site ) ) { |
79 | | - $wiki['fishbowl'] = ''; |
80 | | - } |
81 | | - if( $matrix->isClosed( $lang, $site ) ) { |
82 | | - $wiki['closed'] = ''; |
83 | | - } |
84 | 115 | |
85 | | - $specials[] = $wiki; |
| 116 | + $result->setIndexedTagName( $specials, 'special' ); |
| 117 | + $result->addValue( "sitematrix", "specials", $specials ); |
86 | 118 | } |
87 | | - |
88 | | - $result->setIndexedTagName($specials, 'special'); |
89 | | - $result->addValue("sitematrix", "specials", $specials); |
90 | 119 | } |
91 | 120 | |
92 | 121 | protected function getAllowedParams() { |
93 | | - return array(); |
| 122 | + return array( |
| 123 | + 'type' => array( |
| 124 | + ApiBase::PARAM_ISMULTI => true, |
| 125 | + ApiBase::PARAM_TYPE => array( |
| 126 | + 'special', |
| 127 | + 'language' |
| 128 | + ), |
| 129 | + ApiBase::PARAM_DFLT => 'special|language', |
| 130 | + ), |
| 131 | + ); |
94 | 132 | } |
95 | 133 | |
96 | 134 | protected function getParamDescription() { |
97 | | - return array(); |
| 135 | + return array( |
| 136 | + 'type' => 'Filter the Site Matrix by wiki type', |
| 137 | + ); |
98 | 138 | } |
99 | 139 | |
100 | 140 | protected function getDescription() { |