Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like OutputPage often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use OutputPage, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 43 | class OutputPage extends ContextSource { |
||
| 44 | /** @var array Should be private. Used with addMeta() which adds "<meta>" */ |
||
| 45 | protected $mMetatags = []; |
||
| 46 | |||
| 47 | /** @var array */ |
||
| 48 | protected $mLinktags = []; |
||
| 49 | |||
| 50 | /** @var bool */ |
||
| 51 | protected $mCanonicalUrl = false; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var array Additional stylesheets. Looks like this is for extensions. |
||
| 55 | * Might be replaced by ResourceLoader. |
||
| 56 | */ |
||
| 57 | protected $mExtStyles = []; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var string Should be private - has getter and setter. Contains |
||
| 61 | * the HTML title */ |
||
| 62 | public $mPagetitle = ''; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var string Contains all of the "<body>" content. Should be private we |
||
| 66 | * got set/get accessors and the append() method. |
||
| 67 | */ |
||
| 68 | public $mBodytext = ''; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Holds the debug lines that will be output as comments in page source if |
||
| 72 | * $wgDebugComments is enabled. See also $wgShowDebug. |
||
| 73 | * @deprecated since 1.20; use MWDebug class instead. |
||
| 74 | */ |
||
| 75 | public $mDebugtext = ''; |
||
| 76 | |||
| 77 | /** @var string Stores contents of "<title>" tag */ |
||
| 78 | private $mHTMLtitle = ''; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @var bool Is the displayed content related to the source of the |
||
| 82 | * corresponding wiki article. |
||
| 83 | */ |
||
| 84 | private $mIsarticle = false; |
||
| 85 | |||
| 86 | /** @var bool Stores "article flag" toggle. */ |
||
| 87 | private $mIsArticleRelated = true; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var bool We have to set isPrintable(). Some pages should |
||
| 91 | * never be printed (ex: redirections). |
||
| 92 | */ |
||
| 93 | private $mPrintable = false; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @var array Contains the page subtitle. Special pages usually have some |
||
| 97 | * links here. Don't confuse with site subtitle added by skins. |
||
| 98 | */ |
||
| 99 | private $mSubtitle = []; |
||
| 100 | |||
| 101 | /** @var string */ |
||
| 102 | public $mRedirect = ''; |
||
| 103 | |||
| 104 | /** @var int */ |
||
| 105 | protected $mStatusCode; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @var string Used for sending cache control. |
||
| 109 | * The whole caching system should probably be moved into its own class. |
||
| 110 | */ |
||
| 111 | protected $mLastModified = ''; |
||
| 112 | |||
| 113 | /** @var array */ |
||
| 114 | protected $mCategoryLinks = []; |
||
| 115 | |||
| 116 | /** @var array */ |
||
| 117 | protected $mCategories = []; |
||
| 118 | |||
| 119 | /** @var array */ |
||
| 120 | protected $mIndicators = []; |
||
| 121 | |||
| 122 | /** @var array Array of Interwiki Prefixed (non DB key) Titles (e.g. 'fr:Test page') */ |
||
| 123 | private $mLanguageLinks = []; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Used for JavaScript (predates ResourceLoader) |
||
| 127 | * @todo We should split JS / CSS. |
||
| 128 | * mScripts content is inserted as is in "<head>" by Skin. This might |
||
| 129 | * contain either a link to a stylesheet or inline CSS. |
||
| 130 | */ |
||
| 131 | private $mScripts = ''; |
||
| 132 | |||
| 133 | /** @var string Inline CSS styles. Use addInlineStyle() sparingly */ |
||
| 134 | protected $mInlineStyles = ''; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @var string Used by skin template. |
||
| 138 | * Example: $tpl->set( 'displaytitle', $out->mPageLinkTitle ); |
||
| 139 | */ |
||
| 140 | public $mPageLinkTitle = ''; |
||
| 141 | |||
| 142 | /** @var array Array of elements in "<head>". Parser might add its own headers! */ |
||
| 143 | protected $mHeadItems = []; |
||
| 144 | |||
| 145 | /** @var array */ |
||
| 146 | protected $mModules = []; |
||
| 147 | |||
| 148 | /** @var array */ |
||
| 149 | protected $mModuleScripts = []; |
||
| 150 | |||
| 151 | /** @var array */ |
||
| 152 | protected $mModuleStyles = []; |
||
| 153 | |||
| 154 | /** @var ResourceLoader */ |
||
| 155 | protected $mResourceLoader; |
||
| 156 | |||
| 157 | /** @var array */ |
||
| 158 | protected $mJsConfigVars = []; |
||
| 159 | |||
| 160 | /** @var array */ |
||
| 161 | protected $mTemplateIds = []; |
||
| 162 | |||
| 163 | /** @var array */ |
||
| 164 | protected $mImageTimeKeys = []; |
||
| 165 | |||
| 166 | /** @var string */ |
||
| 167 | public $mRedirectCode = ''; |
||
| 168 | |||
| 169 | protected $mFeedLinksAppendQuery = null; |
||
| 170 | |||
| 171 | /** @var array |
||
| 172 | * What level of 'untrustworthiness' is allowed in CSS/JS modules loaded on this page? |
||
| 173 | * @see ResourceLoaderModule::$origin |
||
| 174 | * ResourceLoaderModule::ORIGIN_ALL is assumed unless overridden; |
||
| 175 | */ |
||
| 176 | protected $mAllowedModules = [ |
||
| 177 | ResourceLoaderModule::TYPE_COMBINED => ResourceLoaderModule::ORIGIN_ALL, |
||
| 178 | ]; |
||
| 179 | |||
| 180 | /** @var bool Whether output is disabled. If this is true, the 'output' method will do nothing. */ |
||
| 181 | protected $mDoNothing = false; |
||
| 182 | |||
| 183 | // Parser related. |
||
| 184 | |||
| 185 | /** @var int */ |
||
| 186 | protected $mContainsNewMagic = 0; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * lazy initialised, use parserOptions() |
||
| 190 | * @var ParserOptions |
||
| 191 | */ |
||
| 192 | protected $mParserOptions = null; |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Handles the Atom / RSS links. |
||
| 196 | * We probably only support Atom in 2011. |
||
| 197 | * @see $wgAdvertisedFeedTypes |
||
| 198 | */ |
||
| 199 | private $mFeedLinks = []; |
||
| 200 | |||
| 201 | // Gwicke work on squid caching? Roughly from 2003. |
||
| 202 | protected $mEnableClientCache = true; |
||
| 203 | |||
| 204 | /** @var bool Flag if output should only contain the body of the article. */ |
||
| 205 | private $mArticleBodyOnly = false; |
||
| 206 | |||
| 207 | /** @var bool */ |
||
| 208 | protected $mNewSectionLink = false; |
||
| 209 | |||
| 210 | /** @var bool */ |
||
| 211 | protected $mHideNewSectionLink = false; |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @var bool Comes from the parser. This was probably made to load CSS/JS |
||
| 215 | * only if we had "<gallery>". Used directly in CategoryPage.php. |
||
| 216 | * Looks like ResourceLoader can replace this. |
||
| 217 | */ |
||
| 218 | public $mNoGallery = false; |
||
| 219 | |||
| 220 | /** @var string */ |
||
| 221 | private $mPageTitleActionText = ''; |
||
| 222 | |||
| 223 | /** @var int Cache stuff. Looks like mEnableClientCache */ |
||
| 224 | protected $mCdnMaxage = 0; |
||
| 225 | /** @var int Upper limit on mCdnMaxage */ |
||
| 226 | protected $mCdnMaxageLimit = INF; |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @var bool Controls if anti-clickjacking / frame-breaking headers will |
||
| 230 | * be sent. This should be done for pages where edit actions are possible. |
||
| 231 | * Setters: $this->preventClickjacking() and $this->allowClickjacking(). |
||
| 232 | */ |
||
| 233 | protected $mPreventClickjacking = true; |
||
| 234 | |||
| 235 | /** @var int To include the variable {{REVISIONID}} */ |
||
| 236 | private $mRevisionId = null; |
||
| 237 | |||
| 238 | /** @var string */ |
||
| 239 | private $mRevisionTimestamp = null; |
||
| 240 | |||
| 241 | /** @var array */ |
||
| 242 | protected $mFileVersion = null; |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @var array An array of stylesheet filenames (relative from skins path), |
||
| 246 | * with options for CSS media, IE conditions, and RTL/LTR direction. |
||
| 247 | * For internal use; add settings in the skin via $this->addStyle() |
||
| 248 | * |
||
| 249 | * Style again! This seems like a code duplication since we already have |
||
| 250 | * mStyles. This is what makes Open Source amazing. |
||
| 251 | */ |
||
| 252 | protected $styles = []; |
||
| 253 | |||
| 254 | private $mIndexPolicy = 'index'; |
||
| 255 | private $mFollowPolicy = 'follow'; |
||
| 256 | private $mVaryHeader = [ |
||
| 257 | 'Accept-Encoding' => [ 'match=gzip' ], |
||
| 258 | ]; |
||
| 259 | |||
| 260 | /** |
||
| 261 | * If the current page was reached through a redirect, $mRedirectedFrom contains the Title |
||
| 262 | * of the redirect. |
||
| 263 | * |
||
| 264 | * @var Title |
||
| 265 | */ |
||
| 266 | private $mRedirectedFrom = null; |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Additional key => value data |
||
| 270 | */ |
||
| 271 | private $mProperties = []; |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @var string|null ResourceLoader target for load.php links. If null, will be omitted |
||
| 275 | */ |
||
| 276 | private $mTarget = null; |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @var bool Whether parser output should contain table of contents |
||
| 280 | */ |
||
| 281 | private $mEnableTOC = true; |
||
| 282 | |||
| 283 | /** |
||
| 284 | * @var bool Whether parser output should contain section edit links |
||
| 285 | */ |
||
| 286 | private $mEnableSectionEditLinks = true; |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @var string|null The URL to send in a <link> element with rel=copyright |
||
| 290 | */ |
||
| 291 | private $copyrightUrl; |
||
| 292 | |||
| 293 | /** @var array Profiling data */ |
||
| 294 | private $limitReportData = []; |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Constructor for OutputPage. This should not be called directly. |
||
| 298 | * Instead a new RequestContext should be created and it will implicitly create |
||
| 299 | * a OutputPage tied to that context. |
||
| 300 | * @param IContextSource|null $context |
||
| 301 | */ |
||
| 302 | function __construct( IContextSource $context = null ) { |
||
| 310 | |||
| 311 | /** |
||
| 312 | * Redirect to $url rather than displaying the normal page |
||
| 313 | * |
||
| 314 | * @param string $url URL |
||
| 315 | * @param string $responsecode HTTP status code |
||
| 316 | */ |
||
| 317 | public function redirect( $url, $responsecode = '302' ) { |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Get the URL to redirect to, or an empty string if not redirect URL set |
||
| 325 | * |
||
| 326 | * @return string |
||
| 327 | */ |
||
| 328 | public function getRedirect() { |
||
| 331 | |||
| 332 | /** |
||
| 333 | * Set the copyright URL to send with the output. |
||
| 334 | * Empty string to omit, null to reset. |
||
| 335 | * |
||
| 336 | * @since 1.26 |
||
| 337 | * |
||
| 338 | * @param string|null $url |
||
| 339 | */ |
||
| 340 | public function setCopyrightUrl( $url ) { |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Set the HTTP status code to send with the output. |
||
| 346 | * |
||
| 347 | * @param int $statusCode |
||
| 348 | */ |
||
| 349 | public function setStatusCode( $statusCode ) { |
||
| 352 | |||
| 353 | /** |
||
| 354 | * Add a new "<meta>" tag |
||
| 355 | * To add an http-equiv meta tag, precede the name with "http:" |
||
| 356 | * |
||
| 357 | * @param string $name Tag name |
||
| 358 | * @param string $val Tag value |
||
| 359 | */ |
||
| 360 | function addMeta( $name, $val ) { |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Returns the current <meta> tags |
||
| 366 | * |
||
| 367 | * @since 1.25 |
||
| 368 | * @return array |
||
| 369 | */ |
||
| 370 | public function getMetaTags() { |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Add a new \<link\> tag to the page header. |
||
| 376 | * |
||
| 377 | * Note: use setCanonicalUrl() for rel=canonical. |
||
| 378 | * |
||
| 379 | * @param array $linkarr Associative array of attributes. |
||
| 380 | */ |
||
| 381 | function addLink( array $linkarr ) { |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Returns the current <link> tags |
||
| 387 | * |
||
| 388 | * @since 1.25 |
||
| 389 | * @return array |
||
| 390 | */ |
||
| 391 | public function getLinkTags() { |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Add a new \<link\> with "rel" attribute set to "meta" |
||
| 397 | * |
||
| 398 | * @param array $linkarr Associative array mapping attribute names to their |
||
| 399 | * values, both keys and values will be escaped, and the |
||
| 400 | * "rel" attribute will be automatically added |
||
| 401 | */ |
||
| 402 | function addMetadataLink( array $linkarr ) { |
||
| 406 | |||
| 407 | /** |
||
| 408 | * Set the URL to be used for the <link rel=canonical>. This should be used |
||
| 409 | * in preference to addLink(), to avoid duplicate link tags. |
||
| 410 | * @param string $url |
||
| 411 | */ |
||
| 412 | function setCanonicalUrl( $url ) { |
||
| 415 | |||
| 416 | /** |
||
| 417 | * Returns the URL to be used for the <link rel=canonical> if |
||
| 418 | * one is set. |
||
| 419 | * |
||
| 420 | * @since 1.25 |
||
| 421 | * @return bool|string |
||
| 422 | */ |
||
| 423 | public function getCanonicalUrl() { |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Get the value of the "rel" attribute for metadata links |
||
| 429 | * |
||
| 430 | * @return string |
||
| 431 | */ |
||
| 432 | public function getMetadataAttribute() { |
||
| 442 | |||
| 443 | /** |
||
| 444 | * Add raw HTML to the list of scripts (including \<script\> tag, etc.) |
||
| 445 | * Internal use only. Use OutputPage::addModules() or OutputPage::addJsConfigVars() |
||
| 446 | * if possible. |
||
| 447 | * |
||
| 448 | * @param string $script Raw HTML |
||
| 449 | */ |
||
| 450 | function addScript( $script ) { |
||
| 453 | |||
| 454 | /** |
||
| 455 | * Register and add a stylesheet from an extension directory. |
||
| 456 | * |
||
| 457 | * @deprecated since 1.27 use addModuleStyles() or addStyle() instead |
||
| 458 | * @param string $url Path to sheet. Provide either a full url (beginning |
||
| 459 | * with 'http', etc) or a relative path from the document root |
||
| 460 | * (beginning with '/'). Otherwise it behaves identically to |
||
| 461 | * addStyle() and draws from the /skins folder. |
||
| 462 | */ |
||
| 463 | public function addExtensionStyle( $url ) { |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Get all styles added by extensions |
||
| 470 | * |
||
| 471 | * @deprecated since 1.27 |
||
| 472 | * @return array |
||
| 473 | */ |
||
| 474 | function getExtStyle() { |
||
| 478 | |||
| 479 | /** |
||
| 480 | * Add a JavaScript file out of skins/common, or a given relative path. |
||
| 481 | * Internal use only. Use OutputPage::addModules() if possible. |
||
| 482 | * |
||
| 483 | * @param string $file Filename in skins/common or complete on-server path |
||
| 484 | * (/foo/bar.js) |
||
| 485 | * @param string $version Style version of the file. Defaults to $wgStyleVersion |
||
| 486 | */ |
||
| 487 | public function addScriptFile( $file, $version = null ) { |
||
| 499 | |||
| 500 | /** |
||
| 501 | * Add a self-contained script tag with the given contents |
||
| 502 | * Internal use only. Use OutputPage::addModules() if possible. |
||
| 503 | * |
||
| 504 | * @param string $script JavaScript text, no "<script>" tags |
||
| 505 | */ |
||
| 506 | public function addInlineScript( $script ) { |
||
| 509 | |||
| 510 | /** |
||
| 511 | * Filter an array of modules to remove insufficiently trustworthy members, and modules |
||
| 512 | * which are no longer registered (eg a page is cached before an extension is disabled) |
||
| 513 | * @param array $modules |
||
| 514 | * @param string|null $position If not null, only return modules with this position |
||
| 515 | * @param string $type |
||
| 516 | * @return array |
||
| 517 | */ |
||
| 518 | protected function filterModules( array $modules, $position = null, |
||
| 535 | |||
| 536 | /** |
||
| 537 | * Get the list of modules to include on this page |
||
| 538 | * |
||
| 539 | * @param bool $filter Whether to filter out insufficiently trustworthy modules |
||
| 540 | * @param string|null $position If not null, only return modules with this position |
||
| 541 | * @param string $param |
||
| 542 | * @return array Array of module names |
||
| 543 | */ |
||
| 544 | public function getModules( $filter = false, $position = null, $param = 'mModules' ) { |
||
| 550 | |||
| 551 | /** |
||
| 552 | * Add one or more modules recognized by ResourceLoader. Modules added |
||
| 553 | * through this function will be loaded by ResourceLoader when the |
||
| 554 | * page loads. |
||
| 555 | * |
||
| 556 | * @param string|array $modules Module name (string) or array of module names |
||
| 557 | */ |
||
| 558 | public function addModules( $modules ) { |
||
| 561 | |||
| 562 | /** |
||
| 563 | * Get the list of module JS to include on this page |
||
| 564 | * |
||
| 565 | * @param bool $filter |
||
| 566 | * @param string|null $position |
||
| 567 | * |
||
| 568 | * @return array Array of module names |
||
| 569 | */ |
||
| 570 | public function getModuleScripts( $filter = false, $position = null ) { |
||
| 573 | |||
| 574 | /** |
||
| 575 | * Add only JS of one or more modules recognized by ResourceLoader. Module |
||
| 576 | * scripts added through this function will be loaded by ResourceLoader when |
||
| 577 | * the page loads. |
||
| 578 | * |
||
| 579 | * @param string|array $modules Module name (string) or array of module names |
||
| 580 | */ |
||
| 581 | public function addModuleScripts( $modules ) { |
||
| 584 | |||
| 585 | /** |
||
| 586 | * Get the list of module CSS to include on this page |
||
| 587 | * |
||
| 588 | * @param bool $filter |
||
| 589 | * @param string|null $position |
||
| 590 | * |
||
| 591 | * @return array Array of module names |
||
| 592 | */ |
||
| 593 | public function getModuleStyles( $filter = false, $position = null ) { |
||
| 596 | |||
| 597 | /** |
||
| 598 | * Add only CSS of one or more modules recognized by ResourceLoader. |
||
| 599 | * |
||
| 600 | * Module styles added through this function will be added using standard link CSS |
||
| 601 | * tags, rather than as a combined Javascript and CSS package. Thus, they will |
||
| 602 | * load when JavaScript is disabled (unless CSS also happens to be disabled). |
||
| 603 | * |
||
| 604 | * @param string|array $modules Module name (string) or array of module names |
||
| 605 | */ |
||
| 606 | public function addModuleStyles( $modules ) { |
||
| 609 | |||
| 610 | /** |
||
| 611 | * @return null|string ResourceLoader target |
||
| 612 | */ |
||
| 613 | public function getTarget() { |
||
| 614 | return $this->mTarget; |
||
| 615 | } |
||
| 616 | |||
| 617 | /** |
||
| 618 | * Sets ResourceLoader target for load.php links. If null, will be omitted |
||
| 619 | * |
||
| 620 | * @param string|null $target |
||
| 621 | */ |
||
| 622 | public function setTarget( $target ) { |
||
| 623 | $this->mTarget = $target; |
||
| 624 | } |
||
| 625 | |||
| 626 | /** |
||
| 627 | * Get an array of head items |
||
| 628 | * |
||
| 629 | * @return array |
||
| 630 | */ |
||
| 631 | function getHeadItemsArray() { |
||
| 632 | return $this->mHeadItems; |
||
| 633 | } |
||
| 634 | |||
| 635 | /** |
||
| 636 | * Add or replace a head item to the output |
||
| 637 | * |
||
| 638 | * Whenever possible, use more specific options like ResourceLoader modules, |
||
| 639 | * OutputPage::addLink(), OutputPage::addMetaLink() and OutputPage::addFeedLink() |
||
| 640 | * Fallback options for those are: OutputPage::addStyle, OutputPage::addScript(), |
||
| 641 | * OutputPage::addInlineScript() and OutputPage::addInlineStyle() |
||
| 642 | * This would be your very LAST fallback. |
||
| 643 | * |
||
| 644 | * @param string $name Item name |
||
| 645 | * @param string $value Raw HTML |
||
| 646 | */ |
||
| 647 | public function addHeadItem( $name, $value ) { |
||
| 650 | |||
| 651 | /** |
||
| 652 | * Add one or more head items to the output |
||
| 653 | * |
||
| 654 | * @since 1.28 |
||
| 655 | * @param string|string[] $value Raw HTML |
||
| 656 | */ |
||
| 657 | public function addHeadItems( $values ) { |
||
| 658 | $this->mHeadItems = array_merge( $this->mHeadItems, (array)$values ); |
||
| 659 | } |
||
| 660 | |||
| 661 | /** |
||
| 662 | * Check if the header item $name is already set |
||
| 663 | * |
||
| 664 | * @param string $name Item name |
||
| 665 | * @return bool |
||
| 666 | */ |
||
| 667 | public function hasHeadItem( $name ) { |
||
| 670 | |||
| 671 | /** |
||
| 672 | * @deprecated since 1.28 Obsolete - wgUseETag experiment was removed. |
||
| 673 | * @param string $tag |
||
| 674 | */ |
||
| 675 | public function setETag( $tag ) { |
||
| 677 | |||
| 678 | /** |
||
| 679 | * Set whether the output should only contain the body of the article, |
||
| 680 | * without any skin, sidebar, etc. |
||
| 681 | * Used e.g. when calling with "action=render". |
||
| 682 | * |
||
| 683 | * @param bool $only Whether to output only the body of the article |
||
| 684 | */ |
||
| 685 | public function setArticleBodyOnly( $only ) { |
||
| 688 | |||
| 689 | /** |
||
| 690 | * Return whether the output will contain only the body of the article |
||
| 691 | * |
||
| 692 | * @return bool |
||
| 693 | */ |
||
| 694 | public function getArticleBodyOnly() { |
||
| 697 | |||
| 698 | /** |
||
| 699 | * Set an additional output property |
||
| 700 | * @since 1.21 |
||
| 701 | * |
||
| 702 | * @param string $name |
||
| 703 | * @param mixed $value |
||
| 704 | */ |
||
| 705 | public function setProperty( $name, $value ) { |
||
| 708 | |||
| 709 | /** |
||
| 710 | * Get an additional output property |
||
| 711 | * @since 1.21 |
||
| 712 | * |
||
| 713 | * @param string $name |
||
| 714 | * @return mixed Property value or null if not found |
||
| 715 | */ |
||
| 716 | public function getProperty( $name ) { |
||
| 723 | |||
| 724 | /** |
||
| 725 | * checkLastModified tells the client to use the client-cached page if |
||
| 726 | * possible. If successful, the OutputPage is disabled so that |
||
| 727 | * any future call to OutputPage->output() have no effect. |
||
| 728 | * |
||
| 729 | * Side effect: sets mLastModified for Last-Modified header |
||
| 730 | * |
||
| 731 | * @param string $timestamp |
||
| 732 | * |
||
| 733 | * @return bool True if cache-ok headers was sent. |
||
| 734 | */ |
||
| 735 | public function checkLastModified( $timestamp ) { |
||
| 815 | |||
| 816 | /** |
||
| 817 | * Override the last modified timestamp |
||
| 818 | * |
||
| 819 | * @param string $timestamp New timestamp, in a format readable by |
||
| 820 | * wfTimestamp() |
||
| 821 | */ |
||
| 822 | public function setLastModified( $timestamp ) { |
||
| 825 | |||
| 826 | /** |
||
| 827 | * Set the robot policy for the page: <http://www.robotstxt.org/meta.html> |
||
| 828 | * |
||
| 829 | * @param string $policy The literal string to output as the contents of |
||
| 830 | * the meta tag. Will be parsed according to the spec and output in |
||
| 831 | * standardized form. |
||
| 832 | * @return null |
||
| 833 | */ |
||
| 834 | public function setRobotPolicy( $policy ) { |
||
| 844 | |||
| 845 | /** |
||
| 846 | * Set the index policy for the page, but leave the follow policy un- |
||
| 847 | * touched. |
||
| 848 | * |
||
| 849 | * @param string $policy Either 'index' or 'noindex'. |
||
| 850 | * @return null |
||
| 851 | */ |
||
| 852 | public function setIndexPolicy( $policy ) { |
||
| 858 | |||
| 859 | /** |
||
| 860 | * Set the follow policy for the page, but leave the index policy un- |
||
| 861 | * touched. |
||
| 862 | * |
||
| 863 | * @param string $policy Either 'follow' or 'nofollow'. |
||
| 864 | * @return null |
||
| 865 | */ |
||
| 866 | public function setFollowPolicy( $policy ) { |
||
| 872 | |||
| 873 | /** |
||
| 874 | * Set the new value of the "action text", this will be added to the |
||
| 875 | * "HTML title", separated from it with " - ". |
||
| 876 | * |
||
| 877 | * @param string $text New value of the "action text" |
||
| 878 | */ |
||
| 879 | public function setPageTitleActionText( $text ) { |
||
| 882 | |||
| 883 | /** |
||
| 884 | * Get the value of the "action text" |
||
| 885 | * |
||
| 886 | * @return string |
||
| 887 | */ |
||
| 888 | public function getPageTitleActionText() { |
||
| 891 | |||
| 892 | /** |
||
| 893 | * "HTML title" means the contents of "<title>". |
||
| 894 | * It is stored as plain, unescaped text and will be run through htmlspecialchars in the skin file. |
||
| 895 | * |
||
| 896 | * @param string|Message $name |
||
| 897 | */ |
||
| 898 | public function setHTMLTitle( $name ) { |
||
| 905 | |||
| 906 | /** |
||
| 907 | * Return the "HTML title", i.e. the content of the "<title>" tag. |
||
| 908 | * |
||
| 909 | * @return string |
||
| 910 | */ |
||
| 911 | public function getHTMLTitle() { |
||
| 914 | |||
| 915 | /** |
||
| 916 | * Set $mRedirectedFrom, the Title of the page which redirected us to the current page. |
||
| 917 | * |
||
| 918 | * @param Title $t |
||
| 919 | */ |
||
| 920 | public function setRedirectedFrom( $t ) { |
||
| 923 | |||
| 924 | /** |
||
| 925 | * "Page title" means the contents of \<h1\>. It is stored as a valid HTML |
||
| 926 | * fragment. This function allows good tags like \<sup\> in the \<h1\> tag, |
||
| 927 | * but not bad tags like \<script\>. This function automatically sets |
||
| 928 | * \<title\> to the same content as \<h1\> but with all tags removed. Bad |
||
| 929 | * tags that were escaped in \<h1\> will still be escaped in \<title\>, and |
||
| 930 | * good tags like \<i\> will be dropped entirely. |
||
| 931 | * |
||
| 932 | * @param string|Message $name |
||
| 933 | */ |
||
| 934 | public function setPageTitle( $name ) { |
||
| 950 | |||
| 951 | /** |
||
| 952 | * Return the "page title", i.e. the content of the \<h1\> tag. |
||
| 953 | * |
||
| 954 | * @return string |
||
| 955 | */ |
||
| 956 | public function getPageTitle() { |
||
| 959 | |||
| 960 | /** |
||
| 961 | * Set the Title object to use |
||
| 962 | * |
||
| 963 | * @param Title $t |
||
| 964 | */ |
||
| 965 | public function setTitle( Title $t ) { |
||
| 968 | |||
| 969 | /** |
||
| 970 | * Replace the subtitle with $str |
||
| 971 | * |
||
| 972 | * @param string|Message $str New value of the subtitle. String should be safe HTML. |
||
| 973 | */ |
||
| 974 | public function setSubtitle( $str ) { |
||
| 978 | |||
| 979 | /** |
||
| 980 | * Add $str to the subtitle |
||
| 981 | * |
||
| 982 | * @param string|Message $str String or Message to add to the subtitle. String should be safe HTML. |
||
| 983 | */ |
||
| 984 | public function addSubtitle( $str ) { |
||
| 991 | |||
| 992 | /** |
||
| 993 | * Build message object for a subtitle containing a backlink to a page |
||
| 994 | * |
||
| 995 | * @param Title $title Title to link to |
||
| 996 | * @param array $query Array of additional parameters to include in the link |
||
| 997 | * @return Message |
||
| 998 | * @since 1.25 |
||
| 999 | */ |
||
| 1000 | public static function buildBacklinkSubtitle( Title $title, $query = [] ) { |
||
| 1007 | |||
| 1008 | /** |
||
| 1009 | * Add a subtitle containing a backlink to a page |
||
| 1010 | * |
||
| 1011 | * @param Title $title Title to link to |
||
| 1012 | * @param array $query Array of additional parameters to include in the link |
||
| 1013 | */ |
||
| 1014 | public function addBacklinkSubtitle( Title $title, $query = [] ) { |
||
| 1017 | |||
| 1018 | /** |
||
| 1019 | * Clear the subtitles |
||
| 1020 | */ |
||
| 1021 | public function clearSubtitle() { |
||
| 1024 | |||
| 1025 | /** |
||
| 1026 | * Get the subtitle |
||
| 1027 | * |
||
| 1028 | * @return string |
||
| 1029 | */ |
||
| 1030 | public function getSubtitle() { |
||
| 1033 | |||
| 1034 | /** |
||
| 1035 | * Set the page as printable, i.e. it'll be displayed with all |
||
| 1036 | * print styles included |
||
| 1037 | */ |
||
| 1038 | public function setPrintable() { |
||
| 1041 | |||
| 1042 | /** |
||
| 1043 | * Return whether the page is "printable" |
||
| 1044 | * |
||
| 1045 | * @return bool |
||
| 1046 | */ |
||
| 1047 | public function isPrintable() { |
||
| 1050 | |||
| 1051 | /** |
||
| 1052 | * Disable output completely, i.e. calling output() will have no effect |
||
| 1053 | */ |
||
| 1054 | public function disable() { |
||
| 1057 | |||
| 1058 | /** |
||
| 1059 | * Return whether the output will be completely disabled |
||
| 1060 | * |
||
| 1061 | * @return bool |
||
| 1062 | */ |
||
| 1063 | public function isDisabled() { |
||
| 1066 | |||
| 1067 | /** |
||
| 1068 | * Show an "add new section" link? |
||
| 1069 | * |
||
| 1070 | * @return bool |
||
| 1071 | */ |
||
| 1072 | public function showNewSectionLink() { |
||
| 1075 | |||
| 1076 | /** |
||
| 1077 | * Forcibly hide the new section link? |
||
| 1078 | * |
||
| 1079 | * @return bool |
||
| 1080 | */ |
||
| 1081 | public function forceHideNewSectionLink() { |
||
| 1084 | |||
| 1085 | /** |
||
| 1086 | * Add or remove feed links in the page header |
||
| 1087 | * This is mainly kept for backward compatibility, see OutputPage::addFeedLink() |
||
| 1088 | * for the new version |
||
| 1089 | * @see addFeedLink() |
||
| 1090 | * |
||
| 1091 | * @param bool $show True: add default feeds, false: remove all feeds |
||
| 1092 | */ |
||
| 1093 | public function setSyndicated( $show = true ) { |
||
| 1100 | |||
| 1101 | /** |
||
| 1102 | * Add default feeds to the page header |
||
| 1103 | * This is mainly kept for backward compatibility, see OutputPage::addFeedLink() |
||
| 1104 | * for the new version |
||
| 1105 | * @see addFeedLink() |
||
| 1106 | * |
||
| 1107 | * @param string $val Query to append to feed links or false to output |
||
| 1108 | * default links |
||
| 1109 | */ |
||
| 1110 | public function setFeedAppendQuery( $val ) { |
||
| 1121 | |||
| 1122 | /** |
||
| 1123 | * Add a feed link to the page header |
||
| 1124 | * |
||
| 1125 | * @param string $format Feed type, should be a key of $wgFeedClasses |
||
| 1126 | * @param string $href URL |
||
| 1127 | */ |
||
| 1128 | public function addFeedLink( $format, $href ) { |
||
| 1133 | |||
| 1134 | /** |
||
| 1135 | * Should we output feed links for this page? |
||
| 1136 | * @return bool |
||
| 1137 | */ |
||
| 1138 | public function isSyndicated() { |
||
| 1141 | |||
| 1142 | /** |
||
| 1143 | * Return URLs for each supported syndication format for this page. |
||
| 1144 | * @return array Associating format keys with URLs |
||
| 1145 | */ |
||
| 1146 | public function getSyndicationLinks() { |
||
| 1149 | |||
| 1150 | /** |
||
| 1151 | * Will currently always return null |
||
| 1152 | * |
||
| 1153 | * @return null |
||
| 1154 | */ |
||
| 1155 | public function getFeedAppendQuery() { |
||
| 1158 | |||
| 1159 | /** |
||
| 1160 | * Set whether the displayed content is related to the source of the |
||
| 1161 | * corresponding article on the wiki |
||
| 1162 | * Setting true will cause the change "article related" toggle to true |
||
| 1163 | * |
||
| 1164 | * @param bool $v |
||
| 1165 | */ |
||
| 1166 | public function setArticleFlag( $v ) { |
||
| 1172 | |||
| 1173 | /** |
||
| 1174 | * Return whether the content displayed page is related to the source of |
||
| 1175 | * the corresponding article on the wiki |
||
| 1176 | * |
||
| 1177 | * @return bool |
||
| 1178 | */ |
||
| 1179 | public function isArticle() { |
||
| 1182 | |||
| 1183 | /** |
||
| 1184 | * Set whether this page is related an article on the wiki |
||
| 1185 | * Setting false will cause the change of "article flag" toggle to false |
||
| 1186 | * |
||
| 1187 | * @param bool $v |
||
| 1188 | */ |
||
| 1189 | public function setArticleRelated( $v ) { |
||
| 1195 | |||
| 1196 | /** |
||
| 1197 | * Return whether this page is related an article on the wiki |
||
| 1198 | * |
||
| 1199 | * @return bool |
||
| 1200 | */ |
||
| 1201 | public function isArticleRelated() { |
||
| 1204 | |||
| 1205 | /** |
||
| 1206 | * Add new language links |
||
| 1207 | * |
||
| 1208 | * @param array $newLinkArray Associative array mapping language code to the page |
||
| 1209 | * name |
||
| 1210 | */ |
||
| 1211 | public function addLanguageLinks( array $newLinkArray ) { |
||
| 1214 | |||
| 1215 | /** |
||
| 1216 | * Reset the language links and add new language links |
||
| 1217 | * |
||
| 1218 | * @param array $newLinkArray Associative array mapping language code to the page |
||
| 1219 | * name |
||
| 1220 | */ |
||
| 1221 | public function setLanguageLinks( array $newLinkArray ) { |
||
| 1224 | |||
| 1225 | /** |
||
| 1226 | * Get the list of language links |
||
| 1227 | * |
||
| 1228 | * @return array Array of Interwiki Prefixed (non DB key) Titles (e.g. 'fr:Test page') |
||
| 1229 | */ |
||
| 1230 | public function getLanguageLinks() { |
||
| 1233 | |||
| 1234 | /** |
||
| 1235 | * Add an array of categories, with names in the keys |
||
| 1236 | * |
||
| 1237 | * @param array $categories Mapping category name => sort key |
||
| 1238 | */ |
||
| 1239 | public function addCategoryLinks( array $categories ) { |
||
| 1305 | |||
| 1306 | /** |
||
| 1307 | * Reset the category links (but not the category list) and add $categories |
||
| 1308 | * |
||
| 1309 | * @param array $categories Mapping category name => sort key |
||
| 1310 | */ |
||
| 1311 | public function setCategoryLinks( array $categories ) { |
||
| 1315 | |||
| 1316 | /** |
||
| 1317 | * Get the list of category links, in a 2-D array with the following format: |
||
| 1318 | * $arr[$type][] = $link, where $type is either "normal" or "hidden" (for |
||
| 1319 | * hidden categories) and $link a HTML fragment with a link to the category |
||
| 1320 | * page |
||
| 1321 | * |
||
| 1322 | * @return array |
||
| 1323 | */ |
||
| 1324 | public function getCategoryLinks() { |
||
| 1327 | |||
| 1328 | /** |
||
| 1329 | * Get the list of category names this page belongs to |
||
| 1330 | * |
||
| 1331 | * @return array Array of strings |
||
| 1332 | */ |
||
| 1333 | public function getCategories() { |
||
| 1336 | |||
| 1337 | /** |
||
| 1338 | * Add an array of indicators, with their identifiers as array |
||
| 1339 | * keys and HTML contents as values. |
||
| 1340 | * |
||
| 1341 | * In case of duplicate keys, existing values are overwritten. |
||
| 1342 | * |
||
| 1343 | * @param array $indicators |
||
| 1344 | * @since 1.25 |
||
| 1345 | */ |
||
| 1346 | public function setIndicators( array $indicators ) { |
||
| 1351 | |||
| 1352 | /** |
||
| 1353 | * Get the indicators associated with this page. |
||
| 1354 | * |
||
| 1355 | * The array will be internally ordered by item keys. |
||
| 1356 | * |
||
| 1357 | * @return array Keys: identifiers, values: HTML contents |
||
| 1358 | * @since 1.25 |
||
| 1359 | */ |
||
| 1360 | public function getIndicators() { |
||
| 1363 | |||
| 1364 | /** |
||
| 1365 | * Adds help link with an icon via page indicators. |
||
| 1366 | * Link target can be overridden by a local message containing a wikilink: |
||
| 1367 | * the message key is: lowercase action or special page name + '-helppage'. |
||
| 1368 | * @param string $to Target MediaWiki.org page title or encoded URL. |
||
| 1369 | * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o. |
||
| 1370 | * @since 1.25 |
||
| 1371 | */ |
||
| 1372 | public function addHelpLink( $to, $overrideBaseUrl = false ) { |
||
| 1395 | |||
| 1396 | /** |
||
| 1397 | * Do not allow scripts which can be modified by wiki users to load on this page; |
||
| 1398 | * only allow scripts bundled with, or generated by, the software. |
||
| 1399 | * Site-wide styles are controlled by a config setting, since they can be |
||
| 1400 | * used to create a custom skin/theme, but not user-specific ones. |
||
| 1401 | * |
||
| 1402 | * @todo this should be given a more accurate name |
||
| 1403 | */ |
||
| 1404 | public function disallowUserJs() { |
||
| 1422 | |||
| 1423 | /** |
||
| 1424 | * Show what level of JavaScript / CSS untrustworthiness is allowed on this page |
||
| 1425 | * @see ResourceLoaderModule::$origin |
||
| 1426 | * @param string $type ResourceLoaderModule TYPE_ constant |
||
| 1427 | * @return int ResourceLoaderModule ORIGIN_ class constant |
||
| 1428 | */ |
||
| 1429 | public function getAllowedModules( $type ) { |
||
| 1438 | |||
| 1439 | /** |
||
| 1440 | * Limit the highest level of CSS/JS untrustworthiness allowed. |
||
| 1441 | * |
||
| 1442 | * If passed the same or a higher level than the current level of untrustworthiness set, the |
||
| 1443 | * level will remain unchanged. |
||
| 1444 | * |
||
| 1445 | * @param string $type |
||
| 1446 | * @param int $level ResourceLoaderModule class constant |
||
| 1447 | */ |
||
| 1448 | public function reduceAllowedModules( $type, $level ) { |
||
| 1451 | |||
| 1452 | /** |
||
| 1453 | * Prepend $text to the body HTML |
||
| 1454 | * |
||
| 1455 | * @param string $text HTML |
||
| 1456 | */ |
||
| 1457 | public function prependHTML( $text ) { |
||
| 1460 | |||
| 1461 | /** |
||
| 1462 | * Append $text to the body HTML |
||
| 1463 | * |
||
| 1464 | * @param string $text HTML |
||
| 1465 | */ |
||
| 1466 | public function addHTML( $text ) { |
||
| 1469 | |||
| 1470 | /** |
||
| 1471 | * Shortcut for adding an Html::element via addHTML. |
||
| 1472 | * |
||
| 1473 | * @since 1.19 |
||
| 1474 | * |
||
| 1475 | * @param string $element |
||
| 1476 | * @param array $attribs |
||
| 1477 | * @param string $contents |
||
| 1478 | */ |
||
| 1479 | public function addElement( $element, array $attribs = [], $contents = '' ) { |
||
| 1482 | |||
| 1483 | /** |
||
| 1484 | * Clear the body HTML |
||
| 1485 | */ |
||
| 1486 | public function clearHTML() { |
||
| 1489 | |||
| 1490 | /** |
||
| 1491 | * Get the body HTML |
||
| 1492 | * |
||
| 1493 | * @return string HTML |
||
| 1494 | */ |
||
| 1495 | public function getHTML() { |
||
| 1498 | |||
| 1499 | /** |
||
| 1500 | * Get/set the ParserOptions object to use for wikitext parsing |
||
| 1501 | * |
||
| 1502 | * @param ParserOptions|null $options Either the ParserOption to use or null to only get the |
||
| 1503 | * current ParserOption object |
||
| 1504 | * @return ParserOptions |
||
| 1505 | */ |
||
| 1506 | public function parserOptions( $options = null ) { |
||
| 1544 | |||
| 1545 | /** |
||
| 1546 | * Set the revision ID which will be seen by the wiki text parser |
||
| 1547 | * for things such as embedded {{REVISIONID}} variable use. |
||
| 1548 | * |
||
| 1549 | * @param int|null $revid An positive integer, or null |
||
| 1550 | * @return mixed Previous value |
||
| 1551 | */ |
||
| 1552 | public function setRevisionId( $revid ) { |
||
| 1556 | |||
| 1557 | /** |
||
| 1558 | * Get the displayed revision ID |
||
| 1559 | * |
||
| 1560 | * @return int |
||
| 1561 | */ |
||
| 1562 | public function getRevisionId() { |
||
| 1565 | |||
| 1566 | /** |
||
| 1567 | * Set the timestamp of the revision which will be displayed. This is used |
||
| 1568 | * to avoid a extra DB call in Skin::lastModified(). |
||
| 1569 | * |
||
| 1570 | * @param string|null $timestamp |
||
| 1571 | * @return mixed Previous value |
||
| 1572 | */ |
||
| 1573 | public function setRevisionTimestamp( $timestamp ) { |
||
| 1576 | |||
| 1577 | /** |
||
| 1578 | * Get the timestamp of displayed revision. |
||
| 1579 | * This will be null if not filled by setRevisionTimestamp(). |
||
| 1580 | * |
||
| 1581 | * @return string|null |
||
| 1582 | */ |
||
| 1583 | public function getRevisionTimestamp() { |
||
| 1586 | |||
| 1587 | /** |
||
| 1588 | * Set the displayed file version |
||
| 1589 | * |
||
| 1590 | * @param File|bool $file |
||
| 1591 | * @return mixed Previous value |
||
| 1592 | */ |
||
| 1593 | public function setFileVersion( $file ) { |
||
| 1600 | |||
| 1601 | /** |
||
| 1602 | * Get the displayed file version |
||
| 1603 | * |
||
| 1604 | * @return array|null ('time' => MW timestamp, 'sha1' => sha1) |
||
| 1605 | */ |
||
| 1606 | public function getFileVersion() { |
||
| 1609 | |||
| 1610 | /** |
||
| 1611 | * Get the templates used on this page |
||
| 1612 | * |
||
| 1613 | * @return array (namespace => dbKey => revId) |
||
| 1614 | * @since 1.18 |
||
| 1615 | */ |
||
| 1616 | public function getTemplateIds() { |
||
| 1619 | |||
| 1620 | /** |
||
| 1621 | * Get the files used on this page |
||
| 1622 | * |
||
| 1623 | * @return array (dbKey => array('time' => MW timestamp or null, 'sha1' => sha1 or '')) |
||
| 1624 | * @since 1.18 |
||
| 1625 | */ |
||
| 1626 | public function getFileSearchOptions() { |
||
| 1629 | |||
| 1630 | /** |
||
| 1631 | * Convert wikitext to HTML and add it to the buffer |
||
| 1632 | * Default assumes that the current page title will be used. |
||
| 1633 | * |
||
| 1634 | * @param string $text |
||
| 1635 | * @param bool $linestart Is this the start of a line? |
||
| 1636 | * @param bool $interface Is this text in the user interface language? |
||
| 1637 | * @throws MWException |
||
| 1638 | */ |
||
| 1639 | public function addWikiText( $text, $linestart = true, $interface = true ) { |
||
| 1646 | |||
| 1647 | /** |
||
| 1648 | * Add wikitext with a custom Title object |
||
| 1649 | * |
||
| 1650 | * @param string $text Wikitext |
||
| 1651 | * @param Title $title |
||
| 1652 | * @param bool $linestart Is this the start of a line? |
||
| 1653 | */ |
||
| 1654 | public function addWikiTextWithTitle( $text, &$title, $linestart = true ) { |
||
| 1657 | |||
| 1658 | /** |
||
| 1659 | * Add wikitext with a custom Title object and tidy enabled. |
||
| 1660 | * |
||
| 1661 | * @param string $text Wikitext |
||
| 1662 | * @param Title $title |
||
| 1663 | * @param bool $linestart Is this the start of a line? |
||
| 1664 | */ |
||
| 1665 | function addWikiTextTitleTidy( $text, &$title, $linestart = true ) { |
||
| 1668 | |||
| 1669 | /** |
||
| 1670 | * Add wikitext with tidy enabled |
||
| 1671 | * |
||
| 1672 | * @param string $text Wikitext |
||
| 1673 | * @param bool $linestart Is this the start of a line? |
||
| 1674 | */ |
||
| 1675 | public function addWikiTextTidy( $text, $linestart = true ) { |
||
| 1679 | |||
| 1680 | /** |
||
| 1681 | * Add wikitext with a custom Title object |
||
| 1682 | * |
||
| 1683 | * @param string $text Wikitext |
||
| 1684 | * @param Title $title |
||
| 1685 | * @param bool $linestart Is this the start of a line? |
||
| 1686 | * @param bool $tidy Whether to use tidy |
||
| 1687 | * @param bool $interface Whether it is an interface message |
||
| 1688 | * (for example disables conversion) |
||
| 1689 | */ |
||
| 1690 | public function addWikiTextTitle( $text, Title $title, $linestart, |
||
| 1709 | |||
| 1710 | /** |
||
| 1711 | * Add a ParserOutput object, but without Html. |
||
| 1712 | * |
||
| 1713 | * @deprecated since 1.24, use addParserOutputMetadata() instead. |
||
| 1714 | * @param ParserOutput $parserOutput |
||
| 1715 | */ |
||
| 1716 | public function addParserOutputNoText( $parserOutput ) { |
||
| 1720 | |||
| 1721 | /** |
||
| 1722 | * Add all metadata associated with a ParserOutput object, but without the actual HTML. This |
||
| 1723 | * includes categories, language links, ResourceLoader modules, effects of certain magic words, |
||
| 1724 | * and so on. |
||
| 1725 | * |
||
| 1726 | * @since 1.24 |
||
| 1727 | * @param ParserOutput $parserOutput |
||
| 1728 | */ |
||
| 1729 | public function addParserOutputMetadata( $parserOutput ) { |
||
| 1730 | $this->mLanguageLinks += $parserOutput->getLanguageLinks(); |
||
| 1731 | $this->addCategoryLinks( $parserOutput->getCategories() ); |
||
| 1732 | $this->setIndicators( $parserOutput->getIndicators() ); |
||
| 1733 | $this->mNewSectionLink = $parserOutput->getNewSection(); |
||
| 1734 | $this->mHideNewSectionLink = $parserOutput->getHideNewSection(); |
||
| 1735 | |||
| 1736 | if ( !$parserOutput->isCacheable() ) { |
||
| 1737 | $this->enableClientCache( false ); |
||
| 1738 | } |
||
| 1739 | $this->mNoGallery = $parserOutput->getNoGallery(); |
||
| 1740 | $this->mHeadItems = array_merge( $this->mHeadItems, $parserOutput->getHeadItems() ); |
||
| 1741 | $this->addModules( $parserOutput->getModules() ); |
||
| 1742 | $this->addModuleScripts( $parserOutput->getModuleScripts() ); |
||
| 1743 | $this->addModuleStyles( $parserOutput->getModuleStyles() ); |
||
| 1744 | $this->addJsConfigVars( $parserOutput->getJsConfigVars() ); |
||
| 1745 | $this->mPreventClickjacking = $this->mPreventClickjacking |
||
| 1746 | || $parserOutput->preventClickjacking(); |
||
| 1747 | |||
| 1748 | // Template versioning... |
||
| 1749 | foreach ( (array)$parserOutput->getTemplateIds() as $ns => $dbks ) { |
||
| 1750 | if ( isset( $this->mTemplateIds[$ns] ) ) { |
||
| 1751 | $this->mTemplateIds[$ns] = $dbks + $this->mTemplateIds[$ns]; |
||
| 1752 | } else { |
||
| 1753 | $this->mTemplateIds[$ns] = $dbks; |
||
| 1754 | } |
||
| 1755 | } |
||
| 1756 | // File versioning... |
||
| 1757 | foreach ( (array)$parserOutput->getFileSearchOptions() as $dbk => $data ) { |
||
| 1758 | $this->mImageTimeKeys[$dbk] = $data; |
||
| 1759 | } |
||
| 1760 | |||
| 1761 | // Hooks registered in the object |
||
| 1762 | $parserOutputHooks = $this->getConfig()->get( 'ParserOutputHooks' ); |
||
| 1763 | foreach ( $parserOutput->getOutputHooks() as $hookInfo ) { |
||
| 1764 | list( $hookName, $data ) = $hookInfo; |
||
| 1765 | if ( isset( $parserOutputHooks[$hookName] ) ) { |
||
| 1766 | call_user_func( $parserOutputHooks[$hookName], $this, $parserOutput, $data ); |
||
| 1767 | } |
||
| 1768 | } |
||
| 1769 | |||
| 1770 | // Enable OOUI if requested via ParserOutput |
||
| 1771 | if ( $parserOutput->getEnableOOUI() ) { |
||
| 1772 | $this->enableOOUI(); |
||
| 1773 | } |
||
| 1774 | |||
| 1775 | // Include profiling data |
||
| 1776 | $this->setLimitReportData( $parserOutput->getLimitReportData() ); |
||
| 1777 | |||
| 1778 | // Link flags are ignored for now, but may in the future be |
||
| 1779 | // used to mark individual language links. |
||
| 1780 | $linkFlags = []; |
||
| 1781 | Hooks::run( 'LanguageLinks', [ $this->getTitle(), &$this->mLanguageLinks, &$linkFlags ] ); |
||
| 1782 | Hooks::run( 'OutputPageParserOutput', [ &$this, $parserOutput ] ); |
||
| 1783 | } |
||
| 1784 | |||
| 1785 | /** |
||
| 1786 | * Add the HTML and enhancements for it (like ResourceLoader modules) associated with a |
||
| 1787 | * ParserOutput object, without any other metadata. |
||
| 1788 | * |
||
| 1789 | * @since 1.24 |
||
| 1790 | * @param ParserOutput $parserOutput |
||
| 1791 | */ |
||
| 1792 | public function addParserOutputContent( $parserOutput ) { |
||
| 1801 | |||
| 1802 | /** |
||
| 1803 | * Add the HTML associated with a ParserOutput object, without any metadata. |
||
| 1804 | * |
||
| 1805 | * @since 1.24 |
||
| 1806 | * @param ParserOutput $parserOutput |
||
| 1807 | */ |
||
| 1808 | public function addParserOutputText( $parserOutput ) { |
||
| 1813 | |||
| 1814 | /** |
||
| 1815 | * Add everything from a ParserOutput object. |
||
| 1816 | * |
||
| 1817 | * @param ParserOutput $parserOutput |
||
| 1818 | */ |
||
| 1819 | function addParserOutput( $parserOutput ) { |
||
| 1830 | |||
| 1831 | /** |
||
| 1832 | * Add the output of a QuickTemplate to the output buffer |
||
| 1833 | * |
||
| 1834 | * @param QuickTemplate $template |
||
| 1835 | */ |
||
| 1836 | public function addTemplate( &$template ) { |
||
| 1839 | |||
| 1840 | /** |
||
| 1841 | * Parse wikitext and return the HTML. |
||
| 1842 | * |
||
| 1843 | * @param string $text |
||
| 1844 | * @param bool $linestart Is this the start of a line? |
||
| 1845 | * @param bool $interface Use interface language ($wgLang instead of |
||
| 1846 | * $wgContLang) while parsing language sensitive magic words like GRAMMAR and PLURAL. |
||
| 1847 | * This also disables LanguageConverter. |
||
| 1848 | * @param Language $language Target language object, will override $interface |
||
| 1849 | * @throws MWException |
||
| 1850 | * @return string HTML |
||
| 1851 | */ |
||
| 1852 | public function parse( $text, $linestart = true, $interface = false, $language = null ) { |
||
| 1881 | |||
| 1882 | /** |
||
| 1883 | * Parse wikitext, strip paragraphs, and return the HTML. |
||
| 1884 | * |
||
| 1885 | * @param string $text |
||
| 1886 | * @param bool $linestart Is this the start of a line? |
||
| 1887 | * @param bool $interface Use interface language ($wgLang instead of |
||
| 1888 | * $wgContLang) while parsing language sensitive magic |
||
| 1889 | * words like GRAMMAR and PLURAL |
||
| 1890 | * @return string HTML |
||
| 1891 | */ |
||
| 1892 | public function parseInline( $text, $linestart = true, $interface = false ) { |
||
| 1896 | |||
| 1897 | /** |
||
| 1898 | * @param $maxage |
||
| 1899 | * @deprecated since 1.27 Use setCdnMaxage() instead |
||
| 1900 | */ |
||
| 1901 | public function setSquidMaxage( $maxage ) { |
||
| 1904 | |||
| 1905 | /** |
||
| 1906 | * Set the value of the "s-maxage" part of the "Cache-control" HTTP header |
||
| 1907 | * |
||
| 1908 | * @param int $maxage Maximum cache time on the CDN, in seconds. |
||
| 1909 | */ |
||
| 1910 | public function setCdnMaxage( $maxage ) { |
||
| 1913 | |||
| 1914 | /** |
||
| 1915 | * Lower the value of the "s-maxage" part of the "Cache-control" HTTP header |
||
| 1916 | * |
||
| 1917 | * @param int $maxage Maximum cache time on the CDN, in seconds |
||
| 1918 | * @since 1.27 |
||
| 1919 | */ |
||
| 1920 | public function lowerCdnMaxage( $maxage ) { |
||
| 1924 | |||
| 1925 | /** |
||
| 1926 | * Use enableClientCache(false) to force it to send nocache headers |
||
| 1927 | * |
||
| 1928 | * @param bool $state |
||
| 1929 | * |
||
| 1930 | * @return bool |
||
| 1931 | */ |
||
| 1932 | public function enableClientCache( $state ) { |
||
| 1935 | |||
| 1936 | /** |
||
| 1937 | * Get the list of cookies that will influence on the cache |
||
| 1938 | * |
||
| 1939 | * @return array |
||
| 1940 | */ |
||
| 1941 | function getCacheVaryCookies() { |
||
| 1956 | |||
| 1957 | /** |
||
| 1958 | * Check if the request has a cache-varying cookie header |
||
| 1959 | * If it does, it's very important that we don't allow public caching |
||
| 1960 | * |
||
| 1961 | * @return bool |
||
| 1962 | */ |
||
| 1963 | function haveCacheVaryCookies() { |
||
| 1974 | |||
| 1975 | /** |
||
| 1976 | * Add an HTTP header that will influence on the cache |
||
| 1977 | * |
||
| 1978 | * @param string $header Header name |
||
| 1979 | * @param string[]|null $option Options for the Key header. See |
||
| 1980 | * https://datatracker.ietf.org/doc/draft-fielding-http-key/ |
||
| 1981 | * for the list of valid options. |
||
| 1982 | */ |
||
| 1983 | public function addVaryHeader( $header, array $option = null ) { |
||
| 1992 | |||
| 1993 | /** |
||
| 1994 | * Return a Vary: header on which to vary caches. Based on the keys of $mVaryHeader, |
||
| 1995 | * such as Accept-Encoding or Cookie |
||
| 1996 | * |
||
| 1997 | * @return string |
||
| 1998 | */ |
||
| 1999 | public function getVaryHeader() { |
||
| 2010 | |||
| 2011 | /** |
||
| 2012 | * Get a complete Key header |
||
| 2013 | * |
||
| 2014 | * @return string |
||
| 2015 | */ |
||
| 2016 | public function getKeyHeader() { |
||
| 2041 | |||
| 2042 | /** |
||
| 2043 | * T23672: Add Accept-Language to Vary and Key headers |
||
| 2044 | * if there's no 'variant' parameter existed in GET. |
||
| 2045 | * |
||
| 2046 | * For example: |
||
| 2047 | * /w/index.php?title=Main_page should always be served; but |
||
| 2048 | * /w/index.php?title=Main_page&variant=zh-cn should never be served. |
||
| 2049 | */ |
||
| 2050 | function addAcceptLanguage() { |
||
| 2078 | |||
| 2079 | /** |
||
| 2080 | * Set a flag which will cause an X-Frame-Options header appropriate for |
||
| 2081 | * edit pages to be sent. The header value is controlled by |
||
| 2082 | * $wgEditPageFrameOptions. |
||
| 2083 | * |
||
| 2084 | * This is the default for special pages. If you display a CSRF-protected |
||
| 2085 | * form on an ordinary view page, then you need to call this function. |
||
| 2086 | * |
||
| 2087 | * @param bool $enable |
||
| 2088 | */ |
||
| 2089 | public function preventClickjacking( $enable = true ) { |
||
| 2092 | |||
| 2093 | /** |
||
| 2094 | * Turn off frame-breaking. Alias for $this->preventClickjacking(false). |
||
| 2095 | * This can be called from pages which do not contain any CSRF-protected |
||
| 2096 | * HTML form. |
||
| 2097 | */ |
||
| 2098 | public function allowClickjacking() { |
||
| 2101 | |||
| 2102 | /** |
||
| 2103 | * Get the prevent-clickjacking flag |
||
| 2104 | * |
||
| 2105 | * @since 1.24 |
||
| 2106 | * @return bool |
||
| 2107 | */ |
||
| 2108 | public function getPreventClickjacking() { |
||
| 2111 | |||
| 2112 | /** |
||
| 2113 | * Get the X-Frame-Options header value (without the name part), or false |
||
| 2114 | * if there isn't one. This is used by Skin to determine whether to enable |
||
| 2115 | * JavaScript frame-breaking, for clients that don't support X-Frame-Options. |
||
| 2116 | * |
||
| 2117 | * @return string |
||
| 2118 | */ |
||
| 2119 | public function getFrameOptions() { |
||
| 2128 | |||
| 2129 | /** |
||
| 2130 | * Send cache control HTTP headers |
||
| 2131 | */ |
||
| 2132 | public function sendCacheControl() { |
||
| 2197 | |||
| 2198 | /** |
||
| 2199 | * Finally, all the text has been munged and accumulated into |
||
| 2200 | * the object, let's actually output it: |
||
| 2201 | */ |
||
| 2202 | public function output() { |
||
| 2312 | |||
| 2313 | /** |
||
| 2314 | * Prepare this object to display an error page; disable caching and |
||
| 2315 | * indexing, clear the current text and redirect, set the page's title |
||
| 2316 | * and optionally an custom HTML title (content of the "<title>" tag). |
||
| 2317 | * |
||
| 2318 | * @param string|Message $pageTitle Will be passed directly to setPageTitle() |
||
| 2319 | * @param string|Message $htmlTitle Will be passed directly to setHTMLTitle(); |
||
| 2320 | * optional, if not passed the "<title>" attribute will be |
||
| 2321 | * based on $pageTitle |
||
| 2322 | */ |
||
| 2323 | public function prepareErrorPage( $pageTitle, $htmlTitle = false ) { |
||
| 2335 | |||
| 2336 | /** |
||
| 2337 | * Output a standard error page |
||
| 2338 | * |
||
| 2339 | * showErrorPage( 'titlemsg', 'pagetextmsg' ); |
||
| 2340 | * showErrorPage( 'titlemsg', 'pagetextmsg', array( 'param1', 'param2' ) ); |
||
| 2341 | * showErrorPage( 'titlemsg', $messageObject ); |
||
| 2342 | * showErrorPage( $titleMessageObject, $messageObject ); |
||
| 2343 | * |
||
| 2344 | * @param string|Message $title Message key (string) for page title, or a Message object |
||
| 2345 | * @param string|Message $msg Message key (string) for page text, or a Message object |
||
| 2346 | * @param array $params Message parameters; ignored if $msg is a Message object |
||
| 2347 | */ |
||
| 2348 | public function showErrorPage( $title, $msg, $params = [] ) { |
||
| 2368 | |||
| 2369 | /** |
||
| 2370 | * Output a standard permission error page |
||
| 2371 | * |
||
| 2372 | * @param array $errors Error message keys |
||
| 2373 | * @param string $action Action that was denied or null if unknown |
||
| 2374 | */ |
||
| 2375 | public function showPermissionsErrorPage( array $errors, $action = null ) { |
||
| 2440 | |||
| 2441 | /** |
||
| 2442 | * Display an error page indicating that a given version of MediaWiki is |
||
| 2443 | * required to use it |
||
| 2444 | * |
||
| 2445 | * @param mixed $version The version of MediaWiki needed to use the page |
||
| 2446 | */ |
||
| 2447 | public function versionRequired( $version ) { |
||
| 2453 | |||
| 2454 | /** |
||
| 2455 | * Format a list of error messages |
||
| 2456 | * |
||
| 2457 | * @param array $errors Array of arrays returned by Title::getUserPermissionsErrors |
||
| 2458 | * @param string $action Action that was denied or null if unknown |
||
| 2459 | * @return string The wikitext error-messages, formatted into a list. |
||
| 2460 | */ |
||
| 2461 | public function formatPermissionsErrorMessage( array $errors, $action = null ) { |
||
| 2490 | |||
| 2491 | /** |
||
| 2492 | * Display a page stating that the Wiki is in read-only mode. |
||
| 2493 | * Should only be called after wfReadOnly() has returned true. |
||
| 2494 | * |
||
| 2495 | * Historically, this function was used to show the source of the page that the user |
||
| 2496 | * was trying to edit and _also_ permissions error messages. The relevant code was |
||
| 2497 | * moved into EditPage in 1.19 (r102024 / d83c2a431c2a) and removed here in 1.25. |
||
| 2498 | * |
||
| 2499 | * @deprecated since 1.25; throw the exception directly |
||
| 2500 | * @throws ReadOnlyError |
||
| 2501 | */ |
||
| 2502 | public function readOnlyPage() { |
||
| 2509 | |||
| 2510 | /** |
||
| 2511 | * Turn off regular page output and return an error response |
||
| 2512 | * for when rate limiting has triggered. |
||
| 2513 | * |
||
| 2514 | * @deprecated since 1.25; throw the exception directly |
||
| 2515 | */ |
||
| 2516 | public function rateLimited() { |
||
| 2520 | |||
| 2521 | /** |
||
| 2522 | * Show a warning about slave lag |
||
| 2523 | * |
||
| 2524 | * If the lag is higher than $wgSlaveLagCritical seconds, |
||
| 2525 | * then the warning is a bit more obvious. If the lag is |
||
| 2526 | * lower than $wgSlaveLagWarning, then no warning is shown. |
||
| 2527 | * |
||
| 2528 | * @param int $lag Slave lag |
||
| 2529 | */ |
||
| 2530 | public function showLagWarning( $lag ) { |
||
| 2540 | |||
| 2541 | public function showFatalError( $message ) { |
||
| 2546 | |||
| 2547 | public function showUnexpectedValueError( $name, $val ) { |
||
| 2550 | |||
| 2551 | public function showFileCopyError( $old, $new ) { |
||
| 2554 | |||
| 2555 | public function showFileRenameError( $old, $new ) { |
||
| 2558 | |||
| 2559 | public function showFileDeleteError( $name ) { |
||
| 2562 | |||
| 2563 | public function showFileNotFoundError( $name ) { |
||
| 2566 | |||
| 2567 | /** |
||
| 2568 | * Add a "return to" link pointing to a specified title |
||
| 2569 | * |
||
| 2570 | * @param Title $title Title to link |
||
| 2571 | * @param array $query Query string parameters |
||
| 2572 | * @param string $text Text of the link (input is not escaped) |
||
| 2573 | * @param array $options Options array to pass to Linker |
||
| 2574 | */ |
||
| 2575 | public function addReturnTo( $title, array $query = [], $text = null, $options = [] ) { |
||
| 2580 | |||
| 2581 | /** |
||
| 2582 | * Add a "return to" link pointing to a specified title, |
||
| 2583 | * or the title indicated in the request, or else the main page |
||
| 2584 | * |
||
| 2585 | * @param mixed $unused |
||
| 2586 | * @param Title|string $returnto Title or String to return to |
||
| 2587 | * @param string $returntoquery Query string for the return to link |
||
| 2588 | */ |
||
| 2589 | public function returnToMain( $unused = null, $returnto = null, $returntoquery = null ) { |
||
| 2613 | |||
| 2614 | /** |
||
| 2615 | * @param Skin $sk The given Skin |
||
| 2616 | * @param bool $includeStyle Unused |
||
| 2617 | * @return string The doctype, opening "<html>", and head element. |
||
| 2618 | */ |
||
| 2619 | public function headElement( Skin $sk, $includeStyle = true ) { |
||
| 2702 | |||
| 2703 | /** |
||
| 2704 | * Get a ResourceLoader object associated with this OutputPage |
||
| 2705 | * |
||
| 2706 | * @return ResourceLoader |
||
| 2707 | */ |
||
| 2708 | public function getResourceLoader() { |
||
| 2717 | |||
| 2718 | /** |
||
| 2719 | * Construct neccecary html and loader preset states to load modules on a page. |
||
| 2720 | * |
||
| 2721 | * Use getHtmlFromLoaderLinks() to convert this array to HTML. |
||
| 2722 | * |
||
| 2723 | * @param array|string $modules One or more module names |
||
| 2724 | * @param string $only ResourceLoaderModule TYPE_ class constant |
||
| 2725 | * @param array $extraQuery [optional] Array with extra query parameters for the request |
||
| 2726 | * @return array A list of HTML strings and array of client loader preset states |
||
| 2727 | */ |
||
| 2728 | public function makeResourceLoaderLink( $modules, $only, array $extraQuery = [] ) { |
||
| 2908 | |||
| 2909 | /** |
||
| 2910 | * Build html output from an array of links from makeResourceLoaderLink. |
||
| 2911 | * @param array $links |
||
| 2912 | * @return string|WrappedStringList HTML |
||
| 2913 | */ |
||
| 2914 | protected static function getHtmlFromLoaderLinks( array $links ) { |
||
| 2936 | |||
| 2937 | /** |
||
| 2938 | * JS stuff to put in the "<head>". This is the startup module, config |
||
| 2939 | * vars and modules marked with position 'top' |
||
| 2940 | * |
||
| 2941 | * @return string HTML fragment |
||
| 2942 | */ |
||
| 2943 | function getHeadScripts() { |
||
| 2946 | |||
| 2947 | /** |
||
| 2948 | * <script src="..."> tags for "<head>".This is the startup module |
||
| 2949 | * and other modules marked with position 'top'. |
||
| 2950 | * |
||
| 2951 | * @return string|WrappedStringList HTML |
||
| 2952 | */ |
||
| 2953 | function getExternalHeadScripts() { |
||
| 2960 | |||
| 2961 | /** |
||
| 2962 | * Inline "<script>" tags to put in "<head>". |
||
| 2963 | * |
||
| 2964 | * @return string|WrappedStringList HTML |
||
| 2965 | */ |
||
| 2966 | function getInlineHeadScripts() { |
||
| 3016 | |||
| 3017 | /** |
||
| 3018 | * JS stuff to put at the 'bottom', which goes at the bottom of the `<body>`. |
||
| 3019 | * These are modules marked with position 'bottom', legacy scripts ($this->mScripts), |
||
| 3020 | * site JS, and user JS. |
||
| 3021 | * |
||
| 3022 | * @param bool $unused Previously used to let this method change its output based |
||
| 3023 | * on whether it was called by getExternalHeadScripts() or getBottomScripts(). |
||
| 3024 | * @return string|WrappedStringList HTML |
||
| 3025 | */ |
||
| 3026 | function getScriptsForBottomQueue( $unused = null ) { |
||
| 3088 | |||
| 3089 | /** |
||
| 3090 | * JS stuff to put at the bottom of the "<body>" |
||
| 3091 | * @return string |
||
| 3092 | */ |
||
| 3093 | function getBottomScripts() { |
||
| 3094 | return $this->getScriptsForBottomQueue() . |
||
| 3095 | ResourceLoader::makeInlineScript( |
||
| 3096 | ResourceLoader::makeConfigSetScript( |
||
| 3097 | [ 'wgPageParseReport' => $this->limitReportData ], |
||
| 3098 | true |
||
| 3099 | ) |
||
| 3100 | ); |
||
| 3101 | } |
||
| 3102 | |||
| 3103 | /** |
||
| 3104 | * Get the javascript config vars to include on this page |
||
| 3105 | * |
||
| 3106 | * @return array Array of javascript config vars |
||
| 3107 | * @since 1.23 |
||
| 3108 | */ |
||
| 3109 | public function getJsConfigVars() { |
||
| 3112 | |||
| 3113 | /** |
||
| 3114 | * Add one or more variables to be set in mw.config in JavaScript |
||
| 3115 | * |
||
| 3116 | * @param string|array $keys Key or array of key/value pairs |
||
| 3117 | * @param mixed $value [optional] Value of the configuration variable |
||
| 3118 | */ |
||
| 3119 | View Code Duplication | public function addJsConfigVars( $keys, $value = null ) { |
|
| 3129 | |||
| 3130 | /** |
||
| 3131 | * Get an array containing the variables to be set in mw.config in JavaScript. |
||
| 3132 | * |
||
| 3133 | * Do not add things here which can be evaluated in ResourceLoaderStartUpModule |
||
| 3134 | * - in other words, page-independent/site-wide variables (without state). |
||
| 3135 | * You will only be adding bloat to the html page and causing page caches to |
||
| 3136 | * have to be purged on configuration changes. |
||
| 3137 | * @return array |
||
| 3138 | */ |
||
| 3139 | public function getJSVars() { |
||
| 3256 | |||
| 3257 | /** |
||
| 3258 | * To make it harder for someone to slip a user a fake |
||
| 3259 | * user-JavaScript or user-CSS preview, a random token |
||
| 3260 | * is associated with the login session. If it's not |
||
| 3261 | * passed back with the preview request, we won't render |
||
| 3262 | * the code. |
||
| 3263 | * |
||
| 3264 | * @return bool |
||
| 3265 | */ |
||
| 3266 | public function userCanPreview() { |
||
| 3297 | |||
| 3298 | /** |
||
| 3299 | * @return array Array in format "link name or number => 'link html'". |
||
| 3300 | */ |
||
| 3301 | public function getHeadLinksArray() { |
||
| 3562 | |||
| 3563 | /** |
||
| 3564 | * @return string HTML tag links to be put in the header. |
||
| 3565 | * @deprecated since 1.24 Use OutputPage::headElement or if you have to, |
||
| 3566 | * OutputPage::getHeadLinksArray directly. |
||
| 3567 | */ |
||
| 3568 | public function getHeadLinks() { |
||
| 3572 | |||
| 3573 | /** |
||
| 3574 | * Generate a "<link rel/>" for a feed. |
||
| 3575 | * |
||
| 3576 | * @param string $type Feed type |
||
| 3577 | * @param string $url URL to the feed |
||
| 3578 | * @param string $text Value of the "title" attribute |
||
| 3579 | * @return string HTML fragment |
||
| 3580 | */ |
||
| 3581 | private function feedLink( $type, $url, $text ) { |
||
| 3589 | |||
| 3590 | /** |
||
| 3591 | * Add a local or specified stylesheet, with the given media options. |
||
| 3592 | * Internal use only. Use OutputPage::addModuleStyles() if possible. |
||
| 3593 | * |
||
| 3594 | * @param string $style URL to the file |
||
| 3595 | * @param string $media To specify a media type, 'screen', 'printable', 'handheld' or any. |
||
| 3596 | * @param string $condition For IE conditional comments, specifying an IE version |
||
| 3597 | * @param string $dir Set to 'rtl' or 'ltr' for direction-specific sheets |
||
| 3598 | */ |
||
| 3599 | public function addStyle( $style, $media = '', $condition = '', $dir = '' ) { |
||
| 3612 | |||
| 3613 | /** |
||
| 3614 | * Adds inline CSS styles |
||
| 3615 | * Internal use only. Use OutputPage::addModuleStyles() if possible. |
||
| 3616 | * |
||
| 3617 | * @param mixed $style_css Inline CSS |
||
| 3618 | * @param string $flip Set to 'flip' to flip the CSS if needed |
||
| 3619 | */ |
||
| 3620 | public function addInlineStyle( $style_css, $flip = 'noflip' ) { |
||
| 3627 | |||
| 3628 | /** |
||
| 3629 | * Build a set of "<link>" elements for stylesheets specified in the $this->styles array. |
||
| 3630 | * |
||
| 3631 | * @return string|WrappedStringList HTML |
||
| 3632 | */ |
||
| 3633 | public function buildCssLinks() { |
||
| 3737 | |||
| 3738 | /** |
||
| 3739 | * @return array |
||
| 3740 | */ |
||
| 3741 | public function buildCssLinksArray() { |
||
| 3758 | |||
| 3759 | /** |
||
| 3760 | * Generate \<link\> tags for stylesheets |
||
| 3761 | * |
||
| 3762 | * @param string $style URL to the file |
||
| 3763 | * @param array $options Option, can contain 'condition', 'dir', 'media' keys |
||
| 3764 | * @return string HTML fragment |
||
| 3765 | */ |
||
| 3766 | protected function styleLink( $style, array $options ) { |
||
| 3800 | |||
| 3801 | /** |
||
| 3802 | * Transform path to web-accessible static resource. |
||
| 3803 | * |
||
| 3804 | * This is used to add a validation hash as query string. |
||
| 3805 | * This aids various behaviors: |
||
| 3806 | * |
||
| 3807 | * - Put long Cache-Control max-age headers on responses for improved |
||
| 3808 | * cache performance. |
||
| 3809 | * - Get the correct version of a file as expected by the current page. |
||
| 3810 | * - Instantly get the updated version of a file after deployment. |
||
| 3811 | * |
||
| 3812 | * Avoid using this for urls included in HTML as otherwise clients may get different |
||
| 3813 | * versions of a resource when navigating the site depending on when the page was cached. |
||
| 3814 | * If changes to the url propagate, this is not a problem (e.g. if the url is in |
||
| 3815 | * an external stylesheet). |
||
| 3816 | * |
||
| 3817 | * @since 1.27 |
||
| 3818 | * @param Config $config |
||
| 3819 | * @param string $path Path-absolute URL to file (from document root, must start with "/") |
||
| 3820 | * @return string URL |
||
| 3821 | */ |
||
| 3822 | public static function transformResourcePath( Config $config, $path ) { |
||
| 3839 | |||
| 3840 | /** |
||
| 3841 | * Utility method for transformResourceFilePath(). |
||
| 3842 | * |
||
| 3843 | * Caller is responsible for ensuring the file exists. Emits a PHP warning otherwise. |
||
| 3844 | * |
||
| 3845 | * @since 1.27 |
||
| 3846 | * @param string $remotePath URL path prefix that points to $localPath |
||
| 3847 | * @param string $localPath File directory exposed at $remotePath |
||
| 3848 | * @param string $file Path to target file relative to $localPath |
||
| 3849 | * @return string URL |
||
| 3850 | */ |
||
| 3851 | public static function transformFilePath( $remotePathPrefix, $localPath, $file ) { |
||
| 3859 | |||
| 3860 | /** |
||
| 3861 | * Transform "media" attribute based on request parameters |
||
| 3862 | * |
||
| 3863 | * @param string $media Current value of the "media" attribute |
||
| 3864 | * @return string Modified value of the "media" attribute, or null to skip |
||
| 3865 | * this stylesheet |
||
| 3866 | */ |
||
| 3867 | public static function transformCssMedia( $media ) { |
||
| 3905 | |||
| 3906 | /** |
||
| 3907 | * Add a wikitext-formatted message to the output. |
||
| 3908 | * This is equivalent to: |
||
| 3909 | * |
||
| 3910 | * $wgOut->addWikiText( wfMessage( ... )->plain() ) |
||
| 3911 | */ |
||
| 3912 | public function addWikiMsg( /*...*/ ) { |
||
| 3917 | |||
| 3918 | /** |
||
| 3919 | * Add a wikitext-formatted message to the output. |
||
| 3920 | * Like addWikiMsg() except the parameters are taken as an array |
||
| 3921 | * instead of a variable argument list. |
||
| 3922 | * |
||
| 3923 | * @param string $name |
||
| 3924 | * @param array $args |
||
| 3925 | */ |
||
| 3926 | public function addWikiMsgArray( $name, $args ) { |
||
| 3929 | |||
| 3930 | /** |
||
| 3931 | * This function takes a number of message/argument specifications, wraps them in |
||
| 3932 | * some overall structure, and then parses the result and adds it to the output. |
||
| 3933 | * |
||
| 3934 | * In the $wrap, $1 is replaced with the first message, $2 with the second, |
||
| 3935 | * and so on. The subsequent arguments may be either |
||
| 3936 | * 1) strings, in which case they are message names, or |
||
| 3937 | * 2) arrays, in which case, within each array, the first element is the message |
||
| 3938 | * name, and subsequent elements are the parameters to that message. |
||
| 3939 | * |
||
| 3940 | * Don't use this for messages that are not in the user's interface language. |
||
| 3941 | * |
||
| 3942 | * For example: |
||
| 3943 | * |
||
| 3944 | * $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>", 'some-error' ); |
||
| 3945 | * |
||
| 3946 | * Is equivalent to: |
||
| 3947 | * |
||
| 3948 | * $wgOut->addWikiText( "<div class='error'>\n" |
||
| 3949 | * . wfMessage( 'some-error' )->plain() . "\n</div>" ); |
||
| 3950 | * |
||
| 3951 | * The newline after the opening div is needed in some wikitext. See bug 19226. |
||
| 3952 | * |
||
| 3953 | * @param string $wrap |
||
| 3954 | */ |
||
| 3955 | public function wrapWikiMsg( $wrap /*, ...*/ ) { |
||
| 3979 | |||
| 3980 | /** |
||
| 3981 | * Enables/disables TOC, doesn't override __NOTOC__ |
||
| 3982 | * @param bool $flag |
||
| 3983 | * @since 1.22 |
||
| 3984 | */ |
||
| 3985 | public function enableTOC( $flag = true ) { |
||
| 3988 | |||
| 3989 | /** |
||
| 3990 | * @return bool |
||
| 3991 | * @since 1.22 |
||
| 3992 | */ |
||
| 3993 | public function isTOCEnabled() { |
||
| 3996 | |||
| 3997 | /** |
||
| 3998 | * Enables/disables section edit links, doesn't override __NOEDITSECTION__ |
||
| 3999 | * @param bool $flag |
||
| 4000 | * @since 1.23 |
||
| 4001 | */ |
||
| 4002 | public function enableSectionEditLinks( $flag = true ) { |
||
| 4005 | |||
| 4006 | /** |
||
| 4007 | * @return bool |
||
| 4008 | * @since 1.23 |
||
| 4009 | */ |
||
| 4010 | public function sectionEditLinksEnabled() { |
||
| 4013 | |||
| 4014 | /** |
||
| 4015 | * Helper function to setup the PHP implementation of OOUI to use in this request. |
||
| 4016 | * |
||
| 4017 | * @since 1.26 |
||
| 4018 | * @param String $skinName The Skin name to determine the correct OOUI theme |
||
| 4019 | * @param String $dir Language direction |
||
| 4020 | */ |
||
| 4021 | public static function setupOOUI( $skinName = '', $dir = 'ltr' ) { |
||
| 4031 | |||
| 4032 | /** |
||
| 4033 | * Add ResourceLoader module styles for OOUI and set up the PHP implementation of it for use with |
||
| 4034 | * MediaWiki and this OutputPage instance. |
||
| 4035 | * |
||
| 4036 | * @since 1.25 |
||
| 4037 | */ |
||
| 4038 | public function enableOOUI() { |
||
| 4054 | |||
| 4055 | /** |
||
| 4056 | * @param array $data Data from ParserOutput::getLimitReportData() |
||
| 4057 | * @since 1.28 |
||
| 4058 | */ |
||
| 4059 | public function setLimitReportData( array $data ) { |
||
| 4062 | } |
||
| 4063 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.