Index: trunk/extensions/HelpCommons/HelpCommons.php |
— | — | @@ -50,25 +50,26 @@ |
51 | 51 | * @return bool |
52 | 52 | */ |
53 | 53 | function wfHelpCommonsLoad( $helppage ) { |
54 | | - global $wgTitle, $wgOut, $wgContLang, $wgHelpCommonsFetchingWikis, $wgLanguageCode, $wgDBname; |
| 54 | + global $wgOut, $wgContLang, $wgHelpCommonsFetchingWikis, $wgLanguageCode, $wgDBname; |
55 | 55 | |
56 | | - if ( $wgTitle->getNamespace() != NS_HELP ) { |
57 | | - return false; |
| 56 | + $title = $helppage->getTitle(); |
| 57 | + |
| 58 | + if ( $title->getNamespace() != NS_HELP ) { |
| 59 | + return true; |
58 | 60 | } |
59 | 61 | |
60 | | - $title = str_replace( ' ', '_', $helppage->mTitle->getText() ); |
| 62 | + $dbkey = $title->getDBkey(); |
61 | 63 | |
62 | 64 | foreach ( $wgHelpCommonsFetchingWikis as $language => $urls ) { |
63 | 65 | foreach ( $urls as $helpwiki ) { |
64 | 66 | if ( $wgLanguageCode == $language && $wgDBname != $helpwiki ) { |
65 | 67 | $dbr = wfGetDB( DB_SLAVE, array(), $helpwiki ); |
66 | | - $page = $dbr->select( |
| 68 | + $page = $dbr->selectRow( |
67 | 69 | 'page', |
68 | 70 | array( 'page_title', 'page_namespace', 'page_latest' ), |
69 | | - array( 'page_namespace' => NS_HELP, 'page_title' => $title ), |
| 71 | + array( 'page_namespace' => NS_HELP, 'page_title' => $dbkey ), |
70 | 72 | __METHOD__ |
71 | 73 | ); |
72 | | - $page = $dbr->fetchObject( $page ); |
73 | 74 | } |
74 | 75 | } |
75 | 76 | } |
— | — | @@ -80,7 +81,7 @@ |
81 | 82 | ); |
82 | 83 | $rev = $dbr->fetchObject( $rev ); |
83 | 84 | } else { |
84 | | - return false; |
| 85 | + return true; |
85 | 86 | } |
86 | 87 | $text = $dbr->select( 'text', |
87 | 88 | array( 'old_id', 'old_text' ), |
— | — | @@ -92,9 +93,9 @@ |
93 | 94 | if ( !empty( $text->old_text ) ) { |
94 | 95 | $wgOut->addWikiText( $text->old_text ); |
95 | 96 | $wgOut->addScript('<style type="text/css">div.noarticletext { display: none; } div.mw-warning-with-logexcerpt { display: none; } #contentSub, #contentSub2 { display: none; }</style>'); |
| 97 | + return false; |
| 98 | + } else { |
96 | 99 | return true; |
97 | | - } else { |
98 | | - return false; |
99 | 100 | } |
100 | 101 | } |
101 | 102 | |
— | — | @@ -104,34 +105,35 @@ |
105 | 106 | * @return bool |
106 | 107 | */ |
107 | 108 | function wfHelpCommonsRedirectTalks( &$helppage, &$outputDone, &$pcache ) { |
108 | | - global $wgTitle, $wgOut, $wgContLang, $wgHelpCommonsFetchingWikis, $wgLanguageCode, $wgDBname; |
| 109 | + global $wgOut, $wgContLang, $wgHelpCommonsFetchingWikis, $wgLanguageCode, $wgDBname; |
109 | 110 | |
110 | | - if ( $wgTitle->getNamespace() != NS_HELP_TALK ) { |
111 | | - return false; |
| 111 | + $title = $helppage->getTitle(); |
| 112 | + |
| 113 | + if ( $title->getNamespace() != NS_HELP_TALK ) { |
| 114 | + return true; |
112 | 115 | } |
113 | 116 | |
114 | | - $title = str_replace( ' ', '_', $helppage->mTitle->getText() ); |
| 117 | + $dbkey = $title->getDBkey(); |
115 | 118 | |
116 | 119 | foreach ( $wgHelpCommonsFetchingWikis as $language => $urls ) { |
117 | 120 | foreach ( $urls as $url => $helpwiki ) { |
118 | 121 | if ( $wgLanguageCode == $language && $wgDBname != $helpwiki ) { |
119 | 122 | $dbr = wfGetDB( DB_SLAVE, array(), $helpwiki ); |
120 | | - $page = $dbr->select( |
| 123 | + $page = $dbr->selectRow( |
121 | 124 | 'page', |
122 | 125 | array( 'page_title', 'page_namespace', 'page_latest' ), |
123 | | - array( 'page_namespace' => NS_HELP, 'page_title' => $title ), |
| 126 | + array( 'page_namespace' => NS_HELP, 'page_title' => $dbkey ), |
124 | 127 | __METHOD__ |
125 | 128 | ); |
126 | | - $page = $dbr->fetchObject( $page ); |
127 | 129 | } |
128 | 130 | if ( !empty( $page->page_title ) ) { |
129 | | - if ( $page->page_title == $title && !$wgTitle->exists() ) { |
| 131 | + if ( $page->page_title == $title && !$title->exists() ) { |
130 | 132 | $helpCommonsRedirectTalk = Title::newFromText( $url . '/index.php?title=' . str_replace( ' ', '_', $wgOut->getTitle() ) ); |
131 | 133 | $redirectTalkPage = $helpCommonsRedirectTalk->getFullText(); |
132 | 134 | $wgOut->redirect( $redirectTalkPage ); |
| 135 | + return false; |
| 136 | + } else { |
133 | 137 | return true; |
134 | | - } else { |
135 | | - return false; |
136 | 138 | } |
137 | 139 | } |
138 | 140 | } |
— | — | @@ -239,19 +241,23 @@ |
240 | 242 | * @return bool |
241 | 243 | */ |
242 | 244 | function wfHelpCommonsChangeEditSectionLink( $skin, $title, $section, $tooltip, $result, $lang = false ) { |
243 | | - global $wgTitle, $wgHelpCommonsFetchingWikis, $wgLanguageCode, $wgDBname; |
| 245 | + global $wgHelpCommonsFetchingWikis, $wgLanguageCode, $wgDBname; |
244 | 246 | |
245 | | - if ( $wgTitle->getNamespace() != NS_HELP ) { |
| 247 | + $baseTitle = $skin->getTitle(); |
| 248 | + |
| 249 | + if ( $baseTitle->getNamespace() != NS_HELP ) { |
246 | 250 | return false; |
247 | 251 | } |
248 | 252 | |
249 | 253 | foreach ( $wgHelpCommonsFetchingWikis as $language => $urls ) { |
250 | 254 | foreach ( $urls as $url => $helpwiki ) { |
251 | | - if ( $wgLanguageCode == $language && $wgDBname != $helpwiki && !$wgTitle->exists() ) { |
| 255 | + if ( $wgLanguageCode == $language && $wgDBname != $helpwiki && !$baseTitle->exists() ) { |
252 | 256 | // FIXME: $result is unused |
253 | | - $result = '<span class="editsection">[<a href="' . $url . '/index.php?title=' . |
254 | | - str_replace( ' ', '_', $title ) . '&action=edit&section=' . $section . |
255 | | - '" title="' . wfMsg( 'editsectionhint', $tooltip ) . '">' . wfMsg( 'editsection' ) . '</a>]</span>'; |
| 257 | + $result = '<span class="editsection">[' . Xml::element( 'a', array( |
| 258 | + 'href' => $url . '/index.php?title=' . str_replace( ' ', '_', $title ) . '&action=edit§ion=' . $section, |
| 259 | + 'title' => wfMsg( 'editsectionhint', $tooltip ) ), |
| 260 | + wfMsg( 'editsection' ) |
| 261 | + ) . ']</span>'; |
256 | 262 | } |
257 | 263 | } |
258 | 264 | } |
— | — | @@ -268,35 +274,36 @@ |
269 | 275 | function fnProtectHelpCommons( &$title, &$user, $action, &$result ) { |
270 | 276 | global $wgHelpCommonsProtect, $wgHelpCommonsProtectAll, $wgHelpCommonsFetchingWikis, $wgLanguageCode, $wgDBname; |
271 | 277 | |
272 | | - if ( !$wgHelpCommonsProtect && !$wgHelpCommonsProtectAll ) { |
273 | | - return false; |
| 278 | + $ns = $title->getNamespace(); |
| 279 | + if ( ( $ns !== NS_HELP && $ns !== NS_HELP_TALK ) || $title->exists() ) { |
| 280 | + return true; |
274 | 281 | } |
275 | 282 | |
| 283 | + // block actions 'create', 'edit' and 'protect' |
| 284 | + if ( $action != 'create' && $action != 'edit' && $action != 'protect' ) { |
| 285 | + return true; |
| 286 | + } |
| 287 | + |
| 288 | + if ( $wgHelpCommonsProtectAll ) { |
| 289 | + $result = array( 'protectedpagetext' ); |
| 290 | + return true; |
| 291 | + } elseif ( !$wgHelpCommonsProtect ) { |
| 292 | + return true; |
| 293 | + } |
| 294 | + |
276 | 295 | foreach ( $wgHelpCommonsFetchingWikis as $language => $urls ) { |
277 | 296 | foreach ( $urls as $url => $helpwiki ) { |
278 | 297 | // only protect non-existent help pages on non-help-page-fetching wikis |
279 | | - if ( $wgLanguageCode == $language && $wgDBname != $helpwiki && !$title->exists() ) { |
280 | | - // block actions 'create', 'edit' and 'protect' |
281 | | - if ( $action != 'create' && $action != 'edit' && $action != 'protect' ) { |
282 | | - return true; |
283 | | - } |
284 | | - |
| 298 | + if ( $wgLanguageCode == $language && $wgDBname != $helpwiki ) { |
285 | 299 | $dbr = wfGetDB( DB_SLAVE, array(), $helpwiki ); |
286 | | - $res = $dbr->select( |
| 300 | + $res = $dbr->selectField( |
287 | 301 | 'page', |
288 | | - array( 'page_title', 'page_namespace', 'page_latest' ), |
289 | | - array( 'page_namespace' => NS_HELP, 'page_title' => str_replace( ' ', '_', $title->getText() ) ), |
| 302 | + '1', |
| 303 | + array( 'page_namespace' => NS_HELP, 'page_title' => $title->getDBkey() ), |
290 | 304 | __METHOD__ |
291 | 305 | ); |
292 | 306 | |
293 | | - if ( $dbr->numRows( $res ) < 1 && $wgHelpCommonsProtect && !$wgHelpCommonsProtectAll ) { |
294 | | - return true; |
295 | | - } |
296 | | - |
297 | | - $ns = $title->getNamespace(); |
298 | | - |
299 | | - // check namespaces |
300 | | - if( $ns == NS_HELP || $ns == NS_HELP_TALK ) { |
| 307 | + if ( $res ) { |
301 | 308 | // error message if action is blocked |
302 | 309 | $result = array( 'protectedpagetext' ); |
303 | 310 | // bail, and stop the request |