Index: trunk/extensions/ApprovedRevs/SpecialApprovedRevs.php |
— | — | @@ -1,33 +1,44 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * Special page that lists all pages that have an approved revision. |
| 4 | + * Special page that displays various lists of pages that either do or do |
| 5 | + * not have an approved revision. |
5 | 6 | * |
6 | 7 | * @author Yaron Koren |
7 | 8 | */ |
8 | 9 | |
9 | 10 | if ( !defined( 'MEDIAWIKI' ) ) die(); |
10 | 11 | |
11 | | -class ARApprovedPages extends SpecialPage { |
| 12 | +class SpecialApprovedRevs extends SpecialPage { |
12 | 13 | |
13 | 14 | /** |
14 | 15 | * Constructor |
15 | 16 | */ |
16 | 17 | function __construct() { |
17 | | - parent::__construct( 'ApprovedPages' ); |
| 18 | + parent::__construct( 'ApprovedRevs' ); |
18 | 19 | wfLoadExtensionMessages( 'ApprovedRevs' ); |
19 | 20 | } |
20 | 21 | |
21 | 22 | function execute( $query ) { |
| 23 | + global $wgRequest; |
| 24 | + |
| 25 | + ApprovedRevs::addCSS(); |
22 | 26 | $this->setHeaders(); |
23 | 27 | list( $limit, $offset ) = wfCheckLimits(); |
24 | | - $rep = new ARApprovedPagesPage(); |
| 28 | + $mode = $wgRequest->getVal( 'show' ); |
| 29 | + $rep = new SpecialApprovedRevsPage( $mode ); |
25 | 30 | return $rep->doQuery( $offset, $limit ); |
26 | 31 | } |
27 | 32 | } |
28 | 33 | |
29 | | -class ARApprovedPagesPage extends QueryPage { |
| 34 | +class SpecialApprovedRevsPage extends QueryPage { |
| 35 | + private $mMode; |
| 36 | + |
| 37 | + public function __construct( $mode ) { |
| 38 | + $this->mMode = $mode; |
| 39 | + } |
| 40 | + |
30 | 41 | function getName() { |
31 | | - return "ApprovedPages"; |
| 42 | + return "ApprovedRevs"; |
32 | 43 | } |
33 | 44 | |
34 | 45 | function isExpensive() { return false; } |
— | — | @@ -35,10 +46,64 @@ |
36 | 47 | function isSyndicated() { return false; } |
37 | 48 | |
38 | 49 | function getPageHeader() { |
39 | | - $header = Xml::element( 'p', null, wfMsg( 'approvedrevs-approvedpages-docu' ) ) . "<br />\n"; |
| 50 | + // show the names of the three lists of pages, with the one |
| 51 | + // corresponding to the current "mode" not being linked |
| 52 | + $approvedPagesPage = SpecialPage::getPage( 'ApprovedRevs' ); |
| 53 | + $approvedPagesTitle = SpecialPage::getPage( 'ApprovedRevs' )->getTitle(); |
| 54 | + $navLine = wfMsg( 'approvedrevs-view' ) . ' '; |
| 55 | + if ( $this->mMode == '' ) { |
| 56 | + $navLine .= Xml::element( 'strong', |
| 57 | + null, |
| 58 | + wfMsg( 'approvedrevs-approvedpages' ) |
| 59 | + ); |
| 60 | + } else { |
| 61 | + $navLine .= Xml::element( 'a', |
| 62 | + array( 'href' => $approvedPagesTitle->getLocalURL() ), |
| 63 | + wfMsg( 'approvedrevs-approvedpages' ) |
| 64 | + ); |
| 65 | + } |
| 66 | + $navLine .= " | "; |
| 67 | + if ( $this->mMode == 'notlatest' ) { |
| 68 | + $navLine .= Xml::element( 'strong', |
| 69 | + null, |
| 70 | + wfMsg( 'approvedrevs-notlatest' ) |
| 71 | + ); |
| 72 | + } else { |
| 73 | + $navLine .= Xml::element( 'a', |
| 74 | + array( 'href' => $approvedPagesTitle->getLocalURL( array( 'show' => 'notlatest' ) ) ), |
| 75 | + wfMsg( 'approvedrevs-notlatest' ) |
| 76 | + ); |
| 77 | + } |
| 78 | + $navLine .= " | "; |
| 79 | + if ( $this->mMode == 'unapproved' ) { |
| 80 | + $navLine .= Xml::element( 'strong', |
| 81 | + null, |
| 82 | + wfMsg( 'approvedrevs-unapprovedpages' ) |
| 83 | + ); |
| 84 | + } else { |
| 85 | + $navLine .= Xml::element( 'a', |
| 86 | + array( 'href' => $approvedPagesTitle->getLocalURL( array( 'show' => 'unapproved' ) ) ), |
| 87 | + wfMsg( 'approvedrevs-unapprovedpages' ) |
| 88 | + ); |
| 89 | + } |
| 90 | + $header = Xml::tags( 'p', null, $navLine ) . "\n"; |
40 | 91 | return $header; |
41 | 92 | } |
42 | 93 | |
| 94 | + /** |
| 95 | + * Set parameters for standard navigation links. |
| 96 | + */ |
| 97 | + function linkParameters() { |
| 98 | + $params = array(); |
| 99 | + if ( $this->mMode == 'notlatest' ) { |
| 100 | + $params['show'] = 'notlatest'; |
| 101 | + } elseif ( $this->mMode == 'unapproved' ) { |
| 102 | + $params['show'] = 'unapproved'; |
| 103 | + } else { // all approved pages |
| 104 | + } |
| 105 | + return $params; |
| 106 | + } |
| 107 | + |
43 | 108 | function getPageFooter() { |
44 | 109 | } |
45 | 110 | |
— | — | @@ -46,10 +111,28 @@ |
47 | 112 | $dbr = wfGetDB( DB_SLAVE ); |
48 | 113 | $approved_revs = $dbr->tableName( 'approved_revs' ); |
49 | 114 | $page = $dbr->tableName( 'page' ); |
50 | | - return "SELECT 'Page' AS type, |
51 | | - p.page_id AS id |
52 | | - FROM $approved_revs ar JOIN $page p |
53 | | - ON ar.page_id = p.page_id"; |
| 115 | + if ( $this->mMode == 'notlatest' ) { |
| 116 | + return "SELECT 'Page' AS type, |
| 117 | + p.page_id AS id, |
| 118 | + ar.rev_id AS rev_id, |
| 119 | + p.page_latest AS latest_id |
| 120 | + FROM $approved_revs ar JOIN $page p |
| 121 | + ON ar.page_id = p.page_id |
| 122 | + WHERE p.page_latest != ar.rev_id"; |
| 123 | + } elseif ( $this->mMode == 'unapproved' ) { |
| 124 | + return "SELECT 'Page' AS type, |
| 125 | + p.page_id AS id |
| 126 | + FROM $approved_revs ar RIGHT OUTER JOIN $page p |
| 127 | + ON ar.page_id = p.page_id |
| 128 | + WHERE ar.page_id IS NULL"; |
| 129 | + } else { // all approved pages |
| 130 | + return "SELECT 'Page' AS type, |
| 131 | + p.page_id AS id, |
| 132 | + ar.rev_id AS rev_id, |
| 133 | + p.page_latest AS latest_id |
| 134 | + FROM $approved_revs ar JOIN $page p |
| 135 | + ON ar.page_id = p.page_id"; |
| 136 | + } |
54 | 137 | } |
55 | 138 | |
56 | 139 | function getOrder() { |
— | — | @@ -58,6 +141,21 @@ |
59 | 142 | |
60 | 143 | function formatResult( $skin, $result ) { |
61 | 144 | $title = Title::newFromId( $result->id ); |
62 | | - return $skin->makeLinkObj( $title ); |
| 145 | + $pageLink = $skin->makeLinkObj( $title ); |
| 146 | + if ( $this->mMode == 'unapproved' ) { |
| 147 | + return $pageLink; |
| 148 | + } else { |
| 149 | + if ( $result->rev_id == $result->latest_id ) { |
| 150 | + $class = "approvedRevIsLatest"; |
| 151 | + } else { |
| 152 | + $class = "approvedRevNotLatest"; |
| 153 | + } |
| 154 | + return $pageLink . ' (' . |
| 155 | + Xml::element( 'span', |
| 156 | + array ( 'class' => $class ), |
| 157 | + wfMsg( 'approvedrevs-revisionnumber', $result->rev_id ) |
| 158 | + ) . |
| 159 | + ')'; |
| 160 | + } |
63 | 161 | } |
64 | 162 | } |