Index: trunk/extensions/ApprovedRevs/maintenance/approveAllPages.php |
— | — | @@ -55,7 +55,7 @@ |
56 | 56 | // some extensions, like Semantic Forms, need $wgTitle |
57 | 57 | // set as well |
58 | 58 | $wgTitle = $title; |
59 | | - if ( ApprovedRevs::hasSupportedNamespace( $title ) && |
| 59 | + if ( ApprovedRevs::pageIsApprovable( $title ) && |
60 | 60 | ! ApprovedRevs::hasApprovedRevision( $title ) ) { |
61 | 61 | ApprovedRevs::setApprovedRevID( $title, $page->page_latest ); |
62 | 62 | $this->output( wfTimestamp( TS_DB ) . ' Approved the last revision of page "' . $title->getFullText() . '".' ); |
Index: trunk/extensions/ApprovedRevs/ApprovedRevs_body.php |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | * one. |
16 | 16 | */ |
17 | 17 | public static function getApprovedRevID( $title ) { |
18 | | - if ( ! self::hasSupportedNamespace( $title ) ) { |
| 18 | + if ( ! self::pageIsApprovable( $title ) ) { |
19 | 19 | return null; |
20 | 20 | } |
21 | 21 | $dbr = wfGetDB( DB_SLAVE ); |
— | — | @@ -45,12 +45,37 @@ |
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | | - * Returns whether this page is in a namespace that the Approved Revs |
50 | | - * extension doesn't support. |
| 49 | + * Returns whether this page can be approved - either because it's in |
| 50 | + * a supported namespace, or because it's been specially marked as |
| 51 | + * approvable. Also stores the boolean answer as a field in the page |
| 52 | + * object, to speed up processing if it's called more than once. |
51 | 53 | */ |
52 | | - public static function hasSupportedNamespace( $title ) { |
| 54 | + public static function pageIsApprovable( $title ) { |
| 55 | + // if this function was already called for this page, the |
| 56 | + // value should have been stored as a field in the $title object |
| 57 | + if ( ! is_null( $title->isApprovable ) ) { |
| 58 | + return $title->isApprovable; |
| 59 | + } |
| 60 | + |
| 61 | + // check the namespace |
53 | 62 | global $egApprovedRevsNamespaces; |
54 | | - return( in_array( $title->getNamespace(), $egApprovedRevsNamespaces ) ); |
| 63 | + if ( in_array( $title->getNamespace(), $egApprovedRevsNamespaces ) ) { |
| 64 | + $title->isApprovable = true; |
| 65 | + return true; |
| 66 | + } |
| 67 | + |
| 68 | + // it's not in an included namespace, so check for the page |
| 69 | + // property - for some reason, calling the standard |
| 70 | + // getProperty() function doesn't work, so we just do a DB |
| 71 | + // query on the page_props table |
| 72 | + $dbr = wfGetDB( DB_SLAVE ); |
| 73 | + extract( $dbr->tableNames( 'page', 'page_props' ) ); |
| 74 | + $sql = "SELECT COUNT(*) FROM $page_props WHERE pp_page = {$title->getArticleID()} AND pp_propname = 'approvedrevs' AND pp_value = 'y'"; |
| 75 | + $res = $dbr->query( $sql ); |
| 76 | + $row = $dbr->fetchRow( $res ); |
| 77 | + $isApprovable = ( $row[0] == '1' ); |
| 78 | + $title->isApprovable = $isApprovable; |
| 79 | + return $isApprovable; |
55 | 80 | } |
56 | 81 | |
57 | 82 | /** |
Index: trunk/extensions/ApprovedRevs/ApprovedRevs.php |
— | — | @@ -47,6 +47,9 @@ |
48 | 48 | $wgHooks['UnknownAction'][] = 'ApprovedRevsHooks::unsetAsApproved'; |
49 | 49 | $wgHooks['BeforeParserFetchTemplateAndtitle'][] = 'ApprovedRevsHooks::setTranscludedPageRev'; |
50 | 50 | $wgHooks['ArticleDeleteComplete'][] = 'ApprovedRevsHooks::deleteRevisionApproval'; |
| 51 | +$wgHooks['MagicWordwgVariableIDs'][] = 'ApprovedRevsHooks::addMagicWordVariableIDs'; |
| 52 | +$wgHooks['LanguageGetMagic'][] = 'ApprovedRevsHooks::addMagicWordLanguage'; |
| 53 | +$wgHooks['ParserBeforeTidy'][] = 'ApprovedRevsHooks::handleMagicWords'; |
51 | 54 | $wgHooks['AdminLinks'][] = 'ApprovedRevsHooks::addToAdminLinks'; |
52 | 55 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'ApprovedRevsHooks::describeDBSchema'; |
53 | 56 | |
Index: trunk/extensions/ApprovedRevs/ApprovedRevs.hooks.php |
— | — | @@ -144,7 +144,7 @@ |
145 | 145 | */ |
146 | 146 | static function addApprovalLink( $historyPage, &$row , &$s ) { |
147 | 147 | $title = $historyPage->getTitle(); |
148 | | - if ( ! ApprovedRevs::hasSupportedNamespace( $title ) ) { |
| 148 | + if ( ! ApprovedRevs::pageIsApprovable( $title ) ) { |
149 | 149 | return true; |
150 | 150 | } |
151 | 151 | |
— | — | @@ -188,7 +188,7 @@ |
189 | 189 | return true; |
190 | 190 | } |
191 | 191 | $title = $article->getTitle(); |
192 | | - if ( ! ApprovedRevs::hasSupportedNamespace( $title ) ) { |
| 192 | + if ( ! ApprovedRevs::pageIsApprovable( $title ) ) { |
193 | 193 | return true; |
194 | 194 | } |
195 | 195 | if ( ! $title->userCan( 'approverevisions' ) ) { |
— | — | @@ -275,6 +275,38 @@ |
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
| 279 | + * Register magic-word variable IDs |
| 280 | + */ |
| 281 | + static function addMagicWordVariableIDs( &$magicWordVariableIDs ) { |
| 282 | + $magicWordVariableIDs[] = 'MAG_APPROVEDREVS'; |
| 283 | + return true; |
| 284 | + } |
| 285 | + |
| 286 | + /** |
| 287 | + * Set the actual value of the magic words |
| 288 | + */ |
| 289 | + static function addMagicWordLanguage( &$magicWords, $langCode ) { |
| 290 | + switch( $langCode ) { |
| 291 | + default: |
| 292 | + $magicWords['MAG_APPROVEDREVS'] = array( 0, '__APPROVEDREVS__' ); |
| 293 | + } |
| 294 | + return true; |
| 295 | + } |
| 296 | + |
| 297 | + /** |
| 298 | + * Set values in the page_props table based on the presence of the |
| 299 | + * 'APPROVEDREVS' magic word in a page |
| 300 | + */ |
| 301 | + static function handleMagicWords( &$parser, &$text ) { |
| 302 | + global $wgOut, $wgAction; |
| 303 | + $mw_hide = MagicWord::get( 'MAG_APPROVEDREVS' ); |
| 304 | + if ( $mw_hide->matchAndRemove( $text ) ) { |
| 305 | + $parser->mOutput->setProperty( 'approvedrevs', 'y' ); |
| 306 | + } |
| 307 | + return true; |
| 308 | + } |
| 309 | + |
| 310 | + /** |
279 | 311 | * Adds a link to 'Special:ApprovedPages' to the the page |
280 | 312 | * 'Special:AdminLinks', defined by the Admin Links extension. |
281 | 313 | */ |