Index: trunk/extensions/Push/Push.i18n.php |
— | — | @@ -39,4 +39,11 @@ |
40 | 40 | |
41 | 41 | // Special page |
42 | 42 | 'special-push' => 'Push pages', |
| 43 | + 'push-special-description' => 'This page enables you to push content of one or more pages to one or more MediaWiki wikis. |
| 44 | + |
| 45 | +To push pages, enter the titles in the text box below, one title per line and hit push all. This can take a while to complete.', |
| 46 | + 'push-special-pushing-desc' => 'Pushing pages to $1.', |
| 47 | + 'push-special-button-text' => 'Push pages', |
| 48 | + 'push-special-target-is' => 'Target wiki: $1', |
| 49 | + 'push-special-select-targets' => 'Target wikis:', |
43 | 50 | ); |
\ No newline at end of file |
Index: trunk/extensions/Push/specials/Push_Body.php |
— | — | @@ -29,6 +29,16 @@ |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
| 33 | + * Sets headers - this should be called from the execute() method of all derived classes! |
| 34 | + */ |
| 35 | + public function setHeaders() { |
| 36 | + global $wgOut; |
| 37 | + $wgOut->setArticleRelated( false ); |
| 38 | + $wgOut->setRobotPolicy( "noindex,nofollow" ); |
| 39 | + $wgOut->setPageTitle( $this->getDescription() ); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
33 | 43 | * Main method. |
34 | 44 | * |
35 | 45 | * @since 0.1 |
— | — | @@ -36,17 +46,219 @@ |
37 | 47 | * @param string $arg |
38 | 48 | */ |
39 | 49 | public function execute( $arg ) { |
40 | | - global $wgOut, $wgUser; |
| 50 | + global $wgOut, $wgUser, $wgRequest, $egPushTargets; |
41 | 51 | |
42 | | - $wgOut->setPageTitle( wfMsg( 'special-push' ) ); |
| 52 | + $this->setHeaders(); |
| 53 | + $this->outputHeader(); |
43 | 54 | |
44 | 55 | // If the user is authorized, display the page, if not, show an error. |
45 | 56 | if ( !$this->userCanExecute( $wgUser ) ) { |
46 | 57 | $this->displayRestrictionError(); |
47 | 58 | return; |
48 | 59 | } |
| 60 | + |
| 61 | + if ( count( $egPushTargets ) == 0 ) { |
| 62 | + $wgOut->addHTML( '<p>' . htmlspecialchars( wfMsg( 'push-tab-no-targets' ) ) . '</p>' ); |
| 63 | + return; |
| 64 | + } |
49 | 65 | |
| 66 | + $doPush = false; |
| 67 | + |
| 68 | + if ( $wgRequest->getCheck( 'addcat' ) ) { |
| 69 | + $pages = $wgRequest->getText( 'pages' ); |
| 70 | + $catname = $wgRequest->getText( 'catname' ); |
| 71 | + |
| 72 | + if ( $catname !== '' && $catname !== null && $catname !== false ) { |
| 73 | + $t = Title::makeTitleSafe( NS_MAIN, $catname ); |
| 74 | + if ( $t ) { |
| 75 | + /** |
| 76 | + * @todo Fixme: this can lead to hitting memory limit for very large |
| 77 | + * categories. Ideally we would do the lookup synchronously |
| 78 | + * during the export in a single query. |
| 79 | + */ |
| 80 | + $catpages = $this->getPagesFromCategory( $t ); |
| 81 | + if ( $catpages ) $pages .= "\n" . implode( "\n", $catpages ); |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + else if( $wgRequest->getCheck( 'addns' ) ) { |
| 86 | + $pages = $wgRequest->getText( 'pages' ); |
| 87 | + $nsindex = $wgRequest->getText( 'nsindex', '' ); |
| 88 | + |
| 89 | + if ( strval( $nsindex ) !== '' ) { |
| 90 | + /** |
| 91 | + * Same implementation as above, so same @todo |
| 92 | + */ |
| 93 | + $nspages = $this->getPagesFromNamespace( $nsindex ); |
| 94 | + if ( $nspages ) $pages .= "\n" . implode( "\n", $nspages ); |
| 95 | + } |
| 96 | + } |
| 97 | + else if( $wgRequest->wasPosted() ) { |
| 98 | + $pages = $wgRequest->getText( 'pages' ); |
| 99 | + if( $pages != '' ) $doPush= true; |
| 100 | + } |
| 101 | + else { |
| 102 | + $pages = ''; |
| 103 | + } |
| 104 | + |
| 105 | + if ( $doPush ) { |
| 106 | + $this->doPush(); |
| 107 | + } |
| 108 | + else { |
| 109 | + $this->displayPushInterface( $arg, $pages ); |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + protected function doPush() { |
| 114 | + global $wgOut, $wgLang; |
| 115 | + |
| 116 | + $targets = array(); |
| 117 | + |
50 | 118 | // TODO |
| 119 | + $wgOut->addWikiMsg( 'push-special-pushing-desc', $wgLang->listToText( $targets ) ); |
| 120 | + |
| 121 | + $this->loadJs(); |
| 122 | + |
| 123 | + // TODO |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * @since 0.2 |
| 128 | + */ |
| 129 | + protected function displayPushInterface( $arg, $pages ) { |
| 130 | + global $wgOut, $wgUser, $wgRequest, $egPushTargets; |
| 131 | + |
| 132 | + $wgOut->addWikiMsg( 'push-special-description' ); |
| 133 | + |
| 134 | + $form = Xml::openElement( 'form', array( 'method' => 'post', |
| 135 | + 'action' => $this->getTitle()->getLocalUrl( 'action=submit' ) ) ); |
| 136 | + $form .= Xml::inputLabel( wfMsg( 'export-addcattext' ) , 'catname', 'catname', 40 ) . ' '; |
| 137 | + $form .= Xml::submitButton( wfMsg( 'export-addcat' ), array( 'name' => 'addcat' ) ) . '<br />'; |
| 138 | + |
| 139 | + $form .= Xml::namespaceSelector( $wgRequest->getText( 'nsindex', '' ), null, 'nsindex', wfMsg( 'export-addnstext' ) ) . ' '; |
| 140 | + $form .= Xml::submitButton( wfMsg( 'export-addns' ), array( 'name' => 'addns' ) ) . '<br />'; |
| 141 | + |
| 142 | + $form .= Xml::element( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ), $pages, false ); |
| 143 | + $form .= '<br />'; |
| 144 | + |
| 145 | + $form .= Xml::checkLabel( wfMsg( 'export-templates' ), 'templates', 'wpExportTemplates', false ) . '<br />'; |
| 146 | + |
| 147 | + if ( count( $egPushTargets ) == 1 ) { |
| 148 | + $names = array_keys( $egPushTargets ); |
| 149 | + $form .= '<b>' . htmlspecialchars( wfMsgExt( 'push-special-target-is', 'parsemag', $names[0] ) ) . '</b><br />'; |
| 150 | + } |
| 151 | + else { |
| 152 | + $form .= '<b>' . htmlspecialchars( wfMsg( 'push-special-select-targets' ) ) . '</b><br />'; |
| 153 | + |
| 154 | + foreach ( $egPushTargets as $targetName => $targetUrl ) { |
| 155 | + $form .= Xml::checkLabel( $targetName, $targetName, $targetName, true ) . '<br />'; |
| 156 | + } |
| 157 | + } |
| 158 | + |
| 159 | + $form .= Xml::submitButton( wfMsg( 'push-special-button-text' ), array( 'style' => 'width: 125px; height: 30px' ) ); |
| 160 | + $form .= Xml::closeElement( 'form' ); |
| 161 | + |
| 162 | + $wgOut->addHTML( $form ); |
| 163 | + } |
| 164 | + |
| 165 | + /** |
| 166 | + * Returns all pages for a category (up to 5000). |
| 167 | + * |
| 168 | + * @since 0.2 |
| 169 | + * |
| 170 | + * @param Title $title |
| 171 | + * |
| 172 | + * @return array |
| 173 | + */ |
| 174 | + protected function getPagesFromCategory( Title $title ) { |
| 175 | + global $wgContLang; |
| 176 | + |
| 177 | + $name = $title->getDBkey(); |
| 178 | + |
| 179 | + $dbr = wfGetDB( DB_SLAVE ); |
| 180 | + $res = $dbr->select( |
| 181 | + array( 'page', 'categorylinks' ), |
| 182 | + array( 'page_namespace', 'page_title' ), |
| 183 | + array( 'cl_from=page_id', 'cl_to' => $name ), |
| 184 | + __METHOD__, |
| 185 | + array( 'LIMIT' => '5000' ) |
| 186 | + ); |
| 187 | + |
| 188 | + $pages = array(); |
| 189 | + |
| 190 | + foreach ( $res as $row ) { |
| 191 | + $n = $row->page_title; |
| 192 | + if ($row->page_namespace) { |
| 193 | + $ns = $wgContLang->getNsText( $row->page_namespace ); |
| 194 | + $n = $ns . ':' . $n; |
| 195 | + } |
| 196 | + |
| 197 | + $pages[] = $n; |
| 198 | + } |
| 199 | + return $pages; |
| 200 | + } |
| 201 | + |
| 202 | + /** |
| 203 | + * Returns all pages for a namespace (up to 5000). |
| 204 | + * |
| 205 | + * @since 0.2 |
| 206 | + * |
| 207 | + * @param integer $nsindex |
| 208 | + * |
| 209 | + * @return array |
| 210 | + */ |
| 211 | + protected function getPagesFromNamespace( $nsindex ) { |
| 212 | + global $wgContLang; |
| 213 | + |
| 214 | + $dbr = wfGetDB( DB_SLAVE ); |
| 215 | + $res = $dbr->select( |
| 216 | + 'page', |
| 217 | + array( 'page_namespace', 'page_title' ), |
| 218 | + array( 'page_namespace' => $nsindex ), |
| 219 | + __METHOD__, |
| 220 | + array( 'LIMIT' => '5000' ) |
| 221 | + ); |
| 222 | + |
| 223 | + $pages = array(); |
| 224 | + |
| 225 | + foreach ( $res as $row ) { |
| 226 | + $n = $row->page_title; |
| 227 | + |
| 228 | + if ( $row->page_namespace ) { |
| 229 | + $ns = $wgContLang->getNsText( $row->page_namespace ); |
| 230 | + $n = $ns . ':' . $n; |
| 231 | + } |
| 232 | + |
| 233 | + $pages[] = $n; |
| 234 | + } |
| 235 | + return $pages; |
51 | 236 | } |
| 237 | + |
| 238 | + /** |
| 239 | + * Loads the needed JavaScript. |
| 240 | + * Takes care of non-RL compatibility. |
| 241 | + * |
| 242 | + * @since 0.2 |
| 243 | + */ |
| 244 | + protected static function loadJs() { |
| 245 | + global $wgOut; |
| 246 | + |
| 247 | + // For backward compatibility with MW < 1.17. |
| 248 | + if ( is_callable( array( $wgOut, 'addModules' ) ) ) { |
| 249 | + $wgOut->addModules( 'ext.push.special' ); |
| 250 | + } |
| 251 | + else { |
| 252 | + global $egPushScriptPath; |
| 253 | + |
| 254 | + PushFunctions::addJSLocalisation(); |
| 255 | + |
| 256 | + $wgOut->includeJQuery(); |
| 257 | + |
| 258 | + $wgOut->addHeadItem( |
| 259 | + 'ext.push.special', |
| 260 | + Html::linkedScript( $egPushScriptPath . '/specials/ext.push.special.js' ) |
| 261 | + ); |
| 262 | + } |
| 263 | + } |
52 | 264 | |
53 | 265 | } |
\ No newline at end of file |
Index: trunk/extensions/Push/specials/ext.push.special.js |
Property changes on: trunk/extensions/Push/specials/ext.push.special.js |
___________________________________________________________________ |
Added: svn:eol-style |
54 | 266 | + native |
Index: trunk/extensions/Push/Push.php |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | die( 'Not an entry point.' ); |
24 | 24 | } |
25 | 25 | |
26 | | -define( 'Push_VERSION', '0.1' ); |
| 26 | +define( 'Push_VERSION', '0.2 alpha' ); |
27 | 27 | |
28 | 28 | $wgExtensionCredits['other'][] = array( |
29 | 29 | 'path' => __FILE__, |
— | — | @@ -44,16 +44,17 @@ |
45 | 45 | |
46 | 46 | $wgAutoloadClasses['PushHooks'] = dirname( __FILE__ ) . '/Push.hooks.php'; |
47 | 47 | $wgAutoloadClasses['PushTab'] = dirname( __FILE__ ) . '/includes/Push_Tab.php'; |
| 48 | +$wgAutoloadClasses['PushFunctions'] = dirname( __FILE__ ) . '/includes/Push_Functions.php'; |
48 | 49 | $wgAutoloadClasses['SpecialPush'] = dirname( __FILE__ ) . '/specials/Push_Body.php'; |
49 | 50 | |
50 | | -//$wgSpecialPages['Push'] = 'SpecialPush'; |
51 | | -//$wgSpecialPageGroups['Push'] = 'pagetools'; |
| 51 | +$wgSpecialPages['Push'] = 'SpecialPush'; |
| 52 | +$wgSpecialPageGroups['Push'] = 'pagetools'; |
52 | 53 | |
53 | 54 | $wgHooks['UnknownAction'][] = 'PushTab::onUnknownAction'; |
54 | 55 | $wgHooks['SkinTemplateTabs'][] = 'PushTab::displayTab'; |
55 | 56 | $wgHooks['SkinTemplateNavigation'][] = 'PushTab::displayTab2'; |
56 | 57 | |
57 | | -//$wgHooks['AdminLinks'][] = 'PushHooks::addToAdminLinks'; |
| 58 | +$wgHooks['AdminLinks'][] = 'PushHooks::addToAdminLinks'; |
58 | 59 | |
59 | 60 | $wgAvailableRights[] = 'push'; |
60 | 61 | $wgAvailableRights[] = 'pushadmin'; |
— | — | @@ -80,19 +81,13 @@ |
81 | 82 | 'scripts' => 'includes/ext.push.tab.js', |
82 | 83 | 'dependencies' => array(), |
83 | 84 | 'messages' => $egPushJSMessages |
| 85 | + ); |
| 86 | + |
| 87 | + $wgResourceModules['ext.push.special'] = $moduleTemplate + array( |
| 88 | + 'scripts' => 'includes/ext.push.special.js', |
| 89 | + 'dependencies' => array(), |
| 90 | + 'messages' => $egPushJSMessages |
84 | 91 | ); |
85 | 92 | } |
86 | 93 | |
87 | | -function efPushAddJSLocalisation() { |
88 | | - global $egPushJSMessages, $wgOut; |
89 | | - |
90 | | - $data = array(); |
91 | | - |
92 | | - foreach ( $egPushJSMessages as $msg ) { |
93 | | - $data[$msg] = wfMsgNoTrans( $msg ); |
94 | | - } |
95 | | - |
96 | | - $wgOut->addInlineScript( 'var wgPushMessages = ' . json_encode( $data ) . ';' ); |
97 | | -} |
98 | | - |
99 | 94 | require_once 'Push_Settings.php'; |
Index: trunk/extensions/Push/RELEASE-NOTES |
— | — | @@ -4,11 +4,16 @@ |
5 | 5 | Latest version of the release notes: http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Push/RELEASE-NOTES?view=co |
6 | 6 | |
7 | 7 | |
8 | | -== Version 0.1 == |
| 8 | +=== Version 0.2 === |
| 9 | + |
| 10 | +* Added Special:Push for bulk pushing |
| 11 | +* Added AdminLinks hook |
| 12 | + |
| 13 | +=== Version 0.1 === |
9 | 14 | 2010-12-08 |
10 | 15 | |
11 | 16 | Initial release. |
12 | 17 | |
13 | | -* Push tab that allows pushing the page to one or more other wikis |
14 | | -* ApprovedRevs support |
15 | | -* 'push' right |
\ No newline at end of file |
| 18 | +* Added push tab that allows pushing the page to one or more other wikis |
| 19 | +* Added ApprovedRevs support |
| 20 | +* Added 'push' right |
\ No newline at end of file |
Index: trunk/extensions/Push/includes/Push_Tab.php |
— | — | @@ -10,7 +10,6 @@ |
11 | 11 | * |
12 | 12 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
13 | 13 | */ |
14 | | - |
15 | 14 | final class PushTab { |
16 | 15 | |
17 | 16 | /** |
— | — | @@ -87,7 +86,7 @@ |
88 | 87 | else { |
89 | 88 | global $egPushScriptPath; |
90 | 89 | |
91 | | - efPushAddJSLocalisation(); |
| 90 | + PushFunctions::addJSLocalisation(); |
92 | 91 | |
93 | 92 | $wgOut->includeJQuery(); |
94 | 93 | |
Index: trunk/extensions/Push/includes/Push_Functions.php |
— | — | @@ -0,0 +1,29 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Statis class with utility methods for the Push extension. |
| 6 | + * |
| 7 | + * @since 0.2 |
| 8 | + * |
| 9 | + * @file Push_Functions.php |
| 10 | + * @ingroup Push |
| 11 | + * |
| 12 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 13 | + */ |
| 14 | +final class PushFunctions { |
| 15 | + |
| 16 | + public static function addJSLocalisation() { |
| 17 | + global $egPushJSMessages, $wgOut; |
| 18 | + |
| 19 | + $data = array(); |
| 20 | + |
| 21 | + foreach ( $egPushJSMessages as $msg ) { |
| 22 | + $data[$msg] = wfMsgNoTrans( $msg ); |
| 23 | + } |
| 24 | + |
| 25 | + $wgOut->addInlineScript( 'var wgPushMessages = ' . json_encode( $data ) . ';' ); |
| 26 | + } |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Push/includes/Push_Functions.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 31 | + native |