Index: trunk/extensions/HelpCommons/HelpCommons.i18n.php |
— | — | @@ -17,7 +17,11 @@ |
18 | 18 | * @author SVG |
19 | 19 | */ |
20 | 20 | $messages['en'] = array( |
21 | | - 'helpcommons-desc' => 'Fetches help pages from a help wiki and includes them into other wikis on the wiki family', |
| 21 | + 'helpcommons-desc' => 'Fetches help pages from an external or local help wiki and includes them into this wiki', |
| 22 | + 'helpcommons-create' => 'Create on Help Wiki', |
| 23 | + 'helpcommons-edit' => 'Edit on Help Wiki', |
| 24 | + 'helpcommons-discussion' => 'Discuss this on Help Wiki', |
| 25 | + 'helpcommons-info' => 'This content is fetched from $1. See $2.', |
22 | 26 | ); |
23 | 27 | |
24 | 28 | /** Message documentation (Message documentation) |
— | — | @@ -25,6 +29,10 @@ |
26 | 30 | */ |
27 | 31 | $messages['qqq'] = array( |
28 | 32 | 'helpcommons-desc' => '{{desc}}', |
| 33 | + 'helpcommons-create' => 'Second create tab connected to Help Wiki', |
| 34 | + 'helpcommons-edit' => 'Second edit tab connected to Help Wiki', |
| 35 | + 'helpcommons-discussion' => 'Second discussion tab connected to Help Wiki', |
| 36 | + 'helpcommons-info' => "Short description about source at the left side in top in the help page's infobox", |
29 | 37 | ); |
30 | 38 | |
31 | 39 | /** Asturian (Asturianu) |
— | — | @@ -54,7 +62,11 @@ |
55 | 63 | * @author SVG |
56 | 64 | */ |
57 | 65 | $messages['de'] = array( |
58 | | - 'helpcommons-desc' => 'Ermöglicht das Einbinden des Namensraums Hilfe aus einem Wiki in alle anderen Wikis der Wiki-Familie', |
| 66 | + 'helpcommons-desc' => 'Ermöglicht das Einbinden des Hilfe-Namensraums aus einem externen oder lokalen Hilfe Wiki in dieses Wiki', |
| 67 | + 'helpcommons-create' => 'Erstellen im Hilfe Wiki', |
| 68 | + 'helpcommons-edit' => 'Bearbeiten im Hilfe Wiki', |
| 69 | + 'helpcommons-discussion' => 'Diskussion im Hilfe Wiki', |
| 70 | + 'helpcommons-info' => 'Dieser Inhalt ist bezogen aus $1. Siehe $2.', |
59 | 71 | ); |
60 | 72 | |
61 | 73 | /** Lower Sorbian (Dolnoserbski) |
— | — | @@ -127,4 +139,3 @@ |
128 | 140 | $messages['ru'] = array( |
129 | 141 | 'helpcommons-desc' => 'Извлекает страницы справки из справочной вики и добавляет их в другие вики', |
130 | 142 | ); |
131 | | - |
Index: trunk/extensions/HelpCommons/HelpCommons.php |
— | — | @@ -23,79 +23,129 @@ |
24 | 24 | 'author' => array( 'Tim Weyer' ), |
25 | 25 | 'url' => 'https://www.mediawiki.org/wiki/Extension:HelpCommons', |
26 | 26 | 'descriptionmsg' => 'helpcommons-desc', |
27 | | - 'version' => '1.0.2', |
| 27 | + 'version' => '1.3.0', // 02-05-2012 |
28 | 28 | ); |
29 | 29 | |
30 | 30 | // Internationalization |
31 | 31 | $wgExtensionMessagesFiles['HelpCommons'] = dirname( __FILE__ ) . '/HelpCommons.i18n.php'; |
32 | 32 | |
33 | 33 | // Help wiki(s) where the help namespace is fetched from |
| 34 | +// You only need to give a database if you use help pages from your own wiki family so help pages are not fetched for help wiki from help wiki |
| 35 | +// Examples: |
| 36 | +// $wgHelpCommonsFetchingWikis['en']['no-database']['https://meta.wikimedia.org']['w'] = 'Help Wiki'; // https://meta.wikimedia.org/w/api.php |
| 37 | +// $wgHelpCommonsFetchingWikis['de']['dewiki']['http://de.community.wikiunity.com']['no-prefix'] = 'dem deutschsprachigen Hilfe Wiki'; // http://de.community.wikiunity.com/api.php |
| 38 | +// $wgHelpCommonsFetchingWikis['fr']['no-database']['http://fr.wikiunity.com']['no-prefix'] = 'Wikiunity Aidé'; // http://fr.wikiunity.com/api.php |
| 39 | +// $wgHelpCommonsFetchingWikis['ja']['no-database']['http://meta.wikimedia.org']['w'] = 'Help Wiki'; // http://meta.wikimedia.org/w/api.php |
34 | 40 | $wgHelpCommonsFetchingWikis = array(); |
35 | | -// If true, all non-existent help pages and talks which exist on help wiki will be protected on non-help wikis |
36 | | -$wgHelpCommonsProtect = true; |
37 | | -// If true, every non-existent help page will be protected on non-help wikis |
38 | | -$wgHelpCommonsProtectAll = false; |
39 | 41 | |
| 42 | +// Enable local discussions and add an extra tab to help wiki's talk or redirect local discussions to help wiki? |
| 43 | +$wgHelpCommonsEnableLocalDiscussions = true; |
| 44 | + |
| 45 | +// Show re-localized categories from help wiki? |
| 46 | +$wgHelpCommonsShowCategories = true; |
| 47 | + |
| 48 | +// Protection levels for the help namespace and its talk namespace |
| 49 | +// $wgHelpCommonsProtection = 'existing'; => all existing help pages and their discussions |
| 50 | +// $wgHelpCommonsProtection = 'all'; => every help page and every help page discussion |
| 51 | +$wgHelpCommonsProtection = false; |
| 52 | + |
40 | 53 | // Hooks |
41 | | -$wgHooks['ShowMissingArticle'][] = 'wfHelpCommonsLoad'; |
42 | | -$wgHooks['ArticleViewHeader'][] = 'wfHelpCommonsRedirectTalks'; |
43 | | -$wgHooks['LinkBegin'][] = 'efHelpCommonsMakeBlueLinks'; |
44 | | -$wgHooks['LinkBegin'][] = 'efHelpCommonsChangeCategoryLinks'; |
45 | | -$wgHooks['DoEditSectionLink'][] = 'wfHelpCommonsChangeEditSectionLink'; |
46 | | -$wgHooks['getUserPermissionsErrors'][] = 'fnProtectHelpCommons'; |
| 54 | +$wgHooks['BeforePageDisplay'][] = 'fnHelpCommonsLoad'; |
| 55 | +$wgHooks['ArticleViewHeader'][] = 'fnHelpCommonsRedirectTalks'; |
| 56 | +$wgHooks['SkinTemplateTabs'][] = 'fnHelpCommonsInsertTabs'; |
| 57 | +$wgHooks['SkinTemplateNavigation'][] = 'fnHelpCommonsInsertTabsVector'; |
| 58 | +$wgHooks['getUserPermissionsErrors'][] = 'fnHelpCommonsProtection'; |
| 59 | +// This hook is not needed when 'TitleHelpCommonsPageIsKnown' and 'TitleHelpCommonsTalkIsKnown' hooks are used but it does not need to be removed |
| 60 | +$wgHooks['LinkBegin'][] = 'fnHelpCommonsMakeBlueLinks'; |
| 61 | +// HelpCommons' hooks included in Title.php |
| 62 | +// Please see https://www.mediawiki.org/wiki/Extension:HelpCommons to include these hooks |
| 63 | +$wgHooks['TitleHelpCommonsPageIsKnown'][] = 'fnHelpCommonsPageIsKnown'; |
| 64 | +$wgHooks['TitleHelpCommonsTalkIsKnown'][] = 'fnHelpCommonsTalkIsKnown'; |
47 | 65 | |
48 | 66 | /** |
49 | 67 | * @param $helppage Article |
50 | 68 | * @return bool |
51 | 69 | */ |
52 | | -function wfHelpCommonsLoad( $helppage ) { |
53 | | - global $wgHelpCommonsFetchingWikis, $wgLanguageCode, $wgDBname, $wgOut; |
| 70 | +function fnHelpCommonsLoad( OutputPage &$helppage, Skin &$skin ) { |
| 71 | + global $wgRequest, $wgHelpCommonsFetchingWikis, $wgDBname, $wgLanguageCode, $wgOut, $wgHelpCommonsShowCategories, $wgContLang; |
54 | 72 | |
55 | 73 | $title = $helppage->getTitle(); |
56 | 74 | |
57 | | - if ( $title->getNamespace() != NS_HELP ) { |
| 75 | + $action = $wgRequest->getVal( 'action', 'view' ); |
| 76 | + if ( $title->getNamespace() != NS_HELP || ( $action != 'view' && $action != 'purge' ) ) { |
58 | 77 | return true; |
59 | 78 | } |
60 | 79 | |
61 | | - $dbkey = $title->getDBkey(); |
| 80 | + foreach ( $wgHelpCommonsFetchingWikis as $language => $dbs ) { |
| 81 | + foreach ( $dbs as $db => $urls ) { |
| 82 | + foreach ( $urls as $url => $helpWikiPrefixes ) { |
| 83 | + foreach ( $helpWikiPrefixes as $helpWikiPrefix => $name ) { |
| 84 | + if ( $wgLanguageCode == $language ) { |
62 | 85 | |
63 | | - foreach ( $wgHelpCommonsFetchingWikis as $language => $urls ) { |
64 | | - foreach ( $urls as $helpwiki ) { |
65 | | - if ( $wgLanguageCode == $language && $wgDBname != $helpwiki ) { |
66 | | - $dbr = wfGetDB( DB_SLAVE, array(), $helpwiki ); |
67 | | - $page = $dbr->selectRow( |
68 | | - 'page', |
69 | | - array( 'page_title', 'page_namespace', 'page_latest' ), |
70 | | - array( 'page_namespace' => NS_HELP, 'page_title' => $dbkey ), |
71 | | - __METHOD__ |
72 | | - ); |
| 86 | + if ( $db != 'no-database' ) { |
| 87 | + if ( $wgDBname == $db ) { |
| 88 | + return true; |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + $dbkey = $title->getDBkey(); |
| 93 | + |
| 94 | + if ( $helpWikiPrefix != 'no-prefix' ) { |
| 95 | + $prefix = '/' . $helpWikiPrefix; |
| 96 | + } else { |
| 97 | + $prefix = ''; |
| 98 | + } |
| 99 | + |
| 100 | + // check if requested page does exist |
| 101 | + $apiResponse = file_get_contents( $url . $prefix . '/api.php?format=php&action=query&titles=Help:' . $dbkey ); |
| 102 | + $apiData = unserialize( $apiResponse ); |
| 103 | + |
| 104 | + if ( !$apiResponse ) { |
| 105 | + return true; |
| 106 | + } |
| 107 | + |
| 108 | + if ( !$apiData ) { |
| 109 | + return true; |
| 110 | + } |
| 111 | + |
| 112 | + if ( !$apiData['query'] ) { |
| 113 | + return true; |
| 114 | + } |
| 115 | + |
| 116 | + foreach( $apiData['query']['pages'] as $pageId => $pageData ) { |
| 117 | + if ( !isset( $pageData['missing'] ) ) { |
| 118 | + |
| 119 | + // remove noarticletext message and its <div> if not existent (does remove all content) |
| 120 | + if ( !$title->exists() ) { |
| 121 | + $wgOut->clearHTML(); |
| 122 | + } |
| 123 | + |
| 124 | + $response = file_get_contents( $url . $prefix . '/api.php?format=json&action=parse&prop=text|categorieshtml&redirects&disablepp&pst&text={{:Help:' . $dbkey . '}}' ); |
| 125 | + $data = json_decode( $response, /*assoc=*/ true ); |
| 126 | + $text = $data['parse']['text']['*']; |
| 127 | + $text_html = str_replace( '<span class="editsection">[<a href="'.$prefix.'/', '<span class="editsection">[<a href="'.$url.$prefix.'/', $text ); // re-locate [edit] links to help wiki |
| 128 | + if ( $wgHelpCommonsShowCategories ) { |
| 129 | + $categories = $data['parse']['categorieshtml']['*']; |
| 130 | + $categories_html = str_replace( '<a href="', '<a href="'.$url, $categories ); |
| 131 | + $content = $text_html . $categories_html; |
| 132 | + } else { |
| 133 | + $content = $text_html; |
| 134 | + } |
| 135 | + $wgOut->addHTML( '<div id="helpCommons" style="border: solid 1px; padding: 10px; margin: 5px;">' . '<div class="helpCommonsInfo" style="text-align: right; font-size: smaller;padding: 5px;">' . wfMsgForContent( 'helpcommons-info', $name, '<a href="' . $url . $prefix . '/index.php?title=Help:' . $dbkey . '" title="' . $wgContLang->namespaceNames[NS_HELP] . ':' . str_replace( '_', ' ', $dbkey ) . '">' . $wgContLang->namespaceNames[NS_HELP] . ':' . str_replace( '_', ' ', $dbkey ) . '</a>' ) . '</div>' . $content . '</div>' ); |
| 136 | + return false; |
| 137 | + } else { |
| 138 | + return true; |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + } |
| 143 | + |
| 144 | + } |
73 | 145 | } |
74 | 146 | } |
75 | 147 | } |
76 | | - if ( !empty( $page->page_title ) ) { |
77 | | - $rev = $dbr->select( 'revision', |
78 | | - array( 'rev_id', 'rev_text_id' ), |
79 | | - array( 'rev_id' => $page->page_latest ), |
80 | | - __METHOD__ |
81 | | - ); |
82 | | - $rev = $dbr->fetchObject( $rev ); |
83 | | - } else { |
84 | | - return true; |
85 | | - } |
86 | | - $text = $dbr->select( 'text', |
87 | | - array( 'old_id', 'old_text' ), |
88 | | - array( 'old_id' => $rev->rev_text_id ), |
89 | | - __METHOD__ |
90 | | - ); |
91 | | - $text = $dbr->fetchObject( $text ); |
92 | 148 | |
93 | | - if ( !empty( $text->old_text ) ) { |
94 | | - $wgOut->addWikiText( $text->old_text ); |
95 | | - $wgOut->addScript( '<style type="text/css">div.noarticletext { display: none; } div.mw-warning-with-logexcerpt { display: none; } #contentSub, #contentSub2 { display: none; }</style>' ); |
96 | | - return false; |
97 | | - } else { |
98 | | - return true; |
99 | | - } |
| 149 | + return true; |
100 | 150 | } |
101 | 151 | |
102 | 152 | /** |
— | — | @@ -103,87 +153,441 @@ |
104 | 154 | * @param $fields |
105 | 155 | * @return bool |
106 | 156 | */ |
107 | | -function wfHelpCommonsRedirectTalks( &$helppage, &$outputDone, &$pcache ) { |
108 | | - global $wgHelpCommonsFetchingWikis, $wgLanguageCode, $wgDBname, $wgOut; |
| 157 | +function fnHelpCommonsRedirectTalks( &$helppage, &$outputDone, &$pcache ) { |
| 158 | + global $wgHelpCommonsEnableLocalDiscussions, $wgHelpCommonsProtection, $wgHelpCommonsFetchingWikis, $wgLanguageCode, $wgDBname, $wgOut; |
109 | 159 | |
110 | 160 | $title = $helppage->getTitle(); |
111 | 161 | |
112 | | - if ( $title->getNamespace() != NS_HELP_TALK ) { |
| 162 | + if ( $title->getNamespace() != NS_HELP_TALK || ( $wgHelpCommonsEnableLocalDiscussions && $wgHelpCommonsProtection != 'all' && $wgHelpCommonsProtection != 'existing' ) ) { |
113 | 163 | return true; |
114 | 164 | } |
115 | 165 | |
116 | 166 | $dbkey = $title->getDBkey(); |
117 | 167 | |
118 | | - foreach ( $wgHelpCommonsFetchingWikis as $language => $urls ) { |
119 | | - foreach ( $urls as $url => $helpwiki ) { |
120 | | - if ( $wgLanguageCode == $language && $wgDBname != $helpwiki ) { |
121 | | - $dbr = wfGetDB( DB_SLAVE, array(), $helpwiki ); |
122 | | - $page = $dbr->selectRow( |
123 | | - 'page', |
124 | | - array( 'page_title', 'page_namespace', 'page_latest' ), |
125 | | - array( 'page_namespace' => NS_HELP, 'page_title' => $dbkey ), |
126 | | - __METHOD__ |
127 | | - ); |
128 | | - } |
129 | | - if ( !empty( $page->page_title ) ) { |
130 | | - if ( $page->page_title == $dbkey && !$title->exists() ) { |
131 | | - $helpCommonsRedirectTalk = Title::newFromText( $url . '/index.php?title=' . str_replace( ' ', '_', $title ) ); |
132 | | - $redirectTalkPage = $helpCommonsRedirectTalk->getFullText(); |
133 | | - $wgOut->redirect( $redirectTalkPage ); |
134 | | - return false; |
135 | | - } else { |
136 | | - return true; |
| 168 | + foreach ( $wgHelpCommonsFetchingWikis as $language => $dbs ) { |
| 169 | + foreach ( $dbs as $db => $urls ) { |
| 170 | + foreach ( $urls as $url => $helpWikiPrefixes ) { |
| 171 | + foreach ( $helpWikiPrefixes as $helpWikiPrefix => $name ) { |
| 172 | + if ( $wgLanguageCode == $language ) { |
| 173 | + |
| 174 | + if ( $db != 'no-database' ) { |
| 175 | + if ( $wgDBname == $db ) { |
| 176 | + return true; |
| 177 | + } |
| 178 | + } |
| 179 | + |
| 180 | + if ( $helpWikiPrefix != 'no-prefix' ) { |
| 181 | + $prefix = '/' . $helpWikiPrefix; |
| 182 | + } else { |
| 183 | + $prefix = ''; |
| 184 | + } |
| 185 | + |
| 186 | + // check if requested page does exist |
| 187 | + $apiResponse = file_get_contents( $url . $prefix . '/api.php?format=php&action=query&titles=Help:' . $dbkey ); |
| 188 | + $apiData = unserialize( $apiResponse ); |
| 189 | + |
| 190 | + if ( !$apiResponse ) { |
| 191 | + return true; |
| 192 | + } |
| 193 | + |
| 194 | + if ( !$apiData ) { |
| 195 | + return true; |
| 196 | + } |
| 197 | + |
| 198 | + if ( !$apiData['query'] ) { |
| 199 | + return true; |
| 200 | + } |
| 201 | + |
| 202 | + // check if page does exist |
| 203 | + foreach( $apiData['query']['pages'] as $pageId => $pageData ) { |
| 204 | + if ( !isset( $pageData['missing'] ) && !$title->exists() ) { |
| 205 | + $helpCommonsRedirectTalk = $url . $prefix . '/index.php?title=Help_talk:' . $dbkey; |
| 206 | + $wgOut->redirect( $helpCommonsRedirectTalk ); |
| 207 | + return false; |
| 208 | + } else { |
| 209 | + return true; |
| 210 | + } |
| 211 | + } |
| 212 | + |
| 213 | + } |
| 214 | + |
137 | 215 | } |
138 | 216 | } |
139 | 217 | } |
140 | 218 | } |
| 219 | + |
141 | 220 | return true; |
142 | 221 | } |
143 | 222 | |
144 | 223 | /** |
145 | | - * @param $skin |
146 | | - * @param $target Title |
147 | | - * @param $text |
148 | | - * @param $customAttribs |
149 | | - * @param $query |
150 | | - * @param $options array |
151 | | - * @param $ret |
| 224 | + * @param $talkpage Title |
| 225 | + * @param $content_actions |
152 | 226 | * @return bool |
153 | 227 | */ |
154 | | -function efHelpCommonsMakeBlueLinks( $skin, $target, &$text, &$customAttribs, &$query, &$options, &$ret ) { |
155 | | - global $wgHelpCommonsFetchingWikis, $wgDBname; |
| 228 | +function fnHelpCommonsInsertTalkpageTab( $talkpage, &$content_actions ) { |
| 229 | + global $wgHelpCommonsEnableLocalDiscussions, $wgHelpCommonsProtection, $wgHelpCommonsFetchingWikis, $wgLanguageCode, $wgDBname, $wgUser; |
156 | 230 | |
157 | | - // only affects non-help-page-fetching wikis |
158 | | - foreach ( $wgHelpCommonsFetchingWikis as $language => $urls ) { |
159 | | - foreach ( $urls as $url => $helpwiki ) { |
160 | | - if ( $wgDBname == $helpwiki ) { |
161 | | - return true; |
| 231 | + if ( ( $talkpage->getTitle()->getNamespace() != NS_HELP && $talkpage->getTitle()->getNamespace() != NS_HELP_TALK ) || !$wgHelpCommonsEnableLocalDiscussions || $wgHelpCommonsProtection == 'all' || $wgHelpCommonsProtection == 'existing' ) { |
| 232 | + return false; |
| 233 | + } |
| 234 | + |
| 235 | + foreach ( $wgHelpCommonsFetchingWikis as $language => $dbs ) { |
| 236 | + foreach ( $dbs as $db => $urls ) { |
| 237 | + foreach ( $urls as $url => $helpWikiPrefixes ) { |
| 238 | + foreach ( $helpWikiPrefixes as $helpWikiPrefix => $name ) { |
| 239 | + if ( $wgLanguageCode == $language ) { |
| 240 | + |
| 241 | + if ( $db != 'no-database' ) { |
| 242 | + if ( $wgDBname == $db ) { |
| 243 | + return false; |
| 244 | + } |
| 245 | + } |
| 246 | + |
| 247 | + if ( $helpWikiPrefix != 'no-prefix' ) { |
| 248 | + $prefix = '/' . $helpWikiPrefix; |
| 249 | + } else { |
| 250 | + $prefix = ''; |
| 251 | + } |
| 252 | + |
| 253 | + |
| 254 | + // check if requested page does exist |
| 255 | + $apiResponse = file_get_contents( $url . $prefix . '/api.php?format=php&action=query&titles=Help:' . $talkpage->getTitle()->getDBkey() ); |
| 256 | + $apiData = unserialize( $apiResponse ); |
| 257 | + |
| 258 | + if ( !$apiResponse ) { |
| 259 | + return false; |
| 260 | + } |
| 261 | + |
| 262 | + if ( !$apiData ) { |
| 263 | + return false; |
| 264 | + } |
| 265 | + |
| 266 | + if ( !$apiData['query'] ) { |
| 267 | + return false; |
| 268 | + } |
| 269 | + |
| 270 | + // check if page does exist |
| 271 | + foreach( $apiData['query']['pages'] as $pageId => $pageData ) { |
| 272 | + if ( !isset( $pageData['missing'] ) ) { |
| 273 | + |
| 274 | + $tab_keys = array_keys( $content_actions ); |
| 275 | + |
| 276 | + // find the location of the 'talk' link, and |
| 277 | + // add the link to 'Discuss on help wiki' right before it |
| 278 | + $helpcommons_tab_talk = array( |
| 279 | + 'class' => false, |
| 280 | + 'text' => wfMsg( 'helpcommons-discussion' ), |
| 281 | + 'href' => $url.$prefix.'/index.php?title=Help_talk:'.$talkpage->getTitle()->getDBkey(), |
| 282 | + ); |
| 283 | + |
| 284 | + $tab_values = array_values( $content_actions ); |
| 285 | + if ( $wgUser->getSkin()->getSkinName() == 'vector' ) { |
| 286 | + $tabs_location = array_search( 'help_talk', $tab_keys ); |
| 287 | + } else { |
| 288 | + $tabs_location = array_search( 'talk', $tab_keys ); |
| 289 | + } |
| 290 | + array_splice( $tab_keys, $tabs_location, 0, 'talk-helpwiki' ); |
| 291 | + array_splice( $tab_values, $tabs_location, 0, array( $helpcommons_tab_talk ) ); |
| 292 | + |
| 293 | + $content_actions = array(); |
| 294 | + for ( $i = 0; $i < count( $tab_keys ); $i++ ) { |
| 295 | + $content_actions[$tab_keys[$i]] = $tab_values[$i]; |
| 296 | + } |
| 297 | + |
| 298 | + } |
| 299 | + } |
| 300 | + |
| 301 | + } |
| 302 | + } |
162 | 303 | } |
163 | 304 | } |
164 | 305 | } |
165 | 306 | |
166 | | - if ( is_null( $target ) ) { |
167 | | - return true; |
168 | | - } |
| 307 | + return false; |
| 308 | +} |
169 | 309 | |
170 | | - // only affects non-existent help pages and talks |
171 | | - if ( ( $target->getNamespace() != NS_HELP && $target->getNamespace() != NS_HELP_TALK ) || $target->exists() ) { |
172 | | - return true; |
| 310 | +/** |
| 311 | + * @param $action Title |
| 312 | + * @param $content_actions |
| 313 | + * @return bool |
| 314 | + */ |
| 315 | +function fnHelpCommonsInsertActionTab( $action, &$content_actions ) { |
| 316 | + global $wgHelpCommonsFetchingWikis, $wgLanguageCode, $wgDBname, $wgUser, $wgVectorUseIconWatch; |
| 317 | + |
| 318 | + if ( $action->getTitle()->getNamespace() != NS_HELP ) { |
| 319 | + return false; |
173 | 320 | } |
174 | 321 | |
175 | | - // remove "broken" assumption/override |
176 | | - $brokenKey = array_search( 'broken', $options ); |
177 | | - if ( $brokenKey !== false ) { |
178 | | - unset( $options[$brokenKey] ); |
| 322 | + foreach ( $wgHelpCommonsFetchingWikis as $language => $dbs ) { |
| 323 | + foreach ( $dbs as $db => $urls ) { |
| 324 | + foreach ( $urls as $url => $helpWikiPrefixes ) { |
| 325 | + foreach ( $helpWikiPrefixes as $helpWikiPrefix => $name ) { |
| 326 | + if ( $wgLanguageCode == $language ) { |
| 327 | + |
| 328 | + if ( $db != 'no-database' ) { |
| 329 | + if ( $wgDBname == $db ) { |
| 330 | + return false; |
| 331 | + } |
| 332 | + } |
| 333 | + |
| 334 | + if ( $helpWikiPrefix != 'no-prefix' ) { |
| 335 | + $prefix = '/' . $helpWikiPrefix; |
| 336 | + } else { |
| 337 | + $prefix = ''; |
| 338 | + } |
| 339 | + |
| 340 | + |
| 341 | + // check if requested page does exist |
| 342 | + $apiResponse = file_get_contents( $url . $prefix . '/api.php?format=php&action=query&titles=Help:' . $action->getTitle()->getDBkey() ); |
| 343 | + $apiData = unserialize( $apiResponse ); |
| 344 | + |
| 345 | + if ( !$apiResponse ) { |
| 346 | + return false; |
| 347 | + } |
| 348 | + |
| 349 | + if ( !$apiData ) { |
| 350 | + return false; |
| 351 | + } |
| 352 | + |
| 353 | + if ( !$apiData['query'] ) { |
| 354 | + return false; |
| 355 | + } |
| 356 | + |
| 357 | + // check if page does exist |
| 358 | + foreach( $apiData['query']['pages'] as $pageId => $pageData ) { |
| 359 | + if ( !isset( $pageData['missing'] ) ) { |
| 360 | + |
| 361 | + $tab_keys = array_keys( $content_actions ); |
| 362 | + |
| 363 | + // find the location of the 'edit' link or the 'watch' icon of vector, and |
| 364 | + // add the link to 'Edit on help wiki' right before it |
| 365 | + if ( array_search( 'edit', $tab_keys ) || array_search( 'watch', $tab_keys ) ) { |
| 366 | + |
| 367 | + $helpcommons_tab_edit = array( |
| 368 | + 'class' => false, |
| 369 | + 'text' => wfMsg( 'helpcommons-edit' ), |
| 370 | + 'href' => $url.$prefix.'/index.php?title=Help:'.$action->getTitle()->getDBkey().'&action=edit', |
| 371 | + ); |
| 372 | + |
| 373 | + $tab_values = array_values( $content_actions ); |
| 374 | + if ( $wgUser->getSkin()->getSkinName() == 'vector' && $wgVectorUseIconWatch && !$action->getTitle()->exists() ) { |
| 375 | + $tabs_location = array_search( 'watch', $tab_keys ); |
| 376 | + } else { |
| 377 | + $tabs_location = array_search( 'edit', $tab_keys ); |
| 378 | + } |
| 379 | + array_splice( $tab_keys, $tabs_location, 0, 'edit-on-helpwiki' ); |
| 380 | + array_splice( $tab_values, $tabs_location, 0, array( $helpcommons_tab_edit ) ); |
| 381 | + |
| 382 | + $content_actions = array(); |
| 383 | + for ( $i = 0; $i < count( $tab_keys ); $i++ ) { |
| 384 | + $content_actions[$tab_keys[$i]] = $tab_values[$i]; |
| 385 | + } |
| 386 | + |
| 387 | + // find the location of the 'viewsource' link, and |
| 388 | + // add the link to 'Edit on help wiki' right before it |
| 389 | + } elseif ( array_search( 'viewsource', $tab_keys ) ) { |
| 390 | + |
| 391 | + $helpcommons_tab_edit = array( |
| 392 | + 'class' => false, |
| 393 | + 'text' => wfMsg( 'helpcommons-edit' ), |
| 394 | + 'href' => $url.$prefix.'/index.php?title=Help:'.$action->getTitle()->getDBkey().'&action=edit', |
| 395 | + ); |
| 396 | + |
| 397 | + $tab_values = array_values( $content_actions ); |
| 398 | + $tabs_location = array_search( 'viewsource', $tab_keys ); |
| 399 | + array_splice( $tab_keys, $tabs_location, 0, 'edit-on-helpwiki' ); |
| 400 | + array_splice( $tab_values, $tabs_location, 0, array( $helpcommons_tab_edit ) ); |
| 401 | + |
| 402 | + $content_actions = array(); |
| 403 | + for ( $i = 0; $i < count( $tab_keys ); $i++ ) { |
| 404 | + $content_actions[$tab_keys[$i]] = $tab_values[$i]; |
| 405 | + } |
| 406 | + |
| 407 | + } else { |
| 408 | + |
| 409 | + $content_actions['edit-on-helpwiki'] = array( |
| 410 | + 'class' => false, |
| 411 | + 'text' => wfMsg( 'helpcommons-edit' ), |
| 412 | + 'href' => $url.$prefix.'/index.php?title=Help:'.$action->getTitle()->getDBkey().'&action=edit', |
| 413 | + ); |
| 414 | + |
| 415 | + } |
| 416 | + |
| 417 | + } else { |
| 418 | + |
| 419 | + $tab_keys = array_keys( $content_actions ); |
| 420 | + |
| 421 | + // find the location of the 'edit' link or the 'watch' icon of vector, and |
| 422 | + // add the link to 'Edit on help wiki' right before it |
| 423 | + if ( array_search( 'edit', $tab_keys ) || array_search( 'watch', $tab_keys ) ) { |
| 424 | + |
| 425 | + $helpcommons_tab_create = array( |
| 426 | + 'class' => false, |
| 427 | + 'text' => wfMsg( 'helpcommons-create' ), |
| 428 | + 'href' => $url.$prefix.'/index.php?title=Help:'.$action->getTitle()->getDBkey().'&action=edit', |
| 429 | + ); |
| 430 | + |
| 431 | + $tab_values = array_values( $content_actions ); |
| 432 | + if ( $wgUser->getSkin()->getSkinName() == 'vector' && $wgVectorUseIconWatch && !$action->getTitle()->exists() ) { |
| 433 | + $tabs_location = array_search( 'watch', $tab_keys ); |
| 434 | + } else { |
| 435 | + $tabs_location = array_search( 'edit', $tab_keys ); |
| 436 | + } |
| 437 | + array_splice( $tab_keys, $tabs_location, 0, 'create-on-helpwiki' ); |
| 438 | + array_splice( $tab_values, $tabs_location, 0, array( $helpcommons_tab_create ) ); |
| 439 | + |
| 440 | + $content_actions = array(); |
| 441 | + for ( $i = 0; $i < count( $tab_keys ); $i++ ) { |
| 442 | + $content_actions[$tab_keys[$i]] = $tab_values[$i]; |
| 443 | + } |
| 444 | + |
| 445 | + } else { |
| 446 | + |
| 447 | + $content_actions['create-on-helpwiki'] = array( |
| 448 | + 'class' => false, |
| 449 | + 'text' => wfMsg( 'helpcommons-create' ), |
| 450 | + 'href' => $url.$prefix.'/index.php?title=Help:'.$action->getTitle()->getDBkey().'&action=edit', |
| 451 | + ); |
| 452 | + |
| 453 | + } |
| 454 | + |
| 455 | + } |
| 456 | + } |
| 457 | + |
| 458 | + } |
| 459 | + } |
| 460 | + } |
| 461 | + } |
179 | 462 | } |
180 | 463 | |
181 | | - // make the link "blue" |
182 | | - $options[] = 'known'; |
| 464 | + return false; |
| 465 | +} |
183 | 466 | |
| 467 | +/** |
| 468 | + * @param $skin Title |
| 469 | + * @param $content_actions |
| 470 | + * @return bool |
| 471 | + */ |
| 472 | +function fnHelpCommonsInsertTabs( $skin, &$content_actions ) { |
| 473 | + fnHelpCommonsInsertTalkpageTab( $skin, $content_actions ); |
| 474 | + fnHelpCommonsInsertActionTab( $skin, $content_actions ); |
184 | 475 | return true; |
185 | 476 | } |
186 | 477 | |
187 | 478 | /** |
| 479 | + * @param $sktemplate Title |
| 480 | + * @param $links |
| 481 | + * @return bool |
| 482 | + */ |
| 483 | +function fnHelpCommonsInsertTabsVector( SkinTemplate &$sktemplate, array &$links ) { |
| 484 | + // the old '$content_actions' array is thankfully just a |
| 485 | + // sub-array of this one |
| 486 | + fnHelpCommonsInsertTalkpageTab( $sktemplate, $links['namespaces'] ); |
| 487 | + fnHelpCommonsInsertActionTab( $sktemplate, $links['views'] ); |
| 488 | + return true; |
| 489 | +} |
| 490 | + |
| 491 | +/** |
| 492 | + * @param $title Title |
| 493 | + * @param $user User |
| 494 | + * @param $action |
| 495 | + * @param $result |
| 496 | + * @return bool |
| 497 | + */ |
| 498 | +function fnHelpCommonsProtection( &$title, &$user, $action, &$result ) { |
| 499 | + global $wgHelpCommonsFetchingWikis, $wgDBname, $wgLanguageCode, $wgHelpCommonsEnableLocalDiscussions, $wgHelpCommonsProtection; |
| 500 | + |
| 501 | + foreach ( $wgHelpCommonsFetchingWikis as $language => $dbs ) { |
| 502 | + foreach ( $dbs as $db => $urls ) { |
| 503 | + foreach ( $urls as $url => $helpWikiPrefixes ) { |
| 504 | + foreach ( $helpWikiPrefixes as $helpWikiPrefix => $name ) { |
| 505 | + if ( $wgLanguageCode == $language ) { |
| 506 | + |
| 507 | + if ( $db != 'no-database' ) { |
| 508 | + if ( $wgDBname == $db ) { |
| 509 | + return true; |
| 510 | + } |
| 511 | + } |
| 512 | + |
| 513 | + if ( $helpWikiPrefix != 'no-prefix' ) { |
| 514 | + $prefix = '/' . $helpWikiPrefix; |
| 515 | + } else { |
| 516 | + $prefix = ''; |
| 517 | + } |
| 518 | + |
| 519 | + $ns = $title->getNamespace(); |
| 520 | + |
| 521 | + // don't protect existing pages |
| 522 | + if ( $title->exists() ) { |
| 523 | + return true; |
| 524 | + } |
| 525 | + |
| 526 | + // block actions 'create', 'edit' and 'protect' |
| 527 | + if ( $action != 'create' && $action != 'edit' && $action != 'protect' ) { |
| 528 | + return true; |
| 529 | + } |
| 530 | + |
| 531 | + if ( !$wgHelpCommonsEnableLocalDiscussions && $ns == NS_HELP_TALK ) { |
| 532 | + // error message if action is blocked |
| 533 | + $result = array( 'protectedpagetext' ); |
| 534 | + // bail, and stop the request |
| 535 | + return false; |
| 536 | + } |
| 537 | + |
| 538 | + switch ( $wgHelpCommonsProtection ) { |
| 539 | + |
| 540 | + case 'all': |
| 541 | + if ( $ns == NS_HELP || $ns == NS_HELP_TALK ) { |
| 542 | + // error message if action is blocked |
| 543 | + $result = array( 'protectedpagetext' ); |
| 544 | + // bail, and stop the request |
| 545 | + return false; |
| 546 | + } |
| 547 | + break; |
| 548 | + |
| 549 | + case 'existing': |
| 550 | + // check if requested page does exist |
| 551 | + $apiResponse = file_get_contents( $url . $prefix . '/api.php?format=php&action=query&titles=Help:' . $title->getDBkey() ); |
| 552 | + $apiData = unserialize( $apiResponse ); |
| 553 | + |
| 554 | + if ( !$apiResponse ) { |
| 555 | + return true; |
| 556 | + } |
| 557 | + |
| 558 | + if ( !$apiData ) { |
| 559 | + return true; |
| 560 | + } |
| 561 | + |
| 562 | + if ( !$apiData['query'] ) { |
| 563 | + return true; |
| 564 | + } |
| 565 | + |
| 566 | + // check if page does exist |
| 567 | + foreach( $apiData['query']['pages'] as $pageId => $pageData ) { |
| 568 | + if ( !isset( $pageData['missing'] ) && ( $ns == NS_HELP || $ns == NS_HELP_TALK ) ) { |
| 569 | + // error message if action is blocked |
| 570 | + $result = array( 'protectedpagetext' ); |
| 571 | + // bail, and stop the request |
| 572 | + return false; |
| 573 | + } |
| 574 | + } |
| 575 | + break; |
| 576 | + |
| 577 | + default: |
| 578 | + return true; |
| 579 | + } |
| 580 | + |
| 581 | + } |
| 582 | + |
| 583 | + } |
| 584 | + } |
| 585 | + } |
| 586 | + } |
| 587 | + |
| 588 | + return true; |
| 589 | +} |
| 590 | + |
| 591 | +/** |
188 | 592 | * @param $skin |
189 | 593 | * @param $target Title |
190 | 594 | * @param $text |
— | — | @@ -193,45 +597,74 @@ |
194 | 598 | * @param $ret |
195 | 599 | * @return bool |
196 | 600 | */ |
197 | | -function efHelpCommonsChangeCategoryLinks( $skin, $target, &$text, &$customAttribs, &$query, &$options, &$ret ) { |
198 | | - global $wgTitle, $wgHelpCommonsFetchingWikis, $wgLanguageCode, $wgDBname; |
| 601 | +function fnHelpCommonsMakeBlueLinks( $skin, $target, &$text, &$customAttribs, &$query, &$options, &$ret ) { |
| 602 | + global $wgHelpCommonsEnableLocalDiscussions, $wgHelpCommonsFetchingWikis, $wgLanguageCode, $wgDBname; |
199 | 603 | |
200 | | - // only affects non-help-page-fetching wikis |
201 | | - foreach ( $wgHelpCommonsFetchingWikis as $language => $urls ) { |
202 | | - foreach ( $urls as $url => $helpwiki ) { |
203 | | - if ( $wgDBname == $helpwiki ) { |
204 | | - return true; |
205 | | - } |
206 | | - } |
207 | | - } |
208 | | - |
209 | | - if ( $wgTitle->getNamespace() != NS_HELP || $wgTitle->exists() ) { |
| 604 | + if ( is_null( $target ) ) { |
210 | 605 | return true; |
211 | 606 | } |
212 | 607 | |
213 | | - if ( is_null( $target ) ) { |
| 608 | + if ( ( $target->getNamespace() != NS_HELP && $target->getNamespace() != NS_HELP_TALK ) || $target->exists() ) { |
214 | 609 | return true; |
215 | 610 | } |
216 | 611 | |
217 | | - // only affects non-existent categories |
218 | | - if ( $target->getNamespace() != NS_CATEGORY || $target->exists() ) { |
| 612 | + if ( $wgHelpCommonsEnableLocalDiscussions && $target->getNamespace() == NS_HELP_TALK ) { |
219 | 613 | return true; |
220 | 614 | } |
221 | 615 | |
222 | | - // remove "broken" assumption/override |
223 | | - $brokenKey = array_search( 'broken', $options ); |
224 | | - if ( $brokenKey !== false ) { |
225 | | - unset( $options[$brokenKey] ); |
226 | | - } |
| 616 | + foreach ( $wgHelpCommonsFetchingWikis as $language => $dbs ) { |
| 617 | + foreach ( $dbs as $db => $urls ) { |
| 618 | + foreach ( $urls as $url => $helpWikiPrefixes ) { |
| 619 | + foreach ( $helpWikiPrefixes as $helpWikiPrefix => $name ) { |
| 620 | + if ( $wgLanguageCode == $language ) { |
227 | 621 | |
228 | | - // make the link "blue" |
229 | | - $options[] = 'known'; |
| 622 | + if ( $db != 'no-database' ) { |
| 623 | + if ( $wgDBname == $db ) { |
| 624 | + return true; |
| 625 | + } |
| 626 | + } |
230 | 627 | |
231 | | - // change category's link |
232 | | - foreach ( $wgHelpCommonsFetchingWikis as $language => $urls ) { |
233 | | - foreach ( $urls as $url => $helpwiki ) { |
234 | | - if ( $wgLanguageCode == $language ) { |
235 | | - $text = '<a href="' . $url . '/index.php?title=' . str_replace( ' ', '_', $target->getPrefixedText() ) . '">' . $text . '</a>'; |
| 628 | + if ( $helpWikiPrefix != 'no-prefix' ) { |
| 629 | + $prefix = '/' . $helpWikiPrefix; |
| 630 | + } else { |
| 631 | + $prefix = ''; |
| 632 | + } |
| 633 | + |
| 634 | + // check if requested page does exist |
| 635 | + $apiResponse = file_get_contents( $url . $prefix . '/api.php?format=php&action=query&titles=Help:' . $target->getDBkey() ); |
| 636 | + $apiData = unserialize( $apiResponse ); |
| 637 | + |
| 638 | + if ( !$apiResponse ) { |
| 639 | + return true; |
| 640 | + } |
| 641 | + |
| 642 | + if ( !$apiData ) { |
| 643 | + return true; |
| 644 | + } |
| 645 | + |
| 646 | + if ( !$apiData['query'] ) { |
| 647 | + return true; |
| 648 | + } |
| 649 | + |
| 650 | + // check if page does exist |
| 651 | + foreach( $apiData['query']['pages'] as $pageId => $pageData ) { |
| 652 | + if ( !isset( $pageData['missing'] ) ) { |
| 653 | + |
| 654 | + // remove "broken" assumption/override |
| 655 | + $brokenKey = array_search( 'broken', $options ); |
| 656 | + if ( $brokenKey !== false ) { |
| 657 | + unset( $options[$brokenKey] ); |
| 658 | + } |
| 659 | + |
| 660 | + // make the link "blue" |
| 661 | + $options[] = 'known'; |
| 662 | + |
| 663 | + } |
| 664 | + } |
| 665 | + |
| 666 | + } |
| 667 | + |
| 668 | + } |
236 | 669 | } |
237 | 670 | } |
238 | 671 | } |
— | — | @@ -240,94 +673,143 @@ |
241 | 674 | } |
242 | 675 | |
243 | 676 | /** |
244 | | - * @param $skin |
245 | | - * @param $title Title |
246 | | - * @param $section |
247 | | - * @param $tooltip |
248 | | - * @param $result |
249 | | - * @param bool $lang |
| 677 | + * @param $page Article |
250 | 678 | * @return bool |
251 | 679 | */ |
252 | | -function wfHelpCommonsChangeEditSectionLink( $skin, $title, $section, $tooltip, $result, $lang = false ) { |
| 680 | +function fnHelpCommonsPageIsKnown( $page ) { |
253 | 681 | global $wgHelpCommonsFetchingWikis, $wgLanguageCode, $wgDBname; |
254 | 682 | |
255 | | - $baseTitle = $skin->getTitle(); |
| 683 | + foreach ( $wgHelpCommonsFetchingWikis as $language => $dbs ) { |
| 684 | + foreach ( $dbs as $db => $urls ) { |
| 685 | + foreach ( $urls as $url => $helpWikiPrefixes ) { |
| 686 | + foreach ( $helpWikiPrefixes as $helpWikiPrefix => $name ) { |
| 687 | + if ( $wgLanguageCode == $language ) { |
256 | 688 | |
257 | | - if ( $baseTitle->getNamespace() != NS_HELP ) { |
258 | | - return false; |
259 | | - } |
| 689 | + if ( $db != 'no-database' ) { |
| 690 | + if ( $wgDBname == $db ) { |
| 691 | + return false; |
| 692 | + } |
| 693 | + } |
260 | 694 | |
261 | | - foreach ( $wgHelpCommonsFetchingWikis as $language => $urls ) { |
262 | | - foreach ( $urls as $url => $helpwiki ) { |
263 | | - if ( $wgLanguageCode == $language && $wgDBname != $helpwiki && !$baseTitle->exists() ) { |
264 | | - // FIXME: $result is unused |
265 | | - $result = '<span class="editsection">[' . Xml::element( 'a', array( |
266 | | - 'href' => $url . '/index.php?title=' . str_replace( ' ', '_', $title ) . '&action=edit§ion=' . $section, |
267 | | - 'title' => wfMsg( 'editsectionhint', $tooltip ) ), |
268 | | - wfMsg( 'editsection' ) |
269 | | - ) . ']</span>'; |
| 695 | + if ( $helpWikiPrefix != 'no-prefix' ) { |
| 696 | + $prefix = '/' . $helpWikiPrefix; |
| 697 | + } else { |
| 698 | + $prefix = ''; |
| 699 | + } |
| 700 | + |
| 701 | + // check if requested page does exist |
| 702 | + $apiResponse = file_get_contents( $url . $prefix . '/api.php?format=php&action=query&titles=Help:' . $page->getDBkey() ); |
| 703 | + $apiData = unserialize( $apiResponse ); |
| 704 | + |
| 705 | + if ( !$apiResponse ) { |
| 706 | + return false; |
| 707 | + } |
| 708 | + |
| 709 | + if ( !$apiData ) { |
| 710 | + return false; |
| 711 | + } |
| 712 | + |
| 713 | + if ( !$apiData['query'] ) { |
| 714 | + return false; |
| 715 | + } |
| 716 | + |
| 717 | + // check if page does exist |
| 718 | + foreach( $apiData['query']['pages'] as $pageId => $pageData ) { |
| 719 | + if ( !isset( $pageData['missing'] ) ) { |
| 720 | + return true; |
| 721 | + } else { |
| 722 | + return false; |
| 723 | + } |
| 724 | + } |
| 725 | + |
| 726 | + } |
| 727 | + |
| 728 | + } |
270 | 729 | } |
271 | 730 | } |
272 | 731 | } |
273 | | - return true; |
| 732 | + |
| 733 | + return false; |
274 | 734 | } |
275 | 735 | |
276 | 736 | /** |
277 | | - * @param $title Title |
278 | | - * @param $user User |
279 | | - * @param $action |
280 | | - * @param $result |
| 737 | + * @param $talk Article |
281 | 738 | * @return bool |
282 | 739 | */ |
283 | | -function fnProtectHelpCommons( &$title, &$user, $action, &$result ) { |
284 | | - global $wgHelpCommonsFetchingWikis, $wgDBname, $wgHelpCommonsProtectAll, $wgHelpCommonsProtect, $wgLanguageCode; |
| 740 | +function fnHelpCommonsTalkIsKnown( $talk ) { |
| 741 | + global $wgHelpCommonsEnableLocalDiscussions, $wgHelpCommonsFetchingWikis, $wgLanguageCode, $wgDBname; |
285 | 742 | |
286 | | - // only affects non-help-page-fetching wikis |
287 | | - foreach ( $wgHelpCommonsFetchingWikis as $language => $urls ) { |
288 | | - foreach ( $urls as $url => $helpwiki ) { |
289 | | - if ( $wgDBname == $helpwiki ) { |
290 | | - return true; |
291 | | - } |
292 | | - } |
| 743 | + if ( $wgHelpCommonsEnableLocalDiscussions ) { |
| 744 | + return false; |
293 | 745 | } |
294 | 746 | |
295 | | - $ns = $title->getNamespace(); |
296 | | - if ( ( $ns !== NS_HELP && $ns !== NS_HELP_TALK ) || $title->exists() ) { |
297 | | - return true; |
298 | | - } |
| 747 | + foreach ( $wgHelpCommonsFetchingWikis as $language => $dbs ) { |
| 748 | + foreach ( $dbs as $db => $urls ) { |
| 749 | + foreach ( $urls as $url => $helpWikiPrefixes ) { |
| 750 | + foreach ( $helpWikiPrefixes as $helpWikiPrefix => $name ) { |
| 751 | + if ( $wgLanguageCode == $language ) { |
299 | 752 | |
300 | | - // block actions 'create', 'edit' and 'protect' |
301 | | - if ( $action != 'create' && $action != 'edit' && $action != 'protect' ) { |
302 | | - return true; |
303 | | - } |
| 753 | + if ( $db != 'no-database' ) { |
| 754 | + if ( $wgDBname == $db ) { |
| 755 | + return false; |
| 756 | + } |
| 757 | + } |
304 | 758 | |
305 | | - if ( $wgHelpCommonsProtectAll ) { |
306 | | - $result = array( 'protectedpagetext' ); |
307 | | - return false; |
308 | | - } elseif ( !$wgHelpCommonsProtect ) { |
309 | | - return true; |
310 | | - } |
| 759 | + if ( $helpWikiPrefix != 'no-prefix' ) { |
| 760 | + $prefix = '/' . $helpWikiPrefix; |
| 761 | + } else { |
| 762 | + $prefix = ''; |
| 763 | + } |
311 | 764 | |
312 | | - foreach ( $wgHelpCommonsFetchingWikis as $language => $urls ) { |
313 | | - foreach ( $urls as $url => $helpwiki ) { |
314 | | - // only protect non-existent help pages on non-help-page-fetching wikis |
315 | | - if ( $wgLanguageCode == $language ) { |
316 | | - $dbr = wfGetDB( DB_SLAVE, array(), $helpwiki ); |
317 | | - $res = $dbr->selectField( |
318 | | - 'page', |
319 | | - '1', |
320 | | - array( 'page_namespace' => NS_HELP, 'page_title' => $title->getDBkey() ), |
321 | | - __METHOD__ |
322 | | - ); |
| 765 | + // check if requested page does exist |
| 766 | + $apiPageResponse = file_get_contents( $url . $prefix . '/api.php?format=php&action=query&titles=Help:' . $talk->getDBkey() ); |
| 767 | + $apiPageData = unserialize( $apiPageResponse ); |
323 | 768 | |
324 | | - if ( $res ) { |
325 | | - // error message if action is blocked |
326 | | - $result = array( 'protectedpagetext' ); |
327 | | - // bail, and stop the request |
328 | | - return false; |
| 769 | + if ( !$apiPageResponse ) { |
| 770 | + return false; |
| 771 | + } |
| 772 | + |
| 773 | + if ( !$apiPageData ) { |
| 774 | + return false; |
| 775 | + } |
| 776 | + |
| 777 | + if ( !$apiPageData['query'] ) { |
| 778 | + return false; |
| 779 | + } |
| 780 | + |
| 781 | + // check if requested talkpage does exist |
| 782 | + $apiTalkResponse = file_get_contents( $url . $prefix . '/api.php?format=php&action=query&titles=Help_talk:' . $talk->getDBkey() ); |
| 783 | + $apiTalkData = unserialize( $apiTalkResponse ); |
| 784 | + |
| 785 | + if ( !$apiTalkResponse ) { |
| 786 | + return false; |
| 787 | + } |
| 788 | + |
| 789 | + if ( !$apiTalkData ) { |
| 790 | + return false; |
| 791 | + } |
| 792 | + |
| 793 | + if ( !$apiTalkData['query'] ) { |
| 794 | + return false; |
| 795 | + } |
| 796 | + |
| 797 | + // check if page and its talk do exist |
| 798 | + foreach( $apiPageData['query']['pages'] as $pageId => $pageData ) { |
| 799 | + foreach( $apiTalkData['query']['pages'] as $talkId => $talkData ) { |
| 800 | + if ( !isset( $pageData['missing'] ) && !isset( $talkData['missing'] ) ) { |
| 801 | + return true; |
| 802 | + } else { |
| 803 | + return false; |
| 804 | + } |
| 805 | + } |
| 806 | + } |
| 807 | + |
| 808 | + } |
| 809 | + |
329 | 810 | } |
330 | 811 | } |
331 | 812 | } |
332 | 813 | } |
333 | | - return true; |
| 814 | + |
| 815 | + return false; |
334 | 816 | } |