Index: trunk/extensions/SharedHelpNamespace/SharedHelpNamespace.php |
— | — | @@ -46,41 +46,42 @@ |
47 | 47 | function wfSharedHelpNamespaceLoad( $article ) { |
48 | 48 | global $wgTitle, $wgOut, $wgContLang, $wgSharedHelpNamespaceFetchingWikis, $wgLanguageCode, $wgDBname; |
49 | 49 | |
50 | | - if ( $wgTitle->getNamespace() == NS_HELP ) { |
| 50 | + if ( $wgTitle->getNamespace() != NS_HELP ) { |
| 51 | + return false; |
| 52 | + } |
51 | 53 | |
52 | | - $replacewhitespace = str_replace( ' ', '_', $wgOut->getTitle() ); |
53 | | - $title = str_replace( $wgContLang->namespaceNames[NS_HELP].':', '', $replacewhitespace ); |
| 54 | + $replacewhitespace = str_replace( ' ', '_', $wgOut->getTitle() ); |
| 55 | + $title = str_replace( $wgContLang->namespaceNames[NS_HELP].':', '', $replacewhitespace ); |
54 | 56 | |
55 | | - foreach ( $wgSharedHelpNamespaceFetchingWikis as $language => $urls ) { |
56 | | - foreach ( $urls as $wgSharedHelpNamespaceFetchingWiki ) { |
57 | | - if ( $wgLanguageCode == "$language" && $wgDBname != $wgSharedHelpNamespaceFetchingWiki ) { |
58 | | - $dbr = wfGetDB( DB_SLAVE, array(), $wgSharedHelpNamespaceFetchingWiki ); |
59 | | - $page = $dbr->query( 'SELECT page_title, page_namespace, page_latest FROM page WHERE page_namespace = 12 AND page_title = '.$dbr->addQuotes($title) ); |
60 | | - $page = $dbr->fetchObject( $page ); |
61 | | - } |
| 57 | + foreach ( $wgSharedHelpNamespaceFetchingWikis as $language => $urls ) { |
| 58 | + foreach ( $urls as $wgSharedHelpNamespaceFetchingWiki ) { |
| 59 | + if ( $wgLanguageCode == "$language" && $wgDBname != $wgSharedHelpNamespaceFetchingWiki ) { |
| 60 | + $dbr = wfGetDB( DB_SLAVE, array(), $wgSharedHelpNamespaceFetchingWiki ); |
| 61 | + $page = $dbr->query( 'SELECT page_title, page_namespace, page_latest FROM page WHERE page_namespace = 12 AND page_title = '.$dbr->addQuotes($title) ); |
| 62 | + $page = $dbr->fetchObject( $page ); |
62 | 63 | } |
63 | 64 | } |
64 | | - if ( !empty($page->page_title) ) { |
65 | | - $rev = $dbr->select( 'revision', |
66 | | - array( 'rev_id', 'rev_text_id' ), |
67 | | - 'rev_id = '.$dbr->addQuotes($page->page_latest), |
68 | | - __METHOD__ ); |
69 | | - $rev = $dbr->fetchObject( $rev ); |
70 | | - } else { |
71 | | - return false; |
72 | | - } |
73 | | - $text = $dbr->select( 'text', |
74 | | - array( 'old_id', 'old_text' ), |
75 | | - 'old_id = '.$dbr->addQuotes($rev->rev_text_id), |
76 | | - __METHOD__ ); |
77 | | - $text = $dbr->fetchObject( $text ); |
| 65 | + } |
| 66 | + if ( !empty( $page->page_title ) ) { |
| 67 | + $rev = $dbr->select( 'revision', |
| 68 | + array( 'rev_id', 'rev_text_id' ), |
| 69 | + array( 'rev_id' => $page->page_latest ), |
| 70 | + __METHOD__ |
| 71 | + ); |
| 72 | + $rev = $dbr->fetchObject( $rev ); |
| 73 | + } else { |
| 74 | + return false; |
| 75 | + } |
| 76 | + $text = $dbr->select( 'text', |
| 77 | + array( 'old_id', 'old_text' ), |
| 78 | + array( 'old_id' => $rev->rev_text_id ), |
| 79 | + __METHOD__ |
| 80 | + ); |
| 81 | + $text = $dbr->fetchObject( $text ); |
78 | 82 | |
79 | | - if ( !empty($text->old_text) ) { |
80 | | - echo $wgOut->addWikiText( $text->old_text ); |
81 | | - return true; |
82 | | - } else { |
83 | | - return false; |
84 | | - } |
| 83 | + if ( !empty( $text->old_text ) ) { |
| 84 | + $wgOut->addWikiText( $text->old_text ); |
| 85 | + return true; |
85 | 86 | } else { |
86 | 87 | return false; |
87 | 88 | } |
— | — | @@ -94,34 +95,39 @@ |
95 | 96 | function wfSharedHelpNamespaceRedirectTalks( $article, $fields ) { |
96 | 97 | global $wgTitle, $wgOut, $wgContLang, $wgSharedHelpNamespaceFetchingWikis, $wgLanguageCode, $wgDBname; |
97 | 98 | |
98 | | - if ( $wgTitle->getNamespace() == NS_HELP_TALK ) { |
| 99 | + if ( $wgTitle->getNamespace() != NS_HELP_TALK ) { |
| 100 | + return false; |
| 101 | + } |
99 | 102 | |
100 | | - $replacewhitespace = str_replace( ' ', '_', $wgOut->getTitle() ); |
101 | | - $title = str_replace( $wgContLang->namespaceNames[NS_HELP_TALK].':', '', $replacewhitespace ); |
| 103 | + $replacewhitespace = str_replace( ' ', '_', $wgOut->getTitle() ); |
| 104 | + $title = str_replace( $wgContLang->namespaceNames[NS_HELP_TALK].':', '', $replacewhitespace ); |
102 | 105 | |
103 | | - foreach ( $wgSharedHelpNamespaceFetchingWikis as $language => $urls ) { |
104 | | - foreach ( $urls as $url => $wgSharedHelpNamespaceFetchingWiki ) { |
105 | | - if ( $wgLanguageCode == "$language" && $wgDBname != $wgSharedHelpNamespaceFetchingWiki ) { |
106 | | - $dbr = wfGetDB( DB_SLAVE, array(), $wgSharedHelpNamespaceFetchingWiki ); |
107 | | - $page = $dbr->query( 'SELECT page_title, page_namespace, page_latest FROM page WHERE page_namespace = 12 AND page_title = '.$dbr->addQuotes($title) ); |
108 | | - $page = $dbr->fetchObject( $page ); |
| 106 | + foreach ( $wgSharedHelpNamespaceFetchingWikis as $language => $urls ) { |
| 107 | + // FIXME: don't use global esk variable names for non globals |
| 108 | + foreach ( $urls as $url => $wgSharedHelpNamespaceFetchingWiki ) { |
| 109 | + if ( $wgLanguageCode == "$language" && $wgDBname != $wgSharedHelpNamespaceFetchingWiki ) { |
| 110 | + $dbr = wfGetDB( DB_SLAVE, array(), $wgSharedHelpNamespaceFetchingWiki ); |
| 111 | + $page = $dbr->select( |
| 112 | + 'page', |
| 113 | + array( 'page_title', 'page_namespace', 'page_latest' ), |
| 114 | + array( 'page_namespace' => 12, 'page_title' => $title ), |
| 115 | + __METHOD__ |
| 116 | + ); |
| 117 | + $page = $dbr->fetchObject( $page ); |
| 118 | + } |
| 119 | + if ( !empty( $page->page_title ) ) { |
| 120 | + if ( $page->page_title == $title && !$wgTitle->exists() ) { |
| 121 | + $sharedHelpRedirectTalk = Title::newFromText( $url . '/index.php?title=' . str_replace( ' ', '_', $wgOut->getTitle() ) ); |
| 122 | + $redirectTalkPage = $sharedHelpRedirectTalk->getFullText(); |
| 123 | + $wgOut->redirect( $redirectTalkPage ); |
| 124 | + return true; |
| 125 | + } else { |
| 126 | + return false; |
109 | 127 | } |
110 | | - if ( !empty($page->page_title) ) { |
111 | | - if ( $page->page_title == $title && !$wgTitle->exists() ) { |
112 | | - $sharedHelpRedirectTalk = Title::newFromText( $url . '/index.php?title=' . str_replace( ' ', '_', $wgOut->getTitle() ) ); |
113 | | - $redirectTalkPage = $sharedHelpRedirectTalk->getFullText(); |
114 | | - $wgOut->redirect( $redirectTalkPage ); |
115 | | - return true; |
116 | | - } else { |
117 | | - return false; |
118 | | - } |
119 | | - } |
120 | 128 | } |
121 | 129 | } |
122 | | - return true; |
123 | | - } else { |
124 | | - return false; |
125 | 130 | } |
| 131 | + return true; |
126 | 132 | } |
127 | 133 | |
128 | 134 | /** |
— | — | @@ -130,7 +136,7 @@ |
131 | 137 | * @param $text |
132 | 138 | * @param $customAttribs |
133 | 139 | * @param $query |
134 | | - * @param $options |
| 140 | + * @param $options array |
135 | 141 | * @param $ret |
136 | 142 | * @return bool |
137 | 143 | */ |
— | — | @@ -169,19 +175,21 @@ |
170 | 176 | function wfSharedHelpNamespaceChangeEditSectionLink( $skin, $title, $section, $tooltip, $result, $lang = false ) { |
171 | 177 | global $wgTitle, $wgSharedHelpNamespaceFetchingWikis, $wgLanguageCode, $wgDBname; |
172 | 178 | |
173 | | - if ( $wgTitle->getNamespace() == NS_HELP ) { |
174 | | - foreach ( $wgSharedHelpNamespaceFetchingWikis as $language => $urls ) { |
175 | | - foreach ( $urls as $url => $wgSharedHelpNamespaceFetchingWiki ) { |
176 | | - if ( $wgLanguageCode == "$language" && $wgDBname != $wgSharedHelpNamespaceFetchingWiki ) { |
177 | | - $result = '<span class="editsection">[<a href="'.$url.'/index.php?title='.str_replace( ' ', '_', $title ).'&action=edit&section='.$section.'" title="'.wfMsg( 'editsectionhint', $tooltip ).'">'.wfMsg( 'editsection' ).'</a>]</span>'; |
178 | | - } |
| 179 | + if ( $wgTitle->getNamespace() != NS_HELP ) { |
| 180 | + return false; |
| 181 | + } |
| 182 | + foreach ( $wgSharedHelpNamespaceFetchingWikis as $language => $urls ) { |
| 183 | + // FIXME: don't use global esk variable names for non globals |
| 184 | + foreach ( $urls as $url => $wgSharedHelpNamespaceFetchingWiki ) { |
| 185 | + if ( $wgLanguageCode == "$language" && $wgDBname != $wgSharedHelpNamespaceFetchingWiki ) { |
| 186 | + // FIXME: $result is unused |
| 187 | + $result = '<span class="editsection">[<a href="' . $url . '/index.php?title=' . |
| 188 | + str_replace( ' ', '_', $title ) . '&action=edit&section=' . $section . |
| 189 | + '" title="' . wfMsg( 'editsectionhint', $tooltip ) . '">' . wfMsg( 'editsection' ) . '</a>]</span>'; |
179 | 190 | } |
180 | 191 | } |
181 | | - return true; |
182 | | - } else { |
183 | | - return false; |
184 | 192 | } |
185 | | - |
| 193 | + return true; |
186 | 194 | } |
187 | 195 | |
188 | 196 | /** |
— | — | @@ -194,18 +202,23 @@ |
195 | 203 | function fnProtectSharedHelpNamespace( &$title, &$user, $action, &$result) { |
196 | 204 | global $wgSharedHelpNamespaceFetchingWikis, $wgDBname; |
197 | 205 | |
198 | | - foreach ( $wgSharedHelpNamespaceFetchingWikis as $language => $urls ) { |
| 206 | + foreach ( $wgSharedHelpNamespaceFetchingWikis as $urls ) { |
| 207 | + // FIXME: don't use global esk variable names for non globals |
199 | 208 | foreach ( $urls as $url => $wgSharedHelpNamespaceFetchingWiki ) { |
200 | | - // only protect Help pages on non-help-pages-fetching wikis |
| 209 | + // only protect Help pages on non-help-pages-fetching wikis |
201 | 210 | if( $wgDBname != $wgSharedHelpNamespaceFetchingWiki ) { |
202 | 211 | // block actions 'edit' and 'create' |
203 | 212 | if( $action != 'edit' && $action != 'create' ) { |
204 | 213 | return true; |
205 | 214 | } |
206 | 215 | |
207 | | - $dbr = wfGetDB(DB_SLAVE, array(), $wgSharedHelpNamespaceFetchingWiki); |
208 | | - $res = $dbr->query( 'SELECT page_title, page_namespace FROM page WHERE page_namespace = 12 AND page_title = ' |
209 | | - . $dbr->addQuotes(str_replace( ' ', '_', $title->getText())) ); |
| 216 | + $dbr = wfGetDB( DB_SLAVE, array(), $wgSharedHelpNamespaceFetchingWiki ); |
| 217 | + $res = $dbr->select( |
| 218 | + 'page', |
| 219 | + array( 'page_title', 'page_namespace', 'page_latest' ), |
| 220 | + array( 'page_namespace' => 12, 'page_title' => str_replace( ' ', '_', $title->getText() ) ), |
| 221 | + __METHOD__ |
| 222 | + ); |
210 | 223 | |
211 | 224 | if ( $dbr->numRows( $res ) < 1 ) { |
212 | 225 | return true; |