Index: trunk/extensions/EditSimilar/EditSimilar.i18n.php |
— | — | @@ -2,6 +2,7 @@ |
3 | 3 | /** |
4 | 4 | * Internationalisation file for the EditSimilar extension |
5 | 5 | * |
| 6 | + * @file |
6 | 7 | * @ingroup Extensions |
7 | 8 | */ |
8 | 9 | |
— | — | @@ -12,18 +13,18 @@ |
13 | 14 | * @author Łukasz 'TOR' Garczewski |
14 | 15 | */ |
15 | 16 | $messages['en'] = array( |
16 | | - 'editsimilar-desc' => 'Encourages users to edit a similar page after saving a page', |
17 | | - 'editsimilar-thanks' => 'Thank you for your contribution. |
| 17 | + 'editsimilar-desc' => 'Encourages users to edit a similar page after saving a page', |
| 18 | + 'editsimilar-thanks' => 'Thank you for your contribution. |
18 | 19 | Check out these related pages: $1.', |
19 | | - 'editsimilar-thanks-singleresult' => 'Thank you for your contribution. |
| 20 | + 'editsimilar-thanks-singleresult' => 'Thank you for your contribution. |
20 | 21 | Check out this related page: $1.', |
21 | | - 'editsimilar-thanks-notsimilar' => 'Thank you for your contribution. |
| 22 | + 'editsimilar-thanks-notsimilar' => 'Thank you for your contribution. |
22 | 23 | These pages could also use your help: $1.', |
23 | 24 | 'editsimilar-thanks-notsimilar-singleresult' => 'Thank you for your contribution. |
24 | 25 | This page could also use your help: $1.', |
25 | | - 'editsimilar-thankyou' => 'Thank you for your contribution, $1!', |
26 | | - 'editsimilar-link-disable' => 'set preferences', |
27 | | - 'tog-edit-similar' => 'Enable similar pages suggestions', |
| 26 | + 'editsimilar-thankyou' => 'Thank you for your contribution, $1!', |
| 27 | + 'editsimilar-link-disable' => 'set preferences', |
| 28 | + 'tog-edit-similar' => 'Enable similar pages suggestions', |
28 | 29 | ); |
29 | 30 | |
30 | 31 | /** Message documentation (Message documentation) |
Index: trunk/extensions/EditSimilar/EditSimilar.php |
— | — | @@ -1,48 +1,40 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /** |
5 | | -* Extension that suggest editing of similar articles upon saving an article |
6 | | -* |
7 | | -* @package MediaWiki |
8 | | -* @subpackage Extensions |
9 | | -* |
10 | | -* @author Bartek Łapiński <bartek@wikia.com> |
11 | | -* @copyright Copyright © 2008, Wikia Inc. |
12 | | -* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
13 | | -*/ |
| 4 | + * Extension that suggests editing of similar articles upon saving an article |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + * @author Bartek Łapiński <bartek@wikia-inc.com> |
| 9 | + * @copyright Copyright © 2008, Wikia Inc. |
| 10 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 11 | + */ |
14 | 12 | |
15 | | -if (!defined('MEDIAWIKI')) |
16 | | - exit; |
| 13 | +if( !defined( 'MEDIAWIKI' ) ) |
| 14 | + die( "This is not a valid entry point.\n" ); |
17 | 15 | |
18 | 16 | global $wgExtensionFunctions; |
19 | 17 | |
20 | 18 | $dir = dirname(__FILE__); |
21 | 19 | $wgExtensionMessagesFiles['EditSimilar'] = $dir . '/EditSimilar.i18n.php'; |
22 | 20 | |
23 | | -if (empty ($wgEditSimilarMaxResultsPool ) ) { |
24 | | - // maximum number of results to choose from |
25 | | - $wgEditSimilarMaxResultsPool = 50; |
26 | | -} |
| 21 | +// maximum number of results to choose from |
| 22 | +$wgEditSimilarMaxResultsPool = 50; |
27 | 23 | |
28 | | -if (empty ($wgEditSimilarMaxResultsToDisplay)) { |
29 | | - // maximum number of results to display in text |
30 | | - $wgEditSimilarMaxResultsToDisplay = 3; |
31 | | -} |
| 24 | +// maximum number of results to display in text |
| 25 | +$wgEditSimilarMaxResultsToDisplay = 3; |
32 | 26 | |
33 | | -if (empty ($wgEditSimilarCounterValue)) { |
34 | | - // show message per specified number of edits |
35 | | - $wgEditSimilarCounterValue = 1; |
36 | | -} |
| 27 | +// show message per specified number of edits |
| 28 | +$wgEditSimilarCounterValue = 1; |
37 | 29 | |
38 | 30 | $wgExtensionFunctions[] = 'wfEditSimilarSetup'; |
39 | 31 | |
40 | 32 | $wgExtensionCredits['other'][] = array( |
41 | | - 'name' => 'EditSimilar', |
42 | | - 'version' => '1.17', |
43 | | - 'author' => array('Bartek Łapiński', '[http://inside.wikia.com/wiki/User:TOR Łukasz \'TOR\' Garczewski]'), |
44 | | - 'url' => 'http://www.mediawiki.org/wiki/Extension:EditSimilar', |
45 | | - 'description' => 'Encourages users to edit an article similar (by categories) to the one they just had edited.', |
46 | | - 'descriptionmsg' => 'editsimilar-desc', |
| 33 | + 'name' => 'EditSimilar', |
| 34 | + 'version' => '1.17', |
| 35 | + 'author' => array( 'Bartek Łapiński', "Łukasz 'TOR' Garczewski" ), |
| 36 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:EditSimilar', |
| 37 | + 'description' => 'Encourages users to edit an article similar (by categories) to the one they just had edited.', |
| 38 | + 'descriptionmsg' => 'editsimilar-desc', |
47 | 39 | ); |
48 | 40 | |
49 | 41 | /* |
— | — | @@ -76,7 +68,7 @@ |
77 | 69 | var $mSimilarArticles; // to differentiate between really similar results or just needing attention |
78 | 70 | |
79 | 71 | // constructor |
80 | | - function __construct ($article, $markertype = 'category') { |
| 72 | + function __construct( $article, $markertype = 'category' ) { |
81 | 73 | global $wgEditSimilarMaxResultsPool; |
82 | 74 | $this->mBaseArticle = $article; |
83 | 75 | $this->mMarkerType = $markertype; |
— | — | @@ -87,72 +79,71 @@ |
88 | 80 | } |
89 | 81 | |
90 | 82 | // fetch categories marked as 'stub categories' |
91 | | - function getStubCategories () { |
92 | | - $stub_categories = wfMsgForContent('EditSimilar-Categories'); |
| 83 | + function getStubCategories() { |
| 84 | + $stub_categories = wfMsgForContent( 'EditSimilar-Categories' ); |
93 | 85 | if ( ('<EditSimilar-Categories>' == $stub_categories) || ('' == $stub_categories) || ('-' == $stub_categories) ) { |
94 | 86 | return false; |
95 | 87 | } else { |
96 | | - $lines = preg_split ("/\*/", $stub_categories); |
| 88 | + $lines = preg_split( "/\*/", $stub_categories ); |
97 | 89 | $normalised_lines = array(); |
98 | | - array_shift($lines); |
99 | | - foreach ($lines as $line) { |
100 | | - $normalised_lines[] = str_replace(" ", "_", trim ($line)); |
| 90 | + array_shift( $lines ); |
| 91 | + foreach( $lines as $line ) { |
| 92 | + $normalised_lines[] = str_replace( ' ', '_', trim( $line ) ); |
101 | 93 | } |
102 | 94 | return $normalised_lines; |
103 | 95 | } |
104 | 96 | } |
105 | 97 | |
106 | 98 | // this is the main function that returns articles we deem similar or worth showing |
107 | | - function getSimilarArticles () { |
108 | | - global $wgUser, $wgEditSimilarMarker; |
109 | | - global $wgEditSimilarMaxResultsToDisplay; |
| 99 | + function getSimilarArticles() { |
| 100 | + global $wgUser, $wgEditSimilarMaxResultsToDisplay; |
110 | 101 | |
111 | | - if (empty ($this->mAttentionMarkers) || !$this->mAttentionMarkers) { |
| 102 | + if( empty( $this->mAttentionMarkers ) || !$this->mAttentionMarkers ) { |
112 | 103 | return false; |
113 | 104 | } |
114 | 105 | $text = ''; |
115 | 106 | $articles = array(); |
116 | 107 | $x = 0; |
117 | 108 | |
118 | | - while ( (count ($articles) < $wgEditSimilarMaxResultsToDisplay) && ($x < count ($this->mAttentionMarkers)) ) { |
119 | | - $articles = array_merge ($articles, $this->getResults ($this->mAttentionMarkers [$x]) ); |
120 | | - if (!empty ($articles)) { |
121 | | - $articles = array_unique($articles); |
| 109 | + while ( ( count( $articles ) < $wgEditSimilarMaxResultsToDisplay ) && ( $x < count( $this->mAttentionMarkers ) ) ) { |
| 110 | + $articles = array_merge( $articles, $this->getResults( $this->mAttentionMarkers[$x] ) ); |
| 111 | + if( !empty( $articles ) ) { |
| 112 | + $articles = array_unique( $articles ); |
122 | 113 | } |
123 | 114 | $x++; |
124 | 115 | } |
125 | 116 | |
126 | | - if (empty ($articles) ) { |
| 117 | + if( empty( $articles ) ) { |
127 | 118 | $articles = $this->getAdditionalCheck(); |
128 | 119 | // second check to make sure we have anything to display |
129 | | - if (empty ($articles) ) { |
| 120 | + if( empty( $articles ) ) { |
130 | 121 | return false; |
131 | 122 | } |
132 | | - $articles = array_unique($articles); |
| 123 | + $articles = array_unique( $articles ); |
133 | 124 | $this->mSimilarArticles = false; |
134 | 125 | } |
135 | 126 | |
136 | | - if (1 == count ($articles)) { // in this case, array_rand returns a single element, not an array |
137 | | - $rand_articles = array(0); |
| 127 | + if( 1 == count( $articles ) ) { // in this case, array_rand returns a single element, not an array |
| 128 | + $rand_articles = array( 0 ); |
138 | 129 | } else { |
139 | | - $rand_articles = array_rand ($articles, min ($wgEditSimilarMaxResultsToDisplay, count ($articles)) ); |
| 130 | + $rand_articles = array_rand( $articles, min( $wgEditSimilarMaxResultsToDisplay, count( $articles ) ) ); |
140 | 131 | } |
141 | 132 | $sk = $wgUser->getSkin(); |
142 | | - $skinname = get_class($sk); |
143 | | - $skinname = strtolower( substr($skinname, 4) ); |
| 133 | + $skinname = get_class( $sk ); |
| 134 | + $skinname = strtolower( substr( $skinname, 4 ) ); |
144 | 135 | $real_rand_values = array(); |
145 | | - if (empty ($rand_articles)) { |
| 136 | + if( empty( $rand_articles ) ) { |
146 | 137 | return false; |
147 | 138 | } |
148 | 139 | |
149 | 140 | $translated_titles = array(); |
150 | | - foreach ($rand_articles as $r_key => $rand_article_key) { |
| 141 | + foreach( $rand_articles as $r_key => $rand_article_key ) { |
151 | 142 | $translated_titles[] = $articles [$rand_article_key]; |
152 | 143 | } |
153 | | - $translated_titles = $this->idsToTitles($translated_titles); |
| 144 | + $translated_titles = $this->idsToTitles( $translated_titles ); |
154 | 145 | |
155 | | - foreach ($translated_titles as $link_title) { |
156 | | - $article_link = $sk->makeKnownLinkObj($link_title); |
| 146 | + foreach( $translated_titles as $link_title ) { |
| 147 | + $article_link = $sk->makeKnownLinkObj( $link_title ); |
157 | 148 | $real_rand_values[] = $article_link; |
158 | 149 | } |
159 | 150 | |
— | — | @@ -160,30 +151,31 @@ |
161 | 152 | } |
162 | 153 | |
163 | 154 | // extract all categories our base article is in |
164 | | - function getBaseCategories () { |
| 155 | + function getBaseCategories() { |
165 | 156 | global $wgEditSimilarMaxResultsToDisplay; |
166 | | - if (empty ($this->mAttentionMarkers) || !$this->mAttentionMarkers) { |
| 157 | + if( empty( $this->mAttentionMarkers ) || !$this->mAttentionMarkers ) { |
167 | 158 | return false; |
168 | 159 | } |
169 | 160 | |
170 | 161 | $dbr = wfGetDB( DB_SLAVE ); |
171 | 162 | $result_array = array(); |
172 | | - $res = $dbr->select ( |
173 | | - array ('categorylinks'), |
174 | | - array ('cl_to'), |
175 | | - array ( 'cl_from' => $this->mBaseArticle ), |
| 163 | + $res = $dbr->select( |
| 164 | + array( 'categorylinks' ), |
| 165 | + array( 'cl_to' ), |
| 166 | + array( 'cl_from' => $this->mBaseArticle ), |
176 | 167 | __METHOD__, |
177 | | - array ( 'ORDER_BY' => 'cl_from', |
| 168 | + array( |
| 169 | + 'ORDER_BY' => 'cl_from', |
178 | 170 | 'USE_INDEX' => 'cl_from' |
179 | 171 | ) |
180 | | - ) ; |
181 | | - while( $x = $dbr->fetchObject ( $res ) ) { |
182 | | - if (!in_array ($x->cl_to, $this->mAttentionMarkers) ) { |
183 | | - $result_array [] = $x->cl_to; |
184 | | - } |
| 172 | + ); |
| 173 | + while( $x = $dbr->fetchObject( $res ) ) { |
| 174 | + if( !in_array( $x->cl_to, $this->mAttentionMarkers ) ) { |
| 175 | + $result_array [] = $x->cl_to; |
185 | 176 | } |
| 177 | + } |
186 | 178 | |
187 | | - if (!empty ($result_array) ) { |
| 179 | + if( !empty( $result_array ) ) { |
188 | 180 | return $result_array; |
189 | 181 | } else { |
190 | 182 | return false; |
— | — | @@ -198,96 +190,96 @@ |
199 | 191 | this is to ensure we can get always (well, almost - if "marker" categories get no results, it's dead in the water anyway) |
200 | 192 | some results |
201 | 193 | */ |
202 | | - function getAdditionalCheck () { |
| 194 | + function getAdditionalCheck() { |
203 | 195 | $dbr = wfGetDB( DB_SLAVE ); |
204 | 196 | |
205 | | - $query = "SELECT cl_from |
206 | | - FROM categorylinks |
207 | | - WHERE cl_to IN ("; |
208 | | - |
209 | 197 | $fixed_names = array(); |
210 | | - foreach ($this->mAttentionMarkers as $category) { |
211 | | - $fixed_names[] = $dbr->addQuotes($category); |
| 198 | + foreach( $this->mAttentionMarkers as $category ) { |
| 199 | + $fixed_names[] = $dbr->addQuotes( $category ); |
212 | 200 | } |
213 | | - $stringed_names = implode (",", $fixed_names); |
214 | | - $query .= $stringed_names . ")"; |
| 201 | + $stringed_names = implode( ",", $fixed_names ); |
215 | 202 | |
216 | | - $res = $dbr->query($query, __METHOD__); |
| 203 | + $res = $dbr->select( |
| 204 | + 'categorylinks', |
| 205 | + array( 'cl_from' ), |
| 206 | + array( "cl_to IN ($stringed_names)" ), |
| 207 | + __METHOD__ |
| 208 | + ); |
| 209 | + |
217 | 210 | $result_array = array(); |
218 | | - while( $x = $dbr->fetchObject ( $res ) ) { |
219 | | - if ($this->mBaseArticle != $x->cl_from) { |
220 | | - $result_array[] = $x->cl_from; |
221 | | - } |
222 | | - } |
223 | | - $dbr->freeResult( $res ); |
| 211 | + while( $x = $dbr->fetchObject( $res ) ) { |
| 212 | + if( $this->mBaseArticle != $x->cl_from ) { |
| 213 | + $result_array[] = $x->cl_from; |
| 214 | + } |
| 215 | + } |
| 216 | + $dbr->freeResult( $res ); |
224 | 217 | |
225 | 218 | return $result_array; |
226 | | - |
227 | 219 | } |
228 | 220 | |
229 | 221 | // one function to turn result ids into titles in one query rather than multiple ones |
230 | | - function idsToTitles ($id_array) { |
| 222 | + function idsToTitles( $id_array ) { |
231 | 223 | global $wgContentNamespaces; |
232 | | - $dbr = wfGetDB( DB_SLAVE ); |
233 | | - $query = "SELECT page_namespace, page_title |
234 | | - FROM page |
235 | | - WHERE page_id IN ("; |
| 224 | + $dbr = wfGetDB( DB_SLAVE ); |
| 225 | + $stringed_names = implode( ",", $id_array ); |
| 226 | + $res = $dbr->select( |
| 227 | + 'page', |
| 228 | + array( 'page_namespace', 'page_title' ), |
| 229 | + array( "page_id IN ($stringed_names)" ), |
| 230 | + __METHOD__ |
| 231 | + ); |
236 | 232 | |
237 | | - $stringed_names = implode (",", $id_array); |
238 | | - $query .= $stringed_names . ")"; |
| 233 | + $result_array = array(); |
239 | 234 | |
240 | | - $res = $dbr->query ($query, __METHOD__); |
241 | | - $result_array = array(); |
242 | | - |
243 | 235 | // so for now, to speed things up, just discard results from other namespaces (and subpages) |
244 | | - while( ($x = $dbr->fetchObject ( $res )) |
245 | | - && (in_array ($x->page_namespace, $wgContentNamespaces)) |
246 | | - && false === strpos ($x->page_title, "/") ) { |
247 | | - $result_array[] = Title::makeTitle($x->page_namespace, $x->page_title); |
248 | | - } |
| 236 | + while( ( $x = $dbr->fetchObject( $res ) ) |
| 237 | + && ( in_array( $x->page_namespace, $wgContentNamespaces ) ) |
| 238 | + && false === strpos( $x->page_title, "/" ) ) { |
| 239 | + $result_array[] = Title::makeTitle( $x->page_namespace, $x->page_title ); |
| 240 | + } |
249 | 241 | |
250 | | - $dbr->freeResult( $res ); |
251 | | - return $result_array; |
| 242 | + $dbr->freeResult( $res ); |
| 243 | + return $result_array; |
252 | 244 | } |
253 | 245 | |
254 | 246 | // get categories from the 'stub' or 'attention needed' category |
255 | | - function getResults ($marker_category) { |
256 | | - $dbr = wfGetDB( DB_SLAVE ); |
257 | | - $title = Title::makeTitle(NS_CATEGORY, $marker_category); |
| 247 | + function getResults( $marker_category ) { |
| 248 | + $dbr = wfGetDB( DB_SLAVE ); |
| 249 | + $title = Title::makeTitle( NS_CATEGORY, $marker_category ); |
258 | 250 | $result_array = array(); |
259 | 251 | |
260 | | - if (empty ($this->mBaseCategories)) { |
| 252 | + if( empty( $this->mBaseCategories ) ) { |
261 | 253 | return $result_array; |
262 | 254 | } |
263 | 255 | |
264 | 256 | $query = "SELECT c1.cl_from |
265 | | - FROM categorylinks as c1, categorylinks as c2 |
266 | | - WHERE c1.cl_from = c2.cl_from |
267 | | - AND c1.cl_to = " .$dbr->addQuotes ($title->getDBKey ()) . " |
| 257 | + FROM {$dbr->tableName( 'categorylinks' )} AS c1, {$dbr->tableName( 'categorylinks' )} AS c2 |
| 258 | + WHERE c1.cl_from = c2.cl_from |
| 259 | + AND c1.cl_to = " .$dbr->addQuotes( $title->getDBkey() ) . " |
268 | 260 | AND c2.cl_to IN ("; |
269 | 261 | |
270 | 262 | $fixed_names = array(); |
271 | | - foreach ($this->mBaseCategories as $category) { |
272 | | - $fixed_names[] = $dbr->addQuotes($category); |
| 263 | + foreach( $this->mBaseCategories as $category ) { |
| 264 | + $fixed_names[] = $dbr->addQuotes( $category ); |
273 | 265 | } |
274 | | - $stringed_names = implode (",", $fixed_names); |
| 266 | + $stringed_names = implode( ",", $fixed_names ); |
275 | 267 | $query .= $stringed_names . ")"; |
276 | 268 | |
277 | | - $res = $dbr->query ($query, __METHOD__); |
278 | | - while( $x = $dbr->fetchObject ( $res ) ) { |
279 | | - if ($this->mBaseArticle != $x->cl_from) { |
| 269 | + $res = $dbr->query( $query, __METHOD__ ); |
| 270 | + while( $x = $dbr->fetchObject( $res ) ) { |
| 271 | + if( $this->mBaseArticle != $x->cl_from ) { |
280 | 272 | $result_array[] = $x->cl_from; |
281 | 273 | } |
282 | | - } |
283 | | - $dbr->freeResult( $res ); |
| 274 | + } |
| 275 | + $dbr->freeResult( $res ); |
284 | 276 | |
285 | 277 | return $result_array; |
286 | 278 | } |
287 | 279 | |
288 | 280 | // message box wrapper |
289 | | - static public function showMessage ($text) { |
| 281 | + static public function showMessage( $text ) { |
290 | 282 | global $wgOut, $wgUser, $wgScript; |
291 | | - $wgOut->addHTML (" |
| 283 | + $wgOut->addHTML( " |
292 | 284 | <style type=\"text/css\"> |
293 | 285 | .editsimilar { |
294 | 286 | background-color: #c0fec0; |
— | — | @@ -299,114 +291,113 @@ |
300 | 292 | font-size:0.9em; |
301 | 293 | } |
302 | 294 | </style> |
303 | | - ") ; |
304 | | - if ($wgUser->isLoggedIn () ) { |
305 | | - $link = "<div class=\"editsimilar_dismiss\">[<span class=\"plainlinks\"><a href=\"" . $wgScript . "?title=Special:Preferences#prefsection-4\" id=\"editsimilar_preferences\">" . wfMsg('editsimilar-link-disable') . "</a></span>]</div><div style=\"display:block\"> </div>"; |
| 295 | + "); |
| 296 | + if( $wgUser->isLoggedIn() ) { |
| 297 | + $link = '<div class="editsimilar_dismiss">[<span class="plainlinks"><a href="' . $wgScript . '?title=Special:Preferences#prefsection-4" id="editsimilar_preferences">' . wfMsg( 'editsimilar-link-disable' ) . '</a></span>]</div><div style="display:block"> </div>'; |
306 | 298 | } else { |
307 | 299 | $link = ''; |
308 | 300 | } |
309 | | - $wgOut->addHTML ("<div id=\"editsimilar_links\" class=\"usermessage editsimilar\"><div>" . $text . "</div>" . $link . "</div>"); |
| 301 | + $wgOut->addHTML( '<div id="editsimilar_links" class="usermessage editsimilar"><div>' . $text . '</div>' . $link . '</div>' ); |
310 | 302 | } |
311 | 303 | |
312 | | - |
313 | 304 | // this is for determining whether to display the message or not |
314 | | - static public function checkCounter () { |
| 305 | + static public function checkCounter() { |
315 | 306 | global $wgEditSimilarCounterValue; |
316 | | - if (isset ($_SESSION ['ES_counter'])) { |
317 | | - $_SESSION ['ES_counter'] --; |
318 | | - if ($_SESSION ['ES_counter'] > 0) { |
| 307 | + if( isset( $_SESSION['ES_counter'] ) ) { |
| 308 | + $_SESSION['ES_counter']--; |
| 309 | + if( $_SESSION['ES_counter'] > 0 ) { |
319 | 310 | return false; |
320 | 311 | } else { |
321 | | - $_SESSION ['ES_counter'] = $wgEditSimilarCounterValue; |
| 312 | + $_SESSION['ES_counter'] = $wgEditSimilarCounterValue; |
322 | 313 | return true; |
323 | 314 | } |
324 | 315 | } else { |
325 | | - $_SESSION ['ES_counter'] = $wgEditSimilarCounterValue; |
| 316 | + $_SESSION['ES_counter'] = $wgEditSimilarCounterValue; |
326 | 317 | return true; |
327 | 318 | } |
328 | 319 | } |
329 | 320 | } |
330 | 321 | |
331 | | -function wfEditSimilarSetup () { |
| 322 | +function wfEditSimilarSetup() { |
332 | 323 | global $wgHooks, $wgUser; |
333 | 324 | $wgHooks['ArticleSaveComplete'][] = 'wfEditSimilarCheck'; |
334 | 325 | $wgHooks['OutputPageBeforeHTML'][] = 'wfEditSimilarViewMesg'; |
335 | | - if ( $wgUser->isLoggedIn ()) { |
| 326 | + if ( $wgUser->isLoggedIn() ) { |
336 | 327 | $wgHooks['getEditingPreferencesCustomHtml'][] = 'wfEditSimilarPrefCustomHtml'; |
337 | 328 | $wgHooks['UserToggles'][] = 'wfEditSimilarToggle'; |
338 | 329 | } |
339 | 330 | } |
340 | 331 | |
341 | 332 | // check if we had the extension enabled at all and if this is in a content namespace |
342 | | -function wfEditSimilarCheck ($article) { |
| 333 | +function wfEditSimilarCheck( $article ) { |
343 | 334 | global $wgOut, $wgUser, $wgContentNamespaces; |
344 | 335 | |
345 | 336 | $namespace = $article->getTitle()->getNamespace(); |
346 | | - if ( (1 == $wgUser->getOption('edit-similar', 1)) && (in_array ($namespace, $wgContentNamespaces)) ) { |
| 337 | + if ( ( 1 == $wgUser->getOption( 'edit-similar', 1 ) ) && ( in_array( $namespace, $wgContentNamespaces ) ) ) { |
347 | 338 | $_SESSION ['ES_saved'] = 'yes'; |
348 | 339 | } |
349 | 340 | return true; |
350 | 341 | } |
351 | 342 | |
352 | 343 | //view message depending on settings and the relevancy of the results |
353 | | -function wfEditSimilarViewMesg (&$out) { |
| 344 | +function wfEditSimilarViewMesg( &$out ) { |
354 | 345 | global $wgTitle, $wgUser, $wgEditSimilarAlwaysShowThanks; |
355 | | - wfLoadExtensionMessages('EditSimilar'); |
356 | | - if ( !empty ($_SESSION ['ES_saved']) && (1 == $wgUser->getOption ('edit-similar', 1) ) && $out->isArticle ()) { |
357 | | - if (EditSimilar::checkCounter ()) { |
| 346 | + wfLoadExtensionMessages( 'EditSimilar' ); |
| 347 | + if ( !empty( $_SESSION['ES_saved'] ) && ( 1 == $wgUser->getOption( 'edit-similar', 1 ) ) && $out->isArticle() ) { |
| 348 | + if( EditSimilar::checkCounter() ) { |
358 | 349 | $message_text = ''; |
359 | 350 | $article_title = $wgTitle->getText(); |
360 | 351 | // here we'll populate the similar articles and links |
361 | | - $SInstance = new EditSimilar ($wgTitle->getArticleId(), 'category'); |
| 352 | + $SInstance = new EditSimilar( $wgTitle->getArticleId(), 'category' ); |
362 | 353 | $similarities = $SInstance->getSimilarArticles(); |
363 | | - if (!empty($similarities)) { |
364 | | - if ($SInstance->mSimilarArticles) { |
365 | | - if (count($similarities) > 1) { |
366 | | - $message_text = wfMsg('editsimilar-thanks', implode (", ", $similarities)); |
| 354 | + if( !empty( $similarities ) ) { |
| 355 | + if( $SInstance->mSimilarArticles ) { |
| 356 | + if( count( $similarities ) > 1 ) { |
| 357 | + $message_text = wfMsg( 'editsimilar-thanks', implode( ", ", $similarities ) ); |
367 | 358 | } else { |
368 | | - $message_text = wfMsg('editsimilar-thanks-singleresult', implode (", ", $similarities)); |
| 359 | + $message_text = wfMsg( 'editsimilar-thanks-singleresult', implode( ", ", $similarities ) ); |
369 | 360 | } |
370 | 361 | } else { // the articles we found were rather just articles needing attention |
371 | | - if (count($similarities) > 1) { |
372 | | - $message_text = wfMsg('editsimilar-thanks-notsimilar', implode (", ", $similarities)); |
| 362 | + if( count( $similarities ) > 1 ) { |
| 363 | + $message_text = wfMsg( 'editsimilar-thanks-notsimilar', implode( ", ", $similarities ) ); |
373 | 364 | } else { |
374 | | - $message_text = wfMsg('editsimilar-thanks-notsimilar-singleresult', implode (", ", $similarities)); |
| 365 | + $message_text = wfMsg( 'editsimilar-thanks-notsimilar-singleresult', implode( ", ", $similarities ) ); |
375 | 366 | } |
376 | 367 | } |
377 | 368 | } else { |
378 | | - if ($wgUser->isLoggedIn () && !empty ($wgEditSimilarAlwaysShowThanks)) { |
379 | | - $message_text = wfMsg ('editsimilar-thankyou', $wgUser->getName ()); |
| 369 | + if( $wgUser->isLoggedIn() && !empty( $wgEditSimilarAlwaysShowThanks ) ) { |
| 370 | + $message_text = wfMsg( 'editsimilar-thankyou', $wgUser->getName() ); |
380 | 371 | } |
381 | 372 | } |
382 | 373 | |
383 | | - if ('' != $message_text) { |
384 | | - EditSimilar::showMessage($message_text, $article_title); |
| 374 | + if( '' != $message_text ) { |
| 375 | + EditSimilar::showMessage( $message_text, $article_title ); |
385 | 376 | } |
386 | 377 | } |
387 | | - //display that only once |
388 | | - $_SESSION ['ES_saved'] = ''; |
| 378 | + // display that only once |
| 379 | + $_SESSION['ES_saved'] = ''; |
389 | 380 | } |
390 | 381 | return true; |
391 | 382 | } |
392 | 383 | |
393 | 384 | // a customized version of getToggle from SpecialPreferences |
394 | 385 | // this one uses getOption with a default - so we can have it checked if unset |
395 | | -function wfEditSimilarPrefCustomHtml ($prefsForm) { |
396 | | - wfLoadExtensionMessages('EditSimilar'); |
| 386 | +function wfEditSimilarPrefCustomHtml( $prefsForm ) { |
| 387 | + wfLoadExtensionMessages( 'EditSimilar' ); |
397 | 388 | global $wgOut, $wgUser, $wgLang; |
398 | 389 | $tname = 'edit-similar'; |
399 | | - $prefsForm->mUsedToggles [$tname] = true; |
400 | | - $ttext = $wgLang->getUserToggle($tname); |
| 390 | + $prefsForm->mUsedToggles[$tname] = true; |
| 391 | + $ttext = $wgLang->getUserToggle( $tname ); |
401 | 392 | // the catch lies here |
402 | | - $checked = $wgUser->getOption($tname, 1) == 1 ? ' checked="checked"' : ''; |
| 393 | + $checked = $wgUser->getOption( $tname, 1 ) == 1 ? ' checked="checked"' : ''; |
403 | 394 | |
404 | | - $wgOut->addHTML ("<div class='toggle'><input type='checkbox' value='1' id=\"$tname\" name=\"wpOp$tname\"$checked />" . |
405 | | - " <span class='toggletext'><label for=\"$tname\">$ttext</label></span></div>\n"); |
| 395 | + $wgOut->addHTML( "<div class='toggle'><input type='checkbox' value='1' id=\"$tname\" name=\"wpOp$tname\"$checked />" . |
| 396 | + " <span class='toggletext'><label for=\"$tname\">$ttext</label></span></div>\n" ); |
406 | 397 | return true; |
407 | 398 | } |
408 | 399 | |
409 | | -function wfEditSimilarToggle ($toggles) { |
410 | | - wfLoadExtensionMessages('EditSimilar'); |
| 400 | +function wfEditSimilarToggle( $toggles ) { |
| 401 | + wfLoadExtensionMessages( 'EditSimilar' ); |
411 | 402 | $toggles['edit-similar'] = 'edit-similar'; |
412 | | - return true; |
| 403 | + return true; |
413 | 404 | } |
\ No newline at end of file |