Index: branches/wmf/1.18wmf1/extensions/CentralNotice/CentralNoticePageLogPager.php |
— | — | @@ -0,0 +1,207 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * This class generates a paginated log of recent changes to banner messages (the parts that get |
| 6 | + * translated). We use the rencentchanges table since it is lightweight, however, this means that |
| 7 | + * the log only goes back 30 days. |
| 8 | + */ |
| 9 | +class CentralNoticePageLogPager extends ReverseChronologicalPager { |
| 10 | + var $viewPage, $special, $logType; |
| 11 | + |
| 12 | + /** |
| 13 | + * Construct instance of class. |
| 14 | + * @param $special object calling object |
| 15 | + * @param $type string type of log - 'bannercontent' or 'bannermessages' (optional) |
| 16 | + */ |
| 17 | + function __construct( $special, $type = 'bannercontent' ) { |
| 18 | + $this->special = $special; |
| 19 | + parent::__construct( $special ); |
| 20 | + |
| 21 | + $this->viewPage = SpecialPage::getTitleFor( 'NoticeTemplate', 'view' ); |
| 22 | + $this->logType = $type; |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * Sort the log list by timestamp |
| 27 | + */ |
| 28 | + function getIndexField() { |
| 29 | + return 'rc_timestamp'; |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Pull log entries from the database |
| 34 | + */ |
| 35 | + function getQueryInfo() { |
| 36 | + $conds = array( |
| 37 | + 'rc_bot' => 1, // include bot edits (all edits made by CentralNotice are bot edits) |
| 38 | + 'rc_namespace' => 8, // only MediaWiki pages |
| 39 | + ); |
| 40 | + if ( $this->logType == 'bannercontent' ) { |
| 41 | + // Add query contitions for banner content log |
| 42 | + $conds += array( |
| 43 | + "rc_title LIKE 'Centralnotice-template-%'", // get banner content |
| 44 | + ); |
| 45 | + } else { |
| 46 | + // Add query contitions for banner messages log |
| 47 | + $conds += array( |
| 48 | + "rc_title LIKE 'Centralnotice-%'", // get banner messages |
| 49 | + "rc_title NOT LIKE 'Centralnotice-template-%'", // exclude normal banner content |
| 50 | + ); |
| 51 | + } |
| 52 | + return array( |
| 53 | + 'tables' => array( 'recentchanges' ), |
| 54 | + 'fields' => '*', |
| 55 | + 'conds' => $conds, // WHERE conditions |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Generate the content of each table row (1 row = 1 log entry) |
| 61 | + */ |
| 62 | + function formatRow( $row ) { |
| 63 | + global $wgLang, $wgExtensionAssetsPath; |
| 64 | + |
| 65 | + // Create a user object so we can pull the name, user page, etc. |
| 66 | + $loggedUser = User::newFromId( $row->rc_user ); |
| 67 | + // Create the user page link |
| 68 | + $userLink = $this->getSkin()->makeLinkObj( $loggedUser->getUserPage(), |
| 69 | + $loggedUser->getName() ); |
| 70 | + $userTalkLink = $this->getSkin()->makeLinkObj( $loggedUser->getTalkPage(), |
| 71 | + wfMsg ( 'centralnotice-talk-link' ) ); |
| 72 | + |
| 73 | + $language = 'en'; // English is the default for CentralNotice messages |
| 74 | + |
| 75 | + if ( $this->logType == 'bannercontent' ) { |
| 76 | + // Extract the banner name from the title |
| 77 | + $pattern = '/Centralnotice-template-(.*)/'; |
| 78 | + preg_match( $pattern, $row->rc_title, $matches ); |
| 79 | + $banner = $matches[1]; |
| 80 | + } else if ( $this->logType == 'bannermessages' ) { |
| 81 | + // Split the title into banner, message, and language |
| 82 | + $titlePieces = explode( "/", $row->rc_title, 2 ); |
| 83 | + $titleBase = $titlePieces[0]; |
| 84 | + if ( array_key_exists( 1, $titlePieces ) ) $language = $titlePieces[1]; |
| 85 | + $pattern = '/Centralnotice-([^-]*)-(.*)/'; |
| 86 | + preg_match( $pattern, $titleBase, $matches ); |
| 87 | + $banner = $matches[1]; |
| 88 | + $message = $matches[2]; |
| 89 | + } |
| 90 | + |
| 91 | + // Create banner link |
| 92 | + $bannerLink = $this->getSkin()->makeLinkObj( $this->viewPage, |
| 93 | + htmlspecialchars( $banner ), |
| 94 | + 'template=' . urlencode( $banner ) ); |
| 95 | + |
| 96 | + // Create title object |
| 97 | + $title = Title::newFromText( "MediaWiki:{$row->rc_title}" ); |
| 98 | + |
| 99 | + if ( $this->logType == 'bannercontent' ) { |
| 100 | + // If the banner was just created, show a link to the banner. If the banner was |
| 101 | + // edited, show a link to the banner and a link to the diff. |
| 102 | + if ( $row->rc_new ) { |
| 103 | + $bannerCell = $bannerLink; |
| 104 | + } else { |
| 105 | + $querydiff = array( |
| 106 | + 'curid' => $row->rc_cur_id, |
| 107 | + 'diff' => $row->rc_this_oldid, |
| 108 | + 'oldid' => $row->rc_last_oldid |
| 109 | + ); |
| 110 | + $diffUrl = htmlspecialchars( $title->getLinkUrl( $querydiff ) ); |
| 111 | + // Should "diff" be localized? It appears not to be elsewhere in the interface. |
| 112 | + // See ChangesList->preCacheMessages() for example. |
| 113 | + $bannerCell = $bannerLink . " (<a href=\"$diffUrl\">diff</a>)"; |
| 114 | + } |
| 115 | + } else if ( $this->logType == 'bannermessages' ) { |
| 116 | + $bannerCell = $bannerLink; |
| 117 | + |
| 118 | + // Create the message link |
| 119 | + $messageLink = $this->getSkin()->makeLinkObj( $title, htmlspecialchars( $message ) ); |
| 120 | + |
| 121 | + // If the message was just created, show a link to the message. If the message was |
| 122 | + // edited, show a link to the message and a link to the diff. |
| 123 | + if ( $row->rc_new ) { |
| 124 | + $messageCell = $messageLink; |
| 125 | + } else { |
| 126 | + $querydiff = array( |
| 127 | + 'curid' => $row->rc_cur_id, |
| 128 | + 'diff' => $row->rc_this_oldid, |
| 129 | + 'oldid' => $row->rc_last_oldid |
| 130 | + ); |
| 131 | + $diffUrl = htmlspecialchars( $title->getLinkUrl( $querydiff ) ); |
| 132 | + // Should "diff" be localized? It appears not to be elsewhere in the interface. |
| 133 | + // See ChangesList->preCacheMessages() for example. |
| 134 | + $messageCell = $messageLink . " (<a href=\"$diffUrl\">diff</a>)"; |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + // Begin log entry primary row |
| 139 | + $htmlOut = Xml::openElement( 'tr' ); |
| 140 | + |
| 141 | + $htmlOut .= Xml::openElement( 'td', array( 'valign' => 'top' ) ); |
| 142 | + $htmlOut .= Xml::closeElement( 'td' ); |
| 143 | + $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' => 'primary' ), |
| 144 | + $wgLang->date( $row->rc_timestamp ) . ' ' . $wgLang->time( $row->rc_timestamp ) |
| 145 | + ); |
| 146 | + $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' => 'primary' ), |
| 147 | + wfMsg ( 'centralnotice-user-links', $userLink, $userTalkLink ) |
| 148 | + ); |
| 149 | + $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' => 'primary' ), |
| 150 | + $bannerCell |
| 151 | + ); |
| 152 | + if ( $this->logType == 'bannermessages' ) { |
| 153 | + $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' => 'primary' ), |
| 154 | + $messageCell |
| 155 | + ); |
| 156 | + $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top', 'class' => 'primary' ), |
| 157 | + $language |
| 158 | + ); |
| 159 | + } |
| 160 | + $htmlOut .= Xml::tags( 'td', array(), |
| 161 | + ' ' |
| 162 | + ); |
| 163 | + |
| 164 | + // End log entry primary row |
| 165 | + $htmlOut .= Xml::closeElement( 'tr' ); |
| 166 | + |
| 167 | + return $htmlOut; |
| 168 | + } |
| 169 | + |
| 170 | + function getStartBody() { |
| 171 | + $htmlOut = ''; |
| 172 | + $htmlOut .= Xml::openElement( 'table', array( 'id' => 'cn-campaign-logs', 'cellpadding' => 3 ) ); |
| 173 | + $htmlOut .= Xml::openElement( 'tr' ); |
| 174 | + $htmlOut .= Xml::element( 'th', array( 'style' => 'width: 20px;' ) ); |
| 175 | + $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'style' => 'width: 130px;' ), |
| 176 | + wfMsg ( 'centralnotice-timestamp' ) |
| 177 | + ); |
| 178 | + $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'style' => 'width: 160px;' ), |
| 179 | + wfMsg ( 'centralnotice-user' ) |
| 180 | + ); |
| 181 | + $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'style' => 'width: 160px;' ), |
| 182 | + wfMsg ( 'centralnotice-banner' ) |
| 183 | + ); |
| 184 | + if ( $this->logType == 'bannermessages' ) { |
| 185 | + $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'style' => 'width: 160px;' ), |
| 186 | + wfMsg ( 'centralnotice-message' ) |
| 187 | + ); |
| 188 | + $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'style' => 'width: 100px;' ), |
| 189 | + wfMsg ( 'centralnotice-language' ) |
| 190 | + ); |
| 191 | + } |
| 192 | + $htmlOut .= Xml::tags( 'td', array(), |
| 193 | + ' ' |
| 194 | + ); |
| 195 | + $htmlOut .= Xml::closeElement( 'tr' ); |
| 196 | + return $htmlOut; |
| 197 | + } |
| 198 | + |
| 199 | + /** |
| 200 | + * Close table |
| 201 | + */ |
| 202 | + function getEndBody() { |
| 203 | + $htmlOut = ''; |
| 204 | + $htmlOut .= Xml::closeElement( 'table' ); |
| 205 | + return $htmlOut; |
| 206 | + } |
| 207 | + |
| 208 | +} |
Property changes on: branches/wmf/1.18wmf1/extensions/CentralNotice/CentralNoticePageLogPager.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 209 | + native |