Index: trunk/extensions/EditSimilar/EditSimilar.class.php |
— | — | @@ -0,0 +1,269 @@ |
| 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 |
| 11 | + |
| 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) |
| 18 | + |
| 19 | + insert '-' if you want to disable the extension without blanking the commanding article |
| 20 | + |
| 21 | +*/ |
| 22 | + |
| 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 |
| 31 | + |
| 32 | + // constructor |
| 33 | + function __construct( $article, $markertype = 'category' ) { |
| 34 | + global $wgEditSimilarMaxResultsPool; |
| 35 | + $this->mBaseArticle = $article; |
| 36 | + $this->mMarkerType = $markertype; |
| 37 | + $this->mAttentionMarkers = $this->getStubCategories(); |
| 38 | + $this->mPoolLimit = $wgEditSimilarMaxResultsPool; |
| 39 | + $this->mBaseCategories = $this->getBaseCategories(); |
| 40 | + $this->mSimilarArticles = true; |
| 41 | + } |
| 42 | + |
| 43 | + // fetch categories marked as 'stub categories' |
| 44 | + function getStubCategories() { |
| 45 | + $stub_categories = wfMsgForContent( 'EditSimilar-Categories' ); |
| 46 | + if ( ( '<EditSimilar-Categories>' == $stub_categories ) || ( '' == $stub_categories ) || ( '-' == $stub_categories ) ) { |
| 47 | + return false; |
| 48 | + } else { |
| 49 | + $lines = preg_split( "/\*/", $stub_categories ); |
| 50 | + $normalised_lines = array(); |
| 51 | + array_shift( $lines ); |
| 52 | + foreach ( $lines as $line ) { |
| 53 | + $normalised_lines[] = str_replace( ' ', '_', trim( $line ) ); |
| 54 | + } |
| 55 | + return $normalised_lines; |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + // this is the main function that returns articles we deem similar or worth showing |
| 60 | + function getSimilarArticles() { |
| 61 | + global $wgUser, $wgEditSimilarMaxResultsToDisplay; |
| 62 | + |
| 63 | + if ( empty( $this->mAttentionMarkers ) || !$this->mAttentionMarkers ) { |
| 64 | + return false; |
| 65 | + } |
| 66 | + $text = ''; |
| 67 | + $articles = array(); |
| 68 | + $x = 0; |
| 69 | + |
| 70 | + while ( ( count( $articles ) < $wgEditSimilarMaxResultsToDisplay ) && ( $x < count( $this->mAttentionMarkers ) ) ) { |
| 71 | + $articles = array_merge( $articles, $this->getResults( $this->mAttentionMarkers[$x] ) ); |
| 72 | + if ( !empty( $articles ) ) { |
| 73 | + $articles = array_unique( $articles ); |
| 74 | + } |
| 75 | + $x++; |
| 76 | + } |
| 77 | + |
| 78 | + if ( empty( $articles ) ) { |
| 79 | + $articles = $this->getAdditionalCheck(); |
| 80 | + // second check to make sure we have anything to display |
| 81 | + if ( empty( $articles ) ) { |
| 82 | + return false; |
| 83 | + } |
| 84 | + $articles = array_unique( $articles ); |
| 85 | + $this->mSimilarArticles = false; |
| 86 | + } |
| 87 | + |
| 88 | + if ( 1 == count( $articles ) ) { // in this case, array_rand returns a single element, not an array |
| 89 | + $rand_articles = array( 0 ); |
| 90 | + } else { |
| 91 | + $rand_articles = array_rand( $articles, min( $wgEditSimilarMaxResultsToDisplay, count( $articles ) ) ); |
| 92 | + } |
| 93 | + $sk = $wgUser->getSkin(); |
| 94 | + $skinname = get_class( $sk ); |
| 95 | + $skinname = strtolower( substr( $skinname, 4 ) ); |
| 96 | + $real_rand_values = array(); |
| 97 | + if ( empty( $rand_articles ) ) { |
| 98 | + return false; |
| 99 | + } |
| 100 | + |
| 101 | + $translated_titles = array(); |
| 102 | + foreach ( $rand_articles as $r_key => $rand_article_key ) { |
| 103 | + $translated_titles[] = $articles [$rand_article_key]; |
| 104 | + } |
| 105 | + $translated_titles = $this->idsToTitles( $translated_titles ); |
| 106 | + |
| 107 | + foreach ( $translated_titles as $link_title ) { |
| 108 | + $article_link = $sk->makeKnownLinkObj( $link_title ); |
| 109 | + $real_rand_values[] = $article_link; |
| 110 | + } |
| 111 | + |
| 112 | + return $real_rand_values; |
| 113 | + } |
| 114 | + |
| 115 | + // extract all categories our base article is in |
| 116 | + function getBaseCategories() { |
| 117 | + global $wgEditSimilarMaxResultsToDisplay; |
| 118 | + if ( empty( $this->mAttentionMarkers ) || !$this->mAttentionMarkers ) { |
| 119 | + return false; |
| 120 | + } |
| 121 | + |
| 122 | + $dbr = wfGetDB( DB_SLAVE ); |
| 123 | + $result_array = array(); |
| 124 | + $res = $dbr->select( |
| 125 | + array( 'categorylinks' ), |
| 126 | + array( 'cl_to' ), |
| 127 | + array( 'cl_from' => $this->mBaseArticle ), |
| 128 | + __METHOD__, |
| 129 | + array( |
| 130 | + 'ORDER_BY' => 'cl_from', |
| 131 | + 'USE_INDEX' => 'cl_from' |
| 132 | + ) |
| 133 | + ); |
| 134 | + while ( $x = $dbr->fetchObject( $res ) ) { |
| 135 | + if ( !in_array( $x->cl_to, $this->mAttentionMarkers ) ) { |
| 136 | + $result_array[] = $x->cl_to; |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + if ( !empty( $result_array ) ) { |
| 141 | + return $result_array; |
| 142 | + } else { |
| 143 | + return false; |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 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 | + */ |
| 155 | + function getAdditionalCheck() { |
| 156 | + $dbr = wfGetDB( DB_SLAVE ); |
| 157 | + |
| 158 | + $fixed_names = array(); |
| 159 | + foreach ( $this->mAttentionMarkers as $category ) { |
| 160 | + $fixed_names[] = $dbr->addQuotes( $category ); |
| 161 | + } |
| 162 | + $stringed_names = implode( ",", $fixed_names ); |
| 163 | + |
| 164 | + $res = $dbr->select( |
| 165 | + 'categorylinks', |
| 166 | + array( 'cl_from' ), |
| 167 | + array( "cl_to IN ($stringed_names)" ), |
| 168 | + __METHOD__ |
| 169 | + ); |
| 170 | + |
| 171 | + $result_array = array(); |
| 172 | + while ( $x = $dbr->fetchObject( $res ) ) { |
| 173 | + if ( $this->mBaseArticle != $x->cl_from ) { |
| 174 | + $result_array[] = $x->cl_from; |
| 175 | + } |
| 176 | + } |
| 177 | + $dbr->freeResult( $res ); |
| 178 | + |
| 179 | + return $result_array; |
| 180 | + } |
| 181 | + |
| 182 | + // one function to turn result ids into titles in one query rather than multiple ones |
| 183 | + function idsToTitles( $id_array ) { |
| 184 | + global $wgContentNamespaces; |
| 185 | + $dbr = wfGetDB( DB_SLAVE ); |
| 186 | + $stringed_names = implode( ",", $id_array ); |
| 187 | + $res = $dbr->select( |
| 188 | + 'page', |
| 189 | + array( 'page_namespace', 'page_title' ), |
| 190 | + array( "page_id IN ($stringed_names)" ), |
| 191 | + __METHOD__ |
| 192 | + ); |
| 193 | + |
| 194 | + $result_array = array(); |
| 195 | + |
| 196 | + // 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 ); |
| 201 | + } |
| 202 | + |
| 203 | + $dbr->freeResult( $res ); |
| 204 | + return $result_array; |
| 205 | + } |
| 206 | + |
| 207 | + // get categories from the 'stub' or 'attention needed' category |
| 208 | + function getResults( $marker_category ) { |
| 209 | + $dbr = wfGetDB( DB_SLAVE ); |
| 210 | + $title = Title::makeTitle( NS_CATEGORY, $marker_category ); |
| 211 | + $result_array = array(); |
| 212 | + |
| 213 | + if ( empty( $this->mBaseCategories ) ) { |
| 214 | + return $result_array; |
| 215 | + } |
| 216 | + |
| 217 | + $query = "SELECT c1.cl_from |
| 218 | + FROM {$dbr->tableName( 'categorylinks' )} AS c1, {$dbr->tableName( 'categorylinks' )} AS c2 |
| 219 | + WHERE c1.cl_from = c2.cl_from |
| 220 | + AND c1.cl_to = " . $dbr->addQuotes( $title->getDBkey() ) . " |
| 221 | + AND c2.cl_to IN ("; |
| 222 | + |
| 223 | + $fixed_names = array(); |
| 224 | + foreach ( $this->mBaseCategories as $category ) { |
| 225 | + $fixed_names[] = $dbr->addQuotes( $category ); |
| 226 | + } |
| 227 | + $stringed_names = implode( ",", $fixed_names ); |
| 228 | + $query .= $stringed_names . ")"; |
| 229 | + |
| 230 | + $res = $dbr->query( $query, __METHOD__ ); |
| 231 | + while ( $x = $dbr->fetchObject( $res ) ) { |
| 232 | + if ( $this->mBaseArticle != $x->cl_from ) { |
| 233 | + $result_array[] = $x->cl_from; |
| 234 | + } |
| 235 | + } |
| 236 | + $dbr->freeResult( $res ); |
| 237 | + |
| 238 | + return $result_array; |
| 239 | + } |
| 240 | + |
| 241 | + // message box wrapper |
| 242 | + static public function showMessage( $text ) { |
| 243 | + global $wgOut, $wgUser, $wgScript, $wgScriptPath; |
| 244 | + $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/EditSimilar/EditSimilar.css' ); |
| 245 | + 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>'; |
| 247 | + } else { |
| 248 | + $link = ''; |
| 249 | + } |
| 250 | + $wgOut->addHTML( '<div id="editsimilar_links" class="usermessage editsimilar"><div>' . $text . '</div>' . $link . '</div>' ); |
| 251 | + } |
| 252 | + |
| 253 | + // this is for determining whether to display the message or not |
| 254 | + static public function checkCounter() { |
| 255 | + global $wgEditSimilarCounterValue; |
| 256 | + if ( isset( $_SESSION['ES_counter'] ) ) { |
| 257 | + $_SESSION['ES_counter']--; |
| 258 | + if ( $_SESSION['ES_counter'] > 0 ) { |
| 259 | + return false; |
| 260 | + } else { |
| 261 | + $_SESSION['ES_counter'] = $wgEditSimilarCounterValue; |
| 262 | + return true; |
| 263 | + } |
| 264 | + } else { |
| 265 | + $_SESSION['ES_counter'] = $wgEditSimilarCounterValue; |
| 266 | + return true; |
| 267 | + } |
| 268 | + } |
| 269 | + |
| 270 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/EditSimilar/EditSimilar.class.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 271 | + native |
Index: trunk/extensions/EditSimilar/EditSimilar.i18n.php |
— | — | @@ -185,7 +185,7 @@ |
186 | 186 | ); |
187 | 187 | |
188 | 188 | /** Finnish (Suomi) |
189 | | - * @author Jack Phoenix |
| 189 | + * @author Jack Phoenix <jack@countervandalism.net> |
190 | 190 | * @author Mobe |
191 | 191 | * @author Varusmies |
192 | 192 | */ |
— | — | @@ -194,7 +194,7 @@ |
195 | 195 | 'editsimilar-thanks' => 'Kiitos muokkauksestasi. |
196 | 196 | Katso {{PLURAL:$2|tämä aiheeseen liittyvä sivu|nämä aiheeseen liittyvät sivut}}: $1.', |
197 | 197 | 'editsimilar-thanks-notsimilar' => 'Kiitos muokkauksestasi. |
198 | | -{{PLURAL:$2|Tämä sivu|Nämä sivut}} voisivat kaivata apuasi: $1.', |
| 198 | +{{PLURAL:$2|Tämä sivu voisi|Nämä sivut voisivat}} myös kaivata apuasi: $1.', |
199 | 199 | 'editsimilar-thankyou' => 'Kiitos muokkauksestasi, $1!', |
200 | 200 | 'editsimilar-link-disable' => 'aseta asetukset', |
201 | 201 | 'tog-edit-similar' => 'Ota käyttöön samanlaisten sivujen ehdotukset', |
Index: trunk/extensions/EditSimilar/EditSimilar.php |
— | — | @@ -16,6 +16,7 @@ |
17 | 17 | // Internationalization file |
18 | 18 | $dir = dirname( __FILE__ ) . '/'; |
19 | 19 | $wgExtensionMessagesFiles['EditSimilar'] = $dir . 'EditSimilar.i18n.php'; |
| 20 | +$wgAutoloadClasses['EditSimilar'] = $dir . 'EditSimilar.class.php'; |
20 | 21 | |
21 | 22 | // maximum number of results to choose from |
22 | 23 | $wgEditSimilarMaxResultsPool = 50; |
— | — | @@ -35,291 +36,20 @@ |
36 | 37 | $wgExtensionCredits['other'][] = array( |
37 | 38 | 'path' => __FILE__, |
38 | 39 | 'name' => 'EditSimilar', |
39 | | - 'version' => '1.19', |
| 40 | + 'version' => '1.20', |
40 | 41 | 'author' => array( 'Bartek Łapiński', 'Łukasz Garczewski' ), |
41 | 42 | 'url' => 'http://www.mediawiki.org/wiki/Extension:EditSimilar', |
42 | 43 | 'description' => 'Encourages users to edit a page similar (by categories) to the one they just had edited.', |
43 | 44 | 'descriptionmsg' => 'editsimilar-desc', |
44 | 45 | ); |
45 | 46 | |
46 | | -// FIXME: split off into a separate class file. Saves time and resources on init. |
47 | | - |
48 | | -/* |
49 | | - How this extension works: |
50 | | - - upon save, the script searches for articles that are similar |
51 | | - right now, I have assumed the following criteria: |
52 | | - * articles that need attention |
53 | | - * articles similar in category to the one we edited |
54 | | - * if no similar articles were found, we're taking results straight from categories that need attention |
55 | | - * number of articles in result is limited |
56 | | - |
57 | | - IMPORTANT NOTE: This extension REQUIRES the article MediaWiki:EditSimilar-Categories to exist on your |
58 | | - wiki in order to run. If this article is nonexistent, the extension will disable itself. |
59 | | - Format of the article is as follows: |
60 | | - * Chosen Stub Category 1 |
61 | | - * Chosen Stub Category 2 |
62 | | - etc. (separated by stars) |
63 | | - |
64 | | - insert '-' if you want to disable the extension without blanking the commanding article |
65 | | - |
66 | | -*/ |
67 | | - |
68 | | -// base class for this extension |
69 | | -class EditSimilar { |
70 | | - var $mBaseArticle; // the article from which we hail in our quest for similiarities, this is its title |
71 | | - var $mMarkerType; // how do we mark articles that need attention? currently, by category only |
72 | | - var $mAttentionMarkers; // the marker array (for now it contains categories) |
73 | | - var $mMatchType; // how do we match articles as a secondary |
74 | | - var $mPoolLimit; // limit up the pool of 'stubs' to choose from |
75 | | - var $mBaseCategories; // extracted categories that this saved article is in |
76 | | - var $mSimilarArticles; // to differentiate between really similar results or just needing attention |
77 | | - |
78 | | - // constructor |
79 | | - function __construct( $article, $markertype = 'category' ) { |
80 | | - global $wgEditSimilarMaxResultsPool; |
81 | | - $this->mBaseArticle = $article; |
82 | | - $this->mMarkerType = $markertype; |
83 | | - $this->mAttentionMarkers = $this->getStubCategories(); |
84 | | - $this->mPoolLimit = $wgEditSimilarMaxResultsPool; |
85 | | - $this->mBaseCategories = $this->getBaseCategories(); |
86 | | - $this->mSimilarArticles = true; |
87 | | - } |
88 | | - |
89 | | - // fetch categories marked as 'stub categories' |
90 | | - function getStubCategories() { |
91 | | - $stub_categories = wfMsgForContent( 'EditSimilar-Categories' ); |
92 | | - if ( ( '<EditSimilar-Categories>' == $stub_categories ) || ( '' == $stub_categories ) || ( '-' == $stub_categories ) ) { |
93 | | - return false; |
94 | | - } else { |
95 | | - $lines = preg_split( "/\*/", $stub_categories ); |
96 | | - $normalised_lines = array(); |
97 | | - array_shift( $lines ); |
98 | | - foreach ( $lines as $line ) { |
99 | | - $normalised_lines[] = str_replace( ' ', '_', trim( $line ) ); |
100 | | - } |
101 | | - return $normalised_lines; |
102 | | - } |
103 | | - } |
104 | | - |
105 | | - // this is the main function that returns articles we deem similar or worth showing |
106 | | - function getSimilarArticles() { |
107 | | - global $wgUser, $wgEditSimilarMaxResultsToDisplay; |
108 | | - |
109 | | - if ( empty( $this->mAttentionMarkers ) || !$this->mAttentionMarkers ) { |
110 | | - return false; |
111 | | - } |
112 | | - $text = ''; |
113 | | - $articles = array(); |
114 | | - $x = 0; |
115 | | - |
116 | | - while ( ( count( $articles ) < $wgEditSimilarMaxResultsToDisplay ) && ( $x < count( $this->mAttentionMarkers ) ) ) { |
117 | | - $articles = array_merge( $articles, $this->getResults( $this->mAttentionMarkers[$x] ) ); |
118 | | - if ( !empty( $articles ) ) { |
119 | | - $articles = array_unique( $articles ); |
120 | | - } |
121 | | - $x++; |
122 | | - } |
123 | | - |
124 | | - if ( empty( $articles ) ) { |
125 | | - $articles = $this->getAdditionalCheck(); |
126 | | - // second check to make sure we have anything to display |
127 | | - if ( empty( $articles ) ) { |
128 | | - return false; |
129 | | - } |
130 | | - $articles = array_unique( $articles ); |
131 | | - $this->mSimilarArticles = false; |
132 | | - } |
133 | | - |
134 | | - if ( 1 == count( $articles ) ) { // in this case, array_rand returns a single element, not an array |
135 | | - $rand_articles = array( 0 ); |
136 | | - } else { |
137 | | - $rand_articles = array_rand( $articles, min( $wgEditSimilarMaxResultsToDisplay, count( $articles ) ) ); |
138 | | - } |
139 | | - $sk = $wgUser->getSkin(); |
140 | | - $skinname = get_class( $sk ); |
141 | | - $skinname = strtolower( substr( $skinname, 4 ) ); |
142 | | - $real_rand_values = array(); |
143 | | - if ( empty( $rand_articles ) ) { |
144 | | - return false; |
145 | | - } |
146 | | - |
147 | | - $translated_titles = array(); |
148 | | - foreach ( $rand_articles as $r_key => $rand_article_key ) { |
149 | | - $translated_titles[] = $articles [$rand_article_key]; |
150 | | - } |
151 | | - $translated_titles = $this->idsToTitles( $translated_titles ); |
152 | | - |
153 | | - foreach ( $translated_titles as $link_title ) { |
154 | | - $article_link = $sk->makeKnownLinkObj( $link_title ); |
155 | | - $real_rand_values[] = $article_link; |
156 | | - } |
157 | | - |
158 | | - return $real_rand_values; |
159 | | - } |
160 | | - |
161 | | - // extract all categories our base article is in |
162 | | - function getBaseCategories() { |
163 | | - global $wgEditSimilarMaxResultsToDisplay; |
164 | | - if ( empty( $this->mAttentionMarkers ) || !$this->mAttentionMarkers ) { |
165 | | - return false; |
166 | | - } |
167 | | - |
168 | | - $dbr = wfGetDB( DB_SLAVE ); |
169 | | - $result_array = array(); |
170 | | - $res = $dbr->select( |
171 | | - array( 'categorylinks' ), |
172 | | - array( 'cl_to' ), |
173 | | - array( 'cl_from' => $this->mBaseArticle ), |
174 | | - __METHOD__, |
175 | | - array( |
176 | | - 'ORDER_BY' => 'cl_from', |
177 | | - 'USE_INDEX' => 'cl_from' |
178 | | - ) |
179 | | - ); |
180 | | - while ( $x = $dbr->fetchObject( $res ) ) { |
181 | | - if ( !in_array( $x->cl_to, $this->mAttentionMarkers ) ) { |
182 | | - $result_array [] = $x->cl_to; |
183 | | - } |
184 | | - } |
185 | | - |
186 | | - if ( !empty( $result_array ) ) { |
187 | | - return $result_array; |
188 | | - } else { |
189 | | - return false; |
190 | | - } |
191 | | - } |
192 | | - |
193 | | - /* |
194 | | - latest addition: if we got no results at all (indicating that: |
195 | | - A - the article had no categories, |
196 | | - B - the article had no relevant results for its categories) |
197 | | - |
198 | | - this is to ensure we can get always (well, almost - if "marker" categories get no results, it's dead in the water anyway) |
199 | | - some results |
200 | | - */ |
201 | | - function getAdditionalCheck() { |
202 | | - $dbr = wfGetDB( DB_SLAVE ); |
203 | | - |
204 | | - $fixed_names = array(); |
205 | | - foreach ( $this->mAttentionMarkers as $category ) { |
206 | | - $fixed_names[] = $dbr->addQuotes( $category ); |
207 | | - } |
208 | | - $stringed_names = implode( ",", $fixed_names ); |
209 | | - |
210 | | - $res = $dbr->select( |
211 | | - 'categorylinks', |
212 | | - array( 'cl_from' ), |
213 | | - array( "cl_to IN ($stringed_names)" ), |
214 | | - __METHOD__ |
215 | | - ); |
216 | | - |
217 | | - $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 ); |
224 | | - |
225 | | - return $result_array; |
226 | | - } |
227 | | - |
228 | | - // one function to turn result ids into titles in one query rather than multiple ones |
229 | | - function idsToTitles( $id_array ) { |
230 | | - global $wgContentNamespaces; |
231 | | - $dbr = wfGetDB( DB_SLAVE ); |
232 | | - $stringed_names = implode( ",", $id_array ); |
233 | | - $res = $dbr->select( |
234 | | - 'page', |
235 | | - array( 'page_namespace', 'page_title' ), |
236 | | - array( "page_id IN ($stringed_names)" ), |
237 | | - __METHOD__ |
238 | | - ); |
239 | | - |
240 | | - $result_array = array(); |
241 | | - |
242 | | - // so for now, to speed things up, just discard results from other namespaces (and subpages) |
243 | | - while ( ( $x = $dbr->fetchObject( $res ) ) |
244 | | - && ( in_array( $x->page_namespace, $wgContentNamespaces ) ) |
245 | | - && false === strpos( $x->page_title, "/" ) ) { |
246 | | - $result_array[] = Title::makeTitle( $x->page_namespace, $x->page_title ); |
247 | | - } |
248 | | - |
249 | | - $dbr->freeResult( $res ); |
250 | | - return $result_array; |
251 | | - } |
252 | | - |
253 | | - // get categories from the 'stub' or 'attention needed' category |
254 | | - function getResults( $marker_category ) { |
255 | | - $dbr = wfGetDB( DB_SLAVE ); |
256 | | - $title = Title::makeTitle( NS_CATEGORY, $marker_category ); |
257 | | - $result_array = array(); |
258 | | - |
259 | | - if ( empty( $this->mBaseCategories ) ) { |
260 | | - return $result_array; |
261 | | - } |
262 | | - |
263 | | - $query = "SELECT c1.cl_from |
264 | | - FROM {$dbr->tableName( 'categorylinks' )} AS c1, {$dbr->tableName( 'categorylinks' )} AS c2 |
265 | | - WHERE c1.cl_from = c2.cl_from |
266 | | - AND c1.cl_to = " . $dbr->addQuotes( $title->getDBkey() ) . " |
267 | | - AND c2.cl_to IN ("; |
268 | | - |
269 | | - $fixed_names = array(); |
270 | | - foreach ( $this->mBaseCategories as $category ) { |
271 | | - $fixed_names[] = $dbr->addQuotes( $category ); |
272 | | - } |
273 | | - $stringed_names = implode( ",", $fixed_names ); |
274 | | - $query .= $stringed_names . ")"; |
275 | | - |
276 | | - $res = $dbr->query( $query, __METHOD__ ); |
277 | | - while ( $x = $dbr->fetchObject( $res ) ) { |
278 | | - if ( $this->mBaseArticle != $x->cl_from ) { |
279 | | - $result_array[] = $x->cl_from; |
280 | | - } |
281 | | - } |
282 | | - $dbr->freeResult( $res ); |
283 | | - |
284 | | - return $result_array; |
285 | | - } |
286 | | - |
287 | | - // message box wrapper |
288 | | - static public function showMessage( $text ) { |
289 | | - global $wgOut, $wgUser, $wgScript, $wgScriptPath; |
290 | | - $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/EditSimilar/EditSimilar.css' ); |
291 | | - if ( $wgUser->isLoggedIn() ) { |
292 | | - $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>'; |
293 | | - } else { |
294 | | - $link = ''; |
295 | | - } |
296 | | - $wgOut->addHTML( '<div id="editsimilar_links" class="usermessage editsimilar"><div>' . $text . '</div>' . $link . '</div>' ); |
297 | | - } |
298 | | - |
299 | | - // this is for determining whether to display the message or not |
300 | | - static public function checkCounter() { |
301 | | - global $wgEditSimilarCounterValue; |
302 | | - if ( isset( $_SESSION['ES_counter'] ) ) { |
303 | | - $_SESSION['ES_counter']--; |
304 | | - if ( $_SESSION['ES_counter'] > 0 ) { |
305 | | - return false; |
306 | | - } else { |
307 | | - $_SESSION['ES_counter'] = $wgEditSimilarCounterValue; |
308 | | - return true; |
309 | | - } |
310 | | - } else { |
311 | | - $_SESSION['ES_counter'] = $wgEditSimilarCounterValue; |
312 | | - return true; |
313 | | - } |
314 | | - } |
315 | | -} |
316 | | - |
317 | 47 | // check if we had the extension enabled at all and if this is in a content namespace |
318 | 48 | function wfEditSimilarCheck( $article ) { |
319 | 49 | global $wgUser, $wgContentNamespaces; |
320 | 50 | |
321 | 51 | $namespace = $article->getTitle()->getNamespace(); |
322 | 52 | if ( ( 1 == $wgUser->getOption( 'edit-similar', 1 ) ) && ( in_array( $namespace, $wgContentNamespaces ) ) ) { |
323 | | - $_SESSION ['ES_saved'] = 'yes'; |
| 53 | + $_SESSION['ES_saved'] = 'yes'; |
324 | 54 | } |
325 | 55 | return true; |
326 | 56 | } |
— | — | @@ -335,13 +65,13 @@ |
336 | 66 | $message_text = ''; |
337 | 67 | $article_title = $wgTitle->getText(); |
338 | 68 | // here we'll populate the similar articles and links |
339 | | - $SInstance = new EditSimilar( $wgTitle->getArticleId(), 'category' ); |
340 | | - $similarities = $SInstance->getSimilarArticles(); |
| 69 | + $instance = new EditSimilar( $wgTitle->getArticleId(), 'category' ); |
| 70 | + $similarities = $instance->getSimilarArticles(); |
341 | 71 | |
342 | 72 | if ( !empty( $similarities ) ) { |
343 | 73 | global $wgLang; |
344 | 74 | |
345 | | - if ( $SInstance->mSimilarArticles ) { |
| 75 | + if ( $instance->mSimilarArticles ) { |
346 | 76 | $message_text = wfMsgExt( |
347 | 77 | 'editsimilar-thanks', |
348 | 78 | array( 'parsemag' ), |
— | — | @@ -388,4 +118,4 @@ |
389 | 119 | 'label-message' => 'tog-edit-similar', |
390 | 120 | ); |
391 | 121 | return true; |
392 | | -} |
| 122 | +} |
\ No newline at end of file |