Index: trunk/phase3/RELEASE-NOTES-1.19 |
— | — | @@ -16,11 +16,15 @@ |
17 | 17 | * $wgAllowUserSkin (deprecated in 1.16) has now been removed |
18 | 18 | * $wgExtraRandompageSQL (deprecated in 1.16) has now been removed |
19 | 19 | * LogReader and LogViewer classes (deprecated in 1.14) have now been removed |
| 20 | +* (bug 26033) Added $wgArticleCountMethod to select the method to use to say |
| 21 | + whether a page is an article or not. $wgUseCommaCount is now deprecated. |
20 | 22 | |
21 | 23 | === New features in 1.19 === |
22 | 24 | * (bug 28916) A way to to toggle mw.config legacy globals settings from |
23 | 25 | LocalSettings.php has been created by introducing $wgLegacyJavaScriptGlobals. |
24 | 26 | * (bug 28503) Support for ircs:// URL protocols |
| 27 | +* (bug 26033) It is now possible to count all non-redirect pages in content |
| 28 | + namespaces as articles |
25 | 29 | |
26 | 30 | === Bug fixes in 1.19 === |
27 | 31 | * (bug 10154) Don't allow user to specify days beyond $wgRCMaxAge. |
— | — | @@ -38,6 +42,8 @@ |
39 | 43 | * (bug 27864) Transcluding {{Special:Prefix}} with empty prefix now lists all |
40 | 44 | pages. |
41 | 45 | * (bug 18803) JPEG2000 images can no longer be uploaded as JPEG image. |
| 46 | +* (bug 11868) If using links to count articles, the checking will now be based |
| 47 | + on the real presence of an internal link instead of the "[[" string |
42 | 48 | |
43 | 49 | === API changes in 1.19 === |
44 | 50 | * (bug 27790) add query type for querymodules to action=paraminfo |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -2974,15 +2974,31 @@ |
2975 | 2975 | */ |
2976 | 2976 | |
2977 | 2977 | /** |
2978 | | - * Under which condition should a page in the main namespace be counted |
2979 | | - * as a valid article? If $wgUseCommaCount is set to true, it will be |
2980 | | - * counted if it contains at least one comma. If it is set to false |
2981 | | - * (default), it will only be counted if it contains at least one [[wiki |
2982 | | - * link]]. See http://www.mediawiki.org/wiki/Manual:Article_count |
| 2978 | + * Method used to determine if a page in a content namespace should be counted |
| 2979 | + * as a valid article. |
2983 | 2980 | * |
2984 | | - * Retroactively changing this variable will not affect |
2985 | | - * the existing count (cf. maintenance/recount.sql). |
| 2981 | + * Redirect pages will never be counted as valid articles. |
| 2982 | + * |
| 2983 | + * This variable can have the following values: |
| 2984 | + * - 'any': all pages as considered as valid articles |
| 2985 | + * - 'comma': the page must contain a comma to be considered valid |
| 2986 | + * - 'link': the page must contain a [[wiki link]] to be considered valid |
| 2987 | + * - null: the value will be set at run time depending on $wgUseCommaCount: |
| 2988 | + * if $wgUseCommaCount is false, it will be 'link', if it is true |
| 2989 | + * it will be 'comma' |
| 2990 | + * |
| 2991 | + * See also See http://www.mediawiki.org/wiki/Manual:Article_count |
| 2992 | + * |
| 2993 | + * Retroactively changing this variable will not affect the existing count, |
| 2994 | + * to update it, you will need to run the maintenance/updateArticleCount.php |
| 2995 | + * script. |
2986 | 2996 | */ |
| 2997 | +$wgArticleCountMethod = null; |
| 2998 | + |
| 2999 | +/** |
| 3000 | + * Backward compatibility setting, will set $wgArticleCountMethod if it is null. |
| 3001 | + * @deprecated in 1.19; use $wgArticleCountMethod instead |
| 3002 | + */ |
2987 | 3003 | $wgUseCommaCount = false; |
2988 | 3004 | |
2989 | 3005 | /** |
Index: trunk/phase3/includes/Import.php |
— | — | @@ -1027,25 +1027,25 @@ |
1028 | 1028 | $tempTitle = $GLOBALS['wgTitle']; |
1029 | 1029 | $GLOBALS['wgTitle'] = $this->title; |
1030 | 1030 | |
1031 | | - if( $created ) { |
| 1031 | + if ( $created ) { |
1032 | 1032 | wfDebug( __METHOD__ . ": running onArticleCreate\n" ); |
1033 | 1033 | Article::onArticleCreate( $this->title ); |
1034 | | - |
1035 | | - wfDebug( __METHOD__ . ": running create updates\n" ); |
1036 | | - $article->createUpdates( $revision ); |
1037 | | - |
1038 | 1034 | } elseif( $changed ) { |
1039 | 1035 | wfDebug( __METHOD__ . ": running onArticleEdit\n" ); |
1040 | 1036 | Article::onArticleEdit( $this->title ); |
| 1037 | + } |
1041 | 1038 | |
1042 | | - wfDebug( __METHOD__ . ": running edit updates\n" ); |
1043 | | - $article->editUpdates( |
1044 | | - $this->getText(), |
1045 | | - $this->getComment(), |
1046 | | - $this->minor, |
1047 | | - $this->timestamp, |
1048 | | - $revId ); |
1049 | | - } |
| 1039 | + wfDebug( __METHOD__ . ": running updates\n" ); |
| 1040 | + $article->editUpdates( |
| 1041 | + $this->getText(), |
| 1042 | + $this->getComment(), |
| 1043 | + $this->minor, |
| 1044 | + $this->timestamp, |
| 1045 | + $revId, |
| 1046 | + true, |
| 1047 | + null, |
| 1048 | + $created ); |
| 1049 | + |
1050 | 1050 | $GLOBALS['wgTitle'] = $tempTitle; |
1051 | 1051 | |
1052 | 1052 | return true; |
Index: trunk/phase3/includes/Article.php |
— | — | @@ -27,7 +27,6 @@ |
28 | 28 | var $mContentLoaded = false; // !< |
29 | 29 | var $mCounter = -1; // !< Not loaded |
30 | 30 | var $mDataLoaded = false; // !< |
31 | | - var $mGoodAdjustment = 0; // !< |
32 | 31 | var $mIsRedirect = false; // !< |
33 | 32 | var $mLatest = false; // !< |
34 | 33 | var $mOldId; // !< |
— | — | @@ -61,7 +60,6 @@ |
62 | 61 | |
63 | 62 | var $mTimestamp = ''; // !< |
64 | 63 | var $mTitle; // !< Title object |
65 | | - var $mTotalAdjustment = 0; // !< |
66 | 64 | var $mTouched = '19700101000000'; // !< |
67 | 65 | |
68 | 66 | /** |
— | — | @@ -260,7 +258,6 @@ |
261 | 259 | $this->mRedirectTarget = null; # Title object if set |
262 | 260 | $this->mLastRevision = null; # Latest revision |
263 | 261 | $this->mTimestamp = ''; |
264 | | - $this->mGoodAdjustment = $this->mTotalAdjustment = 0; |
265 | 262 | $this->mTouched = '19700101000000'; |
266 | 263 | $this->mIsRedirect = false; |
267 | 264 | $this->mRevIdFetched = 0; |
— | — | @@ -644,15 +641,43 @@ |
645 | 642 | * Determine whether a page would be suitable for being counted as an |
646 | 643 | * article in the site_stats table based on the title & its content |
647 | 644 | * |
648 | | - * @param $text String: text to analyze |
649 | | - * @return bool |
| 645 | + * @param $editInfo Object or false: object returned by prepareTextForEdit(), |
| 646 | + * if false, the current database state will be used |
| 647 | + * @return Boolean |
650 | 648 | */ |
651 | | - public function isCountable( $text ) { |
652 | | - global $wgUseCommaCount; |
| 649 | + public function isCountable( $editInfo = false ) { |
| 650 | + global $wgArticleCountMethod; |
653 | 651 | |
654 | | - $token = $wgUseCommaCount ? ',' : '[['; |
| 652 | + if ( !$this->mTitle->isContentPage() ) { |
| 653 | + return false; |
| 654 | + } |
655 | 655 | |
656 | | - return $this->mTitle->isContentPage() && !$this->isRedirect( $text ) && in_string( $token, $text ); |
| 656 | + $text = $editInfo ? $editInfo->pst : false; |
| 657 | + |
| 658 | + if ( $this->isRedirect( $text ) ) { |
| 659 | + return false; |
| 660 | + } |
| 661 | + |
| 662 | + switch ( $wgArticleCountMethod ) { |
| 663 | + case 'any': |
| 664 | + return true; |
| 665 | + case 'comma': |
| 666 | + if ( $text === false ) { |
| 667 | + $text = $this->getRawText(); |
| 668 | + } |
| 669 | + return in_string( ',', $text ); |
| 670 | + case 'link': |
| 671 | + if ( $editInfo ) { |
| 672 | + // ParserOutput::getLinks() is a 2D array of page links, so |
| 673 | + // to be really correct we would need to recurse in the array |
| 674 | + // but the main array should only have items in it if there are |
| 675 | + // links. |
| 676 | + return (bool)count( $editInfo->output->getLinks() ); |
| 677 | + } else { |
| 678 | + return (bool)wfGetDB( DB_SLAVE )->selectField( 'pagelinks', 1, |
| 679 | + array( 'pl_from' => $this->getId() ), __METHOD__ ); |
| 680 | + } |
| 681 | + } |
657 | 682 | } |
658 | 683 | |
659 | 684 | /** |
— | — | @@ -2067,10 +2092,6 @@ |
2068 | 2093 | $changed = ( strcmp( $text, $oldtext ) != 0 ); |
2069 | 2094 | |
2070 | 2095 | if ( $changed ) { |
2071 | | - $this->mGoodAdjustment = (int)$this->isCountable( $text ) |
2072 | | - - (int)$this->isCountable( $oldtext ); |
2073 | | - $this->mTotalAdjustment = 0; |
2074 | | - |
2075 | 2096 | if ( !$this->mLatest ) { |
2076 | 2097 | # Article gone missing |
2077 | 2098 | wfDebug( __METHOD__ . ": EDIT_UPDATE specified but article doesn't exist\n" ); |
— | — | @@ -2165,12 +2186,6 @@ |
2166 | 2187 | # Create new article |
2167 | 2188 | $status->value['new'] = true; |
2168 | 2189 | |
2169 | | - # Set statistics members |
2170 | | - # We work out if it's countable after PST to avoid counter drift |
2171 | | - # when articles are created with {{subst:}} |
2172 | | - $this->mGoodAdjustment = (int)$this->isCountable( $text ); |
2173 | | - $this->mTotalAdjustment = 1; |
2174 | | - |
2175 | 2190 | $dbw->begin(); |
2176 | 2191 | |
2177 | 2192 | # Add the page record; stake our claim on this title! |
— | — | @@ -2226,7 +2241,7 @@ |
2227 | 2242 | $dbw->commit(); |
2228 | 2243 | |
2229 | 2244 | # Update links, etc. |
2230 | | - $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, true, $user ); |
| 2245 | + $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, true, $user, true ); |
2231 | 2246 | |
2232 | 2247 | # Clear caches |
2233 | 2248 | Article::onArticleCreate( $this->mTitle ); |
— | — | @@ -3064,7 +3079,7 @@ |
3065 | 3080 | return false; |
3066 | 3081 | } |
3067 | 3082 | |
3068 | | - $u = new SiteStatsUpdate( 0, 1, - (int)$this->isCountable( $this->getRawText() ), -1 ); |
| 3083 | + $u = new SiteStatsUpdate( 0, 1, - (int)$this->isCountable(), -1 ); |
3069 | 3084 | array_push( $wgDeferredUpdateList, $u ); |
3070 | 3085 | |
3071 | 3086 | // Bitfields to further suppress the content |
— | — | @@ -3511,8 +3526,11 @@ |
3512 | 3527 | * @param $newid Integer: rev_id value of the new revision |
3513 | 3528 | * @param $changed Boolean: Whether or not the content actually changed |
3514 | 3529 | * @param $user User object: User doing the edit |
| 3530 | + * @param $created Boolean: Whether the edit created the page |
3515 | 3531 | */ |
3516 | | - public function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid, $changed = true, User $user = null ) { |
| 3532 | + public function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid, |
| 3533 | + $changed = true, User $user = null, $created = false ) |
| 3534 | + { |
3517 | 3535 | global $wgDeferredUpdateList, $wgUser, $wgEnableParserCache; |
3518 | 3536 | |
3519 | 3537 | wfProfileIn( __METHOD__ ); |
— | — | @@ -3564,11 +3582,20 @@ |
3565 | 3583 | return; |
3566 | 3584 | } |
3567 | 3585 | |
3568 | | - $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment, $this->mTotalAdjustment ); |
3569 | | - array_push( $wgDeferredUpdateList, $u ); |
3570 | | - $u = new SearchUpdate( $id, $title, $text ); |
3571 | | - array_push( $wgDeferredUpdateList, $u ); |
| 3586 | + if ( !$changed ) { |
| 3587 | + $good = 0; |
| 3588 | + $total = 0; |
| 3589 | + } elseif ( $created ) { |
| 3590 | + $good = (int)$this->isCountable( $editInfo ); |
| 3591 | + $total = 1; |
| 3592 | + } else { |
| 3593 | + $good = (int)$this->isCountable( $editInfo ) - (int)$this->isCountable(); |
| 3594 | + $total = 0; |
| 3595 | + } |
3572 | 3596 | |
| 3597 | + $wgDeferredUpdateList[] = new SiteStatsUpdate( 0, 1, $good, $total ); |
| 3598 | + $wgDeferredUpdateList[] = new SearchUpdate( $id, $title, $text ); |
| 3599 | + |
3573 | 3600 | # If this is another user's talk page, update newtalk |
3574 | 3601 | # Don't do this if $changed = false otherwise some idiot can null-edit a |
3575 | 3602 | # load of user talk pages and piss people off, nor if it's a minor edit |
— | — | @@ -3608,10 +3635,8 @@ |
3609 | 3636 | * anymore. |
3610 | 3637 | */ |
3611 | 3638 | public function createUpdates( $rev ) { |
3612 | | - $this->mGoodAdjustment = $this->isCountable( $rev->getText() ); |
3613 | | - $this->mTotalAdjustment = 1; |
3614 | 3639 | $this->editUpdates( $rev->getText(), $rev->getComment(), |
3615 | | - $rev->isMinor(), wfTimestamp(), $rev->getId(), true ); |
| 3640 | + $rev->isMinor(), wfTimestamp(), $rev->getId(), true, null, true ); |
3616 | 3641 | } |
3617 | 3642 | |
3618 | 3643 | /** |
Index: trunk/phase3/includes/SiteStats.php |
— | — | @@ -285,18 +285,24 @@ |
286 | 286 | * @return Integer |
287 | 287 | */ |
288 | 288 | public function articles() { |
289 | | - global $wgUseCommaCount; |
| 289 | + global $wgArticleCountMethod; |
290 | 290 | |
291 | 291 | $tables = array( 'page' ); |
292 | 292 | $conds = array( |
293 | 293 | 'page_namespace' => MWNamespace::getContentNamespaces(), |
294 | 294 | 'page_is_redirect' => 0, |
295 | | - 'page_len > 0' |
296 | 295 | ); |
297 | 296 | |
298 | | - if ( !$wgUseCommaCount ) { |
| 297 | + if ( $wgArticleCountMethod == 'link' ) { |
299 | 298 | $tables[] = 'pagelinks'; |
300 | 299 | $conds[] = 'pl_from=page_id'; |
| 300 | + } elseif ( $wgArticleCountMethod == 'comma' ) { |
| 301 | + // To make a correct check for this, we would need, for each page, |
| 302 | + // to load the text, maybe uncompress it, maybe decode it and then |
| 303 | + // check if there's one comma. |
| 304 | + // But one thing we are sure is that if the page is empty, it can't |
| 305 | + // contain a comma :) |
| 306 | + $conds[] = 'page_len > 0'; |
301 | 307 | } |
302 | 308 | |
303 | 309 | $this->mArticles = $this->db->selectField( $tables, 'COUNT(DISTINCT page_id)', |
Index: trunk/phase3/includes/Setup.php |
— | — | @@ -293,6 +293,10 @@ |
294 | 294 | # Blacklisted file extensions shouldn't appear on the "allowed" list |
295 | 295 | $wgFileExtensions = array_diff ( $wgFileExtensions, $wgFileBlacklist ); |
296 | 296 | |
| 297 | +if ( $wgArticleCountMethod === null ) { |
| 298 | + $wgArticleCountMethod = $wgUseCommaCount ? 'comma' : 'link'; |
| 299 | +} |
| 300 | + |
297 | 301 | if ( $wgInvalidateCacheOnLocalSettingsChange ) { |
298 | 302 | $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( "$IP/LocalSettings.php" ) ) ); |
299 | 303 | } |
Index: trunk/phase3/includes/actions/DeleteAction.php |
— | — | @@ -245,7 +245,7 @@ |
246 | 246 | return false; |
247 | 247 | } |
248 | 248 | |
249 | | - $updates = new SiteStatsUpdate( 0, 1, - (int)$page->isCountable( $page->getRawText() ), -1 ); |
| 249 | + $updates = new SiteStatsUpdate( 0, 1, - (int)$page->isCountable(), -1 ); |
250 | 250 | array_push( $wgDeferredUpdateList, $updates ); |
251 | 251 | |
252 | 252 | // Bitfields to further suppress the content |