Index: trunk/extensions/PageTriage/PageTriage.hooks.php |
— | — | @@ -0,0 +1,105 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class PageTriageHooks { |
| 5 | + |
| 6 | + /** |
| 7 | + * Mark a page as untriaged after moving the page if the new title is in main namespace |
| 8 | + * |
| 9 | + * @see http://www.mediawiki.org/wiki/Manual:Hooks/SpecialMovepageAfterMove |
| 10 | + * @param $movePage: MovePageForm object |
| 11 | + * @param $oldTitle: old title object |
| 12 | + * @param $newTitle: new title object |
| 13 | + * @return bool |
| 14 | + */ |
| 15 | + public static function onSpecialMovepageAfterMove( $movePage, &$oldTitle, &$newTitle ) { |
| 16 | + $pageId = $newTitle->getArticleID(); |
| 17 | + |
| 18 | + if ( $newTitle->getNamespace() === NS_MAIN ) { |
| 19 | + self::addToPageTriageQueue( $pageId ); |
| 20 | + } |
| 21 | + |
| 22 | + //@Todo - find a solution for partial data compilation |
| 23 | + $articleMetadata = new ArticleMetadata( array( $pageId ) ); |
| 24 | + $articleMetadata->compileMetadata(); |
| 25 | + |
| 26 | + return true; |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Check if a page is created from a redirect page, then insert into it PageTriage Queue |
| 31 | + * |
| 32 | + * @see http://www.mediawiki.org/wiki/Manual:Hooks/NewRevisionFromEditComplete |
| 33 | + * @param $article: the WikiPage edited |
| 34 | + * @param $rev: the new revision |
| 35 | + * @param $baseID: the revision ID this was based off, if any |
| 36 | + * @param $user: the editing user |
| 37 | + * @return bool |
| 38 | + */ |
| 39 | + public static function onNewRevisionFromEditComplete( $article, $rev, $baseID, $user ) { |
| 40 | + $prev = $rev->getPrevious(); |
| 41 | + if ( $prev && !$article->isRedirect() && $article->isRedirect( $prev->getRawText() ) ) { |
| 42 | + self::addToPageTriageQueue( $article->getId() ); |
| 43 | + } |
| 44 | + return true; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Insert new page into PageTriage Queue |
| 49 | + * |
| 50 | + * @see http://www.mediawiki.org/wiki/Manual:Hooks/ArticleInsertComplete |
| 51 | + * @param $article: WikiPage created |
| 52 | + * @param $user: User creating the article |
| 53 | + * @param $text: New content |
| 54 | + * @param $summary: Edit summary/comment |
| 55 | + * @param $isMinor: Whether or not the edit was marked as minor |
| 56 | + * @param $isWatch: (No longer used) |
| 57 | + * @param $section: (No longer used) |
| 58 | + * @param $flags: Flags passed to Article::doEdit() |
| 59 | + * @param $revision: New Revision of the article |
| 60 | + * @return bool |
| 61 | + */ |
| 62 | + public static function onArticleInsertComplete( $article, $user, $text, $summary, $isMinor, $isWatch, $section, $flags, $revision ) { |
| 63 | + self::addToPageTriageQueue( $article->getId() ); |
| 64 | + |
| 65 | + return true; |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Compile the metadata on successful save, this is only for page in PageTriage Queue already |
| 70 | + * |
| 71 | + * @see http://www.mediawiki.org/wiki/Manual:Hooks/ArticleSaveComplete |
| 72 | + * @param $article WikiPage |
| 73 | + * @param $user |
| 74 | + * @param $text |
| 75 | + * @param $summary |
| 76 | + * @param $minoredit |
| 77 | + * @param $watchthis |
| 78 | + * @param $sectionanchor |
| 79 | + * @param $flags |
| 80 | + * @param $revision |
| 81 | + * @param $status |
| 82 | + * @param $baseRevId |
| 83 | + * @return bool |
| 84 | + */ |
| 85 | + public static function onArticleSaveComplete( $article, $user, $text, $summary, $minoredit, $watchthis, $sectionanchor, $flags, $revision, $status, $baseRevId ) { |
| 86 | + $articleMetadata = new ArticleMetadata( array( $article->getId() ) ); |
| 87 | + $articleMetadata->compileMetadata(); |
| 88 | + return true; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Add page to page triage queue |
| 93 | + */ |
| 94 | + private static function addToPageTriageQueue( $pageId ) { |
| 95 | + $dbw = wfGetDB( DB_MASTER ); |
| 96 | + |
| 97 | + $row = array( |
| 98 | + 'ptrp_page_id' => $pageId, |
| 99 | + 'ptrp_triaged' => 0, |
| 100 | + 'ptrp_timestamp' => $dbw->timestamp( wfTimestampNow() ) |
| 101 | + ); |
| 102 | + |
| 103 | + $dbw->replace( 'pagetriage_page', array( 'ptrp_page_id' ), $row, __METHOD__ ); |
| 104 | + } |
| 105 | + |
| 106 | +} |
Index: trunk/extensions/PageTriage/includes/ArticleMetadata.php |
— | — | @@ -374,8 +374,8 @@ |
375 | 375 | $metaData[$row->page_id]['user_name'] = $user->getName(); |
376 | 376 | $metaData[$row->page_id]['user_editcount'] = $user->getEditCount(); |
377 | 377 | $metaData[$row->page_id]['user_creation_date'] = wfTimestamp( TS_MW, $user->getRegistration() ); |
378 | | - $metaData[$row->page_id]['user_autoconfirmed'] = $user->isAllowed( 'autoconfirmed' ); |
379 | | - $metaData[$row->page_id]['user_bot'] = $user->isAllowed( 'bot' ); |
| 378 | + $metaData[$row->page_id]['user_autoconfirmed'] = $user->isAllowed( 'autoconfirmed' ) ? '1' : '0'; |
| 379 | + $metaData[$row->page_id]['user_bot'] = $user->isAllowed( 'bot' ) ? '1' : '0'; |
380 | 380 | $metaData[$row->page_id]['user_block_status'] = $user->isBlocked() ? '1' : '0'; |
381 | 381 | } |
382 | 382 | } |
Index: trunk/extensions/PageTriage/PageTriage.php |
— | — | @@ -52,6 +52,7 @@ |
53 | 53 | $wgSpecialPages['PageTriage'] = 'SpecialPageTriage'; |
54 | 54 | $wgSpecialPageGroups['PageTriage'] = 'changes'; |
55 | 55 | $wgAutoloadClasses['ArticleMetadata'] = $dir . 'includes/ArticleMetadata.php'; |
| 56 | +$wgAutoloadClasses['PageTriageHooks'] = $dir . 'PageTriage.hooks.php'; |
56 | 57 | |
57 | 58 | $wgAutoloadClasses['ApiQueryPageTriage'] = $dir . 'api/ApiQueryPageTriage.php'; |
58 | 59 | $wgAutoloadClasses['ApiPageTriageGetMetadata'] = $dir . 'api/ApiPageTriageGetMetadata.php'; |
— | — | @@ -64,7 +65,12 @@ |
65 | 66 | $wgAPIModules['pagetriage'] = 'ApiQueryPageTriage'; |
66 | 67 | $wgAPIModules['pagetriagegetmetadata'] = 'ApiPageTriageGetMetadata'; |
67 | 68 | |
| 69 | +// hooks |
68 | 70 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'efPageTriageSchemaUpdates'; |
| 71 | +$wgHooks['SpecialMovepageAfterMove'][] = 'PageTriageHooks::onSpecialMovepageAfterMove'; |
| 72 | +$wgHooks['NewRevisionFromEditComplete'][] = 'PageTriageHooks::onNewRevisionFromEditComplete'; |
| 73 | +$wgHooks['ArticleInsertComplete'][] = 'PageTriageHooks::onArticleInsertComplete'; |
| 74 | +$wgHooks['ArticleSaveComplete'][] = 'PageTriageHooks::onArticleSaveComplete'; |
69 | 75 | |
70 | 76 | /** |
71 | 77 | * @param $updater DatabaseUpdater |