Index: trunk/extensions/EditSimilar/EditSimilar.class.php |
— | — | @@ -1,61 +1,109 @@ |
2 | 2 | <?php |
3 | | -/* |
4 | | - How this extension works: |
5 | | - - upon save, the script searches for articles that are similar |
6 | | - right now, I have assumed the following criteria: |
7 | | - * articles that need attention |
8 | | - * articles similar in category to the one we edited |
9 | | - * if no similar articles were found, we're taking results straight from categories that need attention |
10 | | - * number of articles in result is limited |
| 3 | +/** |
| 4 | + * How this extension works: |
| 5 | + * - upon save, the script searches for articles that are similar |
| 6 | + * right now, I have assumed the following criteria: |
| 7 | + * ** articles that need attention |
| 8 | + * ** articles similar in category to the one we edited |
| 9 | + * ** if no similar articles were found, we're taking results straight from |
| 10 | + * categories that need attention |
| 11 | + * ** number of articles in result is limited |
| 12 | + * |
| 13 | + * IMPORTANT NOTE: This extension REQUIRES the article |
| 14 | + * MediaWiki:EditSimilar-Categories to exist on your wiki in order to run. |
| 15 | + * If this article is nonexistent, the extension will disable itself. |
| 16 | + * |
| 17 | + * Format of the article is as follows: |
| 18 | + * * Chosen Stub Category 1 |
| 19 | + * * Chosen Stub Category 2 |
| 20 | + * etc. (separated by stars) |
| 21 | + * |
| 22 | + * Insert '-' if you want to disable the extension without blanking the |
| 23 | + * commanding article. |
| 24 | + * |
| 25 | + * @file |
| 26 | + */ |
11 | 27 | |
12 | | - IMPORTANT NOTE: This extension REQUIRES the article MediaWiki:EditSimilar-Categories to exist on your |
13 | | - wiki in order to run. If this article is nonexistent, the extension will disable itself. |
14 | | - Format of the article is as follows: |
15 | | - * Chosen Stub Category 1 |
16 | | - * Chosen Stub Category 2 |
17 | | - etc. (separated by stars) |
| 28 | +class EditSimilar { |
| 29 | + var $mBaseArticle; // the article from which we hail in our quest for similiarities, this is its title |
18 | 30 | |
19 | | - insert '-' if you want to disable the extension without blanking the commanding article |
| 31 | + /** |
| 32 | + * @var String: how do we mark articles that need attention? Currently, by |
| 33 | + * category only |
| 34 | + */ |
| 35 | + var $mMarkerType; |
20 | 36 | |
21 | | -*/ |
| 37 | + /** |
| 38 | + * @var Array: the marker array (for now it contains categories) |
| 39 | + */ |
| 40 | + var $mAttentionMarkers; |
22 | 41 | |
23 | | -class EditSimilar { |
24 | | - var $mBaseArticle; // the article from which we hail in our quest for similiarities, this is its title |
25 | | - var $mMarkerType; // how do we mark articles that need attention? currently, by category only |
26 | | - var $mAttentionMarkers; // the marker array (for now it contains categories) |
27 | | - var $mMatchType; // how do we match articles as a secondary |
28 | | - var $mPoolLimit; // limit up the pool of 'stubs' to choose from |
29 | | - var $mBaseCategories; // extracted categories that this saved article is in |
30 | | - var $mSimilarArticles; // to differentiate between really similar results or just needing attention |
| 42 | + /** |
| 43 | + * @var Integer: limit up the pool of 'stubs' to choose from, controlled |
| 44 | + * via the $wgEditSimilarMaxResultsPool global variable |
| 45 | + */ |
| 46 | + var $mPoolLimit; |
31 | 47 | |
32 | | - // constructor |
33 | | - function __construct( $article, $markertype = 'category' ) { |
| 48 | + /** |
| 49 | + * @var Array: array of extracted categories that this saved article is in |
| 50 | + */ |
| 51 | + var $mBaseCategories; |
| 52 | + |
| 53 | + /** |
| 54 | + * @var Boolean: to differentiate between really similar results or just |
| 55 | + * needing attention |
| 56 | + */ |
| 57 | + var $mSimilarArticles; |
| 58 | + |
| 59 | + /** |
| 60 | + * Constructor |
| 61 | + * |
| 62 | + * @param $article Integer: article ID number |
| 63 | + * @param $markerType String: always 'category' |
| 64 | + */ |
| 65 | + public function __construct( $article, $markerType = 'category' ) { |
34 | 66 | global $wgEditSimilarMaxResultsPool; |
35 | 67 | $this->mBaseArticle = $article; |
36 | | - $this->mMarkerType = $markertype; |
| 68 | + $this->mMarkerType = $markerType; |
37 | 69 | $this->mAttentionMarkers = $this->getStubCategories(); |
38 | 70 | $this->mPoolLimit = $wgEditSimilarMaxResultsPool; |
39 | 71 | $this->mBaseCategories = $this->getBaseCategories(); |
40 | 72 | $this->mSimilarArticles = true; |
41 | 73 | } |
42 | 74 | |
43 | | - // fetch categories marked as 'stub categories' |
| 75 | + /** |
| 76 | + * Fetch categories marked as 'stub categories', controlled via the |
| 77 | + * MediaWiki:EditSimilar-Categories interface message. |
| 78 | + * |
| 79 | + * @return Array|Boolean: array of category names on success, false on |
| 80 | + * failure (if MediaWiki:EditSimilar-Categories is |
| 81 | + * empty or contains -) |
| 82 | + */ |
44 | 83 | function getStubCategories() { |
45 | | - $stub_categories = wfMsgForContent( 'EditSimilar-Categories' ); |
46 | | - if ( ( '<EditSimilar-Categories>' == $stub_categories ) || ( '' == $stub_categories ) || ( '-' == $stub_categories ) ) { |
| 84 | + $stubCategories = wfMsgForContent( 'EditSimilar-Categories' ); |
| 85 | + if ( |
| 86 | + ( '<EditSimilar-Categories>' == $stubCategories ) || |
| 87 | + ( '' == $stubCategories ) || ( '-' == $stubCategories ) |
| 88 | + ) |
| 89 | + { |
47 | 90 | return false; |
48 | 91 | } else { |
49 | | - $lines = preg_split( "/\*/", $stub_categories ); |
50 | | - $normalised_lines = array(); |
| 92 | + $lines = preg_split( '/\*/', $stubCategories ); |
| 93 | + $normalisedLines = array(); |
51 | 94 | array_shift( $lines ); |
52 | 95 | foreach ( $lines as $line ) { |
53 | | - $normalised_lines[] = str_replace( ' ', '_', trim( $line ) ); |
| 96 | + $normalisedLines[] = str_replace( ' ', '_', trim( $line ) ); |
54 | 97 | } |
55 | | - return $normalised_lines; |
| 98 | + return $normalisedLines; |
56 | 99 | } |
57 | 100 | } |
58 | 101 | |
59 | | - // this is the main function that returns articles we deem similar or worth showing |
| 102 | + /** |
| 103 | + * Main function that returns articles we deem similar or worth showing |
| 104 | + * |
| 105 | + * @return Array|Boolean: array of article names on success, false on |
| 106 | + * failure |
| 107 | + */ |
60 | 108 | function getSimilarArticles() { |
61 | 109 | global $wgUser, $wgEditSimilarMaxResultsToDisplay; |
62 | 110 | |
— | — | @@ -66,8 +114,15 @@ |
67 | 115 | $articles = array(); |
68 | 116 | $x = 0; |
69 | 117 | |
70 | | - while ( ( count( $articles ) < $wgEditSimilarMaxResultsToDisplay ) && ( $x < count( $this->mAttentionMarkers ) ) ) { |
71 | | - $articles = array_merge( $articles, $this->getResults( $this->mAttentionMarkers[$x] ) ); |
| 118 | + while ( |
| 119 | + ( count( $articles ) < $wgEditSimilarMaxResultsToDisplay ) && |
| 120 | + ( $x < count( $this->mAttentionMarkers ) ) |
| 121 | + ) |
| 122 | + { |
| 123 | + $articles = array_merge( |
| 124 | + $articles, |
| 125 | + $this->getResults( $this->mAttentionMarkers[$x] ) |
| 126 | + ); |
72 | 127 | if ( !empty( $articles ) ) { |
73 | 128 | $articles = array_unique( $articles ); |
74 | 129 | } |
— | — | @@ -84,42 +139,51 @@ |
85 | 140 | $this->mSimilarArticles = false; |
86 | 141 | } |
87 | 142 | |
88 | | - if ( 1 == count( $articles ) ) { // in this case, array_rand returns a single element, not an array |
| 143 | + if ( count( $articles ) == 1 ) { // in this case, array_rand returns a single element, not an array |
89 | 144 | $rand_articles = array( 0 ); |
90 | 145 | } else { |
91 | | - $rand_articles = array_rand( $articles, min( $wgEditSimilarMaxResultsToDisplay, count( $articles ) ) ); |
| 146 | + $rand_articles = array_rand( |
| 147 | + $articles, |
| 148 | + min( $wgEditSimilarMaxResultsToDisplay, count( $articles ) ) |
| 149 | + ); |
92 | 150 | } |
| 151 | + |
93 | 152 | $sk = $wgUser->getSkin(); |
94 | | - $skinname = get_class( $sk ); |
95 | | - $skinname = strtolower( substr( $skinname, 4 ) ); |
96 | | - $real_rand_values = array(); |
| 153 | + $realRandValues = array(); |
| 154 | + |
97 | 155 | if ( empty( $rand_articles ) ) { |
98 | 156 | return false; |
99 | 157 | } |
100 | 158 | |
101 | | - $translated_titles = array(); |
| 159 | + $translatedTitles = array(); |
102 | 160 | foreach ( $rand_articles as $r_key => $rand_article_key ) { |
103 | | - $translated_titles[] = $articles [$rand_article_key]; |
| 161 | + $translatedTitles[] = $articles[$rand_article_key]; |
104 | 162 | } |
105 | | - $translated_titles = $this->idsToTitles( $translated_titles ); |
| 163 | + $translatedTitles = $this->idsToTitles( $translatedTitles ); |
106 | 164 | |
107 | | - foreach ( $translated_titles as $link_title ) { |
108 | | - $article_link = $sk->makeKnownLinkObj( $link_title ); |
109 | | - $real_rand_values[] = $article_link; |
| 165 | + foreach ( $translatedTitles as $linkTitle ) { |
| 166 | + $articleLink = $sk->makeKnownLinkObj( $linkTitle ); |
| 167 | + $realRandValues[] = $articleLink; |
110 | 168 | } |
111 | 169 | |
112 | | - return $real_rand_values; |
| 170 | + return $realRandValues; |
113 | 171 | } |
114 | 172 | |
115 | | - // extract all categories our base article is in |
| 173 | + /** |
| 174 | + * Extract all categories our base article is in |
| 175 | + * |
| 176 | + * @return Array|Boolean: array of category names on success, false on |
| 177 | + * failure |
| 178 | + */ |
116 | 179 | function getBaseCategories() { |
117 | 180 | global $wgEditSimilarMaxResultsToDisplay; |
| 181 | + |
118 | 182 | if ( empty( $this->mAttentionMarkers ) || !$this->mAttentionMarkers ) { |
119 | 183 | return false; |
120 | 184 | } |
121 | 185 | |
122 | 186 | $dbr = wfGetDB( DB_SLAVE ); |
123 | | - $result_array = array(); |
| 187 | + $resultArray = array(); |
124 | 188 | $res = $dbr->select( |
125 | 189 | array( 'categorylinks' ), |
126 | 190 | array( 'cl_to' ), |
— | — | @@ -130,127 +194,166 @@ |
131 | 195 | 'USE_INDEX' => 'cl_from' |
132 | 196 | ) |
133 | 197 | ); |
134 | | - while ( $x = $dbr->fetchObject( $res ) ) { |
| 198 | + |
| 199 | + foreach( $res as $x ) { |
135 | 200 | if ( !in_array( $x->cl_to, $this->mAttentionMarkers ) ) { |
136 | | - $result_array[] = $x->cl_to; |
| 201 | + $resultArray[] = $x->cl_to; |
137 | 202 | } |
138 | 203 | } |
139 | 204 | |
140 | | - if ( !empty( $result_array ) ) { |
141 | | - return $result_array; |
| 205 | + if ( !empty( $resultArray ) ) { |
| 206 | + return $resultArray; |
142 | 207 | } else { |
143 | 208 | return false; |
144 | 209 | } |
145 | 210 | } |
146 | 211 | |
147 | | - /* |
148 | | - latest addition: if we got no results at all (indicating that: |
149 | | - A - the article had no categories, |
150 | | - B - the article had no relevant results for its categories) |
151 | | - |
152 | | - this is to ensure we can get always (well, almost - if "marker" categories get no results, it's dead in the water anyway) |
153 | | - some results |
154 | | - */ |
| 212 | + /** |
| 213 | + * Latest addition: if we got no results at all (indicating that: |
| 214 | + * A - the article had no categories, |
| 215 | + * B - the article had no relevant results for its categories) |
| 216 | + * |
| 217 | + * This is to ensure we can get always (well, almost - if "marker" |
| 218 | + * categories get no results, it's dead in the water anyway) some results. |
| 219 | + * |
| 220 | + * @return Array: array of category names |
| 221 | + */ |
155 | 222 | function getAdditionalCheck() { |
156 | 223 | $dbr = wfGetDB( DB_SLAVE ); |
157 | 224 | |
158 | | - $fixed_names = array(); |
| 225 | + $fixedNames = array(); |
159 | 226 | foreach ( $this->mAttentionMarkers as $category ) { |
160 | | - $fixed_names[] = $dbr->addQuotes( $category ); |
| 227 | + $fixedNames[] = $dbr->addQuotes( $category ); |
161 | 228 | } |
162 | | - $stringed_names = implode( ",", $fixed_names ); |
| 229 | + $stringedNames = implode( ',', $fixedNames ); |
163 | 230 | |
164 | 231 | $res = $dbr->select( |
165 | 232 | 'categorylinks', |
166 | 233 | array( 'cl_from' ), |
167 | | - array( "cl_to IN ($stringed_names)" ), |
| 234 | + array( "cl_to IN ($stringedNames)" ), |
168 | 235 | __METHOD__ |
169 | 236 | ); |
170 | 237 | |
171 | | - $result_array = array(); |
172 | | - while ( $x = $dbr->fetchObject( $res ) ) { |
| 238 | + $resultArray = array(); |
| 239 | + foreach( $res as $x ) { |
173 | 240 | if ( $this->mBaseArticle != $x->cl_from ) { |
174 | | - $result_array[] = $x->cl_from; |
| 241 | + $resultArray[] = $x->cl_from; |
175 | 242 | } |
176 | 243 | } |
177 | | - $dbr->freeResult( $res ); |
178 | 244 | |
179 | | - return $result_array; |
| 245 | + return $resultArray; |
180 | 246 | } |
181 | 247 | |
182 | | - // one function to turn result ids into titles in one query rather than multiple ones |
183 | | - function idsToTitles( $id_array ) { |
| 248 | + /** |
| 249 | + * Turn result IDs into Title objects in one query rather than multiple |
| 250 | + * ones. |
| 251 | + * |
| 252 | + * @param $idArray Array: array of page ID numbers |
| 253 | + * @return Array: array of Title objects |
| 254 | + */ |
| 255 | + function idsToTitles( $idArray ) { |
184 | 256 | global $wgContentNamespaces; |
| 257 | + |
185 | 258 | $dbr = wfGetDB( DB_SLAVE ); |
186 | | - $stringed_names = implode( ",", $id_array ); |
| 259 | + $stringedNames = implode( ',', $idArray ); |
187 | 260 | $res = $dbr->select( |
188 | 261 | 'page', |
189 | 262 | array( 'page_namespace', 'page_title' ), |
190 | | - array( "page_id IN ($stringed_names)" ), |
| 263 | + array( "page_id IN ($stringedNames)" ), |
191 | 264 | __METHOD__ |
192 | 265 | ); |
193 | 266 | |
194 | | - $result_array = array(); |
| 267 | + $resultArray = array(); |
195 | 268 | |
196 | 269 | // so for now, to speed things up, just discard results from other namespaces (and subpages) |
197 | | - while ( ( $x = $dbr->fetchObject( $res ) ) |
198 | | - && ( in_array( $x->page_namespace, $wgContentNamespaces ) ) |
199 | | - && false === strpos( $x->page_title, '/' ) ) { |
200 | | - $result_array[] = Title::makeTitle( $x->page_namespace, $x->page_title ); |
| 270 | + while ( |
| 271 | + ( $x = $dbr->fetchObject( $res ) ) && |
| 272 | + ( in_array( $x->page_namespace, $wgContentNamespaces ) ) && |
| 273 | + strpos( $x->page_title, '/' ) === false |
| 274 | + ) |
| 275 | + { |
| 276 | + $resultArray[] = Title::makeTitle( |
| 277 | + $x->page_namespace, |
| 278 | + $x->page_title |
| 279 | + ); |
201 | 280 | } |
202 | 281 | |
203 | 282 | $dbr->freeResult( $res ); |
204 | | - return $result_array; |
| 283 | + return $resultArray; |
205 | 284 | } |
206 | 285 | |
207 | | - // get categories from the 'stub' or 'attention needed' category |
208 | | - function getResults( $marker_category ) { |
| 286 | + /** |
| 287 | + * Get categories from the 'stub' or 'attention needed' category |
| 288 | + * |
| 289 | + * @param $markerCategory String: category name |
| 290 | + * @return Array: array of category names |
| 291 | + */ |
| 292 | + function getResults( $markerCategory ) { |
209 | 293 | $dbr = wfGetDB( DB_SLAVE ); |
210 | | - $title = Title::makeTitle( NS_CATEGORY, $marker_category ); |
211 | | - $result_array = array(); |
| 294 | + $title = Title::makeTitle( NS_CATEGORY, $markerCategory ); |
| 295 | + $resultArray = array(); |
212 | 296 | |
213 | 297 | if ( empty( $this->mBaseCategories ) ) { |
214 | | - return $result_array; |
| 298 | + return $resultArray; |
215 | 299 | } |
216 | 300 | |
| 301 | + // @todo CHECKME: is it possible to make this query use MediaWiki's |
| 302 | + // Database functions? If so, rewrite it! |
217 | 303 | $query = "SELECT c1.cl_from |
218 | 304 | FROM {$dbr->tableName( 'categorylinks' )} AS c1, {$dbr->tableName( 'categorylinks' )} AS c2 |
219 | 305 | WHERE c1.cl_from = c2.cl_from |
220 | 306 | AND c1.cl_to = " . $dbr->addQuotes( $title->getDBkey() ) . " |
221 | 307 | AND c2.cl_to IN ("; |
222 | 308 | |
223 | | - $fixed_names = array(); |
| 309 | + $fixedNames = array(); |
224 | 310 | foreach ( $this->mBaseCategories as $category ) { |
225 | | - $fixed_names[] = $dbr->addQuotes( $category ); |
| 311 | + $fixedNames[] = $dbr->addQuotes( $category ); |
226 | 312 | } |
227 | | - $stringed_names = implode( ",", $fixed_names ); |
228 | | - $query .= $stringed_names . ")"; |
| 313 | + $stringed_names = implode( ',', $fixedNames ); |
| 314 | + $query .= $stringed_names . ')'; |
229 | 315 | |
230 | 316 | $res = $dbr->query( $query, __METHOD__ ); |
231 | | - while ( $x = $dbr->fetchObject( $res ) ) { |
| 317 | + foreach( $res as $x ) { |
232 | 318 | if ( $this->mBaseArticle != $x->cl_from ) { |
233 | | - $result_array[] = $x->cl_from; |
| 319 | + $resultArray[] = $x->cl_from; |
234 | 320 | } |
235 | 321 | } |
236 | | - $dbr->freeResult( $res ); |
237 | 322 | |
238 | | - return $result_array; |
| 323 | + return $resultArray; |
239 | 324 | } |
240 | 325 | |
241 | | - // message box wrapper |
242 | | - static public function showMessage( $text ) { |
| 326 | + /** |
| 327 | + * Message box wrapper |
| 328 | + * |
| 329 | + * @param $text String: message to show |
| 330 | + */ |
| 331 | + public static function showMessage( $text ) { |
243 | 332 | global $wgOut, $wgUser, $wgScript, $wgScriptPath; |
| 333 | + |
244 | 334 | $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/EditSimilar/EditSimilar.css' ); |
| 335 | + |
| 336 | + // If the user is logged in, give them a link to their preferences in |
| 337 | + // case if they want to disable EditSimilar suggestions |
245 | 338 | if ( $wgUser->isLoggedIn() ) { |
246 | | - $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>'; |
| 339 | + $link = '<div class="editsimilar_dismiss">[<span class="plainlinks"><a href="' . |
| 340 | + $wgScript . '?title=Special:Preferences#prefsection-4" id="editsimilar_preferences">' . |
| 341 | + wfMsg( 'editsimilar-link-disable' ) . |
| 342 | + '</a></span>]</div><div style="display:block"> </div>'; |
247 | 343 | } else { |
248 | 344 | $link = ''; |
249 | 345 | } |
250 | | - $wgOut->addHTML( '<div id="editsimilar_links" class="usermessage editsimilar"><div>' . $text . '</div>' . $link . '</div>' ); |
| 346 | + $wgOut->addHTML( |
| 347 | + '<div id="editsimilar_links" class="usermessage editsimilar"><div>' . |
| 348 | + $text . '</div>' . $link . '</div>' |
| 349 | + ); |
251 | 350 | } |
252 | 351 | |
253 | | - // this is for determining whether to display the message or not |
254 | | - static public function checkCounter() { |
| 352 | + /** |
| 353 | + * For determining whether to display the message or not |
| 354 | + * |
| 355 | + * @return Boolean: true to show the message, false to not show it |
| 356 | + */ |
| 357 | + public static function checkCounter() { |
255 | 358 | global $wgEditSimilarCounterValue; |
256 | 359 | if ( isset( $_SESSION['ES_counter'] ) ) { |
257 | 360 | $_SESSION['ES_counter']--; |
Index: trunk/extensions/EditSimilar/EditSimilar.php |
— | — | @@ -8,10 +8,12 @@ |
9 | 9 | * @author Łukasz Garczewski (TOR) <tor@wikia-inc.com> |
10 | 10 | * @copyright Copyright © 2008, Wikia Inc. |
11 | 11 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 12 | + * @link http://www.mediawiki.org/wiki/Extension:EditSimilar Documentation |
12 | 13 | */ |
13 | 14 | |
14 | | -if ( !defined( 'MEDIAWIKI' ) ) |
| 15 | +if ( !defined( 'MEDIAWIKI' ) ) { |
15 | 16 | die( "This is not a valid entry point.\n" ); |
| 17 | +} |
16 | 18 | |
17 | 19 | // Internationalization file |
18 | 20 | $dir = dirname( __FILE__ ) . '/'; |
— | — | @@ -42,28 +44,46 @@ |
43 | 45 | 'descriptionmsg' => 'editsimilar-desc', |
44 | 46 | ); |
45 | 47 | |
46 | | -// check if we had the extension enabled at all and if this is in a content namespace |
| 48 | +/** |
| 49 | + * Check if we had the extension enabled at all and if the current page is in a |
| 50 | + * content namespace. |
| 51 | + * |
| 52 | + * @param $article Object: Article object |
| 53 | + * @return Boolean: true |
| 54 | + */ |
47 | 55 | function wfEditSimilarCheck( $article ) { |
48 | 56 | global $wgUser, $wgContentNamespaces; |
49 | 57 | |
50 | 58 | $namespace = $article->getTitle()->getNamespace(); |
51 | | - if ( ( 1 == $wgUser->getOption( 'edit-similar', 1 ) ) && ( in_array( $namespace, $wgContentNamespaces ) ) ) { |
| 59 | + if ( |
| 60 | + ( $wgUser->getOption( 'edit-similar', 1 ) == 1 ) && |
| 61 | + ( in_array( $namespace, $wgContentNamespaces ) ) |
| 62 | + ) |
| 63 | + { |
52 | 64 | $_SESSION['ES_saved'] = 'yes'; |
53 | 65 | } |
54 | 66 | return true; |
55 | 67 | } |
56 | 68 | |
57 | | -// view message depending on settings and the relevancy of the results |
| 69 | +/** |
| 70 | + * Show a message, depending on settings and the relevancy of the results. |
| 71 | + * |
| 72 | + * @param $out Object: OutputPage instance |
| 73 | + * @return Boolean: true |
| 74 | + */ |
58 | 75 | function wfEditSimilarViewMesg( &$out ) { |
59 | 76 | global $wgUser, $wgEditSimilarAlwaysShowThanks; |
60 | 77 | |
61 | | - |
62 | | - |
63 | | - if ( !empty( $_SESSION['ES_saved'] ) && ( 1 == $wgUser->getOption( 'edit-similar', 1 ) ) && $out->isArticle() ) { |
| 78 | + if ( |
| 79 | + !empty( $_SESSION['ES_saved'] ) && |
| 80 | + ( $wgUser->getOption( 'edit-similar', 1 ) == 1 ) && |
| 81 | + $out->isArticle() |
| 82 | + ) |
| 83 | + { |
64 | 84 | if ( EditSimilar::checkCounter() ) { |
65 | 85 | $message_text = ''; |
66 | 86 | $title = $out->getTitle(); |
67 | | - $article_title = $title->getText(); |
| 87 | + $articleTitle = $title->getText(); |
68 | 88 | // here we'll populate the similar articles and links |
69 | 89 | $instance = new EditSimilar( $title->getArticleId(), 'category' ); |
70 | 90 | $similarities = $instance->getSimilarArticles(); |
— | — | @@ -72,14 +92,14 @@ |
73 | 93 | global $wgLang; |
74 | 94 | |
75 | 95 | if ( $instance->mSimilarArticles ) { |
76 | | - $message_text = wfMsgExt( |
| 96 | + $messageText = wfMsgExt( |
77 | 97 | 'editsimilar-thanks', |
78 | 98 | array( 'parsemag' ), |
79 | 99 | $wgLang->listToText( $similarities ), |
80 | 100 | count( $similarities ) |
81 | 101 | ); |
82 | 102 | } else { // the articles we found were rather just articles needing attention |
83 | | - $message_text = wfMsgExt( |
| 103 | + $messageText = wfMsgExt( |
84 | 104 | 'editsimilar-thanks-notsimilar', |
85 | 105 | array( 'parsemag' ), |
86 | 106 | $wgLang->listToText( $similarities ), |
— | — | @@ -88,12 +108,12 @@ |
89 | 109 | } |
90 | 110 | } else { |
91 | 111 | if ( $wgUser->isLoggedIn() && !empty( $wgEditSimilarAlwaysShowThanks ) ) { |
92 | | - $message_text = wfMsg( 'editsimilar-thankyou', $wgUser->getName() ); |
| 112 | + $messageText = wfMsg( 'editsimilar-thankyou', $wgUser->getName() ); |
93 | 113 | } |
94 | 114 | } |
95 | 115 | |
96 | | - if ( '' != $message_text ) { |
97 | | - EditSimilar::showMessage( $message_text, $article_title ); |
| 116 | + if ( $messageText != '' ) { |
| 117 | + EditSimilar::showMessage( $messageText, $articleTitle ); |
98 | 118 | } |
99 | 119 | } |
100 | 120 | // display that only once |
— | — | @@ -103,15 +123,14 @@ |
104 | 124 | } |
105 | 125 | |
106 | 126 | /** |
107 | | - * Adds the new toggle to Special:Preferences for enabling EditSimilar extension on a per-user basis |
| 127 | + * Adds the new toggle to Special:Preferences for enabling EditSimilar |
| 128 | + * extension on a per-user basis. |
108 | 129 | * |
109 | 130 | * @param $user User object |
110 | 131 | * @param $preferences Preferences object |
111 | | - * @return true |
| 132 | + * @return Boolean: true |
112 | 133 | */ |
113 | 134 | function wfEditSimilarToggle( $user, &$preferences ) { |
114 | | - |
115 | | - |
116 | 135 | $preferences['edit-similar'] = array( |
117 | 136 | 'type' => 'toggle', |
118 | 137 | 'section' => 'editing', |